WS
OR e AND no mesmo SQL com o frame...
Bom dia galera, como faço para fazer um sql assim: select* from disciplina where (id = 15 or name ilike(%matet%)) and (empresa_id = 1)?...
Meu código esta assim:
desde de já agradeço...
Meu código esta assim:
- <?php
- public function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'educacional'
- TTransaction::open('educacional');
-
- // creates a repository for CdnDisciplina
- $repository = new TRepository('CdnDisciplina');
- $limit = 100;
- // 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('CdnDisciplina_filter_id')) {
- $criteria->add(TSession::getValue('CdnDisciplina_filter_id', TExpression::OR_OPERATOR)); // add the session filter
- }
- if (TSession::getValue('CdnDisciplina_filter_nome')) {
- $criteria->add(TSession::getValue('CdnDisciplina_filter_nome'), TExpression::OR_OPERATOR); // add the session filter
- }
- // load the objects according to criteria
- $objects = $repository->load($criteria, FALSE);
-
- if (is_callable($this->transformCallback))
- {
- call_user_func($this->transformCallback, $objects, $param);
- }
- //var_dump($objects);
- $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) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- ?>
desde de já agradeço...
Galera consegui achar um exemplo que fala sobre isso, porém, ele esta remontando o criterio do SQL quando eu uso o onreload ele fica assim: ((empresa_id = 1) AND)((empresa_id = 1) AND)
segue o código:
Como faço para limpar os critérios?...