示例#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();
 }
示例#3
0
 public function actionsAction($goal_id)
 {
     $em = $this->getDoctrine()->getManager();
     $goal = $em->getRepository('AcmeEdelaBundle:Goal')->find($goal_id);
     if (!$goal || $goal->getUser() != $this->container->get('security.context')->getToken()->getUser()) {
         throw $this->createNotFoundException('goal.not_found');
     }
     $tasks = $goal->getTasks()->matching(Criteria::create()->where(Criteria::expr()->orX(Criteria::expr()->eq('dateAt', new \DateTime('today midnight')), Criteria::expr()->isNull('dateAt')))->andWhere(Criteria::expr()->isNull('parent')));
     $task = new Task();
     $task->setGoal($goal);
     $addTaskForm = $this->createForm(new TaskCreateShortFormType(), $task, array('action' => $this->generateUrl('tasks_create_short'), 'em' => $em));
     return $this->render('AcmeEdelaBundle:Actions:list.html.twig', array('goal' => $goal, 'addTaskForm' => $addTaskForm->createView(), 'tasks' => $tasks));
 }