From: moodler Date: Sun, 25 Apr 2004 03:05:58 +0000 (+0000) Subject: Calendar support for the Chat module X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8496c4af27efb3839f0753adb2cf4b3a93ef1467;p=moodle.git Calendar support for the Chat module --- diff --git a/mod/chat/db/mysql.php b/mod/chat/db/mysql.php index bc762e6a5d..6270ccc7a8 100644 --- a/mod/chat/db/mysql.php +++ b/mod/chat/db/mysql.php @@ -28,6 +28,11 @@ function chat_upgrade($oldversion) { table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid"); } + if ($oldversion < 2004042500) { + include_once("$CFG->dirroot/mod/chat/lib.php"); + chat_refresh_events(); + } + return true; } diff --git a/mod/chat/db/postgres7.php b/mod/chat/db/postgres7.php index 82764d6007..caf36d0120 100644 --- a/mod/chat/db/postgres7.php +++ b/mod/chat/db/postgres7.php @@ -11,6 +11,10 @@ function chat_upgrade($oldversion) { table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid"); } + if ($oldversion < 2004042500) { + include_once("$CFG->dirroot/mod/chat/lib.php"); + chat_refresh_events(); + } return true; } diff --git a/mod/chat/lib.php b/mod/chat/lib.php index ed2ec9cfc1..6f4801c890 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -43,7 +43,24 @@ function chat_add_instance($chat) { $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, $chat->chathour, $chat->chatminute); - return insert_record("chat", $chat); + if ($returnid = insert_record("chat", $chat)) { + + $event = NULL; + $event->name = $chat->name; + $event->description = $chat->intro; + $event->courseid = $chat->course; + $event->groupid = 0; + $event->userid = 0; + $event->modulename = 'chat'; + $event->instance = $returnid; + $event->eventtype = $chat->schedule; + $event->timestart = $chat->chattime; + $event->timeduration = 0; + + add_event($event); + } + + return $returnid; } @@ -58,7 +75,21 @@ function chat_update_instance($chat) { $chat->chattime = make_timestamp($chat->chatyear, $chat->chatmonth, $chat->chatday, $chat->chathour, $chat->chatminute); - return update_record("chat", $chat); + if ($returnid = update_record("chat", $chat)) { + + $event = NULL; + + if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { + + $event->name = $chat->name; + $event->description = $chat->intro; + $event->timestart = $chat->chattime; + + update_event($event); + } + } + + return $returnid; } @@ -188,6 +219,47 @@ function chat_get_participants($chatid, $groupid=0) { return ($students); } +function chat_refresh_events($courseid = 0) { +// This standard function will check all instances of this module +// and make sure there are up-to-date events created for each of them. +// If courseid = 0, then every chat event in the site is checked, else +// only chat events belonging to the course specified are checked. +// This function is used, in its new format, by restore_refresh_events() + + if ($courseid) { + if (! $chats = get_records("chat", "course", $courseid)) { + return true; + } + } else { + if (! $chats = get_records("chat")) { + return true; + } + } + + foreach ($chats as $chat) { + $event = NULL; + $event->name = addslashes($chat->name); + $event->description = addslashes($chat->intro); + $event->timestart = $chat->chattime; + + if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { + update_event($event); + + } else { + $event->courseid = $chat->course; + $event->groupid = 0; + $event->userid = 0; + $event->modulename = 'chat'; + $event->instance = $chat->id; + $event->eventtype = $chat->schedule; + $event->timeduration = 0; + + add_event($event); + } + } + return true; +} + ////////////////////////////////////////////////////////////////////// /// Functions that require some SQL @@ -312,6 +384,12 @@ function chat_update_chat_times($chatid=0) { break; } update_record("chat", $chat); + + $event = NULL; // Update calendar too + if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { + $event->timestart = $chat->chattime; + update_event($event); + } } } diff --git a/mod/chat/version.php b/mod/chat/version.php index 3bd9ef5fd1..efdfdbebfa 100644 --- a/mod/chat/version.php +++ b/mod/chat/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2004022300; // The (date) version of this module +$module->version = 2004042500; // The (date) version of this module $module->requires = 2004013101; // Requires this Moodle version $module->cron = 300; // How often should cron check this module (seconds)?