MDL-59538 core_calendar: handle event source on the webservice
authorSimey Lameze <simey@moodle.com>
Mon, 17 Jul 2017 05:56:29 +0000 (13:56 +0800)
committerJun Pataleta <jun@moodle.com>
Fri, 21 Jul 2017 01:01:57 +0000 (09:01 +0800)
Part of MDL-59333.

calendar/externallib.php

index f684ae0..1ab68c7 100644 (file)
@@ -722,6 +722,20 @@ class core_calendar_external extends external_api {
         list($event[$eventid]->description, $event[$eventid]->format) = $eventobj->format_external_text();
         $event[$eventid]->caneditevent = calendar_edit_event_allowed($eventobj);
 
+        $event[$eventid]->subscription = null;
+        $event[$eventid]->displayeventsource = false;
+        if (!empty($event[$eventid]->subscriptionid)) {
+            $subscription = calendar_get_subscription($event[$eventid]->subscriptionid);
+            if (!empty($subscription) && $CFG->calendar_showicalsource) {
+                $event[$eventid]->displayeventsource = true;
+                if (!empty($subscription->url)) {
+                    $event[$eventid]->subscription->url = $subscription->url;
+                }
+                $event[$eventid]->subscription->name = $subscription->name;
+                $event[$eventid]->subscription = json_encode($event[$eventid]->subscription);
+            }
+        }
+
         return array('event' => $event[$eventid], 'warnings' => $warnings);
     }
 
@@ -753,7 +767,10 @@ class core_calendar_external extends external_api {
                     'sequence' => new external_value(PARAM_INT, 'sequence'),
                     'timemodified' => new external_value(PARAM_INT, 'time modified'),
                     'subscriptionid' => new external_value(PARAM_INT, 'Subscription id', VALUE_OPTIONAL, null, NULL_ALLOWED),
+                    'subscription' => new external_value(PARAM_RAW, 'Subscription object serialized', VALUE_OPTIONAL,
+                            null, NULL_ALLOWED),
                     'caneditevent' => new external_value(PARAM_BOOL, 'Whether the user can edit the event'),
+                    'displayeventsource' => new external_value(PARAM_BOOL, 'Whether the source should be displayed'),
                 ),
                 'event'
             ),