Example #1
0
 protected function createFilter($name, $conjunction, $context, $private, $user = null)
 {
     $filter = new Filter();
     $filter->setConjunction($conjunction);
     $filter->setContext($context);
     $filter->setChanged(new \DateTime());
     $filter->setCreated(new \DateTime());
     $filter->setPrivate($private);
     $filter->setUser($user);
     $filter->setCreator($this->getTestUser());
     $filter->setChanger($this->getTestUser());
     $trans = new FilterTranslation();
     $trans->setLocale('de');
     $trans->setName($name);
     $trans->setFilter($filter);
     $filter->addTranslation($trans);
     $conditionGroup1 = new ConditionGroup();
     $conditionGroup1->setFilter($filter);
     $conditionGroup1->addCondition($this->createCondition($conditionGroup1, DataTypes::STRING_TYPE, 'test', 'LIKE', 'name'));
     $conditionGroup2 = new ConditionGroup();
     $conditionGroup2->setFilter($filter);
     $conditionGroup2->addCondition($this->createCondition($conditionGroup2, DataTypes::NUMBER_TYPE, '2', '=', 'id'));
     $conditionGroup3 = new ConditionGroup();
     $conditionGroup3->setFilter($filter);
     $conditionGroup3->addCondition($this->createCondition($conditionGroup3, DataTypes::DATETIME_TYPE, '2015-01-01', '>', 'created'));
     $conditionGroup3->addCondition($this->createCondition($conditionGroup3, DataTypes::DATETIME_TYPE, '2015-02-02', '<', 'created'));
     $filter->addConditionGroup($conditionGroup1);
     $filter->addConditionGroup($conditionGroup2);
     $filter->addConditionGroup($conditionGroup3);
     $this->em->persist($filter);
     $this->em->persist($trans);
     $this->em->persist($conditionGroup1);
     $this->em->persist($conditionGroup2);
     $this->em->persist($conditionGroup3);
     return $filter;
 }
Example #2
0
 /**
  * Removes conditions from condition groups when they are not in the given array.
  *
  * @param ConditionGroupEntity $conditionGroup
  * @param array $conditionIds
  */
 protected function removeNonExistentConditions($conditionGroup, $conditionIds)
 {
     foreach ($conditionGroup->getConditions() as $condition) {
         if ($condition->getId() && !in_array($condition->getId(), $conditionIds)) {
             $conditionGroup->removeCondition($condition);
             $this->em->remove($condition);
         }
     }
 }