Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed courses and subcategories in an invisible category being visibl…

…e (Bug #4074)

This patch is different from the one form MOODLE_15_STABLE as it used the stored path in category data.
  • Loading branch information...
commit 7fb0fec7574d9a40572bc3e4c21f5702ceadf7aa 1 parent 80be7ee
authored December 13, 2005
20  course/lib.php
@@ -2038,4 +2038,24 @@ function move_courses ($courseids, $categoryid) {
2038 2038
     return true;
2039 2039
 }
2040 2040
 
  2041
+function course_parent_visible($course = null) {
  2042
+    return category_parent_visible($course->category);
  2043
+}
  2044
+
  2045
+function category_parent_visible($parent = 0) {
  2046
+    if (!$parent) {
  2047
+        return true;
  2048
+    }
  2049
+    $category = get_record('course_categories', 'id', $parent);
  2050
+    $list = explode('/', preg_replace('/^\/(.*)$/', '$1', $category->path));
  2051
+    $list[] = $parent;
  2052
+    $parents = get_records_list('course_categories', 'id', implode(',', $list), 'depth DESC');
  2053
+    foreach ($parents as $parent) {
  2054
+        if (!$parent->visible) {
  2055
+            return false;
  2056
+        }
  2057
+    }
  2058
+    return true;
  2059
+}
  2060
+
2041 2061
 ?>
12  lib/datalib.php
@@ -2250,7 +2250,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
2250 2250
  */
2251 2251
 function get_my_courses($userid, $sort='visible DESC,sortorder ASC') {
2252 2252
 
2253  
-    global $CFG;
  2253
+    global $CFG, $USER;
2254 2254
 
2255 2255
     $course = array();
2256 2256
 
@@ -2259,6 +2259,12 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC') {
2259 2259
             $course[$student->course] = $student->course;
2260 2260
         }
2261 2261
     }
  2262
+    $courses = get_records_list('course', 'id', implode(',', $course));
  2263
+    foreach ($courses as $k => $c) {
  2264
+        if (empty($USER->admin) && (!$c->visible || !course_parent_visible($c))) {
  2265
+            unset($course[$c->id]);
  2266
+        }
  2267
+    }
2262 2268
     if ($teachers = get_records('user_teachers', 'userid', $userid, '', 'id, course')) {
2263 2269
         foreach ($teachers as $teacher) {
2264 2270
             $course[$teacher->course] = $teacher->course;
@@ -2350,7 +2356,7 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
2350 2356
 
2351 2357
     if ($courses) {  /// Remove unavailable courses from the list
2352 2358
         foreach ($courses as $key => $course) {
2353  
-            if (!$course->visible) {
  2359
+            if (!$course->visible || !course_parent_visible($course)) {
2354 2360
                 if (!isteacher($course->id)) {
2355 2361
                     unset($courses[$key]);
2356 2362
                     $totalcount--;
@@ -2381,7 +2387,7 @@ function get_categories($parent='none', $sort='sortorder ASC') {
2381 2387
     if ($categories) {  /// Remove unavailable categories from the list
2382 2388
         $creator = iscreator();
2383 2389
         foreach ($categories as $key => $category) {
2384  
-            if (!$category->visible) {
  2390
+            if (!$category->visible || !category_parent_visible($category->parent)) {
2385 2391
                 if (!$creator) {
2386 2392
                     unset($categories[$key]);
2387 2393
                 }
14  lib/moodlelib.php
@@ -1587,6 +1587,13 @@ function require_login($courseid=0, $autologinguest=true, $cm=null) {
1587 1587
             }
1588 1588
             return;
1589 1589
         }
  1590
+        if (! $course = get_record('course', 'id', $courseid)) {
  1591
+            error('That course doesn\'t exist');
  1592
+        }
  1593
+        if (!(isteacher($courseid) || !empty($USER->admin)) && (!$course->visible || !course_parent_visible($course))) {
  1594
+            print_header();
  1595
+            notice(get_string('coursehidden'), $CFG->wwwroot .'/');
  1596
+        }
1590 1597
         if (!empty($USER->student[$courseid]) or !empty($USER->teacher[$courseid]) or !empty($USER->admin)) {
1591 1598
             if (isset($USER->realuser)) {   // Make sure the REAL person can also access this course
1592 1599
                 if (!isteacher($courseid, $USER->realuser)) {
@@ -1599,13 +1606,6 @@ function require_login($courseid=0, $autologinguest=true, $cm=null) {
1599 1606
             }
1600 1607
             return;   // user is a member of this course.
1601 1608
         }
1602  
-        if (! $course = get_record('course', 'id', $courseid)) {
1603  
-            error('That course doesn\'t exist');
1604  
-        }
1605  
-        if (!$course->visible) {
1606  
-            print_header();
1607  
-            notice(get_string('coursehidden'), $CFG->wwwroot .'/');
1608  
-        }
1609 1609
         if ($USER->username == 'guest') {
1610 1610
             switch ($course->guest) {
1611 1611
                 case 0: // Guests not allowed

0 notes on commit 7fb0fec

Please sign in to comment.
Something went wrong with that request. Please try again.