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


PHP QueryBuilder::setFirstResult方法代码示例

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


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

示例1: testGetsItemsAtOffsetTen

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

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

示例3: getData

 public function getData(array $p_params, array $p_cols)
 {
     $this->_queryObject = $this->_repository->createQueryBuilder('e');
     // search
     if (!empty($p_params['search'])) {
         $this->search($p_params['search'], $p_cols);
     }
     // sort
     if (@count($p_params['sortCol'])) {
         $this->sort($p_params, $p_cols);
     }
     // limit
     $this->_queryObject->setFirstResult((int) $p_params['displayStart'])->setMaxResults((int) $p_params['displayLength']);
     return $this->_queryObject->getQuery()->getResult();
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:15,代码来源:Doctrine.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: offset

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

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

示例7: paginateQuery

 /**
  * @param QueryBuilder $query
  * @param int $per_page
  * @param int $current_page
  *
  * @return Configuration
  */
 public function paginateQuery(QueryBuilder $query, $per_page, $current_page = 1)
 {
     $counter = clone $query;
     $total = $counter->select(sprintf('COUNT(%s)', current($query->getRootAliases())))->getQuery()->getSingleScalarResult();
     $query->setFirstResult(($current_page - 1) * $per_page)->setMaxResults($per_page);
     return (new Configuration(ceil($total / $per_page), $current_page))->setMaxNavigate($this->max_navigate);
 }
开发者ID:anime-db,项目名称:pagination-bundle,代码行数:14,代码来源:Builder.php

示例8: attachCriteriaToQueryBuilder

 /**
  * Custom findBy so we can filter by related entities
  *
  * @param QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  * @param int $limit
  * @param int $offset
  *
  * @return QueryBuilder
  */
 protected function attachCriteriaToQueryBuilder(QueryBuilder $qb, $criteria, $orderBy, $limit, $offset)
 {
     if (count($criteria)) {
         foreach ($criteria as $key => $value) {
             $values = is_array($value) ? $value : [$value];
             $qb->andWhere($qb->expr()->in("a.{$key}", ":{$key}"));
             $qb->setParameter(":{$key}", $values);
         }
     }
     if (empty($orderBy)) {
         $orderBy = ['user' => 'ASC'];
     }
     if (is_array($orderBy)) {
         foreach ($orderBy as $sort => $order) {
             $qb->addOrderBy('a.' . $sort, $order);
         }
     }
     if ($offset) {
         $qb->setFirstResult($offset);
     }
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:36,代码来源:AuthenticationRepository.php

示例9: setLimit

 /**
  * Paging.
  * Construct the LIMIT clause for server-side processing SQL query.
  *
  * @return $this
  */
 private function setLimit()
 {
     if (isset($this->requestParams['start']) && -1 != $this->requestParams['length']) {
         $this->qb->setFirstResult($this->requestParams['start'])->setMaxResults($this->requestParams['length']);
     }
     return $this;
 }
开发者ID:bigz,项目名称:datatablesbundle,代码行数:13,代码来源:DatatableQuery.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: 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

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

示例13: apply

 public static function apply(QueryBuilder $qb, $page, $perPage)
 {
     if ($perPage > self::MAX_PER_PAGE) {
         $perPage = self::MAX_PER_PAGE;
     }
     $qb->setFirstResult($page * $perPage)->setMaxResults($perPage);
     return $qb;
 }
开发者ID:spdionis,项目名称:un-webservice,代码行数:8,代码来源:PaginateHelper.php

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

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


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