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

This commit is contained in:
Ankit Agarwal 2012-11-16 13:52:44 +08:00
parent 7133a88d06
commit 35ad5fc6bb
2 changed files with 14 additions and 11 deletions

View file

@ -2692,13 +2692,13 @@ function calendar_get_eventtype_choices($courseid) {
calendar_get_allowed_types($allowed, $courseid); calendar_get_allowed_types($allowed, $courseid);
if ($allowed->user) { if ($allowed->user) {
$choices[0] = get_string('userevents', 'calendar'); $choices['user'] = get_string('userevents', 'calendar');
} }
if ($allowed->site) { if ($allowed->site) {
$choices[SITEID] = get_string('globalevents', 'calendar'); $choices['site'] = get_string('globalevents', 'calendar');
} }
if (!empty($allowed->courses)) { 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)) { if (!empty($allowed->groups) and is_array($allowed->groups)) {
$choices['group'] = get_string('group'); $choices['group'] = get_string('group');
@ -2714,11 +2714,15 @@ function calendar_get_eventtype_choices($courseid) {
* @return int The insert ID, if any. * @return int The insert ID, if any.
*/ */
function calendar_add_subscription($sub) { function calendar_add_subscription($sub) {
global $DB, $USER; global $DB, $USER, $SITE;
$sub->courseid = $sub->eventtype; if ($sub->eventtype === 'site') {
if ($sub->eventtype == 'group') { $sub->courseid = $SITE->id;
} else if ($sub->eventtype === 'group' || $sub->eventtype === 'course') {
$sub->courseid = $sub->course; $sub->courseid = $sub->course;
} else {
// User events.
$sub->courseid = 0;
} }
$sub->userid = $USER->id; $sub->userid = $USER->id;
@ -2794,10 +2798,10 @@ function calendar_add_icalendar_event($event, $courseid, $subscriptionid = null)
$eventrecord->userid = $sub->userid; $eventrecord->userid = $sub->userid;
$eventrecord->groupid = $sub->groupid; $eventrecord->groupid = $sub->groupid;
$eventrecord->courseid = $sub->courseid; $eventrecord->courseid = $sub->courseid;
$eventrecord->eventtype = $sub->eventtype;
} else { } else {
$eventrecord->userid = $USER->id; // We should never do anything with an event without a subscription reference.
$eventrecord->groupid = 0; // TODO: ??? return 0;
$eventrecord->courseid = $courseid;
} }
if ($updaterecord = $DB->get_record('event', array('uuid' => $eventrecord->uuid))) { if ($updaterecord = $DB->get_record('event', array('uuid' => $eventrecord->uuid))) {

View file

@ -74,11 +74,10 @@ class calendar_addsubscription_form extends moodleform {
$mform->addHelpButton('pollinterval', 'pollinterval', 'calendar'); $mform->addHelpButton('pollinterval', 'pollinterval', 'calendar');
$mform->setType('pollinterval', PARAM_INT); $mform->setType('pollinterval', PARAM_INT);
// Eventtype: 0 = user, 1 = global, anything else = course ID.
list($choices, $groups) = calendar_get_eventtype_choices($courseid); list($choices, $groups) = calendar_get_eventtype_choices($courseid);
$mform->addElement('select', 'eventtype', get_string('eventkind', 'calendar'), $choices); $mform->addElement('select', 'eventtype', get_string('eventkind', 'calendar'), $choices);
$mform->addRule('eventtype', get_string('required'), 'required'); $mform->addRule('eventtype', get_string('required'), 'required');
$mform->setType('eventtype', PARAM_INT); $mform->setType('eventtype', PARAM_ALPHA);
if (!empty($groups) and is_array($groups)) { if (!empty($groups) and is_array($groups)) {
$groupoptions = array(); $groupoptions = array();