示例#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 getActivityOwners($entity, ActivityList $activityList)
 {
     $entity = $this->getEmailEntity($entity);
     $filter = ['email' => $entity];
     $targetEntities = $this->getTargetEntities($entity);
     $organizations = [$this->getOrganization($entity)];
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     foreach ($targetEntities as $target) {
         try {
             $organizations[] = $propertyAccessor->getValue($target, 'organization');
         } catch (\Exception $e) {
             // skipp target
         }
     }
     if (count($organizations) > 0) {
         $filter['organization'] = $organizations;
     }
     $activityArray = [];
     /** @var EmailUser[] $owners */
     $owners = $this->doctrineRegistryLink->getService()->getRepository('OroEmailBundle:EmailUser')->findBy($filter);
     if ($owners) {
         foreach ($owners as $owner) {
             if ($owner->getMailboxOwner() && $owner->getOrganization() || !$owner->getMailboxOwner() && $owner->getOrganization() && $owner->getOwner()) {
                 $activityOwner = new ActivityOwner();
                 $activityOwner->setActivity($activityList);
                 $activityOwner->setOrganization($owner->getOrganization());
                 $user = $owner->getOwner();
                 if (!$owner->getOwner() && $owner->getMailboxOwner()) {
                     $settings = $owner->getMailboxOwner()->getProcessSettings();
                     if ($settings) {
                         $user = $settings->getOwner();
                     }
                 }
                 $activityOwner->setUser($user);
                 $activityArray[] = $activityOwner;
             }
         }
     }
     return $activityArray;
 }
 /**
  * {@inheritdoc}
  */
 public function getActivityOwners($entity, ActivityList $activityList)
 {
     /** @var $entity GitHubIssue */
     $owner = $entity->getOwner();
     if (!$owner) {
         return [];
     }
     $activityOwner = new ActivityOwner();
     $activityOwner->setActivity($activityList);
     $activityOwner->setUser($owner);
     return [$activityOwner];
 }
 /**
  * {@inheritdoc}
  */
 public function getActivityOwners($entity, ActivityList $activityList)
 {
     $organization = $this->getOrganization($entity);
     $owner = $entity->getOwner();
     if (!$organization || !$owner) {
         return [];
     }
     $activityOwner = new ActivityOwner();
     $activityOwner->setActivity($activityList);
     $activityOwner->setOrganization($organization);
     $activityOwner->setUser($owner);
     return [$activityOwner];
 }
示例#5
0
 /**
  * Whether activity list has specified owner
  *
  * @param ActivityOwner $activityOwner
  *
  * @return bool
  */
 public function hasActivityOwner(ActivityOwner $activityOwner)
 {
     /** @var $owner ActivityOwner */
     foreach ($this->getActivityOwners() as $owner) {
         if ($owner->getUser()->getId() === $activityOwner->getUser()->getId() && $owner->getActivity()->getId() === $activityOwner->getActivity()->getId()) {
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function getActivityOwners($entity, ActivityList $activityList)
 {
     $entity = $this->getEmailEntity($entity);
     $filter = ['email' => $entity];
     $organization = $this->getOrganization($entity);
     if ($organization) {
         $filter['organization'] = $organization;
     }
     $activityArray = [];
     $owners = $this->doctrineRegistryLink->getService()->getRepository('OroEmailBundle:EmailUser')->findBy($filter);
     if ($owners) {
         foreach ($owners as $owner) {
             if ($owner->getOrganization() && $owner->getOwner()) {
                 $activityOwner = new ActivityOwner();
                 $activityOwner->setActivity($activityList);
                 $activityOwner->setOrganization($owner->getOrganization());
                 $activityOwner->setUser($owner->getOwner());
                 $activityArray[] = $activityOwner;
             }
         }
     }
     return $activityArray;
 }
示例#7
0
 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());
 }