Get pagination data from main query
@return array Pagination data
331436
public static function getPaginationData()
    {
        global $wp_query;

        $data = array();

        $data['postType'] = $wp_query->query['post_type'];
        $data['postCount'] = $wp_query->post_count;
        $data['postTotal'] = $wp_query->found_posts;
        $data['pageIndex'] = ($wp_query->query['paged']) ? intval($wp_query->query['paged']) : 1;
        $data['pageTotal'] = $wp_query->max_num_pages;

        return $data;
    }
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'));
    }
1003730
public function getDataAction()
    {
        $request           = $this->getRequest();
        $dataCount         = 0;
        $dataFilteredCount = 0;
        $tableData         = array();
        $draw              = 0;
        if($request->isPost()) {

            $post           = get_object_vars($request->getPost());
            $columns        = array_keys($this->tool()->getColumns());
            $draw           = (int) $post['draw'];
            $selColOrder    = $columns[(int) $post['order'][0]['column']];
            $orderDirection = isset($post['order']['0']['dir']) ? strtoupper($post['order']['0']['dir']) : 'ASC';
            $searchValue    = isset($post['search']['value']) ? $post['search']['value'] : null;
            $searchableCols = $this->tool()->getSearchableColumns();
            $start          = (int) $post['start'];
            $length         = (int) $post['length'];

            $data              = $this->themeTable()->getData($searchValue, $searchableCols, $selColOrder, $orderDirection, $start, $length)->toArray();
            $dataCount         = $this->themeTable()->getTotalData();
            $dataFilteredCount = $this->themeTable()->getTotalFiltered();
            $tableData         = $data;

            for($ctr = 0; $ctr < count($tableData); $ctr++) {
                // apply text limits
                foreach($tableData[$ctr] as $vKey => $vValue) {
                    $tableData[$ctr][$vKey] = $this->tool()->limitedText($vValue, 80);
                }

                $tableData[$ctr]['DT_RowId'] = $tableData[$ctr]['pros_theme_id'];
            }
        }

        $response = [
            'draw'            => $draw,
            'data'            => $tableData,
            'recordsFiltered' => $dataFilteredCount,
            'recordsTotal'    => $dataCount
        ];

        return new JsonModel($response);
    }
1195913
public function query(): array
    {
        $comments = Comment::with([
            'post' => function ($query) {
                $query->select('id', 'type', 'slug');
            },
        ])->latest()
            ->paginate();

        return [
            'comments' => $comments,
        ];
    }
753544
protected function _getCurrentPages()
    {
        $ret = array();
        $p = $this->getData()->getPage();
        while ($p) {
            $ret[] = $p;
            $p = $p->getParentPage();
        }
        return $ret;
    }
317652
public function toQueryParts(): array
    {
        if (empty($this->startIndex) && empty($this->endIndex)) {
            return [];
        }

        // @todo PHP appears to leak memory in both json_decode() and unserialize() with large result sets. Our best
        // guess is that some amount of data causes PHP to allocate larger chunks, and perhaps that class of memory
        // isn't ever a candidate for garbage collection. In general, paging over result sets (like in
        // \Lullabot\Mpx\Tests\Functional\DataService\Media\MediaQueryTest) should use a constant amount of memory per
        // page. 250 comes from tests on macOS with PHP 7.2 - going to 300 results causes an obvious memory leak.
        if ($this->endIndex - $this->startIndex > 250) {
            @trigger_error('PHP may leak memory with large result pages. Consider reducing the number of results per page.', E_USER_DEPRECATED);
        }

        return ['range' => $this->startIndex.'-'.$this->endIndex];
    }
1197064
function paginate() {
        //Check for valid mysql connection
         
         
        //Find total number of rows
        $all_rs = $this->conn->prepare( $this->sql );
        $all_rs->execute();
         
        if (! $all_rs) {
            if ($this->debug)
                echo "SQL query failed. Check your query.<br /><br />Error Returned: " . mysql_error();
            return false;
        }
        $this->total_rows = $all_rs->rowCount();
         
        //Return FALSE if no rows found
        if ($this->total_rows == 0) {
            if ($this->debug)
                echo "Query returned zero rows.";
            return FALSE;
        }
         
        //Max number of pages
        $this->max_pages = ceil($this->total_rows / $this->rows_per_page );
        if ($this->links_per_page > $this->max_pages) {
            $this->links_per_page = $this->max_pages;
        }
         
        //Check the page value just in case someone is trying to input an aribitrary value
        if ($this->page > $this->max_pages || $this->page <= 0) {
            $this->page = 1;
        }
         
        //Calculate Offset
        $this->offset = $this->rows_per_page * ($this->page - 1);
         
        //Fetch the required result set
        $query = $this->sql . " LIMIT {$this->rows_per_page} OFFSET {$this->offset}";

        $rs = $this->conn->prepare( $query );
        $rs->execute();
         
        if (! $rs) {
            if ($this->debug)
                echo "Pagination query failed. Check your query.<br /><br />Error Returned: " . mysql_error();
            return false;
        }

        return $rs;
    }
165064
public function getRows()
    {
        $query = $this->getQuery();
        
        if (!empty($this->columns)) {
            $query->select(implode(', ', $this->columns));
        }
        
        foreach ($this->sort as $key => $value) {
            $query->sortBy($key, $value);
        }
        
        if ($this->range) {
            $query->limit($this->start, $this->range);
        }
        
        if (!empty($this->group)) {
            $query->groupBy($this->group);
        }
        
        return $this->database->query($query, $this->database->getBinds());
    }
1021675
public function getData()
    {
        $limit = $this->getLimit();
        $this->setHeaders();
        $page  = $this->getPage();
        if ($page > 0) {
            $page-=1;
        }
        return $this->getDataSource()->limit($limit)->offset($limit * $page)->getAll();
    }
11300
public function getArrayCopy()
    {
        $results = array_map(function ($entity) {
            return $entity->getArrayCopy();
        }, $this->entities);

        if (! $this->paginationData) {
            return $results;
        } else {
            $data = $this->paginationData->getArrayCopy();
            $data['results'] = $results;
            return $data;
        }
    }
51446
protected function getData()
	{
		if ( \Request::has('search_value') ) {
			$value = \Request::get('search_value');
			$permissions = Permission::where('name', 'LIKE', '%'.$value.'%')
				->orWhere('slug', 'LIKE', '%'.$value.'%')
				->orWhere('description', 'LIKE', '%'.$value.'%')
				->orderBy('name')->paginate( config('watchtower.pagination.permissions', 15) );
			session()->flash('search_value', $value);
		} else {
			$permissions = Permission::orderBy('name')->paginate( config('watchtower.pagination.permissions', 15) );
			session()->forget('search_value');		
		}

		return $permissions;
	}
1165798
protected function _paginationFilter() {
		$conditions = array_filter($this->request->query, function($var) {
			return $var !== '';
		});
		unset($conditions['url'], $conditions['batch_conditions'], $conditions['batch_action']);
		foreach (array('started', 'created', 'stopped', 'modified') as $dateRangeField) {
			if (empty($conditions[$dateRangeField])) {
				continue;
			}
			if (preg_match('/^(?P<start>.*)\s(-|to)\s(?P<end>.*)$/is', $conditions[$dateRangeField], $range)) {
				$conditions[$dateRangeField . ' BETWEEN ? AND ?'] = array(
					(new DateTime($range['start']))->format('Y-m-d H:i:s'),
					(new DateTime($range['end']))->format('Y-m-d H:i:s')
				);
			}
			unset($conditions[$dateRangeField]);
		}
		return $conditions;
	}
408551
public function getVisitedPages()
    {
        $dates = $this->getStartEndDate();

        $items = LaravelAnalytics::getMostVisitedPagesForPeriod($dates['start'], $dates['end']);

        return $items;
    }
1186794
public function current()
    {
        // Getting the first page
        if ($this->currentPage === null) {
            $data = $this->api->searchWithBody($this->body);
            if (isset($data['next_page_token'])) {
                $this->nextPage = $data['next_page_token'];
            }

            return $data;
        }

        // Getting another page
        $body = array_merge($this->body, ['pagetoken' => $this->currentPage]);
        $data = $this->api->searchWithBody($body);
        if (isset($data['next_page_token'])) {
            $this->nextPage = $data['next_page_token'];
        } else {
            $this->nextPage = null;
        }

        return $data;
    }
508418
public function paginate()
    {
        $count = count($this->_model->all());
        $this->_totalPages = ceil($count / $this->_limit);
        $page_at_offset = floor($this->_page + 1 / $this->_limit);
        $this->_offset = ($page_at_offset - 1) * $this->_limit;

        $this->_results = $this->_model->select($this->_capsule, $this->_limit, $this->_offset);

        return $this;
    }
289511
private function getPreviousPageQueryCriteria() {
        $start = $this->getIndexCriteria()->getOffset() - $this->getIndexCriteria()->getLimit();
        if($start < 0) {
            $start = 0;
        }
        return array(
            'start' => $start,
            'count' => $this->getIndexCriteria()->getLimit()
        );
    }
836991
public function getPaginationData(ServiceManager $sm, $paginator, $data, $routeName, $routeParams, $queryParams) 
	{
		$mainService = $sm->get('neobazaar.service.main');
		return array(
			'data' => $data,
			'paginationData' => Json::decode($mainService->getView()->paginationControl(
				$paginator,
				'Sliding',
				array('pagination/paginatorjson', 'Document'),
				array(
					'route' => $routeName,
					'params' => $routeParams, 
					'query' => $queryParams
				)
			))
		);
	}