/** * Update a Task from the submitted data by ID.<br/> * * @ApiDoc( * resource = true, * description = "Updates a task from the submitted data by ID.", * statusCodes = { * 200 = "Returned when successful", * 400 = "Returned when the form has errors" * } * ) * * @param int $taskId TaskId * * @param ParamFetcher $paramFetcher Paramfetcher * * @RequestParam(name="title", nullable=true, strict=true, description="Title.") * @RequestParam(name="body", nullable=true, strict=true, description="Body.") * @RequestParam(name="status", nullable=true, strict=true, description="Status.") * @RequestParam(name="endDate", nullable=true, strict=true, description="End date.") * * @return View */ public function putTaskAction($taskId, ParamFetcher $paramFetcher) { $task = $this->getDoctrine()->getRepository('CentraleLilleGdpBundle:Task')->findOneBy(array('id' => $taskId)); $this->existsProjectUser($task->getProject()->getId(), $this->getUser()->getId()); if ($paramFetcher->get('title')) { $task->setTitle($paramFetcher->get('title')); } if ($paramFetcher->get('body')) { $task->setBody($paramFetcher->get('body')); } if ($paramFetcher->get('status') && TaskStatus::isValidValue($paramFetcher->get('status'))) { $task->setStatus($paramFetcher->get('status')); } if ($paramFetcher->get('endDate')) { $task->setEndDate(new \DateTime(strstr($paramFetcher->get('endDate'), " (", true))); } $view = View::create(); $errors = $this->get('validator')->validate($task, array('Update')); if (count($errors) == 0) { $em = $this->getDoctrine()->getManager(); $em->persist($task); $em->flush(); $view->setData($task)->setStatusCode(200); return $view; } else { $view = $this->getErrorsView($errors); return $view; } }
/** * Set status * * @param boolean $status * * @return Task */ public function setStatus($status) { if (TaskStatus::isValidValue($status)) { $this->status = $status; } return $this; }