/**
  * Apply name formatter to get entity's full name
  *
  * @param mixed $entity
  * @return string
  * @throws \RuntimeException
  */
 protected function getFullName($entity)
 {
     if (!$this->entityNameResolver) {
         throw new \RuntimeException('Name resolver must be configured');
     }
     return $this->entityNameResolver->getName($entity);
 }
 /**
  * @param Calendar $calendar
  *
  * @return string
  */
 protected function buildCalendarName(Calendar $calendar)
 {
     $name = $calendar->getName();
     if (!$name) {
         $name = $this->entityNameResolver->getName($calendar->getOwner());
     }
     return $name;
 }
Example #3
0
 /**
  * @param array  $result
  * @param string $attrName
  * @param User   $user
  */
 protected function addUser(array &$result, $attrName, $user)
 {
     if ($user) {
         $result[$attrName] = $this->entityNameResolver->getName($user);
         $result[$attrName . '_id'] = $user->getId();
         $result[$attrName . '_viewable'] = $this->securityFacade->isGranted('VIEW', $user);
         $avatar = $user->getAvatar();
         $result[$attrName . '_avatar'] = $avatar ? $this->attachmentManager->getFilteredImageUrl($avatar, 'avatar_xsmall') : null;
     }
 }
 /**
  * Gets a list of user's calendars for which it is granted to add events
  *
  * @return array of [id, name]
  */
 public function getUserCalendars()
 {
     /** @var CalendarRepository $repo */
     $repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:Calendar');
     $calendars = $repo->getUserCalendarsQueryBuilder($this->securityFacade->getOrganizationId(), $this->securityFacade->getLoggedUserId())->select('c.id, c.name')->getQuery()->getArrayResult();
     foreach ($calendars as &$calendar) {
         if (empty($calendar['name'])) {
             $calendar['name'] = $this->entityNameResolver->getName($this->securityFacade->getLoggedUser());
         }
     }
     return $calendars;
 }
 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->providerStorage->addProvider($provider);
     $this->entityNameResolver->expects($this->once())->method('getNameDQL')->with(self::TEST_ENTITY, 'owner1')->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
 }
 /**
  * {@inheritdoc}
  */
 public function getData(ActivityList $activityListEntity)
 {
     /** @var Email $email */
     $email = $headEmail = $this->doctrineRegistryLink->getService()->getRepository($activityListEntity->getRelatedActivityClass())->find($activityListEntity->getRelatedActivityId());
     if ($email->isHead() && $email->getThread()) {
         $headEmail = $this->emailThreadProvider->getHeadEmail($this->doctrineHelper->getEntityManager($activityListEntity->getRelatedActivityClass()), $email);
     }
     $data = ['ownerName' => $email->getFromName(), 'ownerLink' => null, 'entityId' => $email->getId(), 'headOwnerName' => $headEmail->getFromName(), 'headSubject' => $headEmail->getSubject(), 'headSentAt' => $headEmail->getSentAt()->format('c'), 'isHead' => $email->isHead() && $email->getThread(), 'treadId' => $email->getThread() ? $email->getThread()->getId() : null];
     if ($email->getThread()) {
         $emails = $email->getThread()->getEmails();
         // if there are just two email - add replayedEmailId to use on client side
         if (count($emails) === 2) {
             $data['replayedEmailId'] = $emails[0]->getId();
         }
     }
     if ($email->getFromEmailAddress()->getHasOwner()) {
         $owner = $email->getFromEmailAddress()->getOwner();
         $data['headOwnerName'] = $data['ownerName'] = $this->entityNameResolver->getName($owner);
         $route = $this->configManager->getEntityMetadata(ClassUtils::getClass($owner))->getRoute('view');
         $securityFacade = $this->securityFacadeLink->getService();
         if (null !== $route && $securityFacade->isGranted('VIEW', $owner)) {
             $id = $this->doctrineHelper->getSingleEntityIdentifier($owner);
             try {
                 $data['ownerLink'] = $this->router->generate($route, ['id' => $id]);
             } catch (RouteNotFoundException $e) {
                 // Do not set owner link if route is not found.
             }
         }
     }
     return $data;
 }
Example #7
0
 /**
  * @param Collection $contacts
  * @param int|null $default
  * @return array
  */
 protected function getInitialElements(Collection $contacts, $default)
 {
     $result = array();
     if ($this->canViewContact) {
         /** @var Contact $contact */
         foreach ($contacts as $contact) {
             if (!$contact->getId()) {
                 continue;
             }
             $primaryPhone = $contact->getPrimaryPhone();
             $primaryEmail = $contact->getPrimaryEmail();
             $result[] = array('id' => $contact->getId(), 'label' => $this->entityNameResolver->getName($contact), 'link' => $this->router->generate('orocrm_contact_info', array('id' => $contact->getId())), 'extraData' => array(array('label' => 'Phone', 'value' => $primaryPhone ? $primaryPhone->getPhone() : null), array('label' => 'Email', 'value' => $primaryEmail ? $primaryEmail->getEmail() : null)), 'isDefault' => $default == $contact->getId());
         }
     }
     return $result;
 }
 /**
  * @param ActivityList $entity
  * @param []           $targetEntityData
  *
  * @return array
  */
 public function getEntityViewModel(ActivityList $entity, $targetEntityData = [])
 {
     $entityProvider = $this->chainProvider->getProviderForEntity($entity->getRelatedActivityClass());
     $activity = $this->doctrineHelper->getEntity($entity->getRelatedActivityClass(), $entity->getRelatedActivityId());
     $ownerName = '';
     $ownerId = '';
     $owner = $entity->getOwner();
     if ($owner) {
         $ownerName = $this->entityNameResolver->getName($owner);
         if ($this->securityFacade->isGranted('VIEW', $owner)) {
             $ownerId = $owner->getId();
         }
     }
     $editorName = '';
     $editorId = '';
     $editor = $entity->getEditor();
     if ($editor) {
         $editorName = $this->entityNameResolver->getName($editor);
         if ($this->securityFacade->isGranted('VIEW', $editor)) {
             $editorId = $editor->getId();
         }
     }
     $isHead = $this->getHeadStatus($entity, $entityProvider);
     $relatedActivityEntities = $this->getRelatedActivityEntities($entity, $entityProvider);
     $numberOfComments = $this->commentManager->getCommentCount($entity->getRelatedActivityClass(), $relatedActivityEntities);
     $data = $entityProvider->getData($entity);
     if (isset($data['isHead']) && !$data['isHead']) {
         $isHead = false;
     }
     $result = ['id' => $entity->getId(), 'owner' => $ownerName, 'owner_id' => $ownerId, 'editor' => $editorName, 'editor_id' => $editorId, 'verb' => $entity->getVerb(), 'subject' => $entity->getSubject(), 'description' => $entity->getDescription(), 'data' => $data, 'relatedActivityClass' => $entity->getRelatedActivityClass(), 'relatedActivityId' => $entity->getRelatedActivityId(), 'createdAt' => $entity->getCreatedAt()->format('c'), 'updatedAt' => $entity->getUpdatedAt()->format('c'), 'editable' => $this->securityFacade->isGranted('EDIT', $activity), 'removable' => $this->securityFacade->isGranted('DELETE', $activity), 'commentCount' => $numberOfComments, 'commentable' => $this->commentManager->isCommentable(), 'targetEntityData' => $targetEntityData, 'is_head' => $isHead];
     return $result;
 }
Example #9
0
 /**
  * Get email address prepared for sending.
  *
  * @param mixed $context
  * @param string|array $data
  *
  * @return string
  */
 protected function getEmailAddress($context, $data)
 {
     $name = null;
     $emailAddress = $this->contextAccessor->getValue($context, $data);
     if (is_array($data)) {
         $emailAddress = $this->contextAccessor->getValue($context, $data['email']);
         if (array_key_exists('name', $data)) {
             $data['name'] = $this->contextAccessor->getValue($context, $data['name']);
             if (is_object($data['name'])) {
                 $name = $this->entityNameResolver->getName($data['name']);
             } else {
                 $name = $data['name'];
             }
         }
     }
     return $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $name);
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function getSenderName()
 {
     $sender = $this->getReminder()->getSender();
     if ($sender) {
         return $this->entityNameResolver->getName($sender);
     }
     return null;
 }
Example #11
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->entityNameResolver->getNameDQL($provider->getEmailOwnerClass(), $relationAlias);
     }
     $expression = '';
     foreach ($expressionsByOwner as $alias => $expressionPart) {
         $expression .= sprintf('WHEN %s.%s IS NOT NULL THEN %s ', $emailFromTableAlias, $alias, $expressionPart);
     }
     $expression = sprintf('CASE %sELSE \'\' 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);
 }
 public function testBuildFullEmailAddress()
 {
     $user = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\User');
     $email = 'email';
     $format = 'format';
     $expected = 'format <email>';
     $user->expects($this->once())->method('getEmail')->willReturn($email);
     $this->entityNameResolver->expects($this->once())->method('getName')->with($user)->willReturn($format);
     $result = $this->helper->buildFullEmailAddress($user);
     $this->assertEquals($expected, $result);
 }
 /**
  * @param ValueRenderEvent $fieldValueEvent
  */
 public function beforeValueRender(ValueRenderEvent $fieldValueEvent)
 {
     $originalValue = $fieldValueEvent->getOriginalValue();
     $metadata = $fieldValueEvent->getMetadata();
     if ($originalValue instanceof AddressInterface) {
         $fieldValueEvent->setConvertedValue($this->addressFormatter->format($originalValue));
     } elseif ($originalValue instanceof NamePrefixInterface || $originalValue instanceof FirstNameInterface || $originalValue instanceof MiddleNameInterface || $originalValue instanceof LastNameInterface || $originalValue instanceof NameSuffixInterface) {
         $fieldValueEvent->setConvertedValue($this->entityNameResolver->getName($originalValue));
     } elseif ($originalValue instanceof \DateTime) {
         $dateType = $metadata->get('render_date_type');
         $timeType = $metadata->get('render_time_type');
         $dateTimePattern = $metadata->get('render_datetime_pattern');
         $fieldValueEvent->setConvertedValue($this->dateTimeFormatter->format($originalValue, $dateType, $timeType, null, null, $dateTimePattern));
     } elseif (is_numeric($originalValue)) {
         $numberStyle = $metadata->get('render_number_style');
         if (!$numberStyle) {
             $numberStyle = 'default_style';
         }
         $fieldValueEvent->setConvertedValue($this->numberFormatter->format($originalValue, $numberStyle));
     }
 }
 public function testGetNameDQLByFallbackFormat()
 {
     $className = 'Test\\Entity';
     $alias = 'entity_alias';
     $format = 'full';
     $locale = 'en_US';
     $expected = $alias . '.field';
     $this->provider1->expects($this->once())->method('getNameDQL')->with($format, $locale, $className, $alias)->willReturn(false);
     $this->provider2->expects($this->at(0))->method('getNameDQL')->with($format, $locale, $className, $alias)->willReturn(false);
     $this->provider2->expects($this->at(1))->method('getNameDQL')->with('short', $locale, $className, $alias)->willReturn($expected);
     $result = $this->entityNameResolver->getNameDQL($className, $alias, $format, $locale);
     $this->assertEquals($expected, $result);
 }
 /**
  * @param array  $result
  * @param object $user
  * @param bool   $addValue
  */
 protected function addUserFullName(array &$result, $user, $addValue)
 {
     if ($user instanceof FullNameInterface) {
         if ($addValue) {
             $val = $this->entityNameResolver->getName($user);
         } else {
             $val = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.user_full_name')];
         }
         $result['userFullName'] = $val;
     } elseif ($addValue) {
         $result['userFullName'] = '';
     }
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function convertItem($user)
 {
     $result = [];
     foreach ($this->fields as $field) {
         $result[$field] = $this->getPropertyValue($field, $user);
     }
     $result['avatar'] = $this->getUserAvatar($user);
     if (!$this->entityNameResolver) {
         throw new \RuntimeException('Name resolver must be configured');
     }
     $result['fullName'] = $this->entityNameResolver->getName($user);
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function getData(ActivityList $activityListEntity)
 {
     /** @var Email $email */
     $email = $headEmail = $this->doctrineRegistryLink->getService()->getRepository($activityListEntity->getRelatedActivityClass())->find($activityListEntity->getRelatedActivityId());
     if ($email->isHead() && $email->getThread()) {
         $headEmail = $this->emailThreadProvider->getHeadEmail($this->doctrineHelper->getEntityManager($activityListEntity->getRelatedActivityClass()), $email);
     }
     $data = ['ownerName' => $email->getFromName(), 'ownerLink' => null, 'entityId' => $email->getId(), 'headOwnerName' => $headEmail->getFromName(), 'headSubject' => $headEmail->getSubject(), 'headSentAt' => $headEmail->getSentAt()->format('c'), 'isHead' => $email->isHead() && $email->getThread(), 'treadId' => $email->getThread() ? $email->getThread()->getId() : null];
     $data = $this->setReplaedEmailId($email, $data);
     if ($email->getFromEmailAddress()->getHasOwner()) {
         $owner = $email->getFromEmailAddress()->getOwner();
         $data['headOwnerName'] = $data['ownerName'] = $this->entityNameResolver->getName($owner);
         $data = $this->setOwnerLink($owner, $data);
     }
     return $data;
 }
Example #18
0
 /**
  * @param Comment $entity
  * @param string  $entityClass
  * @param string  $entityId
  *
  * @return array
  */
 public function getEntityViewModel(Comment $entity, $entityClass = '', $entityId = '')
 {
     $ownerName = '';
     $ownerId = '';
     if ($entity->getOwner()) {
         $ownerName = $this->entityNameResolver->getName($entity->getOwner());
         $ownerId = $entity->getOwner()->getId();
     }
     $editorName = '';
     $editorId = '';
     if ($entity->getUpdatedBy()) {
         $editorName = $this->entityNameResolver->getName($entity->getUpdatedBy());
         $editorId = $entity->getUpdatedBy()->getId();
     }
     $result = ['id' => $entity->getId(), 'owner' => $ownerName, 'owner_id' => $ownerId, 'editor' => $editorName, 'editor_id' => $editorId, 'message' => $entity->getMessage(), 'relationClass' => $entityClass, 'relationId' => $entityId, 'createdAt' => $entity->getCreatedAt()->format('c'), 'updatedAt' => $entity->getUpdatedAt()->format('c'), 'editable' => $this->securityFacade->isGranted('EDIT', $entity), 'removable' => $this->securityFacade->isGranted('DELETE', $entity)];
     $result = array_merge($result, $this->getAttachmentInfo($entity));
     $result = array_merge($result, $this->getCommentAvatarImageUrl($entity->getOwner()));
     return $result;
 }
Example #19
0
 /**
  * Returns a query builder that could be used for fetching the list of entities
  * associated with $associationOwnerClass entities found by $filters and $joins
  *
  * @param string      $associationTargetClass The FQCN of the entity that is the owning side of the association
  * @param mixed|null  $filters                Criteria is used to filter entities which are association owners
  *                                            e.g. ['age' => 20, ...] or \Doctrine\Common\Collections\Criteria
  * @param array|null  $joins                  Additional associations required to filter owning side entities
  * @param array       $associationOwners      The list of fields responsible to store associations between
  *                                            the given target and association owners
  *                                            Array format: [owner_entity_class => field_name]
  * @param int         $limit                  The maximum number of items per page
  * @param int         $page                   The page number
  * @param string|null $orderBy                The ordering expression for the result
  *
  * @return SqlQueryBuilder
  */
 public function getMultiAssociationOwnersQueryBuilder($associationTargetClass, $filters, $joins, $associationOwners, $limit = null, $page = null, $orderBy = null)
 {
     $em = $this->doctrineHelper->getEntityManager($associationTargetClass);
     $criteria = $this->doctrineHelper->normalizeCriteria($filters);
     $selectStmt = null;
     $subQueries = [];
     $targetIdFieldName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($associationTargetClass);
     foreach ($associationOwners as $ownerClass => $fieldName) {
         // dispatch oro_api.request.get_list.before event
         $event = new GetListBefore($this->cloneCriteria($criteria), $associationTargetClass);
         $this->eventDispatcher->dispatch(GetListBefore::NAME, $event);
         $subCriteria = $event->getCriteria();
         $nameExpr = $this->entityNameResolver->getNameDQL($ownerClass, 'e');
         $subQb = $em->getRepository($ownerClass)->createQueryBuilder('e')->select(sprintf('target.%s AS id, e.id AS entityId, \'%s\' AS entityClass, ' . ($nameExpr ?: '\'\'') . ' AS entityTitle', $targetIdFieldName, str_replace('\'', '\'\'', $ownerClass)))->innerJoin('e.' . $fieldName, 'target');
         $this->doctrineHelper->applyJoins($subQb, $joins);
         // fix of doctrine error with Same Field, Multiple Values, Criteria and QueryBuilder
         // http://www.doctrine-project.org/jira/browse/DDC-2798
         // TODO revert changes when doctrine version >= 2.5 in scope of BAP-5577
         QueryBuilderHelper::addCriteria($subQb, $subCriteria);
         // $subQb->addCriteria($criteria);
         $subQuery = $subQb->getQuery();
         $subQueries[] = QueryUtils::getExecutableSql($subQuery);
         if (empty($selectStmt)) {
             $mapping = QueryUtils::parseQuery($subQuery)->getResultSetMapping();
             $selectStmt = sprintf('entity.%s AS id, entity.%s AS entity, entity.%s AS title', QueryUtils::getColumnNameByAlias($mapping, 'entityId'), QueryUtils::getColumnNameByAlias($mapping, 'entityClass'), QueryUtils::getColumnNameByAlias($mapping, 'entityTitle'));
         }
     }
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id', Type::INTEGER)->addScalarResult('entity', 'entity')->addScalarResult('title', 'title');
     $qb = new SqlQueryBuilder($em, $rsm);
     $qb->select($selectStmt)->from('(' . implode(' UNION ALL ', $subQueries) . ')', 'entity');
     if (null !== $limit) {
         $qb->setMaxResults($limit);
         if (null !== $page) {
             $qb->setFirstResult($this->doctrineHelper->getPageOffset($page, $limit));
         }
     }
     if ($orderBy) {
         $qb->orderBy($orderBy);
     }
     return $qb;
 }
Example #20
0
 /**
  * Returns a query builder that could be used for fetching the list of owner side entities
  * the specified $associationTargetClass associated with.
  * The $filters and $joins could be used to filter entities
  *
  * The resulting query would be something like this:
  * <code>
  * SELECT entity.entityId AS id, entity.entityClass AS entity, entity.entityTitle AS title FROM (
  *      SELECT [DISTINCT]
  *          target.id AS id,
  *          e.id AS entityId,
  *          {first_owner_entity_class} AS entityClass,
  *          {first_owner_title} AS entityTitle
  *      FROM {first_owner_entity_class} AS e
  *          INNER JOIN e.{target_field_name_for_first_owner} AS target
  *          {joins}
  *      WHERE {filters}
  *      UNION ALL
  *      SELECT [DISTINCT]
  *          target.id AS id,
  *          e.id AS entityId,
  *          {second_owner_entity_class} AS entityClass,
  *          {second_owner_title} AS entityTitle
  *      FROM {second_owner_entity_class} AS e
  *          INNER JOIN e.{target_field_name_for_second_owner} AS target
  *          {joins}
  *      WHERE {filters}
  *      UNION ALL
  *      ... select statements for other owners
  * ) entity
  * ORDER BY {orderBy}
  * LIMIT {limit} OFFSET {(page - 1) * limit}
  * </code>
  *
  * @param string        $associationTargetClass The FQCN of the entity that is the target side of the association
  * @param mixed|null    $filters                Criteria is used to filter entities which are association owners
  *                                              e.g. ['age' => 20, ...] or \Doctrine\Common\Collections\Criteria
  * @param array|null    $joins                  Additional associations required to filter owning side entities
  * @param array         $associationOwners      The list of fields responsible to store associations between
  *                                              the given target and association owners
  *                                              Array format: [owner_entity_class => field_name]
  * @param int|null      $limit                  The maximum number of items per page
  * @param int|null      $page                   The page number
  * @param string|null   $orderBy                The ordering expression for the result
  * @param callable|null $callback               A callback function which can be used to modify child queries
  *                                              function (QueryBuilder $qb, $ownerEntityClass)
  *
  * @return SqlQueryBuilder
  */
 public function getMultiAssociationOwnersQueryBuilder($associationTargetClass, $filters, $joins, $associationOwners, $limit = null, $page = null, $orderBy = null, $callback = null)
 {
     $em = $this->doctrineHelper->getEntityManager($associationTargetClass);
     $criteria = QueryUtils::normalizeCriteria($filters);
     $selectStmt = null;
     $subQueries = [];
     $targetIdFieldName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($associationTargetClass);
     foreach ($associationOwners as $ownerClass => $fieldName) {
         $nameExpr = $this->entityNameResolver->getNameDQL($ownerClass, 'e');
         $subQb = $em->getRepository($ownerClass)->createQueryBuilder('e')->select(sprintf('target.%s AS id, e.id AS entityId, \'%s\' AS entityClass, ' . ($nameExpr ?: '\'\'') . ' AS entityTitle', $targetIdFieldName, str_replace('\'', '\'\'', $ownerClass)))->innerJoin('e.' . $fieldName, 'target');
         QueryUtils::applyJoins($subQb, $joins);
         $subQb->addCriteria($criteria);
         if (null !== $callback && is_callable($callback)) {
             call_user_func($callback, $subQb, $ownerClass);
         }
         $subQuery = $this->getAclHelper()->apply($subQb);
         $subQueries[] = QueryUtils::getExecutableSql($subQuery);
         if (empty($selectStmt)) {
             $mapping = QueryUtils::parseQuery($subQuery)->getResultSetMapping();
             $selectStmt = sprintf('entity.%s AS id, entity.%s AS entity, entity.%s AS title', QueryUtils::getColumnNameByAlias($mapping, 'entityId'), QueryUtils::getColumnNameByAlias($mapping, 'entityClass'), QueryUtils::getColumnNameByAlias($mapping, 'entityTitle'));
         }
     }
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id', Type::INTEGER)->addScalarResult('entity', 'entity')->addScalarResult('title', 'title');
     $qb = new SqlQueryBuilder($em, $rsm);
     $qb->select($selectStmt)->from('(' . implode(' UNION ALL ', $subQueries) . ')', 'entity');
     if (null !== $limit) {
         $qb->setMaxResults($limit);
         if (null !== $page) {
             $qb->setFirstResult(QueryUtils::getPageOffset($page, $limit));
         }
     }
     if ($orderBy) {
         $qb->orderBy($orderBy);
     }
     return $qb;
 }
 /**
  * Returns a query builder that contains entities from the search result in which titles replaced with
  * text representation of appropriate entities.
  *
  * @todo: This functionality should be removed in the BAP-8995.
  *
  * @param SearchResult $searchResult
  *
  * @return SqlQueryBuilder
  */
 protected function getEmailAssociatedEntitiesQueryBuilder(SearchResult $searchResult)
 {
     /** @var EntityManager $em */
     $em = $this->getObjectManager();
     $selectStmt = null;
     $subQueries = [];
     foreach ($this->getAssociatedEntitiesFilters($searchResult) as $entityClass => $ids) {
         $nameExpr = $this->entityNameResolver->getNameDQL($entityClass, 'e');
         /** @var QueryBuilder $subQb */
         $subQb = $em->getRepository($entityClass)->createQueryBuilder('e')->select(sprintf('e.id AS id, \'%s\' AS entityClass, ' . ($nameExpr ?: '\'\'') . ' AS entityTitle', str_replace('\'', '\'\'', $entityClass)));
         $subQb->where($subQb->expr()->in('e.id', $ids));
         $subQuery = $subQb->getQuery();
         $subQueries[] = QueryUtils::getExecutableSql($subQuery);
         if (empty($selectStmt)) {
             $mapping = QueryUtils::parseQuery($subQuery)->getResultSetMapping();
             $selectStmt = sprintf('entity.%s AS id, entity.%s AS entity, entity.%s AS title', QueryUtils::getColumnNameByAlias($mapping, 'id'), QueryUtils::getColumnNameByAlias($mapping, 'entityClass'), QueryUtils::getColumnNameByAlias($mapping, 'entityTitle'));
         }
     }
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id', Type::INTEGER)->addScalarResult('entity', 'entity')->addScalarResult('title', 'title');
     $qb = new SqlQueryBuilder($em, $rsm);
     $qb->select($selectStmt)->from('(' . implode(' UNION ALL ', $subQueries) . ')', 'entity');
     return $qb;
 }
 /**
  * {@inheritdoc}
  */
 public function getListQueryBuilder($limit = 10, $page = 1, $criteria = [], $orderBy = null, $joins = [])
 {
     $userNameDQL = $this->entityNameResolver->getNameDQL('Oro\\Bundle\\UserBundle\\Entity\\User', 'u');
     $criteria = $this->prepareQueryCriteria($limit ?: null, $page, $criteria, $orderBy);
     return $this->getRepository()->createQueryBuilder('e')->select('e.id, e.invitationStatus, u.email,' . sprintf('%s AS userFullName', $userNameDQL))->join('e.calendar', 'c')->join('c.owner', 'u')->addCriteria($criteria);
 }
 /**
  * @param User $user
  *
  * @return string
  */
 public function buildFullEmailAddress(User $user)
 {
     return $this->emailAddressHelper->buildFullEmailAddress($user->getEmail(), $this->entityNameResolver->getName($user));
 }
Example #24
0
 /**
  * @param User $user
  * @return array
  */
 protected function createUserView(User $user)
 {
     return ['id' => $user->getId(), 'url' => $this->router->generate('oro_user_view', array('id' => $user->getId())), 'fullName' => $this->entityNameResolver->getName($user), 'avatar' => $user->getAvatar() ? $this->attachmentManager->getFilteredImageUrl($user->getAvatar(), 'avatar_xsmall') : null, 'permissions' => array('view' => $this->securityFacade->isGranted('VIEW', $user))];
 }
Example #25
0
 /**
  * Returns a text representation of the given entity.
  *
  * @param object $object
  * @param string $locale
  *
  * @return string
  */
 public function getEntityName($object, $locale = null)
 {
     return $this->entityNameResolver->getName($object, null, $locale);
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $this->contextAccessor->setValue($context, $this->options['attribute'], $this->entityNameResolver->getName($this->contextAccessor->getValue($context, $this->options['object'])));
 }
 /**
  * @param Calendar $calendar
  *
  * @return string
  */
 protected function buildCalendarName(Calendar $calendar)
 {
     return $calendar->getName() ?: $this->entityNameResolver->getName($calendar->getOwner());
 }