From 2fecd85ba69a174a56d5343a05be5007a3086928 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Wed, 7 May 2008 16:00:56 +0000 Subject: [PATCH] MDL-14734 "improve interface for deleting attempts" * The control for deleting attempts is a drop down box with onchange javascript to submit the form, you cannot see the label to say what the drop down box does. Better to use a button. The button label is visible so you can see what it does. * Checkboxes should be displayed when there is no attempt to delete. * The whole column for checkboxes should be removed when no attempts are displayed ie. when showing students with no attempts. --- lang/en_utf8/quiz_overview.php | 1 + mod/quiz/report/overview/report.php | 64 ++++++++++++----------------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/lang/en_utf8/quiz_overview.php b/lang/en_utf8/quiz_overview.php index b7719fd724..0fa8ca95ab 100644 --- a/lang/en_utf8/quiz_overview.php +++ b/lang/en_utf8/quiz_overview.php @@ -6,6 +6,7 @@ $string['allattempts'] = 'Show all attempts'; $string['allstudents'] = 'Show all $a'; $string['attemptsonly'] = 'Show $a with attempts only'; $string['attemptsprepage'] = 'Attempts shown per page'; +$string['deleteselected'] = 'Delete selected attempts'; $string['noattemptsonly'] = 'Show $a with no attempts only'; $string['optallattempts'] = 'all attempts'; $string['optallstudents'] = 'all \'$a\''; diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 0d13a808bc..181c282c47 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -30,33 +30,24 @@ class quiz_report extends quiz_default_report { $this->print_header_and_tabs($cm, $course, $quiz, "overview"); } - // Deal with actions - $action = optional_param('action', '', PARAM_ACTION); - - switch($action) { - case 'delete': // Some attempts need to be deleted - require_capability('mod/quiz:deleteattempts', $context); - $attemptids = optional_param('attemptid', array(), PARAM_INT); - - foreach($attemptids as $attemptid) { - add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, - $attemptid, $cm->id); - quiz_delete_attempt($attemptid, $quiz); - } - break; + if($attemptids = optional_param('attemptid', array(), PARAM_INT)) { + //attempts need to be deleted + require_capability('mod/quiz:deleteattempts', $context); + $attemptids = optional_param('attemptid', array(), PARAM_INT); + foreach($attemptids as $attemptid) { + add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, + $attemptid, $cm->id); + quiz_delete_attempt($attemptid, $quiz); + } + //No need for a redirect, any attemptids that do not exist are ignored. + //So no problem if the user refreshes and tries to delete the same attempts + //twice. } // Set of format options for teacher-created content, for example overall feedback. $nocleanformatoptions = new stdClass; $nocleanformatoptions->noclean = true; - // Prepare list of available actions to perform on attempts - we only want to show the checkbox. - // Column on the table if there are options. - $attemptactions = array(); - if (has_capability('mod/quiz:deleteattempts', $context)) { - $attemptactions['delete'] = get_string('delete'); - } - // Work out some display options - whether there is feedback, and whether scores should be shown. $hasfeedback = quiz_has_feedback($quiz->id) && $quiz->grade > 1.e-7 && $quiz->sumgrades > 1.e-7; $fakeattempt = new stdClass(); @@ -99,6 +90,11 @@ class quiz_report extends quiz_default_report { if ($pagesize < 1) { $pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE; } + // 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', $context) + && ($attemptsmode!= QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO); + $displayoptions = array(); $displayoptions['attemptsmode'] = $attemptsmode; @@ -132,7 +128,7 @@ class quiz_report extends quiz_default_report { $tableheaders = array('', get_string('name'), get_string('startedon', 'quiz'), get_string('timecompleted','quiz'), get_string('attemptduration', 'quiz')); - if (!empty($attemptactions)) { + if ($candelete) { array_unshift($tablecolumns, 'checkbox'); array_unshift($tableheaders, NULL); } @@ -450,8 +446,12 @@ class quiz_report extends quiz_default_report { // Username columns. $row = array(); if (!$download) { - if (!empty($attemptactions)) { - $row[] = ''; + if ($candelete) { + if ($attempt->attempt){ + $row[] = ''; + } else { + $row[] = ''; + } } $row[] = $picture; $row[] = $userlink; @@ -555,9 +555,7 @@ class quiz_report extends quiz_default_report { // Start form echo '
'; echo '
'; + '" onsubmit="confirm(\''.$strreallydel.'\');">'; echo $reporturlwithdisplayoptions->hidden_params_out(); echo '
'; @@ -565,7 +563,7 @@ class quiz_report extends quiz_default_report { $table->print_html(); // Print "Select all" etc. - if (!empty($attempts) && !empty($attemptactions)) { + if (!empty($attempts) && $candelete) { echo ''; echo '
'; echo ''. @@ -573,15 +571,7 @@ class quiz_report extends quiz_default_report { echo ''. get_string('selectnone', 'quiz').' '; echo '  '; - choose_from_menu($attemptactions, 'action', '', get_string('withselected', 'quiz'), - 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');'); - echo ''; - echo ''; + echo ''; echo '
'; } // Close form -- 2.39.5