/** * method onSave() * Executed whenever the user clicks at the save button */ function onSave() { try { $data = $this->form->getData(); // open a transaction with database 'saciq' TTransaction::open('saciq'); // cria um objeto Grupo $object = new Grupo($data->id); $object->clearParts(); $object->nome = $data->nome; $object->sigla = $data->sigla; if ($data->list2) { foreach ($data->list2 as $value) { $object->addFuncionalidade(new Funcionalidade($value)); } } //if ($object->programs) { // foreach ($object->programs as $program) { // $object->addFuncionalidade($program); // } //} $this->form->validate(); // form validation $object->store(); // stores the object $this->form->setData($object); // fill the form with the active record data $usuario = new Usuario(TSession::getValue('id')); $funcionalidades = $usuario->getFuncionalidades(); $funcionalidades['LoginForm'] = TRUE; TSession::setValue('funcionalidades', $funcionalidades); TTransaction::close(); // close the transaction new TMessage('info', 'Registro salvo'); // shows the success message } catch (Exception $e) { // Em caso de erro if ($e->getCode() == 23000) { /*$posi = strpos($e->getMessage(), 'Duplicate entry ') + strlen('Duplicate entry ') + 1; $posf = strpos($e->getMessage(), '\' for key'); $str = substr($e->getMessage(), $posi, 3); $idGrupo = substr($str, 0, strpos($str, '-')); $grupo = new Grupo($idGrupo); $idFuncionalidade = substr($str, strpos($str, '-') + 1); $funcionalidade = new Funcionalidade($idFuncionalidade); new TMessage('error', '<b>Registro duplicado</b><br>A funcionalidade "' . $funcionalidade->nome . '" já foi registrada no grupo ' . $grupo->nome); */ new TMessage('error', '<b>Registro duplicado</b><br>Verifique se a sigla já não foi registrada em outro grupo'); } else { if ($e->getCode() == 0) { new TMessage('error', '<b>Error</b> <br>' . $e->getMessage()); } else { new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode()); } } // desfazer todas as operacoes pendentes TTransaction::rollback(); } }