Browse files

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

Conflicts:

	mod/quiz/report/responses/report.php
  • Loading branch information...
1 parent 1921ff6 commit c8b08dc39290deea0efcfb03244169ec6b624d24 @timhunt timhunt committed with stronk7 Dec 8, 2011
View
52 mod/quiz/report/attemptsreport.php
@@ -391,18 +391,18 @@ protected function delete_selected_attempts($quiz, $cm, $attemptids, $allowed) {
protected $groupstudents;
protected $students;
protected $questions;
- protected $candelete;
+ protected $includecheckboxes;
public function __construct($uniqueid, $quiz, $context, $qmsubselect, $groupstudents,
- $students, $questions, $candelete, $reporturl, $displayoptions) {
+ $students, $questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct($uniqueid);
$this->quiz = $quiz;
$this->context = $context;
$this->qmsubselect = $qmsubselect;
$this->groupstudents = $groupstudents;
$this->students = $students;
$this->questions = $questions;
- $this->candelete = $candelete;
+ $this->includecheckboxes = $includecheckboxes;
$this->reporturl = $reporturl;
$this->displayoptions = $displayoptions;
}
@@ -683,4 +683,50 @@ public function get_sort_columns() {
$sortcolumns['quiza.id'] = SORT_ASC;
return $sortcolumns;
}
+
+ public function wrap_html_start() {
+ if ($this->is_downloading() || !$this->includecheckboxes) {
+ return;
+ }
+
+ $url = new moodle_url($this->reporturl, $this->displayoptions);
+ $url->param('sesskey', sesskey());
+
+ echo '<div id="tablecontainer">';
+ echo '<form id="attemptsform" method="post" action="' . $url->out_omit_querystring() . '">';
+
+ echo html_writer::input_hidden_params($url);
+ echo '<div>';
+ }
+
+ public function wrap_html_finish() {
+ if ($this->is_downloading() || !$this->includecheckboxes) {
+ return;
+ }
+
+ echo '<div id="commands">';
+ echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">' .
+ get_string('selectall', 'quiz') . '</a> / ';
+ echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">' .
+ get_string('selectnone', 'quiz') . '</a> ';
+ echo '&nbsp;&nbsp;';
+ $this->submit_buttons();
+ echo '</div>';
+ // Close form
+ echo '</div>';
+ echo '</form></div>';
+ }
+
+ /**
+ * Output any submit buttons required by the $this->includecheckboxes form.
+ */
+ protected function submit_buttons() {
+ global $PAGE;
+ if (has_capability('mod/quiz:deleteattempts', $this->context)) {
+ echo '<input type="submit" id="deleteattemptsbutton" name="delete" value="' .
+ get_string('deleteselected', 'quiz_overview') . '"/>';
+ $PAGE->requires->event_handler('#deleteattemptsbutton', 'click', 'M.util.show_confirm_dialog',
+ array('message' => get_string('deleteattemptcheck', 'quiz')));
+ }
+ }
}
View
42 mod/quiz/report/overview/overview_table.php
@@ -35,13 +35,12 @@
*/
class quiz_report_overview_table extends quiz_attempt_report_table {
- protected $candelete;
protected $regradedqs = array();
public function __construct($quiz, $context, $qmsubselect, $groupstudents,
- $students, $detailedmarks, $questions, $candelete, $reporturl, $displayoptions) {
+ $students, $detailedmarks, $questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct('mod-quiz-report-overview-report', $quiz , $context,
- $qmsubselect, $groupstudents, $students, $questions, $candelete,
+ $qmsubselect, $groupstudents, $students, $questions, $includecheckboxes,
$reporturl, $displayoptions);
$this->detailedmarks = $detailedmarks;
}
@@ -147,45 +146,12 @@ protected function format_average($record, $question = false) {
}
}
- public function wrap_html_start() {
- if ($this->is_downloading() || !$this->candelete) {
- return;
- }
-
- // Start form
- $url = new moodle_url($this->reporturl, $this->displayoptions +
- array('sesskey' => sesskey()));
- echo '<div id="tablecontainer" class="overview-tablecontainer">';
- echo '<form id="attemptsform" method="post" action="' .
- $this->reporturl->out_omit_querystring() . '">';
- echo '<div style="display: none;">';
- echo html_writer::input_hidden_params($url);
- echo '</div>';
- echo '<div>';
- }
-
- public function wrap_html_finish() {
- if ($this->is_downloading() || !$this->candelete) {
- return;
- }
-
- // TODO add back are you sure, and convert to html_writer.
- echo '<div id="commands">';
- echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">' .
- get_string('selectall', 'quiz') . '</a> / ';
- echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">' .
- get_string('selectnone', 'quiz') . '</a> ';
- echo '&nbsp;&nbsp;';
+ protected function submit_buttons() {
if (has_capability('mod/quiz:regrade', $this->context)) {
echo '<input type="submit" name="regrade" value="' .
get_string('regradeselected', 'quiz_overview') . '"/>';
}
- echo '<input type="submit" name="delete" value="' .
- get_string('deleteselected', 'quiz_overview') . '"/>';
- echo '</div>';
- // Close form
- echo '</div>';
- echo '</form></div>';
+ parent::submit_buttons();
}
public function col_sumgrades($attempt) {
View
7 mod/quiz/report/overview/report.php
@@ -106,7 +106,8 @@ public function display($quiz, $cm, $course) {
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
- $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
+ $includecheckboxes = has_any_capability(
+ array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), $this->context)
&& ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
@@ -126,7 +127,7 @@ public function display($quiz, $cm, $course) {
$questions = quiz_report_get_significant_questions($quiz);
$table = new quiz_report_overview_table($quiz, $this->context, $qmsubselect,
- $groupstudents, $students, $detailedmarks, $questions, $candelete,
+ $groupstudents, $students, $detailedmarks, $questions, $includecheckboxes,
$reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
$courseshortname, $quiz->name);
@@ -288,7 +289,7 @@ public function display($quiz, $cm, $course) {
$columns = array();
$headers = array();
- if (!$table->is_downloading() && $candelete) {
+ if (!$table->is_downloading() && $includecheckboxes) {
$columns[] = 'checkbox';
$headers[] = null;
}
View
18 mod/quiz/report/responses/report.php
@@ -105,7 +105,7 @@ public function display($quiz, $cm, $course) {
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
- $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
+ $includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context)
&& ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
$displayoptions = array();
@@ -124,10 +124,14 @@ public function display($quiz, $cm, $course) {
$allowed = array();
}
- if ($attemptids = optional_param('attemptid', array(), PARAM_INT) && confirm_sesskey()) {
- require_capability('mod/quiz:deleteattempts', $this->context);
- $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
- redirect($reporturl->out(false, $displayoptions));
+ if (empty($currentgroup) || $groupstudents) {
+ if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
+ if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
+ require_capability('mod/quiz:deleteattempts', $this->context);
+ $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
+ redirect($reporturl->out(false, $displayoptions));
+ }
+ }
}
// Load the required questions.
@@ -140,7 +144,7 @@ public function display($quiz, $cm, $course) {
$displaycourseshortname = format_string($COURSE->shortname, true, array('context' => $displaycoursecontext));
$table = new quiz_report_responses_table($quiz, $this->context, $qmsubselect,
- $groupstudents, $students, $questions, $candelete, $reporturl, $displayoptions);
+ $groupstudents, $students, $questions, $includecheckboxes, $reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
$courseshortname, $quiz->name);
$table->is_downloading($download, $filename,
@@ -202,7 +206,7 @@ public function display($quiz, $cm, $course) {
$columns = array();
$headers = array();
- if (!$table->is_downloading() && $candelete) {
+ if (!$table->is_downloading() && $includecheckboxes) {
$columns[] = 'checkbox';
$headers[] = null;
}
View
41 mod/quiz/report/responses/responses_table.php
@@ -36,9 +36,9 @@
class quiz_report_responses_table extends quiz_attempt_report_table {
public function __construct($quiz, $context, $qmsubselect, $groupstudents,
- $students, $questions, $candelete, $reporturl, $displayoptions) {
+ $students, $questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct('mod-quiz-report-responses-report', $quiz, $context,
- $qmsubselect, $groupstudents, $students, $questions, $candelete,
+ $qmsubselect, $groupstudents, $students, $questions, $includecheckboxes,
$reporturl, $displayoptions);
}
@@ -49,43 +49,6 @@ public function build_table() {
}
}
- public function wrap_html_start() {
- global $PAGE;
- if ($this->is_downloading() || !$this->candelete) {
- return;
- }
-
- // Start form
- $url = new moodle_url($this->reporturl, $this->displayoptions);
- $url->param('sesskey', sesskey());
-
- echo '<div id="tablecontainer">';
- echo '<form id="attemptsform" method="post" action="' . $url->out_omit_querystring() . '>';
- echo html_writer::input_hidden_params($url);
- echo '<div>';
- $PAGE->requires->event_handler('#attemptsform', 'submit', 'M.util.show_confirm_dialog',
- array('message' => get_string('deleteattemptcheck', 'quiz')));
- }
-
- public function wrap_html_finish() {
- if ($this->is_downloading() || !$this->candelete) {
- return;
- }
-
- // TODO add back are you sure, and convert to html_writer.
- echo '<div id="commands">';
- echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">'.
- get_string('selectall', 'quiz').'</a> / ';
- echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">'.
- get_string('selectnone', 'quiz').'</a> ';
- echo '&nbsp;&nbsp;';
- echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
- echo '</div>';
- // Close form
- echo '</div>';
- echo '</form></div>';
- }
-
public function col_sumgrades($attempt) {
if (!$attempt->timefinish) {
return '-';

0 comments on commit c8b08dc

Please sign in to comment.