From c0a9edbd18fde2303b122e9e096d02f1923dfbc3 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 9 Jun 2017 11:47:22 +0800 Subject: [PATCH 1/3] MDL-59140 core: changes to the 'navcourselimit' setting Changed the default and description. --- admin/settings/appearance.php | 3 ++- lang/en/admin.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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.'; From fa238237a0ce5701312d51daa162d0cad9b00a58 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 9 Jun 2017 12:56:25 +0800 Subject: [PATCH 2/3] MDL-59140 core: limit the number of courses shown in the navigation If the user is enrolled in more courses than the limit then a 'More...' link is displayed which takes the user to the course/index.php page. --- lib/navigationlib.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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; + } } } From c8f2e0e96b4f98cc6b602fa55941d2365ad702e9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 12 Jun 2017 11:50:14 +0800 Subject: [PATCH 3/3] MDL-59140 core: upgrade 'navcourselimit' if set to old default value --- lib/db/upgrade.php | 10 ++++++++++ version.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 91b611e06839c..bba7ae9eb5a95 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 < 2017061300.01) { + // 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, 2017061300.01); + } + return true; } diff --git a/version.php b/version.php index d9cc08bb9eb6d..13589f8bc02ce 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 = 2017061300.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.