Beispiel #1
0
 public function editAction($task_id)
 {
     /** @var Request $request */
     $request = $this->container->get('request_stack')->getCurrentRequest();
     $em = $this->getDoctrine()->getManager();
     if ($task_id) {
         $task = $em->getRepository('AcmeEdelaBundle:Task')->find($task_id);
     } else {
         $task = new Task();
         $task->setUser($this->container->get('security.context')->getToken()->getUser());
         if (($parent_id = $request->get('parent_id')) && ($parent = $em->getRepository('AcmeEdelaBundle:Task')->find($parent_id)) && $parent->getUser() == $this->container->get('security.context')->getToken()->getUser()) {
             $task->setParent($parent)->setGoal($parent->getGoal())->setIsPrivate($parent->getIsPrivate());
         }
     }
     $form = $this->createForm(new TaskCreateFormType(), $task);
     $originalNotifications = new ArrayCollection();
     foreach ($task->getNotifications() as $notification) {
         $originalNotifications->add($notification);
     }
     $form->handleRequest($request);
     if ($form->isValid()) {
         foreach ($originalNotifications as $notification) {
             if (false === $task->getNotifications()->contains($notification)) {
                 $em->remove($notification);
             }
         }
         $em->persist($task);
         $em->flush();
     }
     return $this->render('AcmeEdelaBundle:Task:edit.html.twig', array('form' => $form->createView()));
 }