Merge branch 'MDL-51495' of https://github.com/NeillM/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 11 Nov 2015 15:56:27 +0000 (16:56 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 11 Nov 2015 15:56:27 +0000 (16:56 +0100)
calendar/externallib.php
calendar/tests/externallib_test.php

index 8fdae9b..c2053fa 100644 (file)
@@ -173,6 +173,8 @@ class core_calendar_external extends external_api {
 
         // Let us findout courses that we can return events from.
         if (!$hassystemcap) {
+            $courses = enrol_get_my_courses('id');
+            $courses = array_keys($courses);
             foreach ($params['events']['courseids'] as $id) {
                try {
                     $context = context_course::instance($id);
@@ -185,7 +187,6 @@ class core_calendar_external extends external_api {
                         'warningcode' => 'nopermissions',
                         'message' => 'No access rights in course context '.$e->getMessage().$e->getTraceAsString()
                     );
-                    continue;
                 }
             }
         } else {
index f1dec3c..8a5b444 100644 (file)
@@ -363,6 +363,13 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
         $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
         $this->assertEquals(1, count($events['events'])); // site.
         $this->assertEquals(0, count($events['warnings']));
+
+        // Try getting a course event by its id.
+        $paramevents = array ('eventids' => array($courseevent->id));
+        $events = core_calendar_external::get_calendar_events($paramevents, $options);
+        $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+        $this->assertEquals(1, count($events['events']));
+        $this->assertEquals(0, count($events['warnings']));
     }
 
     /**