Beispiel #1
0
 /**
  * Test add and remove activity owner from ActivityList
  */
 public function testAddRemoveActivityOwner()
 {
     $activity = new ActivityList();
     $activity->setId(1);
     $organization = new Organization();
     $user1 = new User();
     $user1->setId(1);
     $user1->setFirstName('TestUserName1');
     $entity1 = new ActivityOwner();
     $entity1->setActivity($activity);
     $entity1->setUser($user1);
     $entity1->setOrganization($organization);
     $activity->addActivityOwner($entity1);
     $user2 = new User();
     $user1->setId(2);
     $user2->setFirstName('TestUserName2');
     $entity2 = new ActivityOwner();
     $entity2->setActivity($activity);
     $entity2->setUser($user2);
     $entity2->setOrganization($organization);
     $activity->addActivityOwner($entity2);
     $this->assertTrue($activity->getActivityOwners()->contains($entity1));
     $this->assertTrue($activity->getActivityOwners()->contains($entity2));
     $activity->removeActivityOwner($entity1);
     $activity->removeActivityOwner($entity2);
     $this->assertFalse($activity->getActivityOwners()->contains($entity1));
     $this->assertFalse($activity->getActivityOwners()->contains($entity2));
 }
 /**
  * {@inheritdoc}
  */
 public function getData(ActivityList $activityListEntity)
 {
     /** @var Email $email */
     $email = $headEmail = $this->doctrineRegistryLink->getService()->getRepository($activityListEntity->getRelatedActivityClass())->find($activityListEntity->getRelatedActivityId());
     if ($email->isHead() && $email->getThread()) {
         $headEmail = $this->emailThreadProvider->getHeadEmail($this->doctrineHelper->getEntityManager($activityListEntity->getRelatedActivityClass()), $email);
     }
     $data = ['ownerName' => $email->getFromName(), 'ownerLink' => null, 'entityId' => $email->getId(), 'headOwnerName' => $headEmail->getFromName(), 'headSubject' => $headEmail->getSubject(), 'headSentAt' => $headEmail->getSentAt()->format('c'), 'isHead' => $email->isHead() && $email->getThread(), 'treadId' => $email->getThread() ? $email->getThread()->getId() : null];
     $data = $this->setReplaedEmailId($email, $data);
     if ($email->getFromEmailAddress()->getHasOwner()) {
         $owner = $email->getFromEmailAddress()->getOwner();
         $data['headOwnerName'] = $data['ownerName'] = $this->entityNameResolver->getName($owner);
         $data = $this->setOwnerLink($owner, $data);
     }
     return $data;
 }
 /**
  * Set Create and Update fields
  *
  * @param $entity
  * @param ActivityListProviderInterface $provider
  * @param ActivityList $list
  */
 protected function setDate($entity, ActivityListProviderInterface $provider, $list)
 {
     if ($this->hasCustomDate($provider)) {
         $list->setCreatedAt($provider->getDate($entity));
         $list->setUpdatedAt($provider->getDate($entity));
     }
 }
 /**
  * Set Create and Update fields
  *
  * @param $entity
  * @param ActivityListProviderInterface $provider
  * @param ActivityList $list
  */
 protected function setDate($entity, ActivityListProviderInterface $provider, $list)
 {
     if ($provider instanceof ActivityListDateProviderInterface) {
         if ($provider->getCreatedAt($entity)) {
             $list->setCreatedAt($provider->getCreatedAt($entity));
         }
         if ($provider->getUpdatedAt($entity)) {
             $list->setUpdatedAt($provider->getUpdatedAt($entity));
         }
     }
 }
 /**
  * @param ActivityList $entity
  * @param object       $entityProvider
  *
  * @return array
  */
 protected function getRelatedActivityEntities(ActivityList $entity, $entityProvider)
 {
     $relatedActivityEntities = [$entity];
     if ($this->isGroupingApplicable($entityProvider)) {
         $relationEntity = $this->doctrineHelper->getEntity($entity->getRelatedActivityClass(), $entity->getRelatedActivityId());
         $relatedActivityEntities = $entityProvider->getGroupedEntities($relationEntity);
         if (count($relatedActivityEntities) === 0) {
             $relatedActivityEntities = [$entity];
         }
     }
     return $relatedActivityEntities;
 }
 /**
  * @param object                        $entity
  * @param ActivityListProviderInterface $provider
  * @param string                        $verb
  * @param ActivityList|null             $list
  *
  * @return ActivityList
  */
 protected function getActivityListEntityForEntity($entity, ActivityListProviderInterface $provider, $verb = ActivityList::VERB_CREATE, $list = null)
 {
     if ($provider->isApplicable($entity)) {
         if (!$list) {
             $list = new ActivityList();
         }
         $list->setSubject($provider->getSubject($entity));
         $description = $this->htmlTagHelper->stripTags($this->htmlTagHelper->purify($provider->getDescription($entity)));
         $list->setDescription($description);
         if ($this->hasCustomDate($provider)) {
             $list->setCreatedAt($provider->getDate($entity));
             $list->setUpdatedAt($provider->getDate($entity));
         }
         if ($this->hasGrouping($provider)) {
             $list->setHead($provider->isHead($entity));
         }
         $list->setVerb($verb);
         if ($verb === ActivityList::VERB_UPDATE) {
             $activityListTargets = $list->getActivityListTargetEntities();
             foreach ($activityListTargets as $target) {
                 $list->removeActivityListTarget($target);
             }
         } else {
             $className = $this->doctrineHelper->getEntityClass($entity);
             $list->setRelatedActivityClass($className);
             $list->setRelatedActivityId($this->doctrineHelper->getSingleEntityIdentifier($entity));
             $list->setOrganization($provider->getOrganization($entity));
         }
         $targets = $provider->getTargetEntities($entity);
         foreach ($targets as $target) {
             if ($list->supportActivityListTarget($this->doctrineHelper->getEntityClass($target))) {
                 $list->addActivityListTarget($target);
             }
         }
         return $list;
     }
     return null;
 }
 /**
  * {@inheritdoc}
  */
 public function getData(ActivityList $activityListEntity)
 {
     /** @var Email $email */
     $email = $headEmail = $this->doctrineRegistryLink->getService()->getRepository($activityListEntity->getRelatedActivityClass())->find($activityListEntity->getRelatedActivityId());
     if ($email->isHead() && $email->getThread()) {
         $headEmail = $this->emailThreadProvider->getHeadEmail($this->doctrineHelper->getEntityManager($activityListEntity->getRelatedActivityClass()), $email);
     }
     $data = ['ownerName' => $email->getFromName(), 'ownerLink' => null, 'entityId' => $email->getId(), 'headOwnerName' => $headEmail->getFromName(), 'headSubject' => $headEmail->getSubject(), 'headSentAt' => $headEmail->getSentAt()->format('c'), 'isHead' => $email->isHead() && $email->getThread(), 'treadId' => $email->getThread() ? $email->getThread()->getId() : null];
     if ($email->getThread()) {
         $emails = $email->getThread()->getEmails();
         // if there are just two email - add replayedEmailId to use on client side
         if (count($emails) === 2) {
             $data['replayedEmailId'] = $emails[0]->getId();
         }
     }
     if ($email->getFromEmailAddress()->getHasOwner()) {
         $owner = $email->getFromEmailAddress()->getOwner();
         $data['headOwnerName'] = $data['ownerName'] = $this->entityNameResolver->getName($owner);
         $route = $this->configManager->getEntityMetadata(ClassUtils::getClass($owner))->getRoute('view');
         $securityFacade = $this->securityFacadeLink->getService();
         if (null !== $route && $securityFacade->isGranted('VIEW', $owner)) {
             $id = $this->doctrineHelper->getSingleEntityIdentifier($owner);
             try {
                 $data['ownerLink'] = $this->router->generate($route, ['id' => $id]);
             } catch (RouteNotFoundException $e) {
                 // Do not set owner link if route is not found.
             }
         }
     }
     return $data;
 }
 /**
  * Get ActivityOwner entity by ActivityList entity
  *
  * @param ActivityList              $entity
  * @param ActivityListChainProvider $provider
  *
  * @return ActivityOwner[]
  */
 protected function prepareActivityOwnerData($entity, $provider)
 {
     /** @var  DoctrineHelper $helper */
     $helper = $this->container->get('oro_entity.doctrine_helper');
     $relatedActivityEntity = $helper->getEntity($entity->getRelatedActivityClass(), $entity->getRelatedActivityId());
     $entityProvider = $provider->getProviderForEntity($entity->getRelatedActivityClass());
     $activityOwners = $entityProvider->getActivityOwners($relatedActivityEntity, $entity);
     return $activityOwners;
 }
Beispiel #9
0
 public function testIsNotUpdatedFlags()
 {
     $activityList = new ActivityList();
     $activityList->setUpdatedBy(null);
     $activityList->setUpdatedAt(null);
     $this->assertFalse($activityList->isUpdatedBySet());
     $this->assertFalse($activityList->isUpdatedAtSet());
 }
 /**
  * @param ActivityList $entity
  *
  * @return bool
  */
 protected function isDateUpdatable($entity)
 {
     $provider = $this->activityListChainProvider->getProviderByClass($entity->getRelatedActivityClass());
     if ($provider instanceof ActivityListDateProviderInterface) {
         return $provider->isDateUpdatable();
     } else {
         return true;
     }
 }
Beispiel #11
0
 /**
  * @param ActivityListProviderInterface $provider
  * @param object $entity
  * @param ActivityList $activityList
  */
 protected function fillOwners(ActivityListProviderInterface $provider, $entity, ActivityList $activityList)
 {
     $oldActivityOwners = $activityList->getActivityOwners();
     $newActivityOwners = $provider->getActivityOwners($entity, $activityList);
     $newActivityOwners = new ArrayCollection($newActivityOwners);
     foreach ($oldActivityOwners as $oldOwner) {
         if (!$oldOwner->isOwnerInCollection($newActivityOwners)) {
             $activityList->removeActivityOwner($oldOwner);
         }
     }
     if ($newActivityOwners) {
         foreach ($newActivityOwners as $newOwner) {
             if (!$newOwner->isOwnerInCollection($oldActivityOwners)) {
                 $activityList->addActivityOwner($newOwner);
             }
         }
     }
 }
Beispiel #12
0
 public function testToString()
 {
     $obj = new ActivityList();
     $obj->setSubject('test subject');
     $this->assertEquals('test subject', (string) $obj);
 }
 public function testActivityOwner()
 {
     $user = new User();
     $user->setFirstName('First Name');
     $organization = new Organization();
     $organization->setName('Organization One');
     $activityOwner = new ActivityOwner();
     $activityOwner->setUser($user);
     $activityOwner->setOrganization($organization);
     $activityList = new ActivityList();
     $activityList->addActivityOwner($activityOwner);
     $this->assertCount(1, $activityList->getActivityOwners());
     $firstOwner = $activityList->getActivityOwners()->first();
     $this->assertEquals('First Name', $firstOwner->getUser()->getFirstName());
     $this->assertEquals('Organization One', $firstOwner->getOrganization()->getName());
 }