/** * Returns if scale used anywhere - activities, grade items, outcomes, etc. * @return bool */ function is_used() { global $CFG; // count grade items excluding the $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE scaleid = {$this->id} AND outcomeid IS NULL"; if (count_records_sql($sql)) { return true; } // count outcomes $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_outcomes WHERE scaleid = {$this->id}"; if (count_records_sql($sql)) { return true; } $legacy_mods = false; if ($mods = get_records('modules', 'visible', 1)) { foreach ($mods as $mod) { //Check cm->name/lib.php exists if (file_exists($CFG->dirroot . '/mod/' . $mod->name . '/lib.php')) { include_once $CFG->dirroot . '/mod/' . $mod->name . '/lib.php'; $function_name = $mod->name . '_scale_used_anywhere'; $old_function_name = $mod->name . '_scale_used'; if (function_exists($function_name)) { if ($function_name($this->id)) { return true; } } else { if (function_exists($old_function_name)) { $legacy_mods = true; debugging('Please notify the developer of module "' . $mod->name . '" that new function module_scale_used_anywhere() should be implemented.', DEBUG_DEVELOPER); break; } } } } } // some mods are missing the new xxx_scale_used_anywhere() - use the really slow old way if ($legacy_mods) { if (!empty($this->courseid)) { if (course_scale_used($this->courseid, $this->id)) { return true; } } else { $courses = array(); if (site_scale_used($this->id, $courses)) { return true; } } } return false; }
$path = "{$CFG->wwwroot}/course"; $data = array(); $incustom = true; foreach ($scales as $scale) { //Check the separator if (empty($scale->courseid) && $incustom) { $incustom = false; $line = "hr"; $data[] = $line; } $line = array(); $line[] = "<a target=\"scale\" title=\"{$scale->name}\" href=\"{$CFG->wwwroot}/course/scales.php?id={$course->id}&scaleid={$scale->id}&action=details\" " . "onclick=\"return openpopup('/course/scales.php?id={$course->id}\\&scaleid={$scale->id}&action=details', 'scale', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">" . $scale->name . "</a><br /><font size=\"-1\">" . str_replace(",", ", ", $scale->scale) . "</font>"; if (!empty($scale->courseid)) { $scale_used = course_scale_used($course->id, $scale->id); } else { $scale_used = site_scale_used($scale->id, $courses); } $line[] = $scale_used ? get_string("yes") : get_string("no"); if ($incustom) { $line[] = $strcustomscale; } else { $line[] = $strstandardscale; } $buttons = ""; if (!$scale_used && ($incustom || has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID)))) { $buttons .= "<a title=\"{$stredit}\" href=\"{$path}/scales.php?id={$course->id}&scaleid={$scale->id}&action=edit\"><img" . " src=\"{$CFG->pixpath}/t/edit.gif\" class=\"iconsmall\" alt=\"{$stredit}\" /></a> "; if ($incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $buttons .= "<a title=\"{$strdown}\" href=\"{$path}/scales.php?id={$course->id}&scaleid={$scale->id}&action=down&sesskey={$USER->sesskey}\"><img" . " src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\" alt=\"{$strdown}\" /></a> "; } if (!$incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $buttons .= "<a title=\"{$strup}\" href=\"{$path}/scales.php?id={$course->id}&scaleid={$scale->id}&action=up&sesskey={$USER->sesskey}\"><img" . " src=\"{$CFG->pixpath}/t/up.gif\" class=\"iconsmall\" alt=\"{$strup}\" /></a> ";