MDL-59921 calendar: fix missing course error on event form
authorSimey Lameze <simey@moodle.com>
Wed, 11 Oct 2017 01:37:30 +0000 (09:37 +0800)
committerSimey Lameze <simey@moodle.com>
Wed, 11 Oct 2017 02:03:42 +0000 (10:03 +0800)
calendar/classes/local/event/mappers/create_update_form_mapper.php

index 2f0326a..91c1435 100644 (file)
@@ -88,20 +88,7 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
     public function from_data_to_event_properties(\stdClass $data) {
         $properties = clone($data);
 
-        // Undo the form definition work around to allow us to have two different
-        // course selectors present depending on which event type the user selects.
-        if ($data->eventtype == 'course') {
-            // Default course id if none is set.
-            if (!isset($properties->courseid)) {
-                if ($properties->eventtype === 'site') {
-                    $properties->courseid = SITEID;
-                } else {
-                    $properties->courseid = 0;
-                }
-            } else {
-                $properties->courseid = $data->courseid;
-            }
-        } else if ($data->eventtype == 'group') {
+        if ($data->eventtype == 'group') {
             if (isset($data->groupcourseid)) {
                 $properties->courseid = $data->groupcourseid;
                 unset($properties->groupcourseid);
@@ -113,6 +100,17 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
                 list($courseid, $groupid) = explode('-', $data->groupid);
                 $properties->groupid = $groupid;
             }
+        } else {
+            // Default course id if none is set.
+            if (empty($properties->courseid)) {
+                if ($properties->eventtype == 'site') {
+                    $properties->courseid = SITEID;
+                } else {
+                    $properties->courseid = 0;
+                }
+            } else {
+                $properties->courseid = $data->courseid;
+            }
         }
 
         // Decode the form fields back into valid event property.