more Edit/Outcomes improvements - new course column for standard outcomes; outcomes_c...
authorskodak <skodak>
Tue, 31 Jul 2007 12:03:45 +0000 (12:03 +0000)
committerskodak <skodak>
Tue, 31 Jul 2007 12:03:45 +0000 (12:03 +0000)
grade/edit/outcome/course.php
grade/edit/outcome/edit.php
grade/edit/outcome/edit_form.php
grade/edit/outcome/index.php
grade/edit/scale/edit.php
lib/grade/grade_outcome.php

index aa1dd58ea4bb838557ef1f87ea7bcd43b23f5bc7..98aecd8236ed0e00cbfd9d56df8d2aec0712141f 100644 (file)
@@ -45,10 +45,10 @@ foreach ($courseused as $oid) {
 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 ($realused = get_records_select('grade_items', "courseid=$courseid and outcom
 
             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);
             }
         }
     }
index d24c5132958d73bf4ccb5e4eab235680ee290ee9..ca4c4db8f5472c608e0de2dd56253ca2ef7c158c 100644 (file)
@@ -93,7 +93,7 @@ if ($mform->is_cancelled()) {
         $outcome->update();
     }
 
-    redirect($returnurl, 'temp debug delay', 3);
+    redirect($returnurl);
 }
 
 $strgrades       = get_string('grades');
index cd08325661b187d50d1ead858eed83c831d6450b..6cb718e56af9f75102b4d919116e3e0f8ae225d9 100644 (file)
@@ -80,9 +80,10 @@ class edit_outcome_form extends moodleform {
 
         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 @@ class edit_outcome_form extends moodleform {
             } 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');
             }
 
index 38106aaad65a34aa63c08b4e744edf06021e07f1..8fe76d41ebcb2fd5a2efb15debd9564dfb3db16b 100644 (file)
@@ -41,7 +41,8 @@ $strcustomoutcomes   = get_string('outcomescustom', 'grades');
 $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 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
             }
         }
 
-        $outcomes_uses = $outcome->get_uses_count();
-        $line[] = $outcomes_uses;
+        $line[] = $outcome->get_item_uses_count();
 
         $buttons = "";
         $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$outcome->id\"><img".
                     " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
-        if (empty($outcomes_uses)) {
+        if ($outcome->can_delete()) {
             $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
                         " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
         }
@@ -135,7 +135,7 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
         $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 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
             }
         }
 
-        $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 .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$outcome->id\"><img".
                         " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
         }
-        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 .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
                         " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
         }
@@ -188,9 +188,9 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
         $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);
index ba1d2d4d4d31057ba2a1391f3fded37c8d86ce13..25380cb5a33f930f9dc6eded672651aa4e141534 100644 (file)
@@ -90,7 +90,7 @@ if ($mform->is_cancelled()) {
         $scale->update();
     }
 
-    redirect($returnurl, 'temp debug delay', 3);
+    redirect($returnurl);
 }
 
 $strgrades       = get_string('grades');
index e9480fac81a56b9da5143635dc510a3de16e4cc1..3087266a18254520662d61eff274963e9d55a956 100644 (file)
@@ -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 @@ class grade_outcome extends grade_object {
      * @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);
     }
 
     /**