Ejemplo n.º 1
0
 /**
  * @inheritdoc
  * @return FilterGroupConditionBuilder[]
  */
 public function build($conditions = null)
 {
     $groups = [];
     foreach ($conditions as $groupOperator => $filterData) {
         $group = StringUtils::toLower($groupOperator);
         if (!in_array($group, $this->getAvailableGroups())) {
             $group = FilterCondition::CONDITION_AND;
             $filterData = [$groupOperator => $filterData];
         }
         $conditionBuilder = new FilterGroupConditionBuilder();
         $conditionBuilder->setGroup($group);
         $conditionBuilder->setEventDispatcher($this->dispatcher);
         $conditionBuilder->setConditions($filterData);
         try {
             $groups[] = $conditionBuilder->build();
         } catch (InvalidConditionException $e) {
             continue;
         }
     }
     $this->groups = $groups;
     return $this->groups;
 }
Ejemplo n.º 2
0
 public function testComplex()
 {
     $inputData = ['where' => ['field' => 1, 'field2' => 2, 'field3' => ['field3' => 3, 'field4' => 4], 'field3a' => [3, 4], 'and' => ['field2' => 123, 'field3' => 321, 'field5' => ['Lt' => ['asd', 1, 2, 3]], 'field6' => ['Lt' => 1], 'field7' => ['Lt' => 8], 'field8' => ['Gt' => ['asd', 1, 2, 3]], 'field9' => ['Gt' => 3], 'field10' => ['Gt' => 'ololo']], 'or' => ['field2' => 00, 'field3' => 111, 'field8' => ['Gt' => ['asd', 1, 2, 3]], 'field9' => ['Gt' => 3], 'field10' => ['Gt' => 'ololo'], 'field11' => ['nEq' => ['asd', 1, 2, 3]], 'field12' => ['nEq' => 'asd']], 'like' => ['field15' => 'ololo', 'field16' => 'pewpew'], 'some_piece_of_shit' => ['field4' => 123]], 'limit' => 100520, 'skip' => 45, 'order' => ['field100' => 'AsC', 'field200' => 'DeSc', 'field300' => 'ololo'], 'some_crap' => ['asd' => ['dsfkjldflkjdf' => 1133], 'qwe' => 1133, 'zzzz' => 'dlcvlkj']];
     $builder = new Builder();
     $builder->build($inputData);
     $this->assertEquals(45, $builder->getOffset());
     $this->assertEquals(100520, $builder->getLimit());
     $expectOrders = [new Order('field100', 'asc'), new Order('field200', 'desc')];
     $this->assertEquals($expectOrders, $builder->getOrders());
     /* @var $expectFilters FilterGroupConditionBuilder[] */
     $expectFilters = [FilterGroupConditionBuilder::create('and', ['field' => 1]), FilterGroupConditionBuilder::create('and', ['field2' => 2]), FilterGroupConditionBuilder::create('and', ['field3a' => [3, 4]]), FilterGroupConditionBuilder::create('and', ['field2' => 123, 'field3' => 321, 'field6' => ['lt' => 1], 'field7' => ['lt' => 8], 'field9' => ['gt' => 3]]), FilterGroupConditionBuilder::create('or', ['field2' => 00, 'field3' => 111, 'field9' => ['gt' => 3], 'field11' => ['neq' => ['asd', 1, 2, 3]], 'field12' => ['neq' => 'asd']]), FilterGroupConditionBuilder::create('and', ['field15' => ['like' => 'ololo'], 'field16' => ['like' => 'pewpew']])];
     foreach ($builder->getFilters() as $key => $builder) {
         $this->assertEquals($expectFilters[$key]->getGroup(), $builder->getGroup());
         $this->assertEquals($expectFilters[$key]->getConditions(), $builder->getConditions());
     }
 }