MDL-52013 assign: Allow subplugins to add calendar events
authorMichael Aherne <michael.aherne@strath.ac.uk>
Mon, 2 Nov 2015 12:04:01 +0000 (12:04 +0000)
committerMichael Aherne <michael.aherne@strath.ac.uk>
Thu, 26 Nov 2015 14:28:53 +0000 (14:28 +0000)
mod/assign/locallib.php

index dd61e45..464ae01 100644 (file)
@@ -889,10 +889,12 @@ class assign {
         // Special case for add_instance as the coursemodule has not been set yet.
         $instance = $this->get_instance();
 
+        $eventtype = 'due';
+
         if ($instance->duedate) {
             $event = new stdClass();
 
-            $params = array('modulename'=>'assign', 'instance'=>$instance->id);
+            $params = array('modulename' => 'assign', 'instance' => $instance->id, 'eventtype' => $eventtype);
             $event->id = $DB->get_field('event', 'id', $params);
             $event->name = $instance->name;
             $event->timestart = $instance->duedate;
@@ -929,12 +931,12 @@ class assign {
                 $event->userid      = 0;
                 $event->modulename  = 'assign';
                 $event->instance    = $instance->id;
-                $event->eventtype   = 'due';
+                $event->eventtype   = $eventtype;
                 $event->timeduration = 0;
                 calendar_event::create($event);
             }
         } else {
-            $DB->delete_records('event', array('modulename'=>'assign', 'instance'=>$instance->id));
+            $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id, 'eventtype' => $eventtype));
         }
     }