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


PHP Criteria::setMaxResults方法代码示例

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


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

 /**
  * @Template("Event/sidebarEvents.html.twig")
  * @return type
  */
 public function sidebarEventsAction()
 {
     $em = $this->getDoctrine()->getManager();
     $eventRepository = $em->getRepository("TruckeeMatchBundle:Event");
     //        $user            = $this->getUser();
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->gte('eventdate', new \DateTime()));
     $criteria->orderBy(['eventdate' => 'ASC']);
     $criteria->setMaxResults(5);
     $templates[] = 'Event/hr.html.twig';
     if (!empty($eventRepository)) {
         return array('templates' => $templates, 'events' => $eventRepository->matching($criteria));
     } else {
         return array('templates' => $templates);
     }
 }
开发者ID:truckee,项目名称:match,代码行数:20,代码来源:EventController.php

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

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

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

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

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

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

示例9: loadUserByUsername

 public function loadUserByUsername($username)
 {
     $criteria = new Criteria();
     $criteria->where(new Comparison("username", Comparison::EQ, $username));
     $criteria->orWhere(new Comparison("email", Comparison::EQ, $username));
     $criteria->setMaxResults(1);
     $user = $this->em->getRepository("CoreUserBundle:User")->matching($criteria)->first();
     if ($user) {
         return $user;
     }
     //throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     throw new BadCredentialsException("Bad credentials.");
 }
开发者ID:pixocode,项目名称:noostache,代码行数:13,代码来源:Provider.php

示例10: getHeadEmail

 /**
  * Get head email in thread
  *
  * @param EntityManager $entityManager
  * @param Email $entity
  *
  * @return Email
  */
 public function getHeadEmail(EntityManager $entityManager, Email $entity)
 {
     $headEmail = $entity;
     $thread = $entity->getThread();
     if ($thread) {
         $emails = new ArrayCollection($this->getThreadEmails($entityManager, $entity));
         $criteria = new Criteria();
         $criteria->orderBy(['sentAt' => Criteria::DESC]);
         $criteria->setMaxResults(1);
         $unseenEmails = $emails->matching($criteria);
         if (count($unseenEmails)) {
             $headEmail = $unseenEmails[0];
         } elseif (count($emails)) {
             $headEmail = $emails[0];
         }
     }
     return $headEmail;
 }
开发者ID:Maksold,项目名称:platform,代码行数:26,代码来源:EmailThreadProvider.php

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

示例12: limit

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

示例13: setMaxResults

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

示例14: 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::setMaxResults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。