Skip to content

Commit

Permalink
MDL-76571 quiz reports: should not show description items
Browse files Browse the repository at this point in the history
... or anything else with length = 0. This got broken in MDL-71696.

The only way to fix this kind-of involves and API change to
quiz_report_get_significant_questions. However, it is only changing
the external API of this function back to how it was before the 4.0 release,
and the chnages in 4.0 were never documented, nor, I would guess, intended,
since they just broke things.
  • Loading branch information
timhunt committed Dec 7, 2022
1 parent bdba785 commit 38bad90
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/report/grading/report.php
Expand Up @@ -384,7 +384,7 @@ protected function display_index($includeauto) {

$row[] = $this->questions[$counts->slot]->number;

$row[] = $PAGE->get_renderer('question', 'bank')->qtype_icon($this->questions[$counts->slot]->type);
$row[] = $PAGE->get_renderer('question', 'bank')->qtype_icon($this->questions[$counts->slot]->qtype);

$row[] = format_string($counts->name);

Expand Down
1 change: 0 additions & 1 deletion mod/quiz/report/overview/report.php
Expand Up @@ -203,7 +203,6 @@ public function display($quiz, $cm, $course) {

if ($options->slotmarks) {
foreach ($questions as $slot => $question) {
// Ignore questions of zero length.
$columns[] = 'qsgrade' . $slot;
$header = get_string('qbrief', 'quiz', $question->number);
if (!$table->is_downloading()) {
Expand Down
21 changes: 14 additions & 7 deletions mod/quiz/report/overview/tests/behat/basic.feature
Expand Up @@ -30,28 +30,35 @@ Feature: Basic use of the Grades report
| activity | name | intro | course | idnumber |
| quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | TF1 | First question |
| Test questions | truefalse | TF2 | Second question |
| questioncategory | qtype | name | questiontext |
| Test questions | description | Intro | Welcome to this quiz |
| Test questions | truefalse | TF1 | First question |
| Test questions | truefalse | TF2 | Second question |
And quiz "Quiz 1" contains the following questions:
| question | page | maxmark |
| Intro | 1 | |
| TF1 | 1 | |
| TF2 | 1 | 3.0 |
And user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
| 2 | False |
| 2 | True |
| 3 | False |
And user "student2" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
| 2 | True |
| 3 | True |

@javascript
Scenario: Using the Grades report
# Basic check of the Grades report
When I am on the "Quiz 1" "quiz activity" page logged in as teacher1
And I navigate to "Results" in current page administration
Then I should see "Attempts: 2"

# Verify that the right columns are visible
And I should see "Q. 1"
And I should see "Q. 2"
And I should not see "Q. 3"

# Check student1's grade
And I should see "25.00" in the "S1 Student1" "table_row"
# And student2's grade
Expand Down
30 changes: 15 additions & 15 deletions mod/quiz/report/reportlib.php
Expand Up @@ -91,36 +91,36 @@ function quiz_has_questions($quizid) {
/**
* Get the slots of real questions (not descriptions) in this quiz, in order.
* @param object $quiz the quiz.
* @return array of slot => $question object with fields
* ->slot, ->id, ->maxmark, ->number, ->length.
* @return array of slot => objects with fields
* ->slot, ->id, ->qtype, ->length, ->number, ->maxmark, ->category (for random questions).
*/
function quiz_report_get_significant_questions($quiz) {
global $DB;
$qsbyslot = [];
$quizobj = \quiz::create($quiz->id);
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
$slots = $structure->get_slots();

$qsbyslot = [];
$number = 1;
foreach ($slots as $slot) {
// Ignore 'questions' of zero length.
if ($slot->length == 0) {
continue;
}

$slotreport = new \stdClass();
$slotreport->slot = $slot->slot;
$slotreport->id = $slot->questionid;
$slotreport->qtype = $slot->qtype;
$slotreport->length = $slot->length;
$slotreport->number = $number;
$number += $slot->length;
$slotreport->maxmark = $slot->maxmark;
$slotreport->type = $slot->qtype;
if ($slot->qtype === 'random') {
$categoryobject = $DB->get_record('question_categories', ['id' => $slot->category]);
$slotreport->categoryobject = $categoryobject;
$slotreport->category = $slot->category;
}
$slotreport->category = $slot->category;

$qsbyslot[$slotreport->slot] = $slotreport;
}
ksort($qsbyslot);
$number = 1;
foreach ($qsbyslot as $question) {
$question->number = $number;
$number++;
}

return $qsbyslot;
}

Expand Down
7 changes: 7 additions & 0 deletions mod/quiz/report/upgrade.txt
Expand Up @@ -2,6 +2,13 @@ This files describes API changes for quiz report plugins.

Overview of this plugin type at http://docs.moodle.org/dev/Quiz_reports

=== 4.0.6 ===

There was an ill-advised, never documented, API change in quiz_report_get_significant_questions
in Moodle 4.0. The API has now been reverted to how it was before 4.0. Hopefully this
will not cause anyone a problem. (The API revert did not require any changes in any automated tests
or standard quiz reports.)

=== 3.9 ===

* Quiz report plugins defining capabilities used to require an extra string like
Expand Down

0 comments on commit 38bad90

Please sign in to comment.