當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collections\Criteria類代碼示例

本文整理匯總了PHP中Doctrine\Common\Collections\Criteria的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria類的具體用法?PHP Criteria怎麽用?PHP Criteria使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Criteria類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Doctrine\Common\Collections\Criteria類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。