MDL-59674 core_calendar: add group name to event exporter
authorSimey Lameze <simey@moodle.com>
Fri, 18 Aug 2017 03:27:14 +0000 (11:27 +0800)
committerSimey Lameze <simey@moodle.com>
Mon, 21 Aug 2017 06:07:03 +0000 (14:07 +0800)
calendar/classes/external/event_exporter.php

index 7e4bb7c..6b34cda 100644 (file)
@@ -66,6 +66,12 @@ class event_exporter extends event_exporter_base {
             'type' => event_action_exporter::read_properties_definition(),
             'optional' => true,
         ];
+        $values['groupname'] = [
+            'type' => PARAM_RAW,
+            'optional' => true,
+            'default' => null,
+            'null' => NULL_ALLOWED
+        ];
 
         return $values;
     }
@@ -138,6 +144,15 @@ class event_exporter extends event_exporter_base {
             }
         }
 
+        if ($legacyevent->groupid) {
+            if ($group = calendar_get_group_cached($legacyevent->groupid)) {
+                $values['groupname'] = format_string($group->name, true,
+                        ['context' => \context_course::instance($group->courseid)]);
+            } else {
+                $values['groupname'] = null;
+            }
+        }
+
         return $values;
     }
 }