Skip to content

Commit

Permalink
MDL-63196 calendar: add missing option to export category events
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Mar 22, 2019
1 parent d70651f commit 4c0ea3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions calendar/classes/export_form.php
Expand Up @@ -49,6 +49,7 @@ public function definition() {

$export = array();
$export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsall', 'calendar'), 'all');
$export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsrelatedtocategories', 'calendar'), 'categories');
$export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsrelatedtocourses', 'calendar'), 'courses');
$export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsrelatedtogroups', 'calendar'), 'groups');
$export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventspersonal', 'calendar'), 'user');
Expand Down
18 changes: 13 additions & 5 deletions calendar/export_execute.php
Expand Up @@ -40,8 +40,8 @@
$now = $calendartype->timestamp_to_date_array(time());

// Let's see if we have sufficient and correct data
$allowed_what = array('all', 'user', 'groups', 'courses');
$allowed_time = array('weeknow', 'weeknext', 'monthnow', 'monthnext', 'recentupcoming', 'custom');
$allowedwhat = ['all', 'user', 'groups', 'courses', 'categories'];
$allowedtime = ['weeknow', 'weeknext', 'monthnow', 'monthnext', 'recentupcoming', 'custom'];

if (!empty($generateurl)) {
$authtoken = sha1($user->id . $user->password . $CFG->calendar_exportsalt);
Expand All @@ -56,9 +56,9 @@
redirect($link->out());
die;
}

$paramcategory = false;
if(!empty($what) && !empty($time)) {
if(in_array($what, $allowed_what) && in_array($time, $allowed_time)) {
if(in_array($what, $allowedwhat) && in_array($time, $allowedtime)) {
$courses = enrol_get_users_courses($user->id, true, 'id, visible, shortname');
// Array of courses that we will pass to calendar_get_legacy_events() which
// is initially set to the list of the user's courses.
Expand All @@ -78,13 +78,19 @@
$courses[SITEID] = new stdClass;
$courses[SITEID]->shortname = get_string('globalevents', 'calendar');
$paramcourses[SITEID] = $courses[SITEID];
$paramcategory = true;
} else if ($what == 'groups') {
$users = false;
$paramcourses = array();
} else if ($what == 'user') {
$users = $user->id;
$groups = false;
$paramcourses = array();
} else if ($what == 'categories') {
$users = $user->id;
$groups = false;
$paramcourses = array();
$paramcategory = true;
} else {
$users = false;
$groups = false;
Expand Down Expand Up @@ -180,7 +186,9 @@
die();
}
}
$events = calendar_get_legacy_events($timestart, $timeend, $users, $groups, array_keys($paramcourses), false);

$events = calendar_get_legacy_events($timestart, $timeend, $users, $groups, array_keys($paramcourses), false, true,
$paramcategory);

$ical = new iCalendar;
$ical->add_property('method', 'PUBLISH');
Expand Down
1 change: 1 addition & 0 deletions lang/en/calendar.php
Expand Up @@ -114,6 +114,7 @@
$string['eventsfor'] = '{$a} events';
$string['eventskey'] = 'Events key';
$string['eventspersonal'] = 'My personal events';
$string['eventsrelatedtocategories'] = 'Events related to categories';
$string['eventsrelatedtocourses'] = 'Events related to courses';
$string['eventsrelatedtogroups'] = 'Events related to groups';
$string['eventstarttime'] = 'Start time';
Expand Down

0 comments on commit 4c0ea3f

Please sign in to comment.