1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core_user\form;
|
|
|
18 |
|
1441 |
ariadna |
19 |
use core\di;
|
|
|
20 |
use core\hook\manager;
|
|
|
21 |
use core\lang_string;
|
|
|
22 |
use core_user\hook\extend_default_homepage;
|
1 |
efrain |
23 |
|
|
|
24 |
defined('MOODLE_INTERNAL') || die;
|
|
|
25 |
|
|
|
26 |
require_once($CFG->dirroot . '/lib/formslib.php');
|
|
|
27 |
|
|
|
28 |
/**
|
1441 |
ariadna |
29 |
* Form to allow user to set their default home page
|
1 |
efrain |
30 |
*
|
1441 |
ariadna |
31 |
* @package core_user
|
1 |
efrain |
32 |
* @copyright 2019 Paul Holden <paulh@moodle.com>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class defaulthomepage_form extends \moodleform {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Define the form.
|
|
|
39 |
*/
|
|
|
40 |
public function definition() {
|
|
|
41 |
global $CFG;
|
|
|
42 |
|
|
|
43 |
$mform = $this->_form;
|
|
|
44 |
|
|
|
45 |
$mform->addElement('hidden', 'id');
|
|
|
46 |
$mform->setType('id', PARAM_INT);
|
|
|
47 |
|
|
|
48 |
$options = [HOMEPAGE_SITE => new lang_string('home')];
|
|
|
49 |
if (!empty($CFG->enabledashboard)) {
|
|
|
50 |
$options[HOMEPAGE_MY] = new lang_string('mymoodle', 'admin');
|
|
|
51 |
}
|
|
|
52 |
$options[HOMEPAGE_MYCOURSES] = new lang_string('mycourses', 'admin');
|
|
|
53 |
|
1441 |
ariadna |
54 |
// Allow hook callbacks to extend options.
|
|
|
55 |
$hook = new extend_default_homepage(true);
|
|
|
56 |
di::get(manager::class)->dispatch($hook);
|
|
|
57 |
$options += $hook->get_options();
|
|
|
58 |
|
1 |
efrain |
59 |
$mform->addElement('select', 'defaulthomepage', get_string('defaulthomepageuser'), $options);
|
|
|
60 |
$mform->addHelpButton('defaulthomepage', 'defaulthomepageuser');
|
|
|
61 |
$mform->setDefault('defaulthomepage', get_default_home_page());
|
|
|
62 |
|
|
|
63 |
$this->add_action_buttons(true, get_string('savechanges'));
|
|
|
64 |
}
|
|
|
65 |
}
|