MDL-66851 block_starredcourses: Hide 'hidden' courses from students
authorMihail Geshoski <mihail@moodle.com>
Tue, 8 Oct 2019 01:52:37 +0000 (09:52 +0800)
committerMihail Geshoski <mihail@moodle.com>
Tue, 8 Oct 2019 01:52:37 +0000 (09:52 +0800)
Thanks to Mark Sharp for the bug report and fix suggestion.

blocks/starredcourses/classes/external.php

index f5cb1c2..d1ace2c 100644 (file)
@@ -88,13 +88,18 @@ class block_starredcourses_external extends core_course_external {
             return ($a->timemodified > $b->timemodified) ? -1 : 1;
         });
 
-        $formattedcourses = array_map(function($favourite) use ($renderer) {
+        $formattedcourses = array();
+        foreach ($favourites as $favourite) {
             $course = get_course($favourite->itemid);
             $context = \context_course::instance($favourite->itemid);
-
-            $exporter = new course_summary_exporter($course, ['context' => $context, 'isfavourite' => true]);
-            return $exporter->export($renderer);
-        }, $favourites);
+            $canviewhiddencourses = has_capability('moodle/course:viewhiddencourses', $context);
+
+            if ($course->visible || $canviewhiddencourses) {
+                $exporter = new course_summary_exporter($course, ['context' => $context, 'isfavourite' => true]);
+                $formattedcourse = $exporter->export($renderer);
+                $formattedcourses[] = $formattedcourse;
+            }
+        }
 
         return $formattedcourses;
     }