Skip to content

Commit

Permalink
MDL-37361 completion: make completion overrides visible to students
Browse files Browse the repository at this point in the history
- Set icons in the course/renderer
- Use 'set' in lang strings for simplicity
- Code style fixes
  • Loading branch information
snake committed Oct 10, 2017
1 parent 86f359b commit 6f4adc6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
3 changes: 1 addition & 2 deletions completion/classes/external.php
Expand Up @@ -201,8 +201,7 @@ public static function override_activity_completion_status($userid, $cmid, $news
$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;
Expand Down
25 changes: 18 additions & 7 deletions course/renderer.php
Expand Up @@ -456,7 +456,7 @@ function course_search_form($value = '', $format = 'plain') {
* @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;
Expand Down Expand Up @@ -485,16 +485,20 @@ public function course_section_cm_completion($course, &$completioninfo, cm_info
} 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:
Expand All @@ -503,7 +507,15 @@ public function course_section_cm_completion($course, &$completioninfo, cm_info
}
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.
Expand All @@ -512,7 +524,6 @@ public function course_section_cm_completion($course, &$completioninfo, cm_info
$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
Expand Down
8 changes: 6 additions & 2 deletions lang/en/completion.php
Expand Up @@ -61,17 +61,21 @@
$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.
Expand Down
18 changes: 8 additions & 10 deletions report/progress/index.php
Expand Up @@ -384,15 +384,15 @@ function csv_quote($value) {
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
Expand Down Expand Up @@ -431,16 +431,14 @@ function csv_quote($value) {
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>';
Expand Down

0 comments on commit 6f4adc6

Please sign in to comment.