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();