/** * This will change the activity module icon to represent the grade percentage. * * @param cm_info $cm * @return void */ function mod_subcourse_cm_info_dynamic(cm_info $cm) { global $USER; $currentgrade = grade_get_grades($cm->course, 'mod', 'subcourse', $cm->instance, $USER->id); $gradepass = $currentgrade->items[0]->gradepass; // Use the maximum grade if there is no passing grade set if ($gradepass == 0) { $gradepass = $currentgrade->items[0]->grademax; } if (!empty($currentgrade->items[0]->grades)) { $currentgrade = reset($currentgrade->items[0]->grades); if (isset($currentgrade->grade) and !$currentgrade->hidden) { $grade = $currentgrade->grade; // Convert the percent complete to a whole fraction of 20 to match the icon images. $gradeicon = floor(subcourse_percent_complete($gradepass, $grade) / 5); $cm->set_icon_url(new moodle_url('/mod/subcourse/pix/icon-' . $gradeicon . '.svg')); } } }