Skip to content

Commit

Permalink
Export attempts: show/hide marks #670325
Browse files Browse the repository at this point in the history
  • Loading branch information
danghieu1407 authored and Kristiina.Bax committed Aug 21, 2023
1 parent a9ad568 commit 514ca7d
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 72 deletions.
13 changes: 8 additions & 5 deletions attemptsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

$attemptid = required_param('attempt', PARAM_INT);
$cmid = optional_param('cmid', null, PARAM_INT);
$rightanswer = optional_param('rightanswer', 0, PARAM_BOOL);

$attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
$reportoptions = new report_display_options('answersheets', $attemptobj->get_quiz(),
Expand All @@ -40,15 +39,19 @@
// Check login.
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
require_capability('quiz/answersheets:view', context_module::instance($attemptobj->get_cmid()));

$rightanswer = $reportoptions->rightanswer;
if ($rightanswer) {
require_capability('quiz/answersheets:viewrightanswers', context_module::instance($attemptobj->get_cmid()));
}

$url = new moodle_url('/mod/quiz/report/answersheets/attemptsheet.php',
['attempt' => $attemptid, 'rightanswer' => $rightanswer,
'userinfo' => $reportoptions->combine_user_info_visibility(),
'instruction' => $reportoptions->questioninstruction]);
[
'attempt' => $attemptid,
'rightanswer' => $rightanswer,
'userinfo' => $reportoptions->combine_user_info_visibility(),
'instruction' => $reportoptions->questioninstruction,
'marks' => $reportoptions->marks,
]);

// Work out the page title.
$isattemptfinished = $attemptobj->get_attempt()->state == quiz_attempt::FINISHED;
Expand Down
13 changes: 8 additions & 5 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class renderer extends plugin_renderer_base {
* @param bool $isreviewing True for review page, else attempt page
* @return string HTML string
*/
public function render_question_attempt_content(quiz_attempt $attemptobj, bool $isreviewing = true): string {
public function render_question_attempt_content(quiz_attempt $attemptobj, report_display_options $reportoptions,
bool $isreviewing = true): string {
$output = '';

$slots = $attemptobj->get_slots();
Expand All @@ -63,7 +64,8 @@ public function render_question_attempt_content(quiz_attempt $attemptobj, bool $
$displayoptions->manualcommentlink = null;
$displayoptions->context = context_module::instance($attemptobj->get_cmid());
$displayoptions->history = question_display_options::HIDDEN;
$rightanswer = $this->page->url->get_param('rightanswer');
$displayoptions->marks = $reportoptions->marks;
$rightanswer = $reportoptions->rightanswer;
$qoutput = $this->page->get_renderer('quiz_answersheets', 'core_question_override');

foreach ($slots as $slot) {
Expand Down Expand Up @@ -106,7 +108,8 @@ public function render_question_attempt_content(quiz_attempt $attemptobj, bool $
* @param string $redirect
* @return string HTML string
*/
public function render_question_attempt_form(quiz_attempt $attemptobj, string $redirect = ''): string {
public function render_question_attempt_form(quiz_attempt $attemptobj, report_display_options $reportoptions,
string $redirect = ''): string {
$output = '';

$attemptuser = \core_user::get_user($attemptobj->get_userid());
Expand All @@ -118,7 +121,7 @@ public function render_question_attempt_form(quiz_attempt $attemptobj, string $r
'accept-charset' => 'utf-8', 'id' => 'responseform']);
$output .= html_writer::start_tag('div');

$output .= $this->render_question_attempt_content($attemptobj, false);
$output .= $this->render_question_attempt_content($attemptobj, $reportoptions, false);

// Some hidden fields to trach what is going on.
$output .= html_writer::empty_tag('input',
Expand Down Expand Up @@ -193,7 +196,7 @@ public function render_attempt_sheet(array $sumdata, quiz_attempt $attemptobj,
$templatecontext = [
'questionattemptheader' => utils::get_attempt_sheet_print_header($attemptobj, $sheettype, $reportoptions),
'questionattemptsumtable' => $quizrenderer->review_summary_table($sumdata, 0),
'questionattemptcontent' => $this->render_question_attempt_content($attemptobj)
'questionattemptcontent' => $this->render_question_attempt_content($attemptobj, $reportoptions)
];
$isgecko = \core_useragent::is_gecko();
// We need to use specific layout for Gecko because it does not fully support display flex and table.
Expand Down
17 changes: 16 additions & 1 deletion classes/report_display_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ class report_display_options extends \mod_quiz_attempts_report_options {
*/
public $questioninstruction = true;

/**
* @var bool whether marks has been displayed.
*/
public $marks = true;

/**
* @var bool whether right answer has been displayed.
*/
public $rightanswer = true;

public function __construct($mode, $quiz, $cm, $course) {
parent::__construct($mode, $quiz, $cm, $course);
$this->attempts = quiz_attempts_report::ENROLLED_ALL;
Expand All @@ -82,12 +92,16 @@ public function setup_from_params() {
$this->parse_user_info_visibility($fields);
}
$this->questioninstruction = optional_param('instruction', true, PARAM_BOOL);
$this->marks = optional_param('marks', true, PARAM_BOOL);
$this->rightanswer = optional_param('rightanswer', false, PARAM_BOOL);
}

protected function get_url_params() {
$params = parent::get_url_params();
$params['userinfo'] = $this->combine_user_info_visibility();
$params['instruction'] = $this->questioninstruction;
$params['marks'] = $this->marks;
$params['rightanswer'] = $this->rightanswer;
return $params;
}

Expand All @@ -97,7 +111,7 @@ public function process_settings_from_form($fromform) {
$this->userinfovisibility[$name] = !empty($fromform->{'show' . $name});
}
$this->questioninstruction = (bool) $fromform->questioninstruction;

$this->marks = (bool) $fromform->marks;
parent::process_settings_from_form($fromform);
}

Expand All @@ -108,6 +122,7 @@ public function get_initial_form_data() {
$toform->{'show' . $name} = $show;
}
$toform->questioninstruction = $this->questioninstruction;
$toform->marks = $this->marks;

return $toform;
}
Expand Down
10 changes: 8 additions & 2 deletions classes/report_settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ protected function other_preference_fields(\MoodleQuickForm $mform) {
$mform->addGroup($userinfogroup, 'userinfo',
get_string('showuserinfo', 'quiz_answersheets'), array(' '), false);

$mform->addElement('advcheckbox', 'questioninstruction',
get_string('showquestioninstruction', 'quiz_answersheets'));
$instructionandmarkedcheckboxes = [];
$instructionandmarkedcheckboxes[] = $mform->createElement('advcheckbox', 'questioninstruction',
get_string('showquestioninstruction', 'quiz_answersheets'));
$mform->setDefault('questioninstruction', 1);

$instructionandmarkedcheckboxes[] = $mform->createElement('advcheckbox', 'marks',
get_string('showmarkedoutoftext', 'quiz_answersheets'));
$mform->setDefault('marks', 1);
$mform->addGroup($instructionandmarkedcheckboxes, 'instructionandmarkedcheckboxes', '', '',
false);
}
}
11 changes: 7 additions & 4 deletions classes/report_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public function col_attempt_sheet($row) {
[
'attempt' => $row->attempt,
'userinfo' => $this->options->combine_user_info_visibility(),
'instruction' => $this->options->questioninstruction
'instruction' => $this->options->questioninstruction,
'marks' => $this->options->marks,
]),
get_string('attempt_sheet_label', 'quiz_answersheets'),
['class' => 'reviewlink']);
Expand All @@ -123,7 +124,8 @@ public function col_attempt_sheet($row) {
[
'attempt' => $row->attempt,
'userinfo' => $this->options->combine_user_info_visibility(),
'instruction' => $this->options->questioninstruction
'instruction' => $this->options->questioninstruction,
'marks' => $this->options->marks,
]),
get_string('review_sheet_label', 'quiz_answersheets'),
['class' => 'reviewlink']);
Expand All @@ -145,7 +147,8 @@ public function col_answer_sheet($row) {
'attempt' => $row->attempt,
'rightanswer' => 1,
'userinfo' => $this->options->combine_user_info_visibility(),
'instruction' => $this->options->questioninstruction
'instruction' => $this->options->questioninstruction,
'marks' => $this->options->marks,
]),
get_string('answer_sheet_label', 'quiz_answersheets'),
['class' => 'reviewlink']);
Expand All @@ -166,7 +169,7 @@ public function col_submit_student_responses($row) {
$redirect->param('lastchanged', $row->attempt);
// Add userinfo params so that we only display fields that is used in the filter.
return html_writer::link(new moodle_url('/mod/quiz/report/answersheets/submitresponses.php',
['attempt' => $row->attempt, 'redirect' => $redirect,
['attempt' => $row->attempt, 'redirect' => $redirect, 'marks' => $this->options->marks,
'userinfo' => $this->options->combine_user_info_visibility()]),
get_string('submit_student_responses_label', 'quiz_answersheets'), ['class' => 'reviewlink']);
} else {
Expand Down
1 change: 1 addition & 0 deletions lang/en/quiz_answersheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
$string['review_sheet_label'] = 'Review sheet';
$string['review_sheet_title'] = '{$a->courseshortname} - {$a->quizname} - Review sheet';
$string['response_recorded'] = 'Response recorded: {$a}.';
$string['showmarkedoutoftext'] = 'Show "Marked out of" text?';
$string['showquestioninstruction'] = 'Show default instruction text?';
$string['showuserinfo'] = 'Identifying information to show about users';
$string['submit_student_responses_label'] = 'Submit responses...';
Expand Down
2 changes: 1 addition & 1 deletion submitresponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
$sumdata = utils::prepare_summary_attempt_information($attemptobj, !$isattemptfinished, $reportoptions);
echo $quizrenderer->review_summary_table($sumdata, 0);

echo $renderer->render_question_attempt_form($attemptobj, $redirect);
echo $renderer->render_question_attempt_form($attemptobj, $reportoptions, $redirect);

echo $OUTPUT->footer();
82 changes: 80 additions & 2 deletions tests/behat/question_display_options.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Feature: Review sheet of the Export attempt report
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
| 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 |
Expand All @@ -47,3 +47,81 @@ Feature: Review sheet of the Export attempt report
And ".text-danger" "css_element" should exist in the ".que.truefalse.deferredfeedback.incorrect" "css_element"
And ".text-success" "css_element" should exist in the ".que.truefalse.deferredfeedback.correct" "css_element"
And ".text-danger" "css_element" should exist in the ".que.truefalse.deferredfeedback.correct" "css_element"

@javascript
Scenario: Instruction text not display when I do not tick on checkbox
Given user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
When I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "teacher"
And I click on "Show default instruction text?" "checkbox"
And I click on "Show report" "button"
And I click on "Review sheet" "link" in the "Student One" "table_row"
Then I should see "First question"
And I should not see "Select the correct answer."

@javascript
Scenario: Instruction text display with default ticked checkbox
Given user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
When I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "teacher"
And I click on "Review sheet" "link" in the "Student One" "table_row"
Then I should see "First question"
And I should see "Select the correct answer."

@javascript
Scenario: 'Marked out of' text not display when I do not tick on checkbox on multiples sheets.
Given user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
When I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Show \"Marked out of\" text" "checkbox"
And I click on "Show report" "button"
And I click on "Create Attempt" "button" in the "Student One" "table_row"
And I click on "Create" "button" in the ".modal.show" "css_element"
And I click on "Review sheet" "link" in the "Student One" "table_row"
Then I should not see "Marked out of 1.00"
And I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Show \"Marked out of\" text" "checkbox"
And I click on "Show report" "button"
And I click on "Submit responses..." "link"
And I should not see "Marked out of 1.00"
And I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Show \"Marked out of\" text" "checkbox"
And I click on "Show report" "button"
# There is link with the same name "Attempt sheets" in the head, so we are using css_element to identify the correct link.
And I click on "Attempt sheet" "link" in the "tbody" "css_element"
And I should not see "Marked out of 1.00"

@javascript
Scenario: 'Marked out of' text display with default ticked checkbox on multiples sheets.
Given user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
When I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Show report" "button"
And I click on "Create Attempt" "button" in the "Student One" "table_row"
And I click on "Create" "button" in the ".modal.show" "css_element"
And I click on "Review sheet" "link" in the "Student One" "table_row"
Then I should see "Marked out of 1.00"
And I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Show report" "button"
And I click on "Submit responses..." "link"
And I should see "Marked out of 1.00"
And I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Show report" "button"
# There is link with the same name "Attempt sheets" in the head, so we are using css_element to identify the correct link.
And I click on "Attempt sheet" "link" in the "tbody" "css_element"
And I should see "Marked out of 1.00"

@javascript
Scenario: Right answer is display with right answer sheet
Given user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
When I am on the "Quiz 1" "quiz_answersheets > Report" page logged in as "admin"
And I click on "Create Attempt" "button" in the "Student One" "table_row"
And I click on "Create" "button" in the ".modal.show" "css_element"
And I click on "Right answer sheet" "link"
And I should see "You should have selected true."
52 changes: 0 additions & 52 deletions tests/behat/show_default_instruction.feature

This file was deleted.

0 comments on commit 514ca7d

Please sign in to comment.