/**
  * @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']);
 }
Ejemplo n.º 2
0
 public function testPrepareQueryOneProviderGiven()
 {
     $provider = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Provider\\EmailOwnerProviderInterface');
     $provider->expects($this->any())->method('getEmailOwnerClass')->will($this->returnValue(self::TEST_ENTITY));
     $this->registry->addProvider($provider);
     $this->formatter->expects($this->once())->method('getFormattedNameDQL')->with($this->equalTo('owner1'), $this->equalTo(self::TEST_ENTITY))->will($this->returnValue(self::TEST_NAME_DQL_FORMATTED));
     $em = $this->getTestEntityManager();
     $qb = $em->createQueryBuilder();
     $qb->select('e')->from('OroEmailBundle:Email', 'e')->leftJoin('e.fromEmailAddress', self::JOIN_ALIAS);
     $this->factory->prepareQuery($qb);
     // @codingStandardsIgnoreStart
     $this->assertEquals("SELECT e, " . "CONCAT('', CASE WHEN a.hasOwner = true THEN (" . "CASE WHEN a.owner1 IS NOT NULL THEN CONCAT(a.firstName, CONCAT(a.lastName, '')) ELSE '' END" . ") ELSE a.email END) as fromEmailExpression " . "FROM OroEmailBundle:Email e LEFT JOIN e.fromEmailAddress a LEFT JOIN a.owner1 owner1", $qb->getDQL());
     // @codingStandardsIgnoreEnd
 }
Ejemplo n.º 3
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);
 }
 /**
  * @param StaticSegment $staticSegment
  *
  * @throws \InvalidArgumentException
  * @return QueryBuilder
  */
 protected function getIteratorQueryBuilder(StaticSegment $staticSegment)
 {
     $marketingList = $staticSegment->getMarketingList();
     $qb = $this->marketingListProvider->getMarketingListEntitiesQueryBuilder($marketingList, MarketingListProvider::FULL_ENTITIES_MIXIN);
     $this->prepareIteratorPart($qb);
     /** @var From[] $from */
     $from = $qb->getDQLPart('from');
     $entityAlias = $from[0]->getAlias();
     $parts = $this->formatter->extractNamePartsPaths($marketingList->getEntity(), $entityAlias);
     $qb->resetDQLPart('select');
     if (isset($parts['first_name'])) {
         $qb->addSelect(sprintf('%s AS %s', $parts['first_name'], MemberSyncDataConverter::FIRST_NAME_KEY));
     }
     if (isset($parts['last_name'])) {
         $qb->addSelect(sprintf('%s AS %s', $parts['last_name'], MemberSyncDataConverter::LAST_NAME_KEY));
     }
     $this->marketingListQueryBuilderAdapter->prepareMarketingListEntities($staticSegment, $qb);
     return $qb;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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));
 }