Пример #1
0
 /**
  * Create a Task from the submitted data.
  *
  * @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="label", nullable=false, strict=true, description="Label.")
  * @RequestParam(name="description", nullable=true, strict=true, description="Description.")
  * @RequestParam(name="categories", nullable=true, strict=true, description="Categories.")
  *
  * @return View
  */
 public function postTaskAction(ParamFetcher $paramFetcher)
 {
     $label = filter_var($paramFetcher->get('label'), FILTER_SANITIZE_STRING);
     $desc = filter_var($paramFetcher->get('description'), FILTER_SANITIZE_STRING);
     $categories = json_decode($paramFetcher->get('categories'));
     $statusCode = 201;
     if (isset($label) && $label != '') {
         $task = new Task();
         $task->setLabel($label);
         $task->setDescription($desc);
         $task->setDate(new \DateTime('now'));
         if (is_array($categories)) {
             foreach ($categories as $cat) {
                 $catId = filter_var($cat, FILTER_SANITIZE_NUMBER_INT);
                 $category = $this->getEntityManager()->getRepository('PocApiBundle:Category')->find($catId);
                 if (is_object($category)) {
                     $task->addCategory($category);
                 }
             }
         }
         $manager = $this->getEntityManager();
         $manager->persist($task);
         $manager->flush();
         $id = $task->getId();
         if (!isset($id)) {
             $statusCode = 400;
         }
     } else {
         $statusCode = 400;
     }
     $view = View::create();
     $view->setData($task)->setStatusCode($statusCode);
     return $view;
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $cat = new Category();
     $cat->setLabel('development');
     $cat->setColor('#01579b');
     //        $manager->persist($cat);
     //        $manager->flush();
     $cat2 = new Category();
     $cat2->setLabel('project');
     $cat2->setColor('#D32F2F');
     $manager->persist($cat2);
     $manager->flush();
     $cat3 = new Category();
     $cat3->setLabel('administrative');
     $cat3->setColor('#43A047');
     $manager->persist($cat3);
     $manager->flush();
     $cat4 = new Category();
     $cat4->setLabel('life');
     $cat4->setColor('#512DA8');
     $manager->persist($cat4);
     $manager->flush();
     $cat5 = new Category();
     $cat5->setLabel('tech');
     $cat5->setColor('#F57C00');
     $manager->persist($cat5);
     $manager->flush();
     $cat6 = new Category();
     $cat6->setLabel('miscellaneous');
     $cat6->setColor('#616161');
     $manager->persist($cat6);
     $manager->flush();
     $cat7 = new Category();
     $cat7->setLabel('professionnal');
     $cat7->setColor('#FFD600');
     $manager->persist($cat7);
     $manager->flush();
     $task = new Task();
     $task->setLabel('Développement projet Todo list');
     $task->setDescription('Dev');
     $task->setDate(new \DateTime('now'));
     $task->setDone(new \DateTime('now'));
     $task->addCategory($cat);
     $manager->persist($task);
     $manager->flush();
     $task2 = new Task();
     $task2->setLabel('Hire a new developer');
     $task2->setDescription('Have a look at http://site.arnaudbouvard.com');
     $task2->setDate(new \DateTime('now'));
     $task2->addCategory($cat2);
     $manager->persist($task2);
     $manager->flush();
     $task3 = new Task();
     $task3->setLabel('Call the bank');
     $task3->setDescription('Review my different products.');
     $task3->setDate(new \DateTime('now'));
     $task3->addCategory($cat3);
     $manager->persist($task3);
     $manager->flush();
     $task4 = new Task();
     $task4->setLabel('Rdv with customer Carmichael');
     $task4->setDescription('Present new software modules.');
     $task4->setDate(new \DateTime('now'));
     $task4->addCategory($cat7);
     $manager->persist($task4);
     $manager->flush();
 }