本文整理汇总了PHP中Oro\Bundle\EntityBundle\ORM\DoctrineHelper::getEntityRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP DoctrineHelper::getEntityRepository方法的具体用法?PHP DoctrineHelper::getEntityRepository怎么用?PHP DoctrineHelper::getEntityRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityBundle\ORM\DoctrineHelper
的用法示例。
在下文中一共展示了DoctrineHelper::getEntityRepository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: discoverSimilar
/**
* @param object $entity
* @return object|null
*/
public function discoverSimilar($entity)
{
if (!$this->configuration) {
return null;
}
$idName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($this->discoveryEntityClass);
$idFieldName = self::ROOT_ALIAS . '.' . $idName;
/** @var EntityRepository $repository */
$repository = $this->doctrineHelper->getEntityRepository($this->discoveryEntityClass);
$qb = $repository->createQueryBuilder(self::ROOT_ALIAS)->select(self::ROOT_ALIAS);
// Apply search strategies
$this->applyStrategies($qb, $entity);
// Apply matcher strategy
if ($this->configuration[Configuration::DISCOVERY_OPTIONS_KEY][Configuration::DISCOVERY_MATCH_KEY] === Configuration::DISCOVERY_MATCH_LATEST) {
$qb->orderBy($idFieldName, Criteria::DESC);
}
// Skip current entity
$id = $this->doctrineHelper->getSingleEntityIdentifier($entity);
if (!empty($id)) {
$idParameter = ':' . $idName;
$qb->andWhere($qb->expr()->neq($idFieldName, $idParameter))->setParameter($idParameter, $id);
}
// Add organization limits
$organizationField = $this->ownershipMetadata->getMetadata(ClassUtils::getClass($entity))->getOrganizationFieldName();
if ($organizationField) {
$propertyAccessor = PropertyAccess::createPropertyAccessor();
$organization = $propertyAccessor->getValue($entity, $organizationField);
$qb->andWhere(sprintf('%s.%s = :organization', self::ROOT_ALIAS, $organizationField))->setParameter('organization', $organization);
}
// Get only 1 match
$qb->setMaxResults(1);
return $qb->getQuery()->getOneOrNullResult();
}
示例2: merge
/**
* {@inheritdoc}
*/
public function merge(FieldData $fieldData)
{
$entityData = $fieldData->getEntityData();
$masterEntity = $entityData->getMasterEntity();
$sourceEntity = $fieldData->getSourceEntity();
if ($masterEntity->getId() !== $sourceEntity->getId()) {
$queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $masterEntity->getId());
$notes = $queryBuilder->getQuery()->getResult();
if (!empty($notes)) {
$entityManager = $this->doctrineHelper->getEntityManager(current($notes));
foreach ($notes as $note) {
$entityManager->remove($note);
}
}
$queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $sourceEntity->getId());
$notes = $queryBuilder->getQuery()->getResult();
if (!empty($notes)) {
foreach ($notes as $note) {
$note->setTarget($masterEntity);
}
}
$fieldMetadata = $fieldData->getMetadata();
$activityClass = $fieldMetadata->get('type');
$entityClass = ClassUtils::getRealClass($sourceEntity);
$queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
$activityListItems = $queryBuilder->getQuery()->getResult();
$activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
$this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
}
}
示例3: findOneBy
/**
* @param string $entityName
* @param array $criteria
* @return object|null
*/
public function findOneBy($entityName, array $criteria)
{
$serializationCriteria = [];
$where = [];
foreach ($criteria as $field => $value) {
if (is_object($value)) {
$serializationCriteria[$field] = $this->getIdentifier($value);
} else {
$serializationCriteria[$field] = $value;
}
$where[] = sprintf('e.%s = :%s', $field, $field);
}
$storageKey = $this->getStorageKey($serializationCriteria);
if (empty($this->entities[$entityName]) || empty($this->entities[$entityName][$storageKey])) {
/** @var EntityRepository $entityRepository */
$entityRepository = $this->doctrineHelper->getEntityRepository($entityName);
$queryBuilder = $entityRepository->createQueryBuilder('e')->andWhere(implode(' AND ', $where))->setParameters($criteria)->setMaxResults(1);
if ($this->shouldBeAddedOrganizationLimits($entityName)) {
$ownershipMetadataProvider = $this->ownershipMetadataProviderLink->getService();
$organizationField = $ownershipMetadataProvider->getMetadata($entityName)->getOrganizationFieldName();
$queryBuilder->andWhere('e.' . $organizationField . ' = :organization')->setParameter('organization', $this->securityFacadeLink->getService()->getOrganization());
}
$this->entities[$entityName][$storageKey] = $queryBuilder->getQuery()->getOneOrNullResult();
}
return $this->entities[$entityName][$storageKey];
}
示例4: getCalendarEvents
/**
* {@inheritdoc}
*/
public function getCalendarEvents($organizationId, $userId, $calendarId, $start, $end, $connections, $extraFields = [])
{
if (!$this->calendarConfig->isSystemCalendarEnabled() || !$this->securityFacade->isGranted('oro_system_calendar_view')) {
return [];
}
//@TODO: temporary return all system calendars until BAP-6566 implemented
///** @var CalendarEventRepository $repo */
//$repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:CalendarEvent');
//$qb = $repo->getSystemEventListByTimeIntervalQueryBuilder(
// $calendarId,
// $start,
// $end,
// []
//);
/** @var CalendarEventRepository $repo */
$repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:CalendarEvent');
$qb = $repo->getSystemEventListByTimeIntervalQueryBuilder($start, $end, [], $extraFields)->andWhere('c.organization = :organizationId')->setParameter('organizationId', $organizationId);
$invisibleIds = [];
foreach ($connections as $id => $visible) {
if (!$visible) {
$invisibleIds[] = $id;
}
}
if (!empty($invisibleIds)) {
$qb->andWhere('c.id NOT IN (:invisibleIds)')->setParameter('invisibleIds', $invisibleIds);
}
return $this->calendarEventNormalizer->getCalendarEvents($calendarId, $qb->getQuery());
}
示例5: applyAdditionalData
/**
* {@inheritdoc}
*/
protected function applyAdditionalData(&$items, $calendarId)
{
$parentEventIds = $this->getParentEventIds($items);
if (!empty($parentEventIds)) {
/** @var CalendarEventRepository $repo */
$repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:CalendarEvent');
$invitees = $repo->getInvitedUsersByParentsQueryBuilder($parentEventIds)->getQuery()->getArrayResult();
$groupedInvitees = [];
foreach ($invitees as $invitee) {
$groupedInvitees[$invitee['parentEventId']][] = $invitee;
}
foreach ($items as &$item) {
$item['invitedUsers'] = [];
if (isset($groupedInvitees[$item['id']])) {
foreach ($groupedInvitees[$item['id']] as $invitee) {
$item['invitedUsers'][] = $invitee['userId'];
}
}
}
} else {
foreach ($items as &$item) {
$item['invitedUsers'] = [];
}
}
}
示例6: onResultAfter
/**
* @param OrmResultAfter $event
*/
public function onResultAfter(OrmResultAfter $event)
{
$currencies = $this->getCurrencies();
if (!$currencies) {
return;
}
/** @var ResultRecord[] $records */
$records = $event->getRecords();
$productIds = [];
foreach ($records as $record) {
$productIds[] = $record->getValue('id');
}
/** @var ProductPriceRepository $priceRepository */
$priceRepository = $this->doctrineHelper->getEntityRepository('OroB2BPricingBundle:ProductPrice');
$priceList = $this->getPriceList();
$showTierPrices = $this->priceListRequestHandler->getShowTierPrices();
$prices = $priceRepository->findByPriceListIdAndProductIds($priceList->getId(), $productIds, $showTierPrices);
$groupedPrices = $this->groupPrices($prices);
foreach ($records as $record) {
$record->addData(['showTierPrices' => $showTierPrices]);
$productId = $record->getValue('id');
$priceContainer = [];
foreach ($currencies as $currencyIsoCode) {
$columnName = $this->buildColumnName($currencyIsoCode);
if (isset($groupedPrices[$productId][$currencyIsoCode])) {
$priceContainer[$columnName] = $groupedPrices[$productId][$currencyIsoCode];
} else {
$priceContainer[$columnName] = [];
}
}
if ($priceContainer) {
$record->addData($priceContainer);
}
}
}
示例7: getJob
/**
* @param string $args
* @param array $states
*
* @return Job[]
*/
public function getJob($args = null, array $states = [])
{
$qb = $this->doctrineHelper->getEntityRepository('JMSJobQueueBundle:Job')->createQueryBuilder('j');
$qb->where($qb->expr()->andX($qb->expr()->eq('j.command', ':command'), $qb->expr()->in('j.state', ':states')))->setParameters(['command' => CalculateAnalyticsCommand::COMMAND_NAME, 'states' => $states ?: [Job::STATE_PENDING]]);
if ($args) {
$qb->andWhere($qb->expr()->like('cast(j.args as text)', ':args'))->setParameter('args', '%' . $args . '%');
} else {
$qb->andWhere($qb->expr()->notLike('cast(j.args as text)', ':args'))->setParameter('args', '%--channel%');
}
return $qb->getQuery()->getResult();
}
示例8: getEnumChoices
/**
* @param string $enumClass = ExtendHelper::buildEnumValueClassName($enumCode);
* @return array
*/
public function getEnumChoices($enumClass)
{
/** @var EnumValueRepository $repository */
$repository = $this->doctrineHelper->getEntityRepository($enumClass);
$values = $repository->getValues();
$result = [];
/** @var AbstractEnumValue $enum */
foreach ($values as $enum) {
$result[$enum->getId()] = $enum->getName();
}
return $result;
}
示例9: hasMarketingList
/**
* @param string $className
* @return bool
*/
public function hasMarketingList($className)
{
if (null === $this->marketingListByEntity) {
$this->marketingListByEntity = [];
$repository = $this->doctrineHelper->getEntityRepository('OroCRMMarketingListBundle:MarketingList');
$qb = $repository->createQueryBuilder('ml')->select('ml.entity')->distinct(true);
$entities = $qb->getQuery()->getArrayResult();
foreach ($entities as $entity) {
$this->marketingListByEntity[$entity['entity']] = true;
}
}
return !empty($this->marketingListByEntity[$className]);
}
示例10: getRemoveAceQueryBuilder
/**
* {@inheritdoc}
*/
public function getRemoveAceQueryBuilder(AclClass $aclClass, array $removeScopes)
{
$qb = $this->doctrineHelper->getEntityRepository('OroSecurityBundle:AclEntry')->createQueryBuilder('ae')->delete();
$qb->where('ae.class = :class');
$qbSub = $this->doctrineHelper->getEntityRepository('OroSecurityBundle:AclSecurityIdentity')->createQueryBuilder('asid')->select('asid.id');
$exprOr = $qbSub->expr()->orX();
foreach ($removeScopes as $scope) {
$this->addExprByShareScope($qbSub, $exprOr, $scope);
}
$qbSub->where($exprOr);
$qb->andWhere($qb->expr()->in('ae.securityIdentity', $qbSub->getDQL()))->setParameter('class', $aclClass);
return $qb;
}
示例11: getCalendarEvents
/**
* {@inheritdoc}
*/
public function getCalendarEvents($organizationId, $userId, $calendarId, $start, $end, $connections, $extraFields = [])
{
if (!$this->myTasksEnabled) {
return [];
}
if ($this->isCalendarVisible($connections, self::MY_TASKS_CALENDAR_ID)) {
/** @var TaskRepository $repo */
$repo = $this->doctrineHelper->getEntityRepository('OroCRMTaskBundle:Task');
$qb = $repo->getTaskListByTimeIntervalQueryBuilder($userId, $start, $end, $extraFields);
$query = $this->aclHelper->apply($qb);
return $this->taskCalendarNormalizer->getTasks(self::MY_TASKS_CALENDAR_ID, $query);
}
return [];
}
示例12: onProductView
/**
* @param BeforeListRenderEvent $event
*/
public function onProductView(BeforeListRenderEvent $event)
{
if (!$this->request) {
return;
}
$productId = $this->request->get('id');
/** @var Product $product */
$product = $this->doctrineHelper->getEntityReference('OroB2BProductBundle:Product', $productId);
/** @var CategoryRepository $repository */
$repository = $this->doctrineHelper->getEntityRepository('OroB2BCatalogBundle:Category');
$category = $repository->findOneByProduct($product);
$template = $event->getEnvironment()->render('OroB2BCatalogBundle:Product:category_view.html.twig', ['entity' => $category]);
$this->addCategoryBlock($event->getScrollData(), $template);
}
示例13: testGetEntityRepositoryNotManageableEntity
public function testGetEntityRepositoryNotManageableEntity()
{
$class = 'ItemStubProxy';
$this->setExpectedException('Oro\\Bundle\\EntityBundle\\Exception\\NotManageableEntityException', sprintf('Entity class "%s" is not manageable', $class));
$this->registry->expects($this->once())->method('getManagerForClass')->with($class)->will($this->returnValue(null));
$this->doctrineHelper->getEntityRepository($class);
}
示例14: getProductRepository
/**
* @return ProductRepository
*/
protected function getProductRepository()
{
if (!$this->productRepository) {
$this->productRepository = $this->doctrineHelper->getEntityRepository($this->productClass);
}
return $this->productRepository;
}
示例15: getCategories
/**
* @param int $channelId
* @param string $type
*
* @return RFMMetricCategory[]
*/
protected function getCategories($channelId, $type)
{
if (array_key_exists($channelId, $this->categories) && array_key_exists($type, $this->categories[$channelId])) {
return $this->categories[$channelId][$type];
}
$categories = $this->doctrineHelper->getEntityRepository('OroCRMAnalyticsBundle:RFMMetricCategory')->findBy(['channel' => $channelId, 'categoryType' => $type], ['categoryIndex' => Criteria::ASC]);
$this->categories[$channelId][$type] = $categories;
return $categories;
}