From: moodler Date: Sat, 17 Jan 2004 09:47:45 +0000 (+0000) Subject: EARLY SUPPORT FOR CALENDARS AND EVENTS X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5fba04fba0e2e0c6dd17cde2e907767c495c3466;p=moodle.git EARLY SUPPORT FOR CALENDARS AND EVENTS -------------------------------------- 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. --- diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 4fa7b60788..e3a0e442d9 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -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; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index ebf03f2865..0352414ab9 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -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'; # -------------------------------------------------------- diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index fa509d5386..dd0b7d8076 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index b7984f39ba..53afbea6e0 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -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', diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 077ca95be6..e58029d6e3 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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") { diff --git a/version.php b/version.php index 7519f1b50e..8291c40b03 100644 --- a/version.php +++ b/version.php @@ -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