示例#1
0
 private function buildOrder($field, $direction)
 {
     if (is_array($direction)) {
         throw new InvalidConditionException('wrong direction');
     }
     $direction = StringUtils::toLower($direction);
     if (!in_array($direction, array(self::DIRECTION_ASC, self::DIRECTION_DESC))) {
         throw new InvalidConditionException("Wrong direction");
     }
     if ($this->dispatcher) {
         $this->dispatcher->dispatch(OrderEvent::EVENT_NAME, new OrderEvent($field, $direction));
         $this->dispatcher->dispatch(FieldEvent::EVENT_NAME, new FieldEvent($field));
     }
     return new Order($field, $direction);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function build($conditions = null)
 {
     if (!is_array($conditions)) {
         return $this;
     }
     foreach ($conditions as $key => $values) {
         $key = StringUtils::toLower($key);
         if (!isset(self::$mapping[$key])) {
             continue;
         }
         $className = self::$mapping[$key]['className'];
         /** @var BuilderInterface $builder */
         $builder = $className::{'create'}($values, $this->dispatcher);
         $fieldName = self::$mapping[$key]['field'];
         $this->{$fieldName} = $builder;
     }
     return $this;
 }
 /**
  * @inheritdoc
  * @return ConditionInterface
  * @throws InvalidConditionException
  */
 public function build($conditions = null)
 {
     $condition = StringUtils::toLower($this->compareOperator);
     if ($this->dispatcher) {
         $this->dispatcher->dispatch(OperatorEvent::EVENT_NAME, new OperatorEvent($condition, $this->field, $this->value));
     }
     if ($condition == FilterCondition::CONDITION_EQ && is_array($this->value)) {
         $condition = FilterCondition::CONDITION_IN;
     }
     if (!isset($this->comparesMap[$condition])) {
         throw new InvalidConditionException("Operator doesn't supported");
     }
     if ($this->dispatcher) {
         $this->dispatcher->dispatch(FieldEvent::EVENT_NAME, new FieldEvent($this->field));
     }
     $className = $this->comparesMap[$condition];
     return $className::{'create'}($this->field, $this->value, $this->dispatcher);
 }
示例#4
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;
 }
示例#5
0
 public function __construct($field, $direction)
 {
     $this->field = $field;
     $this->direction = StringUtils::toLower($direction);
 }
 /**
  * @param $group
  * @return $this
  */
 public function setGroup($group)
 {
     $group = StringUtils::toLower($group);
     $this->group = $group;
     return $this;
 }