MDL-27314 quiz reports: fix JS confirmation before deleting attempts.
Conflicts: mod/quiz/report/responses/report.php
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
1921ff62f2
commit
c8b08dc392
@@ -391,10 +391,10 @@ abstract class quiz_attempt_report_table extends table_sql {
|
||||
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;
|
||||
@@ -402,7 +402,7 @@ abstract class quiz_attempt_report_table extends table_sql {
|
||||
$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 @@ abstract class quiz_attempt_report_table extends table_sql {
|
||||
$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 ' ';
|
||||
$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')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
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 @@ class quiz_report_overview_table extends quiz_attempt_report_table {
|
||||
}
|
||||
}
|
||||
|
||||
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 ' ';
|
||||
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) {
|
||||
|
||||
@@ -106,7 +106,8 @@ class quiz_overview_report extends quiz_attempt_report {
|
||||
|
||||
// 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 @@ class quiz_overview_report extends quiz_attempt_report {
|
||||
$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 @@ class quiz_overview_report extends quiz_attempt_report {
|
||||
$columns = array();
|
||||
$headers = array();
|
||||
|
||||
if (!$table->is_downloading() && $candelete) {
|
||||
if (!$table->is_downloading() && $includecheckboxes) {
|
||||
$columns[] = 'checkbox';
|
||||
$headers[] = null;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class quiz_responses_report extends quiz_attempt_report {
|
||||
|
||||
// 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 @@ class quiz_responses_report extends quiz_attempt_report {
|
||||
$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 @@ class quiz_responses_report extends quiz_attempt_report {
|
||||
$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 @@ class quiz_responses_report extends quiz_attempt_report {
|
||||
$columns = array();
|
||||
$headers = array();
|
||||
|
||||
if (!$table->is_downloading() && $candelete) {
|
||||
if (!$table->is_downloading() && $includecheckboxes) {
|
||||
$columns[] = 'checkbox';
|
||||
$headers[] = null;
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
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 @@ class quiz_report_responses_table extends quiz_attempt_report_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 ' ';
|
||||
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 '-';
|
||||
|
||||
Reference in New Issue
Block a user