/** * @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); } }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $assignedTo = $manager->getRepository('OroUserBundle:User')->findOneBy(array('username' => 'admin')); if (!$assignedTo) { return; } $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); $task = new Task(); $task->setSubject('Acl task'); $task->setDescription('New description'); $task->setDueDate(new \DateTime()); $task->setOwner($assignedTo); $task->setOrganization($organization); $manager->persist($task); $manager->flush(); }
/** * {@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(); }