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


PHP QueryBuilder::setMaxResults方法代码示例

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


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

示例1: testGetsItemsAtOffsetZero

 public function testGetsItemsAtOffsetZero()
 {
     $expected = $this->qb->setMaxResults(10)->getQuery()->getResult();
     $actual = $this->paginatorAdapter->getItems(0, 10);
     foreach ($expected as $key => $expectedItem) {
         $this->assertEquals($expectedItem, $actual[$key]);
     }
 }
开发者ID:KBO-Techo-Dev,项目名称:MagazinePro-zf25,代码行数:8,代码来源:AdapterTestIgnore.php

示例2: getQueryResults

 /**
  * Get the query result
  *
  * @param integer $limit
  *
  * @return ArrayCollection
  */
 public function getQueryResults($limit = null)
 {
     if (isset($limit)) {
         $this->queryBuilder->setMaxResults($limit);
     }
     if (!$this->queryBuilder->getDQLPart('orderBy')) {
         $this->queryBuilder->orderBy('a.createdAt', 'ASC');
     }
     return $this->queryBuilder->getQuery()->getResult();
 }
开发者ID:opifer,项目名称:rulesengine,代码行数:17,代码来源:DoctrineEnvironment.php

示例3: getItems

 public function getItems()
 {
     $this->qb->setMaxResults($this->getLimit());
     $this->qb->setFirstResult($this->getOffset());
     list($sortColumn, $sortType) = $this->getSorting();
     if ($sortColumn) {
         $this->qb->orderBy($this->qb->getRootAlias() . "." . $sortColumn, $sortType);
     }
     return $this->qb->getQuery()->getResult();
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:10,代码来源:DoctrineQueryBuilderModel.php

示例4: getQuery

 private function getQuery($filter, $order)
 {
     if (empty($this->queryBuilder)) {
         if (!isset($this->limit)) {
             throw new InvalidStateException('Property limit must be set.');
         }
         if (!isset($this->offset)) {
             throw new InvalidStateException('Property offset must be set.');
         }
         $this->queryBuilder = Callback::invokeArgs($this->callback, [$filter, $order]);
         $this->queryBuilder->setMaxResults($this->limit);
         $this->queryBuilder->setFirstResult($this->offset);
     }
     return new Paginator($this->queryBuilder);
 }
开发者ID:janlavicka,项目名称:datagrid,代码行数:15,代码来源:DoctrineAdapter.php

示例5: paginate

 public function paginate(QueryBuilder $query, $limit, $page)
 {
     $query->setMaxResults($limit)->setFirstResult($limit * ($page - 1));
     $paginator = new Paginator($query->getQuery());
     $paginator->setUseOutputWalkers(false);
     return $paginator;
 }
开发者ID:jacksleight,项目名称:coast-doctrine,代码行数:7,代码来源:EntityManager.php

示例6: getPhotos

 /**
  * @param QueryBuilder $queryBuilder
  * @param Request      $request
  *
  * @return object[]|Photo[]
  */
 public function getPhotos(QueryBuilder $queryBuilder, Request $request)
 {
     $limit = $request->query->getInt('limit', 10);
     $page = $request->query->getInt('page', 1);
     $offset = $limit * ($page - 1);
     return $queryBuilder->setMaxResults($limit)->setFirstResult($offset)->getQuery()->execute();
 }
开发者ID:alexey-wild,项目名称:stfalcon-photos-api,代码行数:13,代码来源:PhotoManager.php

示例7: getQueryRows

 /**
  * Build and returns Query for select rows
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder
  * @param \EMC\TableBundle\Provider\QueryConfigInterface $queryConfig
  * @param array $mapping
  * @return \Doctrine\ORM\Query
  */
 private function getQueryRows(QueryBuilder $queryBuilder, QueryConfigInterface $queryConfig, array &$mapping)
 {
     $queryBuilder->resetDQLPart('select');
     $limit = $queryConfig->getLimit();
     $page = $queryConfig->getPage();
     $select = $queryConfig->getSelect();
     $orderBy = $queryConfig->getOrderBy();
     if ($limit > 0) {
         $queryBuilder->setMaxResults($limit)->setFirstResult(($page - 1) * $limit);
     }
     $mapping = array_map(function ($i) {
         return 'col' . $i;
     }, array_flip($select));
     foreach ($mapping as $column => $name) {
         $queryBuilder->addSelect($column . ' AS ' . $name);
     }
     if (count($orderBy) === 0) {
         $queryBuilder->orderBy($queryBuilder->getRootAlias() . '.id', 'ASC');
     } else {
         foreach ($orderBy as $column => $isAsc) {
             $queryBuilder->orderBy($column, $isAsc ? 'ASC' : 'DESC');
         }
     }
     return $queryBuilder->getQuery();
 }
开发者ID:cwd,项目名称:TableBundle,代码行数:32,代码来源:DataProvider.php

示例8: filter

 /**
  * {@inheritdoc}
  */
 public function filter(Request $request, QueryBuilder $queryBuilder)
 {
     if ($request->query->has('per_page') && $request->query->has('page')) {
         $queryBuilder->setMaxResults($request->query->get('per_page'));
         $queryBuilder->setFirstResult(($request->query->get('page') - 1) * $request->query->get('per_page'));
     }
 }
开发者ID:csbill,项目名称:csbill,代码行数:10,代码来源:PaginateFilter.php

示例9: addCommonFilters

 /**
  * Adds common filter options (limit, offset, order) to a query builder
  * @param  QueryBuilder $qb
  * @param  array        $options
  * @return QueryBuilder
  * @author Yohann Marillet
  */
 protected function addCommonFilters(QueryBuilder $qb, array $options = array())
 {
     if (isset($options['_prefix'])) {
         $options['_prefix'] = rtrim($options['_prefix'], '.') . '.';
     } else {
         $options['_prefix'] = '';
     }
     if (isset($options['limit']) && !empty($options['limit'])) {
         $qb->setMaxResults((int) $options['limit']);
         if (isset($options['offset'])) {
             $qb->setFirstResult((int) $options['offset']);
         }
     }
     if (isset($options['order'])) {
         foreach ($options['order'] as $field => $order) {
             if (is_int($field)) {
                 $field = $order;
                 $order = 'ASC';
             }
             $field = $options['_prefix'] . $field;
             $qb->addOrderBy($this->replaceByJoinAlias($field, $qb), $order);
         }
     }
     return $qb;
 }
开发者ID:ymarillet,项目名称:sknife,代码行数:32,代码来源:AbstractRepository.php

示例10: getFixedQueryBuilder

 /**
  * This method alters the query to return a clean set of object with a working
  * set of Object
  *
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder
  * @return void
  */
 private function getFixedQueryBuilder(QueryBuilder $queryBuilder)
 {
     $queryBuilderId = clone $queryBuilder;
     // step 1 : retrieve the targeted class
     $from = $queryBuilderId->getDQLPart('from');
     $class = $from[0]->getFrom();
     // step 2 : retrieve the column id
     $idName = current($queryBuilderId->getEntityManager()->getMetadataFactory()->getMetadataFor($class)->getIdentifierFieldNames());
     // step 3 : retrieve the different subjects id
     $select = sprintf('%s.%s', $queryBuilderId->getRootAlias(), $idName);
     $queryBuilderId->resetDQLPart('select');
     $queryBuilderId->add('select', 'DISTINCT ' . $select);
     $results = $queryBuilderId->getQuery()->execute(array(), Query::HYDRATE_ARRAY);
     $idx = array();
     $connection = $queryBuilder->getEntityManager()->getConnection();
     foreach ($results as $id) {
         $idx[] = $connection->quote($id[$idName]);
     }
     // step 4 : alter the query to match the targeted ids
     if (count($idx) > 0) {
         $queryBuilder->andWhere(sprintf('%s IN (%s)', $select, implode(',', $idx)));
         $queryBuilder->setMaxResults(null);
         $queryBuilder->setFirstResult(null);
     }
     return $queryBuilder;
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:33,代码来源:ProxyQuery.php

示例11: limit

 /**
  * Set the page for pagination
  *
  * @param $pageNumber
  * @param $itemsPerPage
  * @return $this
  */
 public function limit($pageNumber, $itemsPerPage)
 {
     $offset = $pageNumber <= 1 ? 0 : ($pageNumber - 1) * $itemsPerPage;
     $this->queryBuilder->setMaxResults($itemsPerPage);
     $this->queryBuilder->setFirstResult($offset);
     return $this;
 }
开发者ID:nstapelbroek,项目名称:zf2-doctrine-datagrid,代码行数:14,代码来源:QueryBuilderService.php

示例12: limit

 /**
  * @param int $limit
  *
  * @return Builder
  */
 public function limit($limit)
 {
     if ($limit > 0) {
         $this->select->setMaxResults($limit);
     }
     return $this;
 }
开发者ID:anime-db,项目名称:catalog-bundle,代码行数:12,代码来源:Builder.php

示例13: getItems

 /**
  * @return mixed
  */
 public function getItems()
 {
     $this->qb->setMaxResults($this->getLimit());
     $this->qb->setFirstResult($this->getOffset());
     if (count($this->getSorting()) > 0) {
         foreach ($this->getSorting() as $sortColumn => $sortType) {
             if (isset($this->columnAliases[$sortColumn])) {
                 $sortColumn = $this->columnAliases[$sortColumn]->qbName;
             } else {
                 $aliases = $this->qb->getRootAliases();
                 $sortColumn = $aliases[0] . '.' . $sortColumn;
             }
             $this->qb->addOrderBy($sortColumn, is_string($sortType) && strncasecmp($sortType, 'd', 1) || $sortType > 0 ? 'ASC' : 'DESC');
         }
     }
     return $this->qb->getQuery()->getResult();
 }
开发者ID:natrim,项目名称:gridito,代码行数:20,代码来源:DoctrineQueryBuilderModel.php

示例14: getData

 /**
  * @param int $limit
  * @param int $offset
  * @return array
  */
 public function getData($limit = NULL, $offset = NULL)
 {
     if ($limit !== NULL) {
         $this->builder->setMaxResults($limit);
         $this->builder->setFirstResult($offset);
     }
     $class = $this->DTO;
     if ($class) {
         foreach ($this->builder->getQuery()->getResult($this->resultType) as $item) {
             (yield new $class($item));
         }
     } else {
         foreach ($this->builder->getQuery()->getResult($this->resultType) as $item) {
             (yield $item);
         }
     }
 }
开发者ID:WebChemistry,项目名称:filter,代码行数:22,代码来源:Doctrine.php

示例15: execute

 /**
  * @param $columns \Sorien\DataGridBundle\Grid\Column\Column[]
  * @param $page int Page Number
  * @param $limit int Rows Per Page
  * @return \Sorien\DataGridBundle\Grid\Rows
  */
 public function execute($columns, $page = 0, $limit = 0)
 {
     $this->query = $this->manager->createQueryBuilder($this->class);
     $this->query->from($this->class, self::TABLE_ALIAS);
     $where = $this->query->expr()->andx();
     $sorted = false;
     foreach ($columns as $column) {
         $this->query->addSelect($this->getFieldName($column));
         if ($column->isSorted() && !$column->isDefaultSort()) {
             $this->query->orderBy($this->getFieldName($column, false), $column->getOrder());
             $sorted = true;
         } elseif (!$sorted && $column->isSorted() && $column->isDefaultSort()) {
             $this->query->orderBy($this->getFieldName($column, false), $column->getOrder());
         }
         if ($column->isFiltered()) {
             if ($column->getFiltersConnection() == column::DATA_CONJUNCTION) {
                 foreach ($column->getFilters() as $filter) {
                     $operator = $this->normalizeOperator($filter->getOperator());
                     $where->add($this->query->expr()->{$operator}($this->getFieldName($column, false), $this->normalizeValue($filter->getOperator(), $filter->getValue())));
                 }
             } elseif ($column->getFiltersConnection() == column::DATA_DISJUNCTION) {
                 $sub = $this->query->expr()->orx();
                 foreach ($column->getFilters() as $filter) {
                     $operator = $this->normalizeOperator($filter->getOperator());
                     $sub->add($this->query->expr()->{$operator}($this->getFieldName($column, false), $this->normalizeValue($filter->getOperator(), $filter->getValue())));
                 }
                 $where->add($sub);
             }
             $this->query->where($where);
         }
     }
     foreach ($this->joins as $alias => $field) {
         $this->query->leftJoin($field, $alias);
     }
     if ($page > 0) {
         $this->query->setFirstResult($page * $limit);
     }
     if ($limit > 0) {
         $this->query->setMaxResults($limit);
     }
     //call overridden prepareQuery or associated closure
     $query = $this->prepareQuery(clone $this->query);
     $items = $query->getQuery()->getResult();
     // hydrate result
     $result = new Rows();
     foreach ($items as $item) {
         $row = new Row();
         foreach ($item as $key => $value) {
             $row->setField($key, $value);
         }
         //call overridden prepareRow or associated closure
         if (($modifiedRow = $this->prepareRow($row)) != null) {
             $result->addRow($modifiedRow);
         }
     }
     return $result;
 }
开发者ID:sxn,项目名称:DataGridBundle,代码行数:63,代码来源:Entity.php


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