mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
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.
This commit is contained in:
parent
e34aab0dd0
commit
5fba04fba0
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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';
|
||||
# --------------------------------------------------------
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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") {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user