]> git.mjollnir.org Git - moodle.git/commitdiff
EARLY SUPPORT FOR CALENDARS AND EVENTS
authormoodler <moodler>
Sat, 17 Jan 2004 09:47:45 +0000 (09:47 +0000)
committermoodler <moodler>
Sat, 17 Jan 2004 09:47:45 +0000 (09:47 +0000)
--------------------------------------

New functions and tables, based on work from Gustav Delius
(see http://moodle.org/mod/forum/discuss.php?d=4466)

This forms the core of a new system to store, track and utilise
event information in all modules, as well as allowing external
calendars to be synchronised with new information.

lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
lib/moodlelib.php
version.php

index 4fa7b60788e5c95881c40f1dc25ab9c4e9172189..e3a0e442d9d2c175ce08d6aab306cd60328720ae 100644 (file)
@@ -597,6 +597,27 @@ function main_upgrade($oldversion=0) {
         table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
     }
 
+    if ($oldversion < 2004011700) {
+        modify_database("", "CREATE TABLE `prefix_event` (
+                              `id` int(10) unsigned NOT NULL auto_increment,
+                              `name` varchar(255) NOT NULL default '',
+                              `description` text NOT NULL,
+                              `courseid` int(10) unsigned NOT NULL default '0',
+                              `groupid` int(10) unsigned NOT NULL default '0',
+                              `userid` int(10) unsigned NOT NULL default '0',
+                              `modulename` varchar(20) NOT NULL default '',
+                              `instance` int(10) unsigned NOT NULL default '0',
+                              `eventtype` varchar(20) NOT NULL default '',
+                              `timestart` int(10) unsigned NOT NULL default '0',
+                              `timeduration` int(10) unsigned NOT NULL default '0',
+                              `timemodified` int(10) unsigned NOT NULL default '0',
+                              PRIMARY KEY  (`id`),
+                              UNIQUE KEY `id` (`id`),
+                              KEY `courseid` (`courseid`),
+                              KEY `userid` (`userid`)
+                            ) TYPE=MyISAM COMMENT='For everything with a time associated to it'; ");
+    }
+
     return $result;
 
 }
index ebf03f28658765d105a4d19b4f65426884f97919..0352414ab94d1256611805305a0d7b9a7e8aaed1 100644 (file)
@@ -132,6 +132,29 @@ CREATE TABLE `prefix_course_sections` (
 ) TYPE=MyISAM;
 # --------------------------------------------------------
 
+#
+# Table structure for table `event`
+#
+
+CREATE TABLE `prefix_event` (
+  `id` int(10) unsigned NOT NULL auto_increment,
+  `name` varchar(255) NOT NULL default '',
+  `description` text NOT NULL,
+  `courseid` int(10) unsigned NOT NULL default '0',
+  `groupid` int(10) unsigned NOT NULL default '0',
+  `userid` int(10) unsigned NOT NULL default '0',
+  `modulename` varchar(20) NOT NULL default '',
+  `instance` int(10) unsigned NOT NULL default '0',
+  `eventtype` varchar(20) NOT NULL default '',
+  `timestart` int(10) unsigned NOT NULL default '0',
+  `timeduration` int(10) unsigned NOT NULL default '0',
+  `timemodified` int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (`id`),
+  UNIQUE KEY `id` (`id`),
+  KEY `courseid` (`courseid`),
+  KEY `userid` (`userid`)
+) TYPE=MyISAM COMMENT='For everything with a time associated to it';
+
 #
 # Table structure for table `group`
 #
@@ -146,6 +169,7 @@ CREATE TABLE `prefix_groups` (
   `timecreated` int(10) unsigned NOT NULL default '0',
   `timemodified` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`),
+  UNIQUE KEY `id` (`id`),
   KEY `courseid` (`courseid`)
 ) TYPE=MyISAM COMMENT='Each record is a group in a course.';
 # --------------------------------------------------------
@@ -160,6 +184,7 @@ CREATE TABLE `prefix_groups_members` (
   `userid` int(10) unsigned NOT NULL default '0',
   `timeadded` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`),
+  UNIQUE KEY `id` (`id`),
   KEY `groupid` (`groupid`)
 ) TYPE=MyISAM COMMENT='Lists memberships of users to groups';
 # --------------------------------------------------------
index fa509d5386d23c81f42ff742980c3fbdfa03872d..dd0b7d80767f10a8670bb658c0b766efd96d3746 100644 (file)
@@ -344,6 +344,27 @@ function main_upgrade($oldversion=0) {
         table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
     }
 
+    if ($oldversion < 2004011700) {
+        modify_database("", "CREATE TABLE prefix_event (
+                                id SERIAL PRIMARY KEY,
+                                name varchar(255) NOT NULL default '',
+                                description text,
+                                courseid integer NOT NULL default '0',
+                                groupid integer NOT NULL default '0',
+                                userid integer NOT NULL default '0',
+                                modulename varchar(20) NOT NULL default '',
+                                instance integer NOT NULL default '0',
+                                eventtype varchar(20) NOT NULL default '',
+                                timestart integer NOT NULL default '0',
+                                timeduration integer NOT NULL default '0',
+                                timemodified integer NOT NULL default '0'
+                             ); ");
+
+        modify_database("", "CREATE INDEX prefix_event_courseid_idx ON prefix_event (courseid);");
+        modify_database("", "CREATE INDEX prefix_event_userid_idx ON prefix_event (userid);");
+    }
+
+
     return $result;
 }
 
index b7984f39ba70fdc4846c6422a565a5a2bc9b4107..53afbea6e036287edee4fb93c076a2d06f9c3d2f 100644 (file)
@@ -80,6 +80,24 @@ CREATE TABLE prefix_course_sections (
    visible integer NOT NULL default '1'
 );
 
+CREATE TABLE prefix_event (
+   id SERIAL PRIMARY KEY,
+   name varchar(255) NOT NULL default '',
+   description text,
+   courseid integer NOT NULL default '0',
+   groupid integer NOT NULL default '0',
+   userid integer NOT NULL default '0',
+   modulename varchar(20) NOT NULL default '',
+   instance integer NOT NULL default '0',
+   eventtype varchar(20) NOT NULL default '',
+   timestart integer NOT NULL default '0',
+   timeduration integer NOT NULL default '0',
+   timemodified integer NOT NULL default '0'
+);
+
+CREATE INDEX prefix_event_courseid_idx ON prefix_event (courseid);
+CREATE INDEX prefix_event_userid_idx ON prefix_event (userid);
+
 CREATE TABLE prefix_groups (
    id SERIAL PRIMARY KEY,
    courseid integer NOT NULL default '0',
index 077ca95be693eb0b042d986f862013e102629c57..e58029d6e38037ece2b38d4ae6ad3f2d7740bbfe 100644 (file)
@@ -1679,6 +1679,89 @@ function endecrypt ($pwd, $data, $case) {
 }
 
 
+/// CALENDAR MANAGEMENT  ////////////////////////////////////////////////////////////////
+
+
+function add_event($event) {
+/// call this function to add an event to the calendar table
+///  and to call any calendar plugins
+/// The function returns the id number of the resulting record
+/// The object event should include the following:
+///     $event->name         Name for the event
+///     $event->description  Description of the event (defaults to '')
+///     $event->courseid     The id of the course this event belongs to (0 = all courses)
+///     $event->groupid      The id of the group this event belongs to (0 = no group)
+///     $event->userid       The id of the user this event belongs to (0 = no user)
+///     $event->modulename   Name of the module that creates this event
+///     $event->instance     Instance of the module that owns this event
+///     $event->eventtype    The type info together with the module info could
+///                          be used by calendar plugins to decide how to display event
+///     $event->timestart    Timestamp for start of event
+///     $event->timeduration Duration (defaults to zero)
+
+    global $CFG;
+
+    $event->timemodified = time();
+    
+    if (!$event->id = insert_record("event", $event)) {
+        return false;
+    }
+    
+    if (!empty($CFG->calendar)) { // call the add_event function of the selected calendar
+        if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
+            include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
+            $calendar_add_event = $CFG->calendar.'_add_event';
+            if (function_exists($calendar_add_event)) {
+                $calendar_add_event($event);
+            }
+        }
+    }
+    
+    return $event->id;
+}
+
+
+function update_event($event) {
+/// call this function to update an event in the calendar table
+/// the event will be identified by the id field of the $event object
+
+    global $CFG;
+
+    $event->timemodified = time();
+    
+    if (!empty($CFG->calendar)) { // call the update_event function of the selected calendar
+        if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
+            include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
+            $calendar_update_event = $CFG->calendar.'_update_event';
+            if (function_exists($calendar_update_event)) {
+                $calendar_update_event($event);
+            }
+        }
+    }
+    return update_record("event", $event);
+}
+
+
+function delete_event($id) {
+/// call this function to delete the event with id $id from calendar table
+
+    global $CFG;
+
+    if (!empty($CFG->calendar)) { // call the delete_event function of the selected calendar
+        if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
+            include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
+            $calendar_delete_event = $CFG->calendar.'_delete_event';
+            if (function_exists($calendar_delete_event)) {
+                $calendar_delete_event($id);
+            }
+        }
+    }
+    return delete_records("event", 'id', $id);
+}
+
+
+
+
 /// ENVIRONMENT CHECKING  ////////////////////////////////////////////////////////////
 
 function get_list_of_plugins($plugin="mod") {
index 7519f1b50e320a7f3a088765d1258c0e8253a81a..8291c40b03796fb895eb6c1acea95b2c0ee20143 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2004010900;   // The current version is a date (YYYYMMDDXX)
+$version = 2004011700;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.2 development";   // User-friendly version number