/**
  * Create a Task List from the submitted data.<br/>
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Creates a new task list from the submitted data.",
  *   statusCodes = {
  *     201 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="name", nullable=false, strict=true, description="Name.")
  * @RequestParam(name="project_id", nullable=false, strict=true, description="Project id")
  *
  * @return View
  */
 public function postListAction(ParamFetcher $paramFetcher)
 {
     // Check if no list already exists with this name
     $name = $paramFetcher->get('name');
     $listRepository = $this->getDoctrine()->getRepository('CentraleLilleGdpBundle:TaskList');
     $alreadyExists = $listRepository->findOneBy(array('name' => $name));
     if ($alreadyExists) {
         $view = View::create();
         $view->setData(array('error' => 'Name already in use'))->setStatusCode(400);
         return $view;
     }
     $taskList = new TaskList();
     $taskList->setName($name);
     // assign the list to a project
     $projectRepository = $this->getDoctrine()->getRepository('CustomFosUserBundle:Project');
     $projectId = $paramFetcher->get('project_id');
     $project = $projectRepository->find($projectId);
     $taskList->setProject($project);
     $this->existsProjectUser($projectId, $this->getUser()->getId());
     $view = View::create();
     $em = $this->getDoctrine()->getManager();
     $em->persist($taskList);
     $em->flush();
     $view->setData($taskList)->setStatusCode(201);
     return $view;
 }
Exemplo n.º 2
0
 /**
  * Create a Task List from the submitted data.<br/>.
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Creates a new task list from the submitted data.",
  *   statusCodes = {
  *     201 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="name", nullable=false, strict=true, description="Name.")
  * @RequestParam(name="project_id", nullable=false, strict=true, description="Project id")
  *
  * @return View
  */
 public function postListAction(ParamFetcher $paramFetcher)
 {
     $taskListRepository = $this->getDoctrine()->getRepository('CentraleLilleGdpBundle:TaskList');
     $taskList = new TaskList();
     $taskList->setTitle($paramFetcher->get('name'));
     // assign the list to a project
     $projectRepository = $this->getDoctrine()->getRepository('CustomFosUserBundle:Project');
     $projectId = $paramFetcher->get('project_id');
     $project = $projectRepository->find($projectId);
     $taskList->setProject($project);
     $view = View::create();
     $errors = $this->get('validator')->validate($task, array('Registration'));
     if (count($errors) == 0) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($taskList);
         $em->flush();
         $view->setData($taskList)->setStatusCode(201);
         return $view;
     } else {
         $view = $this->getErrorsView($errors);
         return $view;
     }
 }