Skip to content

Commit

Permalink
MDL-63044 block_myoverview: remove tab preference
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie committed Sep 27, 2018
1 parent 2c13ae0 commit bbe6ead
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 235 deletions.
1 change: 0 additions & 1 deletion blocks/myoverview/amd/build/tab_preferences.min.js

This file was deleted.

61 changes: 0 additions & 61 deletions blocks/myoverview/amd/src/tab_preferences.js

This file was deleted.

20 changes: 1 addition & 19 deletions blocks/myoverview/block_myoverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ public function get_content() {
return $this->content;
}

// Check if the tab to select wasn't passed in the URL, if so see if the user has any preference.
if (!$tab = optional_param('myoverviewtab', null, PARAM_ALPHA)) {
// Check if the user has no preference, if so get the site setting.
if (!$tab = get_user_preferences('block_myoverview_last_tab')) {
$config = get_config('block_myoverview');
$tab = $config->defaulttab;
}
}

$renderable = new \block_myoverview\output\main($tab);
$renderable = new \block_myoverview\output\main();
$renderer = $this->page->get_renderer('block_myoverview');

$this->content = new stdClass();
Expand All @@ -77,13 +68,4 @@ public function get_content() {
public function applicable_formats() {
return array('my' => true);
}

/**
* This block does contain a configuration settings.
*
* @return boolean
*/
public function has_config() {
return true;
}
}
26 changes: 0 additions & 26 deletions blocks/myoverview/classes/output/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class main implements renderable, templatable {

/**
* @var string The tab to display.
*/
public $tab;

/**
* Constructor.
*
* @param string $tab The tab to display.
*/
public function __construct($tab) {
$this->tab = $tab;
}

/**
* Export this data so it can be used as the context for a mustache template.
*
Expand Down Expand Up @@ -88,24 +73,13 @@ public function export_for_template(renderer_base $output) {
$nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();
$noeventsurl = $output->image_url('activities', 'block_myoverview')->out();

// Now, set the tab we are going to be viewing.
$viewingtimeline = false;
$viewingcourses = false;
if ($this->tab == BLOCK_MYOVERVIEW_TIMELINE_VIEW) {
$viewingtimeline = true;
} else {
$viewingcourses = true;
}

return [
'midnight' => usergetmidnight(time()),
'coursesview' => $coursesview->export_for_template($output),
'urls' => [
'nocourses' => $nocoursesurl,
'noevents' => $noeventsurl
],
'viewingtimeline' => $viewingtimeline,
'viewingcourses' => $viewingcourses
];
}
}
27 changes: 6 additions & 21 deletions blocks/myoverview/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,15 @@
* @copyright 2018 Zig Tan <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\user_preference_provider {
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Returns meta-data information about the myoverview block.
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @param \core_privacy\local\metadata\collection $collection A collection of meta-data.
* @return \core_privacy\local\metadata\collection Return the collection of meta-data.
* @return string
*/
public static function get_metadata(\core_privacy\local\metadata\collection $collection) :
\core_privacy\local\metadata\collection {
$collection->add_user_preference('block_myoverview_last_tab', 'privacy:metadata:overviewlasttab');
return $collection;
}

/**
* Export all user preferences for the myoverview block
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$preference = get_user_preferences('block_myoverview_last_tab', null, $userid);
if (isset($preference)) {
\core_privacy\local\request\writer::export_user_preference('block_myoverview', 'block_myoverview_last_tab',
$preference, get_string('privacy:metadata:overviewlasttab', 'block_myoverview'));
}
public static function get_reason() : string {
return 'privacy:metadata';
}
}
32 changes: 17 additions & 15 deletions blocks/myoverview/settings.php → blocks/myoverview/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Settings for the overview block.
* This file keeps track of upgrades to the myoverview block
*
* @package block_myoverview
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package block_myoverview
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

require_once($CFG->dirroot . '/blocks/myoverview/lib.php');

if ($ADMIN->fulltree) {
/**
* Upgrade code for the myoverview block.
*
* @param int $oldversion
*/
function xmldb_block_myoverview_upgrade($oldversion) {
global $DB;

$options = [
BLOCK_MYOVERVIEW_TIMELINE_VIEW => get_string('timeline', 'block_myoverview'),
BLOCK_MYOVERVIEW_COURSES_VIEW => get_string('courses')
];
if ($oldversion < 2018092700) {
$DB->delete_records('user_preferences', ['name' => 'block_myoverview_last_tab']);
upgrade_block_savepoint(true, 2018092700, 'myoverview');
}

$settings->add(new admin_setting_configselect('block_myoverview/defaulttab',
get_string('defaulttab', 'block_myoverview'),
get_string('defaulttab_desc', 'block_myoverview'), 'timeline', $options));
return true;
}
4 changes: 1 addition & 3 deletions blocks/myoverview/lang/en/block_myoverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['defaulttab'] = 'Default tab';
$string['defaulttab_desc'] = 'The tab that will be displayed when a user first views their course overview. When returning to their course overview, the user\'s active tab is remembered.';
$string['future'] = 'Future';
$string['inprogress'] = 'In progress';
$string['morecourses'] = 'More courses';
Expand All @@ -44,4 +42,4 @@
$string['timeline'] = 'Timeline';
$string['viewcourse'] = 'View course';
$string['viewcoursename'] = 'View course {$a}';
$string['privacy:metadata:overviewlasttab'] = 'This stores the last tab selected by the user on the overview block.';
$string['privacy:metadata'] = 'The myoverview block does not store any personal data.';
6 changes: 0 additions & 6 deletions blocks/myoverview/templates/main.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,3 @@
</div>
</div>
</div>
{{#js}}
require(['jquery', 'block_myoverview/tab_preferences'], function($, TabPreferences) {
var root = $('#block-myoverview-view-choices-{{uniqid}}');
TabPreferences.registerEventListeners(root);
});
{{/js}}
80 changes: 0 additions & 80 deletions blocks/myoverview/tests/privacy_test.php

This file was deleted.

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 = 2018051400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2018092700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018050800; // Requires this Moodle version.
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,7 @@ protected function load_courses_enrolled() {
// Show a link to the course page if there are more courses the user is enrolled in.
if ($showmorelinkinnav || $showmorelinkinflatnav) {
// Adding hash to URL so the link is not highlighted in the navigation when clicked.
$url = new moodle_url('/my/?myoverviewtab=courses');
$url = new moodle_url('/my/');
$parent = $this->rootnodes['mycourses'];
$coursenode = $parent->add(get_string('morenavigationlinks'), $url, self::TYPE_CUSTOM, null, self::COURSE_INDEX_PAGE);

Expand Down
2 changes: 1 addition & 1 deletion message/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function test_export_user_preferences() {
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'inbound', $user->id);

// Set an unrelated preference.
set_user_preference('block_myoverview_last_tab', 'courses', $USER->id);
set_user_preference('some_unrelated_preference', 'courses', $USER->id);

provider::export_user_preferences($USER->id);

Expand Down

0 comments on commit bbe6ead

Please sign in to comment.