/** * Process form * * @param Task $entity * * @return bool True on successful processing, false otherwise */ public function process(Task $entity) { $action = $this->entityRoutingHelper->getAction($this->request); $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request); $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request); if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) { $entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId)); FormUtils::replaceField($this->form, 'owner', ['read_only' => true]); } $this->form->setData($entity); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { $this->form->submit($this->request); if ($this->form->isValid()) { // TODO: should be refactored after finishing BAP-8722 // Contexts handling should be moved to common for activities form handler if ($this->form->has('contexts')) { $contexts = $this->form->get('contexts')->getData(); $this->activityManager->setActivityTargets($entity, $contexts); } elseif ($targetEntityClass && $action === 'activity') { // if we don't have "contexts" form field // we should save association between activity and target manually $this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId)); } $this->onSuccess($entity); return true; } } return false; }
public function testGetOwnerId() { $entity = new Task(); $this->assertNull($entity->getOwnerId()); $user = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\User'); $expected = 42; $user->expects($this->once())->method('getId')->will($this->returnValue($expected)); $entity->setOwner($user); $this->assertEquals($expected, $entity->getOwnerId()); }
/** * @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(); }
/** * Process form * * @param Task $entity * * @return bool True on successful processing, false otherwise */ public function process(Task $entity) { $action = $this->entityRoutingHelper->getAction($this->request); $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request); $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request); if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) { $entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId)); FormUtils::replaceField($this->form, 'owner', ['read_only' => true]); } $this->form->setData($entity); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { $this->form->submit($this->request); if ($this->form->isValid()) { if ($targetEntityClass && $action === 'activity') { $this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId)); } $this->onSuccess($entity); return true; } } return false; }
/** * {@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); }