/** * @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()); }
/** * @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 testSetterGetterForOwner() { $this->assertNull($this->entity->getOwner()); $this->entity->setOwner(true); $this->assertEquals(true, $this->entity->getOwner()); }