diff --git a/public/blocks/myoverview/classes/output/main.php b/public/blocks/myoverview/classes/output/main.php index c78abb16f64..1b22765817b 100644 --- a/public/blocks/myoverview/classes/output/main.php +++ b/public/blocks/myoverview/classes/output/main.php @@ -453,10 +453,20 @@ class main implements renderable, templatable { $preferences = $this->get_preferences_as_booleans(); $availablelayouts = $this->get_formatted_available_layouts_for_export(); $sort = ''; - if ($this->sort == BLOCK_MYOVERVIEW_SORTING_SHORTNAME) { - $sort = 'shortname'; - } else { - $sort = $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc'; + + switch ($this->sort) { + case BLOCK_MYOVERVIEW_SORTING_SHORTNAME: + $sort = 'shortname'; + break; + case BLOCK_MYOVERVIEW_SORTING_LASTACCESSED: + $sort = 'ul.timeaccess desc'; + break; + case BLOCK_MYOVERVIEW_SORTING_STARTDATE: + $sort = 'startdate'; + break; + case BLOCK_MYOVERVIEW_SORTING_TITLE: + default: + $sort = 'fullname'; } $defaultvariables = [ diff --git a/public/blocks/myoverview/lang/en/block_myoverview.php b/public/blocks/myoverview/lang/en/block_myoverview.php index 0efbdd33277..ab98fdf4256 100644 --- a/public/blocks/myoverview/lang/en/block_myoverview.php +++ b/public/blocks/myoverview/lang/en/block_myoverview.php @@ -86,6 +86,7 @@ $string['show'] = 'Restore to view'; $string['sortbytitle'] = 'Sort by course name'; $string['sortbylastaccessed'] = 'Sort by last accessed'; $string['sortbyshortname'] = 'Sort by short name'; +$string['sortbystartdate'] = 'Sort by start date'; $string['privacy:request:preference:set'] = 'The value of the setting \'{$a->name}\' was \'{$a->value}\''; $string['viewquickstart'] = 'View Quickstart guide'; $string['zero_default_title'] = 'You\'re not enrolled in any courses.'; diff --git a/public/blocks/myoverview/lib.php b/public/blocks/myoverview/lib.php index 4dd7a1aa446..0ea04d61b7c 100644 --- a/public/blocks/myoverview/lib.php +++ b/public/blocks/myoverview/lib.php @@ -48,6 +48,7 @@ define('BLOCK_MYOVERVIEW_CUSTOMFIELD_EMPTY', -1); define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title'); define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed'); define('BLOCK_MYOVERVIEW_SORTING_SHORTNAME', 'shortname'); +define('BLOCK_MYOVERVIEW_SORTING_STARTDATE', 'startdate'); /** * Constants for the user preferences view options @@ -110,7 +111,8 @@ function block_myoverview_user_preferences(): array { 'choices' => array( BLOCK_MYOVERVIEW_SORTING_TITLE, BLOCK_MYOVERVIEW_SORTING_LASTACCESSED, - BLOCK_MYOVERVIEW_SORTING_SHORTNAME + BLOCK_MYOVERVIEW_SORTING_SHORTNAME, + BLOCK_MYOVERVIEW_SORTING_STARTDATE, ), 'permissioncallback' => [core_user::class, 'is_current_user'], ); diff --git a/public/blocks/myoverview/templates/nav-sort-selector.mustache b/public/blocks/myoverview/templates/nav-sort-selector.mustache index 70b947f2d07..d399b31b0e4 100644 --- a/public/blocks/myoverview/templates/nav-sort-selector.mustache +++ b/public/blocks/myoverview/templates/nav-sort-selector.mustache @@ -33,6 +33,7 @@ {{#title}}{{#str}} sortbytitle, block_myoverview {{/str}}{{/title}} {{#lastaccessed}}{{#str}} sortbylastaccessed, block_myoverview {{/str}}{{/lastaccessed}} {{#shortname}}{{#str}} sortbyshortname, block_myoverview {{/str}}{{/shortname}} + {{#startdate}}{{#str}} sortbystartdate, block_myoverview {{/str}}{{/startdate}} diff --git a/public/blocks/myoverview/tests/behat/block_myoverview_dashboard.feature b/public/blocks/myoverview/tests/behat/block_myoverview_dashboard.feature index bdc1efafdb3..3c9657dafdf 100644 --- a/public/blocks/myoverview/tests/behat/block_myoverview_dashboard.feature +++ b/public/blocks/myoverview/tests/behat/block_myoverview_dashboard.feature @@ -196,6 +196,14 @@ Feature: The my overview block allows users to easily access their courses Then I should see "Sort by short name" in the "Course overview" "block" And "[data-sort='shortname']" "css_element" in the "Course overview" "block" should be visible + Scenario: Course start date sort persistence + Given I am on the "My courses" page logged in as "student1" + And I click on "sortingdropdown" "button" in the "Course overview" "block" + And I click on "Sort by start date" "link" in the "Course overview" "block" + And I reload the page + Then I should see "Sort by start date" in the "Course overview" "block" + And "[data-sort='startdate']" "css_element" in the "Course overview" "block" should be visible + Scenario: View inprogress courses with hide persistent functionality Given I am on the "My courses" page logged in as "student1" And I click on "All" "button" in the "Course overview" "block" diff --git a/public/blocks/myoverview/tests/behat/block_myoverview_sorting.feature b/public/blocks/myoverview/tests/behat/block_myoverview_sorting.feature new file mode 100644 index 00000000000..cd04d6c7ce8 --- /dev/null +++ b/public/blocks/myoverview/tests/behat/block_myoverview_sorting.feature @@ -0,0 +1,43 @@ +@block @block_myoverview @javascript +Feature: The my overview block allows users to easily sort their courses + In order to sort course in the my overview block + As a user + I can choose from a selection of sorting options + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | idnumber | + | student1 | Student | X | student1@example.com | S1 | + And the following "categories" exist: + | name | category | idnumber | + | Category 1 | 0 | CAT1 | + And the following "courses" exist: + | fullname | shortname | category | startdate | enddate | + | Course 1 | C1 | 0 | ##1 month ago## | ##15 days ago## | + | Course 2 | C0 | 0 | ##yesterday## | ##tomorrow## | + | Course 3 | C3 | 0 | ##2 month ago## | ##tomorrow## | + | Course 4 | C4 | CAT1 | ##yesterday## | ##tomorrow## | + | Course 5 | C5 | 0 | ##first day of next month## | ##last day of next month## | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + | student1 | C0 | student | + | student1 | C3 | student | + | student1 | C4 | student | + | student1 | C5 | student | + And the following config values are set as admin: + | courselistshortnames | 1 | + + Scenario Outline: Check the function of available course sorting options + Given I am on the "Course 5" course page logged in as "student1" + When I am on the "My courses" page + And I click on "sortingdropdown" "button" in the "Course overview" "block" + And I click on "" "link" in the "Course overview" "block" + Then "" "text" should appear before "" "text" in the "Course overview" "block" + + Examples: + | dropdownstring | coursebefore | courseafter | + | Sort by course name | Course 1 | Course 2 | + | Sort by short name | Course 2 | Course 1 | + | Sort by last accessed | Course 5 | Course 1 | + | Sort by start date | Course 3 | Course 1 |