コード例 #1
0
 /**
  * Create a Task from the submitted data.<br/>
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Creates a new task from the submitted data.",
  *   statusCodes = {
  *     201 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param int $id id
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="title", nullable=false, strict=true, description="Title.")
  * @RequestParam(name="body", nullable=false, strict=true, description="Body.")
  * @RequestParam(name="endDate", nullable=false, strict=true, description="End date.")
  * @RequestParam(name="taskList", nullable=false, strict=true, description="Task list containing the task")
  *
  * @return View
  */
 public function postProjectTaskAction($id, ParamFetcher $paramFetcher)
 {
     $this->existsProjectUser($id, $this->getUser()->getId());
     $taskListRepository = $this->getDoctrine()->getRepository('CentraleLilleGdpBundle:TaskList');
     $projectRepository = $this->getDoctrine()->getRepository('CustomFosUserBundle:Project');
     $project = $projectRepository->find($id, $this->getUser()->getId());
     $task = new Task();
     $task->setTitle($paramFetcher->get('title'));
     $task->setBody($paramFetcher->get('body'));
     $task->setAuthor($this->getUser());
     $task->setProject($project);
     $task->setEndDate(new \DateTime(strstr($paramFetcher->get('endDate'), " (", true)));
     $taskList = $taskListRepository->findOneBy(array("id" => $paramFetcher->get('taskList')));
     $task->setTaskList($taskList);
     $taskList->addTask($task);
     $view = View::create();
     $errors = $this->get('validator')->validate($task, array('Registration'));
     if (count($errors) == 0) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($task);
         $em->persist($taskList);
         $em->flush();
         $view->setData($task)->setStatusCode(201);
         return $view;
     } else {
         $view = $this->getErrorsView($errors);
         return $view;
     }
 }
コード例 #2
0
ファイル: TaskController.php プロジェクト: pierloui/fablab
 /**
  * Create a Task from the submitted data.<br/>
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Creates a new task from the submitted data.",
  *   statusCodes = {
  *     201 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="title", nullable=false, strict=true, description="Title.")
  * @RequestParam(name="body", nullable=false, strict=true, description="Body.")
  *
  * @return View
  */
 public function postTaskAction(ParamFetcher $paramFetcher)
 {
     $taskRepository = $this->getDoctrine()->getRepository('CentraleLilleGdpBundle:Task');
     $task = new Task();
     $task->setTitle($paramFetcher->get('title'));
     $task->setBody($paramFetcher->get('body'));
     // TODO get current user
     $task->setAuthor('JunkOS');
     $task->setStatus(false);
     $view = View::create();
     $errors = $this->get('validator')->validate($task, array('Registration'));
     if (count($errors) == 0) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($task);
         $em->flush();
         $view->setData($task)->setStatusCode(201);
         return $view;
     } else {
         $view = $this->getErrorsView($errors);
         return $view;
     }
 }