Example #1
0
 /**
  * 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 testCreate()
 {
     $period = new Period(new \DateTime('2014-12-01'), new \DateTime('2014-12-31'));
     $taskEntity = new TaskEntity();
     $taskEntity->setSubject('Subject');
     $task = new Task($taskEntity, $period);
     $this->assertEquals('Subject', $task->getSubject());
 }
 /**
  * @param \DateTime $dueDate
  * @param int       $remindersCount
  * @return Task
  */
 private function createTask($dueDate, $remindersCount)
 {
     $task = new Task();
     $task->setSubject(uniqid('subject'));
     $task->setDueDate($dueDate);
     $reminders = new ArrayCollection();
     for ($i = 0; $i < $remindersCount; $i++) {
         $reminders->add(new Reminder());
     }
     $task->setReminders($reminders);
     return $task;
 }
 /**
  * {@inheritdoc}
  */
 public function startTracking(User $user, Task $task)
 {
     $tracker = $this->trackerRepository->retrieveUserTracker($user);
     if ($tracker && $tracker->getTask()->getId() === $task->getId()) {
         return;
     }
     if ($tracker) {
         // stop previous tracker
         $this->processStopTracking($tracker);
     }
     $tracker = $this->trackerFactory->create($user, $task);
     $this->trackerRepository->save($tracker);
 }
 public function testCreates()
 {
     $taskEntity = new TaskEntity();
     $taskEntity->setId(1);
     $anotherTaskEntity = new TaskEntity();
     $anotherTaskEntity->setId(2);
     $user = new User();
     $period = new Period(new \DateTime('2014-12-01'), new \DateTime('2014-12-31'));
     $worklogs = new ArrayCollection([new Worklog(new TimeSpent(60), new \DateTime('2014-12-02'), $taskEntity, $user), new Worklog(new TimeSpent(120), new \DateTime('2014-12-03'), $taskEntity, $user), new Worklog(new TimeSpent(180), new \DateTime('2014-12-04'), $anotherTaskEntity, $user)]);
     $taskList = new TaskList($period, $worklogs, new \DateTimeZone('UTC'));
     $this->assertEquals($period, $taskList->getPeriod());
     $this->assertInstanceOf('\\Traversable', $taskList->getIterator());
     $this->assertFalse($taskList->isEmpty());
     $this->assertCount(2, $taskList->getIterator());
     foreach ($taskList as $each) {
         $this->assertInstanceOf('\\RA\\OroCrmTimeLapBundle\\Model\\TimeSheet\\Task', $each);
     }
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * @test
  */
 public function testListAllFilteredByTask()
 {
     $taskId = 1;
     $task = new Task();
     $task->setId($taskId);
     $worklogs = [$this->worklog()];
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with(self::CLASS_NAME)->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('loadAll')->with(['task' => $taskId], null, null, null)->will($this->returnValue($worklogs));
     $result = $this->repository->listAllFilteredByTask($task);
     $this->assertTrue(is_array($result));
     $this->assertEquals($worklogs, $result);
 }
 public function testStartTrackingWhenUserTrackingOtherTask()
 {
     $user = new User();
     $task = new Task();
     $task->setId(1);
     $otherTask = new Task();
     $otherTask->setId(2);
     $waitTimeInSeconds = 2;
     $trackerOfOtherTask = new Tracker($user, $otherTask);
     sleep($waitTimeInSeconds);
     $tracker = new Tracker($user, $task);
     $timeSpent = new TimeSpent($tracker->getSpentSeconds());
     $worklog = new Worklog($timeSpent, $trackerOfOtherTask->getDateStarted(), $trackerOfOtherTask->getTask(), $trackerOfOtherTask->getUser());
     $this->trackerRepository->expects($this->once())->method('retrieveUserTracker')->with($user)->will($this->returnValue($trackerOfOtherTask));
     $this->timeSpentFactory->expects($this->once())->method('create')->with($trackerOfOtherTask->getSpentSeconds())->will($this->returnValue($timeSpent));
     $this->worklogFactory->expects($this->once())->method('create')->with($timeSpent, $trackerOfOtherTask->getDateStarted(), $otherTask, $user)->will($this->returnValue($worklog));
     $this->trackerFactory->expects($this->once())->method('create')->with($user, $task)->will($this->returnValue($tracker));
     $this->trackerRepository->expects($this->once())->method('save')->with($tracker);
     $this->trackerRepository->expects($this->once())->method('removeTracker')->with($trackerOfOtherTask);
     $this->worklogRepository->expects($this->once())->method('save')->with($worklog);
     $this->service->startTracking($user, $task);
 }
Example #9
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $assignedTo = $reporter = $manager->getRepository('OroUserBundle:User')->findOneBy(array('username' => 'admin'));
     if (!$reporter) {
         return;
     }
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $task = new Task();
     $task->setSubject('Acl task');
     $task->setDescription('New description');
     $task->setDueDate(new \DateTime());
     $task->setReporter($reporter);
     $task->setOwner($assignedTo);
     $task->setOrganization($organization);
     $manager->persist($task);
     $manager->flush();
 }
Example #10
0
 /**
  * @param Task   $task
  * @param object $target
  */
 protected function addActivityTarget(Task $task, $target)
 {
     if ($task->supportActivityTarget(get_class($target))) {
         $securityContext = $this->container->get('security.context');
         $user = $task->getOwner();
         $token = new UsernamePasswordOrganizationToken($user, $user->getUsername(), 'main', $this->getReference('default_organization'));
         $securityContext->setToken($token);
         $task->addActivityTarget($target);
     }
 }
Example #11
0
 /**
  * @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);
 }
 /**
  * {@inheritdoc}
  */
 public function listAllFilteredByTask(Task $task)
 {
     return $this->findBy(['task' => $task->getId()]);
 }
Example #13
0
 /**
  * @return string
  */
 public function getSubject()
 {
     return $this->task->getSubject();
 }
Example #14
0
 public function testIsNotUpdatedFlags()
 {
     $task = new Task();
     $task->setUpdatedAt(null);
     $this->assertFalse($task->isUpdatedAtSet());
 }
Example #15
0
 public function testPreUpdate()
 {
     $obj = new Task();
     $this->assertNull($obj->getUpdatedAt());
     $obj->preUpdate();
     $this->assertInstanceOf('\\DateTime', $obj->getUpdatedAt());
 }
Example #16
0
 /**
  * @Route("/update/{id}", name="orocrm_task_update", requirements={"id"="\d+"})
  * @Template
  * @Acl(
  *      id="orocrm_task_update",
  *      type="entity",
  *      class="OroCRMTaskBundle:Task",
  *      permission="EDIT"
  * )
  */
 public function updateAction(Task $task)
 {
     $formAction = $this->get('router')->generate('orocrm_task_update', ['id' => $task->getId()]);
     return $this->update($task, $formAction);
 }
Example #17
0
 /**
  * {@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();
 }