/** * 添加新任务 * [ * 'urls': * [ * title:"", * host:"", * url:"", * level:"" * ] * ] * @Route("/addtask", name="addtask") * @Method("POST") */ public function addTask(Request $request) { $em = $this->getDoctrine()->getManager(); $data = $this->getData($request); $this->get('logger')->addError('ERROR', $data); // return $this->response(Response::HTTP_OK,implode($data)); // return $this->response(Response::HTTP_OK, $data); //记录Url if (!empty($data['urls'])) { foreach ($data['urls'] as $url) { $urlInfo = parse_url($url['url']); if (!isset($urlInfo['host'])) { continue; } if ($em->getRepository('AppBundle:Task')->findBy(['url' => $url['url']])) { $this->get('logger')->addError('ERROR', $url['url']); continue; } $task = new Task(); $task->setStatus(Task::STATUS_NO_DO); $task->setTitle($url['title']); $task->setDomain($urlInfo['host']); $task->setUrl($url['url']); $task->setLevel($url['level']); $task->setAddtime(time()); $em->persist($task); $em->flush(); } } //记录已经完成 $task = $em->getRepository('AppBundle:Task')->find($data['id']); $task->setStatus(Task::STATUS_DO_SUCCESS); $em->flush(); return $this->response(Response::HTTP_OK, []); }
/** * @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')); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $state = new State(); $state->setName('Ingresado'); $manager->persist($state); $project = new Project(); $project->setName('Project 1'); $manager->persist($project); $parentTask = new Task(); $parentTask->setTitle('Parent task 1'); $parentTask->setDescription('Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat per.'); $parentTask->setPublishedAt(new \DateTime()); $parentTask->setProject($project); $parentTask->setState($state); $manager->persist($parentTask); $timeEntry = new TimeEntry(); $timeEntry->setTask($parentTask); $timeEntry->setDate(new \DateTime()); $timeEntry->setHours(8); $timeEntry->setComment('Lorem ipsum ad his scripta blandit partiendo'); $manager->persist($timeEntry); $manager->flush(); for ($i = 1; $i <= 5; $i++) { $task = new Task(); $task->setTitle('Task ' . $i); $task->setDescription('Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat per.'); $task->setPublishedAt(new \DateTime()); $task->setProject($project); $task->setState($state); $task->setParent($parentTask); $manager->persist($task); } $manager->flush(); $state = new State(); $state->setName('En curso'); $manager->persist($state); $project = new Project(); $project->setName('Project 2'); $manager->persist($project); $parentTask = new Task(); $parentTask->setTitle('Parent task 2'); $parentTask->setDescription('Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat per.'); $parentTask->setPublishedAt(new \DateTime()); $parentTask->setProject($project); $parentTask->setState($state); $manager->persist($parentTask); $timeEntry = new TimeEntry(); $timeEntry->setTask($parentTask); $timeEntry->setDate(new \DateTime()); $timeEntry->setHours(8); $timeEntry->setComment('Lorem ipsum ad his scripta blandit partiendo'); $manager->persist($timeEntry); $manager->flush(); for ($i = $i; $i <= 10; $i++) { $task = new Task(); $task->setTitle('Task ' . $i); $task->setDescription('Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat per.'); $task->setPublishedAt(new \DateTime()); $task->setProject($project); $task->setState($state); $task->setParent($parentTask); $manager->persist($task); } $manager->flush(); $state = new State(); $state->setName('Finalizado'); $manager->persist($state); $project = new Project(); $project->setName('Project 3'); $manager->persist($project); $parentTask = new Task(); $parentTask->setTitle('Parent task 3'); $parentTask->setDescription('Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat per.'); $parentTask->setPublishedAt(new \DateTime()); $parentTask->setProject($project); $parentTask->setState($state); $timeEntry = new TimeEntry(); $timeEntry->setTask($parentTask); $timeEntry->setDate(new \DateTime()); $timeEntry->setHours(8); $timeEntry->setComment('Lorem ipsum ad his scripta blandit partiendo'); $manager->persist($timeEntry); $manager->persist($parentTask); $manager->flush(); for ($i = $i; $i <= 15; $i++) { $task = new Task(); $task->setTitle('Task ' . $i); $task->setDescription('Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat per.'); $task->setPublishedAt(new \DateTime()); $task->setProject($project); $task->setState($state); $task->setParent($parentTask); $manager->persist($task); } $manager->flush(); }