Integrating assignment module with the calendar

Integrating assignment module with the calendar

by Gustav W Delius -
Number of replies: 2

I have recently integrated WebCalendar into Moodle, see http://moodle.org/mod/forum/discuss.php?d=3944. Now, one-by-one, all modules can be extended to make use of the calendar. As a start I suggest that the due dates for appointments should be entered in the calendar. This requires a change to the functions

assignment_add_instance(), assignment_update_instance() and assignment_delete_instance

in cvs:/moodle/mod/assignment/lib.php so that they automatically add, update, or delete the corresponding due date event. I have attached a zip file with the new version of lib.php. You can simply replace the existing one with this new one. Of course you will also have to install the event module (which integrates the calendar).

More integration is possible. For example if you replace the line

       $due = userdate($assignment->timedue);

in cvs:/moodle/mod/assignment/index.php by

        if (record_exists('event')) { // events module is installed
            require_once('../event/lib.php');
            $due = calendar_link_userdate($assignment->timedue, 'week');
        } else {
            $due = userdate($assignment->timedue);
        }

then the date will become a link to the correct place in the calendar. You could change 'week' above into 'day', or 'month' if you want a day or month view of the calendar instead of a week view.

A similar change could be made in view.php. Replace the line

        $strduedate = userdate($assignment->timedue)." ($strdifference)";

by

        if (record_exists('event')) { // events module is installed
            require_once('../event/lib.php');
            $strduedate = calendar_link_userdate($assignment->timedue, 'week')." ($strdifference)";
        } else {
            $strduedate = userdate($assignment->timedue)." ($strdifference)";
        }

The changes could be made a standard part of the assignment module because if the event module is not installed then they will be ignored.

Average of ratings: -
In reply to Gustav W Delius

Re: Integrating assignment module with the calendar

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Gustav writes: "Now, one-by-one, all modules can be extended to make use of the calendar."

Slow down, my friend. smile I really appreciate all your work and enthusiasm, but please - let's not rebuild Moodle around a two-day-old module without a good look at where this is headed.

From what I've seen of your event module, it doesn't implement the basic idea I mentioned of keeping calendar data separate from the calendar. At this point I do not want Moodle to become dependent on WebCalendar, nor have to maintain an entire copy of the thing within Moodle's CVS.  It's also not good practice to have modules depending on other modules.

It always feels like I'm putting brakes on things, and I guess it's probably annoying, but whenever I let things like this run free I find myself having to deal with the aftermath.  Let's talk over in the other thread about restructuring this around a Moodle API.
In reply to Martin Dougiamas

Re: Integrating assignment module with the calendar

by Gustav W Delius -

Martin writes:
From what I've seen of your event module, it doesn't implement the basic idea I mentioned of keeping calendar data separate from the calendar.

But it does: all events are kept in the moodle table event. All events are updated by calls to event_add_instance, event_update_instance, and event_delete_instance. These functions in terms call calendar specific functions to update WebCalendar. But anyone who wants to use a different calendar just has to change these calendar specific functions in cvs:/contrib/event/lib.php. No code elsewhere in Moodle will depend on what calendar is chosen.