Beispiel #1
0
 /**
  * Add child
  *
  * @param \WikiBundle\Entity\Article $child
  *
  * @return Article
  */
 public function addChild(\WikiBundle\Entity\Article $child)
 {
     // $this->children[] = $child;
     //
     // return $this;
     $child->setParent($this);
     //$this->getChildren()->add($child);
     $this->children[] = $child;
     return $this;
 }
 /**
  * @Route("/wiki/rollback/{slug}", name="wikiBundle_rollback")
  */
 public function rollbackAction($slug)
 {
     if ($this->container->get('security.authorization_checker')->isGranted('ROLE_WIKI_EDITOR')) {
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('WikiBundle:Article')->findOneBySlug($slug);
         if (!$entity) {
             throw $this->createNotFoundException('Unable to find WikiArticle entity.');
         }
         $newEntity = new Article();
         $user = $this->getUser();
         $newEntity->setAuthor($user);
         $newEntity->setBody($entity->getBody());
         $newEntity->setTitle($entity->getTitle());
         $newEntity->setMarkets($entity->getMarkets());
         $newEntity->setAirlines($entity->getAirlines());
         if ($entity->getParent() == null) {
             $entity->getActiveChild()->setCurrent(0);
             $entity->addChild($newEntity);
             //is parent
         } else {
             $entity->getParent()->getActiveChild()->setCurrent(0);
             $entity->getParent()->addChild($newEntity);
         }
         $newEntity->setCurrent(1);
         //Active
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->persist($newEntity);
         $em->flush();
         return $this->render('WikiBundle:Article:rollback.html.twig', array('newEntity' => $newEntity));
     }
 }