mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-73233 admin: Add enabledashboard setting
The $CFG->enabledashboard setting has been added to Appearance > Navigation, to let admins disable the "Dashboard" option from the primary navigation. This commit also changes the behaviour of get_home_page(), to take into account this setting and adds a new method, get_default_home_page(), to return the expected default home page (that wil be used when current default page is not defined or valid).
This commit is contained in:
parent
9344149aba
commit
5349861e69
6 changed files with 196 additions and 14 deletions
|
@ -186,15 +186,29 @@ reports,core_reportbuilder|/reportbuilder/index.php',
|
|||
|
||||
// Navigation settings
|
||||
$temp = new admin_settingpage('navigation', new lang_string('navigation'));
|
||||
$choices = array(
|
||||
HOMEPAGE_SITE => new lang_string('site'),
|
||||
HOMEPAGE_MY => new lang_string('mymoodle', 'admin'),
|
||||
HOMEPAGE_MYCOURSES => new lang_string('mycourses', 'admin'),
|
||||
HOMEPAGE_USER => new lang_string('userpreference', 'admin')
|
||||
);
|
||||
$temp->add(new admin_setting_configcheckbox(
|
||||
'enabledashboard',
|
||||
new lang_string('enabledashboard', 'admin'),
|
||||
new lang_string('enabledashboard_help', 'admin'),
|
||||
1
|
||||
));
|
||||
|
||||
$choices = [HOMEPAGE_SITE => new lang_string('home')];
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
$choices[HOMEPAGE_MY] = new lang_string('mymoodle', 'admin');
|
||||
}
|
||||
$choices[HOMEPAGE_MYCOURSES] = new lang_string('mycourses', 'admin');
|
||||
$choices[HOMEPAGE_USER] = new lang_string('userpreference', 'admin');
|
||||
$temp->add(new admin_setting_configselect('defaulthomepage', new lang_string('defaulthomepage', 'admin'),
|
||||
new lang_string('configdefaulthomepage', 'admin'), HOMEPAGE_MY, $choices));
|
||||
$temp->add(new admin_setting_configcheckbox('allowguestmymoodle', new lang_string('allowguestmymoodle', 'admin'), new lang_string('configallowguestmymoodle', 'admin'), 1));
|
||||
new lang_string('configdefaulthomepage', 'admin'), get_default_home_page(), $choices));
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
$temp->add(new admin_setting_configcheckbox(
|
||||
'allowguestmymoodle',
|
||||
new lang_string('allowguestmymoodle', 'admin'),
|
||||
new lang_string('configallowguestmymoodle', 'admin'),
|
||||
1
|
||||
));
|
||||
}
|
||||
$temp->add(new admin_setting_configcheckbox('navshowfullcoursenames', new lang_string('navshowfullcoursenames', 'admin'), new lang_string('navshowfullcoursenames_help', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0));
|
||||
|
@ -237,9 +251,11 @@ reports,core_reportbuilder|/reportbuilder/index.php',
|
|||
$temp->add(new admin_setting_configcheckbox('doctonewwindow', new lang_string('doctonewwindow', 'admin'), new lang_string('configdoctonewwindow', 'admin'), 0));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
$temp = new admin_externalpage('mypage', new lang_string('mypage', 'admin'), $CFG->wwwroot . '/my/indexsys.php',
|
||||
'moodle/my:configsyspages');
|
||||
$ADMIN->add('appearance', $temp);
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
$temp = new admin_externalpage('mypage', new lang_string('mypage', 'admin'), $CFG->wwwroot . '/my/indexsys.php',
|
||||
'moodle/my:configsyspages');
|
||||
$ADMIN->add('appearance', $temp);
|
||||
}
|
||||
|
||||
$temp = new admin_externalpage('profilepage', new lang_string('myprofile', 'admin'), $CFG->wwwroot . '/user/profilesys.php',
|
||||
'moodle/my:configsyspages');
|
||||
|
|
|
@ -562,6 +562,8 @@ $string['enablecourserelativedates'] = 'Enable course relative dates';
|
|||
$string['enablecourserelativedates_desc'] = 'Allow courses to be set up to display dates relative to the user\'s start date in the course.';
|
||||
$string['enablecourserequests'] = 'Enable course requests';
|
||||
$string['enabled'] = 'Enabled';
|
||||
$string['enabledashboard'] = 'Enable dashboard';
|
||||
$string['enabledashboard_help'] = 'The Dashboard shows Timeline, Calendar and Recently accessed items by default. You can set a different default Dashboard for everyone and allow users to customise their own Dashboard.';
|
||||
$string['enabledevicedetection'] = 'Enable device detection';
|
||||
$string['enableglobalsearch'] = 'Enable global search';
|
||||
$string['enableglobalsearch_desc'] = 'If enabled, data will be indexed and synchronised by a scheduled task.';
|
||||
|
|
|
@ -10367,17 +10367,40 @@ function get_home_page() {
|
|||
global $CFG;
|
||||
|
||||
if (isloggedin() && !isguestuser() && !empty($CFG->defaulthomepage)) {
|
||||
// If dashboard is disabled, home will be set to default page.
|
||||
$defaultpage = get_default_home_page();
|
||||
if ($CFG->defaulthomepage == HOMEPAGE_MY) {
|
||||
return HOMEPAGE_MY;
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
return HOMEPAGE_MY;
|
||||
} else {
|
||||
return $defaultpage;
|
||||
}
|
||||
} else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) {
|
||||
return HOMEPAGE_MYCOURSES;
|
||||
} else {
|
||||
return (int)get_user_preferences('user_home_page_preference', HOMEPAGE_MY);
|
||||
$userhomepage = (int) get_user_preferences('user_home_page_preference', $defaultpage);
|
||||
if (empty($CFG->enabledashboard) && $userhomepage == HOMEPAGE_MY) {
|
||||
// If the user was using the dashboard but it's disabled, return the default home page.
|
||||
$userhomepage = $defaultpage;
|
||||
}
|
||||
return $userhomepage;
|
||||
}
|
||||
}
|
||||
return HOMEPAGE_SITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default home page to display if current one is not defined or can't be applied.
|
||||
* The default behaviour is to return Dashboard if it's enabled or My courses page if it isn't.
|
||||
*
|
||||
* @return int The default home page.
|
||||
*/
|
||||
function get_default_home_page(): int {
|
||||
global $CFG;
|
||||
|
||||
return !empty($CFG->enabledashboard) ? HOMEPAGE_MY : HOMEPAGE_MYCOURSES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a course to be displayed when showing a list of courses.
|
||||
* By default this is just $course->fullname but user can configure it. The
|
||||
|
|
|
@ -5196,4 +5196,143 @@ EOF;
|
|||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_home_page() method.
|
||||
*
|
||||
* @dataProvider get_home_page_provider
|
||||
* @param string $user Whether the user is logged, guest or not logged.
|
||||
* @param int $expected Expected value after calling the get_home_page method.
|
||||
* @param int $defaulthomepage The $CFG->defaulthomepage setting value.
|
||||
* @param int $enabledashboard Whether the dashboard should be enabled or not.
|
||||
* @param int $userpreference User preference for the home page setting.
|
||||
* @covers ::get_home_page
|
||||
*/
|
||||
public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null,
|
||||
?int $userpreference = null) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
if ($user == 'guest') {
|
||||
$this->setGuestUser();
|
||||
} else if ($user == 'logged') {
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
}
|
||||
|
||||
if (isset($defaulthomepage)) {
|
||||
$CFG->defaulthomepage = $defaulthomepage;
|
||||
}
|
||||
if (isset($enabledashboard)) {
|
||||
$CFG->enabledashboard = $enabledashboard;
|
||||
}
|
||||
|
||||
if ($USER) {
|
||||
set_user_preferences(['user_home_page_preference' => $userpreference], $USER->id);
|
||||
}
|
||||
|
||||
$homepage = get_home_page();
|
||||
$this->assertEquals($expected, $homepage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for get_home_page checks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_home_page_provider(): array {
|
||||
return [
|
||||
'No logged user' => [
|
||||
'user' => 'nologged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
],
|
||||
'Guest user' => [
|
||||
'user' => 'guest',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
],
|
||||
'Logged user. Dashboard set as default home page and enabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MY,
|
||||
'defaulthomepage' => HOMEPAGE_MY,
|
||||
'enabledashboard' => 1,
|
||||
],
|
||||
'Logged user. Dashboard set as default home page but disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_MY,
|
||||
'enabledashboard' => 0,
|
||||
],
|
||||
'Logged user. My courses set as default home page with dashboard enabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_MYCOURSES,
|
||||
'enabledashboard' => 1,
|
||||
],
|
||||
'Logged user. My courses set as default home page with dashboard disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_MYCOURSES,
|
||||
'enabledashboard' => 0,
|
||||
],
|
||||
'Logged user. Site set as default home page with dashboard enabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
'defaulthomepage' => HOMEPAGE_SITE,
|
||||
'enabledashboard' => 1,
|
||||
],
|
||||
'Logged user. Site set as default home page with dashboard disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
'defaulthomepage' => HOMEPAGE_SITE,
|
||||
'enabledashboard' => 0,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard enabled and user preference set to dashboard' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MY,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 1,
|
||||
'userpreference' => HOMEPAGE_MY,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard disabled and user preference set to dashboard' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 0,
|
||||
'userpreference' => HOMEPAGE_MY,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard enabled and user preference set to my courses' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 1,
|
||||
'userpreference' => HOMEPAGE_MYCOURSES,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard disabled and user preference set to my courses' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 0,
|
||||
'userpreference' => HOMEPAGE_MYCOURSES,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_default_home_page() method.
|
||||
*
|
||||
* @covers ::get_default_home_page
|
||||
*/
|
||||
public function test_get_default_home_page() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$CFG->enabledashboard = 1;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MY, $default);
|
||||
|
||||
$CFG->enabledashboard = 0;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MYCOURSES, $default);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,6 +247,8 @@ value to get the list of blocks that won't be displayed for a theme.
|
|||
`get_template_name(\renderer_base): string` function which will inform the default render() function with a template
|
||||
name.
|
||||
* The parameter $modinfo of the get_data method in completion_info class has been deprecated and is not used anymore.
|
||||
* A new method, get_default_home_page(), has been added to moodlelib to get the default home page to display if current one is not
|
||||
defined or can't be applied.
|
||||
|
||||
=== 3.11.4 ===
|
||||
* A new option dontforcesvgdownload has been added to the $options parameter of the send_file() function.
|
||||
|
|
|
@ -42,7 +42,7 @@ Feature: Primary navigation
|
|||
|
||||
Examples:
|
||||
| userpreference | homepage |
|
||||
| Site | Home |
|
||||
| Home | Home |
|
||||
| Dashboard | Dashboard |
|
||||
| My courses | My courses |
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue