/**
  * @param BuildBefore $event
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $config = $event->getConfig();
     /*
      * Add generated entity name DQL to be selected under alias.
      * Aliases billingName and shippingName are added to query this way.
      */
     $config->offsetAddToArrayByPath('source.query.select', [$this->dqlNameFormatter->getFormattedNameDQL('ba', 'Marello\\Bundle\\AddressBundle\\Entity\\Address') . ' as billingName', $this->dqlNameFormatter->getFormattedNameDQL('sa', 'Marello\\Bundle\\AddressBundle\\Entity\\Address') . ' as shippingName']);
 }
예제 #2
0
 /**
  * @param string $emailFromTableAlias EmailAddress table alias of joined Email#fromEmailAddress association
  *
  * @return string
  */
 protected function getFromEmailExpression($emailFromTableAlias)
 {
     $providers = $this->emailOwnerProviderStorage->getProviders();
     if (empty($providers)) {
         return sprintf('%s.email', $emailFromTableAlias);
     }
     $expressionsByOwner = [];
     foreach ($providers as $provider) {
         $relationAlias = $this->emailOwnerProviderStorage->getEmailOwnerFieldName($provider);
         $expressionsByOwner[$relationAlias] = $this->formatter->getFormattedNameDQL($relationAlias, $provider->getEmailOwnerClass());
     }
     $expression = '';
     foreach ($expressionsByOwner as $alias => $expressionPart) {
         $expression .= sprintf('WHEN %s.%s IS NOT NULL THEN %s', $emailFromTableAlias, $alias, $expressionPart);
     }
     $expression = sprintf('CASE %s ELSE \'\' END', $expression);
     // if has owner then use expression to expose formatted name, use email otherwise
     return sprintf('CONCAT(\'\', CASE WHEN %1$s.hasOwner = true THEN (%2$s) ELSE %1$s.email END) as fromEmailExpression', $emailFromTableAlias, $expression);
 }
예제 #3
0
 /**
  * @param EmailRecipientsProviderArgs $args
  * @param EmailAwareRepository $repository
  * @param string $alias
  * @param string $entityClass
  *
  * @return Recipient[]
  */
 public function getRecipients(EmailRecipientsProviderArgs $args, EmailAwareRepository $repository, $alias, $entityClass)
 {
     $fullNameQueryPart = $this->dqlNameFormatter->getFormattedNameDQL($alias, $entityClass);
     $excludedEmailNames = $args->getExcludedEmailNamesForEntity($entityClass);
     $primaryEmailsQb = $repository->getPrimaryEmailsQb($fullNameQueryPart, $excludedEmailNames, $args->getQuery())->setMaxResults($args->getLimit());
     $primaryEmailsResult = $this->getRestrictedResult($primaryEmailsQb, $args);
     $recipients = $this->recipientsFromResult($primaryEmailsResult, $entityClass);
     $limit = $args->getLimit() - count($recipients);
     if ($limit > 0) {
         $excludedEmailNames = array_merge($excludedEmailNames, array_map(function (Recipient $recipient) {
             return $recipient->getBasicNameWithOrganization();
         }, $recipients));
         $secondaryEmailsQb = $repository->getSecondaryEmailsQb($fullNameQueryPart, $excludedEmailNames, $args->getQuery())->setMaxResults($limit);
         $secondaryEmailsResult = $this->getRestrictedResult($secondaryEmailsQb, $args);
         $recipients = array_merge($recipients, $this->recipientsFromResult($secondaryEmailsResult, $entityClass));
     }
     return $recipients;
 }
예제 #4
0
 /**
  * @dataProvider metadataProvider
  *
  * @param string $expectedDQL
  * @param string $nameFormat
  * @param string $className
  */
 public function testGetFormattedNameDQL($expectedDQL, $nameFormat, $className)
 {
     $this->nameFormatter->expects($this->once())->method('getNameFormat')->will($this->returnValue($nameFormat));
     $this->assertEquals($expectedDQL, $this->formatter->getFormattedNameDQL('a', $className));
 }