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


PHP Criteria::setFirstResult方法代码示例

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


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

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

示例2: initDatabaseMock

 /**
  * Initialize mocks for Doctrine
  * 
  * @param array $managersToMock List of managers to be mocked
  * 
  * @return void
  */
 protected function initDatabaseMock($managersToMock)
 {
     if (is_null($this->mockedManager)) {
         $test = $this;
         foreach ($managersToMock as $manager) {
             $entityName = $manager['entityName'];
             // EntityManager mock
             $entityManagerMock = new \mock\Doctrine\ORM\EntityManager();
             // ClassMetadata mock
             $classMetadata = new \mock\Doctrine\ORM\Mapping\ClassMetadata($entityName);
             $entityClassName = $manager['entityClassName'];
             $this->calling($classMetadata)->getName = function () use($entityClassName) {
                 return $entityClassName;
             };
             // EntityRepository mock
             $entityRepositoryMock = new \mock\Doctrine\ORM\EntityRepository($entityManagerMock, $classMetadata);
             $this->calling($entityRepositoryMock)->find = function ($id) use($test, $entityName) {
                 if (!empty($test->database[$entityName]) && array_key_exists($id, $test->database[$entityName])) {
                     return clone $test->database[$entityName][$id];
                 }
                 return null;
             };
             $this->calling($entityRepositoryMock)->findBy = function ($criteria = [], $sort = null, $limit = null, $start = 0) use($test, $entityName) {
                 $entities = new ArrayCollection($test->database[$entityName]);
                 $crit = new Criteria();
                 foreach ($criteria as $field => $value) {
                     $crit->andWhere($crit->expr()->eq($field, $value));
                 }
                 if (!is_null($sort)) {
                     $crit->orderBy($sort);
                 }
                 $crit->setFirstResult($start);
                 $crit->setMaxResults($limit);
                 return $entities->matching($crit)->map(function ($item) {
                     return clone $item;
                 });
             };
             // Overload main EntityManager functions
             $this->calling($entityManagerMock)->getRepository = function () use($entityRepositoryMock) {
                 return $entityRepositoryMock;
             };
             $this->calling($entityManagerMock)->getClassMetadata = function ($entity) use($classMetadata) {
                 return $classMetadata;
             };
             $this->calling($entityManagerMock)->persist = function ($entity) use($test, $entityName) {
                 if (!$entity->getId()) {
                     if (!empty($test->database[$entityName])) {
                         $entity->setId(count($test->database[$entityName]) + 1);
                     } else {
                         $entity->setId(1);
                     }
                 }
                 $test->database[$entityName][$entity->getId()] = $entity;
                 return true;
             };
             $this->calling($entityManagerMock)->remove = function ($entity) use($test, $entityName) {
                 if (!$entity->getId() || empty($test->database[$entityName][$entity->getId()])) {
                     return false;
                 }
                 unset($test->database[$entityName][$entity->getId()]);
                 return true;
             };
             $mockClass = '\\mock' . $manager['className'];
             $managerMock = new $mockClass($entityManagerMock, $entityName);
             $this->mockedManager[$manager['serviceName']] = $managerMock;
         }
     }
 }
开发者ID:e-ReColNat,项目名称:recolnat-diff,代码行数:75,代码来源:AbstractDoctrineMockedTest.php

示例3: getItems

 /**
  * Get items
  * @author Mohamed Labib <mohamed.labib@camelcasetech.com>
  * 
  * @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

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

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

示例6: getData

 /**
  * {@inheritdoc}
  */
 public function getData(RequestInterface $request)
 {
     $criteria = new Criteria();
     $criteria->setMaxResults($request->getLimit());
     $criteria->setFirstResult($request->getOffset());
     $this->processOrder($criteria, $request);
     $this->processSearch($criteria, $request);
     $this->processGlobalSearch($criteria, $request);
     $result = $this->collection->matching($criteria);
     return $this->processData($result);
 }
开发者ID:mikemirten,项目名称:ConstructorCMS,代码行数:14,代码来源:SelectableDataProvider.php

示例7: findAllPublic

 public function findAllPublic($page, $itemPerPage)
 {
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('r.published', true));
     $criteria->orderBy(['r.dateUpdated' => 'DESC']);
     $criteria->setFirstResult(($page - 1) * $itemPerPage);
     $criteria->setMaxResults($itemPerPage);
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $this->objectRepository->createQueryBuilder('r');
     $queryBuilder->addCriteria($criteria);
     return new Paginator($queryBuilder);
 }
开发者ID:Indigo1337,项目名称:c4d,代码行数:12,代码来源:ReadService.php

示例8: limit

 /**
  * Apply limit and offset on data
  * @param int $offset
  * @param int $limit
  * @return static
  */
 public function limit($offset, $limit)
 {
     $this->criteria->setFirstResult($offset)->setMaxResults($limit);
     return $this;
 }
开发者ID:ublaboo,项目名称:datagrid,代码行数:11,代码来源:DoctrineCollectionDataSource.php

示例9: testAddCriteriaLimit

 public function testAddCriteriaLimit()
 {
     $qb = $this->_em->createQueryBuilder();
     $criteria = new Criteria();
     $criteria->setFirstResult(2);
     $criteria->setMaxResults(10);
     $qb->addCriteria($criteria);
     $this->assertEquals(2, $qb->getFirstResult());
     $this->assertEquals(10, $qb->getMaxResults());
 }
开发者ID:nicolas-grekas,项目名称:doctrine2,代码行数:10,代码来源:QueryBuilderTest.php

示例10: offset

 /**
  * @param integer $offset
  *
  * @return mixed
  */
 public function offset($offset)
 {
     $this->criteria->setFirstResult($offset);
 }
开发者ID:phprest,项目名称:phprest-service-request-filter,代码行数:9,代码来源:Orm.php

示例11: getItems

 /**
  * {@inheritDoc}
  */
 public function getItems($offset, $itemCountPerPage)
 {
     $this->criteria->setFirstResult($offset)->setMaxResults($itemCountPerPage);
     return $this->selectable->matching($this->criteria)->toArray();
 }
开发者ID:bojanst,项目名称:zf2test,代码行数:8,代码来源:Selectable.php

示例12: setFirstResult

 /**
  * @param int $firstResult
  * @return $this
  */
 public function setFirstResult($firstResult)
 {
     $this->criteria->setFirstResult($firstResult);
     return $this;
 }
开发者ID:davidbadura,项目名称:taskwarrior,代码行数:9,代码来源:QueryBuilder.php

示例13: testAddCriteriaLimit

 public function testAddCriteriaLimit()
 {
     $qb = $this->_em->createQueryBuilder();
     $qb->select('u')->from('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $criteria = new Criteria();
     $criteria->setFirstResult(2);
     $criteria->setMaxResults(10);
     $qb->addCriteria($criteria);
     $this->assertEquals(2, $qb->getFirstResult());
     $this->assertEquals(10, $qb->getMaxResults());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:11,代码来源:QueryBuilderTest.php


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