}
/// 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);
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;
}
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
-?>
+?>
\ No newline at end of file