Returns a list of the most recently items accessed by the logged user

@param int $limit Restrict result set to this amount
@return array List of recent items accessed by userid
337719
public static function get_recent_items(int $limit = 0) {
        global $USER, $DB;

        $userid = $USER->id;

        $courses = array();
        $recentitems = array();

        if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
            // No access tracking.
            return $recentitems;
        }

        // Determine sort sql clause.
        $sort = 'timeaccess DESC';

        $paramsql = array('userid' => $userid);
        $records = $DB->get_records('block_recentlyaccesseditems', $paramsql, $sort);
        $order = 0;

        // Get array of items by course. Use $order index to keep sql sorted results.
        foreach ($records as $record) {
            $courses[$record->courseid][$order++] = $record;
        }

        // Group by courses to reduce get_fast_modinfo requests.
        foreach ($courses as $key => $items) {
            $modinfo = get_fast_modinfo($key);
            if (!can_access_course($modinfo->get_course(), null, '', true)) {
                continue;
            }
            foreach ($items as $key => $item) {
                // Exclude not visible items.
                if (!$modinfo->cms[$item->cmid]->uservisible) {
                    continue;
                }
                $item->modname = $modinfo->cms[$item->cmid]->modname;
                $item->name = $modinfo->cms[$item->cmid]->name;
                $item->coursename = get_course_display_name_for_list($modinfo->get_course());
                $recentitems[$key] = $item;
            }
        }

        ksort($recentitems);

        // Apply limit.
        if (!$limit) {
            $limit = count($recentitems);
        }
        $recentitems = array_slice($recentitems, 0, $limit);

        return $recentitems;
    }
759354
public function get_entries($start=0, $limit=10) {
        global $DB;

        if ($this->entries === null) {
            if ($sqlarray = $this->get_entry_fetch_sql(false, 'created DESC')) {
                $this->entries = $DB->get_records_sql($sqlarray['sql'], $sqlarray['params'], $start, $limit);
                if (!$start && count($this->entries) < $limit) {
                    $this->totalentries = count($this->entries);
                }
            } else {
                return false;
            }
        }

        return $this->entries;
    }
855327
public function list(int $beginId = 0, int $limit = 50, string $status = 'CHECKING')
    {
        $params = [
            'begin_id' => $beginId,
            'limit' => $limit,
            'status' => $status,
        ];

        return $this->httpPostJson('card/submerchant/batchget', $params);
    }
962674
protected function getListLogOrder(array $limit)
    {
        $conditions = array(
            'limit' => $limit,
            'order_id' => $this->data_order['order_id']
        );

        return (array) $this->order_history->getList($conditions);
    }
1321245
public function findLastUpdated($limit = 5)
    {
        $query = $this->createQueryBuilder('c')
            ->orderBy('c.updatedAt', 'DESC')
            ->where('c.layout = :layout')
            ->setParameter(':layout', false)
            ->setMaxResults($limit)
            ->getQuery();

        return $query->getResult();
    }
461036
public function RecentWorkflowComment($limit = 10)
    {
        if ($actions = $this->getWorkflowHistory($limit)) {
            foreach ($actions as $action) {
                if ($action->Comment != '') {
                    return $action;
                }
            }
        }
    }
1105277
public function read($limit = 0)
    {
        $this->limit($limit);
        $query = $this->buildSelect();
        $this->run($query['query'], $query['param']);

        return $this->next();
    }
663912
private function fetchRangeIds($limit, $start)
    {
        $qb = $this->createFilterAndSortQueryBuilder();
        $qb->select(['t.id', 'e.latest_version']);

        if (null !== $limit) {
            $qb->setFirstResult($start);
            $qb->setMaxResults($limit);
        }

        $rows = $this->connection->fetchAll($qb->getSQL());

        $ids = [];
        foreach ($rows as $row) {
            $ids[$row['id']] = $row['latest_version'];
        }

        return $ids;
    }
756296
public function getOrders($limit = 10)
    {
        if ($Member = Security::getCurrentUser()) {
            $Orders = $Member->Orders()->sort('TransactionDate', 'DESC');

            $list = new PaginatedList($Orders, Controller::curr()->getRequest());
            $list->setPageLength($limit);

            return $list;
        }

        return false;
    }
1216853
public function higherItems($limit = null)
    {
        if ($this->isNotInList()) return null;

        $query = $this->listifyScopedQuery()
            ->where($this->positionColumn(), '<', $this->getListifyPosition())
            ->orderBy($this->getTable() . '.' . $this->positionColumn(), 'DESC');

        if (null !== $limit) {
            $query->take($limit);
        }

        return $query->get();
    }
1345677
public function getUserAgents($limit = 0)
    {
        $counter = 0;

        foreach ($this->loadFromPath() as $test) {
            if ($limit && $counter >= $limit) {
                return;
            }

            yield trim($test->ua);
            ++$counter;
        }
    }
630554
public function getQueryResults($limit = null)
    {
        if (isset($limit)) {
            $this->queryBuilder->setMaxResults($limit);
        }
        
        if (!$this->queryBuilder->getDQLPart('orderBy')) {
            $this->queryBuilder->orderBy('a.createdAt', 'ASC');
        }

        return $this->queryBuilder->getQuery()->getResult();
    }
1268599
public function getItems($offset, $limit)
    {
        $this->cursor->skip($offset);
        $this->cursor->limit($limit);

        return iterator_to_array($this->cursor);
    }
367672
public static function top($field, $limit)
    {
        return static::find()->with('user')->with('profile')->orderBy([$field => SORT_DESC, 'last_visit' => SORT_DESC])->limit($limit)->all();
    }
282693
public function findLastPublications($limit = 5)
    {
        $qb = $this->createQueryBuilder('p');

        $currentTime = new \DateTime();

        $qb->select('p')
            ->where(
                $qb->expr()->lt('p.publicationAt', ':datetime')
            )
            ->andWhere('p.enabled = 1')
            ->orderBy('p.publicationAt', 'DESC')
            ->setMaxResults($limit);

        $qb->setParameter(':datetime', $currentTime);

        return $qb->getQuery()->getResult();
    }
1315973
public function getTopTraderEntityData($limit = 10)
    {
        $topTrader = $this->gameDataService->getTopJobCharacter(1);

        return $topTrader->setMaxResults($limit)
            ->getQuery()
            ->getResult();
    }
309644
protected function getLimit($limit = null)
    {
        if (null === $limit) {
            $limit = $this->getDefaultLimit();
        }

        return $this->validateLimit($limit);
    }