. /** * 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 * @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->has_secondary_navigation_setter(false); $PAGE->set_pagetype('my-index'); $PAGE->blocks->add_region('content'); $PAGE->set_subpage($currentpage->id); $PAGE->set_title(get_string('mycourses')); $PAGE->set_heading(get_string('mycourses')); // 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(); if ($coursecat->can_create_course() || $coursecat->has_manage_capability()) { $data = [ 'newcourseurl' => new moodle_url('/course/edit.php', ['category' => $coursecat->id]), 'manageurl' => new moodle_url('/course/management.php', ['categoryid' => $coursecat->id]), ]; $PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $data)); } 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();