Example #1
0
 /**
  * Class Constructor
  * @param  $name     widget's name
  * @param  $database database name
  * @param  $model    model class name
  * @param  $key      table field to be used as key in the combo
  * @param  $value    table field to be listed in the combo
  * @param  $ordercolumn column to order the fields (optional)
  * @param  $criteria criteria (TCriteria object) to filter the model (optional)
  */
 public function __construct($name, $database, $model, $key, $value, $ordercolumn = NULL, TCriteria $criteria = NULL)
 {
     // executes the parent class constructor
     parent::__construct($name);
     if (empty($database)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__));
     }
     if (empty($model)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__));
     }
     if (empty($key)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'key', __CLASS__));
     }
     if (empty($value)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'value', __CLASS__));
     }
     // carrega objetos do banco de dados
     TTransaction::open($database);
     // instancia um repositório de Estado
     $repository = new TRepository($model);
     if (is_null($criteria)) {
         $criteria = new TCriteria();
     }
     $criteria->setProperty('order', isset($ordercolumn) ? $ordercolumn : $key);
     // carrega todos objetos
     $collection = $repository->load($criteria, FALSE);
     // adiciona objetos na combo
     if ($collection) {
         $items = array();
         foreach ($collection as $object) {
             $items[$object->{$key}] = $object->{$value};
         }
         parent::addItems($items);
     }
     TTransaction::close();
 }
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'saciq'
         TTransaction::open('saciq');
         //TTransaction::setLogger(new TLoggerTXT('c:\array\file.txt'));
         // creates a repository for Cessao
         $repository = new TRepository('Cessao');
         $limit = 10;
         // creates a criteria
         $criteria = new TCriteria();
         // default order
         if (empty($param['order'])) {
             $param['order'] = 'id';
             $param['direction'] = 'asc';
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         $criteria->add(new TFilter('aprovado', '=', '1'));
         if (TSession::getValue('CessaoList_filter_numeroCessao')) {
             $criteria->add(TSession::getValue('CessaoList_filter_numeroCessao'));
             // add the session filter
         }
         // load the objects according to criteria
         $objects = $repository->load($criteria, FALSE);
         $this->datagrid->clear();
         if ($objects) {
             // iterate the collection of active records
             foreach ($objects as $object) {
                 if ($object->srp->estaVencida()) {
                     continue;
                 }
                 $object->emissao = TDate::date2br($object->emissao);
                 $object->numeroSRP = $object->srp->numeroSRP;
                 $this->datagrid->addItem($object);
             }
         }
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } 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();
     }
 }
Example #3
0
 /**
  * Load the datagrid with the active record objects
  */
 public function onReload($param = NULL)
 {
     try {
         $model = TSession::getValue('standard_seek_model');
         $database = TSession::getValue('standard_seek_database');
         $pk = constant("{$model}::PRIMARYKEY");
         // begins the transaction with database
         TTransaction::open($database);
         // creates a repository for the model
         $repository = new TRepository($model);
         $limit = 10;
         // creates a criteria
         if (TSession::getValue('standard_seek_criteria')) {
             $criteria = clone TSession::getValue('standard_seek_criteria');
         } else {
             $criteria = new TCriteria();
             // default order
             if (empty($param['order'])) {
                 $param['order'] = $pk;
                 $param['direction'] = 'asc';
             }
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('tstandardseek_filter')) {
             // add the filter to the criteria
             $criteria->add(TSession::getValue('tstandardseek_filter'));
         }
         // load all objects according with the criteria
         $objects = $repository->load($criteria, FALSE);
         $this->datagrid->clear();
         if ($objects) {
             $display_field = TSession::getValue('standard_seek_display_field');
             foreach ($objects as $object) {
                 $item = $object;
                 $item->id = $object->{$pk};
                 $item->display_field = $object->{$display_field};
                 // add the object into the datagrid
                 $this->datagrid->addItem($item);
             }
         }
         // clear the crieteria to count the records
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         $this->pageNavigation->setCount($count);
         // count of records
         $this->pageNavigation->setProperties($param);
         // order, page
         $this->pageNavigation->setLimit($limit);
         // limit
         // closes the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         // shows the exception genearated message
         new TMessage('error', '<b>Erro</b> ' . $e->getMessage());
         // rollback all the database operations
         TTransaction::rollback();
     }
 }
 /**
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'samples'
         TTransaction::open('sobcontrole');
         // creates a repository for City
         $repository = new TRepository('tipocontato');
         $limit = 10;
         // creates a criteria
         $criteria = new TCriteria();
         // default order
         if (!isset($param['order'])) {
             $param['order'] = 'idtipocontato';
             $param['direction'] = 'asc';
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('tipocontato_filtro')) {
             // add the filter stored in the session to the criteria
             $criteria->add(TSession::getValue('tipocontato_filtro'));
         }
         // load the objects according to the criteria
         $tiposdecontato = $repository->load($criteria);
         $this->datagrid->clear();
         if ($tiposdecontato) {
             foreach ($tiposdecontato as $tipocontato) {
                 // add the object inside the datagrid
                 $this->datagrid->addItem($tipocontato);
             }
         }
         // reset the criteria for record count
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         $this->pageNavigation->setCount($count);
         // count of records
         $this->pageNavigation->setProperties($param);
         // order, page
         $this->pageNavigation->setLimit($limit);
         // limit
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * method onReload()
  * carregar o datagrid com objetos do banco
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'saciq'
         TTransaction::open('saciq');
         // creates a repository for Funcionalidade
         $repository = new TRepository('Funcionalidade');
         $limit = 10;
         // creates a criteria
         $criteria = new TCriteria();
         if (!isset($param['order'])) {
             $param['order'] = 'id';
             $param['direction'] = 'asc';
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('Funcionalidade_nome_filter')) {
             // add the filter stored in the session to the criteria
             $criteria->add(TSession::getValue('Funcionalidade_nome_filter'));
         }
         if (TSession::getValue('Funcionalidade_control_filter')) {
             // add the filter stored in the session to the criteria
             $criteria->add(TSession::getValue('Funcionalidade_control_filter'));
         }
         // load the objects according to criteria
         $objects = $repository->load($criteria);
         $this->datagrid->clear();
         if ($objects) {
             // iterate the collection of active records
             foreach ($objects as $object) {
                 // add the object inside the datagrid
                 $this->datagrid->addItem($object);
             }
         }
         // reset the criteria for record count
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         $this->pageNavigation->setCount($count);
         // count of records
         $this->pageNavigation->setProperties($param);
         // order, page
         $this->pageNavigation->setLimit($limit);
         // limit
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } 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();
     }
 }
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 public function onReload($param = NULL)
 {
     try {
         // open a transaction with database
         TTransaction::open($this->database);
         // instancia um repositório
         $repository = new TRepository($this->activeRecord);
         $limit = isset($this->limit) ? $this->limit > 0 ? $this->limit : NULL : 10;
         // creates a criteria
         $criteria = new TCriteria();
         if ($this->order) {
             $criteria->setProperty('order', $this->order);
             $criteria->setProperty('direction', $this->direction);
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         $criteria->add(new TFilter("system_user_id", "=", TSession::getValue("userid")));
         if (TSession::getValue($this->activeRecord . '_filter')) {
             // add the filter stored in the session to the criteria
             $criteria->add(TSession::getValue($this->activeRecord . '_filter'));
         }
         // load the objects according to criteria
         $objects = $repository->load($criteria, FALSE);
         $this->datagrid->clear();
         if ($objects) {
             // iterate the collection of active records
             foreach ($objects as $object) {
                 // add the object inside the datagrid
                 $this->datagrid->addItem($object);
             }
         }
         // reset the criteria for record count
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         if (isset($this->pageNavigation)) {
             $this->pageNavigation->setCount($count);
             // count of records
             $this->pageNavigation->setProperties($param);
             // order, page
             $this->pageNavigation->setLimit($limit);
             // limit
         }
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         // in case of exception
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
Example #7
0
 /**
  * method onReload()
  * carregar o datagrid com objetos do banco
  */
 function onReload($param = NULL)
 {
     try {
         // abre uma transacao com o banco 'saciq'
         TTransaction::open('saciq');
         if (!isset($param['order'])) {
             $param['order'] = 'id';
             $param['direction'] = 'asc';
         }
         // cria um repository para Grupo
         $repository = new TRepository('Grupo');
         $limit = 10;
         // cria um criteria
         $criteria = new TCriteria();
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('s_nome_filter')) {
             // adiciona o filtro gravado na sessao para o obj criteria.
             $criteria->add(TSession::getValue('s_nome_filter'));
         }
         if (TSession::getValue('s_sigla_filter')) {
             // adiciona o filtro gravado na sessao para o obj criteria.
             $criteria->add(TSession::getValue('s_sigla_filter'));
         }
         // carrega os objetos de acordo o filtro criteria
         $objects = $repository->load($criteria);
         $this->datagrid->clear();
         if ($objects) {
             // iterar a coleção de active records
             foreach ($objects as $object) {
                 // adiciona o objeto dentro do datagrid
                 $this->datagrid->addItem($object);
             }
         }
         // reset o criteria para o record count
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         $this->pageNavigation->setCount($count);
         // quantidade de registros
         $this->pageNavigation->setProperties($param);
         // ordem, pagina
         $this->pageNavigation->setLimit($limit);
         // limite
         // fecha a transacao
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } 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();
     }
 }
Example #8
0
 function onReload($param = NULL)
 {
     try {
         // abre uma transação com o banco 'saciq'
         TTransaction::open('saciq');
         //TTransaction::setLogger(new \Adianti\Log\TLoggerTXT("c:\\array\\LOG".date("Ymd-His").".txt"));
         // cria um repository para Srp
         $repository = new TRepository('Srp');
         $limit = 10;
         // cria um criteria
         $criteria = new TCriteria();
         // ordem default
         if (empty($param['order'])) {
             $param['order'] = 'id';
             $param['direction'] = 'asc';
         }
         $criteria->setProperties($param);
         // ordem, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('SrpList_filter_numeroSRP')) {
             $criteria->add(TSession::getValue('SrpList_filter_numeroSRP'));
             // add the session filter
         }
         if (TSession::getValue('SrpList_filter_numeroIRP')) {
             $criteria->add(TSession::getValue('SrpList_filter_numeroIRP'));
             // add the session filter
         }
         if (TSession::getValue('SrpList_filter_numeroProcesso')) {
             $criteria->add(TSession::getValue('SrpList_filter_numeroProcesso'));
             // add the session filter
         }
         if (TSession::getValue('SrpList_filter_uasg')) {
             $criteria->add(TSession::getValue('SrpList_filter_uasg'));
             // add the session filter
         }
         if (TSession::getValue('SrpList_filter_validade')) {
             $criteria->add(TSession::getValue('SrpList_filter_validade'));
             // add the session filter
         }
         if (TSession::getValue('SrpList_filter_nome')) {
             $criteria->add(TSession::getValue('SrpList_filter_nome'));
             // add the session filter
         }
         // carrega os objetos de acordo com os filtros
         $objects = $repository->load($criteria, FALSE);
         $this->datagrid->clear();
         if ($objects) {
             // iterar a coleção de active records
             foreach ($objects as $object) {
                 //muda a data para o formato brasileiro (DD/MM/YYYY)
                 $object->validade = TDate::date2br($object->validade);
                 //adiciona o objeto no datagrid
                 $this->datagrid->addItem($object);
             }
         }
         // reseta o criteria (filtro) para contagem de registros
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         $this->pageNavigation->setCount($count);
         // contagem de registro
         $this->pageNavigation->setProperties($param);
         // ordem, pagina
         $this->pageNavigation->setLimit($limit);
         // limite
         // fecha a transação
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } 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();
     }
 }
Example #9
0
 /**
  * Load composite objects (parts in composition relationship)
  * @param $composite_class Active Record Class for composite objects
  * @param $foreign_key Foreign key in composite objects
  * @param $id Primary key of parent object
  * @returns Array of Active Records
  */
 public function loadComposite($composite_class, $foreign_key, $id = NULL, $order = NULL)
 {
     // discover the primary key name
     $pk = $this->getPrimaryKey();
     // if the user has not passed the ID, take the object ID
     $id = $id ? $id : $this->{$pk};
     $criteria = new TCriteria();
     $criteria->add(new TFilter($foreign_key, '=', $id));
     if ($order) {
         $criteria->setProperty('order', $order);
     }
     $repository = new TRepository($composite_class);
     $objects = $repository->load($criteria);
     return $objects;
 }
Example #10
0
 function onReload($param)
 {
     $this->dg_UltImportacao->clear();
     $this->dg_UltRequisicao->clear();
     $this->dg_UltCesssao->clear();
     $this->dg_SRPAVencer->clear();
     try {
         TTransaction::open('saciq');
         //TTransaction::setLogger(new TLoggerTXT("c:\\array\\LOG".date("Ymd-His").".txt"));
         //ultimas importações
         $criteriaUI = new TCriteria();
         $param['order'] = 'id';
         $param['direction'] = 'desc';
         $criteriaUI->setProperties($param);
         $criteriaUI->setProperty('limit', 8);
         $repositoryUI = new TRepository('Srp');
         $srps = $repositoryUI->load($criteriaUI, false);
         foreach ($srps as $srp) {
             $srp->validade = TDate::date2br($srp->validade);
             $this->dg_UltImportacao->addItem($srp);
         }
         //ultimas Requisições
         $criteriaUR = new TCriteria();
         $param['order'] = 'emissao';
         $param['direction'] = 'desc';
         $criteriaUR->setProperties($param);
         $criteriaUR->setProperty('limit', 8);
         $repositoryUR = new TRepository('Requisicao');
         $requisicoes = $repositoryUR->load($criteriaUR, false);
         foreach ($requisicoes as $requisicao) {
             $requisicao->numeroSRP = $requisicao->srp->numeroSRP;
             $requisicao->aprovado = $requisicao->aprovado == 0 ? 'Não' : 'Sim';
             $requisicao->emissao = TDate::date2br($requisicao->emissao);
             $this->dg_UltRequisicao->addItem($requisicao);
         }
         //Atas a vencer
         $criteriaAV = new TCriteria();
         $param['order'] = 'validade';
         $param['direction'] = 'asc';
         $criteriaAV->setProperties($param);
         $criteriaAV->setProperty('limit', 8);
         $criteriaAV->add(new TFilter('validade', '>=', date("Y-m-d")));
         $repositoryAV = new TRepository('Srp');
         $atasAVencer = $repositoryAV->load($criteriaAV, false);
         foreach ($atasAVencer as $atas) {
             $atas->validade = TDate::date2br($atas->validade);
             $this->dg_SRPAVencer->addItem($atas);
         }
         //ultimas Cessões
         $criteriaUC = new TCriteria();
         $param['order'] = 'emissao';
         $param['direction'] = 'desc';
         $criteriaUC->setProperties($param);
         $criteriaUC->setProperty('limit', 8);
         $repositoryUC = new TRepository('Cessao');
         $cessoes = $repositoryUC->load($criteriaUC, false);
         foreach ($cessoes as $cessao) {
             $cessao->numeroSRP = $cessao->srp->numeroSRP;
             $cessao->aprovado = $cessao->aprovado == 0 ? 'Não' : 'Sim';
             $cessao->emissao = TDate::date2br($cessao->emissao);
             $this->dg_UltCesssao->addItem($cessao);
         }
         $this->loaded = true;
         TTransaction::close();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } 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();
     }
 }