/**
  * @param ArrayCollection $emails
  * @param RecipientList   $recipientList
  * @param object          $entity
  * @param string          $ownerPropertyName
  */
 protected function addOwnerEmails(ArrayCollection $emails, RecipientList $recipientList, $entity, $ownerPropertyName)
 {
     // check if owner exists
     if ($recipientList->getOwner() && $ownerPropertyName) {
         $method = 'get' . ucfirst($ownerPropertyName);
         $owner = method_exists($entity, $method) ? $entity->{$method}() : null;
     } else {
         $owner = null;
     }
     if (!is_object($owner) || !$owner instanceof NotificationEmailInterface) {
         return;
     }
     $owner->getNotificationEmails()->map(function ($email) use($emails) {
         $emails->add($email);
     });
 }
 public function testValidData()
 {
     $group = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $user = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\User');
     $context = $this->getMockBuilder('Symfony\\Component\\Validator\\ExecutionContext')->disableOriginalConstructor()->getMock();
     $context->expects($this->never())->method('getPropertyPath');
     $context->expects($this->never())->method('addViolationAt');
     //only users
     $this->entity->addUser($user);
     $this->entity->isValid($context);
     // clear users
     $this->entity->getUsers()->clear();
     //only groups
     $this->entity->addGroup($group);
     $this->entity->isValid($context);
     // clear groups
     $this->entity->getGroups()->clear();
     // only email
     $this->entity->setEmail('test Email');
     $this->entity->isValid($context);
     $this->entity->setEmail(null);
     // only owner
     $this->entity->setOwner(true);
     $this->entity->isValid($context);
     $this->entity->setEmail(null);
 }
 /**
  * @param RecipientList $recipientList
  * @param $entity
  * @return array
  */
 public function getRecipientEmails(RecipientList $recipientList, $entity)
 {
     // get user emails
     $emails = $recipientList->getUsers()->map(function (EmailHolderInterface $user) {
         return $user->getEmail();
     });
     $groupIds = $recipientList->getGroups()->map(function ($group) {
         return $group->getId();
     })->toArray();
     if ($groupIds) {
         $groupUsers = $this->_em->createQueryBuilder()->select('u.email')->from('OroUserBundle:User', 'u')->leftJoin('u.groups', 'groups')->where('groups.id IN (:groupIds)')->setParameter('groupIds', $groupIds)->getQuery()->getResult();
         // add group users emails
         array_map(function ($groupEmail) use($emails) {
             $emails[] = $groupEmail['email'];
         }, $groupUsers);
     }
     // add owner email
     if ($recipientList->getOwner() && $entity instanceof ContainAuthorInterface) {
         $emails[] = $entity->getCreatedBy()->getEmail();
     }
     // add custom email
     if ($recipientList->getEmail()) {
         $emails[] = $recipientList->getEmail();
     }
     return array_unique($emails->toArray());
 }
Example #4
0
 /**
  * Get recipient users list
  *
  * @return ArrayCollection
  */
 public function getRecipientUsersList()
 {
     return $this->recipientList ? $this->recipientList->getUsers() : new ArrayCollection();
 }