Merge branch 'MDL-60361-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
Jake Dallimore 2017-11-06 09:29:46 +08:00
commit eb354bdefa
14 changed files with 713 additions and 176 deletions

View file

@ -2664,12 +2664,36 @@ function calendar_get_eventtype_choices($courseid) {
function calendar_add_subscription($sub) {
global $DB, $USER, $SITE;
// Undo the form definition work around to allow us to have two different
// course selectors present depending on which event type the user selects.
if (!empty($sub->groupcourseid)) {
$sub->courseid = $sub->groupcourseid;
unset($sub->groupcourseid);
}
// Pull the group id back out of the value. The form saves the value
// as "<courseid>-<groupid>" to allow the javascript to work correctly.
if (!empty($sub->groupid)) {
list($courseid, $groupid) = explode('-', $sub->groupid);
$sub->courseid = $courseid;
$sub->groupid = $groupid;
}
// Default course id if none is set.
if (empty($sub->courseid)) {
if ($sub->eventtype === 'site') {
$sub->courseid = SITEID;
} else {
$sub->courseid = 0;
}
}
if ($sub->eventtype === 'site') {
$sub->courseid = $SITE->id;
} else if ($sub->eventtype === 'group' || $sub->eventtype === 'course') {
$sub->courseid = $sub->course;
$sub->courseid = $sub->courseid;
} else if ($sub->eventtype === 'category') {
$sub->categoryid = $sub->category;
$sub->categoryid = $sub->categoryid;
} else {
// User events.
$sub->courseid = 0;
@ -2689,8 +2713,25 @@ function calendar_add_subscription($sub) {
// Trigger event, calendar subscription added.
$eventparams = array('objectid' => $sub->id,
'context' => calendar_get_calendar_context($sub),
'other' => array('eventtype' => $sub->eventtype, 'courseid' => $sub->courseid)
'other' => array(
'eventtype' => $sub->eventtype,
)
);
switch ($sub->eventtype) {
case 'category':
$eventparams['other']['categoryid'] = $sub->categoryid;
break;
case 'course':
$eventparams['other']['courseid'] = $sub->courseid;
break;
case 'group':
$eventparams['other']['courseid'] = $sub->courseid;
$eventparams['other']['groupid'] = $sub->groupid;
break;
default:
$eventparams['other']['courseid'] = $sub->courseid;
}
$event = \core\event\calendar_subscription_created::create($eventparams);
$event->trigger();
return $id;
@ -2708,13 +2749,13 @@ function calendar_add_subscription($sub) {
* Add an iCalendar event to the Moodle calendar.
*
* @param stdClass $event The RFC-2445 iCalendar event
* @param int $courseid The course ID
* @param int $unused Deprecated
* @param int $subscriptionid The iCalendar subscription ID
* @param string $timezone The X-WR-TIMEZONE iCalendar property if provided
* @throws dml_exception A DML specific exception is thrown for invalid subscriptionids.
* @return int Code: CALENDAR_IMPORT_EVENT_UPDATED = updated, CALENDAR_IMPORT_EVENT_INSERTED = inserted, 0 = error
*/
function calendar_add_icalendar_event($event, $courseid, $subscriptionid, $timezone='UTC') {
function calendar_add_icalendar_event($event, $unused = null, $subscriptionid, $timezone='UTC') {
global $DB;
// Probably an unsupported X-MICROSOFT-CDO-BUSYSTATUS event.
@ -2787,6 +2828,7 @@ function calendar_add_icalendar_event($event, $courseid, $subscriptionid, $timez
$eventrecord->userid = $sub->userid;
$eventrecord->groupid = $sub->groupid;
$eventrecord->courseid = $sub->courseid;
$eventrecord->categoryid = $sub->categoryid;
$eventrecord->eventtype = $sub->eventtype;
if ($updaterecord = $DB->get_record('event', array('uuid' => $eventrecord->uuid,
@ -2867,8 +2909,24 @@ function calendar_delete_subscription($subscription) {
// Trigger event, calendar subscription deleted.
$eventparams = array('objectid' => $subscription->id,
'context' => calendar_get_calendar_context($subscription),
'other' => array('courseid' => $subscription->courseid)
'other' => array(
'eventtype' => $subscription->eventtype,
)
);
switch ($subscription->eventtype) {
case 'category':
$eventparams['other']['categoryid'] = $subscription->categoryid;
break;
case 'course':
$eventparams['other']['courseid'] = $subscription->courseid;
break;
case 'group':
$eventparams['other']['courseid'] = $subscription->courseid;
$eventparams['other']['groupid'] = $subscription->groupid;
break;
default:
$eventparams['other']['courseid'] = $subscription->courseid;
}
$event = \core\event\calendar_subscription_deleted::create($eventparams);
$event->trigger();
}
@ -2907,7 +2965,7 @@ function calendar_get_icalendar($url) {
* @param int $subscriptionid The subscription ID.
* @return string A log of the import progress, including errors.
*/
function calendar_import_icalendar_events($ical, $courseid, $subscriptionid = null) {
function calendar_import_icalendar_events($ical, $unused = null, $subscriptionid = null) {
global $DB;
$return = '';
@ -2934,7 +2992,7 @@ function calendar_import_icalendar_events($ical, $courseid, $subscriptionid = nu
$return = '';
foreach ($ical->components['VEVENT'] as $event) {
$res = calendar_add_icalendar_event($event, $courseid, $subscriptionid, $timezone);
$res = calendar_add_icalendar_event($event, null, $subscriptionid, $timezone);
switch ($res) {
case CALENDAR_IMPORT_EVENT_UPDATED:
$updatecount++;
@ -2984,7 +3042,7 @@ function calendar_update_subscription_events($subscriptionid) {
}
$ical = calendar_get_icalendar($sub->url);
$return = calendar_import_icalendar_events($ical, $sub->courseid, $subscriptionid);
$return = calendar_import_icalendar_events($ical, null, $subscriptionid);
$sub->lastupdated = time();
calendar_update_subscription($sub);
@ -3019,8 +3077,24 @@ function calendar_update_subscription($subscription) {
$eventparams = array('userid' => $subscription->userid,
'objectid' => $subscription->id,
'context' => calendar_get_calendar_context($subscription),
'other' => array('eventtype' => $subscription->eventtype, 'courseid' => $subscription->courseid)
'other' => array(
'eventtype' => $subscription->eventtype,
)
);
switch ($subscription->eventtype) {
case 'category':
$eventparams['other']['categoryid'] = $subscription->categoryid;
break;
case 'course':
$eventparams['other']['courseid'] = $subscription->courseid;
break;
case 'group':
$eventparams['other']['courseid'] = $subscription->courseid;
$eventparams['other']['groupid'] = $subscription->groupid;
break;
default:
$eventparams['other']['courseid'] = $subscription->courseid;
}
$event = \core\event\calendar_subscription_updated::create($eventparams);
$event->trigger();
}
@ -3042,9 +3116,14 @@ function calendar_can_edit_subscription($subscriptionorid) {
$allowed = new \stdClass;
$courseid = $subscription->courseid;
$categoryid = $subscription->categoryid;
$groupid = $subscription->groupid;
$category = null;
calendar_get_allowed_types($allowed, $courseid);
if (!empty($categoryid)) {
$category = \coursecat::get($categoryid);
}
calendar_get_allowed_types($allowed, $courseid, null, $category);
switch ($subscription->eventtype) {
case 'user':
return $allowed->user;
@ -3054,6 +3133,12 @@ function calendar_can_edit_subscription($subscriptionorid) {
} else {
return false;
}
case 'category':
if (isset($allowed->categories[$categoryid])) {
return $allowed->categories[$categoryid];
} else {
return false;
}
case 'site':
return $allowed->site;
case 'group':