From 1b45fa664e3728599872069c44568206ef8f97bd Mon Sep 17 00:00:00 2001 From: danghieu1407 Date: Tue, 10 Dec 2024 10:51:30 +0700 Subject: [PATCH] StudentQuiz: All questions disappear when the number of inputted questions #836555 is equal to or greater than the total available questions --- .github/workflows/moodle-plugin-ci.yml | 4 +- .../question/bank/studentquiz_bank_view.php | 44 +++---------------- tests/behat/pagination.feature | 8 ++++ 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index 53131453..9ab786f9 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -36,8 +36,8 @@ jobs: # - each moodle version at least once # - each database at least once include: - - {php: '8.1', moodle-branch: MOODLE_403_STABLE, database: mariadb} - - {php: '8.2', moodle-branch: MOODLE_404_STABLE, database: pgsql} + - {php: '8.1', moodle-branch: MOODLE_404_STABLE, database: mariadb} + - {php: '8.2', moodle-branch: MOODLE_405_STABLE, database: pgsql} - {php: '8.2', moodle-branch: main, database: mariadb} steps: diff --git a/classes/question/bank/studentquiz_bank_view.php b/classes/question/bank/studentquiz_bank_view.php index 28de1285..f4102fa4 100755 --- a/classes/question/bank/studentquiz_bank_view.php +++ b/classes/question/bank/studentquiz_bank_view.php @@ -569,47 +569,13 @@ private function initialize_filter_form($pageurl) { * @return array array of questions */ public function load_questions() { - global $DB; - $page = $this->get_pagevars('qpage'); - $perpage = $this->get_pagevars('qperpage'); - $rs = $DB->get_recordset_sql($this->loadsql, $this->sqlparams); - - $counterquestions = 0; - $numberofdisplayedquestions = 0; - $showall = $this->pagevars['showall']; - $rs->rewind(); - - // Skip Questions on previous pages. - while ($rs->valid() && !$showall && $counterquestions < $page * $perpage) { - $rs->next(); - $counterquestions++; - } - - // Reset and start from 0 if page was empty. - if (!$showall && $counterquestions < $page * $perpage) { - $rs->rewind(); - } - - // Unfortunately we cant just render the questions directly. - // We need to annotate tags first. - $questions = array(); - // Load questions. - while ($rs->valid() && ($showall || $numberofdisplayedquestions < $perpage)) { - $question = $rs->current(); - $numberofdisplayedquestions++; - $counterquestions++; - $this->displayedquestionsids[] = $question->id; - $rs->next(); + $questionsrs = $this->load_page_questions(); + $questions = []; + foreach ($questionsrs as $question) { $questions[] = $question; } - - // Iterate to end. - while ($rs->valid()) { - $rs->next(); - $counterquestions++; - } - $this->totalnumber = $counterquestions; - $rs->close(); + $questionsrs->close(); + $this->totalnumber = $this->get_question_count(); return $questions; } diff --git a/tests/behat/pagination.feature b/tests/behat/pagination.feature index 7b280c37..1d53b6d8 100644 --- a/tests/behat/pagination.feature +++ b/tests/behat/pagination.feature @@ -59,6 +59,14 @@ Feature: Test pagination for StudentQuiz Then "input[name='changepagesize']" "css_element" should not exist And I should see "TF 01" And I should see "Test question 24" + And I click on "Show 20 per page" "link" + And I click on "Page 2" "link" + And I should see "Test question 9" + And I set the field "qperpage" to "26" + And I press enter + # Verify that the first question and the last question are displayed, ensuring all essential questions are visible. + And I should see "TF 01" + And I should see "Test question 9" @javascript Scenario: Users using filter should keep the same pagination.