/** * @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); } $formAction = $this->get('oro_entity.routing_helper')->generateUrlByRequest('orocrm_task_create', $this->getRequest()); return $this->update($task, $formAction); }
/** * {@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(); }
/** * @param ObjectManager $om * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function persistDemoTasks(ObjectManager $om) { $organization = $this->getReference('default_organization'); $priorities = $om->getRepository('OroCRMTaskBundle:TaskPriority')->findAll(); if (empty($priorities)) { return; } $users = $om->getRepository('OroUserBundle:User')->findAll(); if (empty($users)) { return; } $accounts = $om->getRepository('OroCRMAccountBundle:Account')->findAll(); $contacts = $om->getRepository('OroCRMContactBundle:Contact')->findAll(); for ($i = 0; $i < self::FIXTURES_COUNT; ++$i) { /** @var User $assignedTo */ $assignedTo = $this->getRandomEntity($users); /** @var TaskPriority $taskPriority */ $taskPriority = $this->getRandomEntity($priorities); if ($om->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->setOwner($assignedTo); $task->setTaskPriority($taskPriority); $task->setOrganization($organization); $randomPath = rand(1, 10); if ($randomPath > 2) { $contact = $this->getRandomEntity($contacts); if ($contact) { $this->addActivityTarget($task, $contact); } } if ($randomPath > 3) { $account = $this->getRandomEntity($accounts); if ($account) { $this->addActivityTarget($task, $account); } } if ($randomPath > 4) { $user = $this->getRandomEntity($users); if ($user) { $this->addActivityTarget($task, $user); } } $om->persist($task); } }
/** * @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); }