$mform->setHelpButton('standard', array(false, get_string('scalestandard'),
false, true, false, get_string('scalestandardhelp', 'grades')));
- $mform->addElement('static', 'activities', get_string('activities'));
+ $mform->addElement('static', 'used', get_string('used'));
$mform->addElement('textarea', 'scale', get_string('scale'), array('cols'=>50, 'rows'=>2));
$mform->setHelpButton('scale', array('scales', get_string('scale')));
if ($id = $mform->getElementValue('id')) {
$scale = grade_scale::fetch(array('id'=>$id));
- $count = $scale->get_item_uses_count();
+ $used = $scale->is_used();
- if ($count) {
+ if ($used) {
$mform->hardFreeze('scale');
}
} else if (empty($scale->courseid) and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
- } else if ($count and !empty($scale->courseid)) {
+ } else if ($used and !empty($scale->courseid)) {
$mform->hardFreeze('standard');
}
- $activities_el =& $mform->getElement('activities');
- $activities_el->setValue(get_string('usedinnplaces', '', $count));
+ $usedstr = $scale->is_used() ? get_string('yes') : get_string('no');
+ $used_el =& $mform->getElement('used');
+ $used_el->setValue($usedstr);
} else {
- $mform->removeElement('activities');
+ $mform->removeElement('used');
if (empty($courseid) or !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
}
$strdelete = get_string('delete');
$stredit = get_string('edit');
$srtcreatenewscale = get_string('scalescustomcreate');
-$stritems = get_string('items', 'grades');
+$strused = get_string('used');
$stredit = get_string('edit');
switch ($action) {
$line = array();
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
- $scales_uses = $scale->get_item_uses_count();
- $line[] = $scales_uses;
+ $used = $scale->is_used();
+ $line[] = $used ? get_string('yes') : get_string('no');
$buttons = "";
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$scale->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
- if (empty($scales_uses)) {
+ if (!$used) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
- $table->head = array($strscale, $stritems, $stredit);
+ $table->head = array($strscale, $strused, $stredit);
$table->size = array('70%', '20%', '10%');
$table->align = array('left', 'center', 'center');
$table->width = '90%';
$line = array();
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
- $scales_uses = $scale->get_item_uses_count();
- $line[] = $scales_uses;
+ $used = $scale->is_used();
+ $line[] = $used ? get_string('yes') : get_string('no');
$buttons = "";
if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$scale->id\"><img".
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
}
- if (empty($scales_uses) and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+ if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
- $table->head = array($strscale, $stritems, $stredit);
+ $table->head = array($strscale, $strused, $stredit);
$table->size = array('70%', '20%', '10%');
$table->align = array('left', 'center', 'center');
$table->width = '90%';
$string['uploadserverlimit'] = 'Uploaded file exceeded the maximum size limit set by the server';
$string['uploadthisfile'] = 'Upload this file';
$string['uploadusers'] = 'Upload users';
+$string['used'] = 'Used';
$string['usedinnplaces'] = 'Used in $a places';
$string['usemessageform'] = 'or use the form below to send a message to the selected students';
$string['user'] = 'User';
* @return boolean
*/
function can_delete() {
- $count = $this->get_item_uses_count();
- return empty($count);
+ return !$this->is_used();
}
/**
- * Returns the number of places where scale is used - activities, grade items, outcomes, etc.
- * @return int
+ * Returns if scale used anywhere - activities, grade items, outcomes, etc.
+ * @return bool
*/
- function get_item_uses_count() {
+ function is_used() {
global $CFG;
-//TODO: fix me - this methods does some duplicate counting in grade items and activities
- $count = 0;
- if (!empty($this->courseid)) {
- if ($scales_uses = course_scale_used($this->courseid,$this->id)) {
- $count += count($scales_uses);
- }
- } else {
- $courses = array();
- if ($scales_uses = site_scale_used($this->id,$courses)) {
- $count += count($scales_uses);
- }
- }
-
- // count grade items
+ // count grade items excluding the
$sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE scaleid = {$this->id} AND outcomeid IS NULL";
- if ($scales_uses = count_records_sql($sql)) {
- $count += $scales_uses;
+ if (count_records_sql($sql)) {
+ return true;
}
// count outcomes
$sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_outcomes WHERE scaleid = {$this->id}";
- if ($scales_uses = count_records_sql($sql)) {
- $count += $scales_uses;
+ 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;
+ 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 $count;
+ return false;
}
}
?>
* @param $scaleid int
* @return boolean True if the scale is used by the assignment
*/
-function assignment_scale_used ($assignmentid, $scaleid) {
+function assignment_scale_used($assignmentid, $scaleid) {
$return = false;
return $return;
}
+/**
+ * Checks if scale is being used by any instance of assignment
+ *
+ * This is used to find out if scale used anywhere
+ * @param $scaleid int
+ * @return boolean True if the scale is used by any assignment
+ */
+function assignment_scale_used_anywhere($scaleid) {
+ if ($scaleid and record_exists('assignment', 'grade', -$scaleid)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
/**
* Make sure up-to-date events are created for all assignment instances
*
return $return;
}
+/**
+ * Checks if scale is being used by any instance of forum
+ *
+ * This is used to find out if scale used anywhere
+ * @param $scaleid int
+ * @return boolean True if the scale is used by any forum
+ */
+function forum_scale_used_anywhere($scaleid) {
+ if ($scaleid and record_exists('forum', 'scale', -$scaleid)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
// SQL FUNCTIONS ///////////////////////////////////////////////////////////
/**
return $return;
}
+/**
+ * Checks if scale is being used by any instance of glossary
+ *
+ * This is used to find out if scale used anywhere
+ * @param $scaleid int
+ * @return boolean True if the scale is used by any glossary
+ */
+function glossary_scale_used_anywhere($scaleid) {
+ if ($scaleid and record_exists('glossary', 'scale', -$scaleid)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
//////////////////////////////////////////////////////////////////////////////////////
/// Any other glossary functions go here. Each of them must have a name that
/// starts with glossary_
return $report;
}
+/**
+ * Checks if scale is being used by any instance of hotpot
+ *
+ * This is used to find out if scale used anywhere
+ * @param $scaleid int
+ * @return boolean True if the scale is used by any hotpot
+ */
+function hotpot_scale_used_anywhere($scaleid) {
+ return false;
+}
+
//////////////////////////////////////////////////////////
/// Any other hotpot functions go here.
/// Each of them must have a name that starts with hotpot
return $return;
}
+/**
+ * Checks if scale is being used by any instance of journal
+ *
+ * This is used to find out if scale used anywhere
+ * @param $scaleid int
+ * @return boolean True if the scale is used by any journal
+ */
+function journal_scale_used_anywhere($scaleid) {
+ if ($scaleid and record_exists('journal', 'assessed', -$scaleid)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
// SQL FUNCTIONS ///////////////////////////////////////////////////////////////////
function journal_get_users_done($journal) {
return $return;
}
+/**
+ * Checks if scale is being used by any instance of lams
+ *
+ * This is used to find out if scale used anywhere
+ * @param $scaleid int
+ * @return boolean True if the scale is used by any lams
+ */
+function lams_scale_used_anywhere($scaleid) {
+ return false;
+}
+
//////////////////////////////////////////////////////////////////////////////////////
/// Any other lams functions go here. Each of them must have a name that
/// starts with lams_