/**
  * @throws coding_exception
  */
 public function __construct()
 {
     global $PAGE, $COURSE;
     // Page path blacklist for admin menu.
     $adminblockblacklist = ['/user/profile.php'];
     if (in_array(local::current_url_path(), $adminblockblacklist)) {
         return;
     }
     // Admin users always see the admin menu with the exception of blacklisted pages.
     // The admin menu shows up for other users if they are a teacher in the current course.
     if (!is_siteadmin()) {
         // We don't want students to see the admin menu ever.
         // Editing teachers are identified as people who can manage activities and non editing teachers as those who
         // can view the gradebook. As editing teachers are almost certain to also be able to view the gradebook, the
         // grader:view capability is checked first.
         $caps = ['gradereport/grader:view', 'moodle/course:manageactivities'];
         $canmanageacts = has_any_capability($caps, $PAGE->context);
         $isstudent = !$canmanageacts && !is_role_switched($COURSE->id);
         if ($isstudent) {
             return;
         }
     }
     if (!$PAGE->blocks->is_block_present('settings')) {
         // Throw error if on front page or course page.
         // (There are pages that don't have a settings block so we shouldn't throw an error on those pages).
         if (strpos($PAGE->pagetype, 'course-view') === 0 || $PAGE->pagetype === 'site-index') {
             debugging('Settings block was not found on this page', DEBUG_DEVELOPER);
         }
         return;
     }
     // Core Moodle API appears to be missing a 'get block by name' function.
     // Cycle through all regions and block instances until we find settings.
     foreach ($PAGE->blocks->get_regions() as $region) {
         foreach ($PAGE->blocks->get_blocks_for_region($region) as $block) {
             if (isset($block->instance) && $block->instance->blockname == 'settings') {
                 $this->instanceid = $block->instance->id;
                 break 2;
             }
         }
     }
     if (!has_capability('moodle/block:view', \context_block::instance($this->instanceid))) {
         return;
     }
     $this->output = true;
 }
 /**
  * Get page heading.
  *
  * @param string $tag
  * @return string
  */
 public function page_heading($tag = 'h1')
 {
     global $COURSE, $PAGE;
     $heading = $this->page->heading;
     if ($this->page->pagelayout == 'mypublic') {
         // For the user profile page message button we need to call 2.9 content_header.
         $heading = parent::context_header();
     } else {
         if ($COURSE->id != SITEID && stripos($heading, format_string($COURSE->fullname)) === 0) {
             // If we are on a course page which is not the site level course page.
             $courseurl = new moodle_url('/course/view.php', ['id' => $COURSE->id]);
             // Set heading to course fullname - ditch anything else that's in it.
             // This will make huge page headings like:
             // My course: View: Preferences: Grader report
             // simply show -
             // My course
             // This is intentional.
             $heading = $COURSE->fullname;
             $heading = html_writer::link($courseurl, $heading);
             $heading = html_writer::tag($tag, $heading);
         } else {
             // Default heading.
             $heading = html_writer::tag($tag, $heading);
         }
     }
     // If we are on the main page of a course, add the cover image selector.
     if ($COURSE->id != SITEID) {
         $courseviewpage = local::current_url_path() === '/course/view.php';
         if ($courseviewpage) {
             $heading .= $this->cover_image_selector();
         }
     }
     // For the front page we add the site strapline.
     if ($this->page->pagelayout == 'frontpage') {
         $heading .= '<p class="snap-site-description">' . format_string($this->page->theme->settings->subtitle) . '</p>';
     }
     if ($this->page->user_is_editing() && $this->page->pagelayout == 'frontpage') {
         $url = new moodle_url('/admin/settings.php', ['section' => 'themesettingsnap'], 'admin-fullname');
         $link = html_writer::link($url, get_string('changefullname', 'theme_snap'), ['class' => 'btn btn-default btn-sm']);
         $heading .= $link;
     }
     return $heading;
 }
 public function test_current_url_path()
 {
     global $PAGE;
     // Note, $CFG->wwwroot is set to http://www.example.com/moodle which is ideal for this test.
     // We want to make sure we can get the local path whilst moodle is in a subpath of the url.
     $this->resetAfterTest();
     $PAGE->set_url('/course/view.php', array('id' => 1));
     $urlpath = $PAGE->url->get_path();
     $expected = '/moodle/course/view.php';
     $this->assertEquals($expected, $urlpath);
     $localpath = local::current_url_path();
     $expected = '/course/view.php';
     $this->assertEquals($expected, $localpath);
 }
Example #4
0
    $url = new moodle_url('/admin/settings.php', ['section' => 'themesettingsnap'], 'admin-poster');
    echo $OUTPUT->cover_image_selector();
}
?>
</div>

<section id="region-main">
<?php 
echo $OUTPUT->course_content_header();
// Ensure edit blocks button is only shown for appropriate pages.
$hasadminbutton = stripos($PAGE->button, '"adminedit"') || stripos($PAGE->button, '"edit"');
if ($hasadminbutton) {
    // List paths to black list for 'turn editting on' button here.
    // Note, to use regexs start and end with a pipe symbol - e.g. |^/report/| .
    $editbuttonblacklist = array('/comment/', '/cohort/index.php', '|^/report/|', '|^/admin/|', '|^/mod/data/|', '/tag/manage.php', '/grade/edit/scale/index.php', '/outcome/admin.php', '/mod/assign/adminmanageplugins.php', '/message/defaultoutputs.php', '/theme/index.php', '/user/editadvanced.php', '/user/profile/index.php', '/mnet/service/enrol/index.php', '/local/mrooms/view.php');
    $pagepath = local::current_url_path();
    foreach ($editbuttonblacklist as $blacklisted) {
        if ($blacklisted[0] == '|' && $blacklisted[strlen($blacklisted) - 1] == '|') {
            // Use regex to determine blacklisting.
            if (preg_match($blacklisted, $pagepath) === 1) {
                // This url path is blacklisted, stop button from being displayed.
                $PAGE->set_button('');
            }
        } else {
            if ($pagepath == $blacklisted) {
                // This url path is blacklisted, stop button from being displayed.
                $PAGE->set_button('');
            }
        }
    }
}
Example #5
0
 /**
  * Javascript required by both standard header layout and flexpage layout
  *
  * @return void
  */
 public static function page_requires_js()
 {
     global $CFG, $PAGE, $COURSE, $USER;
     $PAGE->requires->jquery();
     $PAGE->requires->strings_for_js(array('close', 'debugerrors', 'problemsfound', 'error:coverimageexceedsmaxbytes', 'error:coverimageresolutionlow', 'forumtopic', 'forumauthor', 'forumpicturegroup', 'forumreplies', 'forumlastpost', 'hiddencoursestoggle', 'loading', 'more', 'moving', 'movingcount', 'movehere', 'movefailed', 'movingdropsectionhelp', 'movingstartedhelp'), 'theme_snap');
     $PAGE->requires->strings_for_js(['ok', 'cancel'], 'moodle');
     $PAGE->requires->strings_for_js(['printbook'], 'booktool_print');
     // Are we viewing /course/view.php - note, this is different from just checking the page type.
     // We only ever want to load course.js when on site page or view.php - no point in loading it when on
     // course settings page, etc.
     $courseviewpage = local::current_url_path() === '/course/view.php';
     $pagehascoursecontent = $PAGE->pagetype === 'site-index' || $courseviewpage;
     $cancomplete = isloggedin() && !isguestuser();
     $unavailablesections = [];
     $unavailablemods = [];
     if ($cancomplete) {
         $completioninfo = new \completion_info($COURSE);
         if ($completioninfo->is_enabled()) {
             $modinfo = get_fast_modinfo($COURSE);
             $sections = $modinfo->get_section_info_all();
             foreach ($sections as $number => $section) {
                 $ci = new \core_availability\info_section($section);
                 $information = '';
                 if (!$ci->is_available($information, true)) {
                     $unavailablesections[] = $number;
                 }
             }
             foreach ($modinfo as $mod) {
                 $ci = new \core_availability\info_module($mod);
                 if (!$ci->is_available($information, true)) {
                     $unavailablemods[] = $mod->id;
                 }
             }
         }
     }
     list($unavailablesections, $unavailablemods) = local::conditionally_unavailable_elements($COURSE);
     $coursevars = (object) ['id' => $COURSE->id, 'shortname' => $COURSE->shortname, 'contextid' => $PAGE->context->id, 'ajaxurl' => '/course/rest.php', 'unavailablesections' => $unavailablesections, 'unavailablemods' => $unavailablemods, 'enablecompletion' => $COURSE->enablecompletion];
     $initvars = [$coursevars, $pagehascoursecontent, get_max_upload_file_size($CFG->maxbytes)];
     $PAGE->requires->js_call_amd('theme_snap/snap', 'snapInit', $initvars);
     // Does the page have editable course content?
     if ($pagehascoursecontent && $PAGE->user_allowed_editing()) {
         $canmanageacts = has_capability('moodle/course:manageactivities', context_course::instance($COURSE->id));
         if ($canmanageacts && empty($USER->editing)) {
             $modinfo = get_fast_modinfo($COURSE);
             $modnamesused = $modinfo->get_used_module_names();
             // Temporarily change edit mode to on for course ajax to be included.
             $USER->editing = true;
             self::include_course_ajax($COURSE, $modnamesused);
             $USER->editing = false;
         }
     }
 }