Beispiel #1
0
 /**
  * Add to the internal where, the filters set by the user.
  *
  * @param string $where Internal where clause.
  *
  * @return string Where clause.
  */
 public function getFilterWhere($where)
 {
     $filters = $this->getRequest()->getParam('filters', array());
     if (!empty($filters)) {
         $filterClass = new Phprojekt_Filter($this->getModelObject(), $where);
         foreach ($filters as $filter) {
             list($filterOperator, $filterField, $filterRule, $filterValue) = explode(";", $filter);
             $filterOperator = Cleaner::sanitize('alpha', $filterOperator, null);
             $filterField = Cleaner::sanitize('alpha', $filterField, null);
             $filterRule = Cleaner::sanitize('alpha', $filterRule, null);
             $filterValue = Cleaner::sanitize('filter', $filterValue, null);
             if (isset($filterOperator) && isset($filterField) && isset($filterRule) && isset($filterValue)) {
                 $filterClass->addFilter($filterField, $filterRule, $filterValue, $filterOperator);
             }
         }
         $where = $filterClass->getWhere();
     }
     return $where;
 }
Beispiel #2
0
 /**
  * Test _convertRule
  */
 public function testConvertRulePart2()
 {
     $item = new Project_Models_Project();
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('title', 'equal', 'root', 'AND');
     $this->assertEquals("( (`title` = 'root' )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('title', 'notEqual', 'root', 'OR');
     $this->assertEquals("( (`title` != 'root' )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('id', 'major', '2', 'OR');
     $this->assertEquals("( (`id` > 2 )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('id', 'majorEqual', '2', 'OR');
     $this->assertEquals("( (`id` >= 2 )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('id', 'minor', '2', 'OR');
     $this->assertEquals("( (`id` < 2 )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('id', 'minorEqual', '2', 'OR');
     $this->assertEquals("( (`id` <= 2 )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('title', 'begins', 'root', 'OR');
     $this->assertEquals("( (`title` LIKE 'root%' )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('title', 'ends', 'root', 'OR');
     $this->assertEquals("( (`title` LIKE '%root' )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('title', 'notLike', 'root', 'OR');
     $this->assertEquals("( (`title` NOT LIKE '%root%' )  )", $filter->getWhere());
     $filter = new Phprojekt_Filter($item);
     $filter->addFilter('title', 'like', 'root', 'OR');
     $this->assertEquals("( (`title` LIKE '%root%' )  )", $filter->getWhere());
 }
 protected function getFilterWhere($where = null)
 {
     $filters = $this->getRequest()->getParam('filters', "[]");
     $filters = Zend_Json_Decoder::decode($filters);
     if (!empty($filters)) {
         $filterClass = new Phprojekt_Filter($this->newModelObject(), $where);
         foreach ($filters as $filter) {
             list($filterOperator, $filterField, $filterRule, $filterValue) = $filter;
             $filterOperator = Cleaner::sanitize('alpha', $filterOperator, null);
             $filterField = Cleaner::sanitize('alpha', $filterField, null);
             $filterRule = Cleaner::sanitize('alpha', $filterRule, null);
             if (isset($filterOperator) && isset($filterField) && isset($filterRule) && isset($filterValue)) {
                 $filterClass->addFilter($filterField, $filterRule, $filterValue, $filterOperator);
             }
         }
         $where = $filterClass->getWhere();
     }
     return $where;
 }