From 3a13783b048702a445008e7adf625bc934b603ee Mon Sep 17 00:00:00 2001 From: Alexander Bias <alexander.bias@uni-ulm.de> Date: Tue, 17 Aug 2021 13:49:01 +0200 Subject: [PATCH] Bugfix: In-course settings have been shown below course information banners instead of above them. --- CHANGES.md | 1 + classes/output/core_renderer.php | 265 +------------------------------ layout/columns2.php | 7 + locallib.php | 251 +++++++++++++++++++++++++++++ templates/columns2.mustache | 1 + 5 files changed, 265 insertions(+), 260 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0375fc2..807c799 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2021-08-16 - Bugfix: In-course settings have been shown below course information banners instead of above them. * 2021-08-16 - Improvement: Add in-course settings only to HTML tree of the setting is enabled. * 2021-08-16 - Adjust activity_settings_incourse.mustache template based on changes in settings_link_page.mustache * 2021-08-16 - Improvement: Adjusted tab appearance for in-course settings. diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php index 6e842a1..6596d86 100644 --- a/classes/output/core_renderer.php +++ b/classes/output/core_renderer.php @@ -118,21 +118,19 @@ class core_renderer extends \core_renderer { /** - * Override to display switched role information beneath the course header instead of the user menu. - * We change this because the switch role function is course related and therefore it should be placed in the course context. - * - * MODIFICATION: This renderer function is copied and modified from /lib/outputrenderers.php - * * Wrapper for header elements. * + * KIZ MODIFICATION: This renderer function is copied and modified from /lib/outputrenderers.php + * * @return string HTML to display the main header. */ public function full_header() { // MODIFICATION START. - global $USER, $COURSE, $CFG; + global $USER, $COURSE; // MODIFICATION END. - if ($this->page->include_region_main_settings_in_header_actions() && !$this->page->blocks->is_block_present('settings')) { + if ($this->page->include_region_main_settings_in_header_actions() && + !$this->page->blocks->is_block_present('settings')) { // Only include the region main settings if the page has requested it and it doesn't already have // the settings block on it. The region main settings are included in the settings block and // duplicating the content causes behat failures. @@ -191,262 +189,9 @@ class core_renderer extends \core_renderer { // @codingStandardsIgnoreEnd $header->courseheader = $this->course_header(); $header->headeractions = $this->page->get_header_actions(); - // MODIFICATION START: - // Change this to add the result in the html variable to be able to add further features below the header. - $html = $this->render_from_template('core/full_header', $header); - // MODIFICATION END. - // @codingStandardsIgnoreStart - /* ORIGINAL START return $this->render_from_template('core/full_header', $header); - ORIGINAL END. */ - // @codingStandardsIgnoreEnd - - // MODIFICATION START: - // If the setting showhintcoursehidden is set, the visibility of the course is hidden and - // a hint for the visibility will be shown. - if (get_config('theme_boost_campus', 'showhintcoursehidden') == 'yes' - && has_capability('theme/boost_campus:viewhintinhiddencourse', \context_course::instance($COURSE->id)) - && $this->page->has_set_url() - && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE) - && $COURSE->visible == false) { - $html .= html_writer::start_tag('div', array('class' => 'course-hidden-infobox alert alert-warning')); - $html .= html_writer::start_tag('div', array('class' => 'media')); - $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); - $html .= html_writer::tag('i', null, array('class' => 'fa fa-exclamation-circle fa-3x')); - $html .= html_writer::end_tag('div'); - $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); - $html .= get_string('showhintcoursehiddengeneral', 'theme_boost_campus', $COURSE->id); - // If the user has the capability to change the course settings, an additional link to the course settings is shown. - if (has_capability('moodle/course:update', context_course::instance($COURSE->id))) { - $html .= html_writer::tag('div', get_string('showhintcoursehiddensettingslink', - 'theme_boost_campus', array('url' => $CFG->wwwroot.'/course/edit.php?id='. $COURSE->id))); - } - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - } - // MODIFICATION END. - - // MODIFICATION START: - // If the setting showhintcourseguestaccess is set, a hint for users that view the course with guest access is shown. - // We also check that the user did not switch the role. This is a special case for roles that can fully access the course - // without being enrolled. A role switch would show the guest access hint additionally in that case and this is not - // intended. - if (get_config('theme_boost_campus', 'showhintcourseguestaccess') == 'yes' - && is_guest(\context_course::instance($COURSE->id), $USER->id) - && $this->page->has_set_url() - && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE) - && !is_role_switched($COURSE->id)) { - $html .= html_writer::start_tag('div', array('class' => 'course-guestaccess-infobox alert alert-warning')); - $html .= html_writer::start_tag('div', array('class' => 'media')); - $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); - $html .= html_writer::tag('i', null, array('class' => 'fa fa-exclamation-circle fa-3x')); - $html .= html_writer::end_tag('div'); - $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); - $html .= get_string('showhintcourseguestaccessgeneral', 'theme_boost_campus', - array('role' => role_get_name(get_guest_role()))); - $html .= theme_boost_campus_get_course_guest_access_hint($COURSE->id); - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - } - // MODIFICATION END. - - // MODIFICATION START: - // If the setting showhintcourseselfenrol is set, a hint for users is shown that the course allows unrestricted self - // enrolment. This hint is only shown if the course is visible, the self enrolment is visible and if the user has the - // capability "theme/boost_campus:viewhintcourseselfenrol". - if (get_config('theme_boost_campus', 'showhintcourseselfenrol') == 'yes' - && has_capability('theme/boost_campus:viewhintcourseselfenrol', \context_course::instance($COURSE->id)) - && $this->page->has_set_url() - && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE) - && $COURSE->visible == true) { - // Get the active enrol instances for this course. - $enrolinstances = enrol_get_instances($COURSE->id, true); - // Prepare to remember when self enrolment is / will be possible. - $selfenrolmentpossiblecurrently = false; - $selfenrolmentpossiblefuture = false; - foreach ($enrolinstances as $instance) { - // Check if unrestricted self enrolment is possible currently or in the future. - $now = (new \DateTime("now", \core_date::get_server_timezone_object()))->getTimestamp(); - if ($instance->enrol == 'self' && empty($instance->password) && $instance->customint6 == 1 && - (empty($instance->enrolenddate) || $instance->enrolenddate > $now)) { - - // Build enrol instance object with all necessary information for rendering the note later. - $instanceobject = new stdClass(); - - // Remember instance name. - if (empty($instance->name)) { - $instanceobject->name = get_string('pluginname', 'enrol_self') . - " (" . get_string('defaultcoursestudent', 'core') . ")"; - } else { - $instanceobject->name = $instance->name; - } - - // Remember type of unrestrictedness. - if (empty($instance->enrolenddate) && empty($instance->enrolstartdate)) { - $instanceobject->unrestrictedness = 'unlimited'; - $selfenrolmentpossiblecurrently = true; - } else if (empty($instance->enrolstartdate) && - !empty($instance->enrolenddate) && $instance->enrolenddate > $now) { - $instanceobject->unrestrictedness = 'until'; - $selfenrolmentpossiblecurrently = true; - } else if (empty($instance->enrolenddate) && - !empty($instance->enrolstartdate) && $instance->enrolstartdate > $now) { - $instanceobject->unrestrictedness = 'from'; - $selfenrolmentpossiblefuture = true; - } else if (empty($instance->enrolenddate) && - !empty($instance->enrolstartdate) && $instance->enrolstartdate <= $now) { - $instanceobject->unrestrictedness = 'since'; - $selfenrolmentpossiblecurrently = true; - } else if (!empty($instance->enrolstartdate) && $instance->enrolstartdate > $now && - !empty($instance->enrolenddate) && $instance->enrolenddate > $now) { - $instanceobject->unrestrictedness = 'fromuntil'; - $selfenrolmentpossiblefuture = true; - } else if (!empty($instance->enrolstartdate) && $instance->enrolstartdate <= $now && - !empty($instance->enrolenddate) && $instance->enrolenddate > $now) { - $instanceobject->unrestrictedness = 'sinceuntil'; - $selfenrolmentpossiblecurrently = true; - } else { - // This should not happen, thus continue to next instance. - continue; - } - - // Remember enrol start date. - if (!empty($instance->enrolstartdate)) { - $instanceobject->startdate = $instance->enrolstartdate; - } else { - $instanceobject->startdate = null; - } - - // Remember enrol end date. - if (!empty($instance->enrolenddate)) { - $instanceobject->enddate = $instance->enrolenddate; - } else { - $instanceobject->enddate = null; - } - - // Remember this instance. - $selfenrolinstances[$instance->id] = $instanceobject; - } - } - - // If there is at least one unrestricted enrolment instance, - // show the hint with information about each unrestricted active self enrolment in the course. - if (!empty($selfenrolinstances) && - ($selfenrolmentpossiblecurrently == true || $selfenrolmentpossiblefuture == true)) { - // Start hint box. - $html .= html_writer::start_tag('div', array('class' => 'course-selfenrol-infobox alert alert-info')); - $html .= html_writer::start_tag('div', array('class' => 'media')); - $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); - $html .= html_writer::tag('i', null, array('class' => 'fa fa-sign-in fa-3x')); - $html .= html_writer::end_tag('div'); - $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); - - // Show the start of the hint depending on the fact if enrolment is already possible currently or - // will be in the future. - if ($selfenrolmentpossiblecurrently == true) { - $html .= get_string('showhintcourseselfenrolstartcurrently', 'theme_boost_campus'); - } else if ($selfenrolmentpossiblefuture == true) { - $html .= get_string('showhintcourseselfenrolstartfuture', 'theme_boost_campus'); - } - $html .= html_writer::empty_tag('br'); - - // Iterate over all enrolment instances to output the details. - foreach ($selfenrolinstances as $selfenrolinstanceid => $selfenrolinstanceobject) { - // If the user has the capability to config self enrolments, enrich the instance name with the settings link. - if (has_capability('enrol/self:config', \context_course::instance($COURSE->id))) { - $url = new moodle_url('/enrol/editinstance.php', array('courseid' => $COURSE->id, - 'id' => $selfenrolinstanceid, 'type' => 'self')); - $selfenrolinstanceobject->name = html_writer::link($url, $selfenrolinstanceobject->name); - } - - // Show the enrolment instance information depending on the instance configuration. - if ($selfenrolinstanceobject->unrestrictedness == 'unlimited') { - $html .= get_string('showhintcourseselfenrolunlimited', 'theme_boost_campus', - array('name' => $selfenrolinstanceobject->name)); - } else if ($selfenrolinstanceobject->unrestrictedness == 'until') { - $html .= get_string('showhintcourseselfenroluntil', 'theme_boost_campus', - array('name' => $selfenrolinstanceobject->name, - 'until' => userdate($selfenrolinstanceobject->enddate))); - } else if ($selfenrolinstanceobject->unrestrictedness == 'from') { - $html .= get_string('showhintcourseselfenrolfrom', 'theme_boost_campus', - array('name' => $selfenrolinstanceobject->name, - 'from' => userdate($selfenrolinstanceobject->startdate))); - } else if ($selfenrolinstanceobject->unrestrictedness == 'since') { - $html .= get_string('showhintcourseselfenrolsince', 'theme_boost_campus', - array('name' => $selfenrolinstanceobject->name, - 'since' => userdate($selfenrolinstanceobject->startdate))); - } else if ($selfenrolinstanceobject->unrestrictedness == 'fromuntil') { - $html .= get_string('showhintcourseselfenrolfromuntil', 'theme_boost_campus', - array('name' => $selfenrolinstanceobject->name, - 'until' => userdate($selfenrolinstanceobject->enddate), - 'from' => userdate($selfenrolinstanceobject->startdate))); - } else if ($selfenrolinstanceobject->unrestrictedness == 'sinceuntil') { - $html .= get_string('showhintcourseselfenrolsinceuntil', 'theme_boost_campus', - array('name' => $selfenrolinstanceobject->name, - 'until' => userdate($selfenrolinstanceobject->enddate), - 'since' => userdate($selfenrolinstanceobject->startdate))); - } - - // Add a trailing space to separate this instance from the next one. - $html .= ' '; - } - - // If the user has the capability to config self enrolments, add the call for action. - if (has_capability('enrol/self:config', \context_course::instance($COURSE->id))) { - $html .= html_writer::empty_tag('br'); - $html .= get_string('showhintcourseselfenrolinstancecallforaction', 'theme_boost_campus'); - } - - // End hint box. - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - } - } - // MODIFICATION END. - - // MODIFICATION START. - // Only use this if setting 'showswitchedroleincourse' is active. - if (get_config('theme_boost_campus', 'showswitchedroleincourse') === 'yes') { - // Check if the user did a role switch. - // If not, adding this section would make no sense and, even worse, - // user_get_user_navigation_info() will throw an exception due to the missing user object. - if (is_role_switched($COURSE->id)) { - // Get the role name switched to. - $opts = \user_get_user_navigation_info($USER, $this->page); - $role = $opts->metadata['rolename']; - // Get the URL to switch back (normal role). - $url = new moodle_url('/course/switchrole.php', - array('id' => $COURSE->id, 'sesskey' => sesskey(), 'switchrole' => 0, - 'returnurl' => $this->page->url->out_as_local_url(false))); - $html .= html_writer::start_tag('div', array('class' => 'switched-role-infobox alert alert-info')); - $html .= html_writer::start_tag('div', array('class' => 'media')); - $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); - $html .= html_writer::tag('i', null, array('class' => 'fa fa-user-circle fa-3x')); - $html .= html_writer::end_tag('div'); - $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); - $html .= html_writer::start_tag('div'); - $html .= get_string('switchedroleto', 'theme_boost_campus'); - // Give this a span to be able to address via CSS. - $html .= html_writer::tag('span', $role, array('class' => 'switched-role')); - $html .= html_writer::end_tag('div'); - // Return to normal role link. - $html .= html_writer::start_tag('div'); - $html .= html_writer::tag('a', get_string('switchrolereturn', 'core'), - array('class' => 'switched-role-backlink', 'href' => $url)); - $html .= html_writer::end_tag('div'); // Return to normal role link: end div. - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - $html .= html_writer::end_tag('div'); - } - } - // MODIFICATION END. - return $html; } - /** * Override to display course settings on every course site for permanent access * diff --git a/layout/columns2.php b/layout/columns2.php index ec9fb75..173b5f8 100644 --- a/layout/columns2.php +++ b/layout/columns2.php @@ -160,6 +160,13 @@ if ($timedibenable) { } // MODIFICATION END. +// MODIFICATION START: Get and use the course page information banners HTML code, if any course page hints are configured. +$coursepageinformationbannershtml = theme_boost_campus_get_course_information_banners(); +if ($coursepageinformationbannershtml) { + $templatecontext['coursepageinformationbanners'] = $coursepageinformationbannershtml; +} +// MODIFICATION END. + $nav = $PAGE->flatnav; // MODIDFICATION START. // Use the returned value from theme_boost_campus_get_modified_flatnav_defaulthomepageontop as the template context. diff --git a/locallib.php b/locallib.php index f74eaef..c0ad08a 100644 --- a/locallib.php +++ b/locallib.php @@ -532,3 +532,254 @@ function theme_boost_campus_show_timed_banner_on_selected_page($now, $timedibsho return $timedinfobannershowonselectedpage; } + +/** + * Build the course page information banners HTML code. + * This function evaluates and composes all information banners which may appear on a course page below the full header. + * + * @return string. + */ +function theme_boost_campus_get_course_information_banners() { + global $CFG, $COURSE, $PAGE, $USER; + + // Initialize HTML code. + $html = ''; + + // If the setting showhintcoursehidden is set, the visibility of the course is hidden and + // a hint for the visibility will be shown. + if (get_config('theme_boost_campus', 'showhintcoursehidden') == 'yes' + && has_capability('theme/boost_campus:viewhintinhiddencourse', \context_course::instance($COURSE->id)) + && $PAGE->has_set_url() + && $PAGE->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE) + && $COURSE->visible == false) { + $html .= html_writer::start_tag('div', array('class' => 'course-hidden-infobox alert alert-warning')); + $html .= html_writer::start_tag('div', array('class' => 'media')); + $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); + $html .= html_writer::tag('i', null, array('class' => 'fa fa-exclamation-circle fa-3x')); + $html .= html_writer::end_tag('div'); + $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); + $html .= get_string('showhintcoursehiddengeneral', 'theme_boost_campus', $COURSE->id); + // If the user has the capability to change the course settings, an additional link to the course settings is shown. + if (has_capability('moodle/course:update', context_course::instance($COURSE->id))) { + $html .= html_writer::tag('div', get_string('showhintcoursehiddensettingslink', + 'theme_boost_campus', array('url' => $CFG->wwwroot.'/course/edit.php?id='. $COURSE->id))); + } + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + } + + // If the setting showhintcourseguestaccess is set, a hint for users that view the course with guest access is shown. + // We also check that the user did not switch the role. This is a special case for roles that can fully access the course + // without being enrolled. A role switch would show the guest access hint additionally in that case and this is not + // intended. + if (get_config('theme_boost_campus', 'showhintcourseguestaccess') == 'yes' + && is_guest(\context_course::instance($COURSE->id), $USER->id) + && $PAGE->has_set_url() + && $PAGE->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE) + && !is_role_switched($COURSE->id)) { + $html .= html_writer::start_tag('div', array('class' => 'course-guestaccess-infobox alert alert-warning')); + $html .= html_writer::start_tag('div', array('class' => 'media')); + $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); + $html .= html_writer::tag('i', null, array('class' => 'fa fa-exclamation-circle fa-3x')); + $html .= html_writer::end_tag('div'); + $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); + $html .= get_string('showhintcourseguestaccessgeneral', 'theme_boost_campus', + array('role' => role_get_name(get_guest_role()))); + $html .= theme_boost_campus_get_course_guest_access_hint($COURSE->id); + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + } + + // If the setting showhintcourseselfenrol is set, a hint for users is shown that the course allows unrestricted self + // enrolment. This hint is only shown if the course is visible, the self enrolment is visible and if the user has the + // capability "theme/boost_campus:viewhintcourseselfenrol". + if (get_config('theme_boost_campus', 'showhintcourseselfenrol') == 'yes' + && has_capability('theme/boost_campus:viewhintcourseselfenrol', \context_course::instance($COURSE->id)) + && $PAGE->has_set_url() + && $PAGE->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE) + && $COURSE->visible == true) { + // Get the active enrol instances for this course. + $enrolinstances = enrol_get_instances($COURSE->id, true); + // Prepare to remember when self enrolment is / will be possible. + $selfenrolmentpossiblecurrently = false; + $selfenrolmentpossiblefuture = false; + foreach ($enrolinstances as $instance) { + // Check if unrestricted self enrolment is possible currently or in the future. + $now = (new \DateTime("now", \core_date::get_server_timezone_object()))->getTimestamp(); + if ($instance->enrol == 'self' && empty($instance->password) && $instance->customint6 == 1 && + (empty($instance->enrolenddate) || $instance->enrolenddate > $now)) { + + // Build enrol instance object with all necessary information for rendering the note later. + $instanceobject = new stdClass(); + + // Remember instance name. + if (empty($instance->name)) { + $instanceobject->name = get_string('pluginname', 'enrol_self') . + " (" . get_string('defaultcoursestudent', 'core') . ")"; + } else { + $instanceobject->name = $instance->name; + } + + // Remember type of unrestrictedness. + if (empty($instance->enrolenddate) && empty($instance->enrolstartdate)) { + $instanceobject->unrestrictedness = 'unlimited'; + $selfenrolmentpossiblecurrently = true; + } else if (empty($instance->enrolstartdate) && + !empty($instance->enrolenddate) && $instance->enrolenddate > $now) { + $instanceobject->unrestrictedness = 'until'; + $selfenrolmentpossiblecurrently = true; + } else if (empty($instance->enrolenddate) && + !empty($instance->enrolstartdate) && $instance->enrolstartdate > $now) { + $instanceobject->unrestrictedness = 'from'; + $selfenrolmentpossiblefuture = true; + } else if (empty($instance->enrolenddate) && + !empty($instance->enrolstartdate) && $instance->enrolstartdate <= $now) { + $instanceobject->unrestrictedness = 'since'; + $selfenrolmentpossiblecurrently = true; + } else if (!empty($instance->enrolstartdate) && $instance->enrolstartdate > $now && + !empty($instance->enrolenddate) && $instance->enrolenddate > $now) { + $instanceobject->unrestrictedness = 'fromuntil'; + $selfenrolmentpossiblefuture = true; + } else if (!empty($instance->enrolstartdate) && $instance->enrolstartdate <= $now && + !empty($instance->enrolenddate) && $instance->enrolenddate > $now) { + $instanceobject->unrestrictedness = 'sinceuntil'; + $selfenrolmentpossiblecurrently = true; + } else { + // This should not happen, thus continue to next instance. + continue; + } + + // Remember enrol start date. + if (!empty($instance->enrolstartdate)) { + $instanceobject->startdate = $instance->enrolstartdate; + } else { + $instanceobject->startdate = null; + } + + // Remember enrol end date. + if (!empty($instance->enrolenddate)) { + $instanceobject->enddate = $instance->enrolenddate; + } else { + $instanceobject->enddate = null; + } + + // Remember this instance. + $selfenrolinstances[$instance->id] = $instanceobject; + } + } + + // If there is at least one unrestricted enrolment instance, + // show the hint with information about each unrestricted active self enrolment in the course. + if (!empty($selfenrolinstances) && + ($selfenrolmentpossiblecurrently == true || $selfenrolmentpossiblefuture == true)) { + // Start hint box. + $html .= html_writer::start_tag('div', array('class' => 'course-selfenrol-infobox alert alert-info')); + $html .= html_writer::start_tag('div', array('class' => 'media')); + $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); + $html .= html_writer::tag('i', null, array('class' => 'fa fa-sign-in fa-3x')); + $html .= html_writer::end_tag('div'); + $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); + + // Show the start of the hint depending on the fact if enrolment is already possible currently or + // will be in the future. + if ($selfenrolmentpossiblecurrently == true) { + $html .= get_string('showhintcourseselfenrolstartcurrently', 'theme_boost_campus'); + } else if ($selfenrolmentpossiblefuture == true) { + $html .= get_string('showhintcourseselfenrolstartfuture', 'theme_boost_campus'); + } + $html .= html_writer::empty_tag('br'); + + // Iterate over all enrolment instances to output the details. + foreach ($selfenrolinstances as $selfenrolinstanceid => $selfenrolinstanceobject) { + // If the user has the capability to config self enrolments, enrich the instance name with the settings link. + if (has_capability('enrol/self:config', \context_course::instance($COURSE->id))) { + $url = new moodle_url('/enrol/editinstance.php', array('courseid' => $COURSE->id, + 'id' => $selfenrolinstanceid, 'type' => 'self')); + $selfenrolinstanceobject->name = html_writer::link($url, $selfenrolinstanceobject->name); + } + + // Show the enrolment instance information depending on the instance configuration. + if ($selfenrolinstanceobject->unrestrictedness == 'unlimited') { + $html .= get_string('showhintcourseselfenrolunlimited', 'theme_boost_campus', + array('name' => $selfenrolinstanceobject->name)); + } else if ($selfenrolinstanceobject->unrestrictedness == 'until') { + $html .= get_string('showhintcourseselfenroluntil', 'theme_boost_campus', + array('name' => $selfenrolinstanceobject->name, + 'until' => userdate($selfenrolinstanceobject->enddate))); + } else if ($selfenrolinstanceobject->unrestrictedness == 'from') { + $html .= get_string('showhintcourseselfenrolfrom', 'theme_boost_campus', + array('name' => $selfenrolinstanceobject->name, + 'from' => userdate($selfenrolinstanceobject->startdate))); + } else if ($selfenrolinstanceobject->unrestrictedness == 'since') { + $html .= get_string('showhintcourseselfenrolsince', 'theme_boost_campus', + array('name' => $selfenrolinstanceobject->name, + 'since' => userdate($selfenrolinstanceobject->startdate))); + } else if ($selfenrolinstanceobject->unrestrictedness == 'fromuntil') { + $html .= get_string('showhintcourseselfenrolfromuntil', 'theme_boost_campus', + array('name' => $selfenrolinstanceobject->name, + 'until' => userdate($selfenrolinstanceobject->enddate), + 'from' => userdate($selfenrolinstanceobject->startdate))); + } else if ($selfenrolinstanceobject->unrestrictedness == 'sinceuntil') { + $html .= get_string('showhintcourseselfenrolsinceuntil', 'theme_boost_campus', + array('name' => $selfenrolinstanceobject->name, + 'until' => userdate($selfenrolinstanceobject->enddate), + 'since' => userdate($selfenrolinstanceobject->startdate))); + } + + // Add a trailing space to separate this instance from the next one. + $html .= ' '; + } + + // If the user has the capability to config self enrolments, add the call for action. + if (has_capability('enrol/self:config', \context_course::instance($COURSE->id))) { + $html .= html_writer::empty_tag('br'); + $html .= get_string('showhintcourseselfenrolinstancecallforaction', 'theme_boost_campus'); + } + + // End hint box. + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + } + } + + // Only use this if setting 'showswitchedroleincourse' is active. + if (get_config('theme_boost_campus', 'showswitchedroleincourse') === 'yes') { + // Check if the user did a role switch. + // If not, adding this section would make no sense and, even worse, + // user_get_user_navigation_info() will throw an exception due to the missing user object. + if (is_role_switched($COURSE->id)) { + // Get the role name switched to. + $opts = \user_get_user_navigation_info($USER, $PAGE); + $role = $opts->metadata['rolename']; + // Get the URL to switch back (normal role). + $url = new moodle_url('/course/switchrole.php', + array('id' => $COURSE->id, 'sesskey' => sesskey(), 'switchrole' => 0, + 'returnurl' => $PAGE->url->out_as_local_url(false))); + $html .= html_writer::start_tag('div', array('class' => 'switched-role-infobox alert alert-info')); + $html .= html_writer::start_tag('div', array('class' => 'media')); + $html .= html_writer::start_tag('div', array('class' => 'mr-3 icon-size-5')); + $html .= html_writer::tag('i', null, array('class' => 'fa fa-user-circle fa-3x')); + $html .= html_writer::end_tag('div'); + $html .= html_writer::start_tag('div', array('class' => 'media-body align-self-center')); + $html .= html_writer::start_tag('div'); + $html .= get_string('switchedroleto', 'theme_boost_campus'); + // Give this a span to be able to address via CSS. + $html .= html_writer::tag('span', $role, array('class' => 'switched-role')); + $html .= html_writer::end_tag('div'); + // Return to normal role link. + $html .= html_writer::start_tag('div'); + $html .= html_writer::tag('a', get_string('switchrolereturn', 'core'), + array('class' => 'switched-role-backlink', 'href' => $url)); + $html .= html_writer::end_tag('div'); // Return to normal role link: end div. + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + $html .= html_writer::end_tag('div'); + } + } + + // Return HTML code. + return $html; +} diff --git a/templates/columns2.mustache b/templates/columns2.mustache index c862412..3915a17 100644 --- a/templates/columns2.mustache +++ b/templates/columns2.mustache @@ -124,6 +124,7 @@ <div> {{{ output.region_main_settings_menu }}} </div> </div> {{/hasregionmainsettingsmenu}} + {{{coursepageinformationbanners}}} <section id="region-main" {{#hasblocks}}class="has-blocks mb-3"{{/hasblocks}} aria-label="{{#str}}content{{/str}}"> {{#hasregionmainsettingsmenu}} -- GitLab