MDL-66016 block_myoverview: Make course filter options configurable

This commit is contained in:
Alexander Bias
2019-08-23 20:44:19 +02:00
parent cd4abbc740
commit 2276614cd8
9 changed files with 459 additions and 9 deletions
+125 -2
View File
@@ -81,6 +81,55 @@ class main implements renderable, templatable {
*/
private $layouts;
/**
* Store a course grouping option setting
*
* @var boolean
*/
private $displaygroupingallincludinghidden;
/**
* Store a course grouping option setting.
*
* @var boolean
*/
private $displaygroupingall;
/**
* Store a course grouping option setting.
*
* @var boolean
*/
private $displaygroupinginprogress;
/**
* Store a course grouping option setting.
*
* @var boolean
*/
private $displaygroupingfuture;
/**
* Store a course grouping option setting.
*
* @var boolean
*/
private $displaygroupingpast;
/**
* Store a course grouping option setting.
*
* @var boolean
*/
private $displaygroupingstarred;
/**
* Store a course grouping option setting.
*
* @var boolean
*/
private $displaygroupinghidden;
/**
* main constructor.
* Initialize the user preferences
@@ -92,23 +141,89 @@ class main implements renderable, templatable {
* @throws \dml_exception
*/
public function __construct($grouping, $sort, $view, $paging) {
$this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL;
// Get plugin config.
$config = get_config('block_myoverview');
// Build the course grouping option name to check if the given grouping is enabled afterwards.
$groupingconfigname = 'displaygrouping'.$grouping;
// Check the given grouping and remember it if it is enabled.
if ($grouping && $config->$groupingconfigname == true) {
$this->grouping = $grouping;
// Otherwise fall back to another grouping in a reasonable order.
// This is done to prevent one-time UI glitches in the case when a user has chosen a grouping option previously which
// was then disabled by the admin in the meantime.
} else if ($config->displaygroupingall == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_ALL;
} else if ($config->displaygroupingallincludinghidden == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_ALLINCLUDINGHIDDEN;
} else if ($config->displaygroupinginprogress == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_INPROGRESS;
} else if ($config->displaygroupingfuture == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_FUTURE;
} else if ($config->displaygroupingpast == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_PAST;
} else if ($config->displaygroupingstarred == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_FAVOURITES;
} else if ($config->displaygroupinghidden == true) {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_HIDDEN;
// In this case, no grouping option is enabled and the grouping is not needed at all.
// But it's better not to leave $this->grouping unset for any unexpected case.
} else {
$this->grouping = BLOCK_MYOVERVIEW_GROUPING_ALLINCLUDINGHIDDEN;
}
unset ($groupingconfigname);
// Check and remember the given sorting.
$this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE;
// Check and remember the given view.
$this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD;
// Check and remember the given page size.
if ($paging == BLOCK_MYOVERVIEW_PAGING_ALL) {
$this->paging = BLOCK_MYOVERVIEW_PAGING_ALL;
} else {
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
}
$config = get_config('block_myoverview');
// Check and remember if the course categories should be shown or not.
if (!$config->displaycategories) {
$this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF;
} else {
$this->displaycategories = BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON;
}
// Get and remember the available layouts.
$this->set_available_layouts();
$this->view = $view ? $view : reset($this->layouts);
// Check and remember if the particular grouping options should be shown or not.
$this->displaygroupingallincludinghidden = $config->displaygroupingallincludinghidden;
$this->displaygroupingall = $config->displaygroupingall;
$this->displaygroupinginprogress = $config->displaygroupinginprogress;
$this->displaygroupingfuture = $config->displaygroupingfuture;
$this->displaygroupingpast = $config->displaygroupingpast;
$this->displaygroupingstarred = $config->displaygroupingstarred;
$this->displaygroupinghidden = $config->displaygroupinghidden;
// Check and remember if the grouping selector should be shown at all or not.
// It will be shown if more than 1 grouping option is enabled.
$displaygroupingselectors = array($this->displaygroupingallincludinghidden,
$this->displaygroupingall,
$this->displaygroupinginprogress,
$this->displaygroupingfuture,
$this->displaygroupingpast,
$this->displaygroupingstarred,
$this->displaygroupinghidden);
$displaygroupingselectorscount = count(array_filter($displaygroupingselectors));
if ($displaygroupingselectorscount > 1) {
$this->displaygroupingselector = true;
} else {
$this->displaygroupingselector = false;
}
unset ($displaygroupingselectors, $displaygroupingselectorscount);
}
@@ -204,6 +319,14 @@ class main implements renderable, templatable {
'layouts' => $availablelayouts,
'displaycategories' => $this->displaycategories,
'displaydropdown' => (count($availablelayouts) > 1) ? true : false,
'displaygroupingallincludinghidden' => $this->displaygroupingallincludinghidden,
'displaygroupingall' => $this->displaygroupingall,
'displaygroupinginprogress' => $this->displaygroupinginprogress,
'displaygroupingfuture' => $this->displaygroupingfuture,
'displaygroupingpast' => $this->displaygroupingpast,
'displaygroupingstarred' => $this->displaygroupingstarred,
'displaygroupinghidden' => $this->displaygroupinghidden,
'displaygroupingselector' => $this->displaygroupingselector,
];
return array_merge($defaultvariables, $preferences);
@@ -45,6 +45,8 @@ $string['aria:past'] = 'Show past courses';
$string['aria:removefromfavourites'] = 'Remove star for';
$string['aria:summary'] = 'Switch to summary view';
$string['aria:sortingdropdown'] = 'Sorting drop-down menu';
$string['availablegroupings'] = 'Available filters';
$string['availablegroupings_desc'] = 'Course filters which are available for selection by users. If none are selected, all courses will be displayed.';
$string['card'] = 'Card';
$string['cards'] = 'Cards';
$string['courseprogress'] = 'Course progress:';
+46
View File
@@ -45,4 +45,50 @@ if ($ADMIN->fulltree) {
$choices,
$choices));
// Enable / Disable course filter items.
$settings->add(new admin_setting_heading('block_myoverview/availablegroupings',
get_string('availablegroupings', 'block_myoverview'),
get_string('availablegroupings_desc', 'block_myoverview')));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupingallincludinghidden',
get_string('allincludinghidden', 'block_myoverview'),
'',
0));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupingall',
get_string('all', 'block_myoverview'),
'',
1));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupinginprogress',
get_string('inprogress', 'block_myoverview'),
'',
1));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupingpast',
get_string('past', 'block_myoverview'),
'',
1));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupingfuture',
get_string('future', 'block_myoverview'),
'',
1));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupingstarred',
get_string('favourites', 'block_myoverview'),
'',
1));
$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupinghidden',
get_string('hiddencourses', 'block_myoverview'),
'',
1));
}
+5
View File
@@ -0,0 +1,5 @@
/* Hide the first dropdown-divider if no filter option element is listed before it.
This can happen for some subset configurations of the block_myoverview course filter. */
.block_myoverview button#groupingdropdown + .dropdown-menu li:first-of-type.dropdown-divider:first-of-type {
display: none;
}
@@ -27,10 +27,18 @@
"future": false,
"past": false,
"favourites": false,
"hidden": false
"hidden": false,
"displaygroupingallincludinghidden": false,
"displaygroupingall": true,
"displaygroupinginprogress": true,
"displaygroupingfuture": true,
"displaygroupingpast": true,
"displaygroupingstarred": true,
"displaygroupinghidden": true,
"displaygroupingselector": true
}
}}
{{#displaygroupingselector}}
<div class="dropdown mb-1 mr-auto">
<button id="groupingdropdown" type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="{{#str}} aria:groupingdropdown, block_myoverview {{/str}}">
{{#pix}} i/filter {{/pix}}
@@ -45,11 +53,14 @@
</span>
</button>
<ul class="dropdown-menu" data-show-active-item data-active-item-text aria-labelledby="groupingdropdown">
{{#displaygroupingallincludinghidden}}
<li>
<a class="dropdown-item {{#allincludinghidden}}active{{/allincludinghidden}}" href="#" data-filter="grouping" data-value="allincludinghidden" data-pref="allincludinghidden" aria-label="{{#str}} aria:allcoursesincludinghidden, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
{{#str}} allincludinghidden, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupingallincludinghidden}}
{{#displaygroupingall}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
@@ -58,6 +69,8 @@
{{#str}} all, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupingall}}
{{#displaygroupinginprogress}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
@@ -66,16 +79,34 @@
{{#str}} inprogress, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupinginprogress}}
{{#displaygroupingfuture}}
{{^displaygroupinginprogress}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
{{/displaygroupinginprogress}}
<li>
<a class="dropdown-item {{#future}}active{{/future}}" href="#" data-filter="grouping" data-value="future" data-pref="future" aria-label="{{#str}} aria:future, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
{{#str}} future, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupingfuture}}
{{#displaygroupingpast}}
{{^displaygroupinginprogress}}
{{^displaygroupingfuture}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
{{/displaygroupingfuture}}
{{/displaygroupinginprogress}}
<li>
<a class="dropdown-item {{#past}}active{{/past}}" href="#" data-filter="grouping" data-value="past" data-pref="past" aria-label="{{#str}} aria:past, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
{{#str}} past, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupingpast}}
{{#displaygroupingstarred}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
@@ -83,7 +114,8 @@
<a class="dropdown-item {{#favourites}}active{{/favourites}}" href="#" data-filter="grouping" data-value="favourites" data-pref="favourites" aria-label="{{#str}} aria:favourites, block_myoverview {{/str}}" aria-controls="courses-view-{{uniqid}}">
{{#str}} favourites, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupingstarred}}
{{#displaygroupinghidden}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
@@ -92,5 +124,12 @@
{{#str}} hiddencourses, block_myoverview {{/str}}
</a>
</li>
{{/displaygroupinghidden}}
</ul>
</div>
{{/displaygroupingselector}}
{{^displaygroupingselector}}
<div class="mb-1 mr-auto">
<span class="filler">&nbsp;</span>
</div>
{{/displaygroupingselector}}
@@ -0,0 +1,226 @@
@block @block_myoverview @javascript
Feature: The my overview block allows admins to easily configure the students' course list
In order to adapt the my overview block to my users' needs
As an admin
I can configure the appearance of the my overview block
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 | C2 | 0 | ##yesterday## | ##tomorrow## |
| Course 3 | C3 | 0 | ##yesterday## | ##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 | C2 | student |
| student1 | C3 | student |
| student1 | C4 | student |
| student1 | C5 | student |
Scenario: Enable 'All' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "All" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
# We have to check for the data attribute instead of the list element text as we would get false positives from the "All (except hidden)" element otherwise
Then "[data-value='allincludinghidden']" "css_element" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'All' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "All" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
# We have to check for the data attribute instead of the list element text as we would get false negatives "All (except hidden)" element otherwise
Then "[data-value='allincludinghidden']" "css_element" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Enable 'All (except hidden)' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "All (except hidden)" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "All (except hidden)" "list_item" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'All (except hidden)' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "All (except hidden)" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
# 'All (except hidden)' option has been disabled, so the button is falling back to the 'In progress' option which is the next enabled option.
And I click on "In progress" "button" in the "Course overview" "block"
Then "All (except hidden)" "list_item" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Enable 'In progress' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "In progress" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "In progress" "list_item" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'In progress' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "In progress" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "In progress" "list_item" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Enable 'Future' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Future" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Future" "list_item" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'Future' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Future" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Future" "list_item" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Enable 'Past' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Past" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Past" "list_item" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'Past' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Past" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Past" "list_item" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Enable 'Starred' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Starred" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Starred" "list_item" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'Starred' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Starred" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Starred" "list_item" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Enable 'Hidden' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Hidden" to "1"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Hidden" "list_item" should exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable 'Hidden' course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "Hidden" to "0"
And I press "Save"
And I log out
Then I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
Then "Hidden" "list_item" should not exist in the ".block_myoverview .dropdown-menu" "css_element"
And I log out
Scenario: Disable all course filter options
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "All" to "0"
And I set the field "All (except hidden)" to "0"
And I set the field "In progress" to "0"
And I set the field "Future" to "0"
And I set the field "Past" to "0"
And I set the field "Starred" to "0"
And I set the field "Hidden" to "0"
And I press "Save"
And I log out
And I log in as "student1"
Then "button#groupingdropdown" "css_element" should not exist in the ".block_myoverview" "css_element"
And I should see "Course 1" in the "Course overview" "block"
And I should see "Course 2" in the "Course overview" "block"
And I should see "Course 3" in the "Course overview" "block"
And I should see "Course 4" in the "Course overview" "block"
And I should see "Course 5" in the "Course overview" "block"
And I log out
Scenario: Disable all but one course filter option
Given I log in as "admin"
And I navigate to "Plugins > Blocks > Course overview" in site administration
And I set the field "All" to "0"
And I set the field "All (except hidden)" to "0"
And I set the field "In progress" to "1"
And I set the field "Future" to "0"
And I set the field "Past" to "0"
And I set the field "Starred" to "0"
And I set the field "Hidden" to "0"
And I press "Save"
And I log out
And I log in as "student1"
Then "button#groupingdropdown" "css_element" should not exist in the ".block_myoverview" "css_element"
And I should see "Course 2" in the "Course overview" "block"
And I should see "Course 3" in the "Course overview" "block"
And I should see "Course 4" in the "Course overview" "block"
And I should not see "Course 1" in the "Course overview" "block"
And I should not see "Course 5" in the "Course overview" "block"
And I log out
@@ -71,7 +71,10 @@ Feature: The my overview block allows users to easily access their courses
And I log out
Scenario: View all (including hidden) courses
Given I log in as "student1"
Given the following config values are set as admin:
| config | value | plugin |
| displaygroupingallincludinghidden | 1 | block_myoverview |
And I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
# We have to click on the data attribute instead of the button element text as we might risk to click on the false positive "All (except hidden)" element instead
When I click on "[data-value='allincludinghidden']" "css_element" in the "Course overview" "block"
@@ -231,7 +234,10 @@ Feature: The my overview block allows users to easily access their courses
And I log out
Scenario: View all (including hidden) courses with hide persistent functionality
Given I log in as "student1"
Given the following config values are set as admin:
| config | value | plugin |
| displaygroupingallincludinghidden | 1 | block_myoverview |
And I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
# We have to click on the data attribute instead of the button element text as we might risk to click on the false positive "All (except hidden)" element instead
When I click on "[data-value='allincludinghidden']" "css_element" in the "Course overview" "block"
@@ -100,7 +100,10 @@ Feature: The my overview block allows users to hide their courses
And I log out
Scenario: Test a course is never hidden with "All (including hidden)" courses
Given I log in as "student1"
Given the following config values are set as admin:
| config | value | plugin |
| displaygroupingallincludinghidden | 1 | block_myoverview |
And I log in as "student1"
And I click on "All (except hidden)" "button" in the "Course overview" "block"
# We have to click on the data attribute instead of the button element text as we might risk to click on the false positive "All (except hidden)" element instead
When I click on "[data-value='allincludinghidden']" "css_element" in the "Course overview" "block"
+1 -1
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2019070400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019070401; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2019051100; // Requires this Moodle version.
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).