コード例 #1
0
 /**
  * method onInlineEdit()
  * Inline record editing
  * @param $param Array containing:
  *              key: object ID value
  *              field name: object attribute to be updated
  *              value: new attribute content
  */
 function onInlineEdit($param)
 {
     try {
         // get the parameter $key
         $field = $param['field'];
         $key = $param['key'];
         $value = $param['value'];
         TTransaction::open('atividade');
         // open a transaction with database
         $object = new Atividade($key);
         // instantiates the Active Record
         $object->{$field} = $value;
         $object->store();
         // update the object in the database
         TTransaction::close();
         // close the transaction
         $this->onReload($param);
         // reload the listing
         new TMessage('info', "Record Updated");
     } catch (Exception $e) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // shows the exception error message
         TTransaction::rollback();
         // undo all pending operations
     }
 }
コード例 #2
0
 /**
  * method onSave()
  * Executed whenever the user clicks at the save button
  */
 function onSave()
 {
     try {
         TTransaction::open('atividade');
         // open a transaction
         // get the form data into an active record Atividade
         $object = $this->form->getData();
         $this->form->validate();
         // form validation
         $tipo = new TipoAtividade($object->tipo_atividade_id);
         // Start date
         $date = $this->string->formatDate($object->data_inicial);
         // End date
         $end_date = $this->string->formatDate($object->data_final);
         while (strtotime($date) <= strtotime($end_date)) {
             $criteria = new TCriteria();
             $criteria->add(new TFilter("data_ponto", "=", $date));
             $criteria->add(new TFilter("colaborador_id", "=", $object->colaborador_id));
             $repo = new TRepository('Ponto');
             $count = $repo->count($criteria);
             if (!$count) {
                 $criteria = new TCriteria();
                 $criteria->add(new TFilter("data_atividade", "=", $date));
                 $criteria->add(new TFilter("colaborador_id", "=", $object->colaborador_id));
                 $repo = new TRepository('Atividade');
                 $count = $repo->count($criteria);
                 if (!$count) {
                     $ponto = new Ponto();
                     $ponto->data_ponto = $date;
                     $ponto->hora_entrada = '08:15:00';
                     $ponto->hora_saida = '18:03:00';
                     $ponto->colaborador_id = $object->colaborador_id;
                     $ponto->store();
                     $atividade = new Atividade();
                     $atividade->data_atividade = $date;
                     $atividade->hora_inicio = '09:15:00';
                     $atividade->hora_fim = '18:03:00';
                     $atividade->descricao = 'AUSENCIA CADASTRADA EM LOTE';
                     $atividade->colaborador_id = $object->colaborador_id;
                     $atividade->tipo_atividade_id = $object->tipo_atividade_id;
                     $atividade->sistema_id = $tipo->sistema_id;
                     $atividade->ticket_id = $tipo->ticket_id;
                     $atividade->store();
                 }
             } else {
                 new TMessage('error', '<b>Erro:</b> Ponto já cadastrado dia: ' . $this->string->formatDateBR($date));
                 break;
             }
             $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
         }
         $this->form->setData($object);
         // keep form data
         TTransaction::close();
         // close the transaction
         // shows the success message
         if (!$count) {
             new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
         }
     } catch (Exception $e) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // shows the exception error message
         $this->form->setData($this->form->getData());
         // keep form data
         TTransaction::rollback();
         // undo all pending operations
     }
 }