MDL-37361 completion: make completion overrides visible to students
authorJake Dallimore <jake@moodle.com>
Mon, 3 Apr 2017 02:08:10 +0000 (10:08 +0800)
committerJake Dallimore <jake@moodle.com>
Tue, 10 Oct 2017 09:11:13 +0000 (17:11 +0800)
- Set icons in the course/renderer
- Use 'set' in lang strings for simplicity
- Code style fixes

completion/classes/external.php
course/renderer.php
lang/en/completion.php
report/progress/index.php

index 685c3b9..310b2bf 100644 (file)
@@ -201,8 +201,7 @@ class core_completion_external extends external_api {
         $a->activity = $cm->id;
         $fulldescribe = get_string('progress-title', 'completion', $a);
 
-        $img = '<img src="'.$OUTPUT->pix_url('i/'.$completionicon).
-                '" alt="'.s($describe).'" title="'.s($fulldescribe).'" />';
+        $img = $OUTPUT->pix_icon('i/' . $completionicon, s($fulldescribe));
 
         // Set data values for next completion change.
         $otherstate = ($state == COMPLETION_COMPLETE) ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE;
index b1ef9e9..55cc100 100644 (file)
@@ -456,7 +456,7 @@ class core_course_renderer extends plugin_renderer_base {
      * @return string
      */
     public function course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()) {
-        global $CFG;
+        global $CFG, $DB;
         $output = '';
         if (!empty($displayoptions['hidecompletion']) || !isloggedin() || isguestuser() || !$mod->uservisible) {
             return $output;
@@ -485,16 +485,20 @@ class core_course_renderer extends plugin_renderer_base {
         } else if ($completion == COMPLETION_TRACKING_MANUAL) {
             switch($completiondata->completionstate) {
                 case COMPLETION_INCOMPLETE:
-                    $completionicon = 'manual-n'; break;
+                    $completionicon = 'manual-n' . ($completiondata->overrideby ? '-override' : '');
+                    break;
                 case COMPLETION_COMPLETE:
-                    $completionicon = 'manual-y'; break;
+                    $completionicon = 'manual-y' . ($completiondata->overrideby ? '-override' : '');
+                    break;
             }
         } else { // Automatic
             switch($completiondata->completionstate) {
                 case COMPLETION_INCOMPLETE:
-                    $completionicon = 'auto-n'; break;
+                    $completionicon = 'auto-n' . ($completiondata->overrideby ? '-override' : '');
+                    break;
                 case COMPLETION_COMPLETE:
-                    $completionicon = 'auto-y'; break;
+                    $completionicon = 'auto-y' . ($completiondata->overrideby ? '-override' : '');
+                    break;
                 case COMPLETION_COMPLETE_PASS:
                     $completionicon = 'auto-pass'; break;
                 case COMPLETION_COMPLETE_FAIL:
@@ -503,7 +507,15 @@ class core_course_renderer extends plugin_renderer_base {
         }
         if ($completionicon) {
             $formattedname = $mod->get_formatted_name();
-            $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
+            if ($completiondata->overrideby) {
+                $args = new stdClass();
+                $args->modname = $formattedname;
+                $overridebyuser = $DB->get_record('user', array('id' => $completiondata->overrideby), '*', MUST_EXIST);
+                $args->overrideuser = fullname($overridebyuser);
+                $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $args);
+            } else {
+                $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
+            }
 
             if ($this->page->user_is_editing()) {
                 // When editing, the icon is just an image.
@@ -512,7 +524,6 @@ class core_course_renderer extends plugin_renderer_base {
                 $output .= html_writer::tag('span', $this->output->render($completionpixicon),
                         array('class' => 'autocompletion'));
             } else if ($completion == COMPLETION_TRACKING_MANUAL) {
-                $imgtitle = get_string('completion-title-' . $completionicon, 'completion', $formattedname);
                 $newstate =
                     $completiondata->completionstate == COMPLETION_COMPLETE
                     ? COMPLETION_INCOMPLETE
index db94880..5d303c6 100644 (file)
@@ -61,17 +61,21 @@ $string['completion'] = 'Completion tracking';
 $string['completion-alt-auto-enabled'] = 'The system marks this item complete according to conditions: {$a}';
 $string['completion-alt-auto-fail'] = 'Completed: {$a} (did not achieve pass grade)';
 $string['completion-alt-auto-n'] = 'Not completed: {$a}';
+$string['completion-alt-auto-n-override'] = 'Not completed: {$a->modname} (set by {$a->overrideuser})';
 $string['completion-alt-auto-pass'] = 'Completed: {$a} (achieved pass grade)';
 $string['completion-alt-auto-y'] = 'Completed: {$a}';
+$string['completion-alt-auto-y-override'] = 'Completed: {$a->modname} (set by {$a->overrideuser})';
 $string['completion-alt-manual-enabled'] = 'Students can manually mark this item complete: {$a}';
 $string['completion-alt-manual-n'] = 'Not completed: {$a}. Select to mark as complete.';
+$string['completion-alt-manual-n-override'] = 'Not completed: {$a->modname} (set by {$a->overrideuser}). Select to mark as complete.';
 $string['completion-alt-manual-y'] = 'Completed: {$a}. Select to mark as not complete.';
+$string['completion-alt-manual-y-override'] = 'Completed: {$a->modname} (set by {$a->overrideuser}). Select to mark as not complete.';
 $string['completion-fail'] = 'Completed (did not achieve pass grade)';
 $string['completion-n'] = 'Not completed';
-$string['completion-n-override'] = 'Not completed (overrride by {$a})';
+$string['completion-n-override'] = 'Not completed (set by {$a})';
 $string['completion-pass'] = 'Completed (achieved pass grade)';
 $string['completion-y'] = 'Completed';
-$string['completion-y-override'] = 'Completed (overrride by {$a})';
+$string['completion-y-override'] = 'Completed (set by {$a})';
 $string['completion_automatic'] = 'Show activity as complete when conditions are met';
 $string['completion_help'] = 'If enabled, activity completion is tracked, either manually or automatically, based on certain conditions. Multiple conditions may be set if desired. If so, the activity will only be considered complete when ALL conditions are met.
 
index 064461c..234f0eb 100644 (file)
@@ -384,15 +384,15 @@ foreach($progress as $user) {
     foreach($activities as $activity) {
 
         // Get progress information and state
-        if (array_key_exists($activity->id,$user->progress)) {
-            $thisprogress=$user->progress[$activity->id];
-            $state=$thisprogress->completionstate;
+        if (array_key_exists($activity->id, $user->progress)) {
+            $thisprogress = $user->progress[$activity->id];
+            $state = $thisprogress->completionstate;
             $overrideby = $thisprogress->overrideby;
-            $date=userdate($thisprogress->timemodified);
+            $date = userdate($thisprogress->timemodified);
         } else {
-            $state=COMPLETION_INCOMPLETE;
+            $state = COMPLETION_INCOMPLETE;
             $overrideby = 0;
-            $date='';
+            $date = '';
         }
 
         // Work out how it corresponds to an icon
@@ -431,16 +431,14 @@ foreach($progress as $user) {
         if ($csv) {
             print $sep.csv_quote($describe).$sep.csv_quote($date);
         } else {
-            $celltext = '<img src="'.$OUTPUT->image_url('i/'.$completionicon).
-                '" alt="'.s($describe).'" title="'.s($fulldescribe).'" />';
+            $celltext = $OUTPUT->pix_icon('i/' . $completionicon, s($fulldescribe));
             if (has_capability('moodle/course:overridecompletion', $context) &&
                     $state != COMPLETION_COMPLETE_PASS && $state != COMPLETION_COMPLETE_FAIL) {
                 $newstate = ($state == COMPLETION_COMPLETE) ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE;
                 $changecompl = $user->id . '-' . $activity->id . '-' . $newstate;
                 $url = new moodle_url($PAGE->url, array('sesskey' => sesskey(),
                     'changecompl' => $changecompl));
-                $celltext = html_writer::link($url, $celltext, array('class' => 'changecompl',
-                    'data-changecompl' => $changecompl));
+                $celltext = html_writer::link($url, $celltext, array('class' => 'changecompl', 'data-changecompl' => $changecompl));
             }
             print '<td class="completion-progresscell '.$formattedactivities[$activity->id]->datepassedclass.'">'.
                 $celltext . '</td>';