setChanger() 공개 메소드

Sets the changer of the filter.
public setChanger ( Sulu\Component\Security\Authentication\UserInterface $user )
$user Sulu\Component\Security\Authentication\UserInterface The changer of the filter
예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function save(array $data, $locale, $userId, $id = null)
 {
     $user = $this->userRepository->findUserById($userId);
     // TODO SECURITY: Only the user which is referenced by the filter should be allowed to
     // to change the filter - or the administrator
     if ($id) {
         $filter = $this->filterRepository->findByIdAndLocale($id, $locale);
         if (!$filter) {
             throw new FilterNotFoundException($id);
         }
         $filter = new Filter($filter, $locale);
     } else {
         $this->checkData($data, true);
         $filter = new Filter(new FilterEntity(), $locale);
         $filter->setCreated(new \DateTime());
         $filter->setCreator($user);
         $this->em->persist($filter->getEntity());
     }
     // set direct properties and translation
     $filter->setChanged(new \DateTime());
     $filter->setChanger($user);
     $filter->setName($this->getProperty($data, 'name', $filter->getName()));
     if (array_key_exists('context', $data)) {
         if ($this->hasContext($data['context'])) {
             $filter->setContext($data['context']);
         } else {
             throw new UnknownContextException($data['context']);
         }
     }
     if (array_key_exists('private', $data) && $data['private'] === true) {
         $filter->setPrivate($data['private']);
         $filter->setUser($user);
     } else {
         $filter->setPrivate(false);
         $filter->setUser(null);
     }
     $filter->setConjunction($this->getProperty($data, 'conjunction', $filter->getConjunction()));
     $filter->setChanger($user);
     $filter->setChanged(new \DateTime());
     // update condition groups and conditions
     if (isset($data['conditionGroups'])) {
         $get = function (ConditionGroupEntity $conditionGroup) {
             return $conditionGroup->getId();
         };
         $add = function ($conditionGroupData) use($filter) {
             return $this->addConditionGroup($filter, $conditionGroupData);
         };
         $delete = function (ConditionGroupEntity $conditionGroup) use($filter) {
             $this->em->remove($conditionGroup);
             return true;
         };
         $update = function (ConditionGroupEntity $conditionGroup, $matchedEntry) {
             return $this->updateConditionGroup($conditionGroup, $matchedEntry);
         };
         $this->processSubEntities($filter->getEntity()->getConditionGroups(), $data['conditionGroups'], $get, $add, $update, $delete);
     }
     $this->em->flush();
     return $filter;
 }