Why no event is adding to the calendar for a choice activity?

Re: Why no event is adding to the calendar for a choice activity?

by Christopher O'Kelly -
Number of replies: 0

I've not worked around it personally, but I believe it would be relatively easy to do by copying the choice module (from /mod/choice) into a new module, say choice_custom and adding to the choice_add_instance function (in lib.php). you can probably copy most of the code you will need from another module, like the assignment module, which has in it's add_instance function (in lib.php)-

if ($assignment->timedue) {
            $event = new stdClass();
            $event->name        = $assignment->name;
            $event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
            $event->courseid    = $assignment->course;
            $event->groupid     = 0;
            $event->userid      = 0;
            $event->modulename  = 'assignment';
            $event->instance    = $returnid;
            $event->eventtype   = 'due';
            $event->timestart   = $assignment->timedue;
            $event->timeduration = 0;
 

           calendar_event::create($event);


Obviously a little work will need to be done to change that to suit the choice module, but it gets you 90% there. Then you will need to just add the custom choice rather than the original one to courses.

You will also want to check out the functions for deleting and updating instances to delete and update the relevant calendar events, but once again, the assignment module or any other that already DOES add events can help you out here. Most of the work to hack your way around this will be copy-pasta.