From 7133a88d06284d17f15fdf57380187dd723fdea1 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 16 Nov 2012 13:49:26 +0800 Subject: [PATCH 1/3] MDL-36614 calendar: Add event type field to the database --- lib/db/install.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 5bd64ecb4ce..f60af6cb9b4 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2888,8 +2888,9 @@ - - + + + From 35ad5fc6bbfa32276b51060bb15c29908a044f24 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 16 Nov 2012 13:52:44 +0800 Subject: [PATCH 2/3] MDL-36614 calendar: Add support for storing the submitted event type --- calendar/lib.php | 22 +++++++++++++--------- calendar/managesubscriptions_form.php | 3 +-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 02f541bbb79..c51ba4c0239 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2692,13 +2692,13 @@ function calendar_get_eventtype_choices($courseid) { calendar_get_allowed_types($allowed, $courseid); if ($allowed->user) { - $choices[0] = get_string('userevents', 'calendar'); + $choices['user'] = get_string('userevents', 'calendar'); } if ($allowed->site) { - $choices[SITEID] = get_string('globalevents', 'calendar'); + $choices['site'] = get_string('globalevents', 'calendar'); } if (!empty($allowed->courses)) { - $choices[$courseid] = get_string('courseevents', 'calendar'); + $choices['course'] = get_string('courseevents', 'calendar'); } if (!empty($allowed->groups) and is_array($allowed->groups)) { $choices['group'] = get_string('group'); @@ -2714,11 +2714,15 @@ function calendar_get_eventtype_choices($courseid) { * @return int The insert ID, if any. */ function calendar_add_subscription($sub) { - global $DB, $USER; + global $DB, $USER, $SITE; - $sub->courseid = $sub->eventtype; - if ($sub->eventtype == 'group') { + if ($sub->eventtype === 'site') { + $sub->courseid = $SITE->id; + } else if ($sub->eventtype === 'group' || $sub->eventtype === 'course') { $sub->courseid = $sub->course; + } else { + // User events. + $sub->courseid = 0; } $sub->userid = $USER->id; @@ -2794,10 +2798,10 @@ function calendar_add_icalendar_event($event, $courseid, $subscriptionid = null) $eventrecord->userid = $sub->userid; $eventrecord->groupid = $sub->groupid; $eventrecord->courseid = $sub->courseid; + $eventrecord->eventtype = $sub->eventtype; } else { - $eventrecord->userid = $USER->id; - $eventrecord->groupid = 0; // TODO: ??? - $eventrecord->courseid = $courseid; + // We should never do anything with an event without a subscription reference. + return 0; } if ($updaterecord = $DB->get_record('event', array('uuid' => $eventrecord->uuid))) { diff --git a/calendar/managesubscriptions_form.php b/calendar/managesubscriptions_form.php index fcd7979c0b8..80ab634f9cc 100644 --- a/calendar/managesubscriptions_form.php +++ b/calendar/managesubscriptions_form.php @@ -74,11 +74,10 @@ class calendar_addsubscription_form extends moodleform { $mform->addHelpButton('pollinterval', 'pollinterval', 'calendar'); $mform->setType('pollinterval', PARAM_INT); - // Eventtype: 0 = user, 1 = global, anything else = course ID. list($choices, $groups) = calendar_get_eventtype_choices($courseid); $mform->addElement('select', 'eventtype', get_string('eventkind', 'calendar'), $choices); $mform->addRule('eventtype', get_string('required'), 'required'); - $mform->setType('eventtype', PARAM_INT); + $mform->setType('eventtype', PARAM_ALPHA); if (!empty($groups) and is_array($groups)) { $groupoptions = array(); From 20131e5cddd9b070b58e853d0649d40ebe9ac947 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Mon, 19 Nov 2012 13:17:24 +0800 Subject: [PATCH 3/3] MDL-36614 calendar: upgrade code for adding eventtype field to all existing installs --- lib/db/upgrade.php | 14 ++++++++++++++ version.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 65c304649ad..acd035a0c7e 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1472,6 +1472,20 @@ function xmldb_main_upgrade($oldversion) { // Main savepoint reached. upgrade_main_savepoint(true, 2012111200.01); } + if ($oldversion < 2012111601.01) { + + // Define field eventtype to be added to event_subscriptions. + $table = new xmldb_table('event_subscriptions'); + $field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'userid'); + + // Conditionally launch add field eventtype. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2012111601.01); + } return true; diff --git a/version.php b/version.php index 87c44901a67..0e2b56e4a01 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012111601.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012111601.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes