Skip to content

Commit

Permalink
MDL-51749 CALENDAR: Add ical export for user or group events
Browse files Browse the repository at this point in the history
  • Loading branch information
aspark21 committed Apr 16, 2016
1 parent 4f33514 commit 6552198
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions calendar/classes/export_form.php
Expand Up @@ -48,6 +48,8 @@ public function definition() {
$export = array();
$export[] = $mform->createElement('radio', 'exportevents', '', get_string('eventsall', 'calendar'), 'all');
$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');

$mform->addGroup($export, 'events', get_string('export', 'calendar'), '<br/>');
$mform->addGroupRule('events', get_string('required'), 'required');
Expand Down
15 changes: 12 additions & 3 deletions calendar/export_execute.php
Expand Up @@ -40,7 +40,7 @@
$now = $calendartype->timestamp_to_date_array(time());

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

if (!empty($generateurl)) {
Expand All @@ -61,8 +61,7 @@
if(in_array($what, $allowed_what) && in_array($time, $allowed_time)) {
$courses = enrol_get_users_courses($user->id, true, 'id, visible, shortname');

if ($what == 'all') {
$users = $user->id;
if ($what == 'all' || $what == 'groups') {
$groups = array();
foreach ($courses as $course) {
$course_groups = groups_get_all_groups($course->id, $user->id);
Expand All @@ -71,8 +70,18 @@
if (empty($groups)) {
$groups = false;
}
}
if ($what == 'all') {
$users = $user->id;
$courses[SITEID] = new stdClass;
$courses[SITEID]->shortname = get_string('globalevents', 'calendar');
} else if ($what == 'groups') {
$users = false;
$courses = array();
} else if ($what == 'user') {
$users = $user->id;
$groups = false;
$courses = array();
} else {
$users = false;
$groups = false;
Expand Down
3 changes: 2 additions & 1 deletion lang/en/calendar.php
Expand Up @@ -86,7 +86,9 @@
$string['eventsupdated'] = 'Events updated: {$a}';
$string['eventsfor'] = '{$a} events';
$string['eventskey'] = 'Events key';
$string['eventspersonal'] = 'My personal events';
$string['eventsrelatedtocourses'] = 'Events related to courses';
$string['eventsrelatedtogroups'] = 'Events related to groups';
$string['eventstarttime'] = 'Start time';
$string['eventtime'] = 'Time';
$string['eventview'] = 'Event details';
Expand Down Expand Up @@ -215,4 +217,3 @@
$string['weekthis'] = 'This week';
$string['yesterday'] = 'Yesterday';
$string['youcandeleteallrepeats'] = 'This event is part of a repeating event series. You can delete this event only, or all {$a} events in the series at once.';

0 comments on commit 6552198

Please sign in to comment.