diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 5a20af8e8e37e..1a63f4f1cfa4d 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -179,7 +179,8 @@ 'idnumber' => new lang_string('sort_idnumber', 'admin'), ); $temp->add(new admin_setting_configselect('navsortmycoursessort', new lang_string('navsortmycoursessort', 'admin'), new lang_string('navsortmycoursessort_help', 'admin'), 'sortorder', $sortoptions)); - $temp->add(new admin_setting_configtext('navcourselimit',new lang_string('navcourselimit','admin'),new lang_string('confignavcourselimit', 'admin'),20,PARAM_INT)); + $temp->add(new admin_setting_configtext('navcourselimit', new lang_string('navcourselimit', 'admin'), + new lang_string('confignavcourselimit', 'admin'), 10, PARAM_INT)); $temp->add(new admin_setting_configcheckbox('usesitenameforsitepages', new lang_string('usesitenameforsitepages', 'admin'), new lang_string('configusesitenameforsitepages', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('linkadmincategories', new lang_string('linkadmincategories', 'admin'), new lang_string('linkadmincategories_help', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('linkcoursesections', new lang_string('linkcoursesections', 'admin'), new lang_string('linkcoursesections_help', 'admin'), 0)); diff --git a/lang/en/admin.php b/lang/en/admin.php index f0d5e4f4c943e..b9bb1e5cded70 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -274,7 +274,7 @@ $string['configmycoursesperpage'] = 'Maximum number of courses to display in any list of a user\'s own courses'; $string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site navigation with /my'; $string['configmypagelocked'] = 'This setting prevents the default page from being edited by any non-admins'; -$string['confignavcourselimit'] = 'Limits the number of courses shown to the user when they are either not logged in or are not enrolled in any courses.'; +$string['confignavcourselimit'] = 'Limits the number of courses shown to the user in the navigation.'; $string['confignavshowallcourses'] = 'This setting determines whether users who are enrolled in courses can see Courses (listing all courses) in the navigation, in addition to My Courses (listing courses in which they are enrolled).'; $string['confignavshowcategories'] = 'Show course categories in the navigation bar and navigation blocks. This does not occur with courses the user is currently enrolled in, they will still be listed under mycourses without categories.'; $string['confignoreplyaddress'] = 'Emails are sometimes sent out on behalf of a user (eg forum posts). The email address you specify here will be used as the "From" address in those cases when the recipients should not be able to reply directly to the user (eg when a user chooses to keep their address private). This setting will also be used as the envelope sender when sending email.'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 91b611e06839c..8d1c664b05350 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2877,5 +2877,15 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2017061201.00); } + if ($oldversion < 2017061301.00) { + // Check if the value of 'navcourselimit' is set to the old default value, if so, change it to the new default. + if ($CFG->navcourselimit == 20) { + set_config('navcourselimit', 10); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2017061301.00); + } + return true; } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 8f536cd537340..0a9b47c7cb98c 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -84,6 +84,8 @@ class navigation_node implements renderable { const COURSE_MY = 1; /** var int Course the current user is currently viewing */ const COURSE_CURRENT = 2; + /** var string The course index page navigation node */ + const COURSE_INDEX_PAGE = 'courseindexpage'; /** @var int Parameter to aid the coder in tracking [optional] */ public $id = null; @@ -430,7 +432,7 @@ public function find($key, $type) { public function build_flat_navigation_list(flat_navigation $nodes, $showdivider = false) { if ($this->showinflatnavigation) { $indent = 0; - if ($this->type == self::TYPE_COURSE) { + if ($this->type == self::TYPE_COURSE || $this->key == self::COURSE_INDEX_PAGE) { $indent = 1; } $flat = new flat_navigation_node($this, $indent); @@ -2892,6 +2894,9 @@ public function find($key, $type) { */ protected function load_courses_enrolled() { global $CFG; + + $limit = (int) $CFG->navcourselimit; + $sortorder = 'visible DESC'; // Prevent undefined $CFG->navsortmycoursessort errors. if (empty($CFG->navsortmycoursessort)) { @@ -2900,7 +2905,9 @@ protected function load_courses_enrolled() { // Append the chosen sortorder. $sortorder = $sortorder . ',' . $CFG->navsortmycoursessort . ' ASC'; $courses = enrol_get_my_courses('*', $sortorder); - if (count($courses) && $this->show_my_categories()) { + $numcourses = count($courses); + $courses = array_slice($courses, 0, $limit); + if ($numcourses && $this->show_my_categories()) { // Generate an array containing unique values of all the courses' categories. $categoryids = array(); foreach ($courses as $course) { @@ -2956,6 +2963,14 @@ protected function load_courses_enrolled() { foreach ($courses as $course) { $this->add_course($course, false, self::COURSE_MY); } + // Show a link to the course page if there are more courses the user is enrolled in. + if ($numcourses > $limit) { + // Adding hash to URL so the link is not highlighted in the navigation when clicked. + $url = new moodle_url('/course/index.php#'); + $parent = $this->rootnodes['mycourses']; + $coursenode = $parent->add(get_string('morenavigationlinks'), $url, self::TYPE_CUSTOM, null, self::COURSE_INDEX_PAGE); + $coursenode->showinflatnavigation = true; + } } } diff --git a/version.php b/version.php index d9cc08bb9eb6d..b36d5e2f90732 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2017061300.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2017061301.00; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.