Permalink
Browse files

MDL-36614 calendar: Add support for storing the submitted event type

  • Loading branch information...
1 parent 7133a88 commit 35ad5fc6bbfa32276b51060bb15c29908a044f24 @ankitagarwal ankitagarwal committed Nov 16, 2012
Showing with 14 additions and 11 deletions.
  1. +13 −9 calendar/lib.php
  2. +1 −2 calendar/managesubscriptions_form.php
View
@@ -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))) {
@@ -74,11 +74,10 @@ public function definition() {
$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();

0 comments on commit 35ad5fc

Please sign in to comment.