示例#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()));
 }
示例#2
0
 /**
  * @Rest\View
  * @Rest\Post("/tasks")
  */
 public function postTaskAction(Request $request)
 {
     /** @var Request $request */
     $request = $this->container->get('request_stack')->getCurrentRequest();
     $task = new Task();
     $user = $this->container->get('security.context')->getToken()->getUser();
     $task->setUser($user);
     $form = $this->createForm(new TaskCreateShortFormType(), $task, array('em' => $this->getDoctrine()->getManager(), 'csrf_protection' => false));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($task);
         $em->flush();
         return ['id' => $task->getId(), 'created_at' => $task->getCreatedAt(), 'title' => $task->getName(), 'is_important' => false, 'parent' => $task->getParent() ? $task->getParent()->getId() : 0, 'goal_title' => $task->getGoal() ? $task->getGoal()->getName() : null, 'goal_id' => $task->getGoal() ? $task->getGoal()->getId() : null, 'done' => false, 'is_urgent' => false, 'is_sms_notification' => false, 'notification_time' => $task->getNotificationTime() ? $task->getNotificationTime()->format('H:i') : null, 'date' => $task->getDateAt() ? $task->getDateAt()->format('Y-m-d') : null, 'note' => $task->getNote()];
     }
     return $form->getErrors();
 }