Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StudentQuiz: All questions disappear when the number of inputted ques… #515

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading