Prepares information for the pagination of the module

@param Demand $demand
@param int $count
@return array
513843
protected function preparePagination(Demand $demand, int $count): array
    {
        $numberOfPages = ceil($count / $demand->getLimit());
        $endRecord = $demand->getOffset() + $demand->getLimit();
        if ($endRecord > $count) {
            $endRecord = $count;
        }

        $pagination = [
            'current' => $demand->getPage(),
            'numberOfPages' => $numberOfPages,
            'hasLessPages' => $demand->getPage() > 1,
            'hasMorePages' => $demand->getPage() < $numberOfPages,
            'startRecord' => $demand->getOffset() + 1,
            'endRecord' => $endRecord
        ];
        if ($pagination['current'] < $pagination['numberOfPages']) {
            $pagination['nextPage'] = $pagination['current'] + 1;
        }
        if ($pagination['current'] > 1) {
            $pagination['previousPage'] = $pagination['current'] - 1;
        }
        return $pagination;
    }
1272068
private function paginate()
    {
        $this->list = null;
        try {
            $query = $this->prepareQuery();
            $this->addFilters($query);
            $this->checkReturnFields($query);
            $this->addOrders($query);
            list($page, $limit) = $this->extractPagination();
            if ($limit === -1) {
                $this->list = $query->find($this->con);
            } else {
                $this->list = $query->paginate($page, $limit, $this->con);
            }
        } catch (\Exception $e) {
            Logger::log($e->getMessage(), LOG_ERR);
        }
    }
845392
protected function paginationInformation($request)
    {
        $paginated = $this->resource->resource->toArray();

        return [
            'links' => $this->paginationLinks($paginated),
            'meta' => $this->meta($paginated),
        ];
    }
894883
public function paginate(Query $query, array $countFields = [], $total = false)
    {
        $limit = $this->defaultLimit;
        if (in_array((integer)$this->request->getQuery('l', 0), $this->limits)) {
            $limit = (integer)$this->request->getQuery('l');
            $this->activeLimit = $limit;
        }
        if (!$this->activeLimit) {
            $lastLimit = $this->request->getSession()->read(join('.', [
                'LIMIT_' . $this->request->getParam('plugin'),
                $this->controller->getName(),
                $this->action
            ]));
            if ($lastLimit) {
                $limit = $lastLimit;
            }
            $this->activeLimit = $limit;
        }
        $this->request = $this->request->withData('l', $limit);

        if ($total === false) {
            $countQuery = clone $query;
            if (!empty($countFields)) {
                $countQuery->select($countFields);
            }
            $total = $countQuery->count();
        }

        if ($limit !== null && $total !== null) {
            $pages = ceil($total / $limit);
            if ($this->page > $pages) {
                $this->page = $pages;
            }
            if ($this->page < 1) {
                $this->page = 1;
            }
            $offset = ($this->page > 1) ? ($this->page - 1) * $limit : 0;
            $from = ($offset > 0) ? $offset + 1 : 1;
            $to = (($from + $limit - 1) > $total) ? $total : $from + $limit - 1;

            $query->limit($limit)->offset($offset);

            $this->paginationParams = [
                'from' => ($total === 0) ? 0 : $from,
                'page' => $this->page,
                'pages' => ($total === 0) ? 1 : $pages,
                'to' => $to,
                'total' => $total,
                'defaultLimit' => $this->defaultLimit,
                'limits' => array_combine($this->limits, $this->limits),
                'passParams' => []
            ];

            if (!empty($this->_passParams)) {
                $this->paginationParams['passParams'] = $this->_passParams;
            }
        }

        return $query;
    }
1220507
public function page($page, $count)
    {
        $pagination = new Pagination($page, $count);
        $this->option->offset = $pagination->getLimitOffset();
        $this->option->limit = $count;
        return $this;
    }
766522
private function paginateRecords(ActiveQueryInterface $query, $pageNumber, $count)
    {
        $offset = ($pageNumber - 1) * $count;
        $limit = $count;

        return $query->offset($offset)->limit($limit);
    }
328992
private function content(Post $post, int $count): string
    {
        $out = '';

        if (!$this->posts->isContent()) {
            return $out;
        }

        $content = $post->content(
            $this->posts->args['excerpt']['more_text'],
            '',
            $this->posts->args['excerpt']['paginate']
        );

        if (!$content) {
            return $out;
        }

        $out .= '<div class="entry-content" itemprop="articleBody">';
        $out .= $content;
        $out .= '</div><!-- .entry-content -->';

        return $out;
    }
467259
public function createQuery($managerName, Request $request, array $criteria = [], array $orderBy = [], $strictMode = true)
	{
		$this->lastManagerName = $managerName;
		$config = $this->getManagerConfig($managerName);
		$options = [
				'twig_extension_enabled' 	=> $this->container->getParameter('oka_pagination.twig.enable_extension'),
				'strict_mode' 				=> $strictMode
		];
		
		$sortConfig = $config['request']['sort'];
		$queryMapConfig = $config['request']['query_map'];
		
		// Extract pagination data in request
		$page = RequestParser::extractPageInRequest($request, $queryMapConfig['page'], 1);
		$config['item_per_page'] = RequestParser::extractItemPerPageInRequest($request, $queryMapConfig['item_per_page'], $config['item_per_page']);
		$filters = RequestParser::extractFiltersInRequest($request, $queryMapConfig['filters']);
		
		// Parse pagination request query for sort
		$sortAttributes = RequestParser::parseQueryToArray($request, $queryMapConfig['sort'], $sortConfig['delimiter']);
		$descAttributes = RequestParser::parseQueryToArray($request, $queryMapConfig['desc'], $sortConfig['delimiter']);
		
		foreach ($sortAttributes as $key => $attribute) {
			if (!in_array($attribute, $sortConfig['attributes_availables'])) {
				if (true === $strictMode) {
					throw new SortAttributeNotAvailableException($attribute, sprintf('Invalid request sort attribute "%s" not avalaible.', $attribute));
				}
				continue;
			}
			
			$sortAttributes[$attribute] = in_array($attribute, $descAttributes) ? 'DESC' : 'ASC';
			unset($sortAttributes[$key]);
		}
		
		$criteria = empty($filters) ? $criteria : array_merge($criteria, $filters);
		$orderBy = empty($sortAttributes) ? $orderBy : array_merge($orderBy, $sortAttributes);
		
		if (isset($config['model_manager_name']) && isset($config['db_driver'])) {
			/** @var \Doctrine\Bundle\DoctrineBundle\Registry $registry */
			$registry = $this->container->get(BundleExtension::$doctrineDrivers[$config['db_driver']]['registry']);
			$objectManager = $registry->getManager($config['model_manager_name']);
		} else {
			$objectManager = $this->container->get('oka_pagination.default.object_manager');
		}
		
		$query = new PaginationQuery($objectManager, $this->qbHandler, null, $managerName, $options, $config, $page, $criteria, $orderBy);
		$query->addQueryPart('select', RequestParser::parseQueryToArray($request, 'fields', ',', []));
		$query->addQueryPart('distinct', (boolean) RequestParser::getRequestParameterValue($request, 'distinct', true));
		
		if (true === $options['twig_extension_enabled']) {
			$query->setTwig($this->container->get('twig'));
		}
		
		return $query;
	}
117135
private function handle(Response $response, $count = false)
    {
        $responseData = json_decode($response->getContent(), true);

        if (!$response->isSuccessful()) {
            // @todo get better error
            throw new \RuntimeException($response->getContent());
        }

        if (true === $count) {
            switch ($responseData['kind']) {
                case 'youtube#playlistItemListResponse':
                    return (int) $responseData['pageInfo']['totalResults'];
                    break;

                default:
                    throw new \Exception('unsupported count operation');
                    break;
            }
        }

        if (isset($responseData['nextPageToken'])) {
            $this->nextPageToken = $responseData['nextPageToken'];
        } else {
            $this->nextPageToken = null;
        }
        return $responseData['items'];
    }
720910
final public function limit($offsetOrCount, $count = null)
    {
        $this->getQuery()->limit($offsetOrCount, $count);
        $this->pagedQuery = true;

        return $this;
    }
347420
public function iterNextPage($count = 3)
    {
        if ($this->getPage() == 1 && $this->getPagesCount() >= $count * 2) {
            $count *= 2;
        }
        $pages = [];
        foreach (range(1, $count) as $i) {
            $page = $this->getPage() + $i;
            if ($page <= $this->getPagesCount()) {
                $pages[] = $page;
            }
        }

        return $pages;
    }
430377
public function listByProfileAction(Request $request, $token)
    {
        list($transUnits, $count) = $this->get('lexik_translation.data_grid.request_handler')->getPageByToken($request, $token);

        return $this->get('lexik_translation.data_grid.formatter')->createListResponse($transUnits, $count);
    }
912127
public function paginateVideos ($offset = 0, $count = 20)
    {
        $json = $this->paginate(MediaType::VIDEO, $offset, $count);
        $resultSet = [];
        
        foreach ($json->item as $item) {
            $resultSet[] = new Paginated\Video($item->media_id, $item->update_time);
        }

        return new Paginated\VideoResultSet($resultSet, $json->total_count, $offset);
    }
1246746
public function messages(int $count = 200) : array
    {
        $messages = [];

        $messageFields = $this->info($count, true);

        foreach ($messageFields->threadEvents as $message) {
            $messages[] = new Message($this->client, $message->messageEventDetail, $this);
        }

        return $messages;
    }
843442
protected function loadQueue($eventname, $count)
    {
        $queueEvent = new LoadQueueEvent();
        $queueEvent->setKind($eventname);
        $queueEvent->setCount($count);
        $this->dispatcher->dispatch($queueEvent::NAME, $queueEvent);
        return $queueEvent->getEvents();
    }
671909
public function queryAndCount($resultName, $countName, QueryObjectInterface $queryObject, DisplayCriteriaInterface $displayCriteria = null)
    {
        list($result, $count) = $this->doQueryAndCount($queryObject, $displayCriteria);

        $this->data[$resultName] = $result;
        $this->data[$countName] = $count;

        return [$result, $count];
    }
678316
public function paginateRaw($count, $page, $itemsPerPage)
    {
        $this->paginator->tweak($count, $itemsPerPage, $page);
        $this->limit($this->paginator->countOffset(), $this->paginator->getItemsPerPage());

        return $this;
    }