Create an array of pagination

@return void
160673
public function build()
	{
		$pageNumber = -1;
		$count = 0;

		while($count < count($this->posts))
		{
			$i = 0; // $i define post per page
			$pageNumber++; 

			if($pageNumber == 0)
				$pagination = new Pagination($pageNumber, '/index.html');
			else
				$pagination = new Pagination($pageNumber, '/index' . $pageNumber . '.html');

			while($i < $this->config['config']['pagination'] && $count < count($this->posts))
			{
				$pagination->setPost($this->posts[$count]);
				$i++;
				$count++;
			}

			if(isset($this->paginations[$pageNumber - 1]))
			{
				$pagination->setPreviousPage($this->paginations[$pageNumber - 1]);
				$this->paginations[$pageNumber - 1]->setNextPage($pagination);
			}
			$this->paginations[] = $pagination;
		}
	}
384514
public function pagination() {
		global $post, $page, $numpages, $multipage;
		$post = $this;
		$ret = array();
		if ( $multipage ) {
			for ( $i = 1; $i <= $numpages; $i++ ) {
				$link = self::get_wp_link_page($i);
				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
				if ( $i == $page ) {
					$data['current'] = true;
				}
				$ret['pages'][] = $data;
			}
			$i = $page - 1;
			if ( $i ) {
				$link = self::get_wp_link_page($i);
				$ret['prev'] = array('link' => $link);
			}
			$i = $page + 1;
			if ( $i <= $numpages ) {
				$link = self::get_wp_link_page($i);
				$ret['next'] = array('link' => $link);
			}
		}
		return $ret;
	}
8177
public function getPages()
    {
        $pages = array();

        if ($this->pages <= 1) {
            return array();
        }

        if ($this->pages <= $this->limit_pages) {
            for ($i = 1; $i <= $this->pages; $i++) {
                $pages[] = $this->createPage($i, $i == $this->current);
            }

            return $pages;
        }

        $num_adjacents = (int) floor(($this->limit_pages - 3) / 2);

        if ($this->current + $num_adjacents > $this->pages) {
            $sliding_start = $this->pages - $this->limit_pages + 2;
        } else {
            $sliding_start = $this->current - $num_adjacents;
        }

        if ($sliding_start < 2) {
            $sliding_start = 2;
        }

        $sliding_end = $sliding_start + $this->limit_pages - 3;

        if ($sliding_end >= $this->pages) {
            $sliding_end = $this->pages - 1;
        }

        $pages[] = $this->createPage(1, $this->current == 1);

        if ($sliding_start > 2) {
            $pages[] = $this->createPageEllipsis();
        }

        for ($i = $sliding_start; $i <= $sliding_end; $i++) {
            $pages[] = $this->createPage($i, $i == $this->current);
        }

        if ($sliding_end < $this->pages - 1) {
            $pages[] = $this->createPageEllipsis();
        }

        $pages[] = $this->createPage($this->pages, $this->current == $this->pages);

        return $pages;
    }
307662
public function index()
    {
        /** @var \Colibri\Database\ModelCollection $items */
        $items = new $this->listClass();
        $this->applyListFilters($items);
        $items->load();

        $this->template->vars[$this->listTplVar] = $items;
        if ($this->pagedList) {
            $this->template->vars['pagination'] = [
                'page'           => (int)(isset($_GET['page']) ? $_GET['page'] : 0),
                'recordsPerPage' => $items->recordsPerPage,
                'recordsCount'   => $items->recordsCount,
                'pagesCount'     => $items->pagesCount,
                'base_url'       => '/' . $this->division . '/' . $this->module,
            ];
        }
    }
463533
public function index() {
        if ($this->overrideAction('index')) {
            return;
        }

        $this->paginate = array_merge(array(
            'limit' => 25,
            'order' => array($this->Model->alias . '.' . $this->Model->displayField => 'ASC'),
            'contain' => array_keys($this->Model->belongsTo)
        ), $this->Model->admin['paginate']);

        $this->AdminToolbar->setBelongsToData($this->Model);

        // Filters
        if (!empty($this->request->params['named'])) {
            $this->paginate['conditions'] = $this->AdminToolbar->parseFilterConditions($this->Model, $this->request->params['named']);
        }

        // Batch delete
        if ($this->request->is('post')) {
            if (!$this->Model->admin['batchProcess']) {
                throw new ForbiddenException(__d('admin', 'Batch Access Protected'));
            }

            $action = $this->request->data[$this->Model->alias]['batch_action'];
            $items = $this->request->data[$this->Model->alias]['items'];
            $processed = array();

            foreach ($items as $id) {
                if (!$id) {
                    continue;
                }

                if ($action === 'delete_item') {
                    if ($this->Model->delete($id, true)) {
                        $processed[] = $id;
                    }
                } else {
                    if (call_user_func(array($this->Model, $action), $id)) {
                        $processed[] = $id;
                    }
                }
            }

            $count = count($processed);

            if ($count > 0) {
                $this->AdminToolbar->logAction(ActionLog::BATCH_DELETE, $this->Model, '', sprintf('Processed IDs: %s', implode(', ', $processed)));
                $this->AdminToolbar->setFlashMessage(__d('admin', '%s %s have been processed', array($count, mb_strtolower($this->Model->pluralName))));

                $this->request->data[$this->Model->alias] = array();
            }
        }

        $this->set('results', $this->paginate($this->Model));
        $this->overrideView('index');
    }
982224
private function _setPagination(array $pagination) {
		foreach ($this->_paginationEnvelopeKeys as $key => $name) {
			$this->_pagination[$key] = isset($pagination[$name])
				? $pagination[$name]
				: null;
		}

		return $this;
	}
1289871
public function generateItems()
    {
        // Iterator for pagination pages.
        $j = 1;

        foreach ($this->getLinks() as $index => $link) {
            // Create new pagination item
            $item = new PaginationItem($link);

            // If we on first link and currently active page is not first,
            // we know that this link is for previous pagination item.
            if ($index === 0 && $this->currentPage != 1) {
                $this->markAsPrevious($item);

                continue;
            }

            // If we on last link and currently active page is not last,
            // we know that this link is for next pagination item.
            if (
                $index === $this->getLinksCount(true)
                && $this->currentPage != $this->getLinksCount(true)
            ) {
                $this->markAsNext($item);

                break;
            }

            // We can't use loop index, because sometimes first and
            // last link are for the next and previous item, so use
            // external iterator to index pages of pagination.
            $item->number = $j++;

            // Push pagination pages to items collection.
            $this->items[] = $item;
        }
    }
887447
public function index()
    {
        $page = $this->request->getQuery('page', 1);

        $this->paginate['order'] = ['tag' => 'ASC'];

        //Limit X4
        $this->paginate['limit'] = $this->paginate['maxLimit'] = $this->paginate['limit'] * 4;

        //Sets the cache name
        $cache = sprintf('tags_limit_%s_page_%s', $this->paginate['limit'], $page);

        //Tries to get data from the cache
        list($tags, $paging) = array_values(Cache::readMany(
            [$cache, sprintf('%s_paging', $cache)],
            $this->PostsTags->getCacheName()
        ));

        //If the data are not available from the cache
        if (empty($tags) || empty($paging)) {
            $query = $this->PostsTags->Tags->find('active');
            $tags = $this->paginate($query);

            //Writes on cache
            Cache::writeMany([
                $cache => $tags,
                sprintf('%s_paging', $cache) => $this->request->getParam('paging'),
            ], $this->PostsTags->getCacheName());
        //Else, sets the paging parameter
        } else {
            $this->request = $this->request->withParam('paging', $paging);
        }

        $this->set(compact('tags'));
    }
585847
public function processPaginated(array $pages = [], $perPage = 50, $currentPage = 0)
    {
        $models = [];

        foreach ($pages as $results) {
            // Go through each page and process the results into an objects array.
            $models = array_merge($models, $this->process($results));
        }

        $models = $this->processSort($models)->toArray();

        return $this->newPaginator($models, $perPage, $currentPage, count($pages));
    }
952140
public function build()
    {
        $this->result = new PaginationResult();

        if ($this->total === 0 || $this->limit === 0 || $this->pages === 1) {
            return $this;
        }

        // Lower
        $offset = $this->current - 1;

        // -1 is simple pagination
        if ($this->total === -1) {
            $neighbours = 1;
        } else {
            $neighbours = $this->current - $this->neighbours;
            $neighbours = $neighbours < static::BASE_PAGE ? static::BASE_PAGE : $neighbours;
        }

        for ($i = $offset; $i >= $neighbours; $i--) {
            $this->result->addLower($i);
        }

        if ($neighbours - static::BASE_PAGE >= 2) {
            $this->result->setLess($neighbours - 1);
        }

        $this->result->setPrevious($this->current - 1);

        // First
        if ($this->current - $this->neighbours > static::BASE_PAGE) {
            $this->result->setFirst(static::BASE_PAGE);
        }

        // Higher
        $offset     = $this->current + 1;
        $neighbours = $this->current + $this->neighbours;
        $neighbours = $neighbours > $this->pages ? $this->pages : $neighbours;

        for ($i = $offset; $i <= $neighbours; $i++) {
            $this->result->addHigher($i);
        }

        if ($this->pages - $neighbours > 0) {
            $this->result->setMore($neighbours + 1);
        }

        // Show next button if not last page or for simple pagination
        if ($this->total === -1 || $this->current !== $this->pages) {
            $this->result->setNext($this->current + 1);
        }

        // Last
        if ($this->current + $this->neighbours < $this->pages) {
            $this->result->setLast($this->pages);
        }

        // Current
        $this->result->setCurrent($this->current);

        return $this;
    }
389779
public function toArray() {
        $data = array_map(function ($value) {
            if ($value instanceof ArrayAble) {
                return $value->toArray();
            }
            return $value;
        }, $this->getPage());
        return [
            'paging' => [
                'limit' => $this->getPageSize(),
                'offset' => $this->getIndex(),
                'total' => $this->getTotal(),
                'more' => $this->hasMore()
            ],
            'data' => $data
        ];
    }
756247
public function pagination()
    {
        if ($this->pagination === null) {
            $this->pagination = $this->createPagination();
        }

        return $this->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);
        }
    }
572290
protected function createPageLinks()
    {
        $pageLinks = array();

        if ($this->totalPages > 10) {
            $startRange = $this->page - floor($this->range/2);
            $endRange   = $this->page + floor($this->range/2);

            //Start range
            if ($startRange <= 0) {
                $startRange = 1;
                $endRange += abs($startRange) + 1;
            }

            // End range
            if ($endRange > $this->totalPages) {
                $startRange -= $endRange - $this->totalPages;
                $endRange = $this->totalPages;
            }

            // Range
            $range = range($startRange, $endRange);

            // Add first page
            $this->pageLinks[] = array(
                'page' => 1,
                'uri'  => $this->createUri(1)
            );

            foreach ($range as $page) {
                // Skip for first and last page
                if ($page == 1 or $page == $this->totalPages) {
                    continue;
                }

                $this->pageLinks[] = array(
                    'page' => $page,
                    'uri'  => $this->createUri($page)
                );
            }

            // Add last page
            $this->pageLinks[] = array(
                'page' => $this->totalPages,
                'uri'  => $this->createUri($this->totalPages)
            );
        } else {
            for ($i = 1; $i <= $this->totalPages; $i++) {
                $this->pageLinks[] = array(
                    'page' => $i,
                    'uri'  => $this->createUri($i)
                );
            }
        }
    }
85484
public function index()
    {
        $this->paginate = [
            'contain' => ['CmsTerm', 'CmsContent']
        ];
        $this->set('data', $this->paginate($this->CmsPermission));
        $this->set('_serialize', ['data']);
    }
415222
public function index() {
        $this->paginate = array_merge(array(
            'limit' => 25,
            'contain' => array_keys($this->Model->belongsTo)
        ), $this->Model->admin['paginate']);

        $this->set('results', $this->paginate($this->Model));
    }
748765
public function render()
    {
        $paginationData = $this->paginator->getPages();
        $previous       = $this->getElement()->spawnChild('li');
        $next           = $this->getElement()->spawnChild('li');
        $previousAnchor = $previous->spawnChild('a')->setContent($this->getPrevLabel());
        $nextAnchor     = $next->spawnChild('a')->setContent($this->getNextLabel());

        $this->getElement()->addAttributes($this->getListAttributes());

        $previousAnchor->setAttributes($this->getPreviousAttributes());
        $nextAnchor->setAttributes($this->getNextAttributes());

        if (empty($paginationData->previous)) {
            $previous->addClass('disabled');
        } else {
            $previousAnchor->addAttribute('data-page', $paginationData->previous);
            $previousAnchor->addAttribute('href', $this->getUrl(
                $this->getRoute(),
                array_merge(
                    array('page' => $paginationData->previous),
                    $this->getRouteParams()
                )
            ));
        }

        if (empty($paginationData->next)) {
            $next->addClass('disabled');
        } else {
            $nextAnchor->addAttribute('data-page', $paginationData->next);
            $nextAnchor->addAttribute('href', $this->getUrl(
                $this->getRoute(),
                array_merge(
                    array('page' => $paginationData->next),
                    $this->getRouteParams()
                )
            ));
        }

        if ($this->align) {
            $previous->addClass('previous');
            $next->addClass('next');
        }

        return $this->getElement()->render();
    }