]> git.mjollnir.org Git - moodle.git/commitdiff
edit/outcomeitem.php - fixed selection of outcomes to show only available course...
authorskodak <skodak>
Tue, 31 Jul 2007 13:04:35 +0000 (13:04 +0000)
committerskodak <skodak>
Tue, 31 Jul 2007 13:04:35 +0000 (13:04 +0000)
grade/edit/outcome/course.php
grade/edit/tree/outcomeitem_form.php
lib/grade/grade_outcome.php

index 98aecd8236ed0e00cbfd9d56df8d2aec0712141f..b8ccb2985cbcdb2d9deecc7e8919221b2986e559 100644 (file)
@@ -19,13 +19,9 @@ require_capability('moodle/course:update', $context);
 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcomes', 'courseid'=>$courseid));
 
 // first of all fix the state of outcomes_course table
-if (!$standardoutcomes = grade_outcome::fetch_all_global()) {
-    $standardoutcomes = array();
-}
-if (!$co_custom = grade_outcome::fetch_all_local($courseid)) {
-    $co_custom = array();
-}
-$co_standard_used = array();
+$standardoutcomes    = grade_outcome::fetch_all_global();
+$co_custom           = grade_outcome::fetch_all_local($courseid);
+$co_standard_used    = array();
 $co_standard_notused = array();
 
 if ($courseused = get_records('grade_outcomes_courses', 'courseid', $courseid, '', 'outcomeid')) {
index e00ff1b034afe73426ed682e429befd6e79ee4b7..eb9a5058a8a5281af0cfaffc7fd520a93733238d 100644 (file)
@@ -20,7 +20,7 @@ class edit_outcomeitem_form extends moodleform {
 
         // allow setting of outcomes on module items too
         $options = array();
-        if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$COURSE->id), true)) {
+        if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
             foreach ($outcomes as $outcome) {
                 $options[$outcome->id] = $outcome->get_name();
             }
index af00c562decf11a3ffd0ca45b93c53040da8a5f5..62b094797de36ae128173626d042177e8b824fde 100644 (file)
@@ -162,20 +162,55 @@ class grade_outcome extends grade_object {
 
     /**
      * Static function returning all global outcomes
+     * @static
      * @return object
      */
     function fetch_all_global() {
-        return grade_outcome::fetch_all(array('courseid'=>null));
+        if (!$outcomes = grade_outcome::fetch_all(array('courseid'=>null))) {
+            $outcomes = array();
+        }
+        return $outcomes;
     }
 
     /**
      * Static function returning all local course outcomes
+     * @static
+     * @param int $courseid
      * @return object
      */
     function fetch_all_local($courseid) {
-        return grade_outcome::fetch_all(array('courseid'=>$courseid));
+        if (!$outcomes =grade_outcome::fetch_all(array('courseid'=>$courseid))) {
+            $outcomes = array();
+        }
+        return $outcomes;
     }
 
+    /**
+     * Static method - returns all outcomes available in course
+     * @static
+     * @param int $courseid
+     * @return array
+     */
+    function fetch_all_available($courseid) {
+        global $CFG;
+
+        $result = array();
+        $sql = "SELECT go.*
+                  FROM {$CFG->prefix}grade_outcomes go, {$CFG->prefix}grade_outcomes_courses goc
+                 WHERE go.id = goc.outcomeid AND goc.courseid = {$courseid}
+              ORDER BY go.id ASC";
+
+        if ($datas = get_records_sql($sql)) {
+            foreach($datas as $data) {
+                $instance = new grade_outcome();
+                grade_object::set_properties($instance, $data);
+                $result[$instance->id] = $instance;
+            }
+        }
+        return $result;
+    }
+
+
     /**
      * Returns the most descriptive field for this object. This is a standard method used
      * when we do not know the exact type of an object.