Helper method to get pagination result as objects if pagination is requested.

@param array $rows
@param bool  $pagination
@return array
481610
protected function getDbEntitiesFromRowsPaginated(array $rows, $pagination)
    {
        if ($pagination) {
            $totalRowCount = $this->db->fetchValue('SELECT FOUND_ROWS()');
            return [$this->getDbEntitiesFromRows($rows), $totalRowCount];
        }

        return $this->getDbEntitiesFromRows($rows);
    }
512352
public function process(array $rows)
    {
        foreach ($this->queue as $queue) {
            // Just references
            $relation = $queue[self::PARAM_RELATION];
            $args = $queue[self::PARAM_ARGS];

            switch ($relation) {
                case 'asOneToMany':
                    $relation = new OneToMany($this->db);

                    // Grab values from arguments passed in $db->asOneToMany()
                    $slaveTable = $args[0];
                    $slaveColumnId = $args[1];
                    $alias = $args[2];

                    $rows = $relation->merge($this->getMasterPkName(), $rows, $alias, $slaveTable, $slaveColumnId);
                break;

                case 'asOneToOne':
                    // Grab values from arguments passed in $db->asOneToOne()
                    $column = $args[0];
                    $alias = $args[1];
                    $table = $args[2];
                    $link = $args[3];

                    $relation = new OneToOne($this->db);
                    $rows = $relation->merge($rows, $column, $alias, $table, $link);
                break;

                case 'asManyToMany':
                    // Grab values from arguments passed in $db->asManyToMany()
                    $alias = $args[0];
                    $junction = $args[1];
                    $column = $args[2];
                    $table = $args[3];
                    $pk = $args[4];
                    $columns = $args[5];

                    $relation = new ManyToMany($this->db);
                    $rows = $relation->merge($this->getMasterPkName(), $alias, $rows, $junction, $column, $table, $pk, $columns);
                break;
            }
        }

        $this->clearQueue();
        return $rows;
    }
280423
private function processPaginatedResults($pages, $perPage = 50, $currentPage = 0)
    {
        // Make sure we have at least one page of results
        if (count($pages) > 0) {
            $objects = [];

            // Go through each page
            foreach ($pages as $results) {
                // Get the entries for each page
                $entries = $this->connection->getEntries($results);

                /*
                 * If we've retrieved entries, we'll go through
                 * each and construct the entry attributes, and
                 * put them all inside the objects array
                 */
                if (is_array($entries) && array_key_exists('count', $entries)) {
                    for ($i = 0; $i < $entries['count']; $i++) {
                        $entry = $this->newLdapEntry($entries[$i], $this->connection);

                        $objects[] = $entry->getAttributes();
                    }
                }
            }

            /*
             * If we're sorting, we'll process all of
             * our results so it's sorted correctly
             */
            if (!empty($this->sortByField)) {
                $objects = $this->processSortBy($objects);
            }

            // Return a new Paginator instance
            return $this->newPaginator($objects, $perPage, $currentPage, count($pages));
        }

        // Looks like we don't have any results, return false
        return false;
    }
158647
public function extractGroupsFromRows(array $rows)
    {
        $groups = array();

        foreach ($rows as $row) {
            $group = new Group();
            $group->id = (int)$row['id'];
            $group->created = (int)$row['created'];
            $group->creatorId = (int)$row['creator_id'];
            $group->modified = (int)$row['modified'];
            $group->modifierId = (int)$row['modifier_id'];
            $group->identifier = $row['name'];

            $groups[] = $group;
        }

        return $groups;
    }
1012504
public function getPages(Paginator $paginator, $pageRange = null)
    {
        if ($pageRange === null) {
            $pageRange = $paginator->getPageRange();
        }

        $pageNumber = $paginator->getCurrentPageNumber();
        $pageCount  = count($paginator);

        if ($pageRange > $pageCount) {
            $pageRange = $pageCount;
        }

        $delta = ceil($pageRange / 2);

        if ($pageNumber - $delta > $pageCount - $pageRange) {
            $lowerBound = $pageCount - $pageRange + 1;
            $upperBound = $pageCount;
        } else {
            if ($pageNumber - $delta < 0) {
                $delta = $pageNumber;
            }

            $offset     = $pageNumber - $delta;
            $lowerBound = $offset + 1;
            $upperBound = $offset + $pageRange;
        }

        return $paginator->getPagesInRange($lowerBound, $upperBound);
    }
1211730
protected static function indexByChild($rows)
    {
        $child = [];

        foreach ($rows as $row) {
            $child[(int)$row['child_id']] = (int) $row['parent_id'];
        }

        return $child;
    }
79296
public function read(Paginator $paginator = NULL) {
		if ($this->hasNonSaveEntity() === FALSE) {
			$this->rows = array();
		}
		$this->selection = $this->buildSql($paginator);
		return $this;
	}
356843
public function buildRawPaginator($paginator, $results, $perPage)
	{
		// For queries which have a group by, we will actually retrieve the entire set
		// of rows from the table and "slice" them via PHP. This is inefficient and
		// the developer must be aware of this behavior; however, it's an option.
		$start = ($paginator->getCurrentPage() - 1) * $perPage;

		$sliced = array_slice($results, $start, $perPage);

		return $paginator->make($sliced, count($results), $perPage);
	}
1333618
protected function paginate($qb, $pageOpts, $filters = array())
    {
        $db = $this->db;

        $total = count($db->fetchAll($qb->getSQL(), $filters));

        if (isset($pageOpts['start'])) {
            $qb->setFirstResult(isset($pageOpts['start']) ? $pageOpts['start'] : 0)
                ->setMaxResults(isset($pageOpts['limit']) ? $pageOpts['limit'] : 200);
        }

        $result = $db->fetchAll($qb->getSQL(), $filters);

        return array(
            'total' => $total,
            'results' => $result
        );
    }
774714
public function extractUserPreferencesFromRows(array $rows): array
    {
        $userPreferences = [];
        foreach ($rows as $row) {
            $userPreferences[] = $this->extractUserPreferenceFromRow($row);
        }

        return $userPreferences;
    }
42166
public function fetchAll($paginated = false)
    {
        if ($paginated) {
            $paginatorAdapter   = new DbTableGateway($this->tableGateway);
            $paginator          = new Paginator($paginatorAdapter);

            return $paginator;
        }

        $resultSet = $this->getTableGateway()->select();

        return $resultSet;
    }
980339
public function getCountForPagination($columns = ['*'])
    {
        $results = $this->runPaginationCountQuery($columns);

        // Once we have run the pagination count query, we will get the resulting count and
        // take into account what type of query it was. When there is a group by we will
        // just return the count of the entire results set since that will be correct.
        if (isset($this->groups)) {
            return count($results);
        }
        if (!isset($results[0])) {
            return 0;
        }
        if (is_object($results[0])) {
            return (int) $results[0]->aggregate;
        }

        return (int) array_change_key_case((array) $results[0])['aggregate'];
    }
1251707
public function getRes($pageColumns = null){
      $page = array();
      $pageColumns = empty($pageColumns) && (!is_array($pageColumns)) ? $this->pageColumnsRes : $pageColumns;
      if (empty($pageColumns)) {
          $page = $this->pageArray;
      }else{
          $page = array();
          foreach ($pageColumns as $index => $key) {
              $page[$key] = $this->pageArray[$key];
          }
      }
      $lists = empty($this->lists)?array():$this->lists;
      return array(
          'lists'=>$lists,
          'page'=>$page
      );
  }
812748
public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
    {
        return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
    }
1133375
public function extractURLsFromRows(array $rows)
    {
        $urls = [];

        foreach ($rows as $row) {
            $url = new URL();
            $url->id = (int)$row['id'];
            $url->url = $row['url'];
            $url->originalUrlMd5 = $row['original_url_md5'];
            $url->isValid = (bool)$row['is_valid'];
            $url->lastChecked = (int)$row['last_checked'];
            $url->created = (int)$row['created'];
            $url->modified = (int)$row['modified'];

            $urls[] = $url;
        }

        return $urls;
    }
1209611
public function getPaginated($limit = 1, $fields = null, $sqlQuery = false)
    {
        $sql = $this->buildQuery('select', $fields, ['count'=>null, 'field'=>'num']);
        $result = $this->executeQuery($sql);
        $row = $result->fetch_array(MYSQLI_ASSOC);
        $total = $row['num'];
        if($total == 0 && $sqlQuery == false) {
            return [];
        }
        $this->pagination->initialize($limit, $total);
        return $this->limit($limit, $this->pagination->getStartPoint())->getAll($fields, $sqlQuery);
    }
667072
protected function fillRows(array $rows)
    {
        $row = [];
        $seriesOptions = $this->seriesOptions();
        foreach ($seriesOptions as $serieId => $serieOpts) {
            $row[$serieId] = '0';
        }

        $starts = clone($this->startDate());
        $ends = $this->endDate();
        while ($starts < $ends) {
            $x = $starts->format($this->dateFormat());
            if (!isset($rows[$x])) {
                $rows[$x] = $row;
            }
            $starts->add($this->dateInterval());
        }
        ksort($rows);
        return $rows;
    }