]> git.mjollnir.org Git - moodle.git/commitdiff
fixed several warnings in get_course()
authorskodak <skodak>
Sun, 17 Sep 2006 18:07:35 +0000 (18:07 +0000)
committerskodak <skodak>
Sun, 17 Sep 2006 18:07:35 +0000 (18:07 +0000)
course/index.php
lib/datalib.php

index 6fbd3808bcd6798e6f08516d641dd1247ea5811e..b83a4a1a473132b8c89edf87f742f5591d1f1ae6 100644 (file)
     }
 
 /// Find any orphan courses that don't yet have a valid category and set to default
-    if ($courses = get_courses(NULL,NULL,'c.id, c.category, c.sortorder')) {
+    if ($courses = get_courses(NULL,NULL,'c.id, c.category, c.sortorder, c.visible')) {
         foreach ($courses as $course) {
             if ($course->category and !isset($categories[$course->category])) {
                 set_field("course", "category", $default, "id", $course->id);
index 2b8cea1315d1de07f5a7e151a9b7e2f046ca0c62..e5b8158682e7464b77e8a823c0909b92627f8464 100644 (file)
@@ -483,30 +483,38 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
 
     global $USER, $CFG;
     
-    $categoryselect = "";
     if ($categoryid != "all" && is_numeric($categoryid)) {
         $categoryselect = "WHERE c.category = '$categoryid'";
     } else {
         $categoryselect = "";  
-    }  
+    }
+
+    if (empty($sort)) {
+        $sortstatement = "";
+    } else {
+        $sortstatement = "ORDER BY $sort";
+    }
+
+    $visiblecourses = array();
     
     // pull out all course matching the cat
-    $courses = get_records_sql("SELECT $fields 
+    if ($courses = get_records_sql("SELECT $fields 
                                 FROM {$CFG->prefix}course c 
                                 $categoryselect
-                                ORDER BY $sort");
-    $visiblecourses = array();
-    
-    // loop throught them
-    foreach ($courses as $course) {
-        if ($course->visible <= 0) {
-            // for hidden courses, require visibility check
-            if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
+                                $sortstatement")) {
+
+        // loop throught them
+        foreach ($courses as $course) {
+
+            if ($course->visible <= 0) {
+                // for hidden courses, require visibility check
+                if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
+                    $visiblecourses [] = $course;  
+                }
+            } else {
                 $visiblecourses [] = $course;  
-            }
-        } else {
-            $visiblecourses [] = $course;  
-        } 
+            } 
+        }
     }
     return $visiblecourses;
 
@@ -1540,4 +1548,4 @@ function category_parent_visible($parent = 0) {
 }
 
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
-?>
+?>
\ No newline at end of file