我使用此代码来创建颜色更改功能 我的moodle lib.php代码是
function learningbell_initialise_colourswitcher(moodle_page $page) {
user_preference_allow_ajax_update('theme_learningbell_chosen_colour', PARAM_ALPHA);
$page->requires->yui_module('moodle-theme_learningbell-colourswitcher', 'M.theme_learningbell.initColourSwitcher', array(array('div'=>'#colourswitcher')));
}
/**
* Gets the colour the user has selected, or the default if they have never changed
*
* @param string $default The default colour to use, normally red
* @return string The colour the user has selected
*/
function learningbell_get_colour($default='blue') {
return get_user_preferences('theme_learningbell_chosen_colour', $default);
}
/**
* Checks if the user is switching colours with a refresh (JS disabled)
*
* If they are this updates the users preference in the database
*
* @return bool
*/
function learningbell_check_colourswitch() {
$changecolour = optional_param('learningbellcolour', null, PARAM_ALPHA);
if (in_array($changecolour, array('blue', 'green', 'red', 'orange', 'yellow', 'pink'))) {
return set_user_preference('theme_learningbell_chosen_colour', $changecolour);
}
return false;
}
但我想使默认颜色应该选择颜色,如任何颜色('蓝色','绿色','红色','橙色','黄色','粉红色'),这是当前由管理员选择的颜色。如果我选择粉红色,但问题是注销后它需要自动蓝色 请帮帮我。
答案 0 :(得分:0)
您是否在调用get_user_preference()之前设置了用户首选项?
$selectedcolour = ...
set_user_preference('theme_learningbell_chosen_colour', $selectedcolour);