Return matched comments

@param  int $page
@return array
62
public function get_comments($page = '') {
        global $DB, $CFG, $USER, $OUTPUT;
        if (!$this->can_view()) {
            return false;
        }
        if (!is_numeric($page)) {
            $page = 0;
        }
        $params = array();
        $perpage = (!empty($CFG->commentsperpage))?$CFG->commentsperpage:15;
        $start = $page * $perpage;
        $ufields = user_picture::fields('u');

        list($componentwhere, $component) = $this->get_component_select_sql('c');
        if ($component) {
            $params['component'] = $component;
        }

        $sql = "SELECT $ufields, c.id AS cid, c.content AS ccontent, c.format AS cformat, c.timecreated AS ctimecreated
                  FROM {comments} c
                  JOIN {user} u ON u.id = c.userid
                 WHERE c.contextid = :contextid AND
                       c.commentarea = :commentarea AND
                       c.itemid = :itemid AND
                       $componentwhere
              ORDER BY c.timecreated DESC";
        $params['contextid'] = $this->contextid;
        $params['commentarea'] = $this->commentarea;
        $params['itemid'] = $this->itemid;

        $comments = array();
        $formatoptions = array('overflowdiv' => true, 'blanktarget' => true);
        $rs = $DB->get_recordset_sql($sql, $params, $start, $perpage);
        foreach ($rs as $u) {
            $c = new stdClass();
            $c->id          = $u->cid;
            $c->content     = $u->ccontent;
            $c->format      = $u->cformat;
            $c->timecreated = $u->ctimecreated;
            $c->strftimeformat = get_string('strftimerecentfull', 'langconfig');
            $url = new moodle_url('/user/view.php', array('id'=>$u->id, 'course'=>$this->courseid));
            $c->profileurl = $url->out(false); // URL should not be escaped just yet.
            $c->fullname = fullname($u);
            $c->time = userdate($c->timecreated, $c->strftimeformat);
            $c->content = format_text($c->content, $c->format, $formatoptions);
            $c->avatar = $OUTPUT->user_picture($u, array('size'=>18));
            $c->userid = $u->id;

            $candelete = $this->can_delete($c->id);
            if (($USER->id == $u->id) || !empty($candelete)) {
                $c->delete = true;
            }
            $comments[] = $c;
        }
        $rs->close();

        if (!empty($this->plugintype)) {
            // moodle module will filter comments
            $comments = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'display', array($comments, $this->comment_param), $comments);
        }

        return $comments;
    }
825647
function PageStartComment(Page $page)
    {
        $text = str_replace('{0}', $page->GetID(), self::START_PAGE_COMMENT);
        return new CommentLine($text);
    }
331062
public function getComments($postId = false)
    {
        $cArgs = [
            'author__in' => $this->ID,
            'orderby' => 'comment_date_gmt'
        ];
        if ($postId) {
            $cArgs['post_id'] = $postId;
        }
        $comments = [];
        foreach (get_comments($cArgs) as $c) {
            $comments[] = Comment::find($c->comment_ID);
        }
        return $comments;
    }
953582
public function print_comments($page = 0, $return = true, $nonjs = true) {
        global $DB, $CFG, $PAGE;

        if (!$this->can_view()) {
            return '';
        }

        if (!(self::$comment_itemid == $this->itemid &&
            self::$comment_context == $this->context->id &&
            self::$comment_area == $this->commentarea &&
            self::$comment_component == $this->component
        )) {
            $page = 0;
        }
        $comments = $this->get_comments($page);

        $html = '';
        if ($nonjs) {
            $html .= html_writer::tag('h3', get_string('comments'));
            $html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list'));
        }
        // Reverse the comments array to display them in the correct direction
        foreach (array_reverse($comments) as $cmt) {
            $html .= html_writer::tag('li', $this->print_comment($cmt, $nonjs), array('id' => 'comment-'.$cmt->id.'-'.$this->cid));
        }
        if ($nonjs) {
            $html .= html_writer::end_tag('ul');
            $html .= $this->get_pagination($page);
        }
        if ($nonjs && $this->can_post()) {
            // Form to add comments
            $html .= html_writer::start_tag('form', array('method' => 'post', 'action' => new moodle_url('/comment/comment_post.php')));
            // Comment parameters
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'contextid', 'value' => $this->contextid));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action',    'value' => 'add'));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'area',      'value' => $this->commentarea));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'component', 'value' => $this->component));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'itemid',    'value' => $this->itemid));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'courseid',  'value' => $this->courseid));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',   'value' => sesskey()));
            $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'returnurl', 'value' => $PAGE->url));
            // Textarea for the actual comment
            $html .= html_writer::tag('textarea', '', array('name' => 'content', 'rows' => 2));
            // Submit button to add the comment
            $html .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('submit')));
            $html .= html_writer::end_tag('form');
        }
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
372504
public function TopCharacters(int $page = 1): array
    {
        return $this->myanimelist->getTopCharacters(
            new Request\Top\TopCharactersRequest($page)
        );
    }
711483
function PageEndComment(Page $page)
    {
        $text = str_replace('{0}', $page->GetID(), self::END_PAGE_COMMENT);
        return new CommentLine($text);
    }
63862
static function FindPageGroup(Page $page)
    {
        $currPage = $page;
        $result = null;
        do 
        {
            $result = $currPage->GetUserGroup();
            $currPage = $currPage->GetParent();
        } 
        while (!$result && $currPage);
        if (!$result && $page->GetSite())
        {
            return $page->GetSite()->GetUserGroup();
        }
        return $result;
    }
569356
public function UserFriends(string $username, int $page = 1): array
    {
        return $this->myanimelist->getUserFriends(
            new Request\User\UserFriendsRequest($username, $page)
        );
    }
374558
protected function _getPaginatedUrl($page)
    {
        $url = $this->_getSortUrl();

        if ($page > 1) {
            if (!isset($url['?'])) {
                $url['?'] = [];
            }
            $url['?']['p'] = $page;
        }

        return $url;
    }
137700
public function getPagedResults($limit = 25, $page = 0)
    {
        $template = self::DQL_ALL;
        $dql = sprintf($template, Application::class);

        return $this->getPaginator($dql, $limit, $page, []);
    }
1297640
public function getCustomers($page = '')
    {
        $customerObjects = [];
        $customers = $this->getCustomerResource()->getAll($page);

        if ($customers instanceof \Exception) {
            throw $customers;
        }

        foreach ($customers as $customer) {
            $customerObject = new Customer($this->getCustomerResource());
            $customerObjects[] = $customerObject->_setAttributes($customer);
        }

        return $customerObjects;
    }
425563
private function get_config( $page ) {
		// Defaults.
		$config = array(
			'instructions' => $this->get_instructions(),
			'icon'         => 'question',
			'color'        => '#A4286A',
			'poweredBy'    => false,
			'translation'  => $this->get_translations(),
			'showSubject'  => true,
			'zIndex'       => 1000001,
		);

		foreach ( $this->settings as $setting ) {
			if ( method_exists( $setting, 'get_config' ) ) {
				$config = array_merge( $config, $setting->get_config( $page ) );
			}
		}

		return $config;
	}
459638
public function lines($page = null)
    {
        $url = sprintf('buckets/%d/chats/%d/lines.json', $this->bucket, $this->parent);

        $lines = $this->client->get($url, [
            'query' => [
                'page' => $page,
            ]
        ]);

        return $this->indexResponse($lines, CampfireLine::class);
    }
1179970
protected function getIssues($page)
	{
		$this->out(sprintf('Getting issues page #%02d.', $page));
		$this->out(str_pad('', 40, '-'));

		$issues = $this->api->issues
			->getListByRepository('joomla', 'joomla-framework', null, 'closed', null, null, null, 'updated', 'desc', null, $page, 100);

		$this->out(sprintf('Got %s issues.', count($issues)));

		return $issues;
	}
1163357
public function getAllShowsByPage($page=null){
		if($page == null){
			$url = self::APIURL.'/shows';
		}else{
			$url = self::APIURL.'/shows?page'.$page;
		}

		$shows = $this->getFile($url);

		$relevant_shows = [];
		foreach($shows as $series){
			$TVShow = new TVShow($series);
			$relevant_shows[] = $TVShow;
		}
		return $relevant_shows;
	}
1153374
public function index($page = null)
    {
        $url = sprintf('buckets/%d/chats/%d/integrations.json', $this->bucket, $this->parent);

        $chatbots = $this->client->get($url, [
            'query' => [
                'page' => $page,
            ],
        ]);

        return $this->indexResponse($chatbots, Chatbot::class)->map(function ($chatbot) {
            $chatbot->inContext($this->bucket, $this->parent);
            return $chatbot;
        });
    }
794505
public function listAction($page = 1)
    {
        $paginator = $this->get("knp_paginator");

        if ($paginator instanceof \Knp\Component\Pager\Paginator) ;

        $query = $this->getPaginatorQuery();

        if ($this->getRequest()->get("sort")) {
            $query->orderBy($this->getRequest()->get("sort"), strtolower($this->getRequest()->get("direction")) == "asc" ? "asc" : "desc");
        }

        $pagination = $paginator->paginate(
            $query,
            $page
        );

        $pagination->setTemplate('KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig');

        return array(
            'page' => $page,
            'pagination' => $pagination,
            'sort' => $this->getRequest()->get('sort'),
            'direction' => $this->getRequest()->get('direction'),
            'route' => $this->getRouteName(),
            'routeParams' => $this->getRouteParams(),
            'template' => $this->getListTemplate()
        );
    }