diff --git a/grade/edit/outcome/course.php b/grade/edit/outcome/course.php
index aa1dd58ea4bb8..98aecd8236ed0 100644
--- a/grade/edit/outcome/course.php
+++ b/grade/edit/outcome/course.php
@@ -45,10 +45,10 @@
foreach($co_custom as $oid=>$outcome) {
if (!in_array($oid, $courseused)) {
$courseused[$oid] = $oid;
- $obj = new object();
- $obj->courseid = $courseid;
- $obj->outcomeid = $oid;
- insert_record('grade_outcomes_courses', $obj);
+ $goc = new object();
+ $goc->courseid = $courseid;
+ $goc->outcomeid = $oid;
+ insert_record('grade_outcomes_courses', $goc);
}
}
@@ -63,10 +63,10 @@
if (!in_array($oid, $courseused)) {
$courseused[$oid] = $oid;
- $obj = new object();
- $obj->courseid = $courseid;
- $obj->outcomeid = $oid;
- insert_record('grade_outcomes_courses', $obj);
+ $goc = new object();
+ $goc->courseid = $courseid;
+ $goc->outcomeid = $oid;
+ insert_record('grade_outcomes_courses', $goc);
}
}
}
diff --git a/grade/edit/outcome/edit.php b/grade/edit/outcome/edit.php
index d24c5132958d7..ca4c4db8f5472 100644
--- a/grade/edit/outcome/edit.php
+++ b/grade/edit/outcome/edit.php
@@ -93,7 +93,7 @@
$outcome->update();
}
- redirect($returnurl, 'temp debug delay', 3);
+ redirect($returnurl);
}
$strgrades = get_string('grades');
diff --git a/grade/edit/outcome/edit_form.php b/grade/edit/outcome/edit_form.php
index cd08325661b18..6cb718e56af9f 100644
--- a/grade/edit/outcome/edit_form.php
+++ b/grade/edit/outcome/edit_form.php
@@ -80,9 +80,10 @@ function definition_after_data() {
if ($id = $mform->getElementValue('id')) {
$outcome = grade_outcome::fetch(array('id'=>$id));
- $count = $outcome->get_uses_count();
+ $itemcount = $outcome->get_item_uses_count();
+ $coursecount = $outcome->get_course_uses_count();
- if ($count) {
+ if ($itemcount) {
$mform->hardFreeze('scaleid');
}
@@ -92,7 +93,7 @@ function definition_after_data() {
} else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
- } else if ($count and !empty($outcome->courseid)) {
+ } else if ($coursecount and empty($outcome->courseid)) {
$mform->hardFreeze('standard');
}
diff --git a/grade/edit/outcome/index.php b/grade/edit/outcome/index.php
index 38106aaad65a3..8fe76d41ebcb2 100644
--- a/grade/edit/outcome/index.php
+++ b/grade/edit/outcome/index.php
@@ -41,7 +41,8 @@
$strdelete = get_string('delete');
$stredit = get_string('edit');
$srtcreatenewoutcome = get_string('outcomecreate', 'grades');
-$stractivities = get_string('activities');
+$stritems = get_string('items', 'grades');
+$strcourses = get_string('courses');
$stredit = get_string('edit');
switch ($action) {
@@ -121,13 +122,12 @@
}
}
- $outcomes_uses = $outcome->get_uses_count();
- $line[] = $outcomes_uses;
+ $line[] = $outcome->get_item_uses_count();
$buttons = "";
$buttons .= "id\">pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /> ";
- if (empty($outcomes_uses)) {
+ if ($outcome->can_delete()) {
$buttons .= "id&action=delete&sesskey=$USER->sesskey\">pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /> ";
}
@@ -135,7 +135,7 @@
$data[] = $line;
}
$table = new object();
- $table->head = array($strfullname, $strshortname, $strscale, $stractivities, $stredit);
+ $table->head = array($strfullname, $strshortname, $strscale, $stritems, $stredit);
$table->size = array('30%', '20%', '20%', '20%', '10%');
$table->align = array('left', 'left', 'left', 'center', 'center');
$table->width = '90%';
@@ -172,15 +172,15 @@
}
}
- $outcomes_uses = $outcome->get_uses_count();
- $line[] = $outcomes_uses;
+ $line[] = $outcome->get_course_uses_count();
+ $line[] = $outcome->get_item_uses_count();
$buttons = "";
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$buttons .= "id\">pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /> ";
}
- if (empty($outcomes_uses) and has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
+ if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM)) and $outcome->can_delete()) {
$buttons .= "id&action=delete&sesskey=$USER->sesskey\">pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /> ";
}
@@ -188,9 +188,9 @@
$data[] = $line;
}
$table = new object();
- $table->head = array($strfullname, $strshortname, $strscale, $stractivities, $stredit);
- $table->size = array('30%', '20%', '20%', '20%', '10%');
- $table->align = array('left', 'left', 'left', 'center', 'center');
+ $table->head = array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit);
+ $table->size = array('30%', '20%', '20%', '10%', '10%', '10%');
+ $table->align = array('left', 'left', 'left', 'center', 'center', 'center');
$table->width = '90%';
$table->data = $data;
print_table($table);
diff --git a/grade/edit/scale/edit.php b/grade/edit/scale/edit.php
index ba1d2d4d4d310..25380cb5a33f9 100644
--- a/grade/edit/scale/edit.php
+++ b/grade/edit/scale/edit.php
@@ -90,7 +90,7 @@
$scale->update();
}
- redirect($returnurl, 'temp debug delay', 3);
+ redirect($returnurl);
}
$strgrades = get_string('grades');
diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php
index e9480fac81a56..3087266a18254 100644
--- a/lib/grade/grade_outcome.php
+++ b/lib/grade/grade_outcome.php
@@ -78,6 +78,35 @@ class grade_outcome extends grade_object {
*/
var $usermodified;
+ /**
+ * Deletes this outcome from the database.
+ * @param string $source from where was the object deleted (mod/forum, manual, etc.)
+ * @return boolean success
+ */
+ function delete($source=null) {
+ if (!empty($this->courseid)) {
+ delete_records('grade_outcomes_courses', 'outcomeid', $this->id, 'courseid', $this->courseid);
+ }
+ return parent::delete($source);
+ }
+
+ /**
+ * Records this object in the Database, sets its id to the returned value, and returns that value.
+ * If successful this function also fetches the new object data from database and stores it
+ * in object properties.
+ * @param string $source from where was the object inserted (mod/forum, manual, etc.)
+ * @return int PK ID if successful, false otherwise
+ */
+ function insert($source=null) {
+ if ($result = parent::insert($source)) {
+ $goc = new object();
+ $goc->courseid = $this->courseid;
+ $goc->outcomeid = $this->id;
+ insert_record('grade_outcomes_courses', $goc);
+ }
+ return $result;
+ }
+
/**
* Finds and returns a grade_outcome instance based on params.
* @static
@@ -150,26 +179,37 @@ function get_shortname() {
* @return boolean
*/
function can_delete() {
- $count = $this->get_uses_count();
- return empty($count);
+ if ($this->get_item_uses_count()) {
+ return false;
+ }
+ if (empty($this->courseid)) {
+ if ($this->get_course_uses_count()) {
+ return false;
+ }
+ }
+ return true;
}
/**
* Returns the number of places where outcome is used.
* @return int
*/
- function get_uses_count() {
+ function get_course_uses_count() {
global $CFG;
- $count = 0;
-
- // count grade items
- $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE outcomeid = {$this->id}";
- if ($scales_uses = count_records_sql($sql)) {
- $count += $scales_uses;
+ if (!empty($this->courseid)) {
+ return 1;
}
- return $count;
+ return count_records('grade_outcomes_courses', 'outcomeid', $this->id);
+ }
+
+ /**
+ * Returns the number of places where outcome is used.
+ * @return int
+ */
+ function get_item_uses_count() {
+ return count_records('grade_items', 'outcomeid', $this->id);
}
/**