Exemplo n.º 1
0
 /**
  * @param object|null $relatedEntity
  * @param string|null $query
  * @param Organization|null $organization
  * @param int $limit
  *
  * @return array
  */
 public function getEmailRecipients($relatedEntity = null, $query = null, Organization $organization = null, $limit = 100)
 {
     $emails = [];
     foreach ($this->providers as $provider) {
         if ($limit <= 0) {
             break;
         }
         $args = new EmailRecipientsProviderArgs($relatedEntity, $query, $limit, array_reduce($emails, 'array_merge', []), $organization);
         $recipients = $provider->getRecipients($args);
         if (!$recipients) {
             continue;
         }
         $limit = max([0, $limit - count($recipients)]);
         if (!array_key_exists($provider->getSection(), $emails)) {
             $emails[$provider->getSection()] = [];
         }
         $emails[$provider->getSection()] = array_merge($emails[$provider->getSection()], $recipients);
     }
     $result = [];
     foreach ($emails as $section => $sectionEmails) {
         $items = array_map(function (Recipient $recipient) {
             return $this->emailRecipientsHelper->createRecipientData($recipient);
         }, $sectionEmails);
         $result[] = ['text' => $this->translator->trans($section), 'children' => array_values($items)];
     }
     return $result;
 }
 /**
  * @param object|null $owner
  *
  * @return RecipientEntity|null
  */
 protected function createRecipientEntity($owner = null)
 {
     if (!$owner) {
         return null;
     }
     $metadata = $this->registry->getManager()->getClassMetadata(ClassUtils::getClass($owner));
     return $this->emailRecipientsHelper->createRecipientEntity($owner, $metadata);
 }
 /**
  * {@inheritdoc}
  */
 public function getRecipients(EmailRecipientsProviderArgs $args)
 {
     if (!$args->getRelatedEntity()) {
         return [];
     }
     return EmailRecipientsHelper::filterRecipients($args, $this->relatedEmailsProvider->getRecipients($args->getRelatedEntity(), 2, false, $args->getOrganization()));
 }
 /**
  * {@inheritdoc}
  */
 public function getRecipients(EmailRecipientsProviderArgs $args)
 {
     if (!$args->getRelatedEntity() instanceof Account) {
         return [];
     }
     $customers = $this->getCustomerRepository()->findBy(['account' => $args->getRelatedEntity()]);
     $recipients = [];
     foreach ($customers as $customer) {
         $recipients = array_merge($recipients, EmailRecipientsHelper::filterRecipients($args, $this->relatedEmailsProvider->getRecipients($customer, 2, false, $args->getOrganization())));
     }
     return $recipients;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getRecipients(EmailRecipientsProviderArgs $args)
 {
     if (!$args->getRelatedEntity()) {
         return [];
     }
     $relatedEntity = $args->getRelatedEntity();
     $relatedEntityClass = ClassUtils::getClass($relatedEntity);
     $em = $this->registry->getManagerForClass($relatedEntityClass);
     $metadata = $em->getClassMetadata($relatedEntityClass);
     $idNames = $metadata->getIdentifierFieldNames();
     if (count($idNames) !== 1) {
         return [];
     }
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     $relatedEntityId = $propertyAccessor->getValue($relatedEntity, $idNames[0]);
     $recipients = [];
     $activities = $this->activityManager->getActivities($relatedEntityClass);
     $activityListQb = $this->createActivityListQb($relatedEntityClass, $relatedEntityId);
     $activityListDql = $activityListQb->getQuery()->getDQL();
     $limit = $args->getLimit();
     $activityKeys = array_keys($activities);
     foreach ($activityKeys as $class) {
         $qb = $this->getRepository($class)->createQueryBuilder('e');
         $qb->andWhere($qb->expr()->exists($activityListDql))->setParameter('related_activity_class', $class);
         foreach ($activityListQb->getParameters() as $param) {
             $qb->setParameter($param->getName(), $param->getValue(), $param->getType());
         }
         $iterator = new BufferedQueryResultIterator($qb);
         $iterator->setBufferSize($limit);
         foreach ($iterator as $entity) {
             $recipients = array_merge($recipients, EmailRecipientsHelper::filterRecipients($args, $this->relatedEmailsProvider->getRecipients($entity, 2, false, $args->getOrganization())));
             $limit -= count($recipients);
             if ($limit <= 0) {
                 break 2;
             }
         }
     }
     return $recipients;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function getRecipients(EmailRecipientsProviderArgs $args)
 {
     return $this->emailRecipientsHelper->getRecipients($args, $this->getUserRepository(), 'u', 'Oro\\Bundle\\UserBundle\\Entity\\User');
 }
 /**
  * @dataProvider filterRecipientsDataProvider
  */
 public function testFilterRecipients(EmailRecipientsProviderArgs $args, array $recipients, array $expectedResult)
 {
     $this->assertEquals($expectedResult, EmailRecipientsHelper::filterRecipients($args, $recipients));
 }
Exemplo n.º 8
0
 /**
  * @param $object
  * @param $ignoreAcl
  * @param Organization|null $organization
  * @return bool
  */
 protected function isAccessDenyForOrganization($object, $ignoreAcl, Organization $organization = null)
 {
     return !$ignoreAcl && !$this->emailRecipientsHelper->isObjectAllowedForOrganization($object, $organization);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getRecipients(EmailRecipientsProviderArgs $args)
 {
     return $this->emailRecipientsHelper->getRecipients($args, $this->getContactRepository(), 'c', 'OroCRM\\Bundle\\ContactBundle\\Entity\\Contact');
 }