Skip to content

Commit

Permalink
MDL-67690 block_myoverview: Update starred to favourites to fix prefs
Browse files Browse the repository at this point in the history
Core libs use favourites, so need to use that consistently for user
preferences to be remembered properly.
  • Loading branch information
ericmerrill committed Jan 23, 2020
1 parent fd12600 commit 2d2189a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 14 deletions.
10 changes: 5 additions & 5 deletions blocks/myoverview/classes/output/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class main implements renderable, templatable {
*
* @var boolean
*/
private $displaygroupingstarred;
private $displaygroupingfavourites;

/**
* Store a course grouping option setting.
Expand Down Expand Up @@ -214,7 +214,7 @@ public function __construct($grouping, $sort, $view, $paging, $customfieldvalue
$this->displaygroupinginprogress = $config->displaygroupinginprogress;
$this->displaygroupingfuture = $config->displaygroupingfuture;
$this->displaygroupingpast = $config->displaygroupingpast;
$this->displaygroupingstarred = $config->displaygroupingstarred;
$this->displaygroupingfavourites = $config->displaygroupingfavourites;
$this->displaygroupinghidden = $config->displaygroupinghidden;
$this->displaygroupingcustomfield = ($config->displaygroupingcustomfield && $config->customfiltergrouping);
$this->customfiltergrouping = $config->customfiltergrouping;
Expand All @@ -226,7 +226,7 @@ public function __construct($grouping, $sort, $view, $paging, $customfieldvalue
$this->displaygroupinginprogress,
$this->displaygroupingfuture,
$this->displaygroupingpast,
$this->displaygroupingstarred,
$this->displaygroupingfavourites,
$this->displaygroupinghidden);
$displaygroupingselectorscount = count(array_filter($displaygroupingselectors));
if ($displaygroupingselectorscount > 1 || $this->displaygroupingcustomfield) {
Expand Down Expand Up @@ -259,7 +259,7 @@ private function get_fallback_grouping($config) {
if ($config->displaygroupingpast == true) {
return BLOCK_MYOVERVIEW_GROUPING_PAST;
}
if ($config->displaygroupingstarred == true) {
if ($config->displaygroupingfavourites == true) {
return BLOCK_MYOVERVIEW_GROUPING_FAVOURITES;
}
if ($config->displaygroupinghidden == true) {
Expand Down Expand Up @@ -439,7 +439,7 @@ public function export_for_template(renderer_base $output) {
'displaygroupinginprogress' => $this->displaygroupinginprogress,
'displaygroupingfuture' => $this->displaygroupingfuture,
'displaygroupingpast' => $this->displaygroupingpast,
'displaygroupingstarred' => $this->displaygroupingstarred,
'displaygroupingfavourites' => $this->displaygroupingfavourites,
'displaygroupinghidden' => $this->displaygroupinghidden,
'displaygroupingselector' => $this->displaygroupingselector,
'displaygroupingcustomfield' => $this->displaygroupingcustomfield && $customfieldvalues,
Expand Down
22 changes: 21 additions & 1 deletion blocks/myoverview/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @param int $oldversion
*/
function xmldb_block_myoverview_upgrade($oldversion) {
global $DB;
global $DB, $CFG, $OUTPUT;

if ($oldversion < 2019091800) {
// Remove orphaned course favourites, which weren't being deleted when the course was deleted.
Expand All @@ -58,5 +58,25 @@ function xmldb_block_myoverview_upgrade($oldversion) {
// Automatically generated Moodle v3.8.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2019111801) {
// Renaming the setting from displaygroupingstarred to displaygroupingfavourites to match Moodle convention.

// Check to see if record exists. get_config doesn't allow differentiation between not exists and false.
$dbval = $DB->get_field('config_plugins', 'value', ['plugin' => 'block_myoverview', 'name' => 'displaygroupingstarred']);
if ($dbval !== false) {
set_config('displaygroupingfavourites', $dbval, 'block_myoverview');
unset_config('displaygroupingstarred', 'block_myoverview');
}

if (isset($CFG->forced_plugin_settings['block_myoverview']['displaygroupingstarred'])) {
// Check to see if the starred setting is defined in the config file. Display a warning if so.
$warn = 'Setting block_myoverview->displaygroupingstarred has been renamed '.
'to block_myoverview->displaygroupingfavourites. Old setting present in config.php.';
echo $OUTPUT->notification($warn, 'notifyproblem');
}

upgrade_block_savepoint(true, 2019111801, 'myoverview', false);
}

return true;
}
2 changes: 1 addition & 1 deletion blocks/myoverview/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function block_myoverview_user_preferences() {
* @param stdClass $course The deleted course
*/
function block_myoverview_pre_course_delete(\stdClass $course) {
// Removing any starred courses which have been created for users, for this course.
// Removing any favourited courses which have been created for users, for this course.
$service = \core_favourites\service_factory::get_service_for_component('core_course');
$service->delete_favourites_by_type_and_item('courses', $course->id);
}
2 changes: 1 addition & 1 deletion blocks/myoverview/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
$settings->hide_if('block_myoverview/customfiltergrouping', 'block_myoverview/displaygroupingcustomfield');

$settings->add(new admin_setting_configcheckbox(
'block_myoverview/displaygroupingstarred',
'block_myoverview/displaygroupingfavourites',
get_string('favourites', 'block_myoverview'),
'',
1));
Expand Down
6 changes: 3 additions & 3 deletions blocks/myoverview/templates/nav-grouping-selector.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"displaygroupinginprogress": true,
"displaygroupingfuture": true,
"displaygroupingpast": true,
"displaygroupingstarred": true,
"displaygroupingfavourites": true,
"displaygroupinghidden": true,
"displaygroupingselector": true
}
Expand Down Expand Up @@ -122,15 +122,15 @@
</li>
{{/customfieldvalues}}
{{/displaygroupingcustomfield}}
{{#displaygroupingstarred}}
{{#displaygroupingfavourites}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
</li>
<li>
<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>
{{/displaygroupingstarred}}
{{/displaygroupingfavourites}}
{{#displaygroupinghidden}}
<li class="dropdown-divider" role="presentation">
<span class="filler">&nbsp;</span>
Expand Down
14 changes: 14 additions & 0 deletions blocks/myoverview/tests/behat/block_myoverview_dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ Feature: The my overview block allows users to easily access their courses
And I should not see "Course 3" in the "Course overview" "block"
And I should not see "Course 4" in the "Course overview" "block"

Scenario: View favourite courses - w/ persistence
Given I log in as "student1"
And I click on ".coursemenubtn" "css_element" in the "//div[@class='card dashboard-card' and contains(.,'Course 2')]" "xpath_element"
And I click on "Star this course" "link" in the "//div[@class='card dashboard-card' and contains(.,'Course 2')]" "xpath_element"
And I click on "All (except removed from view)" "button" in the "Course overview" "block"
When I click on "Starred" "link" in the "Course overview" "block"
And I reload the page
Then I should see "Starred" in the "Course overview" "block"
And I should see "Course 2" in the "Course overview" "block"
And I should not see "Course 1" in the "Course overview" "block"
And I should not see "Course 3" in the "Course overview" "block"
And I should not see "Course 4" in the "Course overview" "block"
And I should not see "Course 5" in the "Course overview" "block"

Scenario: List display persistence
Given I log in as "student1"
And I click on "Display drop-down menu" "button" in the "Course overview" "block"
Expand Down
2 changes: 1 addition & 1 deletion blocks/myoverview/tests/myoverview_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function test_get_block_config_for_external() {
$this->assertEquals(1, $configs->plugin->displaygroupinghidden);
$this->assertEquals(1, $configs->plugin->displaygroupinginprogress);
$this->assertEquals(1, $configs->plugin->displaygroupingpast);
$this->assertEquals(1, $configs->plugin->displaygroupingstarred);
$this->assertEquals(1, $configs->plugin->displaygroupingfavourites);
$this->assertEquals('card,list,summary', $configs->plugin->layouts);
$this->assertEquals(get_config('block_myoverview', 'version'), $configs->plugin->version);
// Test custom fields.
Expand Down
6 changes: 5 additions & 1 deletion blocks/myoverview/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ This file describes API changes in the myoverview block code.

=== 3.7 ===

* The 'block/myoverview:addinstance' capability has been removed. It has never been used in code.
* The 'block/myoverview:addinstance' capability has been removed. It has never been used in code.

=== 3.9 ===

* Rename setting block_myoverview->displaygroupingstarred to block_myoverview->displaygroupingfavourites.
2 changes: 1 addition & 1 deletion blocks/myoverview/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2019111800; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019111801; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2019111200; // Requires this Moodle version.
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).

0 comments on commit 2d2189a

Please sign in to comment.