}
/**
- debugging('course_scale_used() is deprecated and never used, plugins must implement <modname>_scale_used_anywhere, '.
+ * Returns the rename action.
+ *
+ * @deprecated since 3.1
+ * @param cm_info $mod The module to produce editing buttons for
+ * @param int $sr The section to link back to (used for creating the links)
+ * @return The markup for the rename action, or an empty string if not available.
+ */
+function course_get_cm_rename_action(cm_info $mod, $sr = null) {
+ global $COURSE, $OUTPUT;
+
+ static $str;
+ static $baseurl;
+
+ debugging('Function course_get_cm_rename_action() is deprecated. Please use inplace_editable ' .
+ 'https://docs.moodle.org/dev/Inplace_editable', DEBUG_DEVELOPER);
+
+ $modcontext = context_module::instance($mod->id);
+ $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
+
+ if (!isset($str)) {
+ $str = get_strings(array('edittitle'));
+ }
+
+ if (!isset($baseurl)) {
+ $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
+ }
+
+ if ($sr !== null) {
+ $baseurl->param('sr', $sr);
+ }
+
+ // AJAX edit title.
+ if ($mod->has_view() && $hasmanageactivities && course_ajax_enabled($COURSE) &&
+ (($mod->course == $COURSE->id) || ($mod->course == SITEID))) {
+ // we will not display link if we are on some other-course page (where we should not see this module anyway)
+ return html_writer::span(
+ html_writer::link(
+ new moodle_url($baseurl, array('update' => $mod->id)),
+ $OUTPUT->pix_icon('t/editstring', '', 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')),
+ array(
+ 'class' => 'editing_title',
+ 'data-action' => 'edittitle',
+ 'title' => $str->edittitle,
+ )
+ )
+ );
+ }
+ return '';
+}
++
++/*
+ * This function returns the number of activities using the given scale in the given course.
+ *
+ * @deprecated since Moodle 3.1
+ * @param int $courseid The course ID to check.
+ * @param int $scaleid The scale ID to check
+ * @return int
+ */
+ function course_scale_used($courseid, $scaleid) {
+ global $CFG, $DB;
+
- debugging('site_scale_used() is deprecated and never used, plugins must implement <modname>_scale_used_anywhere, '.
++ debugging('course_scale_used() is deprecated and never used, plugins can implement <modname>_scale_used_anywhere, '.
+ 'all implementations of <modname>_scale_used are now ignored', DEBUG_DEVELOPER);
+
+ $return = 0;
+
+ if (!empty($scaleid)) {
+ if ($cms = get_course_mods($courseid)) {
+ foreach ($cms as $cm) {
+ // Check cm->name/lib.php exists.
+ if (file_exists($CFG->dirroot.'/mod/'.$cm->modname.'/lib.php')) {
+ include_once($CFG->dirroot.'/mod/'.$cm->modname.'/lib.php');
+ $functionname = $cm->modname.'_scale_used';
+ if (function_exists($functionname)) {
+ if ($functionname($cm->instance, $scaleid)) {
+ $return++;
+ }
+ }
+ }
+ }
+ }
+
+ // Check if any course grade item makes use of the scale.
+ $return += $DB->count_records('grade_items', array('courseid' => $courseid, 'scaleid' => $scaleid));
+
+ // Check if any outcome in the course makes use of the scale.
+ $return += $DB->count_records_sql("SELECT COUNT('x')
+ FROM {grade_outcomes_courses} goc,
+ {grade_outcomes} go
+ WHERE go.id = goc.outcomeid
+ AND go.scaleid = ? AND goc.courseid = ?",
+ array($scaleid, $courseid));
+ }
+ return $return;
+ }
+
+ /**
+ * This function returns the number of activities using scaleid in the entire site
+ *
+ * @deprecated since Moodle 3.1
+ * @param int $scaleid
+ * @param array $courses
+ * @return int
+ */
+ function site_scale_used($scaleid, &$courses) {
+ $return = 0;
+
++ debugging('site_scale_used() is deprecated and never used, plugins can implement <modname>_scale_used_anywhere, '.
+ 'all implementations of <modname>_scale_used are now ignored', DEBUG_DEVELOPER);
+
+ if (!is_array($courses) || count($courses) == 0) {
+ $courses = get_courses("all", false, "c.id, c.shortname");
+ }
+
+ if (!empty($scaleid)) {
+ if (is_array($courses) && count($courses) > 0) {
+ foreach ($courses as $course) {
+ $return += course_scale_used($course->id, $scaleid);
+ }
+ }
+ }
+ return $return;
+ }