Ejemplo n.º 1
0
 /**
  * setRole
  *
  * @param LifecycleEventArgs $args
  */
 public function setRole(LifeCycleEventArgs $args)
 {
     /** @var User $object */
     $object = $args->getEntity();
     if ($object instanceof AdvancedUserInterface) {
         $object->setRoles(User::ROLE_USER);
     }
 }
Ejemplo n.º 2
0
 /**
  * Remove empty values after persisting, to avoid null 'Value' values in
  * the database.
  *
  * @param LifeCycleEventArgs $args
  *
  * @return void
  */
 public function postPersist(LifeCycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $entityManager = $args->getEntityManager();
     if ($entity instanceof ValueInterface && $entity->isEmpty()) {
         $entityManager->remove($entity);
     }
 }
Ejemplo n.º 3
0
 private function setMaxRootSequence($item, LifeCycleEventArgs $event)
 {
     $em = $event->getEntityManager();
     $qb = $em->createQueryBuilder();
     $maxSequence = $qb->select('MAX(i.rootSequence)')->from(get_class($item), 'i')->getQuery()->getOneOrNullResult();
     $sequenceNext = (int) $maxSequence[1] + 1;
     if (is_null($item->getParent())) {
         $item->setRootSequence($sequenceNext);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist(LifeCycleEventArgs $args)
 {
     /** @var AdvancedUserInterface $object */
     $object = $args->getEntity();
     if ($object instanceof AdvancedUserInterface) {
         $salt = md5(uniqid(null, true));
         $object->setSalt($salt);
         $encoder = $this->encoder->getEncoder($object);
         $encodedPassword = $encoder->encodePassword($object->getPlainPassword(), $object->getSalt());
         $object->setPassword($encodedPassword);
         $object->setLastLogin(new \DateTime(date('Y-m-d H:i:s')));
     }
 }
Ejemplo n.º 5
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist(LifeCycleEventArgs $args)
 {
     /** @var UrlInterface $object */
     $object = $args->getEntity();
     if ($object instanceof UrlInterface) {
         $urlUtility = new UrlUtility();
         $processedUrl = $urlUtility->process($object->getMetaUrl());
         $found = $args->getEntityManager()->getRepository(get_class($object))->findOneBy(['metaUrl' => $processedUrl]);
         if ($found) {
             throw new \LogicException('Given URL already exists');
         }
         $object->setMetaUrl($processedUrl);
     }
 }
Ejemplo n.º 6
0
 /**
  * postPersist
  *
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifeCycleEventArgs $args)
 {
     /** @var Node $parent */
     /** @var Node $object */
     $dm = $args->getDocumentManager();
     $object = $args->getDocument();
     if ($object instanceof NodeInterface) {
         if ($parent = $object->getParent()) {
             $parent->addChild($object);
             $dm->persist($parent);
             $dm->flush();
         }
     }
 }
Ejemplo n.º 7
0
 public function prePersist(LifeCycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof Post || $entity instanceof Comment) {
         // is authentication information available?
         if (null !== $this->tokenStorage->getToken()) {
             // get User
             $user = $this->tokenStorage->getToken()->getUser();
             if (is_object($user)) {
                 $entity->setAuthorEmail($user->getEmail());
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @param LifecycleEventArgs $args
  */
 private function updateChildren(LifeCycleEventArgs $args)
 {
     $dm = $args->getDocumentManager();
     /** @var NodeInterface $object */
     /** @var Category $parent */
     /** @var Category $child */
     $object = $args->getDocument();
     if ($object instanceof NodeInterface) {
         //            var_dump($object->getParent());
         if ($parent = $object->getParent()) {
             foreach ($parent->getChildren() as $child) {
                 if ($child->getId() == $object->getId()) {
                     $parent->removeChild($child);
                 }
             }
             $parent->addChild($object);
             $dm->persist($parent);
             $dm->flush();
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * PreUpdate
  */
 public function preUpdate(LifeCycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $entity->doPreUpdate();
 }