MDL-66888 block_myoverview: Add course sorting options to overview block
This commit is contained in:
@@ -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 = [
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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'],
|
||||
);
|
||||
|
||||
@@ -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}}
|
||||
</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu" data-show-active-item data-skip-active-class="true" aria-labelledby="sortingdropdown">
|
||||
@@ -53,6 +54,11 @@
|
||||
{{#str}} sortbylastaccessed, block_myoverview {{/str}}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="#" data-filter="sort" data-pref="startdate" data-value="startdate" aria-controls="courses-view-{{uniqid}}" role="menuitem" {{#startdate}}aria-current="true"{{/startdate}}>
|
||||
{{#str}} sortbystartdate, block_myoverview {{/str}}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 "<dropdownstring>" "link" in the "Course overview" "block"
|
||||
Then "<coursebefore>" "text" should appear before "<courseafter>" "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 |
|
||||
Reference in New Issue
Block a user