Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-27314 quiz reports: fix JS confirmation before deleting attempts.

  • Loading branch information...
commit a6395af1b912615c6b355757242a917c25aa2700 1 parent 4dbdc83
Tim Hunt timhunt authored stronk7 committed
52 mod/quiz/report/attemptsreport.php
@@ -398,10 +398,10 @@ protected function delete_selected_attempts($quiz, $cm, $attemptids, $allowed) {
398 398 protected $groupstudents;
399 399 protected $students;
400 400 protected $questions;
401   - protected $candelete;
  401 + protected $includecheckboxes;
402 402
403 403 public function __construct($uniqueid, $quiz, $context, $qmsubselect, $groupstudents,
404   - $students, $questions, $candelete, $reporturl, $displayoptions) {
  404 + $students, $questions, $includecheckboxes, $reporturl, $displayoptions) {
405 405 parent::__construct($uniqueid);
406 406 $this->quiz = $quiz;
407 407 $this->context = $context;
@@ -409,7 +409,7 @@ public function __construct($uniqueid, $quiz, $context, $qmsubselect, $groupstud
409 409 $this->groupstudents = $groupstudents;
410 410 $this->students = $students;
411 411 $this->questions = $questions;
412   - $this->candelete = $candelete;
  412 + $this->includecheckboxes = $includecheckboxes;
413 413 $this->reporturl = $reporturl;
414 414 $this->displayoptions = $displayoptions;
415 415 }
@@ -690,4 +690,50 @@ public function get_sort_columns() {
690 690 $sortcolumns['quiza.id'] = SORT_ASC;
691 691 return $sortcolumns;
692 692 }
  693 +
  694 + public function wrap_html_start() {
  695 + if ($this->is_downloading() || !$this->includecheckboxes) {
  696 + return;
  697 + }
  698 +
  699 + $url = new moodle_url($this->reporturl, $this->displayoptions);
  700 + $url->param('sesskey', sesskey());
  701 +
  702 + echo '<div id="tablecontainer">';
  703 + echo '<form id="attemptsform" method="post" action="' . $url->out_omit_querystring() . '">';
  704 +
  705 + echo html_writer::input_hidden_params($url);
  706 + echo '<div>';
  707 + }
  708 +
  709 + public function wrap_html_finish() {
  710 + if ($this->is_downloading() || !$this->includecheckboxes) {
  711 + return;
  712 + }
  713 +
  714 + echo '<div id="commands">';
  715 + echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">' .
  716 + get_string('selectall', 'quiz') . '</a> / ';
  717 + echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">' .
  718 + get_string('selectnone', 'quiz') . '</a> ';
  719 + echo '&nbsp;&nbsp;';
  720 + $this->submit_buttons();
  721 + echo '</div>';
  722 + // Close form
  723 + echo '</div>';
  724 + echo '</form></div>';
  725 + }
  726 +
  727 + /**
  728 + * Output any submit buttons required by the $this->includecheckboxes form.
  729 + */
  730 + protected function submit_buttons() {
  731 + global $PAGE;
  732 + if (has_capability('mod/quiz:deleteattempts', $this->context)) {
  733 + echo '<input type="submit" id="deleteattemptsbutton" name="delete" value="' .
  734 + get_string('deleteselected', 'quiz_overview') . '"/>';
  735 + $PAGE->requires->event_handler('#deleteattemptsbutton', 'click', 'M.util.show_confirm_dialog',
  736 + array('message' => get_string('deleteattemptcheck', 'quiz')));
  737 + }
  738 + }
693 739 }
42 mod/quiz/report/overview/overview_table.php
@@ -35,13 +35,12 @@
35 35 */
36 36 class quiz_report_overview_table extends quiz_attempt_report_table {
37 37
38   - protected $candelete;
39 38 protected $regradedqs = array();
40 39
41 40 public function __construct($quiz, $context, $qmsubselect, $groupstudents,
42   - $students, $detailedmarks, $questions, $candelete, $reporturl, $displayoptions) {
  41 + $students, $detailedmarks, $questions, $includecheckboxes, $reporturl, $displayoptions) {
43 42 parent::__construct('mod-quiz-report-overview-report', $quiz , $context,
44   - $qmsubselect, $groupstudents, $students, $questions, $candelete,
  43 + $qmsubselect, $groupstudents, $students, $questions, $includecheckboxes,
45 44 $reporturl, $displayoptions);
46 45 $this->detailedmarks = $detailedmarks;
47 46 }
@@ -147,45 +146,12 @@ protected function format_average($record, $question = false) {
147 146 }
148 147 }
149 148
150   - public function wrap_html_start() {
151   - if ($this->is_downloading() || !$this->candelete) {
152   - return;
153   - }
154   -
155   - // Start form
156   - $url = new moodle_url($this->reporturl, $this->displayoptions +
157   - array('sesskey' => sesskey()));
158   - echo '<div id="tablecontainer" class="overview-tablecontainer">';
159   - echo '<form id="attemptsform" method="post" action="' .
160   - $this->reporturl->out_omit_querystring() . '">';
161   - echo '<div style="display: none;">';
162   - echo html_writer::input_hidden_params($url);
163   - echo '</div>';
164   - echo '<div>';
165   - }
166   -
167   - public function wrap_html_finish() {
168   - if ($this->is_downloading() || !$this->candelete) {
169   - return;
170   - }
171   -
172   - // TODO add back are you sure, and convert to html_writer.
173   - echo '<div id="commands">';
174   - echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">' .
175   - get_string('selectall', 'quiz') . '</a> / ';
176   - echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">' .
177   - get_string('selectnone', 'quiz') . '</a> ';
178   - echo '&nbsp;&nbsp;';
  149 + protected function submit_buttons() {
179 150 if (has_capability('mod/quiz:regrade', $this->context)) {
180 151 echo '<input type="submit" name="regrade" value="' .
181 152 get_string('regradeselected', 'quiz_overview') . '"/>';
182 153 }
183   - echo '<input type="submit" name="delete" value="' .
184   - get_string('deleteselected', 'quiz_overview') . '"/>';
185   - echo '</div>';
186   - // Close form
187   - echo '</div>';
188   - echo '</form></div>';
  154 + parent::submit_buttons();
189 155 }
190 156
191 157 public function col_sumgrades($attempt) {
7 mod/quiz/report/overview/report.php
@@ -106,7 +106,8 @@ public function display($quiz, $cm, $course) {
106 106
107 107 // We only want to show the checkbox to delete attempts
108 108 // if the user has permissions and if the report mode is showing attempts.
109   - $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
  109 + $includecheckboxes = has_any_capability(
  110 + array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), $this->context)
110 111 && ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
111 112
112 113 if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
@@ -128,7 +129,7 @@ public function display($quiz, $cm, $course) {
128 129 $questions = quiz_report_get_significant_questions($quiz);
129 130
130 131 $table = new quiz_report_overview_table($quiz, $this->context, $qmsubselect,
131   - $groupstudents, $students, $detailedmarks, $questions, $candelete,
  132 + $groupstudents, $students, $detailedmarks, $questions, $includecheckboxes,
132 133 $reporturl, $displayoptions);
133 134 $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
134 135 $courseshortname, $quiz->name);
@@ -290,7 +291,7 @@ public function display($quiz, $cm, $course) {
290 291 $columns = array();
291 292 $headers = array();
292 293
293   - if (!$table->is_downloading() && $candelete) {
  294 + if (!$table->is_downloading() && $includecheckboxes) {
294 295 $columns[] = 'checkbox';
295 296 $headers[] = null;
296 297 }
19 mod/quiz/report/responses/report.php
@@ -105,7 +105,7 @@ public function display($quiz, $cm, $course) {
105 105
106 106 // We only want to show the checkbox to delete attempts
107 107 // if the user has permissions and if the report mode is showing attempts.
108   - $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
  108 + $includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context)
109 109 && ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
110 110
111 111 $displayoptions = array();
@@ -124,11 +124,14 @@ public function display($quiz, $cm, $course) {
124 124 $allowed = array();
125 125 }
126 126
127   - $attemptids = optional_param_array('attemptid', array(), PARAM_INT);
128   - if ($attemptids && confirm_sesskey()) {
129   - require_capability('mod/quiz:deleteattempts', $this->context);
130   - $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
131   - redirect($reporturl->out(false, $displayoptions));
  127 + if (empty($currentgroup) || $groupstudents) {
  128 + if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
  129 + if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
  130 + require_capability('mod/quiz:deleteattempts', $this->context);
  131 + $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
  132 + redirect($reporturl->out(false, $displayoptions));
  133 + }
  134 + }
132 135 }
133 136
134 137 // Load the required questions.
@@ -143,7 +146,7 @@ public function display($quiz, $cm, $course) {
143 146 array('context' => $displaycoursecontext));
144 147
145 148 $table = new quiz_report_responses_table($quiz, $this->context, $qmsubselect,
146   - $groupstudents, $students, $questions, $candelete, $reporturl, $displayoptions);
  149 + $groupstudents, $students, $questions, $includecheckboxes, $reporturl, $displayoptions);
147 150 $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
148 151 $courseshortname, $quiz->name);
149 152 $table->is_downloading($download, $filename,
@@ -205,7 +208,7 @@ public function display($quiz, $cm, $course) {
205 208 $columns = array();
206 209 $headers = array();
207 210
208   - if (!$table->is_downloading() && $candelete) {
  211 + if (!$table->is_downloading() && $includecheckboxes) {
209 212 $columns[] = 'checkbox';
210 213 $headers[] = null;
211 214 }
41 mod/quiz/report/responses/responses_table.php
@@ -36,9 +36,9 @@
36 36 class quiz_report_responses_table extends quiz_attempt_report_table {
37 37
38 38 public function __construct($quiz, $context, $qmsubselect, $groupstudents,
39   - $students, $questions, $candelete, $reporturl, $displayoptions) {
  39 + $students, $questions, $includecheckboxes, $reporturl, $displayoptions) {
40 40 parent::__construct('mod-quiz-report-responses-report', $quiz, $context,
41   - $qmsubselect, $groupstudents, $students, $questions, $candelete,
  41 + $qmsubselect, $groupstudents, $students, $questions, $includecheckboxes,
42 42 $reporturl, $displayoptions);
43 43 }
44 44
@@ -49,43 +49,6 @@ public function build_table() {
49 49 }
50 50 }
51 51
52   - public function wrap_html_start() {
53   - global $PAGE;
54   - if ($this->is_downloading() || !$this->candelete) {
55   - return;
56   - }
57   -
58   - // Start form
59   - $url = new moodle_url($this->reporturl, $this->displayoptions);
60   - $url->param('sesskey', sesskey());
61   -
62   - echo '<div id="tablecontainer">';
63   - echo '<form id="attemptsform" method="post" action="' . $url->out_omit_querystring() . '>';
64   - echo html_writer::input_hidden_params($url);
65   - echo '<div>';
66   - $PAGE->requires->event_handler('#attemptsform', 'submit', 'M.util.show_confirm_dialog',
67   - array('message' => get_string('deleteattemptcheck', 'quiz')));
68   - }
69   -
70   - public function wrap_html_finish() {
71   - if ($this->is_downloading() || !$this->candelete) {
72   - return;
73   - }
74   -
75   - // TODO add back are you sure, and convert to html_writer.
76   - echo '<div id="commands">';
77   - echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">'.
78   - get_string('selectall', 'quiz').'</a> / ';
79   - echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">'.
80   - get_string('selectnone', 'quiz').'</a> ';
81   - echo '&nbsp;&nbsp;';
82   - echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
83   - echo '</div>';
84   - // Close form
85   - echo '</div>';
86   - echo '</form></div>';
87   - }
88   -
89 52 public function col_sumgrades($attempt) {
90 53 if (!$attempt->timefinish) {
91 54 return '-';

0 comments on commit a6395af

Please sign in to comment.
Something went wrong with that request. Please try again.