Get pagination index
@param unknown $optionsPagination : array with the info of pagination (nb results, nb results per page, current page etc)
@return $indexRange = range of the index to display
545130
private function getPaginationIndex($optionsPagination = array())
    {
        $nbResult = 0;
        $nbPages = 0;
        $currentPage = 0;
        $nextPage = 0;
        $previousPage = 0;
        $nbResultPerPage = 10;
        $offset = 4;
        $indexToDisplay = array();

        //Setting vars
        if (isset($optionsPagination['nbResult'])) {
            $nbResult =$optionsPagination['nbResult'];
        }
        if (isset($optionsPagination['nbPages'])) {
            $nbPages = $optionsPagination['nbPages'];
        }
        if (isset($optionsPagination['currentPage'])) {
            $currentPage = $optionsPagination['currentPage'];
        }
        if (isset($optionsPagination['nextPage'])) {
            $nextPage = $optionsPagination['nextPage'];
        }
        if (isset($optionsPagination['previousPage'])) {
            $previousPage = $optionsPagination['previousPage'];
        }
        if (isset($optionsPagination['nbResultPerPage'])) {
            $nbResultPerPage = $optionsPagination['nbResultPerPage'];
        }
        if (isset($optionsPagination['offset'])) {
            $offset = $optionsPagination['offset'];
        }

        //Processing firstpage index
        if ($nbPages<=(2*$offset+1)) {
            $indexToDisplay['firstPage'] = 0;
            $indexToDisplay['lastPage'] = $nbPages-1;
        } else {
            if (($currentPage - $offset)<= 0) {
                $indexToDisplay['firstPage'] = 0;
            } else {
                $indexToDisplay['firstPage'] = $currentPage - $offset - 1;
            }

            //Processing lastpage index
            if (($currentPage+$offset)>=$nbPages) {
                $indexToDisplay['lastPage'] = $nbPages-1;
            } else {
                $indexToDisplay['lastPage']=$currentPage+$offset-1;
            }

            // Adjusting first page index or last page index if nb of previous pages are not balanced compared to next ones
            // Adding the extra missing page to a side or another to really have 9 pages (aka 2*offset+1)
            if ((2*$offset+1) > ($indexToDisplay['lastPage'] - $indexToDisplay['firstPage'] )) {
                //Calculating the offset to add to first or last page
                $offsetAdd=(2*$offset+1) - ($indexToDisplay['lastPage'] - $indexToDisplay['firstPage'] );

                if ($indexToDisplay['firstPage'] == 0) {
                    $indexToDisplay['lastPage']+=$offsetAdd-1;
                } else {
                    $indexToDisplay['firstPage']-=$offsetAdd-1;
                }
            }
        }

        $indexRange = array();
        for ($i = $indexToDisplay['firstPage']; $i <= $indexToDisplay['lastPage']; $i++) {
            $indexRange[] = $i;
        }
        $indexToDisplay['range'] = $indexRange;
        return $indexRange;
    }
1306426
protected function getLinks($options = array())
	{
		global $wp_query, $wp_rewrite;

		//use the query for paging
		$current = $wp_query->query_vars['paged'] > 1 ? $wp_query->query_vars['paged'] : 1;

		//set the "paginate_links" array to do what we would like it it.
		//Check the codex for examples http://codex.wordpress.org/Function_Reference/paginate_links
		$pagination = array(
			'base'     => @add_query_arg('paged', '%#%'),
			//'format' => '',
			'showall'  => false,
			'end_size' => $this->endSize,
			'mid_size' => $this->midSize,
			'total'    => $wp_query->max_num_pages,
			'current'  => $current,
			'type'     => 'array',
			'prev_text' => $this->defaults['prev_text'],
			'next_text' => $this->defaults['next_text'],
		);

		//build the paging links
		if ($wp_rewrite->using_permalinks())
		{
			$pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
		}

		//more paging links
		if (!empty($wp_query->query_vars['s']))
		{
			$pagination['add_args'] = array('s' => urlencode(get_query_var('s')));
		}

		$aLinks = paginate_links($pagination);

		if (!$aLinks)
		{
			return null;
		}

		return $this->parseWpLinks($aLinks);

	}
640015
public function options($options)
    {
        if (!$options) {
            return $this;
        }

        if (isset($options['limit'])) {
            $this->limit($options['limit'], isset($options['offset']) ? $options['offset'] : 0);
        } elseif (isset($options['size'])) {
            $this->page($options['size'], isset($options['page']) ? $options['page'] : null);
        }

        if (isset($options['distinct'])) {
            $this->distinct($options['distinct']);
        }

        if (isset($options['order'])) {
            $this->orderBy($options['order']);
        }

        if (isset($options['index'])) {
            $this->indexBy($options['index']);
        }

        if (isset($options['with'])) {
            $this->with($options['with']);
        }

        if (isset($options['group'])) {
            $this->groupBy($options['group']);
        }

        return $this;
    }
676341
protected function isPageInRange(LengthAwarePaginator $paginator)
    {
        return $paginator->currentPage() <= ceil($paginator->lastItem() / $paginator->perPage());
    }
103563
public function setPager(array $options)
    {
        $pager = $this->getPager($options);
        $this->data['_pager'] = $pager['rendered'];
        return $pager['limit'];
    }
803402
protected function jumpingBuildPagesRange(IPaginator $paginator, $pagesCountInRange)
    {
        $currentPage = $paginator->getCurrentPage();
        $pagesCount = $paginator->getPagesCount();
        $currentRange = ceil($currentPage / $pagesCountInRange);
        $ragesCount = ceil($pagesCount / $pagesCountInRange);
        if ($currentRange == 1) {
            $rangeEnd = $pagesCount < $pagesCountInRange ? $pagesCount : $pagesCountInRange;

            return range(1, $rangeEnd);
        }
        $rangeStart = ($currentRange - 1) * $pagesCountInRange + 1;
        if ($currentRange < $ragesCount) {
            return range($rangeStart, $rangeStart + $pagesCountInRange - 1);
        } else {
            return range($rangeStart, $pagesCount);
        }
    }
1206156
public function getList($lang, $pagination)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Media', 'read')) {
            return $this->noPermission();
        }
        $list = Pagination::infiniteScrollPagination('media', $pagination, Media::$infinitPaginationShow);
        $results = [
            'list'               => $list,
            'count'              => $list->count(),
            'pagination'         => $pagination,
            'imagesExtensions'   => config('media.image_extensions'),
            'videoExtensions'    => config('media.video_extensions'),
            'videoIconUrl'       => config('media.video_icon_url'),
            'audioExtensions'    => config('media.video_extensions'),
            'audioIconUrl'       => config('media.audio_icon_url'),
            'documentExtensions' => config('media.document_extensions'),
            'documentIconUrl'    => config('media.document_icon_url'),
        ];

        $results['events'] = Event::fire('media:pre_update', [$results]);

        return $results;
    }
187125
public function getPaginateOptions($excludeFields = null) {
		$page = 1;
		$limit = 20;
		$fields = $this->getListLocalFields($excludeFields);
		$order = $this->getOrderFiled();
		$contain = $this->getListContain('Subordinate');
		$result = compact(
			'page',
			'limit',
			'fields',
			'order',
			'contain'
		);

		return $result;
	}
528291
protected function paginate($collection, $options = array(), $dataRenderer = null)
    {
        return (new Paginator())->paginate($collection, $options, $dataRenderer);
    }
491661
public function getPagination(): array
    {
        if ($this->pagination === null) {
            $this->pagination = $this->setPagination();
        }

        return $this->pagination;
    }
1283292
public function actionIndex($excludeFieldsPaginate = []) {
		if (!$this->_controller->Components->loaded('Paginator')) {
			$this->_controller->Paginator = $this->_controller->Components->load('Paginator');
			$this->_controller->Paginator->initialize($this->_controller);
		}
		if (!$this->_controller->Components->loaded('Filter')) {
			$this->_controller->Filter = $this->_controller->Components->load('CakeTheme.Filter');
			$this->_controller->Filter->initialize($this->_controller);
		}

		$excludeFieldsPaginateDefault = [
			'department_id'
		];
		$excludeFieldsPaginateFull = array_unique(array_merge($excludeFieldsPaginateDefault, (array)$excludeFieldsPaginate));
		$this->_controller->Paginator->settings = $this->_modelEmployee->getPaginateOptions($excludeFieldsPaginateFull);
		$conditions = $this->_controller->Filter->getFilterConditions();
		$employees = $this->_controller->Paginator->paginate('Employee', $conditions);
		if (empty($employees)) {
			$this->_controller->Flash->information(__d('cake_ldap', 'Employees not found'));
		}

		$filterOptions = $this->_modelEmployee->getFilterOptions();
		$fieldsConfig = $this->_modelEmployee->getFieldsConfig();
		$isTreeReady = $this->_modelConfigSync->getFlagTreeSubordinateEnable();
		$pageHeader = __d('cake_ldap', 'Index of employees');
		$headerMenuActions = [
			[
				'fas fa-sync-alt',
				__d('cake_ldap', 'Synchronize information with LDAP server'),
				['controller' => 'employees', 'action' => 'sync', 'prefix' => false],
				[
					'title' => __d('cake_ldap', 'Synchronize information of employees with LDAP server'),
					'data-toggle' => 'request-only',
				]
			]
		];
		if ($isTreeReady) {
			$headerMenuActions[] = [
				'fas fa-sitemap',
				__d('cake_ldap', 'Tree of employees'),
				['controller' => 'employees', 'action' => 'tree', 'prefix' => false],
				['title' => __d('cake_ldap', 'Tree view of employees')]
			];
		}
		$breadCrumbs = $this->_modelEmployee->getBreadcrumbInfo();
		$breadCrumbs[] = __d('cake_ldap', 'Index');
		$this->_controller->ViewExtension->setRedirectUrl(true, 'employee');

		$this->_controller->set(compact(
			'employees',
			'filterOptions',
			'fieldsConfig',
			'isTreeReady',
			'pageHeader',
			'headerMenuActions',
			'breadCrumbs'
		));
	}
1254198
public function pagination( $prefs = array() ) {
		if ( !$this->pagination && is_a($this->queryIterator, 'Timber\QueryIterator') ) {
			$this->pagination = $this->queryIterator->get_pagination($prefs, $this->get_query());
		}
		return $this->pagination;
	}
379495
public function getPager(array $options = array())
    {
        $options += array(
            'query' => $this->getFilterQuery(),
            'limit' => $this->config('list_limit', 20)
        );

        return array(
            'rendered' => $this->getWidgetPager($options),
            'limit' => $this->pager->getLimit()
        );
    }
619650
public function getPagination()
    {
        if ($this->perPage == 'all' || ! $this->totalCount)
        {
            return '<span class="pagination">&nbsp;</span>';
        }

        ob_start();
        // calculate advance shortcut
        // Advance shortcut
        if ($this->pageJump)
        {
            $this->jumpNext = min($this->page  + $this->pageJump, $this->lastPage);
            $this->jumpPrev = max($this->page  - $this->pageJump, $this->firstPage);
        }

        $pagi_from = max($this->page - ceil($this->pageJump / 2), $this->firstPage);
        $pagi_to = min($pagi_from + $this->pageJump, $this->lastPage);

        ?>
        <ul class="pagination pagination--offset pull-right">
            <?php
            $this->createPagiList(1, '<i class="icon-double-angle-left"></i> first', $this->page == $this->firstPage);

            if ($this->pageJump)
            {
                $this->createPagiList($this->jumpPrev, "<i class=\"icon-angle-left\"></i> - {$this->pageJump}", $this->jumpPrev == $this->firstPage);
            }

            $this->createPagiList($this->prevPage,'<i class="icon-angle-left"></i> prev',$this->page == $this->firstPage);

            for($i = $pagi_from;$i <= $pagi_to; $i++)
            {
                $this->createPagiList($i,$i,false,($i == $this->page));
            }

            $this->createPagiList($this->nextPage, 'next <i class="icon-angle-right"></i>', $this->page == $this->lastPage);

            if ($this->pageJump)
            {
                $this->createPagiList($this->jumpNext, "{$this->pageJump} + <i class=\"icon-angle-right\"></i>", $this->jumpNext == $this->lastPage);
            }

            $this->createPagiList($this->lastPage, 'last <i class="icon-double-angle-right"></i>',$this->lastPage == $this->page);
            ?>
        </ul>

        <?php
        return ob_get_clean();
    }
649132
protected function slidingBuildPagesRange(IPaginator $paginator, $pagesCountInRange)
    {
        $currentPage = $paginator->getCurrentPage();
        $pagesCount = $paginator->getPagesCount();
        $rangeStart = $currentPage - ceil($pagesCountInRange / 2);
        $lastPossibleStart = $pagesCount - $pagesCountInRange + 1;
        if ($rangeStart <= 0) {
            $rangeEnd = $pagesCountInRange >= $pagesCount ? $pagesCount : $pagesCountInRange;

            return range(1, $rangeEnd);
        } elseif ($rangeStart >= $lastPossibleStart) {
            $lastPossibleStart = $lastPossibleStart ?: 1;

            return range($lastPossibleStart, $pagesCount);
        } else {
            return range($rangeStart + 1, $rangeStart + $pagesCountInRange);
        }
    }
745515
protected function resolvePerPage($paginate)
    {
        if ($perPage = request($this->perPageName)) {
            if (is_array($paginate)) {
                $paginate['arguments'][0] = (int) $perPage;

                return $paginate['arguments'];
            }

            $this->perPage = (int) $perPage;
        }

        if (isset($paginate['arguments'][0])) {
            return $paginate['arguments'];
        }

        if ($name = $this->grid->getName()) {
            return [$this->perPage, ['*'], "{$name}_page"];
        }

        return [$this->perPage];
    }
1325351
public function getPaginator($params) 
	{
        $limit = isset($params['limit']) ? (int) $params['limit'] : 10;
        $offset = isset($params['offset']) ? (int) $params['offset'] : 0;
        
        // @todo (re)setting limit and offset, make it better...
        $params['limit'] = $limit;
        $params['offset'] = $offset;
		
		// must check for limit
		//$page = isset($params['page']) ? (int)$params['page'] : 1;
		
		$fields = isset($params['field']) ? array_values($params['field']) : array();
		$values = isset($params['value']) ? array_values($params['value']) : array();
		
		$page = $params['offset'] / $params['limit'] + 1;
		$isLoggedUserSearch = false;
		$isFullSearch = false;
		$userId = '';
		foreach($fields as $key => $field) {
			switch($field) {
				case 'account':
					$isLoggedUserSearch = true;
					$userId = $values[$key];
					break;
			}
		}
		if($isLoggedUserSearch) {
			    //throw new \Exception('WIP hashid');
			$qb = $this->_em->createQueryBuilder();
			$qb->select(array('a'));
			$qb->from($this->getEntityName(), 'a');
			//$qb->andWhere($qb->expr()->eq('a.user', ':paramUserId'));
			$qb->andWhere($qb->expr()->eq('SHA1(CONCAT_WS(\'\', \'neo\', a.user, \'bazaar\'))', ':paramUserId'));
			$qb->andWhere($qb->expr()->eq('a.documentType', ':paramDocumentType'));
			$qb->andWhere($qb->expr()->neq('a.state', ':paramDocumentState'));
			$qb->setParameter('paramUserId', $userId);
			$qb->setParameter('paramDocumentType', Document::DOCUMENT_TYPE_CLASSIFIED);
			$qb->setParameter('paramDocumentState', Document::DOCUMENT_STATE_DELETED);
			//$qb->addOrderBy('COALESCE(a.dateEdit, a.dateInsert)', 'DESC');
			//$qb->addOrderBy('a.documentId', 'DESC');
			$qb->addOrderBy('a.dateEdit', 'DESC');
			$query = $qb->getQuery();
			$query->setFirstResult($params['offset']);
			$query->setMaxResults($params['limit']);
			$paginatorAdapter = new DoctrinePaginatorAdapter(new DoctrinePaginator($query));
			
			
// 			$paginator = new DoctrinePaginator($query, $fetchJoinCollection = true);
// 			$result = array();
// 			foreach($paginator as $p) {
// 				$result[] = $p->getDocumentId();
// 			}
// 			$result = $query->getResult();
// 			$paginatorAdapter =  new RazorPaginator(
// 				$result,
// 				count($paginator)
// 			);
		} else {
			$query = $this->fetchGridData($params);
			$query->setFirstResult(0);
			$query->setMaxResults($params['limit']);
			$paginatorAdapter =  new RazorArrayAdapter(
				$query->getResult(),
				$this->getSphinxClient()->getLastSearchCount()
			);
			//$paginatorAdapter = new DoctrinePaginatorAdapter(new DoctrinePaginator($query));
		}
		
		
		$paginator = new Paginator($paginatorAdapter);
		$paginator->setCurrentPageNumber($page);
		$paginator->setDefaultItemCountPerPage($params['limit']);
		
		return $paginator;
	}