/** * @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()); }
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 ArrayCollection $emails * @param RecipientList $recipientList */ protected function addGroupUsersEmails(ArrayCollection $emails, RecipientList $recipientList) { $groupIds = $recipientList->getGroups()->map(function ($group) { return $group->getId(); })->toArray(); if (!$groupIds) { return; } $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(); array_map(function ($groupEmail) use($emails) { $emails->add($groupEmail['email']); }, $groupUsers); }
/** * Get recipient groups list * * @return ArrayCollection */ public function getRecipientGroupsList() { return $this->recipientList ? $this->recipientList->getGroups() : new ArrayCollection(); }