本文整理汇总了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;
}
示例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);
}
}
示例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;
}
}
}
示例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
}
示例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();
}
示例6: apply
/**
* {@inheritdoc}
*/
public function apply(Criteria $criteria, FilterValue $value = null)
{
$val = null !== $value ? $value->getValue() : $this->getDefaultValue();
if (null !== $val) {
$criteria->setMaxResults($val);
}
}
示例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);
}
示例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);
}
示例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.");
}
示例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;
}
示例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());
}
示例12: limit
/**
* @param integer $limit
*
* @return void
*/
public function limit($limit)
{
$this->criteria->setMaxResults($limit);
}
示例13: setMaxResults
/**
* @param int $maxResults
* @return $this
*/
public function setMaxResults($maxResults)
{
$this->criteria->setMaxResults($maxResults);
return $this;
}
示例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());
}