]> git.mjollnir.org Git - moodle.git/commitdiff
Calendar support for the Chat module
authormoodler <moodler>
Sun, 25 Apr 2004 03:05:58 +0000 (03:05 +0000)
committermoodler <moodler>
Sun, 25 Apr 2004 03:05:58 +0000 (03:05 +0000)
mod/chat/db/mysql.php
mod/chat/db/postgres7.php
mod/chat/lib.php
mod/chat/version.php

index bc762e6a5d983842a912ef789061d22cab141fd2..6270ccc7a85202bea69af3e939f7a80bf869e147 100644 (file)
@@ -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;
 }
 
index 82764d60077009072d53975329585d5874475d66..caf36d012083ec5be77e4a98849e314eab853401 100644 (file)
@@ -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;
 }
index ed2ec9cfc1976c79f44b89b4582c8dddc52a4499..6f4801c89091c381d17c3c04b25cb611a9800d43 100644 (file)
@@ -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);
+        }
     }
 }
 
index 3bd9ef5fd1e0a3463d093f2de461ef0adf8c6ac1..efdfdbebfad034c4a728d5c34a171fe51e680ffa 100644 (file)
@@ -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)?