• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Collections\Criteria类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\Common\Collections\Criteria的典型用法代码示例。如果您正苦于以下问题:PHP Criteria类的具体用法?PHP Criteria怎么用?PHP Criteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: applyFilter

 /**
  * @param Request         $request
  * @param FilterInterface $filter
  * @param Criteria        $criteria
  * @param ClassMetadata   $embedClassMeta
  *
  * @return null
  */
 protected function applyFilter(Request $request, FilterInterface $filter, Criteria $criteria, ClassMetadata $embedClassMeta)
 {
     $properties = $filter->getRequestProperties($request);
     if ($filter instanceof OrderFilter && !empty($properties)) {
         $criteria->orderBy($properties);
         return null;
     }
     if ($filter instanceof SearchFilter) {
         foreach ($properties as $name => $propertie) {
             if (in_array($name, $embedClassMeta->getIdentifier())) {
                 continue;
             }
             $expCriterial = Criteria::expr();
             if ($embedClassMeta->hasAssociation($name)) {
                 $associationTargetClass = $embedClassMeta->getAssociationTargetClass($name);
                 $propertyResource = $this->resourceResolver->getResourceForEntity($associationTargetClass);
                 $propertyObj = $this->dataProviderChain->getItem($propertyResource, (int) $propertie['value'], true);
                 if ($propertyObj && $propertyResource instanceof ResourceInterface) {
                     $whereCriteria = $expCriterial->in($name, [$propertyObj]);
                     $criteria->where($whereCriteria);
                 }
             } else {
                 if ($embedClassMeta->hasField($name)) {
                     $fieldMapping = $embedClassMeta->getFieldMapping($name);
                     $type = isset($fieldMapping['type']) ? $fieldMapping['type'] : null;
                     $value = isset($this->mappingFilterVar[$type]) ? filter_var($propertie['value'], $this->mappingFilterVar[$type]) : $propertie['value'];
                     $whereCriteria = isset($propertie['precision']) && $propertie['precision'] === 'exact' ? $expCriterial->eq($name, $value) : $expCriterial->contains($name, $propertie['value']);
                     $criteria->where($whereCriteria);
                 }
             }
         }
     }
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:41,代码来源:ApplyCriteriaEmbed.php


示例2: createCriteria

 private function createCriteria()
 {
     $criteria = new Criteria();
     $criteria->orderBy(array('username' => 'ASC'));
     $criteria->setFirstResult(2);
     $criteria->setMaxResults(3);
     return $criteria;
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:8,代码来源:DoctrineSelectableAdapterTest.php


示例3: generateMenu

 protected function generateMenu()
 {
     $criteria = new Criteria();
     $criteria->orderBy(['hierarchy' => 'asc']);
     $collection = $this->adminMenuRepository->matching($criteria);
     $elements = $this->filterElements($collection, null);
     $tree = $this->generateTree($collection, $elements);
     return $tree;
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:9,代码来源:AdminMenuProvider.php


示例4: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Criteria $criteria, FilterValue $value = null)
 {
     $val = null !== $value ? $value->getValue() : $this->getDefaultValue();
     if (!empty($val)) {
         $criteria->orderBy($val);
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:10,代码来源:SortFilter.php


示例5: findEmailsByIds

 /**
  * Gets emails by ids
  *
  * @param int[] $ids
  *
  * @return Email[]
  */
 public function findEmailsByIds($ids)
 {
     $queryBuilder = $this->createQueryBuilder('e');
     $criteria = new Criteria();
     $criteria->where(Criteria::expr()->in('id', $ids));
     $criteria->orderBy(['sentAt' => Criteria::DESC]);
     $queryBuilder->addCriteria($criteria);
     $result = $queryBuilder->getQuery()->getResult();
     return $result;
 }
开发者ID:olegpopadko,项目名称:platform,代码行数:17,代码来源:EmailRepository.php


示例6: getMenu

 public function getMenu()
 {
     $criteria = new Criteria();
     $criteria->orderBy(['hierarchy' => 'asc']);
     $criteria->andWhere($criteria->expr()->eq('parent', null));
     return $this->adminMenuRepository->matching($criteria);
 }
开发者ID:Sywooch,项目名称:WellCommerce,代码行数:7,代码来源:AdminMenuProvider.php


示例7: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->neq('xThreadId', null));
     /** @var QueryBuilder $threadQueryBuilder */
     $threadQueryBuilder = $manager->getRepository('OroEmailBundle:Email')->createQueryBuilder('entity');
     $threadQueryBuilder->distinct()->select('entity.xThreadId');
     $threadQueryBuilder->addCriteria($criteria);
     $iterator = new BufferedQueryResultIterator($threadQueryBuilder);
     $iterator->setBufferSize(self::BATCH_SIZE);
     $itemsCount = 0;
     $entities = [];
     foreach ($iterator as $threadResult) {
         $threadId = $threadResult['xThreadId'];
         /** @var QueryBuilder $queryBuilder */
         $queryBuilder = $manager->getRepository('OroEmailBundle:Email')->createQueryBuilder('entity');
         $criteria = new Criteria();
         $criteria->where($criteria->expr()->eq('xThreadId', $threadId));
         $criteria->orderBy(['created' => 'ASC']);
         $queryBuilder->addCriteria($criteria);
         $queryBuilder->setFirstResult(0);
         $emails = $queryBuilder->getQuery()->execute();
         if (count($emails) > 1) {
             $itemsCount++;
             $newThread = new EmailThread();
             $manager->persist($newThread);
             foreach ($emails as $key => $email) {
                 /** @var Email $email */
                 if ($key == 0) {
                     $email->setHead(true);
                 } else {
                     $email->setHead(false);
                 }
                 $email->setThread($newThread);
                 $entities[] = $email;
             }
         } elseif (count($emails) == 1) {
             $email = $emails[0];
             $email->setHead(true);
             $itemsCount++;
             $entities[] = $email;
         }
         if (0 == $itemsCount % self::BATCH_SIZE) {
             $this->saveEntities($manager, $entities);
             $entities = [];
         }
     }
     if ($itemsCount % self::BATCH_SIZE > 0) {
         $this->saveEntities($manager, $entities);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:54,代码来源:AddEmailActivityGrouping.php


示例8: getShippingMethods

 /**
  * {@inheritdoc}
  */
 public function getShippingMethods() : Collection
 {
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('enabled', true));
     $criteria->orderBy(['hierarchy' => 'asc']);
     $methods = $this->matching($criteria)->filter(function (ShippingMethodInterface $shippingMethod) {
         $paymentMethodsCount = $shippingMethod->getPaymentMethods()->count();
         $shippingMethodCostCount = $shippingMethod->getCosts()->count();
         return $paymentMethodsCount > 0 && $shippingMethodCostCount > 0;
     });
     return $methods;
 }
开发者ID:WellCommerce,项目名称:ShippingBundle,代码行数:15,代码来源:ShippingMethodRepository.php


示例9: createService

 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $entityManager = $serviceLocator->get('entity-manager');
     $languageEntity = $serviceLocator->get('lang-entity');
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->gt('status', 0))->orderBy(['status' => Criteria::DESC]);
     $language = new \Application\Service\Invokable\Language();
     $languageClassName = get_class($languageEntity);
     $activeLanguages = $entityManager->getRepository($languageClassName)->matching($criteria);
     $language->setActiveLanguages($activeLanguages);
     $defaultLanguage = $entityManager->getRepository($languageClassName)->findOneByStatus(Lang::STATUS_DEFAULT);
     $defaultLanguage = $defaultLanguage ?: new Lang();
     $language->setDefaultLanguage($defaultLanguage);
     $request = $serviceLocator->get('Request');
     $router = $serviceLocator->get('Router');
     $match = $router->match($request);
     if ($match) {
         $matchedLangIso = $match->getParam('lang', $defaultLanguage->getIsoCode());
         if ($matchedLangIso) {
             $currentLanguage = $entityManager->getRepository($languageClassName)->findOneByIsoCode($matchedLangIso);
         }
     }
     $currentLanguage = isset($currentLanguage) ? $currentLanguage : new Lang();
     $language->setCurrentLanguage($currentLanguage);
     return $language;
 }
开发者ID:veniva,项目名称:zcms,代码行数:26,代码来源:Language.php


示例10: findByTag

 public function findByTag($tagstring)
 {
     $criteria = new Criteria();
     $criteria->andWhere(Criteria::expr()->contains('t.name', "%" . $tagstring . "%"));
     $queryBuilder = $this->_em->createQueryBuilder()->select('p')->distinct(true)->from($this->getEntityName(), "p")->leftJoin('Product\\Entity\\ProductTags', 'pt', \Doctrine\ORM\Query\Expr\Join::WITH, 'p.id = pt.idProduct')->leftJoin('Product\\Entity\\Tags', 't', \Doctrine\ORM\Query\Expr\Join::WITH, 't.id = pt.idTag')->addCriteria($criteria)->orderBy("p.creationdate", "ASC")->getQuery();
     return $queryBuilder->getArrayResult();
 }
开发者ID:89snake89,项目名称:PHPTest,代码行数:7,代码来源:ProductRepository.php


示例11: testMatchingAcceptsCriteriaWithNullWhereExpression

 public function testMatchingAcceptsCriteriaWithNullWhereExpression()
 {
     $repository = $this->dm->getRepository('Documents\\User');
     $criteria = new Criteria();
     $this->assertNull($criteria->getWhereExpression());
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $repository->matching($criteria));
 }
开发者ID:dominium,项目名称:mongodb-odm,代码行数:7,代码来源:DocumentRepositoryTest.php


示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $indexName = $input->getOption('index');
     $batchSize = $input->getOption('batch_size');
     $indexManager = $this->getIndexManager($indexName);
     $totalDocuments = $indexManager->getTotalEntities();
     $iterations = $this->getIterations($totalDocuments, $batchSize);
     $output->writeln(sprintf('<info>Reindexing</info> "%s"', $indexName));
     $output->writeln(sprintf('<comment>Total documents:</comment> %s', $totalDocuments));
     $output->writeln(sprintf('<comment>Batch size:</comment> %s', $batchSize));
     $output->writeln(sprintf('<comment>Iterations:</comment> %s', $iterations));
     $progress = new ProgressBar($output, $totalDocuments);
     $progress->setFormat('verbose');
     $progress->setRedrawFrequency($batchSize);
     $progress->start();
     $indexManager->purgeIndex();
     for ($i = 0; $i < $iterations; $i++) {
         $criteria = new Criteria();
         $criteria->setMaxResults($batchSize);
         $criteria->setFirstResult($i * $batchSize);
         $collection = $indexManager->getEntitiesCollection($criteria);
         $collection->map(function (EntityInterface $entity) use($indexManager, $progress) {
             $indexManager->addEntity($entity);
             $progress->advance();
         });
     }
     $progress->finish();
     $output->writeln('');
     $output->writeln(sprintf('<info>Optimizing "%s"</info>', $indexName));
     $indexManager->optimizeIndex();
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:31,代码来源:ReindexCommand.php


示例13: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Criteria $criteria, FilterValue $value = null)
 {
     $val = null !== $value ? $value->getValue() : $this->getDefaultValue();
     if (null !== $val) {
         $criteria->setMaxResults($val);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:PageSizeFilter.php


示例14: findAvailableForUser

 /**
  * @param User $user
  * @param int $limit
  * @return Collection|Game[]
  */
 public function findAvailableForUser(User $user, $limit)
 {
     $criteria = new Criteria();
     $expr = Criteria::expr();
     $criteria->where($expr->neq('user1', $user))->andWhere($expr->isNull('user2'))->setMaxResults($limit)->orderBy(['id' => 'DESC']);
     return $this->matching($criteria);
 }
开发者ID:jlekowski,项目名称:battleships-api,代码行数:12,代码来源:GameRepository.php


示例15: testUsersWithFacebookLogin

 public function testUsersWithFacebookLogin()
 {
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->neq('facebook_id', null));
     $users = $this->getUserRepository()->matching($criteria);
     $this->assertCount(8, $users);
 }
开发者ID:bonesmccoy,项目名称:symfex,代码行数:7,代码来源:UserTest.php


示例16: getItems

 /**
  * Get items
  * @author Mohamed Labib <[email protected]>
  * 
  * @access public
  * 
  * @param int $offset
  * @param int $itemCountPerPage
  * @return array items queried
  */
 public function getItems($offset, $itemCountPerPage)
 {
     $this->setCriteria();
     $this->criteria->setFirstResult($offset);
     $this->criteria->setMaxResults($itemCountPerPage);
     return $this->query->filter($this->entityName, $this->criteria);
     //($pageNumber-1) for zero based count
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:18,代码来源:PaginatorAdapter.php


示例17: findByStatusAndBeforeUpdatedAt

 /**
  * Finds operations
  *
  * @param Status $status status to filter upon
  * @param DateTime $date optional date to filter upon
  *
  * @return OperationInterface[]
  */
 public function findByStatusAndBeforeUpdatedAt(Status $status, DateTime $date)
 {
     $criteria = new Criteria();
     $exprBuilder = new ExpressionBuilder();
     $criteria->where($exprBuilder->eq('status', $status->getValue()));
     $criteria->andWhere($exprBuilder->lte('updatedAt', $date));
     return $this->matching($criteria)->toArray();
 }
开发者ID:hipay,项目名称:hipay-wallet-cashout-mirakl-integration,代码行数:16,代码来源:OperationRepository.php


示例18: count

 public function count(array $criteria)
 {
     $criteriaObj = new Criteria();
     foreach ($criteria as $field => $value) {
         $criteriaObj->where($criteriaObj->expr()->eq($field, $value));
     }
     return $this->repository->matching($criteriaObj)->count();
 }
开发者ID:rmukras,项目名称:ekda.org,代码行数:8,代码来源:Repository.php


示例19: testFind

 /**
  * @depends testUpdate
  */
 public function testFind()
 {
     $criteria = new Criteria();
     $expression = new ExpressionBuilder();
     $exp = $expression->eq('username', 'john');
     $criteria->where($exp);
     $this->assertEquals(1, count($this->getRepository(UserExtraEntity::class)->findBy($criteria)));
     $this->assertEquals(2, count($this->getRepository(UserExtraEntity::class)->findAll()));
 }
开发者ID:eoko,项目名称:odm-documentmanager,代码行数:12,代码来源:RepositoryExtraTest.php


示例20: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Criteria $criteria, FilterValue $value = null)
 {
     $val = null !== $value ? $value->getValue() : $this->getDefaultValue();
     if (null !== $val) {
         $pageSize = $criteria->getMaxResults();
         if (null !== $pageSize) {
             $criteria->setFirstResult(QueryUtils::getPageOffset($val, $pageSize));
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:13,代码来源:PageNumberFilter.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP DataFixtures\Loader类代码示例发布时间:2022-05-23
下一篇:
PHP Collections\Collection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap