Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Problema com datagrid Boa tarde, prezados, Estou desenvolvendo um formulário onde possui os campos, em seguida um mapa com a api do google maps e em baixo do mapa um datagrid que quero colocar os pontos do mapa, porém ao preencher o campos e clicar no botão para adicionar o ponto na datagrid, a página carrega e não é preenchido o campo, se alguém puder ajudar serei muito grato. Segue abaixo o código: ...
PA
Problema com datagrid  
Boa tarde, prezados,
Estou desenvolvendo um formulário onde possui os campos, em seguida um mapa com a api do google maps e em baixo do mapa um datagrid que quero colocar os pontos do mapa, porém ao preencher o campos e clicar no botão para adicionar o ponto na datagrid, a página carrega e não é preenchido o campo, se alguém puder ajudar serei muito grato.
Segue abaixo o código:

  1. <?php
  2. /**
  3.  * SystemUnitForm
  4.  *
  5.  * @version    1.0
  6.  * @package    control
  7.  * @subpackage admin
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class CadastrarPonto extends TStandardForm
  13. {
  14.     protected $form// form
  15.     
  16.     /**
  17.      * Class constructor
  18.      * Creates the page and the registration form
  19.      */
  20.     function __construct()
  21.     {
  22.         parent::__construct();
  23.         
  24.         $this->setDatabase('permission');              // defines the database
  25.         $this->setActiveRecord('PontosRonda');     // defines the active record
  26.         
  27.         // creates the form
  28.         $this->form = new BootstrapFormBuilder('form_PontosRonda');
  29.         $this->form->setFormTitle('Teste123');
  30.         
  31.         // create the form fields
  32.         $id = new TEntry('id');
  33.         $nome_unidade = new TEntry('nome_unidade');
  34.         $id_unidade = new THidden('id_unidade');
  35.         $nome = new TEntry('nome');
  36.         $codigo_pin = new TEntry('codigo_pin');
  37.         $estado = new TCombo('estado');
  38.         $cidade = new TEntry('cidade');
  39.         $bairro = new TEntry('bairro');
  40.         $logradouro = new TEntry('logradouro');
  41.         $cep = new TEntry('cep');
  42.         $latitude = new TEntry('latitude');
  43.         $longitude = new TEntry('longitude');
  44.         $buscar TButton::create('buscar',  array($this'onSearchAddress'), 'Localizar''fa:search blue');
  45.         $adicionar TButton::create('adicionar',  array($this'onAddPoint'), 'Adicionar ponto''fa:plus green');
  46.         $estado->addItems(array('AC' => 'ACRE''AL' => 'ALAGOAS''AM' => 'AMAZONAS''AP' => 'AMAPÁ''BA' => 'BAHIA''CE' => 'CEARÁ''DF' => 'DISTRITO FEDERAL''ES' => 'ESPÍRITO SANTO''GO' => 'GOIÁS''MA' => 'MARANHÃO''MG' => 'MINAS GERAIS''MS' => 'MATO GROSSO DO SUL''MT' => 'MATO GROSSO''PA' => 'PARÁ''PB' => 'PARAÍBA''PE' => 'PERNAMBUCO''PI' => 'PIAUÍ''PR' => 'PARANÁ''RJ' => 'RIO DE JANEIRO''RN' => 'RIO GRANDE DO NORTE''RO' => 'RONDÔNIA''RR' => 'RORAIMA''RS' => 'RIO GRANDE DO SUL''SC' => 'SANTA CATARINA''SE' => 'SERGIPE''SP' => 'SÃO PAULO''TO' => 'TOCANTINS'));
  47.         $cep->setMask('99.999-999');
  48.         $mapaDenuncia = new TElement('div');
  49.         $mapaDenuncia->id 'mapaDenuncia';
  50.         $mapaDenuncia->style 'width:100%; height:400px; min-height:200px; border:1px solid gray; padding:4px; margin: auto auto 30px auto; text-align: center;';
  51.         
  52.         $id->setEditable(FALSE);
  53.         $latitude->setEditable(false);
  54.         $longitude->setEditable(false);
  55.         $id->setSize('12%');
  56.         $nome_unidade->setSize('70%');
  57.         $nome->setSize('70%');
  58.         $codigo_pin->setSize('70%');
  59.         $estado->setSize('70%');
  60.         $cidade->setSize('70%');
  61.         $bairro->setSize('70%');
  62.         $logradouro->setSize('70%');
  63.         $cep->setSize('27.8%');
  64.         $latitude->setSize('70%');
  65.         $longitude->setSize('73.5%');
  66.         //criar botão
  67.         $add_unidade  TButton::create('add_unidade',  array($this,'onAddUnidade'), _t('Add'), 'fa:plus green');
  68.         //criar datagrid
  69.         $this->listagem_pontos = new BootstrapDatagridWrapper(new TQuickGrid);
  70.         $this->listagem_pontos->setHeight(200);
  71.         $this->listagem_pontos->makeScrollable();
  72.         $this->listagem_pontos->style='width: 100%';
  73.         $this->listagem_pontos->id 'lista_unidade';
  74.         $this->listagem_pontos->disableDefaultClick();
  75.         $this->listagem_pontos->addQuickColumn('''edit''center''5%');
  76.         $this->listagem_pontos->addQuickColumn('''delete''center''5%');
  77.         $this->listagem_pontos->addQuickColumn('Pontos''unidade''center''90%');
  78.         $this->listagem_pontos->createModel();
  79.         //formulário da localização
  80.         $this->form->addFields( [new TLabel('Id')], [$id]);
  81.         $this->form->addFields( [new TLabel('Estado')], [$estado], [new TLabel('Cidade')], [$cidade] );
  82.         $this->form->addFields( [new TLabel('Bairro')], [$bairro], [new TLabel('Logradouro')], [$logradouro] );
  83.         $this->form->addFields( [new TLabel('CEP')], [$cep$buscar] );
  84.         $label2 = new TLabel('''#000000'12'bi');
  85.         $label2->style='text-align: center; border-bottom: 1px solid #c0c0c0; width: 100%';
  86.         $this->form->addContent( [$label2] );
  87.         //formulário dos pontos
  88.         $this->form->addFields( [new TLabel('Nome')], [$nome], [new TLabel('PIN')], [$codigo_pin] );
  89.         $this->form->addFields( [new TLabel('Latitude')], [$latitude], [new TLabel('Longitude')], [$longitude$adicionar] );
  90.         
  91.         //mapa
  92.         $this->form->addContent( [$mapaDenuncia] );
  93.         //datagrid dos pontos
  94.         $this->form->addFields( [new TLabel('Nome')], [$nome_unidade$add_unidade] );
  95.         $this->form->addContent(  [$this->listagem_pontos] );
  96.         // create the form actions
  97.         $btn $this->form->addAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  98.         $btn->class 'btn btn-sm btn-primary';
  99.         $this->form->addAction(_t('Clear'),  new TAction(array($this'onEdit')), 'fa:eraser red');
  100.         $this->form->addAction(_t('Back'),new TAction(array('CadastroRonda','onReload')),'fa:arrow-circle-o-left blue');
  101.         
  102.         // vertical box container
  103.         $container = new TVBox;
  104.         $container->style 'width: 100%';
  105.         $container->add(new TXMLBreadCrumb('menu.xml''CadastroRonda'));
  106.         $container->add($this->form );
  107.         
  108.         parent::add($container);
  109.          TScript::create("
  110.             var pontos = [];
  111.             function removePoint(id){
  112.                 pontos[id].setMap(null);
  113.             }
  114.             function addPonto(){
  115.                 Adianti.waitMessage = 'Carregando';
  116.                 __adianti_post_data('form_PontosRonda', 'class=GoogleMaps&method=onAddPoint&static=1');
  117.                 return false;
  118.             }
  119.             var mapOptions = {
  120.                 zoom: 13,
  121.                 center: {lat: -12.984588, lng: -38.485411},
  122.                 styles: [
  123.                     { 'featureType': 'administrative', 'elementType': 'labels.text.fill', 'stylers': [ { 'color': '#444444' } ] },
  124.                     { 'featureType': 'landscape', 'elementType': 'all', 'stylers': [ { 'color': '#f2f2f2' } ] },
  125.                     { 'featureType': 'poi', 'elementType': 'all', 'stylers': [ { 'visibility': 'off' } ] },
  126.                     { 'featureType': 'road', 'elementType': 'all', 'stylers': [ { 'saturation': -100 }, { 'lightness': 45 } ] },
  127.                     { 'featureType': 'road.highway', 'elementType': 'all', 'stylers': [ { 'visibility': 'simplified' } ] },
  128.                     { 'featureType': 'road.arterial', 'elementType': 'labels.icon', 'stylers': [ { 'visibility': 'off' } ] },
  129.                     { 'featureType': 'transit', 'elementType': 'all', 'stylers': [ { 'visibility': 'off' } ] },
  130.                     { 'featureType': 'water', 'elementType': 'all', 'stylers': [ { 'color': '#46bcec' }, { 'visibility': 'on' } ] }
  131.                 ]
  132.             };
  133.             /* Instantiate a directions service. */
  134.             var directionsService = new google.maps.DirectionsService;
  135.             /* Create a map */
  136.             var map = new google.maps.Map(document.getElementById('mapaDenuncia'), mapOptions);
  137.             /* Create a renderer for directions and bind it to the map. */
  138.             var directionsDisplay = new google.maps.DirectionsRenderer({map: map, suppressMarkers: true});
  139.             google.maps.event.addListener(map, 'click', function (e) {
  140.                 var point0 = new google.maps.Marker({
  141.                     position: e.latLng, 
  142.                     draggable: false,
  143.                     map: map,
  144.                     title: 'Perímetro'
  145.                 });
  146.                 pontos[pontos.length] = point0;
  147.                 var lat = e.latLng.lat();
  148.                 var lng = e.latLng.lng();
  149.                 
  150.                 $('input[name=\"latitude\"]').val(lat);
  151.                 $('input[name=\"longitude\"]').val(lng);
  152.                 /*addPonto();*/
  153.             });
  154.             var infoWindow = new google.maps.InfoWindow({
  155.                 content: 'Seu perímetro.'
  156.             });
  157.             if (navigator.geolocation) {
  158.                 navigator.geolocation.getCurrentPosition(function(position) {
  159.                     var pos = {lat: position.coords.latitude, lng: position.coords.longitude};
  160.                     map.setCenter(pos);
  161.                 }, function() {
  162.                     handleLocationError(true, infoWindow, map.getCenter());
  163.                 });
  164.             } else {
  165.                 /* Browser doesn't support Geolocation*/
  166.                 handleLocationError(false, infoWindow, map.getCenter());
  167.             }
  168.             function handleLocationError(browserHasGeolocation, infoWindow, pos) {}
  169.         ");
  170.     }
  171.     //função para filtrar com funções php
  172.     public static function test_input($data) {
  173.         $data trim($data);
  174.         $data stripslashes($data);
  175.         $data htmlspecialchars($data);
  176.         return $data;
  177.     }
  178.     public static function onSearchAddress($param)
  179.     {
  180.         if((isset($param['estado']) && strlen(trim($param['estado'])) > 0) || (isset($param['cep']) && strlen(trim($param['cep'])) > 0)){
  181.             $estado $param['estado'];
  182.             $cidade trim($param['cidade']);
  183.             $bairro trim($param['bairro']);
  184.             $logradouro trim($param['logradouro']);
  185.             $cep str_replace(array('-''.'), array(''''), trim($param['cep']));
  186.             $coordenadas WebService::getCoordinates$estado$cidade$bairro$logradouro$cep);
  187.             if(sizeof($coordenadas) > 0){
  188.                 if(strlen($coordenadas['lat']) > 0){
  189.                     TScript::create("
  190.                         map.setCenter({lat: {$coordenadas['lat']}, lng: {$coordenadas['lon']}});
  191.                         map.setZoom(17);
  192.                     ");
  193.                 } else {
  194.                     new TMessage('error''Local não encontrado!');
  195.                 }
  196.             }
  197.         }
  198.     }
  199.         public static function onAddPoint($param)
  200.     {
  201.         if(isset($param['nome']) && strlen(trim($param['nome'])) > && isset($param['latitude']) && strlen(trim($param['latitude'])) > && isset($param['longitude']) && strlen(trim($param['longitude'])) > 0){
  202.             $pontos TSession::getValue('lista_pontos');
  203.             $novoPonto = new PontosRonda;
  204.             $novoPonto->nome $param['nome'];
  205.             $novoPonto->latitude $param['latitude'];
  206.             $novoPonto->longitude $param['longitude'];
  207.             $novoPonto->codigo_pin $param['codigo_pin'];
  208.             $pontos[] = $novoPonto;
  209.             TSession::setValue('lista_pontos'$pontos);
  210.             $data = new stdClass;
  211.             $data->nome '';
  212.             $data->latitude '';
  213.             $data->longitude '';
  214.             $data->codigo_pin '';
  215.             TForm::sendData('form_PontosRonda'$data);
  216.         } else {
  217.             new TMessage('error''Informe o nome e as coordenadas do ponto');
  218.         }
  219.     }
  220.         public static function onRemovePoint($param){
  221.         $pontos TSession::getValue('lista_pontos');
  222.         unset($ponto[$param['id']]);
  223.         TSession::setValue('lista_pontos'$pontos);
  224.         TScript::create("removePoint(" $param['key'] . ");");
  225.     }
  226.     public static function updateUnidadeDatagrid($listagem_pontos){
  227.         TScript::create('$(\'table[id="listagem_pontos"] tbody\').empty();');
  228.         foreach ($listagem_pontos as $key => $value) {
  229.             $i = new TElement('i');
  230.             $i->{'class'} = 'fa fa-pencil-square-o blue';
  231.             $btn1 = new TElement('a');
  232.             $btn1->{'onclick'} = "__adianti_ajax_exec(\'class=TESTE123&method=editUnidade&id=$key\');";
  233.             $btn1->{'class'} = 'btn btn-default btn-sm';
  234.             $btn1->add($i);
  235.             $i = new TElement('i');
  236.             $i->{'class'} = 'fa fa-trash red';
  237.             $btn2 = new TElement('a');
  238.             $btn2->{'onclick'} = "__adianti_ajax_exec(\'class=TESTE123&method=confirmDeleteUnidade&id=$key\');";
  239.             $btn2->{'class'} = 'btn btn-default btn-sm';
  240.             $btn2->add($i);
  241.             
  242.             $tr = new TTableRow;
  243.             $tr->{'class'} = 'tdatagrid_row_odd';
  244.             $tr->{'style'} = 'width: 100%;display: inline-table;';
  245.             $cell $tr->addCell$btn1 );
  246.             $cell->{'style'}='text-align:center';
  247.             $cell->{'class'}='tdatagrid_cell';
  248.             $cell->{'width'} = '5%';
  249.             $cell $tr->addCell$btn2 );
  250.             $cell->{'style'}='text-align:center';
  251.             $cell->{'class'}='tdatagrid_cell';
  252.             $cell->{'width'} = '5%';
  253.             $cell $tr->addCell$value );
  254.             $cell->{'style'}='text-align:center';
  255.             $cell->{'class'}='tdatagrid_cell';
  256.             $cell->{'width'} = '5%';
  257.             
  258.             TScript::create("tdatagrid_add_serialized_row('listagem_pontos', '$tr');");
  259.         }
  260.     }
  261.     public static function confirmDeleteUnidade($param)
  262.     {
  263.         // define the delete action
  264.         $action = new TAction(array('TESTE123''deleteUnidade'));
  265.         $action->setParameters($param); // pass the key parameter ahead
  266.         
  267.         // shows a dialog to the user
  268.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  269.     }
  270.     public static function deleteUnidade($param)
  271.     {
  272.         $listagem_pontos TSession::getValue('listagem_pontos');
  273.         unset($listagem_pontos$param['id'] ]);
  274.         TSession::setValue('listagem_pontos'$listagem_pontos);
  275.         CadastrarPonto::updateUnidadeDatagrid($listagem_pontos);
  276.     }
  277.     public static function editUnidade($param)
  278.     {
  279.         $listagem_pontos TSession::getValue('listagem_pontos');
  280.         $data = new stdClass;
  281.         $data->id_unidade $param['id'];
  282.         $data->nome_unidade $listagem_pontos$param['id'] ];
  283.         TForm::sendData('form_PontosRonda'$data);
  284.     }
  285.     public static function onAddUnidade($param)
  286.     {
  287.         if(isset($param['nome_unidade']) && strlen(trim($param['nome_unidade'])) > 0){
  288.             $id date('Y_m_d_H_i_s') . '_' rand(09999);
  289.             if(isset($param['id_unidade']) && strlen(trim($param['id_unidade'])) > 0){
  290.                 $id $param['id_unidade'];
  291.             }
  292.             $listagem_pontos TSession::getValue('listagem_pontos');
  293.             $listagem_pontos[$id] = trim($param['nome_unidade']);
  294.             TSession::setValue('listagem_pontos'$listagem_pontos);
  295.             CadastrarPonto::updateUnidadeDatagrid($listagem_pontos);
  296.             
  297.             $data = new stdClass;
  298.             $data->id_unidade '';
  299.             $data->nome_unidade '';
  300.             TForm::sendData('form_PontosRonda'$data);
  301.         }
  302.     }
  303.     function onEdit($param)
  304.     {
  305.         try
  306.         {
  307.             TSession::setValue('listagem_pontos', []);
  308.             if (isset($param['key']))
  309.             {
  310.                 // get the parameter $key
  311.                 $key=$param['key'];
  312.                 
  313.                 // open a transaction with database 'permission'
  314.                 TTransaction::open('permission');
  315.                 
  316.                 // instantiates object System_group
  317.                 $object = new PontosRonda($key);
  318.                 
  319.                 // fill the form with the active record data
  320.                 $this->form->setData($object);
  321.                 $criterio = new TCriteria;
  322.                 $criterio->add(new TFilter('fk_id_ponto_ronda''='$key));
  323.                 $unidades PontosRonda::getObjects($criterio);
  324.                 $script "
  325.                     var point0 = new google.maps.Marker({
  326.                         position: {lat: {$object->latitude}, lng: {$object->longitude}}, 
  327.                         draggable: false,
  328.                         map: map,
  329.                         title: 'Perímetro'
  330.                     });
  331.                     pontos[0] = point0;
  332.                 ";
  333.                 $lista_pontos = array();
  334.                 $lista_pontos[0] = $object;
  335.                 $indice 1;
  336.                 foreach ($pontos as $ponto)
  337.                 {
  338.                     //$id = date('Y_m_d_H_i_s') . '_' . rand(0, 9999);
  339.                     $id $ponto->id;
  340.                     
  341.                     $lista_pontos[$id] = $ponto;
  342.                     $script .= "
  343.                         var point{$indice} = new google.maps.Marker({
  344.                             position: {lat: {$ponto->latitude}, lng: {$ponto->longitude}}, 
  345.                             draggable: false,
  346.                             map: map,
  347.                             title: 'Perímetro'
  348.                         });
  349.                         pontos[$indice] = point{$indice};
  350.                     ";
  351.                     $item = new stdClass;
  352.                     $item->id $id;
  353.                     $item->ponto $ponto->nome;
  354.                     $indice++;
  355.                 }
  356.                 $listagem_pontos = array();
  357.                 foreach ($unidades as $unidade)
  358.                 {
  359.                     //$id = date('Y_m_d_H_i_s') . '_' . rand(0, 9999);
  360.                     $id $unidade->id;
  361.                     
  362.                     $listagem_pontos[$id] = $unidade->nome;
  363.                     
  364.                     $item = new stdClass;
  365.                     $item->id $id;
  366.                     $item->unidade $unidade->nome;
  367.                     $i = new TElement('i');
  368.                     $i->{'class'} = 'fa fa-pencil-square-o blue';
  369.                     $btn1 = new TElement('a');
  370.                     $btn1->{'onclick'} = "__adianti_ajax_exec('class=TESTE123&method=editUnidade&id={$id}');";
  371.                     $btn1->{'class'} = 'btn btn-default btn-sm';
  372.                     $btn1->add$i );
  373.                     
  374.                     $i = new TElement('i');
  375.                     $i->{'class'} = 'fa fa-trash red';
  376.                     $btn2 = new TElement('a');
  377.                     $btn2->{'onclick'} = "__adianti_ajax_exec('class=TESTE123&method=confirmDeleteUnidade&id={$id}');";
  378.                     $btn2->{'class'} = 'btn btn-default btn-sm';
  379.                     $btn2->add$i );
  380.                     
  381.                     $item->edit $btn1;
  382.                     $item->delete $btn2;
  383.                     $tr $this->listagem_pontos->addItem($item);
  384.                     $tr->{'style'} = 'width: 100%;display: inline-table;';
  385.                 }
  386.                 TSession::setValue('listagem_pontos'$listagem_pontos);
  387.                 TSession::setValue('lista_pontos'$lista_pontos);
  388.                 $data = new stdClass;
  389.                 TForm::sendData('form_PontosRonda'$data);
  390.                 TScript::create("
  391.                     {$script}
  392.                     map.setCenter(new google.maps.LatLng({$object->latitude}{$object->longitude}));
  393.                     map.setZoom(15);
  394.                 ");
  395.                 
  396.                 // close the transaction
  397.                 TTransaction::close();
  398.             } else {
  399.                 $this->form->clear();
  400.             }
  401.         } catch (Exception $e) {
  402.             // shows the exception error message
  403.             new TMessage('error'$e->getMessage());
  404.             
  405.             // undo all pending operations
  406.             TTransaction::rollback();
  407.         }
  408.     }
  409.     function onEdit2($param)
  410.     {
  411.         try
  412.         {
  413.             TSession::setValue('listagem_pontos', []);
  414.             if (isset($param['key']))
  415.             {
  416.                 // get the parameter $key
  417.                 $key=$param['key'];
  418.                 
  419.                 // open a transaction with database 'permission'
  420.                 TTransaction::open('permission');
  421.                 
  422.                 // instantiates object
  423.                 $object = new PontosRonda($key);
  424.                 
  425.                 // fill the form with the active record data
  426.                 $this->form->setData($object);
  427.                 $criterio = new TCriteria;
  428.                 $criterio->add(new TFilter('id''='$key));
  429.                 $unidades PontosRonda::getObjects($criterio);
  430.                 $listagem_pontos = array();
  431.                 foreach ($unidades as $unidade)
  432.                 {
  433.                     //$id = date('Y_m_d_H_i_s') . '_' . rand(0, 9999);
  434.                     $id $unidade->id;
  435.                     
  436.                     $listagem_pontos[$id] = $unidade->nome;
  437.                     
  438.                     $item = new stdClass;
  439.                     $item->id $id;
  440.                     $item->unidade $unidade->nome;
  441.                 }
  442.                 TSession::setValue('listagem_pontos'$listagem_pontos);
  443.                 $data = new stdClass;
  444.                 TForm::sendData('form_PontosRonda'$data);
  445.                 TScript::create("
  446.                     selectedPoint = new google.maps.Marker({
  447.                         position: {lat: {$object->latitude}, lng: {$object->longitude}}, 
  448.                         draggable: false,
  449.                         map: map,
  450.                         title: 'Perímetro'
  451.                     });
  452.                     map.setCenter(new google.maps.LatLng({$object->latitude}{$object->longitude}));
  453.                     map.setZoom(15);
  454.                 ");
  455.                 
  456.                 // close the transaction
  457.                 TTransaction::close();
  458.             } else {
  459.                 $this->form->clear();
  460.             }
  461.         } catch (Exception $e) {
  462.             // shows the exception error message
  463.             new TMessage('error'$e->getMessage());
  464.             
  465.             // undo all pending operations
  466.             TTransaction::rollback();
  467.         }
  468.     }
  469.     function onSave()
  470.     {
  471.         try
  472.         {
  473.             // open a transaction with database 'permission'
  474.             TTransaction::open('permission');
  475.             
  476.             // get the form data into an active record System_group
  477.             $data $this->form->getData();
  478.             $listagem_pontos TSession::getValue('listagem_pontos');
  479.             $lista TSession::getValue('lista_pontos');
  480.             PontosRonda::updateUnidadeDatagrid($listagem_pontos);
  481.             $this->form->validate();
  482.             $object = new PontosRonda;
  483.             $object->fromArray( (array) $data );
  484.             $object->store();
  485.             $unitsToMaintain = [];
  486.             foreach ($listagem_pontos as $key => $value) {
  487.                 if(strpos($key'_') !== false){
  488.                     $elemento = new PontosRonda;
  489.                 } else {
  490.                     $elemento = new PontosRonda($key);
  491.                 }
  492.                 $elemento->id $object->id;
  493.                 $elemento->nome $value;
  494.                 $elemento->store();
  495.                 $unitsToMaintain[] = $elemento->id;
  496.             }
  497.             if(sizeof($unitsToMaintain) > 0){
  498.                 PontosRonda::where('id''='$object->id)->where('id''NOT IN'$unitsToMaintain)->delete();
  499.             } else {
  500.                 PontosRonda::where('id''='$object->id)->delete();
  501.             }
  502.             if(sizeof($lista) > 0){
  503.                 // open a transaction with database 'permission'
  504.                 TTransaction::open('permission');
  505.                 if($data->id){
  506.                     PontosRonda::where('fk_id_ponto_ronda''='$data->id)->delete();
  507.                     $ponto = new PontosRonda($data->id);
  508.                     $ponto->delete();
  509.                 }
  510.                 $fk null;
  511.                 foreach ($lista as $ponto) {
  512.                     $ponto->id null;
  513.                     $ponto->nome TESTE123::test_input($ponto->nome);
  514.                     $ponto->fk_id_ponto_ronda $fk;
  515.                     $ponto->store();
  516.                     if($fk == null){
  517.                         $fk $ponto->id;
  518.                     }
  519.                 }
  520.                 TTransaction::close(); // close the transaction
  521.                 TApplication::loadPage('CadastroRonda''showMessage');
  522.             } else {
  523.                 new TMessage('error''Informe pelo menos um ponto da ronda!');
  524.             }
  525.             
  526.             TTransaction::close(); // close the transaction
  527.             //TApplication::loadPage('CadastroRonda', 'showMessage');
  528.         }
  529.         catch (Exception $e// in case of exception
  530.         {
  531.             // shows the exception error message
  532.             new TMessage('error'$e->getMessage());
  533.             
  534.             // undo all pending operations
  535.             TTransaction::rollback();
  536.         }
  537.     }
  538. }

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (0)