This commit is contained in:
Jun Pataleta 2023-08-28 17:03:27 +08:00
commit be35034f1c
No known key found for this signature in database
GPG key ID: F83510526D99E2C7
26 changed files with 213 additions and 59 deletions

View file

@ -141,10 +141,6 @@ class block_settings extends block_base {
} else {
$this->content->footer = '';
}
if (!empty($this->config->enabledock) && $this->config->enabledock == 'yes') {
user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings::$navcount, PARAM_INT);
}
}
$this->contentgenerated = true;

View file

@ -32,10 +32,14 @@
* @param string $name the name of the user_perference we should allow to be updated by remote calls.
* @param integer $paramtype one of the PARAM_{TYPE} constants, user to clean submitted values before set_user_preference is called.
* @return null
*
* @deprecated since Moodle 4.3
*/
function user_preference_allow_ajax_update($name, $paramtype) {
global $USER, $PAGE;
debugging(__FUNCTION__ . '() is deprecated. Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
// Record in the session that this user_preference is allowed to updated remotely.
$USER->ajax_updatable_user_prefs[$name] = $paramtype;
}

View file

@ -24,6 +24,7 @@
* @category preference
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since Moodle 4.3
*/
require_once(__DIR__ . '/../../config.php');
@ -39,6 +40,8 @@ if (!isset($USER->ajax_updatable_user_prefs[$name])) {
throw new \moodle_exception('notallowedtoupdateprefremotely');
}
debugging('Use of setuserpref.php is deprecated. Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
// Get and the value.
$value = required_param('value', $USER->ajax_updatable_user_prefs[$name]);

View file

@ -979,6 +979,60 @@ class core_user {
'permissioncallback' => function($user, $preferencename) {
return self::is_current_user($user) && has_capability('moodle/blog:view', context_system::instance());
});
$preferences['filemanager_recentviewmode'] = [
'type' => PARAM_INT,
'null' => NULL_NOT_ALLOWED,
'default' => 1,
'choices' => [1, 2, 3],
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['filepicker_recentrepository'] = [
'type' => PARAM_INT,
'null' => NULL_NOT_ALLOWED,
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['filepicker_recentlicense'] = [
'type' => PARAM_SAFEDIR,
'null' => NULL_NOT_ALLOWED,
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['filepicker_recentviewmode'] = [
'type' => PARAM_INT,
'null' => NULL_NOT_ALLOWED,
'default' => 1,
'choices' => [1, 2, 3],
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['userselector_optionscollapsed'] = [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => true,
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['userselector_autoselectunique'] = [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['userselector_preserveselected'] = [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['userselector_searchanywhere'] = [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'permissioncallback' => [static::class, 'is_current_user'],
];
$preferences['question_bank_advanced_search'] = [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'permissioncallback' => [static::class, 'is_current_user'],
];
$choices = [HOMEPAGE_SITE];
if (!empty($CFG->enabledashboard)) {

View file

@ -1912,6 +1912,7 @@ $functions = array(
'type' => 'write',
'capabilities' => 'moodle/site:config',
'ajax' => true,
'loginrequired' => false,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_user_agree_site_policy' => array(

View file

@ -1218,8 +1218,10 @@ M.form_filemanager.init = function(Y, options) {
},
set_preference: function(name, value) {
if (this.userprefs[name] != value) {
M.util.set_user_preference('filemanager_' + name, value);
this.userprefs[name] = value;
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference('filemanager_' + name, value);
this.userprefs[name] = value;
}.bind(this));
}
},
});

View file

@ -453,7 +453,6 @@ class form_filemanager implements renderable {
$this->options->userprefs = array();
$this->options->userprefs['recentviewmode'] = get_user_preferences('filemanager_recentviewmode', '');
user_preference_allow_ajax_update('filemanager_recentviewmode', PARAM_INT);
// building file picker options
$params = new stdClass();

View file

@ -160,7 +160,9 @@ M.util.CollapsibleRegion = function(Y, id, userpref, strtooltip) {
animation.set('reverse', this.div.hasClass('collapsed'));
// Update the user preference.
if (this.userpref) {
M.util.set_user_preference(this.userpref, !this.div.hasClass('collapsed'));
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference(this.userpref, !this.div.hasClass('collapsed'));
}.bind(this));
}
animation.run();
}, this, animation);
@ -195,27 +197,16 @@ M.util.CollapsibleRegion.prototype.icon = null;
* user_preference_allow_ajax_update from moodlelib.php to tell Moodle that
* the udpate is allowed, and how to safely clean and submitted values.
*
* @param String name the name of the setting to udpate.
* @param String the value to set it to.
* @param {String} name the name of the setting to update.
* @param {String} value the value to set it to.
*
* @deprecated since Moodle 4.3.
*/
M.util.set_user_preference = function(name, value) {
YUI().use('io', function(Y) {
var url = M.cfg.wwwroot + '/lib/ajax/setuserpref.php?sesskey=' +
M.cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value);
Y.log('M.util.set_user_preference is deprecated. Please use the "core_user/repository" module instead.', 'warn');
// If we are a developer, ensure that failures are reported.
var cfg = {
method: 'get',
on: {}
};
if (M.cfg.developerdebug) {
cfg.on.failure = function(id, o, args) {
alert("Error updating user preference '" + name + "' using ajax. Clicking this link will repeat the Ajax call that failed so you can see the error: ");
}
}
// Make the request.
Y.io(url, cfg);
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference(name, value);
});
};
@ -588,7 +579,9 @@ M.util.init_block_hider = function(Y, config) {
}
},
updateState : function(e, hide) {
M.util.set_user_preference(this.get('preference'), hide);
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference(this.get('preference'), hide);
}.bind(this));
if (hide) {
this.get('block').addClass('hidden');
this.get('block').one('.block-hider-show').focus();

View file

@ -2560,7 +2560,6 @@ function print_collapsible_region_start($classes, $id, $caption, $userpref = '',
// Work out the initial state.
if (!empty($userpref) and is_string($userpref)) {
user_preference_allow_ajax_update($userpref, PARAM_BOOL);
$collapsed = get_user_preferences($userpref, $default);
} else {
$collapsed = $default;

View file

@ -72,9 +72,6 @@ class grading_app implements templatable, renderable {
$this->userid = $userid;
$this->groupid = $groupid;
$this->assignment = $assignment;
user_preference_allow_ajax_update('assign_filter', PARAM_ALPHA);
user_preference_allow_ajax_update('assign_workflowfilter', PARAM_ALPHA);
user_preference_allow_ajax_update('assign_markerfilter', PARAM_ALPHANUMEXT);
$this->participants = $assignment->list_participants_with_filter_status_and_group($groupid);
if (!$this->userid && count($this->participants)) {
$this->userid = reset($this->participants)->id;

View file

@ -2252,6 +2252,38 @@ function workshop_get_coursemodule_info($coursemodule) {
return $result;
}
/**
* Get the current user preferences that are available
*
* @return array[]
*/
function mod_workshop_user_preferences(): array {
$preferencedefinition = [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'permissioncallback' => [core_user::class, 'is_current_user'],
];
return [
'workshop-viewlet-allexamples-collapsed' => $preferencedefinition,
'workshop-viewlet-allsubmissions-collapsed' => $preferencedefinition,
'workshop-viewlet-assessmentform-collapsed' => $preferencedefinition,
'workshop-viewlet-assignedassessments-collapsed' => $preferencedefinition,
'workshop-viewlet-cleargrades-collapsed' => $preferencedefinition,
'workshop-viewlet-conclusion-collapsed' => $preferencedefinition,
'workshop-viewlet-examples-collapsed' => $preferencedefinition,
'workshop-viewlet-examplesfail-collapsed' => $preferencedefinition,
'workshop-viewlet-gradereport-collapsed' => $preferencedefinition,
'workshop-viewlet-instructauthors-collapsed' => $preferencedefinition,
'workshop-viewlet-instructreviewers-collapsed' => $preferencedefinition,
'workshop-viewlet-intro-collapsed' => $preferencedefinition,
'workshop-viewlet-ownsubmission-collapsed' => $preferencedefinition,
'workshop-viewlet-publicsubmissions-collapsed' => $preferencedefinition,
'workshop-viewlet-yourgrades-collapsed' => $preferencedefinition,
];
}
/**
* Callback to fetch the activity event type lang string.
*

View file

@ -0,0 +1,41 @@
<?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/>.
/**
* Callback methods for preview question component
*
* @package qbank_previewquestion
* @copyright 2023 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
/**
* Get the current user preferences that are available
*
* @return array[]
*/
function qbank_previewquestion_user_preferences(): array {
return [
'core_question_preview_techinfo_collapsed' => [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => true,
'permissioncallback' => [core_user::class, 'is_current_user'],
],
];
}

View file

@ -2125,8 +2125,10 @@ M.core_filepicker.init = function(Y, options) {
},
set_preference: function(name, value) {
if (this.options.userprefs[name] != value) {
M.util.set_user_preference('filepicker_' + name, value);
this.options.userprefs[name] = value;
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference('filepicker_' + name, value);
this.options.userprefs[name] = value;
}.bind(this));
}
},
in_iframe: function () {

View file

@ -3190,11 +3190,6 @@ function initialise_filepicker($args) {
$return->userprefs['recentlicense'] = get_user_preferences('filepicker_recentlicense', '');
$return->userprefs['recentviewmode'] = get_user_preferences('filepicker_recentviewmode', '');
user_preference_allow_ajax_update('filepicker_recentrepository', PARAM_INT);
user_preference_allow_ajax_update('filepicker_recentlicense', PARAM_SAFEDIR);
user_preference_allow_ajax_update('filepicker_recentviewmode', PARAM_INT);
// provided by form element
$return->accepted_types = file_get_typegroup('extension', $args->accepted_types);
$return->return_types = $args->return_types;

View file

@ -5,6 +5,6 @@
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("theme_boost/drawer",["jquery","core/custom_interaction_events","core/log","core/pubsub","core/aria"],(function($,CustomEvents,Log,PubSub,Aria){var SELECTORS_TOGGLE_REGION='[data-region="drawer-toggle"]',SELECTORS_TOGGLE_ACTION='[data-action="toggle-drawer"]',SELECTORS_BODY="body",SELECTORS_SECTION='.list-group-item[href*="#section-"]',SELECTORS_DRAWER="#nav-drawer",small=$(document).width()<768,Drawer=function(){$(SELECTORS_TOGGLE_REGION).length||Log.debug("Page is missing a drawer region"),$(SELECTORS_TOGGLE_ACTION).length||Log.debug("Page is missing a drawer toggle link"),$(SELECTORS_TOGGLE_REGION).each(function(index,ele){var trigger=$(ele).find(SELECTORS_TOGGLE_ACTION),drawerid=trigger.attr("aria-controls"),drawer=$(document.getElementById(drawerid)),hidden="false"==trigger.attr("aria-expanded"),side=trigger.attr("data-side"),body=$(SELECTORS_BODY),preference=trigger.attr("data-preference");small&&M.util.set_user_preference(preference,"false"),drawer.on("mousewheel DOMMouseScroll",this.preventPageScroll),hidden?trigger.attr("aria-expanded","false"):(body.addClass("drawer-open-"+side),trigger.attr("aria-expanded","true"))}.bind(this)),this.registerEventListeners(),small&&this.closeAll()};return Drawer.prototype.closeAll=function(){$(SELECTORS_TOGGLE_REGION).each((function(index,ele){var trigger=$(ele).find(SELECTORS_TOGGLE_ACTION),side=trigger.attr("data-side"),body=$(SELECTORS_BODY),drawerid=trigger.attr("aria-controls"),drawer=$(document.getElementById(drawerid)),preference=trigger.attr("data-preference");trigger.attr("aria-expanded","false"),body.removeClass("drawer-open-"+side),Aria.hide(drawer.get()),drawer.addClass("closed"),small||M.util.set_user_preference(preference,"false")}))},Drawer.prototype.toggleDrawer=function(e){var trigger=$(e.target).closest("[data-action=toggle-drawer]"),drawerid=trigger.attr("aria-controls"),drawer=$(document.getElementById(drawerid)),body=$(SELECTORS_BODY),side=trigger.attr("data-side"),preference=trigger.attr("data-preference");small&&M.util.set_user_preference(preference,"false"),body.addClass("drawer-ease");var open="true"==trigger.attr("aria-expanded");open?(body.removeClass("drawer-open-"+side),trigger.attr("aria-expanded","false"),drawer.addClass("closed").delay(500).queue((function(){$(this).hasClass("closed")&&Aria.hide(this),$(this).dequeue()})),small||M.util.set_user_preference(preference,"false")):(trigger.attr("aria-expanded","true"),Aria.unhide(drawer.get()),drawer.focus(),body.addClass("drawer-open-"+side),drawer.removeClass("closed"),small||M.util.set_user_preference(preference,"true")),PubSub.publish("nav-drawer-toggle-start",open)},Drawer.prototype.preventPageScroll=function(e){var delta=e.wheelDelta||e.originalEvent&&e.originalEvent.wheelDelta||-e.originalEvent.detail,bottomOverflow=this.scrollTop+$(this).outerHeight()-this.scrollHeight>=0,topOverflow=this.scrollTop<=0;(delta<0&&bottomOverflow||delta>0&&topOverflow)&&e.preventDefault()},Drawer.prototype.registerEventListeners=function(){$(SELECTORS_TOGGLE_ACTION).each(function(index,element){CustomEvents.define($(element),[CustomEvents.events.activate]),$(element).on(CustomEvents.events.activate,function(e,data){this.toggleDrawer(data.originalEvent),data.originalEvent.preventDefault()}.bind(this))}.bind(this)),$(SELECTORS_SECTION).click(function(){small&&this.closeAll()}.bind(this)),$(SELECTORS_DRAWER).on("webkitTransitionEnd msTransitionEnd transitionend",(function(e){var open=!!$(e.target).closest(SELECTORS_DRAWER).attr("aria-hidden");PubSub.publish("nav-drawer-toggle-end",open)}))},{init:function(){return new Drawer}}}));
define("theme_boost/drawer",["jquery","core/custom_interaction_events","core/log","core/pubsub","core/aria","core_user/repository"],(function($,CustomEvents,Log,PubSub,Aria,UserRepository){var SELECTORS_TOGGLE_REGION='[data-region="drawer-toggle"]',SELECTORS_TOGGLE_ACTION='[data-action="toggle-drawer"]',SELECTORS_BODY="body",SELECTORS_SECTION='.list-group-item[href*="#section-"]',SELECTORS_DRAWER="#nav-drawer",small=$(document).width()<768,Drawer=function(){$(SELECTORS_TOGGLE_REGION).length||Log.debug("Page is missing a drawer region"),$(SELECTORS_TOGGLE_ACTION).length||Log.debug("Page is missing a drawer toggle link"),$(SELECTORS_TOGGLE_REGION).each(function(index,ele){var trigger=$(ele).find(SELECTORS_TOGGLE_ACTION),drawerid=trigger.attr("aria-controls"),drawer=$(document.getElementById(drawerid)),hidden="false"==trigger.attr("aria-expanded"),side=trigger.attr("data-side"),body=$(SELECTORS_BODY),preference=trigger.attr("data-preference");small&&UserRepository.setUserPreference(preference,!1),drawer.on("mousewheel DOMMouseScroll",this.preventPageScroll),hidden?trigger.attr("aria-expanded","false"):(body.addClass("drawer-open-"+side),trigger.attr("aria-expanded","true"))}.bind(this)),this.registerEventListeners(),small&&this.closeAll()};return Drawer.prototype.closeAll=function(){$(SELECTORS_TOGGLE_REGION).each((function(index,ele){var trigger=$(ele).find(SELECTORS_TOGGLE_ACTION),side=trigger.attr("data-side"),body=$(SELECTORS_BODY),drawerid=trigger.attr("aria-controls"),drawer=$(document.getElementById(drawerid)),preference=trigger.attr("data-preference");trigger.attr("aria-expanded","false"),body.removeClass("drawer-open-"+side),Aria.hide(drawer.get()),drawer.addClass("closed"),small||UserRepository.setUserPreference(preference,!1)}))},Drawer.prototype.toggleDrawer=function(e){var trigger=$(e.target).closest("[data-action=toggle-drawer]"),drawerid=trigger.attr("aria-controls"),drawer=$(document.getElementById(drawerid)),body=$(SELECTORS_BODY),side=trigger.attr("data-side"),preference=trigger.attr("data-preference");small&&UserRepository.setUserPreference(preference,!1),body.addClass("drawer-ease");var open="true"==trigger.attr("aria-expanded");open?(body.removeClass("drawer-open-"+side),trigger.attr("aria-expanded","false"),drawer.addClass("closed").delay(500).queue((function(){$(this).hasClass("closed")&&Aria.hide(this),$(this).dequeue()})),small||UserRepository.setUserPreference(preference,!1)):(trigger.attr("aria-expanded","true"),Aria.unhide(drawer.get()),drawer.focus(),body.addClass("drawer-open-"+side),drawer.removeClass("closed"),small||UserRepository.setUserPreference(preference,!0)),PubSub.publish("nav-drawer-toggle-start",open)},Drawer.prototype.preventPageScroll=function(e){var delta=e.wheelDelta||e.originalEvent&&e.originalEvent.wheelDelta||-e.originalEvent.detail,bottomOverflow=this.scrollTop+$(this).outerHeight()-this.scrollHeight>=0,topOverflow=this.scrollTop<=0;(delta<0&&bottomOverflow||delta>0&&topOverflow)&&e.preventDefault()},Drawer.prototype.registerEventListeners=function(){$(SELECTORS_TOGGLE_ACTION).each(function(index,element){CustomEvents.define($(element),[CustomEvents.events.activate]),$(element).on(CustomEvents.events.activate,function(e,data){this.toggleDrawer(data.originalEvent),data.originalEvent.preventDefault()}.bind(this))}.bind(this)),$(SELECTORS_SECTION).click(function(){small&&this.closeAll()}.bind(this)),$(SELECTORS_DRAWER).on("webkitTransitionEnd msTransitionEnd transitionend",(function(e){var open=!!$(e.target).closest(SELECTORS_DRAWER).attr("aria-hidden");PubSub.publish("nav-drawer-toggle-end",open)}))},{init:function(){return new Drawer}}}));
//# sourceMappingURL=drawer.min.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -20,8 +20,8 @@
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', 'core/aria'],
function($, CustomEvents, Log, PubSub, Aria) {
define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', 'core/aria', 'core_user/repository'],
function($, CustomEvents, Log, PubSub, Aria, UserRepository) {
var SELECTORS = {
TOGGLE_REGION: '[data-region="drawer-toggle"]',
@ -55,7 +55,7 @@ define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', '
var body = $(SELECTORS.BODY);
var preference = trigger.attr('data-preference');
if (small) {
M.util.set_user_preference(preference, 'false');
UserRepository.setUserPreference(preference, false);
}
drawer.on('mousewheel DOMMouseScroll', this.preventPageScroll);
@ -88,7 +88,7 @@ define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', '
Aria.hide(drawer.get());
drawer.addClass('closed');
if (!small) {
M.util.set_user_preference(preference, 'false');
UserRepository.setUserPreference(preference, false);
}
});
};
@ -107,7 +107,7 @@ define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', '
var side = trigger.attr('data-side');
var preference = trigger.attr('data-preference');
if (small) {
M.util.set_user_preference(preference, 'false');
UserRepository.setUserPreference(preference, false);
}
body.addClass('drawer-ease');
@ -120,7 +120,7 @@ define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', '
body.addClass('drawer-open-' + side);
drawer.removeClass('closed');
if (!small) {
M.util.set_user_preference(preference, 'true');
UserRepository.setUserPreference(preference, true);
}
} else {
// Close.
@ -134,7 +134,7 @@ define(['jquery', 'core/custom_interaction_events', 'core/log', 'core/pubsub', '
$(this).dequeue();
});
if (!small) {
M.util.set_user_preference(preference, 'false');
UserRepository.setUserPreference(preference, false);
}
}

View file

@ -27,6 +27,7 @@ import {dispatchEvent} from 'core/event_dispatcher';
import {debounce} from 'core/utils';
import {isSmall, isLarge} from 'core/pagehelpers';
import Pending from 'core/pending';
import {setUserPreference} from 'core_user/repository';
// The jQuery module is only used for interacting with Boostrap 4. It can we removed when MDL-71979 is integrated.
import jQuery from 'jquery';
@ -439,7 +440,7 @@ export default class Drawers {
const preference = this.drawerNode.dataset.preference;
if (preference && !isSmall() && (this.drawerNode.dataset.forceopen != 1)) {
M.util.set_user_preference(preference, true);
setUserPreference(preference, true);
}
const state = this.drawerNode.dataset.state;
@ -508,7 +509,7 @@ export default class Drawers {
const preference = this.drawerNode.dataset.preference;
if (preference && updatePreferences && !isSmall()) {
M.util.set_user_preference(preference, false);
setUserPreference(preference, false);
}
const state = this.drawerNode.dataset.state;

View file

@ -30,9 +30,6 @@ require_once($CFG->dirroot . '/course/lib.php');
// Add block button in editing mode.
$addblockbutton = $OUTPUT->addblockbutton();
user_preference_allow_ajax_update('drawer-open-index', PARAM_BOOL);
user_preference_allow_ajax_update('drawer-open-block', PARAM_BOOL);
if (isloggedin()) {
$courseindexopen = (get_user_preferences('drawer-open-index', true) == true);
$blockdraweropen = (get_user_preferences('drawer-open-block') == true);

View file

@ -93,6 +93,28 @@ function theme_boost_pluginfile($course, $cm, $context, $filearea, $args, $force
}
}
/**
* Get the current user preferences that are available
*
* @return array[]
*/
function theme_boost_user_preferences(): array {
return [
'drawer-open-block' => [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'permissioncallback' => [core_user::class, 'is_current_user'],
],
'drawer-open-index' => [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => true,
'permissioncallback' => [core_user::class, 'is_current_user'],
],
];
}
/**
* Returns the main SCSS content.
*

View file

@ -1822,14 +1822,14 @@ class core_user_external extends \core_external\external_api {
* @throws moodle_exception
*/
public static function set_user_preferences($preferences) {
global $USER;
global $PAGE, $USER;
$params = self::validate_parameters(self::set_user_preferences_parameters(), array('preferences' => $preferences));
$warnings = array();
$saved = array();
$context = context_system::instance();
self::validate_context($context);
$PAGE->set_context($context);
$userscache = array();
foreach ($params['preferences'] as $pref) {
@ -1855,7 +1855,18 @@ class core_user_external extends \core_external\external_api {
}
try {
if (core_user::can_edit_preference($pref['name'], $user)) {
// Support legacy preferences from the old M.util.set_user_preference API (always using the current user).
if (isset($USER->ajax_updatable_user_prefs[$pref['name']])) {
debugging('Updating preferences via ajax_updatable_user_prefs is deprecated. ' .
'Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
set_user_preference($pref['name'], $pref['value']);
$saved[] = array(
'name' => $pref['name'],
'userid' => $USER->id,
);
} else if (core_user::can_edit_preference($pref['name'], $user)) {
$value = core_user::clean_preference($pref['value'], $pref['name']);
set_user_preference($pref['name'], $value, $user->id);
$saved[] = array(

View file

@ -679,7 +679,6 @@ abstract class user_selector_base {
'" value="1"' . $checked . ' /> ' . $label .
"</label>
</div>\n";
user_preference_allow_ajax_update($name, PARAM_BOOL);
return $output;
}

View file

@ -368,7 +368,9 @@ M.core_user.init_user_selector_options_tracker = function(Y) {
* @param {string} name The name of the preference to set
*/
set_user_preference : function(e, name) {
M.util.set_user_preference(name, Y.one('#' + name + 'id').get('checked'));
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference(name, Y.one('#' + name + 'id').get('checked'));
});
}
};
// Initialise the options tracker

View file

@ -9,6 +9,10 @@ This files describes API changes for code that uses the user API.
* The `core_user/repository` Javascript module now exports new methods for manipulating user preferences:
- `[get|set]UserPreference`
- `[get|set]UserPreferences`
* The following user preference helpers have been deprecated, please use the `core_user/repository` module instead:
- `user_preference_allow_ajax_update`
- `M.util.set_user_preference`
- `lib/ajax/setuserpref.php`
* The external `core_user_set_user_preferences` method will now default the `userid` property of each preference to
that of the current user, if omitted
* The following previously deprecated methods have been removed and can no longer be used: