Skip to content

Commit

Permalink
Merge branch 'MDL-71952-master' of git://github.com/rezaies/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Aug 24, 2021
2 parents 2bb8497 + 7a529cc commit d29c6f5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 40 deletions.
44 changes: 26 additions & 18 deletions calendar/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
}

$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);
Expand All @@ -76,48 +77,55 @@
$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);
$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');
Expand Down
47 changes: 29 additions & 18 deletions calendar/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,50 @@
$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);
$data['eventtype'] = 'course';
$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)) {
Expand All @@ -63,22 +90,6 @@
$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,
Expand Down
21 changes: 17 additions & 4 deletions calendar/managesubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@
$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.
Expand All @@ -63,6 +74,8 @@
print_error('errorcannotimport', 'calendar');
}

$PAGE->navbar->add(get_string('managesubscriptions', 'calendar'));

$importresults = '';

if (!empty($subscriptionid)) {
Expand Down
8 changes: 8 additions & 0 deletions calendar/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@

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());
}
Expand Down

0 comments on commit d29c6f5

Please sign in to comment.