/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $organization = $this->getReference('default_organization'); for ($i = 0; $i < self::FIXTURES_COUNT; ++$i) { $reporter = $this->getRandomEntity('OroUserBundle:User', $manager); $assignedTo = $this->getRandomEntity('OroUserBundle:User', $manager); $taskPriority = $this->getRandomEntity('OroCRMTaskBundle:TaskPriority', $manager); if (!$reporter || !$taskPriority || !$assignedTo) { // If we don't have users and task statuses we cannot load fixture tasks break; } if ($manager->getRepository('OroCRMTaskBundle:Task')->findOneBySubject(self::$fixtureSubjects[$i])) { // Task with this title is already exist continue; } $task = new Task(); $task->setSubject(self::$fixtureSubjects[$i]); $task->setDescription(self::$fixtureDescriptions[$i]); $dueDate = new \DateTime(); $dueDate->add(new \DateInterval(sprintf('P%dDT%dM', rand(0, 30), rand(0, 1440)))); $task->setDueDate($dueDate); $task->setReporter($reporter); $task->setOwner($assignedTo); $task->setTaskPriority($taskPriority); $task->setOrganization($organization); $contact = $this->getRandomEntity('OroCRMContactBundle:Contact', $manager); if ($contact) { $task->setRelatedContact($contact); } $account = $this->getRandomEntity('OroCRMAccountBundle:Account', $manager); if ($account) { $task->setRelatedAccount($account); } $manager->persist($task); } $manager->flush(); }
/** * @Route("/create", name="orocrm_task_create") * @Acl( * id="orocrm_task_create", * type="entity", * class="OroCRMTaskBundle:Task", * permission="CREATE" * ) * @Template("OroCRMTaskBundle:Task:update.html.twig") */ public function createAction() { $task = new Task(); $defaultPriority = $this->getRepository('OroCRMTaskBundle:TaskPriority')->find('normal'); if ($defaultPriority) { $task->setTaskPriority($defaultPriority); } $accountId = $this->getRequest()->get('accountId'); if ($accountId) { $account = $this->getRepository('OroCRMAccountBundle:Account')->find($accountId); if (!$account) { throw new NotFoundHttpException(sprintf('Account with ID %s is not found', $accountId)); } $task->setRelatedAccount($account); } $contactId = $this->getRequest()->get('contactId'); if ($contactId) { $contact = $this->getRepository('OroCRMContactBundle:Contact')->find($contactId); if (!$contact) { throw new NotFoundHttpException(sprintf('Contact with ID %s is not found', $contactId)); } $task->setRelatedContact($contact); } $assignedToId = $this->getRequest()->get('assignedToId'); if ($assignedToId) { $assignedTo = $this->getRepository('OroUserBundle:User')->find($assignedToId); if (!$assignedTo) { throw new NotFoundHttpException(sprintf('User with ID %s is not found', $assignedToId)); } $task->setOwner($assignedTo); } $reporter = $this->getCurrentUser(); if ($reporter) { $task->setReporter($reporter); } return $this->update($task); }