Skip to content

Commit

Permalink
Merge branch 'MDL-51749-master' of git://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jun 16, 2016
2 parents 134e456 + 3de445b commit d7c9327
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 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
21 changes: 16 additions & 5 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 @@ -60,9 +60,9 @@
if(!empty($what) && !empty($time)) {
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;
// Array of courses that we will pass to calendar_get_events() which is initially set to the list of the user's courses.
$paramcourses = $courses;
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 +71,19 @@
if (empty($groups)) {
$groups = false;
}
}
if ($what == 'all') {
$users = $user->id;
$courses[SITEID] = new stdClass;
$courses[SITEID]->shortname = get_string('globalevents', 'calendar');
$paramcourses[SITEID] = $courses[SITEID];
} else if ($what == 'groups') {
$users = false;
$paramcourses = array();
} else if ($what == 'user') {
$users = $user->id;
$groups = false;
$paramcourses = array();
} else {
$users = false;
$groups = false;
Expand Down Expand Up @@ -168,7 +179,7 @@
die();
}
}
$events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys($courses), false);
$events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys($paramcourses), false);

$ical = new iCalendar;
$ical->add_property('method', 'PUBLISH');
Expand Down
57 changes: 57 additions & 0 deletions calendar/tests/behat/export.feature
@@ -0,0 +1,57 @@
@core @core_calendar @core_calendar_export
Feature: Export calendar events
In order to be able to use my calendar events outside of Moodle
As a user
I need to export calendar events in iCalendar format

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "student1"

Scenario: Viewing calendar export options
Given I follow "This month"
When I click on "Export calendar" "button"
Then I should see "All events"
And I should see "Events related to courses"
And I should see "Events related to groups"
And I should see "My personal events"

Scenario: Generating calendar URL for all events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "All events" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=all&"

Scenario: Generating calendar URL for course events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "Events related to courses" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=courses&"

Scenario: Generating calendar URL for group events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "Events related to groups" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=groups&"

Scenario: Generating calendar URL for user events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "My personal events" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=user&"
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 d7c9327

Please sign in to comment.