2021-10-21 12:13:36 +08:00
|
|
|
<?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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* My Courses.
|
|
|
|
*
|
|
|
|
* - each user can currently have their own page (cloned from system and then customised)
|
|
|
|
* - only the user can see their own dashboard
|
|
|
|
* - users can add any blocks they want
|
|
|
|
*
|
|
|
|
* @package core
|
|
|
|
* @subpackage my
|
|
|
|
* @copyright 2021 Mathew May <mathew.solutions>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once(__DIR__ . '/../config.php');
|
|
|
|
require_once($CFG->dirroot . '/my/lib.php');
|
|
|
|
|
|
|
|
redirect_if_major_upgrade_required();
|
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
|
|
|
|
if ($hassiteconfig && moodle_needs_upgrading()) {
|
|
|
|
redirect(new moodle_url('/admin/index.php'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$context = context_system::instance();
|
|
|
|
|
|
|
|
// Get the My Moodle page info. Should always return something unless the database is broken.
|
|
|
|
if (!$currentpage = my_get_page(null, MY_PAGE_PUBLIC, MY_PAGE_COURSES)) {
|
|
|
|
throw new Exception('mymoodlesetup');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start setting up the page.
|
|
|
|
$PAGE->set_context($context);
|
|
|
|
$PAGE->set_url('/my/courses.php');
|
|
|
|
$PAGE->add_body_classes(['limitedwidth', 'page-mycourses']);
|
|
|
|
$PAGE->set_pagelayout('mycourses');
|
|
|
|
|
|
|
|
$PAGE->set_pagetype('my-index');
|
2021-11-26 17:50:56 +00:00
|
|
|
$PAGE->blocks->add_region('content');
|
2021-10-21 12:13:36 +08:00
|
|
|
$PAGE->set_subpage($currentpage->id);
|
|
|
|
$PAGE->set_title(get_string('mycourses'));
|
|
|
|
$PAGE->set_heading(get_string('mycourses'));
|
2022-03-24 18:27:04 +08:00
|
|
|
|
|
|
|
// No blocks can be edited on this page (including by managers/admins) because:
|
|
|
|
// - Course overview is a fixed item on the page and cannot be moved/removed.
|
|
|
|
// - We do not want new blocks on the page.
|
|
|
|
// - Only global blocks (if any) should be visible on the site panel, and cannot be moved int othe centre pane.
|
|
|
|
$PAGE->force_lock_all_blocks();
|
|
|
|
|
2021-10-21 12:13:36 +08:00
|
|
|
// Force the add block out of the default area.
|
|
|
|
$PAGE->theme->addblockposition = BLOCK_ADDBLOCK_POSITION_CUSTOM;
|
|
|
|
|
|
|
|
// Add course management if the user has the capabilities for it.
|
|
|
|
$coursecat = core_course_category::user_top();
|
2022-03-02 13:16:18 +07:00
|
|
|
$coursemanagemenu = [];
|
2022-03-17 18:39:14 +01:00
|
|
|
if ($coursecat && ($category = core_course_category::get_nearest_editable_subcategory($coursecat, ['create']))) {
|
2022-03-02 13:16:18 +07:00
|
|
|
// The user has the capability to create course.
|
|
|
|
$coursemanagemenu['newcourseurl'] = new moodle_url('/course/edit.php', ['category' => $category->id]);
|
|
|
|
}
|
2022-03-17 18:39:14 +01:00
|
|
|
if ($coursecat && ($category = core_course_category::get_nearest_editable_subcategory($coursecat, ['manage']))) {
|
2022-03-02 13:16:18 +07:00
|
|
|
// The user has the capability to manage the course category.
|
|
|
|
$coursemanagemenu['manageurl'] = new moodle_url('/course/management.php', ['categoryid' => $category->id]);
|
|
|
|
}
|
|
|
|
if (!empty($coursemanagemenu)) {
|
|
|
|
// Render the course management menu.
|
|
|
|
$PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $coursemanagemenu));
|
2021-10-21 12:13:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
|
|
|
|
if (core_userfeedback::should_display_reminder()) {
|
|
|
|
core_userfeedback::print_reminder_block();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->custom_block_region('content');
|
|
|
|
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
|
|
|
|
// Trigger dashboard has been viewed event.
|
|
|
|
$eventparams = array('context' => $context);
|
|
|
|
$event = \core\event\mycourses_viewed::create($eventparams);
|
|
|
|
$event->trigger();
|