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


PHP Criteria::orderBy方法代码示例

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


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

示例1: sort

 /**
  * @param DataStructure\Sort $sorting
  *
  * @return void
  */
 public function sort(DataStructure\Sort $sorting)
 {
     $sortings = [];
     foreach ($sorting as $sortingEntity) {
         if ($this->isExcludedProperty($sortingEntity->getProperty())) {
             continue;
         }
         $sortings[$sortingEntity->getProperty()] = $sortingEntity instanceof DataStructure\Sort\Asc ? 'asc' : 'desc';
     }
     $this->criteria->orderBy($sortings);
 }
开发者ID:phprest,项目名称:phprest-service-request-filter,代码行数:16,代码来源:Orm.php

示例2: searchByContains

 public function searchByContains(array $criteria, array $orderBy = null, $page = 0, $pageSize = PHP_INT_MAX)
 {
     if ($page < 0 || $pageSize < 1) {
         throw new \Exception("Invalid page or pageSize: page must be >= 0 and pageSize must be > 0");
     } else {
         $criteriaObj = new Criteria();
         $i = 0;
         foreach ($criteria as $field => $value) {
             if ($value == null) {
                 continue;
             } else {
                 if ($i++ == 0) {
                     $criteriaObj->where($criteriaObj->expr()->contains($field, $value));
                 } else {
                     $criteriaObj->orWhere($criteriaObj->expr()->contains($field, $value));
                 }
             }
         }
         if ($orderBy != null) {
             $criteriaObj->orderBy($orderBy);
         }
         $total = $this->repository->matching($criteriaObj)->count();
         $query = $this->repository->createQueryBuilder("q")->addCriteria($criteriaObj);
         $items = $query->setFirstResult($page * $pageSize)->setMaxResults($pageSize)->getQuery()->getResult();
         return ResponseUtils::createSearchResponse($total, $items, $page, $pageSize);
     }
 }
开发者ID:rmukras,项目名称:coffee,代码行数:27,代码来源:Repository.php

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: sort

 /**
  * Sort data
  * @param Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         call_user_func($sorting->getSortCallback(), $this->criteria, $sorting->getSort());
         return $this;
     }
     if ($sort = $sorting->getSort()) {
         $this->criteria->orderBy($sort);
         return $this;
     }
     $this->criteria->orderBy([$this->primary_key => 'ASC']);
     return $this;
 }
开发者ID:ublaboo,项目名称:datagrid,代码行数:18,代码来源:DoctrineCollectionDataSource.php

示例10: 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

示例11: __invoke

 public function __invoke(Criteria $criteria)
 {
     if (!$this->getController() instanceof AbstractController) {
         throw new \LogicException('Cannot locate the controller');
     }
     $sort = $this->getController()->params()->fromQuery('sorting');
     if ($sort) {
         $fields = explode(',', $sort);
         $orderBy = [];
         foreach ($fields as $field) {
             $parts = explode(':', $field);
             // Ignore it
             if (count($parts) != 2) {
                 continue;
             }
             $orderBy[$parts[0]] = $parts[1];
         }
         $criteria->orderBy($orderBy);
     }
 }
开发者ID:interactive-solutions,项目名称:zf-stdlib,代码行数:20,代码来源:InjectSortingIntoCriteria.php

示例12: testOrderings

 public function testOrderings()
 {
     $criteria = new Criteria();
     $criteria->orderBy(array("foo" => "ASC"));
     $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
 }
开发者ID:richardjh,项目名称:zf2-addressbook,代码行数:6,代码来源:CriteriaTest.php

示例13: getProducerCollection

 /**
  * Returns the collection of producers for given identifiers
  *
  * @param array $identifiers
  *
  * @return \Doctrine\Common\Collections\Collection
  */
 protected function getProducerCollection(array $identifiers = [])
 {
     $criteria = new Criteria();
     $criteria->orderBy(['id' => 'asc']);
     $criteria->where($criteria->expr()->in('id', $identifiers));
     return $this->producerRepository->matching($criteria);
 }
开发者ID:pguso,项目名称:WellCommerce,代码行数:14,代码来源:ProductLayeredNavigationHelper.php

示例14: processOrder

 /**
  * Process order
  * 
  * @param Criteria         $criteria
  * @param RequestInterface $request
  */
 protected function processOrder(Criteria $criteria, RequestInterface $request)
 {
     $criteria->orderBy($request->getOrder());
 }
开发者ID:mikemirten,项目名称:zgrid-bundle,代码行数:10,代码来源:SelectableDataProvider.php

示例15: 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


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