ohwhatalovelyday

Untitled

Sep 10th, 2023
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.16 KB | None | 0 0
  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. /**
  18.  * Itam page.
  19.  *
  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
  23.  *
  24.  * @package    core
  25.  * @subpackage my
  26.  * @copyright  2023 Lisa Plastinina
  27.  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28.  */
  29.  
  30. require_once(__DIR__ . '/../config.php');
  31. require_once($CFG->dirroot . '/my/lib.php');
  32. require_once($CFG->dirroot . '/course/lib.php');
  33. require_once($CFG->dirroot . '/course/renderer.php');
  34.  
  35. redirect_if_major_upgrade_required();
  36.  
  37. require_login();
  38.  
  39. $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
  40. if ($hassiteconfig && moodle_needs_upgrading()) {
  41.     redirect(new moodle_url('/admin/index.php'));
  42. }
  43.  
  44. $context = context_system::instance();
  45.  
  46. // Get the My Moodle page info.  Should always return something unless the database is broken.
  47. if (!$currentpage = my_get_page(null, MY_PAGE_PUBLIC, MY_PAGE_COURSES)) {
  48.     throw new Exception('mymoodlesetup');
  49. }
  50.  
  51.  
  52. // Start setting up the page.
  53. $PAGE->set_context($context);
  54. $PAGE->set_url('/my/itam.php');
  55. $PAGE->add_body_classes(['limitedwidth', 'page-mycourses']);
  56. $PAGE->set_pagelayout('mycourses');
  57. echo "<body style='background-color:pink'>";
  58.  
  59. $PAGE->set_pagetype('my-index');
  60. $PAGE->blocks->add_region('content');
  61. $PAGE->set_subpage($currentpage->id);
  62. $PAGE->set_title('ITAM');
  63. $PAGE->set_heading("ITAM");
  64.  
  65. // No blocks can be edited on this page (including by managers/admins) because:
  66. // - Course overview is a fixed item on the page and cannot be moved/removed.
  67. // - We do not want new blocks on the page.
  68. // - Only global blocks (if any) should be visible on the site panel, and cannot be moved int othe centre pane.
  69. $PAGE->force_lock_all_blocks();
  70.  
  71. // Force the add block out of the default area.
  72. $PAGE->theme->addblockposition  = BLOCK_ADDBLOCK_POSITION_CUSTOM;
  73.  
  74. // Add course management if the user has the capabilities for it.
  75. $coursecat = core_course_category::user_top();
  76. $coursemanagemenu = [];
  77. if ($coursecat && ($category = core_course_category::get_nearest_editable_subcategory($coursecat, ['create']))) {
  78.     // The user has the capability to create course.
  79.     $coursemanagemenu['newcourseurl'] = new moodle_url('/course/edit.php', ['category' => $category->id]);
  80. }
  81. if ($coursecat && ($category = core_course_category::get_nearest_editable_subcategory($coursecat, ['manage']))) {
  82.     // The user has the capability to manage the course category.
  83.     $coursemanagemenu['manageurl'] = new moodle_url('/course/management.php', ['categoryid' => $category->id]);
  84. }
  85. if ($coursecat) {
  86.     $category = core_course_category::get_nearest_editable_subcategory($coursecat, ['moodle/course:request']);
  87.     if ($category && $category->can_request_course()) {
  88.         $coursemanagemenu['courserequesturl'] = new moodle_url('/course/request.php', ['categoryid' => $category->id]);
  89.  
  90.     }
  91. }
  92. if (!empty($coursemanagemenu)) {
  93.     // Render the course management menu.
  94.     $PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $coursemanagemenu));
  95. }
  96.  
  97. echo $OUTPUT->header();
  98.  
  99. if (core_userfeedback::should_display_reminder()) {
  100.     core_userfeedback::print_reminder_block();
  101. }
  102.  
  103. echo $OUTPUT->custom_block_region('content');
  104.  
  105. echo $OUTPUT->footer();
  106.  
  107. // Trigger dashboard has been viewed event.
  108. $eventparams = array('context' => $context);
  109. $event = \core\event\mycourses_viewed::create($eventparams);
  110. $event->trigger();
Advertisement
Add Comment
Please, Sign In to add comment