MDL-63044 block_myoverview: remove tab preference
This commit is contained in:
@@ -1 +0,0 @@
|
||||
define(["jquery","core/ajax","core/custom_interaction_events","core/notification"],function(a,b,c,d){var e=function(e){c.define(e,[c.events.activate]),e.on(c.events.activate,"[data-toggle='tab']",function(c){var e=a(c.currentTarget).data("tabname");"function"==typeof window.history.pushState&&window.history.pushState(null,null,"?myoverviewtab="+e);var f={methodname:"core_user_update_user_preferences",args:{preferences:[{type:"block_myoverview_last_tab",value:e}]}};b.call([f])[0].fail(d.exception)})};return{registerEventListeners:e}});
|
||||
@@ -1,61 +0,0 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Javascript used to save the user's tab preference.
|
||||
*
|
||||
* @package block_myoverview
|
||||
* @copyright 2017 Mark Nelson <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define(['jquery', 'core/ajax', 'core/custom_interaction_events',
|
||||
'core/notification'], function($, Ajax, CustomEvents, Notification) {
|
||||
|
||||
/**
|
||||
* Registers an event that saves the user's tab preference when switching between them.
|
||||
*
|
||||
* @param {object} root The container element
|
||||
*/
|
||||
var registerEventListeners = function(root) {
|
||||
CustomEvents.define(root, [CustomEvents.events.activate]);
|
||||
root.on(CustomEvents.events.activate, "[data-toggle='tab']", function(e) {
|
||||
var tabname = $(e.currentTarget).data('tabname');
|
||||
// Bootstrap does not change the URL when using BS tabs, so need to do this here.
|
||||
// Also check to make sure the browser supports the history API.
|
||||
if (typeof window.history.pushState === "function") {
|
||||
window.history.pushState(null, null, '?myoverviewtab=' + tabname);
|
||||
}
|
||||
var request = {
|
||||
methodname: 'core_user_update_user_preferences',
|
||||
args: {
|
||||
preferences: [
|
||||
{
|
||||
type: 'block_myoverview_last_tab',
|
||||
value: tabname
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
Ajax.call([request])[0]
|
||||
.fail(Notification.exception);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
registerEventListeners: registerEventListeners
|
||||
};
|
||||
});
|
||||
@@ -50,16 +50,7 @@ class block_myoverview extends block_base {
|
||||
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();
|
||||
@@ -77,13 +68,4 @@ class block_myoverview extends block_base {
|
||||
public function applicable_formats() {
|
||||
return array('my' => true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This block does contain a configuration settings.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_config() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,21 +39,6 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
* @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.
|
||||
*
|
||||
@@ -88,15 +73,6 @@ class main implements renderable, templatable {
|
||||
$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),
|
||||
@@ -104,8 +80,6 @@ class main implements renderable, templatable {
|
||||
'nocourses' => $nocoursesurl,
|
||||
'noevents' => $noeventsurl
|
||||
],
|
||||
'viewingtimeline' => $viewingtimeline,
|
||||
'viewingcourses' => $viewingcourses
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,30 +32,15 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
/**
|
||||
* Upgrade code for the myoverview block.
|
||||
*
|
||||
* @param int $oldversion
|
||||
*/
|
||||
function xmldb_block_myoverview_upgrade($oldversion) {
|
||||
global $DB;
|
||||
|
||||
if ($ADMIN->fulltree) {
|
||||
if ($oldversion < 2018092700) {
|
||||
$DB->delete_records('user_preferences', ['name' => 'block_myoverview_last_tab']);
|
||||
upgrade_block_savepoint(true, 2018092700, 'myoverview');
|
||||
}
|
||||
|
||||
$options = [
|
||||
BLOCK_MYOVERVIEW_TIMELINE_VIEW => get_string('timeline', 'block_myoverview'),
|
||||
BLOCK_MYOVERVIEW_COURSES_VIEW => get_string('courses')
|
||||
];
|
||||
|
||||
$settings->add(new admin_setting_configselect('block_myoverview/defaulttab',
|
||||
get_string('defaulttab', 'block_myoverview'),
|
||||
get_string('defaulttab_desc', 'block_myoverview'), 'timeline', $options));
|
||||
return true;
|
||||
}
|
||||
@@ -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';
|
||||
@@ -44,4 +42,4 @@ $string['sortbydates'] = 'Sort by dates';
|
||||
$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.';
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the block_myoverview implementation of the privacy API.
|
||||
*
|
||||
* @package block_myoverview
|
||||
* @category test
|
||||
* @copyright 2018 Adrian Greeve <adriangreeve.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_privacy\local\request\writer;
|
||||
use \block_myoverview\privacy\provider;
|
||||
|
||||
/**
|
||||
* Unit tests for the block_myoverview implementation of the privacy API.
|
||||
*
|
||||
* @copyright 2018 Adrian Greeve <adriangreeve.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_myoverview_privacy_testcase extends \core_privacy\tests\provider_testcase {
|
||||
|
||||
/**
|
||||
* Ensure that export_user_preferences returns no data if the user has not visited the myoverview block.
|
||||
*/
|
||||
public function test_export_user_preferences_no_pref() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
provider::export_user_preferences($user->id);
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
$this->assertFalse($writer->has_any_data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the preference courses is exported properly.
|
||||
*/
|
||||
public function test_export_user_preferences_course_preference() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
set_user_preference('block_myoverview_last_tab', 'courses', $user);
|
||||
|
||||
provider::export_user_preferences($user->id);
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
$blockpreferences = $writer->get_user_preferences('block_myoverview');
|
||||
$this->assertEquals('courses', $blockpreferences->block_myoverview_last_tab->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the preference timeline is exported properly.
|
||||
*/
|
||||
public function test_export_user_preferences_timeline_preference() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
set_user_preference('block_myoverview_last_tab', 'timeline', $user);
|
||||
|
||||
provider::export_user_preferences($user->id);
|
||||
$writer = writer::with_context(\context_system::instance());
|
||||
$blockpreferences = $writer->get_user_preferences('block_myoverview');
|
||||
$this->assertEquals('timeline', $blockpreferences->block_myoverview_last_tab->value);
|
||||
}
|
||||
}
|
||||
@@ -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).
|
||||
|
||||
@@ -3036,7 +3036,7 @@ class global_navigation extends navigation_node {
|
||||
// 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);
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user