diff --git a/admin/tool/monitor/classes/output/managesubs/renderer.php b/admin/tool/monitor/classes/output/managesubs/renderer.php index edf8b499527..30d6b660562 100644 --- a/admin/tool/monitor/classes/output/managesubs/renderer.php +++ b/admin/tool/monitor/classes/output/managesubs/renderer.php @@ -71,8 +71,9 @@ class renderer extends \plugin_renderer_base { * @return string to display on the mangesubs page. */ protected function render_course_select(rules $renderable) { - $select = $renderable->get_user_courses_select(); - return $this->render($select);; + if ($select = $renderable->get_user_courses_select()) { + return $this->render($select); + } } /** diff --git a/admin/tool/monitor/classes/output/managesubs/rules.php b/admin/tool/monitor/classes/output/managesubs/rules.php index f891e90c1a1..debe732e9be 100644 --- a/admin/tool/monitor/classes/output/managesubs/rules.php +++ b/admin/tool/monitor/classes/output/managesubs/rules.php @@ -154,14 +154,24 @@ class rules extends \table_sql implements \renderable { /** * Gets a list of courses where the current user can subscribe to rules as a dropdown. * - * @return \single_select list of courses. + * @return \single_select|bool returns the list of courses, or false if the select box + * should not be displayed. */ public function get_user_courses_select() { - $courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname'); + global $DB; + + // If the number of courses on the site exceed the maximum drop down limit do not display the select box. + $numcourses = $DB->count_records('course'); + if ($numcourses > COURSE_MAX_COURSES_PER_DROPDOWN) { + return false; + } + $options = array(0 => get_string('site')); - $systemcontext = \context_system::instance(); - foreach ($courses as $course) { - $options[$course->id] = format_text($course->fullname, array('context' => $systemcontext)); + if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname')) { + foreach ($courses as $course) { + $options[$course->id] = format_string($course->fullname, true, + array('context' => \context_course::instance($course->id))); + } } $url = new \moodle_url('/admin/tool/monitor/index.php'); $select = new \single_select($url, 'courseid', $options, $this->courseid);