From 4d378e9f70750ae8958b90cc6159b492b0b86644 Mon Sep 17 00:00:00 2001 From: Syxton Date: Thu, 5 Jun 2014 10:25:40 -0400 Subject: [PATCH 1/3] MDL-45884 navigation: setting that allows sites to collapse My Courses by default --- admin/settings/appearance.php | 1 + lang/en/admin.php | 2 ++ lib/navigationlib.php | 9 +++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 1df0a092cbe..8acf69196b9 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -122,6 +122,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp $temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0)); + $temp->add(new admin_setting_configcheckbox('navcollapsemycourses', new lang_string('navcollapsemycourses', 'admin'), new lang_string('confignavcollapsemycourses', 'admin'), 0)); $sortoptions = array( 'sortorder' => new lang_string('sort_sortorder', 'admin'), 'fullname' => new lang_string('sort_fullname', 'admin'), diff --git a/lang/en/admin.php b/lang/en/admin.php index 62734b5311c..75fc0c1cbb3 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -271,6 +271,7 @@ $string['confignavcourselimit'] = 'Limits the number of courses shown to the use $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['confignotifyloginfailures'] = 'Send login failure notification messages to these selected users. This requires an internal logstore (eg Standard Logstore) to be enabled.'; +$string['confignavcollapsemycourses'] = 'Show the My Courses area as collapsed.'; $string['confignotifyloginthreshold'] = 'If notifications about failed logins are active, how many failed login attempts by one user or one IP address is it worth notifying about?'; $string['confignotloggedinroleid'] = 'Users who are not logged in to the site will be treated as if they have this role granted to them at the site context. Guest is almost always what you want here, but you might want to create roles that are less or more restrictive. Things like creating posts still require the user to log in properly.'; $string['configopentogoogle'] = 'If you enable this setting, then Google will be allowed to enter your site as a Guest. In addition, people coming in to your site via a Google search will automatically be logged in as a Guest. Note that this only provides transparent access to courses that already allow guest access.'; @@ -739,6 +740,7 @@ $string['navshowfrontpagemods_help'] = 'If enabled, front page activities will b $string['navshowallcourses'] = 'Show all courses'; $string['navshowcategories'] = 'Show course categories'; $string['navshowmycoursecategories'] = 'Show my course categories'; +$string['navcollapsemycourses'] = 'Show My Courses as collapsed'; $string['navshowmycoursecategories_help'] = 'If enabled courses in the users my courses branch will be shown in categories.'; $string['navsortmycoursessort'] = 'Sort my courses'; $string['navsortmycoursessort_help'] = 'This determines whether courses are listed under My courses according to the sort order (i.e. the order set in Site administration > Courses > Manage courses and categories) or alphabetically by course setting.'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 10fde52e255..bdc2537326e 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1133,8 +1133,13 @@ class global_navigation extends navigation_node { $this->rootnodes['courses']->isexpandable = true; } - if ($this->rootnodes['mycourses']->isactive) { - $this->load_courses_enrolled(); + if (empty($CFG->navcollapsemycourses)){ + if ($this->rootnodes['mycourses']->isactive) { + $this->load_courses_enrolled(); + } + } else { + $this->rootnodes['mycourses']->collapse = true; + $this->rootnodes['mycourses']->make_inactive(); } $canviewcourseprofile = true; From aab6438ca1681f4e7cfe757d4bcd026a3a9e6e12 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Fri, 6 Jun 2014 10:06:04 +1200 Subject: [PATCH 2/3] MDL-45884 navigation: tidied up code and added behat tests --- admin/settings/appearance.php | 2 +- .../behat/collapse_my_courses_setting.feature | 55 +++++++++++++++++++ lang/en/admin.php | 4 +- lib/navigationlib.php | 16 +++--- 4 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 blocks/navigation/tests/behat/collapse_my_courses_setting.feature diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 8acf69196b9..762d1728a2c 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -122,7 +122,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp $temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0)); - $temp->add(new admin_setting_configcheckbox('navcollapsemycourses', new lang_string('navcollapsemycourses', 'admin'), new lang_string('confignavcollapsemycourses', 'admin'), 0)); + $temp->add(new admin_setting_configcheckbox('navcollapsemycourses', new lang_string('navcollapsemycourses', 'admin'), new lang_string('navcollapsemycourses_desc', 'admin'), 0)); $sortoptions = array( 'sortorder' => new lang_string('sort_sortorder', 'admin'), 'fullname' => new lang_string('sort_fullname', 'admin'), diff --git a/blocks/navigation/tests/behat/collapse_my_courses_setting.feature b/blocks/navigation/tests/behat/collapse_my_courses_setting.feature new file mode 100644 index 00000000000..bb79564944b --- /dev/null +++ b/blocks/navigation/tests/behat/collapse_my_courses_setting.feature @@ -0,0 +1,55 @@ +@block @block_navigation +Feature: Test collapse my courses navigation setting + As a student + I visit my My Moodle page and observe the the My Courses branch + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@asd.com | + And the following "categories" exist: + | name | category | idnumber | + | cat1 | 0 | cat1 | + And the following "courses" exist: + | fullname | shortname | category | + | Course1 | c1 | cat1 | + | Course2 | c2 | cat1 | + | Course3 | c3 | cat1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | c1 | student | + | student1 | c2 | student | + + Scenario: The My Courses branch is expanded on the My Moodle page by default + When I log in as "student1" + And I follow "My home" + Then I should see "c1" in the "Navigation" "block" + And I should see "c2" in the "Navigation" "block" + And I should not see "c3" in the "Navigation" "block" + + Scenario: The My Courses branch is collapsed when collapse my courses is on + Given I log in as "admin" + And I set the following administration settings values: + | Keep My Courses collapsed initially | 1 | + And I log out + Given I log in as "student1" + And I follow "My home" + Then I should not see "c1" in the "Navigation" "block" + And I should not see "c2" in the "Navigation" "block" + And I should not see "c3" in the "Navigation" "block" + + @javascript + Scenario: My Courses can be expanded on the My Moodle page when collapse my courses is on + Given I log in as "admin" + And I set the following administration settings values: + | Keep My Courses collapsed initially | 1 | + And I log out + Given I log in as "student1" + And I follow "My home" + And I should not see "c1" in the "Navigation" "block" + And I should not see "c2" in the "Navigation" "block" + And I should not see "c3" in the "Navigation" "block" + And I expand "My courses" node + Then I should see "c1" in the "Navigation" "block" + And I should see "c2" in the "Navigation" "block" + And I should not see "c3" in the "Navigation" "block" \ No newline at end of file diff --git a/lang/en/admin.php b/lang/en/admin.php index 75fc0c1cbb3..5a2689d0637 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -271,7 +271,6 @@ $string['confignavcourselimit'] = 'Limits the number of courses shown to the use $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['confignotifyloginfailures'] = 'Send login failure notification messages to these selected users. This requires an internal logstore (eg Standard Logstore) to be enabled.'; -$string['confignavcollapsemycourses'] = 'Show the My Courses area as collapsed.'; $string['confignotifyloginthreshold'] = 'If notifications about failed logins are active, how many failed login attempts by one user or one IP address is it worth notifying about?'; $string['confignotloggedinroleid'] = 'Users who are not logged in to the site will be treated as if they have this role granted to them at the site context. Guest is almost always what you want here, but you might want to create roles that are less or more restrictive. Things like creating posts still require the user to log in properly.'; $string['configopentogoogle'] = 'If you enable this setting, then Google will be allowed to enter your site as a Guest. In addition, people coming in to your site via a Google search will automatically be logged in as a Guest. Note that this only provides transparent access to courses that already allow guest access.'; @@ -740,7 +739,8 @@ $string['navshowfrontpagemods_help'] = 'If enabled, front page activities will b $string['navshowallcourses'] = 'Show all courses'; $string['navshowcategories'] = 'Show course categories'; $string['navshowmycoursecategories'] = 'Show my course categories'; -$string['navcollapsemycourses'] = 'Show My Courses as collapsed'; +$string['navcollapsemycourses'] = 'Keep My Courses collapsed initially'; +$string['navcollapsemycourses_desc'] = 'When enabled the My Courses branch will never be expanded initially. The user will need to click to expand it. At present the My Courses branch is only expanded initially when on the My Moodle page.'; $string['navshowmycoursecategories_help'] = 'If enabled courses in the users my courses branch will be shown in categories.'; $string['navsortmycoursessort'] = 'Sort my courses'; $string['navsortmycoursessort_help'] = 'This determines whether courses are listed under My courses according to the sort order (i.e. the order set in Site administration > Courses > Manage courses and categories) or alphabetically by course setting.'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index bdc2537326e..0f9a0ba3ae3 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -979,7 +979,7 @@ class global_navigation extends navigation_node { protected $initialised = false; /** @var array An array of course information */ protected $mycourses = array(); - /** @var array An array for containing root navigation nodes */ + /** @var navigation_node[] An array for containing root navigation nodes */ protected $rootnodes = array(); /** @var bool A switch for whether to show empty sections in the navigation */ protected $showemptysections = true; @@ -1133,13 +1133,13 @@ class global_navigation extends navigation_node { $this->rootnodes['courses']->isexpandable = true; } - if (empty($CFG->navcollapsemycourses)){ - if ($this->rootnodes['mycourses']->isactive) { - $this->load_courses_enrolled(); - } - } else { - $this->rootnodes['mycourses']->collapse = true; - $this->rootnodes['mycourses']->make_inactive(); + // Load the users enrolled courses if they are viewing the My Moodle page AND the admin has not + // set that they wish to keep the My Courses branch collapsed by default. + if (empty($CFG->navcollapsemycourses) && $this->rootnodes['mycourses']->isactive){ + $this->load_courses_enrolled(); + } else { + $this->rootnodes['mycourses']->collapse = true; + $this->rootnodes['mycourses']->make_inactive(); } $canviewcourseprofile = true; From 99f041ebfa3ca3d21d8fd26009abddcee1813d0e Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Thu, 12 Jun 2014 10:35:52 +1200 Subject: [PATCH 3/3] MDL-45884 navigation: changed to positive setting phrasing --- admin/settings/appearance.php | 2 +- ...ting.feature => expand_my_courses_setting.feature} | 11 ++++++----- lang/en/admin.php | 4 ++-- lib/navigationlib.php | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) rename blocks/navigation/tests/behat/{collapse_my_courses_setting.feature => expand_my_courses_setting.feature} (87%) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 762d1728a2c..fd31903a3f3 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -122,7 +122,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp $temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0)); - $temp->add(new admin_setting_configcheckbox('navcollapsemycourses', new lang_string('navcollapsemycourses', 'admin'), new lang_string('navcollapsemycourses_desc', 'admin'), 0)); + $temp->add(new admin_setting_configcheckbox('navexpandmycourses', new lang_string('navexpandmycourses', 'admin'), new lang_string('navexpandmycourses_desc', 'admin'), 1)); $sortoptions = array( 'sortorder' => new lang_string('sort_sortorder', 'admin'), 'fullname' => new lang_string('sort_fullname', 'admin'), diff --git a/blocks/navigation/tests/behat/collapse_my_courses_setting.feature b/blocks/navigation/tests/behat/expand_my_courses_setting.feature similarity index 87% rename from blocks/navigation/tests/behat/collapse_my_courses_setting.feature rename to blocks/navigation/tests/behat/expand_my_courses_setting.feature index bb79564944b..79eeb0eedb2 100644 --- a/blocks/navigation/tests/behat/collapse_my_courses_setting.feature +++ b/blocks/navigation/tests/behat/expand_my_courses_setting.feature @@ -1,5 +1,5 @@ @block @block_navigation -Feature: Test collapse my courses navigation setting +Feature: Test expand my courses navigation setting As a student I visit my My Moodle page and observe the the My Courses branch @@ -27,10 +27,11 @@ Feature: Test collapse my courses navigation setting And I should see "c2" in the "Navigation" "block" And I should not see "c3" in the "Navigation" "block" - Scenario: The My Courses branch is collapsed when collapse my courses is on + @javascript + Scenario: The My Courses branch is collapsed when expand my courses is off Given I log in as "admin" And I set the following administration settings values: - | Keep My Courses collapsed initially | 1 | + | Expand My Courses initially on My Moodle page | 0 | And I log out Given I log in as "student1" And I follow "My home" @@ -39,10 +40,10 @@ Feature: Test collapse my courses navigation setting And I should not see "c3" in the "Navigation" "block" @javascript - Scenario: My Courses can be expanded on the My Moodle page when collapse my courses is on + Scenario: My Courses can be expanded on the My Moodle page when expand my courses is off Given I log in as "admin" And I set the following administration settings values: - | Keep My Courses collapsed initially | 1 | + | Expand My Courses initially on My Moodle page | 0 | And I log out Given I log in as "student1" And I follow "My home" diff --git a/lang/en/admin.php b/lang/en/admin.php index 5a2689d0637..4e9db3dd647 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -732,6 +732,8 @@ $string['navadduserpostslinks'] = 'Add links to view user posts'; $string['navadduserpostslinks_help'] = 'If enabled two links will be added to each user in the navigation to view discussions the user has started and posts the user has made in forums throughout the site or in specific courses.'; $string['navigationupgrade'] = 'This upgrade introduces two new navigation blocks that will replace these blocks: Administration, Courses, Activities and Participants. If you had set any special permissions on those blocks you should check to make sure everything is behaving as you want it.'; $string['navcourselimit'] = 'Course limit'; +$string['navexpandmycourses'] = 'Expand My Courses initially on My Moodle page'; +$string['navexpandmycourses_desc'] = 'When enabled the My Courses branch will be expanded initially on the My Moodle page and any pages within the My Moodle area.'; $string['navshowfullcoursenames'] = 'Show course full names'; $string['navshowfullcoursenames_help'] = 'If enabled courses in the navigation will be shown with using their full name rather than their short name.'; $string['navshowfrontpagemods'] = 'Show front page activities in the navigation'; @@ -739,8 +741,6 @@ $string['navshowfrontpagemods_help'] = 'If enabled, front page activities will b $string['navshowallcourses'] = 'Show all courses'; $string['navshowcategories'] = 'Show course categories'; $string['navshowmycoursecategories'] = 'Show my course categories'; -$string['navcollapsemycourses'] = 'Keep My Courses collapsed initially'; -$string['navcollapsemycourses_desc'] = 'When enabled the My Courses branch will never be expanded initially. The user will need to click to expand it. At present the My Courses branch is only expanded initially when on the My Moodle page.'; $string['navshowmycoursecategories_help'] = 'If enabled courses in the users my courses branch will be shown in categories.'; $string['navsortmycoursessort'] = 'Sort my courses'; $string['navsortmycoursessort_help'] = 'This determines whether courses are listed under My courses according to the sort order (i.e. the order set in Site administration > Courses > Manage courses and categories) or alphabetically by course setting.'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 0f9a0ba3ae3..0ea480b22b8 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1135,7 +1135,7 @@ class global_navigation extends navigation_node { // Load the users enrolled courses if they are viewing the My Moodle page AND the admin has not // set that they wish to keep the My Courses branch collapsed by default. - if (empty($CFG->navcollapsemycourses) && $this->rootnodes['mycourses']->isactive){ + if (!empty($CFG->navexpandmycourses) && $this->rootnodes['mycourses']->isactive){ $this->load_courses_enrolled(); } else { $this->rootnodes['mycourses']->collapse = true;