MDL-73532 mod_feedback: Update the load_module_navigation() method
[moodle.git] / my / courses.php
blob9b59fc84acbdd3c1430ac99e66b50682bc32e457
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.
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/>.
17 /**
18 * My Courses.
20 * - each user can currently have their own page (cloned from system and then customised)
21 * - only the user can see their own dashboard
22 * - users can add any blocks they want
24 * @package core
25 * @subpackage my
26 * @copyright 2021 Mathew May <mathew.solutions>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require_once(__DIR__ . '/../config.php');
31 require_once($CFG->dirroot . '/my/lib.php');
33 redirect_if_major_upgrade_required();
35 require_login();
37 $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
38 if ($hassiteconfig && moodle_needs_upgrading()) {
39 redirect(new moodle_url('/admin/index.php'));
42 $context = context_system::instance();
44 // Get the My Moodle page info. Should always return something unless the database is broken.
45 if (!$currentpage = my_get_page(null, MY_PAGE_PUBLIC, MY_PAGE_COURSES)) {
46 throw new Exception('mymoodlesetup');
49 // Start setting up the page.
50 $PAGE->set_context($context);
51 $PAGE->set_url('/my/courses.php');
52 $PAGE->add_body_classes(['limitedwidth', 'page-mycourses']);
53 $PAGE->set_pagelayout('mycourses');
54 $PAGE->has_secondary_navigation_setter(false);
56 $PAGE->set_pagetype('my-index');
57 $PAGE->blocks->add_region('content');
58 $PAGE->set_subpage($currentpage->id);
59 $PAGE->set_title(get_string('mycourses'));
60 $PAGE->set_heading(get_string('mycourses'));
61 // Force the add block out of the default area.
62 $PAGE->theme->addblockposition = BLOCK_ADDBLOCK_POSITION_CUSTOM;
64 // Add course management if the user has the capabilities for it.
65 $coursecat = core_course_category::user_top();
66 if ($coursecat->can_create_course() || $coursecat->has_manage_capability()) {
67 $data = [
68 'newcourseurl' => new moodle_url('/course/edit.php', ['category' => $coursecat->id]),
69 'manageurl' => new moodle_url('/course/management.php', ['categoryid' => $coursecat->id]),
71 $PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $data));
74 echo $OUTPUT->header();
76 if (core_userfeedback::should_display_reminder()) {
77 core_userfeedback::print_reminder_block();
80 echo $OUTPUT->custom_block_region('content');
82 echo $OUTPUT->footer();
84 // Trigger dashboard has been viewed event.
85 $eventparams = array('context' => $context);
86 $event = \core\event\mycourses_viewed::create($eventparams);
87 $event->trigger();