Example #1
0
 public function load(ObjectManager $manager)
 {
     $obj = new Task();
     $obj->setName("Exemple de tâche pour l'été");
     $obj->setNotes("Cette tâche est créée pour la data fixture. C'est seulement pour la démonstration. Désolé!");
     $obj->setCreatedAt(new \DateTime());
     $obj->setFinished(false);
     $obj->setDueDate(new \DateTime());
     $obj->addTag($this->getReference('tag:home'));
     $obj->addTag($this->getReference('tag:important'));
     $obj->setUser($this->getReference('user:toto'));
     $manager->persist($obj);
     $manager->flush();
 }
Example #2
0
 /**
  * @Route("json/admin/tasks/add", name="json_tasks_add")
  * @Method("POST")
  * @param Request $request
  * @return Response
  */
 public function jsonAddTaskAction(Request $request)
 {
     $task = new Task();
     $task->setTitle($request->request->get('title'));
     $task->setCreatedAt(new DateTime($request->request->get('dateFrom')));
     $task->setFinishDate(new DateTime($request->request->get('dateTo')));
     $task->setDescription($request->request->get('description'));
     $this->get('task_manager')->saveTask($task);
     foreach ($request->request->get('employees') as $employee) {
         $user = $this->get('user_repository')->findByPk($employee);
         $user->addTask($task);
     }
     $this->getDoctrine()->getManager()->flush();
     return new JsonResponse(array('Success'));
 }
 /**
  * @Route("/", name="homepage")
  * @Method({"GET", "POST"})
  */
 public function indexAction(Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $task = new Task();
     $task->setCreatedAt(new \DateTime());
     $form = $this->createFormBuilder($task)->setAction($this->generateUrl('homepage'))->setMethod('POST')->add('task', 'text')->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($task);
         $em->flush();
         $this->addFlash('notice', 'Task added.');
         return $this->redirectToRoute('homepage');
     }
     $tasks = $em->getRepository('AppBundle:Task')->findAll();
     return $this->render('default/index.html.twig', ['form' => $form->createView(), 'tasks' => $tasks]);
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     foreach (range(1, 2) as $s) {
         foreach (range(1, 5) as $i) {
             $task = new Task();
             $task->setProject($this->getReference('project' . $s));
             $task->setName('Project-' . $s . '-Task-' . $i);
             $task->setStatus('Pending');
             $task->setDescription('Some brief project description to go here.');
             $task->setUserId($s);
             $task->setCreatedAt(new \DateTime('now'));
             $task->setUpdatedAt(new \DateTime('now'));
             $date = new \DateTime('now');
             $duedate = $date->add(new \DateInterval('P30D'));
             $task->setDueDate($duedate);
             $manager->persist($task);
         }
     }
     $manager->flush();
 }