From 7a529cc85872d6be7beaedb8de16d698c9ffd307 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Wed, 21 Jul 2021 19:50:51 +1000 Subject: [PATCH] MDL-71952 calendar: Make breadcrumb consistent within calendar pages --- calendar/export.php | 44 ++++++++++++++++++------------ calendar/import.php | 47 ++++++++++++++++++++------------ calendar/managesubscriptions.php | 21 +++++++++++--- calendar/view.php | 8 ++++++ 4 files changed, 80 insertions(+), 40 deletions(-) diff --git a/calendar/export.php b/calendar/export.php index ea32f29df62..bfa8ca4b0a5 100644 --- a/calendar/export.php +++ b/calendar/export.php @@ -55,6 +55,7 @@ if (empty($CFG->enablecalendarexport)) { } $courseid = optional_param('course', SITEID, PARAM_INT); +$categoryid = optional_param('category', null, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA); $day = optional_param('cal_d', 0, PARAM_INT); $mon = optional_param('cal_m', 0, PARAM_INT); @@ -76,32 +77,44 @@ if (!empty($day) && !empty($mon) && !empty($year)) { $time = time(); } +$url = new moodle_url('/calendar/export.php', array('time' => $time)); +$managesubscriptionsurl = new moodle_url('/calendar/managesubscriptions.php'); + if ($courseid != SITEID && !empty($courseid)) { // Course ID must be valid and existing. $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $courses = array($course->id => $course); - $issite = false; + $url->param('course', $course->id); + $managesubscriptionsurl->param('course', $course->id); + + navigation_node::override_active_url(new moodle_url('/course/view.php', ['id' => $course->id])); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'course' => $course->id]) + ); } else { $course = get_site(); $courses = calendar_get_default_courses(); - $issite = true; + + if (!empty($categoryid)) { + $managesubscriptionsurl->param('category', $categoryid); + + navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid])); + $PAGE->set_category_by_id($categoryid); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'category' => $categoryid]) + ); + } else { + navigation_node::override_active_url(new moodle_url('/calendar/view.php', ['view' => 'month'])); + } } require_login($course, false); -$url = new moodle_url('/calendar/export.php', array('time' => $time)); -$managesubscriptionsurl = new moodle_url('/calendar/managesubscriptions.php'); - if ($action !== '') { $url->param('action', $action); } -if ($course !== NULL) { - $url->param('course', $course->id); - - if ($course->id != SITEID) { - $managesubscriptionsurl->param('course', $course->id); - } -} $PAGE->set_url($url); $calendar = new calendar_information(0, 0, 0, $time); @@ -109,15 +122,10 @@ $calendar->set_sources($course, $courses); $pagetitle = get_string('export', 'calendar'); -// Print title and header -if ($issite) { - $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id))); -} -$link = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid)); -$PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time)); $PAGE->navbar->add(get_string('managesubscriptions', 'calendar'), $managesubscriptionsurl); $PAGE->navbar->add($pagetitle); +// Print title and header. $PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); diff --git a/calendar/import.php b/calendar/import.php index 526392c1151..d0d1df7ea59 100644 --- a/calendar/import.php +++ b/calendar/import.php @@ -32,8 +32,6 @@ $category = optional_param('category', 0, PARAM_INT); $data = []; $pageurl = new moodle_url('/calendar/import.php'); $managesubscriptionsurl = new moodle_url('/calendar/managesubscriptions.php'); -$calendarurl = new moodle_url('/calendar/view.php', ['view' => 'month']); -navigation_node::override_active_url($calendarurl); if ($courseid != SITEID && !empty($courseid)) { $course = get_course($courseid); @@ -41,14 +39,43 @@ if ($courseid != SITEID && !empty($courseid)) { $data['courseid'] = $course->id; $pageurl->param('course', $course->id); $managesubscriptionsurl->param('course', $course->id); + navigation_node::override_active_url(new moodle_url('/course/view.php', ['id' => $course->id])); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'course' => $course->id]) + ); +} else if (!empty($category)) { + $course = get_site(); + $pageurl->param('category', $category); + $managesubscriptionsurl->param('category', $category); + $data['category'] = $category; + $data['eventtype'] = 'category'; + navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $category])); + $PAGE->set_category_by_id($category); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'category' => $category]) + ); } else { $course = get_site(); + navigation_node::override_active_url(new moodle_url('/calendar/view.php', ['view' => 'month'])); } + require_login($course, false); if (!calendar_user_can_add_event($course)) { throw new \moodle_exception('errorcannotimport', 'calendar'); } +$heading = get_string('importcalendar', 'calendar'); +$pagetitle = $course->shortname . ': ' . get_string('calendar', 'calendar') . ': ' . $heading; + +$PAGE->set_title($pagetitle); +$PAGE->set_heading($heading); +$PAGE->set_url($pageurl); +$PAGE->set_pagelayout('admin'); +$PAGE->navbar->add(get_string('managesubscriptions', 'calendar'), $managesubscriptionsurl); +$PAGE->navbar->add($heading); + // Populate the 'group' select box based on the given 'groupcourseid', if necessary. $groups = []; if (!empty($groupcourseid)) { @@ -63,22 +90,6 @@ if (!empty($groupcourseid)) { $data['eventtype'] = 'group'; $pageurl->param('groupcourseid', $groupcourseid); } -if (!empty($category)) { - $pageurl->param('category', $category); - $managesubscriptionsurl->param('category', $category); - $data['category'] = $category; - $data['eventtype'] = 'category'; -} - -$heading = get_string('importcalendar', 'calendar'); -$pagetitle = $course->shortname . ': ' . get_string('calendar', 'calendar') . ': ' . $heading; - -$PAGE->set_title($pagetitle); -$PAGE->set_heading($heading); -$PAGE->set_url($pageurl); -$PAGE->set_pagelayout('admin'); -$PAGE->navbar->add(get_string('managesubscriptions', 'calendar'), $managesubscriptionsurl); -$PAGE->navbar->add($heading); $customdata = [ 'courseid' => $course->id, diff --git a/calendar/managesubscriptions.php b/calendar/managesubscriptions.php index 72d259e6022..2d2ca7a4e94 100644 --- a/calendar/managesubscriptions.php +++ b/calendar/managesubscriptions.php @@ -40,14 +40,25 @@ $action = optional_param('action', '', PARAM_INT); $url = new moodle_url('/calendar/managesubscriptions.php'); if ($courseid != SITEID && !empty($courseid)) { $url->param('course', $courseid); -} -if ($categoryid) { + navigation_node::override_active_url(new moodle_url('/course/view.php', ['id' => $courseid])); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'course' => $courseid]) + ); +} else if ($categoryid) { $url->param('categoryid', $categoryid); + navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid])); + $PAGE->set_category_by_id($categoryid); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'category' => $categoryid]) + ); +} else { + navigation_node::override_active_url(new moodle_url('/calendar/view.php', ['view' => 'month'])); } -navigation_node::override_active_url(new moodle_url('/calendar/view.php', array('view' => 'month'))); + $PAGE->set_url($url); $PAGE->set_pagelayout('admin'); -$PAGE->navbar->add(get_string('managesubscriptions', 'calendar')); if ($courseid != SITEID && !empty($courseid)) { // Course ID must be valid and existing. @@ -63,6 +74,8 @@ if (!calendar_user_can_add_event($course)) { print_error('errorcannotimport', 'calendar'); } +$PAGE->navbar->add(get_string('managesubscriptions', 'calendar')); + $importresults = ''; if (!empty($subscriptionid)) { diff --git a/calendar/view.php b/calendar/view.php index 0b9adfc8c01..827bbdaa233 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -96,10 +96,18 @@ $course = get_course($courseid); if ($iscoursecalendar && !empty($courseid)) { navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id))); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'course' => $course->id]) + ); } else if (!empty($categoryid)) { core_course_category::get($categoryid); // Check that category exists and can be accessed. $PAGE->set_category_by_id($categoryid); navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid))); + $PAGE->navbar->add( + get_string('calendar', 'calendar'), + new moodle_url('/calendar/view.php', ['view' => 'month', 'category' => $categoryid]) + ); } else { $PAGE->set_context(context_system::instance()); }