Skip to content

Commit

Permalink
StudentQuiz: All questions disappear when the number of inputted ques…
Browse files Browse the repository at this point in the history
…tions #836555

is equal to or greater than the total available questions
  • Loading branch information
danghieu1407 authored and AnupamaSarjoshi committed Dec 11, 2024
1 parent 0406734 commit f4473b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 5 additions & 39 deletions classes/question/bank/studentquiz_bank_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/behat/pagination.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f4473b7

Please sign in to comment.