本文整理汇总了PHP中Doctrine\ORM\Query::setFirstResult方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setFirstResult方法的具体用法?PHP Query::setFirstResult怎么用?PHP Query::setFirstResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::setFirstResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPagerParameters
/**
* @param Query $pageQuery
*/
protected function setPagerParameters(Query $pageQuery)
{
$pageQuery->setFirstResult($this->getFirstResult());
$pageQuery->setMaxResults($this->bufferSize);
}
示例2: applyPaging
/**
* @param int
* @param int
* @return ResultSet
*/
public function applyPaging($offset, $limit)
{
if ($this->query->getFirstResult() != $offset || $this->query->getMaxResults() != $limit) {
$this->query->setFirstResult($offset);
$this->query->setMaxResults($limit);
$this->iterator = NULL;
}
return $this;
}
示例3: __construct
/**
* Constructor.
*
* Stores various parameters that are otherwise unavailable
* because Doctrine\ORM\Query\SqlWalker keeps everything private without
* accessors.
*
* @param \Doctrine\ORM\Query $query
* @param \Doctrine\ORM\Query\ParserResult $parserResult
* @param array $queryComponents
*/
public function __construct($query, $parserResult, array $queryComponents)
{
$this->platform = $query->getEntityManager()->getConnection()->getDatabasePlatform();
$this->rsm = $parserResult->getResultSetMapping();
$this->queryComponents = $queryComponents;
// Reset limit and offset
$this->firstResult = $query->getFirstResult();
$this->maxResults = $query->getMaxResults();
$query->setFirstResult(null)->setMaxResults(null);
parent::__construct($query, $parserResult, $queryComponents);
}
示例4: paginate
public function paginate($page, Query $query, $itemsPerPage = 10)
{
if (!is_numeric($page)) {
throw new \Exception('Valor no numerico para la paginacion');
}
$this->currentPage = (int) $page;
$this->itemsPerPage = $itemsPerPage;
$this->calLastPage(count($query->getResult()));
$this->calRange();
$query->setFirstResult($this->offset())->setMaxResults($this->itemsPerPage);
return $query->getResult();
}
示例5: _getNextBatch
private function _getNextBatch()
{
if ($this->clearEntitiesOnBatch) {
$em = $this->query->getEntityManager();
foreach ($this->clearEntitiesOnBatch as $e) {
$em->clear($e);
}
}
if (!$this->_count || $this->_count == $this->resultsPerBatch) {
if ($this->countTotal && $this->offset + $this->resultsPerBatch > $this->countTotal) {
$maxResults = $this->countTotal - $this->offset;
} else {
$maxResults = $this->resultsPerBatch;
}
$this->results = $this->query->setFirstResult($this->offset)->setMaxResults($maxResults)->getResult($this->hydrationMode);
} else {
$this->results = array();
}
$this->offset += $this->resultsPerBatch;
$this->_index = 0;
$this->_count = count($this->results);
}
示例6: getPaginatedResult
/**
* @param Query|QueryBuilder $query
* @param int $page
* @param int $limit
* @param Closure $callback
*
* @return array
*/
public function getPaginatedResult($query, $page, $limit, $callback = null)
{
$query->setFirstResult(($page - 1) * $limit)->setMaxResults($limit);
if ($query instanceof QueryBuilder) {
$query = $query->getQuery();
}
$items = $query->getResult();
if ($callback == null) {
$callback = function ($item) {
return ['id' => $item->getId(), 'text' => (string) $item];
};
}
$data = array_map($callback, $items);
$more = count($data) >= $limit;
return ['items' => $data, 'itemsPerPage' => $limit, 'more' => $more];
}
示例7: paginate
/**
* {@inheritdoc}
*/
public function paginate(Query $query, $results, $offset, $arrayResult = true)
{
if ($results <= 0 || $results > $this->maxResults) {
$results = $this->defaultResults;
}
if ($offset < 0) {
$offset = 0;
}
$paginator = new Paginator($query, false);
$query->setFirstResult($offset)->setMaxResults($results);
if ($arrayResult) {
$result = $query->getArrayResult();
} else {
$result = $query->getResult();
}
return ['recordsTotal' => count($paginator), 'recordsFiltered' => count($paginator), 'data' => $result];
}
示例8: getPaginator
/**
* Create and returns a doctrine pagination.
*
* @param Query $query the doctrine object query
* @param int $currentPageNumber current page
* @param int $itemCountPerPage items per page
*
* @return Paginator
*/
public function getPaginator(Query $query, $currentPageNumber = null, $itemCountPerPage = null)
{
$this->setPagination($currentPageNumber, $itemCountPerPage);
$query->setFirstResult($this->firstResult)->setMaxResults($this->maxResults);
return new Paginator($query);
}
示例9: prepareQueryToExecute
/**
* Makes final preparation of a query object before its execute method will be called.
*
* @param Query $query
*/
protected function prepareQueryToExecute(Query $query)
{
$query->setFirstResult($this->firstResult + $query->getMaxResults() * $this->page);
}
示例10: offset
/**
* Creates offset.
*
* @access public
* @param integer $iVal
* @return $this
* @since 1.0.0-alpha
* @version 1.0.0-alpha
*/
public function offset($iVal)
{
$this->oQuery->setFirstResult($iVal);
return $this;
}
示例11: prepareQueryToExecute
/**
* {@inheritdoc}
*/
protected function prepareQueryToExecute(Query $query)
{
// always iterate from the first record
$query->setFirstResult($this->firstResult);
}
示例12: calculateFirstResult
/**
* Calculate first result based on page and max-per-page
*/
protected function calculateFirstResult()
{
$maxPerPage = $this->getMaxPerPage();
$page = $this->getPage();
$this->query->setFirstResult($maxPerPage * ($page - 1));
}
示例13: findCollectionSet
/**
* {@inheritdoc}
*/
public function findCollectionSet($depth = 0, $filter = [], CollectionInterface $collection = null, $sortBy = [])
{
try {
$dql = sprintf('SELECT n, collectionMeta, defaultMeta, collectionType, collectionParent, parentMeta, collectionChildren
FROM %s AS n
LEFT OUTER JOIN n.meta AS collectionMeta
LEFT JOIN n.defaultMeta AS defaultMeta
LEFT JOIN n.type AS collectionType
LEFT JOIN n.parent AS collectionParent
LEFT JOIN n.children AS collectionChildren
LEFT JOIN collectionParent.meta AS parentMeta
WHERE (n.depth <= :depth + :maxDepth OR collectionChildren.depth <= :maxDepthPlusOne)', $this->_entityName);
if ($collection !== null) {
$dql .= ' AND n.lft BETWEEN :lft AND :rgt AND n.id != :id';
}
if (array_key_exists('search', $filter) && $filter['search'] !== null) {
$dql .= ' AND collectionMeta.title LIKE :search';
}
if (array_key_exists('locale', $filter)) {
$dql .= ' AND (collectionMeta.locale = :locale OR defaultMeta != :locale)';
}
if ($sortBy !== null && is_array($sortBy) && sizeof($sortBy) > 0) {
$orderBy = [];
foreach ($sortBy as $column => $order) {
$orderBy[] = 'collectionMeta.' . $column . ' ' . (strtolower($order) === 'asc' ? 'ASC' : 'DESC');
}
$dql .= ' ORDER BY ' . implode(', ', $orderBy);
}
$query = new Query($this->_em);
$query->setDQL($dql);
$query->setParameter('maxDepth', intval($depth));
$query->setParameter('maxDepthPlusOne', intval($depth) + 1);
$query->setParameter('depth', $collection !== null ? $collection->getDepth() : 0);
if ($collection !== null) {
$query->setParameter('lft', $collection->getLft());
$query->setParameter('rgt', $collection->getRgt());
$query->setParameter('id', $collection->getId());
}
if (array_key_exists('search', $filter) && $filter['search'] !== null) {
$query->setParameter('search', '%' . $filter['search'] . '%');
}
if (array_key_exists('limit', $filter)) {
$query->setMaxResults($filter['limit']);
}
if (array_key_exists('offset', $filter)) {
$query->setFirstResult($filter['offset']);
}
if (array_key_exists('locale', $filter)) {
$query->setParameter('locale', $filter['locale']);
}
return new Paginator($query);
} catch (NoResultException $ex) {
return [];
}
}
示例14: getPaginateQuery
/**
* Given the Query it returns a new query that is a paginatable query
* using a modified subselect.
*
* @param Query $query
* @return Query
*/
public static function getPaginateQuery(Query $query, $offset, $itemCountPerPage, array $hints = array())
{
foreach ($hints as $name => $hint) {
$query->setHint($name, $hint);
}
return $query->setFirstResult($offset)->setMaxResults($itemCountPerPage);
}
示例15: applyPagingOptionsToQuery
/**
* Applies the paging configuration to the query object.
*
* @param Query $query Query object
* @param QueryOptions $options Paging options
*/
protected function applyPagingOptionsToQuery(Query $query, QueryOptions $options = null)
{
if ($options == null) {
return;
}
if ($options->hasPagination()) {
$query->setFirstResult(($options->page - 1) * $options->itemsPerPage);
$query->setMaxResults($options->itemsPerPage);
}
}