当前位置: 首页>>代码示例>>PHP>>正文


PHP ManagerRegistry::getRepository方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\ManagerRegistry::getRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry::getRepository方法的具体用法?PHP ManagerRegistry::getRepository怎么用?PHP ManagerRegistry::getRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\ManagerRegistry的用法示例。


在下文中一共展示了ManagerRegistry::getRepository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getLastSyncDate

 /**
  * @return \DateTime|null
  */
 public function getLastSyncDate()
 {
     $channel = $this->getChannel();
     $repository = $this->managerRegistry->getRepository('OroIntegrationBundle:Status');
     /**
      * @var Status $status
      */
     $status = $repository->findOneBy(['code' => Status::STATUS_COMPLETED, 'channel' => $channel, 'connector' => $this->getType()], ['date' => 'DESC']);
     $timezone = new \DateTimeZone('UTC');
     $date = new \DateTime('now', $timezone);
     $context = $this->getStepExecution()->getExecutionContext();
     $data = $context->get(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY) ?: [];
     $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, array_merge($data, [self::LAST_SYNC_DATE_KEY => $date->format(\DateTime::ISO8601)]));
     if (!$status) {
         return null;
     }
     $data = $status->getData();
     if (empty($data)) {
         return null;
     }
     if (!empty($data[self::LAST_SYNC_DATE_KEY])) {
         return new \DateTime($data[self::LAST_SYNC_DATE_KEY], $timezone);
     }
     return null;
 }
开发者ID:aculvi,项目名称:OroCRMMailChimpBundle,代码行数:28,代码来源:AbstractMailChimpConnector.php

示例2: setUp

 protected function setUp()
 {
     $this->initClient();
     $this->registry = $this->getContainer()->get('doctrine');
     $this->repository = $this->registry->getRepository('OroB2BCatalogBundle:Category');
     $this->loadFixtures(['OroB2B\\Bundle\\CatalogBundle\\Tests\\Functional\\DataFixtures\\LoadCategoryData']);
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:7,代码来源:CategoryRepositoryTest.php

示例3: getNewCustomerChartView

 /**
  * @param ChartViewBuilder $viewBuilder
  * @param array            $dateRange
  *
  * @return ChartView
  */
 public function getNewCustomerChartView(ChartViewBuilder $viewBuilder, $dateRange)
 {
     /** @var CustomerRepository $customerRepository */
     $customerRepository = $this->registry->getRepository('OroCRMMagentoBundle:Customer');
     /** @var ChannelRepository $channelRepository */
     $channelRepository = $this->registry->getRepository('OroCRMChannelBundle:Channel');
     list($past, $now) = $this->dateHelper->getPeriod($dateRange, 'OroCRMMagentoBundle:Customer', 'createdAt');
     $items = [];
     // get all integration channels
     $channels = $channelRepository->getAvailableChannelNames($this->aclHelper, ChannelType::TYPE);
     $channelIds = array_keys($channels);
     $dates = $this->dateHelper->getDatePeriod($past, $now);
     $data = $customerRepository->getGroupedByChannelArray($this->aclHelper, $this->dateHelper, $past, $now, $channelIds);
     foreach ($data as $row) {
         $key = $this->dateHelper->getKey($past, $now, $row);
         $channelId = (int) $row['channelId'];
         $channelName = $channels[$channelId]['name'];
         if (!isset($items[$channelName])) {
             $items[$channelName] = $dates;
         }
         if (isset($items[$channelName][$key])) {
             $items[$channelName][$key]['cnt'] = (int) $row['cnt'];
         }
     }
     // restore default keys
     foreach ($items as $channelName => $item) {
         $items[$channelName] = array_values($item);
     }
     $chartOptions = array_merge_recursive(['name' => 'multiline_chart'], $this->configProvider->getChartConfig('new_web_customers'));
     $chartType = $this->dateHelper->getFormatStrings($past, $now)['viewType'];
     $chartOptions['data_schema']['label']['type'] = $chartType;
     $chartOptions['data_schema']['label']['label'] = sprintf('oro.dashboard.chart.%s.label', $chartType);
     return $viewBuilder->setOptions($chartOptions)->setArrayData($items)->getView();
 }
开发者ID:antrampa,项目名称:crm,代码行数:40,代码来源:CustomerDataProvider.php

示例4: process

 /**
  * {@inheritDoc}
  */
 public function process(DatagridInterface $grid, array $config)
 {
     $this->datagrid = $grid;
     if (isset($config['query'])) {
         $queryConfig = array_intersect_key($config, array_flip(['query']));
         $converter = new YamlConverter();
         $this->qb = $converter->parse($queryConfig, $this->doctrine);
     } elseif (isset($config['entity']) && isset($config['repository_method'])) {
         $entity = $config['entity'];
         $method = $config['repository_method'];
         $repository = $this->doctrine->getRepository($entity);
         if (method_exists($repository, $method)) {
             $qb = $repository->{$method}();
             if ($qb instanceof QueryBuilder) {
                 $this->qb = $qb;
             } else {
                 throw new DatasourceException(sprintf('%s::%s() must return an instance of Doctrine\\ORM\\QueryBuilder, %s given', get_class($repository), $method, is_object($qb) ? get_class($qb) : gettype($qb)));
             }
         } else {
             throw new DatasourceException(sprintf('%s has no method %s', get_class($repository), $method));
         }
     } else {
         throw new DatasourceException(get_class($this) . ' expects to be configured with query or repository method');
     }
     if (isset($config['hints'])) {
         $this->queryHints = $config['hints'];
     }
     $grid->setDatasource(clone $this);
 }
开发者ID:Maksold,项目名称:platform,代码行数:32,代码来源:OrmDatasource.php

示例5: setDefaultOptions

 /**
  * {@inheritDoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('entity_class' => null, 'config_id' => null));
     $resolver->setNormalizers(array('choices' => function (Options $options, $value) {
         if (!empty($value)) {
             return $value;
         }
         $entityClass = $options['entity_class'];
         if (!$entityClass && $options->has('config_id')) {
             $configId = $options['config_id'];
             if ($configId && $configId instanceof ConfigIdInterface) {
                 $entityClass = $configId->getClassName();
             }
         }
         $choices = array();
         if ($entityClass) {
             /** @var WorkflowDefinition[] $definitions */
             $definitions = $this->registry->getRepository('OroWorkflowBundle:WorkflowDefinition')->findBy(array('relatedEntity' => $entityClass));
             foreach ($definitions as $definition) {
                 $name = $definition->getName();
                 $label = $definition->getLabel();
                 $choices[$name] = $label;
             }
         }
         return $choices;
     }));
 }
开发者ID:Maksold,项目名称:platform,代码行数:30,代码来源:WorkflowSelectType.php

示例6: 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 = serialize($serializationCriteria);
     if (empty($this->entities[$entityName]) || empty($this->entities[$entityName][$storageKey])) {
         /** @var EntityRepository $entityRepository */
         $entityRepository = $this->registry->getRepository($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];
 }
开发者ID:northdakota,项目名称:platform,代码行数:31,代码来源:DatabaseHelper.php

示例7: getOrigin

 /**
  * {@inheritdoc}
  */
 public function getOrigin(OriginAwareInterface $originAware)
 {
     if (null === $originAware->getOriginId() || null === $originAware->getOriginType()) {
         return null;
     }
     return $this->manager->getRepository($originAware->getOriginType())->findOneBy(array($this->identifier => $originAware->getOriginId()));
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:10,代码来源:Originator.php

示例8: getRepository

 /**
  * @return PaymentMethodRepository
  */
 public function getRepository()
 {
     if (null === $this->repository) {
         $this->repository = $this->registry->getRepository('CSBillPaymentBundle:PaymentMethod');
     }
     return $this->repository;
 }
开发者ID:csbill,项目名称:csbill,代码行数:10,代码来源:PaymentExtension.php

示例9: reverseTransform

 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!$value) {
         return [];
     }
     /** @var CalendarRepository $calendarRepository */
     $calendarRepository = $this->registry->getRepository('OroCalendarBundle:Calendar');
     $organizationId = $this->securityFacade->getOrganizationId();
     if (!$organizationId) {
         throw new TransformationFailedException('Can\'t get current organization');
     }
     $events = new ArrayCollection();
     /** @var User $user */
     $userIds = [];
     foreach ($value as $user) {
         $userIds[] = $user->getId();
     }
     $calendars = $calendarRepository->findDefaultCalendars($userIds, $organizationId);
     foreach ($calendars as $calendar) {
         $event = new CalendarEvent();
         $event->setCalendar($calendar);
         $events->add($event);
     }
     return $events;
 }
开发者ID:Maksold,项目名称:platform,代码行数:28,代码来源:EventsToUsersTransformer.php

示例10: __construct

 /**
  * @param ManagerRegistry $registry
  * @param ScreenplayProducer $screenplayProducer
  */
 public function __construct(ManagerRegistry $registry, ScreenplayProducer $screenplayProducer)
 {
     parent::__construct();
     $this->languagesRepository = $registry->getRepository(Language::class);
     $this->scenariosRepository = $registry->getRepository(Screenplay::class);
     $this->screenplayProducer = $screenplayProducer;
 }
开发者ID:legendik,项目名称:DwarfSearch,代码行数:11,代码来源:ScreenplayExportCommand.php

示例11: onConsoleTerminate

 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if ($event->getCommand() instanceof UpdateSchemaDoctrineCommand) {
         $output = $event->getOutput();
         $input = $event->getInput();
         if ($input->getOption('force')) {
             $result = $this->fulltextIndexManager->createIndexes();
             $output->writeln('Schema update and create index completed.');
             if ($result) {
                 $output->writeln('Indexes were created.');
             }
         }
     }
     if ($event->getCommand() instanceof UpdateSchemaCommand) {
         $entities = $this->registry->getRepository('OroSearchBundle:UpdateEntity')->findAll();
         if (count($entities)) {
             $em = $this->registry->getManager();
             foreach ($entities as $entity) {
                 $job = new Job(ReindexCommand::COMMAND_NAME, ['class' => $entity->getEntity()]);
                 $em->persist($job);
                 $em->remove($entity);
             }
             $em->flush($job);
         }
     }
 }
开发者ID:northdakota,项目名称:platform,代码行数:29,代码来源:UpdateSchemaDoctrineListener.php

示例12: setSourceEntityName

 /**
  * @param string       $entityName
  * @param Organization $organization
  */
 public function setSourceEntityName($entityName, Organization $organization = null)
 {
     /** @var QueryBuilder $qb */
     $queryBuilder = $this->registry->getRepository($entityName)->createQueryBuilder('o');
     $metadata = $queryBuilder->getEntityManager()->getClassMetadata($entityName);
     foreach (array_keys($metadata->getAssociationMappings()) as $fieldName) {
         // can't join with *-to-many relations because they affects query pagination
         if ($metadata->isAssociationWithSingleJoinColumn($fieldName)) {
             $alias = '_' . $fieldName;
             $queryBuilder->addSelect($alias);
             $queryBuilder->leftJoin('o.' . $fieldName, $alias);
         }
     }
     foreach ($metadata->getIdentifierFieldNames() as $fieldName) {
         $queryBuilder->orderBy('o.' . $fieldName, 'ASC');
     }
     // Limit data with current organization
     if ($organization) {
         $organizationField = $this->ownershipMetadata->getMetadata($entityName)->getOrganizationFieldName();
         if ($organizationField) {
             $queryBuilder->andWhere('o.' . $organizationField . ' = :organization')->setParameter('organization', $organization);
         }
     }
     $this->setSourceQueryBuilder($queryBuilder);
 }
开发者ID:xamin123,项目名称:platform,代码行数:29,代码来源:EntityReader.php

示例13: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $repository = $this->manager->getRepository($options['class']);
     $transformer = new EntityToIdentifierTransformer($repository, $options['identifier']);
     $builder->addModelTransformer($transformer);
     $builder->setAttribute('repository', $repository);
 }
开发者ID:sfblaauw,项目名称:pulsar,代码行数:10,代码来源:EntityHiddenType.php

示例14: getChartData

 /**
  * @param $dateRange array with key start, end and type values is DateTime
  *
  * @return array
  */
 public function getChartData($dateRange)
 {
     $start = $dateRange['start'];
     $end = $dateRange['end'];
     $dates = $items = [];
     $period = new \DatePeriod($start, new \DateInterval('P1M'), $end);
     /** @var \DateTime $dt */
     foreach ($period as $dt) {
         $key = $dt->format('Y-m');
         $dates[$key] = ['month_year' => sprintf('%s-01', $key), 'amount' => 0];
     }
     $endDateKey = $end->format('Y-m');
     if (!in_array($endDateKey, array_keys($dates))) {
         $dates[$endDateKey] = ['month_year' => sprintf('%s-01', $endDateKey), 'amount' => 0];
     }
     $channelNames = $this->registry->getRepository('OroCRMChannelBundle:Channel')->getAvailableChannelNames($this->aclHelper);
     $data = $this->registry->getRepository('OroCRMChannelBundle:LifetimeValueAverageAggregation')->findForPeriod($start, $end, array_keys($channelNames));
     foreach ($data as $row) {
         $key = date('Y-m', strtotime(sprintf('%s-%s', $row['year'], $row['month'])));
         $channelName = $channelNames[$row['channelId']]['name'];
         if (!isset($items[$channelName])) {
             $items[$channelName] = $dates;
         }
         $items[$channelName][$key]['amount'] = (int) $row['amount'];
     }
     // restore default keys
     foreach ($items as $channelName => $item) {
         $items[$channelName] = array_values($item);
     }
     return $items;
 }
开发者ID:antrampa,项目名称:crm,代码行数:36,代码来源:AverageLifetimeWidgetProvider.php

示例15: associationsAction

 /**
  * Display association grids
  *
  * @param Request $request the request
  * @param integer $id      the product id (owner)
  *
  * @AclAncestor("pim_enrich_associations_view")
  *
  * @return Response
  */
 public function associationsAction(Request $request, $id)
 {
     $product = $this->findProductOr404($id);
     $this->productManager->ensureAllAssociationTypes($product);
     $associationTypes = $this->doctrine->getRepository('PimCatalogBundle:AssociationType')->findAll();
     return $this->templating->renderResponse('PimEnrichBundle:Association:_associations.html.twig', array('product' => $product, 'associationTypes' => $associationTypes, 'dataLocale' => $request->get('dataLocale', null)));
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:17,代码来源:AssociationController.php


注:本文中的Doctrine\Common\Persistence\ManagerRegistry::getRepository方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。