예제 #1
0
 /**
  * Adds a condition group to the given filter.
  *
  * @param Filter $filter The filter to add the condition group to
  * @param array $conditionGroupData The array containing the data for the additional condition group
  *
  * @return bool
  *
  * @throws EntityIdAlreadySetException
  * @throws FilterDependencyNotFoundException
  */
 protected function addConditionGroup(Filter $filter, $conditionGroupData)
 {
     if (array_key_exists('id', $conditionGroupData)) {
         throw new EntityIdAlreadySetException(self::$conditionGroupEntityName, $conditionGroupData['id']);
     } elseif (array_key_exists('conditions', $conditionGroupData)) {
         $conditionGroup = new ConditionGroupEntity();
         $conditionGroup->setFilter($filter->getEntity());
         foreach ($conditionGroupData['conditions'] as $conditionData) {
             if (array_key_exists('id', $conditionData)) {
                 throw new EntityIdAlreadySetException(self::$conditionEntityName, $conditionData['id']);
             } elseif ($this->isValidConditionData($conditionData)) {
                 $condition = new ConditionEntity();
                 $condition->setType($conditionData['type']);
                 $value = $this->getValueForCondition($conditionData['value'], $conditionData['type']);
                 $condition->setValue($value);
                 $condition->setOperator($conditionData['operator']);
                 $condition->setField($conditionData['field']);
                 $condition->setConditionGroup($conditionGroup);
                 $conditionGroup->addCondition($condition);
                 $conditionGroup->setFilter($filter->getEntity());
                 $this->em->persist($condition);
             }
         }
         $filter->getEntity()->addConditionGroup($conditionGroup);
         $this->em->persist($conditionGroup);
     }
     return true;
 }
예제 #2
0
 /**
  * Set filter.
  *
  * @param Filter $filter
  */
 public function setFilter(Filter $filter)
 {
     $this->entity->setFilter($filter->getEntity());
 }