Exemple #1
0
 /**
  * Test the build process.
  *
  * @return void
  */
 public function testBuild()
 {
     $metaModel = new MetaModel(array('id' => '1', 'sorting' => '1', 'tstamp' => '0', 'name' => 'MetaModel', 'tableName' => 'mm_test', 'mode' => '', 'translated' => '1', 'languages' => array('en' => array('isfallback' => '1'), 'de' => array('isfallback' => '')), 'varsupport' => '1'));
     /** @var \MetaModels\Attribute\Base $attribute */
     $attribute = $this->getMockForAbstractClass('MetaModels\\Attribute\\Base', array($metaModel, array('colname' => 'test1')));
     $metaModel->addAttribute($attribute);
     $config = DefaultConfig::init();
     $config->setFilter(array(array('operation' => '=', 'property' => 'foo', 'value' => 0)));
     $dataBase = Database::getNewTestInstance();
     $builder = new FilterBuilderSql($metaModel->getTableName(), 'AND', $dataBase);
     $dataBase->getQueryCollection()->theQuery('SELECT id FROM mm_test WHERE ((test = ?))')->with(0)->result()->addRows(array(array('id' => 0), array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)));
     $this->assertTrue($builder->isEmpty());
     $this->assertEquals($builder, $builder->addChild(array('operation' => '=', 'property' => 'test', 'value' => 0)));
     $this->assertEquals(array(0, 1, 2, 3, 4, 5), $builder->build()->getMatchingIds());
 }
Exemple #2
0
 /**
  * Add a sub procedure.
  *
  * @param FilterBuilderSql $subProcedure The sub procedure to add.
  *
  * @return FilterBuilderSql
  */
 public function addSubProcedure(FilterBuilderSql $subProcedure)
 {
     $this->procedures[] = $subProcedure->getProcedure();
     $this->parameter = array_merge($this->parameter, $subProcedure->getParameters());
     return $this;
 }
Exemple #3
0
 /**
  * Calculate a native SQL sub procedure.
  *
  * @param FilterBuilderSql $procedure The procedure to which to append to.
  *
  * @param array            $children  The children to calculate.
  *
  * @return array
  */
 protected function buildNativeSqlProcedure(FilterBuilderSql $procedure, $children)
 {
     $skipped = array();
     $metaModel = $this->getMetaModel();
     $tableName = $metaModel->getTableName();
     foreach ($children as $child) {
         // If there is an attribute contained within this rule, skip it.
         if (isset($child['property']) && $metaModel->hasAttribute($child['property'])) {
             $skipped[] = $child;
             continue;
         }
         // Try to parse the sub procedure and extract as much as possible.
         if ($child['operation'] == 'AND' || $child['operation'] == 'OR') {
             $subProcedure = new FilterBuilderSql($tableName, $child['operation'], $this->getDatabase());
             $subSkipped = $this->buildNativeSqlProcedure($subProcedure, $child['children']);
             if (count($subSkipped) !== count($child['operation'])) {
                 $procedure->addSubProcedure($subProcedure);
             }
             if (!empty($subSkipped)) {
                 $skipped += $subSkipped;
             }
             continue;
         }
         $procedure->addChild($child);
     }
     return $skipped;
 }