예제 #1
0
 public function listar($param)
 {
     try {
         TTransaction::open('sample');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('categoria_id', '=', $param['id']));
         $produtos = Produtos::getObjects($criteria);
         TTransaction::close();
         //cria um array vario
         $replace_detail = array();
         if ($produtos) {
             // iterate products
             foreach ($produtos as $p) {
                 // adicio os itens no array
                 // a função toArray(), transforma o objeto em um array
                 // passando assim para a $variavel
                 $replace_detail[] = $p->toArray();
             }
         }
         // ativa a sessão e substitui as variaveis
         //o parametro true quer dizer que é um loop
         $this->produtos->enableSection('produtos', $replace_detail, TRUE);
     } catch (Exception $e) {
         new Message('error', $e->getMessage());
     }
 }
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'samples'
         TTransaction::open('samples');
         // creates a repository for Category
         $repository = new TRepository('Category');
         // creates a criteria, ordered by id
         $criteria = new TCriteria();
         $order = isset($param['order']) ? $param['order'] : 'id';
         $criteria->setProperty('order', $order);
         // load the objects according to criteria
         $categories = $repository->load($criteria);
         $this->datagrid->clear();
         if ($categories) {
             // iterate the collection of active records
             foreach ($categories as $category) {
                 // add the object inside the datagrid
                 $this->datagrid->addItem($category);
             }
         }
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
예제 #3
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  array $filter   TFilter (optional) By Alexandre
  * @param array $expresione TExpression (opcional) by Alexandre
  */
 public function __construct($name, $database, $model, $key, $value, $ordercolumn = NULL, $filter = NULL, $expression = NULL)
 {
     new TSession();
     // executes the parent class constructor
     parent::__construct($name);
     // carrega objetos do banco de dados
     TTransaction::open($database);
     // instancia um repositório de Estado
     $repository = new TRepository($model);
     $criteria = new TCriteria();
     $criteria->setProperty('order', isset($ordercolumn) ? $ordercolumn : $key);
     if ($filter) {
         foreach ($filter as $fil) {
             if ($expression) {
                 foreach ($expression as $ex) {
                     $criteria->add($fil, $ex);
                 }
             } else {
                 $criteria->add($fil);
             }
         }
     }
     // carrega todos objetos
     $collection = $repository->load($criteria);
     // adiciona objetos na combo
     if ($collection) {
         $items = array();
         foreach ($collection as $object) {
             $items[$object->{$key}] = $object->{$value};
         }
         parent::addItems($items);
     }
     TTransaction::close();
 }
예제 #4
0
 public static function logar($email, $senha)
 {
     try {
         TTransaction::open('sample');
         $criteria = new TCriteria();
         $filter = new TFilter('email', '=', $email);
         $filter2 = new TFilter('senha', '=', $senha);
         $criteria->add($filter);
         $criteria->add($filter2);
         $user = Clientes::getObjects($criteria);
         if ($user) {
             TSession::setValue('cliente_logado', true);
             // cria a sessão para mostrar que o usuario esta no sistema
             TSession::setValue('cliente', $user);
             // guarda os dados do cliente
             foreach ($user as $c) {
                 TSession::setValue('id', $c->id);
                 // guarda os dados do cliente
             }
             TCoreApplication::executeMethod('Home');
         } else {
             new TMessage('error', 'Usuario ou Senha invalidos');
         }
         TTransaction::close();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
예제 #5
0
 public static function listForCategory($category_id)
 {
     $criteria = new TCriteria();
     $criteria->add(new TFilter('category_id', '=', $category_id));
     $repos = new TRepository('Post');
     return $repos->load($criteria);
 }
 public function getSocial()
 {
     //RECUPERA CONEXAO BANCO DE DADOS
     TTransaction::open('my_bd_site');
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->setProperty('order', 'nome ASC');
     // instancia a instrução de SELECT
     $sql = new TSqlSelect();
     $sql->addColumn('*');
     $sql->setEntity('social');
     //  atribui o critério passado como parâmetro
     $sql->setCriteria($criteria);
     // obtém transação ativa
     if ($conn = TTransaction::get()) {
         // registra mensagem de log
         TTransaction::log($sql->getInstruction());
         // executa a consulta no banco de dados
         $result = $conn->Query($sql->getInstruction());
         $this->results = array();
         if ($result) {
             // percorre os resultados da consulta, retornando um objeto
             while ($row = $result->fetchObject()) {
                 // armazena no array $this->results;
                 $this->results[] = $row;
             }
         }
     }
     TTransaction::close();
     return $this->results;
 }
 /**
  * Class constructor
  * Creates the page
  */
 function __construct()
 {
     parent::__construct();
     // create the form using TQuickForm class
     $this->form = new TQuickForm('form_seek_sample');
     $this->form->setFormTitle('Seek button');
     $this->form->class = 'tform';
     // create the form fields
     $city_id1 = new TSeekButton('city_id1');
     $city_name1 = new TEntry('city_name1');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('id', '>', 1));
     $criteria->add(new TFilter('id', '<', 5));
     $criteria->setProperty('order', 'name');
     // define the action for city_id1
     $obj = new TestCitySeek();
     $action = new TAction(array($obj, 'onReload'));
     $city_id1->setAction($action);
     $city_id1->setSize(100);
     $city_name1->setEditable(FALSE);
     $this->form->addQuickFields('Manual SeekButton', array($city_id1, $city_name1));
     $this->form->addQuickAction('Save', new TAction(array($this, 'onSave')), 'fa:floppy-o');
     // wrap the page content using vertical box
     $vbox = new TVBox();
     $vbox->add($this->form);
     parent::add($vbox);
 }
 public function removeListOfMaterialPermanente()
 {
     $criteria = new TCriteria();
     $criteria->add(new TFilter('tipo_material_permanente_id', '=', $this->id));
     $repository = new TRepository('MaterialPermanente');
     return $repository->delete($criteria);
 }
예제 #9
0
 public function delete($id = NULL)
 {
     $id = isset($id) ? $id : $this->{'id'};
     $criteria = new TCriteria();
     $criteria->add(new TFilter('project_id', '=', $id));
     $repository = new TRepository('Backlog');
     $repository->delete($criteria);
     parent::delete($id);
 }
예제 #10
0
 /**
  * Delete an Active Record object from the database
  * @param [$id]     The Object ID
  * @exception       Exception if there's no active transaction opened
  */
 public function delete($id = NULL)
 {
     $id = isset($id) ? $id : $this->{'id'};
     $note_rep = new TRepository('Note');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('id_issue', '=', $id));
     $note_rep->delete($criteria);
     // delete the object itself
     parent::delete($id);
 }
예제 #11
0
 /**
  * Retorna uma instância de usuário a partir do login
  * @param $login Login do usuário
  */
 public static function newFromLogin($login)
 {
     $repos = new TRepository('User');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('login', '=', $login));
     $objects = $repos->load($criteria);
     if (isset($objects[0])) {
         return $objects[0];
     }
 }
예제 #12
0
 public function delete($id = NULL)
 {
     $id = isset($id) ? $id : $this->logra_id;
     $repository = new TRepository('LogradouroBairro');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('tb_logradouros_logra_id', '=', $id));
     $repository->delete($criteria);
     // delete the object itself
     parent::delete($id);
 }
예제 #13
0
 /**
  * Delete the object and its aggregates
  * @param $id object ID
  */
 public function delete($id = NULL)
 {
     // delete the related System_groupSystem_program objects
     $id = isset($id) ? $id : $this->id;
     $repository = new TRepository('SystemGroupProgram');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('system_group_id', '=', $id));
     $repository->delete($criteria);
     // delete the object itself
     parent::delete($id);
 }
 function get_inscricoes()
 {
     // cria um critério de seleção
     $criteria = new TCriteria();
     // filtra por codigo do aluno
     $criteria->add(new TFilter('ref_aluno', '=', $this->id));
     // instancia repositório de Inscrições
     $repository = new TRepository('Inscricao');
     // retorna todas inscrições que satisfazem o critério
     return $repository->load($criteria);
 }
예제 #15
0
 /**
  * Returns the Item from its barcode
  */
 public static function newFromBarcode($barcode)
 {
     $rep = new TRepository('Item');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('barcode', '=', $barcode));
     $objects = $rep->load($criteria);
     if ($objects) {
         $item = $objects[0];
         return $item;
     }
 }
예제 #16
0
 /**
  * Delete the object and its aggregates
  * @param $id object ID
  */
 public function delete($id = NULL)
 {
     // delete the related System_userSystem_user_group objects
     $id = isset($id) ? $id : $this->id;
     $repository = new TRepository('SystemStock');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('id', '=', $id));
     $repository->delete($criteria);
     // delete the object itself
     parent::delete($id);
 }
예제 #17
0
 public function getEmails()
 {
     $this->collectionEmails = NULL;
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->addFilter('ativo', '=', 1);
     $criteria->setProperty('order', 'email');
     $this->repository->addColumn('email');
     $this->repository->addEntity('emails');
     $this->collectionEmails = $this->repository->load($criteria);
     return $this->collectionEmails;
 }
 public function getTelefones()
 {
     $this->collectionTelefones = NULL;
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->addFilter('ativo', '=', 1);
     $criteria->setProperty('order', 'codigo');
     $this->repository->addColumn('telefone');
     $this->repository->addEntity('telefones');
     $this->collectionTelefones = $this->repository->load($criteria);
     return $this->collectionTelefones;
 }
 /**
  * Método getImoveis
  * Retorna os Imóveis
  * 
  * @access  public
  * @return  TRepository Coleção de Imóveis
  */
 public function getImoveis()
 {
     $this->collectionImoveis = NULL;
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->addFilter('ativo', '=', 1);
     $criteria->setProperty('order', 'endereco');
     $this->repository->addColumn('*');
     $this->repository->addEntity('imoveis');
     $this->collectionImoveis = $this->repository->load($criteria);
     return $this->collectionImoveis;
 }
예제 #20
0
 public function get_itens()
 {
     // instancia um repositório de Item
     $repositorio = new TRepository('Item');
     // define o critério de seleção
     $criterio = new TCriteria();
     $criterio->add(new TFilter('id_venda', '=', $this->id));
     // carrega a coleção de itens
     $this->itens = $repositorio->load($criterio);
     // retorna os itens
     return $this->itens;
 }
예제 #21
0
 /**
  * Return the week events
  * @return Event[]
  */
 public static function getWeekEvents()
 {
     $first_week_day = self::getFirstWeekDay();
     $last_week_day = self::getLastWeekDay();
     // load objects
     $repo = new TRepository('Event');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('event_date', '>=', $first_week_day));
     $criteria->add(new TFilter('event_date', '<=', $last_week_day));
     $criteria->setProperty('order', 'event_date, start_hour');
     return $repo->load($criteria);
 }
예제 #22
0
 /**
  * Get the last loan (not arrived) from a barcode
  */
 public static function getFromBarcode($barcode)
 {
     $rep = new TRepository('Loan');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('barcode', '=', $barcode));
     $criteria->add(new TFilter('arrive_date', 'is', NULL));
     $objects = $rep->load($criteria);
     if ($objects) {
         $loan = $objects[0];
         return $loan;
     }
 }
예제 #23
0
 public function delete($id = NULL)
 {
     //sobrescrito!
     $id = isset($id) ? $id : $this->id;
     $repository = new TRepository('TurmaDisciplina');
     $criteria = new TCriteria();
     $criteria->add(new TFilter('turma_id', '=', $id));
     $repository->delete($criteria);
     $repository = new TRepository('AlunoTurma');
     $repository->delete($criteria);
     parent::delete($id);
 }
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'samples'
         TTransaction::open('samples');
         // creates a repository for Product
         $repository = new TRepository('Product');
         $limit = 10;
         // creates a criteria
         $criteria = new TCriteria();
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         // update the save action parameters to pass
         // offset, limit, page and other info to the save action
         $this->saveAction->setParameters($param);
         // important!
         // 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) {
                 $object->sale_price_edit = new TEntry('sale_price_' . $object->id);
                 $object->sale_price_edit->setNumericMask(1, '.', ',');
                 $object->sale_price_edit->setSize(120);
                 $object->sale_price_edit->setValue($object->sale_price);
                 $this->form->addField($object->sale_price_edit);
                 // important!
                 // 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) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * Método getLocalizacoes
  * Retorna as localizações
  * 
  * @access  public
  * @return  TRepository Coleção de Localizações
  */
 public function getCategorias()
 {
     $this->collectionCategoria = NULL;
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->addFilter('ativo', '=', 1);
     $criteria->setProperty('order', 'categoria');
     $this->repository->addColumn('codigo');
     $this->repository->addColumn('categoria');
     $this->repository->addEntity('categoriaimoveis');
     $this->collectionCategoria = $this->repository->load($criteria);
     return $this->collectionCategoria;
 }
 /**
  * Método getLocalizacoes
  * Retorna as localizações
  * 
  * @access  public
  * @return  TRepository Coleção de Localizações
  */
 public function getSituacoes()
 {
     $this->collectionSituacao = NULL;
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->addFilter('ativo', '=', 1);
     $criteria->setProperty('order', 'situacao');
     $this->repository->addColumn('codigo');
     $this->repository->addColumn('situacao');
     $this->repository->addEntity('situacaoimoveis');
     $this->collectionSituacao = $this->repository->load($criteria);
     return $this->collectionSituacao;
 }
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'atividade'
         TTransaction::open('atividade');
         // creates a repository for StatusTicket
         $repository = new TRepository('StatusTicket');
         $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);
         if (TSession::getValue('StatusTicket_filter')) {
             // add the filter stored in the session to the criteria
             $criteria->add(TSession::getValue('StatusTicket_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);
         $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) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // shows the exception error message
         TTransaction::rollback();
         // undo all pending operations
     }
 }
 public static function listBetween($from, $to)
 {
     TTransaction::open('samples');
     $response = array();
     $criteria = new TCriteria();
     $criteria->add(new TFilter('id', '>', $from));
     $criteria->add(new TFilter('id', '<', $to));
     $all = Customer::getObjects($criteria);
     foreach ($all as $customer) {
         $response[] = $customer->toArray();
     }
     TTransaction::close();
     return $response;
 }
예제 #29
0
 /**
  * Método load
  * Recupera um conjunto de objetos (collection) da base de dados através de um critério de seleção
  * 
  * @access public
  * @param  $criteria   Critério de Seleção
  * @throws Exception   Não há transação ativa
  * @return Resultados da Busca
  */
 function load(TCriteria $criteria = NULL)
 {
     $sql = new TSqlSelect();
     //Colunas
     if (count($this->columns) == 1) {
         $sql->addColumn($this->columns[0]);
     } else {
         foreach ($this->columns as $coluna) {
             $sql->addColumn($coluna);
         }
     }
     //Entidade
     if (count($this->entity) == 1) {
         $sql->addEntity($this->entity[0]);
     } else {
         foreach ($this->entity as $entidade) {
             $sql->addEntity($entidade);
         }
     }
     //Criteria
     if (!isset($criteria)) {
         $criteria = new TCriteria();
     }
     if (count($this->entity) > 1) {
         foreach ($this->entity as $entity) {
             $entity = explode(' ', $entity);
             $criteria->addFilter($entity[1] . '.excluido', '=', 0);
         }
     } else {
         $criteria->addFilter('excluido', '=', 0);
     }
     $sql->setCriteria($criteria);
     //echo $sql->getInstruction();
     //RECUPERA CONEXAO BANCO DE DADOS
     TTransaction::open('my_bd_site');
     if ($conn = TTransaction::get()) {
         $result = $conn->query($sql->getInstruction());
         $results = array();
         if ($result) {
             while ($row = $result->fetchObject(get_class($this))) {
                 $results[] = $row;
             }
         }
         TTransaction::close();
         return $results;
     } else {
         throw new Exception('Não há transação ativa!');
     }
 }
 /**
  *  Método getGaleriaImovel
  *  Obtém a galeria de fotos do imóvel de acordo com o código do imóvel
  *
  *  @access public
  *  @param  int         $codigo     Código do Imóvel
  *  @return TRepository             Coleção de imagens do Imóvel
  */
 public function getGaleriaImovel($codigo)
 {
     $this->collectionGaleria = NULL;
     //TABELA exposition_gallery
     $criteria = new TCriteria();
     $criteria->addFilter('ativo', '=', 1);
     $criteria->addFilter('codigoImovel', '=', $codigo);
     $criteria->setProperty('order', 'ordem');
     $this->repository->addColumn('imagem');
     $this->repository->addColumn('titulo');
     $this->repository->addColumn('descricao');
     $this->repository->addEntity('galeria');
     $this->collectionGaleria = $this->repository->load($criteria);
     return $this->collectionGaleria;
 }