Doctrine table data loader

@param int $page
@param int $limit

@return SimpleTableData
961718
public function dataLoader($page, $limit)
    {
        if ($limit > 0) {
            $this->getQueryBuilder()->setMaxResults($limit);
            $this->getQueryBuilder()->setFirstResult(($page - 1) * $limit);
        }

        $paginator = new Paginator($this->getQueryBuilder());
        $tableData = new SimpleTableData();
        $tableData->setTotalResults(count($paginator));
        $tableData->setResults(iterator_to_array($paginator->getIterator()));

        return $tableData;
    }
875828
private function getPaginator($dql, $limit, $page, array $parameters = [])
    {
        $query = $this->getEntityManager()
            ->createQuery($dql)
            ->setMaxResults($limit)
            ->setFirstResult($limit * $page);

        foreach ($parameters as $param => $value) {
            $query = $query->setParameter($param, $value);
        }

        return new Paginator($query);
    }
828543
public function createPaginator($dql, $page, $limit)
    {
        $offset        = ($page - 1) * $limit;
        $query         = $this->entityManager->createQuery($dql)->setMaxResults($limit)->setFirstResult($offset);
        $paginator     = new Paginator($query);
        $adapter       = new DoctrinePaginatorAdapter($paginator);
        $zendPaginator = new ZendPaginator($adapter);
        $zendPaginator->setCurrentPageNumber($page);
        $zendPaginator->setItemCountPerPage($limit);
        return $zendPaginator;
    }
634753
public function getRootCategoriesPager($page = 1, $limit = 25, $criteria = [])
    {
        $page = 0 === (int) $page ? 1 : (int) $page;

        $queryBuilder = $this->getObjectManager()->createQueryBuilder()
            ->select('c')
            ->from($this->class, 'c')
            ->andWhere('c.parent IS NULL');

        $pager = new Pager($limit);
        $pager->setQuery(new ProxyQuery($queryBuilder));
        $pager->setPage($page);
        $pager->init();

        return $pager;
    }
1307992
public function getByPage(
        int $page = 1,
        int $limit = 10,
        array $where = [],
        array $with = [],
        string $orderBy = null,
        string $order = 'desc'
    ) {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        if ($orderBy) {
            $query = $query->orderBy($orderBy, $order);
        }

        return $query->skip($limit * ($page - 1))
            ->take($limit)
            ->get();
    }
807155
public function getPagedResults($limit = 50, $page = 0)
    {
        $dql = sprintf(self::DQL_GET_USERS, User::class);

        return $this->getPaginator($dql, $limit, $page);
    }
1088052
public function actionList($sort = '', $page = 1, $limit = 20)
    {
        $link_id = \Yii::$app->request->get('link_id');
        $menu_id = \Yii::$app->request->get('menu_id');
        $url_id = \Yii::$app->request->get('url_id');
        $status = \Yii::$app->request->post('status');
        $limit = intval($limit);
        $order = ExtHelpers::getOrder($sort, [
            'link_id',
            'url_id',
        ], [], 'link_id DESC');
        $condition = '1';
        $params = [];
        $tabName = DpAdminMenuUrlRelation::tableName();
        $order = join(',', array_map(function ($value) use ($tabName) {
            return $tabName . '.' . $value;
        }, explode(',', $order)));
        if ($link_id) {
            $condition .= ' and ' . $tabName . '.link_id=:link_id';
            $params[':link_id'] = $link_id;
        }
        if ($menu_id) {
            $condition .= ' and ' . $tabName . '.menu_id=:menu_id';
            $params[':menu_id'] = $menu_id;
        }
        if ($url_id) {
            $condition .= ' and ' . $tabName . '.url_id=:url_id';
            $params[':url_id'] = $url_id;
        }
        if (is_numeric($status)) {
            $condition .= ' and ' . $tabName . '.status=:status';
            $params[':status'] = $status;
        }
        $data = DpAdminMenuUrlRelation::getListByCondition($condition, $params, $order, $page, $limit);
        if ($data['list']) {
            foreach ($data['list'] as &$item) {
                foreach ($item['menuUrl'] as $k => $v) {
                    $item['url.' . $k] = $v;
                }
                unset($item['menuUrl']);
            }
        }

        return [
            'total' => $data['pagination']['totalCount'],
            'list' => $data['list'],
        ];
    }
1348317
public function limit($limit, $page = 1) {
        if($page >= 1) $this->page = $page;
        $this->limit = $limit;

        return $this;
    }
992767
public function loadUrlWildcardsData($offset = 0, $limit = -1)
    {
        $limit = $limit === -1 ? self::MAX_LIMIT : $limit;

        /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */
        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            '*'
        )->from(
            $this->dbHandler->quoteTable('ezurlwildcard')
        )->limit(
            $limit > 0 ? $limit : self::MAX_LIMIT,
            $offset
        );

        $stmt = $query->prepare();
        $stmt->execute();

        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
39257
public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
    {
        $qb = $this->getDocumentManager()->getRepository($this->class)
            ->createQueryBuilder()
            ->sort('createdAt', 'desc');

        $criteria['status'] = $criteria['status'] ?? CommentInterface::STATUS_VALID;
        $qb->field('status')->equals($criteria['status']);

        if (isset($criteria['postId'])) {
            $qb->field('post')->equals($criteria['postId']);
        }

        $pager = new Pager(500); // no limit
        $pager->setQuery(new ProxyQuery($qb));
        $pager->setPage($page);
        $pager->init();

        return $pager;
    }
247959
public function listSites($limit, $page, $canary = false)
    {
        if ($this->connector->getURL() === null) {
            return 'Cannot find site URL from configuration.';
        }
        $params = [
          'limit' => $limit,
          'page' => $page,
          'canary' => $canary,
        ];
        $url = $this->connector->getURL().self::VERSION;

        $response = $this->connector->connecting($url, $params, 'GET');

        if (isset($response->sites)) {
            return $response->sites;
        }

        return $response;
    }
1271749
private function hasNextPage(\Countable $queryResult, $limit, $page, $pageSize)
    {
        $count = $queryResult->count();
        if ($limit && $limit < $count) {
            $count = $limit;
        }

        return $count > ($page * $pageSize);
    }
550873
public function load(int $offset = 0, int $limit = 25): self
    {
        $this->data = array_map(
            function (Location $location) {
                return $this->valueFactory->createBookmark($location);
            },
            $this->bookmarkService->loadBookmarks($offset, $limit)->items
        );

        return $this;
    }
758887
public function loadRecent(
        $limit = ArticleViewDocumentRepository::DEFAULT_LIMIT,
        array $types = null,
        $locale = null,
        $ignoreWebspaces = false
    ) {
        $excludeUuid = null;

        /** @var Request $request */
        $request = $this->requestStack->getCurrentRequest();

        $articleDocument = $request->get('object');
        if ($articleDocument instanceof ArticleDocument) {
            $excludeUuid = $articleDocument->getUuid();

            if (!$types) {
                $types = [$this->getArticleType($articleDocument)];
            }
        }

        if (!$locale) {
            $locale = $request->getLocale();
        }

        $webspaceKey = $this->getWebspaceKey($request, $ignoreWebspaces);

        $articleViewDocuments = $this->articleViewDocumentRepository->findRecent(
            $excludeUuid,
            $limit,
            $types,
            $locale,
            $webspaceKey
        );

        return $this->getResourceItems($articleViewDocuments);
    }
21028
public function getPagedResults($limit = 50, $page = 0)
    {
        $dql = sprintf(self::DQL_GET_VCSS, VersionControlProvider::class);

        return $this->getPaginator($dql, $limit, $page);
    }
157891
public function process(int $page, int $limit, array $filters = [], array $orders = []): Data
    {
        // process filters
        $this->applyFilters($filters);

        // process orders
        $this->applyOrders($orders);

        $data = $this->getSource();

        $total = \count($data);

        // process pages
        $data = \array_slice($data, $limit * ($page - 1), $limit);

        $gridData = new Data($data);
        $gridData->setTotal($total);
        return $gridData;
    }
1272932
public function getPaginatedData($tableName, $page = 1, $limit = 10, $orderAttribute = null, $order = 'ASC')
    {
        Paginator::currentPageResolver(function () use ($page) {
            return $page;
        });
        $data = $this->database->table($tableName);
        if (null === $orderAttribute) {
            return $data->paginate($limit)->toArray();
        }
        return $data->orderBy($orderAttribute, $order)->paginate($limit)->toArray();
    }