MDL-57888 core_calendar: moved functions from calendar/lib.php
Part of MDL-55611 epic.
This commit is contained in:
committed by
Damyon Wiese
parent
e46efe3a72
commit
12cbce0aa3
@@ -70,22 +70,25 @@ class block_calendar_month extends block_base {
|
||||
if ($issite) {
|
||||
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
|
||||
// the list of courses it will be grabbing events from.
|
||||
$filtercourse = calendar_get_default_courses();
|
||||
$filtercourse = \core_calendar\api::get_default_courses();
|
||||
} else {
|
||||
// Forcibly filter events to include only those from the particular course we are in.
|
||||
$filtercourse = array($courseid => $this->page->course);
|
||||
}
|
||||
|
||||
list($courses, $group, $user) = calendar_set_filters($filtercourse);
|
||||
list($courses, $group, $user) = \core_calendar\api::set_filters($filtercourse);
|
||||
if ($issite) {
|
||||
// For the front page.
|
||||
$this->content->text .= calendar_get_mini($courses, $group, $user, false, false, 'frontpage', $courseid, $time);
|
||||
$this->content->text .= \core_calendar\api::get_mini_calendar($courses, $group, $user, false, false,
|
||||
'frontpage', $courseid, $time);
|
||||
// No filters for now.
|
||||
} else {
|
||||
// For any other course.
|
||||
$this->content->text .= calendar_get_mini($courses, $group, $user, false, false, 'course', $courseid, $time);
|
||||
$this->content->text .= \core_calendar\api::get_mini_calendar($courses, $group, $user, false, false,
|
||||
'course', $courseid, $time);
|
||||
$this->content->text .= '<h3 class="eventskey">'.get_string('eventskey', 'calendar').'</h3>';
|
||||
$this->content->text .= '<div class="filters calendar_filters">'.calendar_filter_controls($this->page->url).'</div>';
|
||||
$this->content->text .= '<div class="filters calendar_filters">' .
|
||||
\core_calendar\api::get_filter_controls($this->page->url) . '</div>';
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
|
||||
@@ -65,14 +65,14 @@ class block_calendar_upcoming extends block_base {
|
||||
if ($courseshown == SITEID) {
|
||||
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
|
||||
// the list of courses it will be grabbing events from.
|
||||
$filtercourse = calendar_get_default_courses();
|
||||
$filtercourse = \core_calendar\api::get_default_courses();
|
||||
} else {
|
||||
// Forcibly filter events to include only those from the particular course we are in.
|
||||
$filtercourse = array($courseshown => $this->page->course);
|
||||
}
|
||||
}
|
||||
|
||||
list($courses, $group, $user) = calendar_set_filters($filtercourse);
|
||||
list($courses, $group, $user) = \core_calendar\api::set_filters($filtercourse);
|
||||
|
||||
$defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
|
||||
if (isset($CFG->calendar_lookahead)) {
|
||||
@@ -85,12 +85,12 @@ class block_calendar_upcoming extends block_base {
|
||||
$defaultmaxevents = intval($CFG->calendar_maxevents);
|
||||
}
|
||||
$maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
|
||||
$events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents);
|
||||
$events = \core_calendar\api::get_upcoming($courses, $group, $user, $lookahead, $maxevents);
|
||||
|
||||
if (!empty($this->instance)) {
|
||||
$link = 'view.php?view=day&course='.$courseshown.'&';
|
||||
$showcourselink = ($this->page->course->id == SITEID);
|
||||
$this->content->text = calendar_get_block_upcoming($events, $link, $showcourselink);
|
||||
$this->content->text = self::get_upcoming_content($events, $link, $showcourselink);
|
||||
}
|
||||
|
||||
if (empty($this->content->text)) {
|
||||
@@ -99,6 +99,54 @@ class block_calendar_upcoming extends block_base {
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upcoming event block content.
|
||||
*
|
||||
* @param array $events list of events
|
||||
* @param \moodle_url|string $linkhref link to event referer
|
||||
* @param boolean $showcourselink whether links to courses should be shown
|
||||
* @return string|null $content html block content
|
||||
*/
|
||||
public static function get_upcoming_content($events, $linkhref = null, $showcourselink = false) {
|
||||
$content = '';
|
||||
$lines = count($events);
|
||||
|
||||
if (!$lines) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $lines; ++$i) {
|
||||
if (!isset($events[$i]->time)) {
|
||||
continue;
|
||||
}
|
||||
$events[$i] = \core_calendar\api::add_event_metadata($events[$i]);
|
||||
$content .= '<div class="event"><span class="icon c0">' . $events[$i]->icon . '</span>';
|
||||
if (!empty($events[$i]->referer)) {
|
||||
// That's an activity event, so let's provide the hyperlink.
|
||||
$content .= $events[$i]->referer;
|
||||
} else {
|
||||
if (!empty($linkhref)) {
|
||||
$href = \core_calendar\api::get_link_href(new \moodle_url(CALENDAR_URL . $linkhref), 0, 0, 0,
|
||||
$events[$i]->timestart);
|
||||
$href->set_anchor('event_' . $events[$i]->id);
|
||||
$content .= \html_writer::link($href, $events[$i]->name);
|
||||
} else {
|
||||
$content .= $events[$i]->name;
|
||||
}
|
||||
}
|
||||
$events[$i]->time = str_replace('»', '<br />»', $events[$i]->time);
|
||||
if ($showcourselink && !empty($events[$i]->courselink)) {
|
||||
$content .= \html_writer::div($events[$i]->courselink, 'course');
|
||||
}
|
||||
$content .= '<div class="date">' . $events[$i]->time . '</div></div>';
|
||||
if ($i < $lines - 1) {
|
||||
$content .= '<hr />';
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -78,7 +78,7 @@ class event {
|
||||
}
|
||||
|
||||
if (!empty($data->subscriptionid)) {
|
||||
$data->subscription = calendar_get_subscription($data->subscriptionid);
|
||||
$data->subscription = api::get_subscription($data->subscriptionid);
|
||||
}
|
||||
|
||||
// Default to a user event.
|
||||
@@ -306,7 +306,7 @@ class event {
|
||||
if (empty($this->properties->id) || $this->properties->id < 1) {
|
||||
|
||||
if ($checkcapability) {
|
||||
if (!calendar_add_event_allowed($this->properties)) {
|
||||
if (!\core_calendar\api::can_add_event($this->properties)) {
|
||||
print_error('nopermissiontoupdatecalendar');
|
||||
}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ class event {
|
||||
} else {
|
||||
|
||||
if ($checkcapability) {
|
||||
if (!calendar_edit_event_allowed($this->properties)) {
|
||||
if (!api::can_edit_event($this->properties)) {
|
||||
print_error('nopermissiontoupdatecalendar');
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ if (!$course) {
|
||||
}
|
||||
|
||||
// Check the user has the required capabilities to edit an event
|
||||
if (!calendar_edit_event_allowed($event)) {
|
||||
if (!\core_calendar\api::can_edit_event($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -94,7 +94,7 @@ if ($courseid != SITEID && !empty($courseid)) {
|
||||
$issite = false;
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
$courses = \core_calendar\api::get_default_courses();
|
||||
$issite = true;
|
||||
}
|
||||
require_login($course, false);
|
||||
@@ -114,7 +114,7 @@ $formoptions = new stdClass;
|
||||
if ($eventid !== 0) {
|
||||
$title = get_string('editevent', 'calendar');
|
||||
$event = \core_calendar\event::load($eventid);
|
||||
if (!calendar_edit_event_allowed($event)) {
|
||||
if (!\core_calendar\api::can_edit_event($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
$event->action = $action;
|
||||
@@ -122,7 +122,7 @@ if ($eventid !== 0) {
|
||||
$event->timedurationuntil = $event->timestart + $event->timeduration;
|
||||
$event->count_repeats();
|
||||
|
||||
if (!calendar_add_event_allowed($event)) {
|
||||
if (!\core_calendar\api::can_add_event($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ if ($eventid !== 0) {
|
||||
|
||||
} else {
|
||||
$title = get_string('newevent', 'calendar');
|
||||
calendar_get_allowed_types($formoptions->eventtypes, $course);
|
||||
\core_calendar\api::get_allowed_types($formoptions->eventtypes, $course);
|
||||
$event = new stdClass();
|
||||
$event->action = $action;
|
||||
$event->course = $courseid;
|
||||
@@ -150,7 +150,7 @@ if ($eventid !== 0) {
|
||||
}
|
||||
$event->timestart = $time;
|
||||
$event = new \core_calendar\event($event);
|
||||
if (!calendar_add_event_allowed($event)) {
|
||||
if (!\core_calendar\api::can_add_event($event)) {
|
||||
print_error('nopermissions');
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -82,7 +82,7 @@ if ($courseid != SITEID && !empty($courseid)) {
|
||||
$issite = false;
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
$courses = \core_calendar\api::get_default_courses();
|
||||
$issite = true;
|
||||
}
|
||||
require_course_login($course);
|
||||
@@ -108,7 +108,7 @@ if ($issite) {
|
||||
$PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
$link = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$calendar->courseid));
|
||||
$PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time));
|
||||
$PAGE->navbar->add(get_string('calendar', 'calendar'), \core_calendar\api::get_link_href($link, 0, 0, 0, $time));
|
||||
$PAGE->navbar->add($pagetitle);
|
||||
|
||||
$PAGE->set_title($course->shortname.': '.get_string('calendar', 'calendar').': '.$pagetitle);
|
||||
@@ -133,7 +133,7 @@ $formdata = array(
|
||||
// If today it's weekend, give the "next week" option.
|
||||
'allownextweek' => $weekend & (1 << $now['wday']),
|
||||
// If it's the last week of the month, give the "next month" option.
|
||||
'allownextmonth' => calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek,
|
||||
'allownextmonth' => \core_calendar\api::get_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek,
|
||||
// If today it's weekend but tomorrow it isn't, do NOT give the "this week" option.
|
||||
'allowthisweek' => !(($weekend & (1 << $now['wday'])) && !($weekend & (1 << (($now['wday'] + 1) % $numberofdaysinweek))))
|
||||
);
|
||||
|
||||
+16
-15
@@ -60,7 +60,8 @@ if (!empty($generateurl)) {
|
||||
if(!empty($what) && !empty($time)) {
|
||||
if(in_array($what, $allowed_what) && in_array($time, $allowed_time)) {
|
||||
$courses = enrol_get_users_courses($user->id, true, 'id, visible, shortname');
|
||||
// Array of courses that we will pass to calendar_get_events() which is initially set to the list of the user's courses.
|
||||
// Array of courses that we will pass to \core_calendar\api::get_events() which
|
||||
// is initially set to the list of the user's courses.
|
||||
$paramcourses = $courses;
|
||||
if ($what == 'all' || $what == 'groups') {
|
||||
$groups = array();
|
||||
@@ -94,12 +95,12 @@ if(!empty($what) && !empty($time)) {
|
||||
|
||||
switch($time) {
|
||||
case 'weeknow':
|
||||
$startweekday = calendar_get_starting_weekday();
|
||||
$startweekday = \core_calendar\api::get_starting_weekday();
|
||||
$startmonthday = find_day_in_month($now['mday'] - ($numberofdaysinweek - 1), $startweekday, $now['mon'], $now['year']);
|
||||
$startmonth = $now['mon'];
|
||||
$startyear = $now['year'];
|
||||
if($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
|
||||
if ($startmonthday > \core_calendar\api::get_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = \core_calendar\api::get_next_month($startmonth, $startyear);
|
||||
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($startyear, $startmonth, $startmonthday);
|
||||
@@ -109,8 +110,8 @@ if(!empty($what) && !empty($time)) {
|
||||
$endmonthday = $startmonthday + $numberofdaysinweek;
|
||||
$endmonth = $startmonth;
|
||||
$endyear = $startyear;
|
||||
if($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
|
||||
if ($endmonthday > \core_calendar\api::get_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = \core_calendar\api::get_next_month($endmonth, $endyear);
|
||||
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($endyear, $endmonth, $endmonthday);
|
||||
@@ -118,12 +119,12 @@ if(!empty($what) && !empty($time)) {
|
||||
$gregoriandate['hour'], $gregoriandate['minute']);
|
||||
break;
|
||||
case 'weeknext':
|
||||
$startweekday = calendar_get_starting_weekday();
|
||||
$startweekday = \core_calendar\api::get_starting_weekday();
|
||||
$startmonthday = find_day_in_month($now['mday'] + 1, $startweekday, $now['mon'], $now['year']);
|
||||
$startmonth = $now['mon'];
|
||||
$startyear = $now['year'];
|
||||
if($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
|
||||
if ($startmonthday > \core_calendar\api::get_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = \core_calendar\api::get_next_month($startmonth, $startyear);
|
||||
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($startyear, $startmonth, $startmonthday);
|
||||
@@ -133,8 +134,8 @@ if(!empty($what) && !empty($time)) {
|
||||
$endmonthday = $startmonthday + $numberofdaysinweek;
|
||||
$endmonth = $startmonth;
|
||||
$endyear = $startyear;
|
||||
if($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
|
||||
if ($endmonthday > \core_calendar\api::get_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = \core_calendar\api::get_next_month($endmonth, $endyear);
|
||||
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($endyear, $endmonth, $endmonthday);
|
||||
@@ -147,11 +148,11 @@ if(!empty($what) && !empty($time)) {
|
||||
|
||||
$timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
|
||||
$gregoriandate['hour'], $gregoriandate['minute']);
|
||||
$timeend = $timestart + (calendar_days_in_month($now['mon'], $now['year']) * DAYSECS);
|
||||
$timeend = $timestart + (\core_calendar\api::get_days_in_month($now['mon'], $now['year']) * DAYSECS);
|
||||
break;
|
||||
case 'monthnext':
|
||||
// Get the next month for this calendar.
|
||||
list($nextmonth, $nextyear) = calendar_add_month($now['mon'], $now['year']);
|
||||
list($nextmonth, $nextyear) = \core_calendar\api::get_next_month($now['mon'], $now['year']);
|
||||
|
||||
// Convert to gregorian.
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($nextyear, $nextmonth, 1);
|
||||
@@ -159,7 +160,7 @@ if(!empty($what) && !empty($time)) {
|
||||
// Create the timestamps.
|
||||
$timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
|
||||
$gregoriandate['hour'], $gregoriandate['minute']);
|
||||
$timeend = $timestart + (calendar_days_in_month($nextmonth, $nextyear) * DAYSECS);
|
||||
$timeend = $timestart + (\core_calendar\api::get_days_in_month($nextmonth, $nextyear) * DAYSECS);
|
||||
break;
|
||||
case 'recentupcoming':
|
||||
//Events in the last 5 or next 60 days
|
||||
@@ -179,7 +180,7 @@ if(!empty($what) && !empty($time)) {
|
||||
die();
|
||||
}
|
||||
}
|
||||
$events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys($paramcourses), false);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, $users, $groups, array_keys($paramcourses), false);
|
||||
|
||||
$ical = new iCalendar;
|
||||
$ical->add_property('method', 'PUBLISH');
|
||||
|
||||
@@ -81,7 +81,7 @@ class core_calendar_external extends external_api {
|
||||
$eventobj = \core_calendar\event::load($event['eventid']);
|
||||
|
||||
// Let's check if the user is allowed to delete an event.
|
||||
if (!calendar_edit_event_allowed($eventobj)) {
|
||||
if (!\core_calendar\api::can_edit_event($eventobj)) {
|
||||
throw new moodle_exception("nopermissions");
|
||||
}
|
||||
// Time to do the magic.
|
||||
@@ -228,14 +228,14 @@ class core_calendar_external extends external_api {
|
||||
}
|
||||
|
||||
// Event list does not check visibility and permissions, we'll check that later.
|
||||
$eventlist = calendar_get_events($params['options']['timestart'], $params['options']['timeend'], $funcparam['users'], $funcparam['groups'],
|
||||
$funcparam['courses'], true, $params['options']['ignorehidden']);
|
||||
$eventlist = \core_calendar\api::get_events($params['options']['timestart'], $params['options']['timeend'],
|
||||
$funcparam['users'], $funcparam['groups'], $funcparam['courses'], true, $params['options']['ignorehidden']);
|
||||
|
||||
// WS expects arrays.
|
||||
$events = array();
|
||||
|
||||
// We need to get events asked for eventids.
|
||||
if ($eventsbyid = calendar_get_events_by_id($params['events']['eventids'])) {
|
||||
if ($eventsbyid = \core_calendar\api::get_events_by_id($params['events']['eventids'])) {
|
||||
$eventlist += $eventsbyid;
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ class core_calendar_external extends external_api {
|
||||
(!empty($eventobj->groupid) && in_array($eventobj->groupid, $groups)) ||
|
||||
(!empty($eventobj->courseid) && in_array($eventobj->courseid, $courses)) ||
|
||||
($USER->id == $eventobj->userid) ||
|
||||
(calendar_edit_event_allowed($eventid))) {
|
||||
(\core_calendar\api::can_edit_event($eventid))) {
|
||||
$events[$eventid] = $event;
|
||||
} else {
|
||||
$warnings[] = array('item' => $eventid, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to view this event');
|
||||
@@ -373,7 +373,7 @@ class core_calendar_external extends external_api {
|
||||
$eventobj = new \core_calendar\event($event);
|
||||
|
||||
// Let's check if the user is allowed to delete an event.
|
||||
if (!calendar_add_event_allowed($eventobj)) {
|
||||
if (!\core_calendar\api::can_add_event($eventobj)) {
|
||||
$warnings [] = array('item' => $event['name'], 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to create this event');
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-2394
File diff suppressed because it is too large
Load Diff
@@ -49,10 +49,10 @@ if ($courseid != SITEID && !empty($courseid)) {
|
||||
$courses = array($course->id => $course);
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
$courses = \core_calendar\api::get_default_courses();
|
||||
}
|
||||
require_course_login($course);
|
||||
if (!calendar_user_can_add_event($course)) {
|
||||
if (!\core_calendar\api::can_add_event_to_course($course)) {
|
||||
print_error('errorcannotimport', 'calendar');
|
||||
}
|
||||
|
||||
@@ -66,20 +66,20 @@ $importresults = '';
|
||||
$formdata = $form->get_data();
|
||||
if (!empty($formdata)) {
|
||||
require_sesskey(); // Must have sesskey for all actions.
|
||||
$subscriptionid = calendar_add_subscription($formdata);
|
||||
$subscriptionid = \core_calendar\api::add_subscription($formdata);
|
||||
if ($formdata->importfrom == CALENDAR_IMPORT_FROM_FILE) {
|
||||
// Blank the URL if it's a file import.
|
||||
$formdata->url = '';
|
||||
$calendar = $form->get_file_content('importfile');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid);
|
||||
$importresults = \core_calendar\api::import_icalendar_events($ical, $courseid, $subscriptionid);
|
||||
} else {
|
||||
try {
|
||||
$importresults = calendar_update_subscription_events($subscriptionid);
|
||||
$importresults = \core_calendar\api::update_subscription_events($subscriptionid);
|
||||
} catch (moodle_exception $e) {
|
||||
// Delete newly added subscription and show invalid url error.
|
||||
calendar_delete_subscription($subscriptionid);
|
||||
\core_calendar\api::delete_subscription($subscriptionid);
|
||||
print_error($e->errorcode, $e->module, $PAGE->url);
|
||||
}
|
||||
}
|
||||
@@ -88,9 +88,9 @@ if (!empty($formdata)) {
|
||||
} else if (!empty($subscriptionid)) {
|
||||
// The user is wanting to perform an action upon an existing subscription.
|
||||
require_sesskey(); // Must have sesskey for all actions.
|
||||
if (calendar_can_edit_subscription($subscriptionid)) {
|
||||
if (\core_calendar\api::can_edit_subscription($subscriptionid)) {
|
||||
try {
|
||||
$importresults = calendar_process_subscription_row($subscriptionid, $pollinterval, $action);
|
||||
$importresults = \core_calendar\api::process_subscription_row($subscriptionid, $pollinterval, $action);
|
||||
} catch (moodle_exception $e) {
|
||||
// If exception caught, then user should be redirected to page where he/she came from.
|
||||
print_error($e->errorcode, $e->module, $PAGE->url);
|
||||
@@ -117,7 +117,7 @@ echo $OUTPUT->header();
|
||||
|
||||
// Filter subscriptions which user can't edit.
|
||||
foreach($subscriptions as $subscription) {
|
||||
if (!calendar_can_edit_subscription($subscription)) {
|
||||
if (!\core_calendar\api::can_edit_subscription($subscription)) {
|
||||
unset($subscriptions[$subscription->id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class calendar_addsubscription_form extends moodleform {
|
||||
$mform->setForceLtr('url');
|
||||
|
||||
// Poll interval
|
||||
$choices = calendar_get_pollinterval_choices();
|
||||
$choices = \core_calendar\api::get_poll_interval_choices();
|
||||
$mform->addElement('select', 'pollinterval', get_string('pollinterval', 'calendar'), $choices);
|
||||
$mform->setDefault('pollinterval', 604800);
|
||||
$mform->addHelpButton('pollinterval', 'pollinterval', 'calendar');
|
||||
@@ -78,7 +78,7 @@ class calendar_addsubscription_form extends moodleform {
|
||||
$mform->disabledIf('importfile', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_URL);
|
||||
|
||||
// Eventtype: 0 = user, 1 = global, anything else = course ID.
|
||||
list($choices, $groups) = calendar_get_eventtype_choices($courseid);
|
||||
list($choices, $groups) = \core_calendar\api::get_event_type_choices($courseid);
|
||||
$mform->addElement('select', 'eventtype', get_string('eventkind', 'calendar'), $choices);
|
||||
$mform->addRule('eventtype', get_string('required'), 'required');
|
||||
$mform->setType('eventtype', PARAM_ALPHA);
|
||||
|
||||
+38
-25
@@ -64,7 +64,8 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
|
||||
$returnurl = $this->page->url;
|
||||
$returnurl->param('course', $courseid);
|
||||
return html_writer::tag('div', calendar_filter_controls($returnurl), array('class'=>'calendar_filters filters'));
|
||||
return html_writer::tag('div', \core_calendar\api::get_filter_controls($returnurl),
|
||||
array('class' => 'calendar_filters filters'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,24 +82,27 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
|
||||
$date = $calendartype->timestamp_to_date_array($calendar->time);
|
||||
|
||||
$prevmonth = calendar_sub_month($date['mon'], $date['year']);
|
||||
$prevmonth = \core_calendar\api::get_prev_month($date['mon'], $date['year']);
|
||||
$prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1);
|
||||
$prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'],
|
||||
$prevmonthtime['hour'], $prevmonthtime['minute']);
|
||||
|
||||
$nextmonth = calendar_add_month($date['mon'], $date['year']);
|
||||
$nextmonth = \core_calendar\api::get_next_month($date['mon'], $date['year']);
|
||||
$nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1);
|
||||
$nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'],
|
||||
$nextmonthtime['hour'], $nextmonthtime['minute']);
|
||||
|
||||
$content = html_writer::start_tag('div', array('class' => 'minicalendarblock'));
|
||||
$content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, false, false, 'display', $calendar->courseid, $prevmonthtime);
|
||||
$content .= \core_calendar\api::get_mini_calendar($calendar->courses, $calendar->groups, $calendar->users,
|
||||
false, false, 'display', $calendar->courseid, $prevmonthtime);
|
||||
$content .= html_writer::end_tag('div');
|
||||
$content .= html_writer::start_tag('div', array('class' => 'minicalendarblock'));
|
||||
$content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, false, false, 'display', $calendar->courseid, $calendar->time);
|
||||
$content .= \core_calendar\api::get_mini_calendar($calendar->courses, $calendar->groups, $calendar->users,
|
||||
false, false, 'display', $calendar->courseid, $calendar->time);
|
||||
$content .= html_writer::end_tag('div');
|
||||
$content .= html_writer::start_tag('div', array('class' => 'minicalendarblock'));
|
||||
$content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, false, false, 'display', $calendar->courseid, $nextmonthtime);
|
||||
$content .= \core_calendar\api::get_mini_calendar($calendar->courses, $calendar->groups, $calendar->users,
|
||||
false, false, 'display', $calendar->courseid, $nextmonthtime);
|
||||
$content .= html_writer::end_tag('div');
|
||||
return $content;
|
||||
}
|
||||
@@ -164,16 +168,18 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
$returnurl = $this->page->url;
|
||||
}
|
||||
|
||||
$events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today());
|
||||
$events = \core_calendar\api::get_upcoming($calendar->courses, $calendar->groups, $calendar->users,
|
||||
1, 100, $calendar->timestamp_today());
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'header'));
|
||||
$output .= $this->course_filter_selector($returnurl, get_string('dayviewfor', 'calendar'));
|
||||
if (calendar_user_can_add_event($calendar->course)) {
|
||||
if (\core_calendar\api::can_add_event_to_course($calendar->course)) {
|
||||
$output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
|
||||
}
|
||||
$output .= html_writer::end_tag('div');
|
||||
// Controls
|
||||
$output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'time' => $calendar->time)), array('class'=>'controls'));
|
||||
$output .= html_writer::tag('div', \core_calendar\api::get_top_controls('day', array('id' => $calendar->courseid,
|
||||
'time' => $calendar->time)), array('class' => 'controls'));
|
||||
|
||||
if (empty($events)) {
|
||||
// There is nothing to display today.
|
||||
@@ -186,7 +192,8 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
$event = new \core_calendar\event($event);
|
||||
$event->calendarcourseid = $calendar->courseid;
|
||||
if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now
|
||||
$event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
|
||||
$event->time = \core_calendar\api::get_format_event_time($event, time(), null, false,
|
||||
$calendar->timestamp_today());
|
||||
$output .= $this->event($event);
|
||||
} else { // Save this for later
|
||||
$underway[] = $event;
|
||||
@@ -198,7 +205,8 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
$output .= html_writer::span(get_string('spanningevents', 'calendar'),
|
||||
'calendar-information calendar-span-multiple-days');
|
||||
foreach ($underway as $event) {
|
||||
$event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
|
||||
$event->time = \core_calendar\api::get_format_event_time($event, time(), null, false,
|
||||
$calendar->timestamp_today());
|
||||
$output .= $this->event($event);
|
||||
}
|
||||
}
|
||||
@@ -219,12 +227,12 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
public function event(\core_calendar\event $event, $showactions=true) {
|
||||
global $CFG;
|
||||
|
||||
$event = calendar_add_event_metadata($event);
|
||||
$event = \core_calendar\api::add_event_metadata($event);
|
||||
$context = $event->context;
|
||||
$output = '';
|
||||
|
||||
$output .= $this->output->box_start('card-header clearfix');
|
||||
if (calendar_edit_event_allowed($event) && $showactions) {
|
||||
if (\core_calendar\api::can_edit_event($event) && $showactions) {
|
||||
if (empty($event->cmid)) {
|
||||
$editlink = new moodle_url(CALENDAR_URL.'event.php', array('action' => 'edit', 'id' => $event->id));
|
||||
$deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id' => $event->id));
|
||||
@@ -281,7 +289,7 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
$output .= html_writer::tag('span', $event->time, array('class' => 'date pull-xs-right m-r-1'));
|
||||
} else {
|
||||
$attrs = array('class' => 'date pull-xs-right m-r-1');
|
||||
$output .= html_writer::tag('span', calendar_time_representation($event->timestart), $attrs);
|
||||
$output .= html_writer::tag('span', \core_calendar\api::get_time_representation($event->timestart), $attrs);
|
||||
}
|
||||
if (!empty($event->courselink)) {
|
||||
$output .= html_writer::tag('div', $event->courselink, array('class' => 'course'));
|
||||
@@ -344,13 +352,13 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
// Get the starting week day for this month.
|
||||
$startwday = dayofweek(1, $date['mon'], $date['year']);
|
||||
// Get the days in a week.
|
||||
$daynames = calendar_get_days();
|
||||
$daynames = \core_calendar\api::get_days();
|
||||
// Store the number of days in a week.
|
||||
$numberofdaysinweek = $calendartype->get_num_weekdays();
|
||||
|
||||
$display->minwday = calendar_get_starting_weekday();
|
||||
$display->minwday = \core_calendar\api::get_starting_weekday();
|
||||
$display->maxwday = $display->minwday + ($numberofdaysinweek - 1);
|
||||
$display->maxdays = calendar_days_in_month($date['mon'], $date['year']);
|
||||
$display->maxdays = \core_calendar\api::get_days_in_month($date['mon'], $date['year']);
|
||||
|
||||
// These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
|
||||
$display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
|
||||
@@ -363,7 +371,8 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
}
|
||||
|
||||
// Get events from database
|
||||
$events = calendar_get_events($display->tstart, $display->tend, $calendar->users, $calendar->groups, $calendar->courses);
|
||||
$events = \core_calendar\api::get_events($display->tstart, $display->tend, $calendar->users, $calendar->groups,
|
||||
$calendar->courses);
|
||||
if (!empty($events)) {
|
||||
foreach($events as $eventid => $event) {
|
||||
$event = new \core_calendar\event($event);
|
||||
@@ -377,16 +386,18 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
}
|
||||
|
||||
// Extract information: events vs. time
|
||||
calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday, $typesbyday, $calendar->courses);
|
||||
\core_calendar\api::get_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday,
|
||||
$typesbyday, $calendar->courses);
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'header'));
|
||||
$output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar'));
|
||||
if (calendar_user_can_add_event($calendar->course)) {
|
||||
if (\core_calendar\api::can_add_event_to_course($calendar->course)) {
|
||||
$output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
|
||||
}
|
||||
$output .= html_writer::end_tag('div', array('class'=>'header'));
|
||||
// Controls
|
||||
$output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'time' => $calendar->time)), array('class' => 'controls'));
|
||||
$output .= html_writer::tag('div', \core_calendar\api::get_top_controls('month', array('id' => $calendar->courseid,
|
||||
'time' => $calendar->time)), array('class' => 'controls'));
|
||||
|
||||
$table = new html_table();
|
||||
$table->attributes = array('class'=>'calendarmonth calendartable');
|
||||
@@ -432,7 +443,8 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
|
||||
// Reset vars
|
||||
$cell = new html_table_cell();
|
||||
$dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
|
||||
$dayhref = \core_calendar\api::get_link_href(new moodle_url(CALENDAR_URL . 'view.php',
|
||||
array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
|
||||
|
||||
$cellclasses = array();
|
||||
|
||||
@@ -527,11 +539,12 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
$returnurl = $this->page->url;
|
||||
}
|
||||
|
||||
$events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, $futuredays, $maxevents);
|
||||
$events = \core_calendar\api::get_upcoming($calendar->courses, $calendar->groups, $calendar->users,
|
||||
$futuredays, $maxevents);
|
||||
|
||||
$output = html_writer::start_tag('div', array('class'=>'header'));
|
||||
$output .= $this->course_filter_selector($returnurl, get_string('upcomingeventsfor', 'calendar'));
|
||||
if (calendar_user_can_add_event($calendar->course)) {
|
||||
if (\core_calendar\api::can_add_event_to_course($calendar->course)) {
|
||||
$output .= $this->add_event_button($calendar->course->id);
|
||||
}
|
||||
$output .= html_writer::end_tag('div');
|
||||
@@ -673,7 +686,7 @@ class core_calendar_renderer extends plugin_renderer_base {
|
||||
// Assemble pollinterval control.
|
||||
$html .= html_writer::start_tag('div', array('style' => 'float:left;'));
|
||||
$html .= html_writer::start_tag('select', array('name' => 'pollinterval', 'class' => 'custom-select'));
|
||||
foreach (calendar_get_pollinterval_choices() as $k => $v) {
|
||||
foreach (\core_calendar\api::get_poll_interval_choices() as $k => $v) {
|
||||
$attributes = array();
|
||||
if ($k == $subscription->pollinterval) {
|
||||
$attributes['selected'] = 'selected';
|
||||
|
||||
+4
-4
@@ -61,16 +61,16 @@ $PAGE->set_context(context_system::instance());
|
||||
|
||||
switch($var) {
|
||||
case 'showgroups':
|
||||
calendar_set_event_type_display(CALENDAR_EVENT_GROUP);
|
||||
\core_calendar\api::set_event_type_display(CALENDAR_EVENT_GROUP);
|
||||
break;
|
||||
case 'showcourses':
|
||||
calendar_set_event_type_display(CALENDAR_EVENT_COURSE);
|
||||
\core_calendar\api::set_event_type_display(CALENDAR_EVENT_COURSE);
|
||||
break;
|
||||
case 'showglobal':
|
||||
calendar_set_event_type_display(CALENDAR_EVENT_GLOBAL);
|
||||
\core_calendar\api::set_event_type_display(CALENDAR_EVENT_GLOBAL);
|
||||
break;
|
||||
case 'showuser':
|
||||
calendar_set_event_type_display(CALENDAR_EVENT_USER);
|
||||
\core_calendar\api::set_event_type_display(CALENDAR_EVENT_USER);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,31 +15,32 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Calendar lib unit tests
|
||||
* Contains the class containing unit tests for the calendar API.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2013 Dan Poltawski <dan@moodle.com>
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
/**
|
||||
* Unit tests for calendar lib
|
||||
* Class contaning unit tests for the calendar API.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2013 Dan Poltawski <dan@moodle.com>
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_lib_testcase extends advanced_testcase {
|
||||
class core_calendar_api_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests set up
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
public function test_calendar_get_course_cached() {
|
||||
public function test_get_course_cached() {
|
||||
// Setup some test courses.
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
@@ -47,9 +48,9 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
|
||||
// Load courses into cache.
|
||||
$coursecache = null;
|
||||
calendar_get_course_cached($coursecache, $course1->id);
|
||||
calendar_get_course_cached($coursecache, $course2->id);
|
||||
calendar_get_course_cached($coursecache, $course3->id);
|
||||
\core_calendar\api::get_course_cached($coursecache, $course1->id);
|
||||
\core_calendar\api::get_course_cached($coursecache, $course2->id);
|
||||
\core_calendar\api::get_course_cached($coursecache, $course3->id);
|
||||
|
||||
// Verify the cache.
|
||||
$this->assertArrayHasKey($course1->id, $coursecache);
|
||||
@@ -72,51 +73,9 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar cron with a working subscription URL.
|
||||
* Test that the get_events() function only returns activity events that are enabled.
|
||||
*/
|
||||
public function test_calendar_cron_working_url() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/lib/cronlib.php');
|
||||
|
||||
// ICal URL from external test repo.
|
||||
$subscriptionurl = $this->getExternalTestFileUrl('/ical.ics');
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$subscription->url = $subscriptionurl;
|
||||
$subscription->pollinterval = 86400;
|
||||
$subscription->lastupdated = 0;
|
||||
calendar_add_subscription($subscription);
|
||||
|
||||
$this->expectOutputRegex('/Events imported: .* Events updated:/');
|
||||
calendar_cron();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar cron with a broken subscription URL.
|
||||
*/
|
||||
public function test_calendar_cron_broken_url() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/lib/cronlib.php');
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$subscription->url = 'brokenurl';
|
||||
$subscription->pollinterval = 86400;
|
||||
$subscription->lastupdated = 0;
|
||||
calendar_add_subscription($subscription);
|
||||
|
||||
$this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/');
|
||||
calendar_cron();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the calendar_get_events() function only returns activity
|
||||
* events that are enabled.
|
||||
*/
|
||||
public function test_calendar_get_events_with_disabled_module() {
|
||||
public function test_get_events_with_disabled_module() {
|
||||
global $DB;
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
@@ -124,7 +83,6 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
$student = $generator->create_user();
|
||||
$generator->enrol_user($student->id, $course->id, 'student');
|
||||
$this->setUser($student);
|
||||
|
||||
$events = [
|
||||
[
|
||||
'name' => 'Start of assignment',
|
||||
@@ -140,7 +98,6 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
'timeduration' => 86400,
|
||||
'visible' => 1
|
||||
], [
|
||||
|
||||
'name' => 'Start of lesson',
|
||||
'description' => '',
|
||||
'format' => 1,
|
||||
@@ -155,25 +112,20 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
'visible' => 1
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
\core_calendar\event::create($event, false);
|
||||
}
|
||||
|
||||
$timestart = time() - 60;
|
||||
$timeend = time() + 60;
|
||||
|
||||
// Get all events.
|
||||
$events = calendar_get_events($timestart, $timeend, true, 0, true);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, true, 0, true);
|
||||
$this->assertCount(2, $events);
|
||||
|
||||
// Disable the lesson module.
|
||||
$modulerecord = $DB->get_record('modules', ['name' => 'lesson']);
|
||||
$modulerecord->visible = 0;
|
||||
$DB->update_record('modules', $modulerecord);
|
||||
|
||||
// Check that we only return the assign event.
|
||||
$events = calendar_get_events($timestart, $timeend, true, 0, true);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, true, 0, true);
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
$this->assertEquals('assign', $event->modulename);
|
||||
@@ -184,7 +136,6 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_calendar_get_events_with_overrides() {
|
||||
global $DB;
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course();
|
||||
$plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
@@ -192,31 +143,26 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
$params['course'] = $course->id;
|
||||
}
|
||||
$instance = $plugingenerator->create_instance($params);
|
||||
|
||||
// Create users.
|
||||
$useroverridestudent = $generator->create_user();
|
||||
$group1student = $generator->create_user();
|
||||
$group2student = $generator->create_user();
|
||||
$group12student = $generator->create_user();
|
||||
$nogroupstudent = $generator->create_user();
|
||||
|
||||
// Enrol users.
|
||||
$generator->enrol_user($useroverridestudent->id, $course->id, 'student');
|
||||
$generator->enrol_user($group1student->id, $course->id, 'student');
|
||||
$generator->enrol_user($group2student->id, $course->id, 'student');
|
||||
$generator->enrol_user($group12student->id, $course->id, 'student');
|
||||
$generator->enrol_user($nogroupstudent->id, $course->id, 'student');
|
||||
|
||||
// Create groups.
|
||||
$group1 = $generator->create_group(['courseid' => $course->id]);
|
||||
$group2 = $generator->create_group(['courseid' => $course->id]);
|
||||
|
||||
// Add members to groups.
|
||||
$generator->create_group_member(['groupid' => $group1->id, 'userid' => $group1student->id]);
|
||||
$generator->create_group_member(['groupid' => $group2->id, 'userid' => $group2student->id]);
|
||||
$generator->create_group_member(['groupid' => $group1->id, 'userid' => $group12student->id]);
|
||||
$generator->create_group_member(['groupid' => $group2->id, 'userid' => $group12student->id]);
|
||||
|
||||
$now = time();
|
||||
// Events with the same module name, instance and event type.
|
||||
$events = [
|
||||
@@ -277,48 +223,39 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
'priority' => 2,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\core_calendar\event::create($event, false);
|
||||
}
|
||||
|
||||
$timestart = $now - 100;
|
||||
$timeend = $now + (3 * 86400);
|
||||
|
||||
$groups = [$group1->id, $group2->id];
|
||||
|
||||
// Get user override events.
|
||||
$this->setUser($useroverridestudent);
|
||||
$events = calendar_get_events($timestart, $timeend, $useroverridestudent->id, $groups, $course->id);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, $useroverridestudent->id, $groups, $course->id);
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
$this->assertEquals('Assignment 1 due date - User override', $event->name);
|
||||
|
||||
// Get event for user with override but with the timestart and timeend parameters only covering the original event.
|
||||
$events = calendar_get_events($timestart, $now, $useroverridestudent->id, $groups, $course->id);
|
||||
$events = \core_calendar\api::get_events($timestart, $now, $useroverridestudent->id, $groups, $course->id);
|
||||
$this->assertCount(0, $events);
|
||||
|
||||
// Get events for user that does not belong to any group and has no user override events.
|
||||
$this->setUser($nogroupstudent);
|
||||
$events = calendar_get_events($timestart, $timeend, $nogroupstudent->id, $groups, $course->id);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, $nogroupstudent->id, $groups, $course->id);
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
$this->assertEquals('Assignment 1 due date', $event->name);
|
||||
|
||||
// Get events for user that belongs to groups A and B and has no user override events.
|
||||
$this->setUser($group12student);
|
||||
$events = calendar_get_events($timestart, $timeend, $group12student->id, $groups, $course->id);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, $group12student->id, $groups, $course->id);
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
$this->assertEquals('Assignment 1 due date - Group B override', $event->name);
|
||||
|
||||
// Get events for user that belongs to group A and has no user override events.
|
||||
$this->setUser($group1student);
|
||||
$events = calendar_get_events($timestart, $timeend, $group1student->id, $groups, $course->id);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, $group1student->id, $groups, $course->id);
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
$this->assertEquals('Assignment 1 due date - Group A override', $event->name);
|
||||
|
||||
// Add repeating events.
|
||||
$repeatingevents = [
|
||||
[
|
||||
@@ -353,11 +290,100 @@ class core_calendar_lib_testcase extends advanced_testcase {
|
||||
],
|
||||
];
|
||||
foreach ($repeatingevents as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\core_calendar\event::create($event, false);
|
||||
}
|
||||
|
||||
// Make sure repeating events are not filtered out.
|
||||
$events = calendar_get_events($timestart, $timeend, true, true, true);
|
||||
$events = \core_calendar\api::get_events($timestart, $timeend, true, true, true);
|
||||
$this->assertCount(3, $events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the update_subscription() function.
|
||||
*/
|
||||
public function test_update_subscription() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$id = \core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$subscription = \core_calendar\api::get_subscription($id);
|
||||
$subscription->name = 'awesome';
|
||||
\core_calendar\api::update_subscription($subscription);
|
||||
$sub = \core_calendar\api::get_subscription($id);
|
||||
$this->assertEquals($subscription->name, $sub->name);
|
||||
|
||||
$subscription = \core_calendar\api::get_subscription($id);
|
||||
$subscription->name = 'awesome2';
|
||||
$subscription->pollinterval = 604800;
|
||||
\core_calendar\api::update_subscription($subscription);
|
||||
$sub = \core_calendar\api::get_subscription($id);
|
||||
$this->assertEquals($subscription->name, $sub->name);
|
||||
$this->assertEquals($subscription->pollinterval, $sub->pollinterval);
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'awesome4';
|
||||
$this->expectException('coding_exception');
|
||||
\core_calendar\api::update_subscription($subscription);
|
||||
}
|
||||
|
||||
public function test_add_subscription() {
|
||||
global $DB, $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/lib/bennu/bennu.inc.php');
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Test for Microsoft Outlook 2010.
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'Microsoft Outlook 2010';
|
||||
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
|
||||
$subscription->eventtype = 'site';
|
||||
$id = \core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$this->assertEquals($ical->parser_errors, array());
|
||||
|
||||
$sub = \core_calendar\api::get_subscription($id);
|
||||
\core_calendar\api::import_icalendar_events($ical, $sub->courseid, $sub->id);
|
||||
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
|
||||
$this->assertEquals($count, 1);
|
||||
|
||||
// Test for OSX Yosemite.
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'OSX Yosemite';
|
||||
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
|
||||
$subscription->eventtype = 'site';
|
||||
$id = \core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$this->assertEquals($ical->parser_errors, array());
|
||||
|
||||
$sub = \core_calendar\api::get_subscription($id);
|
||||
\core_calendar\api::import_icalendar_events($ical, $sub->courseid, $sub->id);
|
||||
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
|
||||
$this->assertEquals($count, 1);
|
||||
|
||||
// Test for Google Gmail.
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'Google Gmail';
|
||||
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
|
||||
$subscription->eventtype = 'site';
|
||||
$id = \core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$this->assertEquals($ical->parser_errors, array());
|
||||
|
||||
$sub = \core_calendar\api::get_subscription($id);
|
||||
\core_calendar\api::import_icalendar_events($ical, $sub->courseid, $sub->id);
|
||||
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
|
||||
$this->assertEquals($count, 1);
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,6 @@ require_once($CFG->dirroot . '/calendar/tests/calendartype_test_example.php');
|
||||
require_once($CFG->libdir . '/form/dateselector.php');
|
||||
require_once($CFG->libdir . '/form/datetimeselector.php');
|
||||
|
||||
// Used to test the calendar/lib.php functions.
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
// Used to test the user datetime profile field.
|
||||
require_once($CFG->dirroot . '/user/profile/lib.php');
|
||||
require_once($CFG->dirroot . '/user/profile/definelib.php');
|
||||
@@ -108,8 +105,6 @@ class core_calendar_type_testcase extends advanced_testcase {
|
||||
* different calendar types.
|
||||
*/
|
||||
public function test_calendar_type_dateselector_elements() {
|
||||
global $CFG;
|
||||
|
||||
// We want to reset the test data after this run.
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -200,11 +195,11 @@ class core_calendar_type_testcase extends advanced_testcase {
|
||||
userdate($this->user->timecreated));
|
||||
|
||||
// Test the calendar/lib.php functions.
|
||||
$this->assertEquals($calendar->get_weekdays(), calendar_get_days());
|
||||
$this->assertEquals($calendar->get_starting_weekday(), calendar_get_starting_weekday());
|
||||
$this->assertEquals($calendar->get_num_days_in_month('1986', '9'), calendar_days_in_month('9', '1986'));
|
||||
$this->assertEquals($calendar->get_next_month('1986', '9'), calendar_add_month('9', '1986'));
|
||||
$this->assertEquals($calendar->get_prev_month('1986', '9'), calendar_sub_month('9', '1986'));
|
||||
$this->assertEquals($calendar->get_weekdays(), \core_calendar\api::get_days());
|
||||
$this->assertEquals($calendar->get_starting_weekday(), \core_calendar\api::get_starting_weekday());
|
||||
$this->assertEquals($calendar->get_num_days_in_month('1986', '9'), \core_calendar\api::get_days_in_month('9', '1986'));
|
||||
$this->assertEquals($calendar->get_next_month('1986', '9'), \core_calendar\api::get_next_month('9', '1986'));
|
||||
$this->assertEquals($calendar->get_prev_month('1986', '9'), \core_calendar\api::get_prev_month('9', '1986'));
|
||||
|
||||
// Test the lib/moodle.php functions.
|
||||
$this->assertEquals($calendar->get_num_days_in_month('1986', '9'), days_in_month('9', '1986'));
|
||||
|
||||
@@ -438,7 +438,7 @@ class core_calendar_events_testcase extends advanced_testcase {
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$id = calendar_add_subscription($subscription);
|
||||
$id = \core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
@@ -465,13 +465,13 @@ class core_calendar_events_testcase extends advanced_testcase {
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$subscription->courseid = $this->course->id;
|
||||
$subscription->id = calendar_add_subscription($subscription);
|
||||
$subscription->id = \core_calendar\api::add_subscription($subscription);
|
||||
// Now edit it.
|
||||
$subscription->name = 'awesome';
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
calendar_update_subscription($subscription);
|
||||
\core_calendar\api::update_subscription($subscription);
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
// Check that the event data is valid.
|
||||
@@ -497,11 +497,11 @@ class core_calendar_events_testcase extends advanced_testcase {
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$subscription->courseid = $this->course->id;
|
||||
$subscription->id = calendar_add_subscription($subscription);
|
||||
$subscription->id = \core_calendar\api::add_subscription($subscription);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
calendar_delete_subscription($subscription);
|
||||
\core_calendar\api::delete_subscription($subscription);
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
// Check that the event data is valid.
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Calendar Ical unit tests
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for ical APIs.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.5
|
||||
*/
|
||||
class core_calendar_ical_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests set up
|
||||
*/
|
||||
protected function setUp() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_calendar_update_subscription() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$id = calendar_add_subscription($subscription);
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription = calendar_get_subscription($id);
|
||||
$subscription->name = 'awesome';
|
||||
calendar_update_subscription($subscription);
|
||||
$sub = calendar_get_subscription($id);
|
||||
$this->assertEquals($subscription->name, $sub->name);
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription = calendar_get_subscription($id);
|
||||
$subscription->name = 'awesome2';
|
||||
$subscription->pollinterval = 604800;
|
||||
calendar_update_subscription($subscription);
|
||||
$sub = calendar_get_subscription($id);
|
||||
$this->assertEquals($subscription->name, $sub->name);
|
||||
$this->assertEquals($subscription->pollinterval, $sub->pollinterval);
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'awesome4';
|
||||
calendar_update_subscription($subscription);
|
||||
}
|
||||
|
||||
public function test_calendar_add_subscription() {
|
||||
global $DB, $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/lib/bennu/bennu.inc.php');
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Test for Microsoft Outlook 2010.
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'Microsoft Outlook 2010';
|
||||
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
|
||||
$subscription->eventtype = 'site';
|
||||
$id = calendar_add_subscription($subscription);
|
||||
|
||||
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$this->assertEquals($ical->parser_errors, array());
|
||||
|
||||
$sub = calendar_get_subscription($id);
|
||||
$result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
|
||||
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
|
||||
$this->assertEquals($count, 1);
|
||||
|
||||
// Test for OSX Yosemite.
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'OSX Yosemite';
|
||||
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
|
||||
$subscription->eventtype = 'site';
|
||||
$id = calendar_add_subscription($subscription);
|
||||
|
||||
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$this->assertEquals($ical->parser_errors, array());
|
||||
|
||||
$sub = calendar_get_subscription($id);
|
||||
$result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
|
||||
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
|
||||
$this->assertEquals($count, 1);
|
||||
|
||||
// Test for Google Gmail.
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'Google Gmail';
|
||||
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
|
||||
$subscription->eventtype = 'site';
|
||||
$id = calendar_add_subscription($subscription);
|
||||
|
||||
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics');
|
||||
$ical = new iCalendar();
|
||||
$ical->unserialize($calendar);
|
||||
$this->assertEquals($ical->parser_errors, array());
|
||||
|
||||
$sub = calendar_get_subscription($id);
|
||||
$result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
|
||||
$count = $DB->count_records('event', array('subscriptionid' => $sub->id));
|
||||
$this->assertEquals($count, 1);
|
||||
}
|
||||
}
|
||||
+51
-1
@@ -4,9 +4,59 @@ information provided here is intended especially for developers.
|
||||
=== 3.3 ===
|
||||
* calendar_event_hook() has been removed. Developers should be using the Moodle events system to achieve this behaviour,
|
||||
rather than using a hacky calendar specific implementation.
|
||||
* calendar_get_days() is deprecated, please use \core_calendar\api::get_days() instead.
|
||||
* calendar_get_subscription() is deprecated, please use \core_calendar\api::get_subscription() instead.
|
||||
* calendar_get_starting_weekday() is deprecated, please use \core_calendar\api::get_starting_weekday() instead.
|
||||
* calendar_get_mini() is deprecated, please use \core_calendar\api::get_mini_calendar() instead.
|
||||
* calendar_get_popup() is deprecated, please use \core_calendar\api::get_popup() instead.
|
||||
* calendar_get_upcoming() is deprecated, please use \core_calendar\api::get_upcoming() instead.
|
||||
* calendar_get_courselink() is deprecated, please use \core_calendar\api::get_courselink() instead.
|
||||
* calendar_get_module_cached() is deprecated, please use \core_calendar\api::get_module_cached() instead.
|
||||
* calendar_get_course_cached() is deprecated, please use \core_calendar\api::get_course_cached() instead.
|
||||
* calendar_get_group_cached() is deprecated, please use \core_calendar\api::get_group_cached() instead.
|
||||
* calendar_add_event_metadata() is deprecated, please use \core_calendar\api::add_event_metadata() instead.
|
||||
* calendar_get_events() is deprecated, please use \core_calendar\api::get_events() instead.
|
||||
* calendar_get_events_by_id() is deprecated, please use \core_calendar\api::get_events_by_id() instead.
|
||||
* calendar_top_controls() is deprecated, please use \core_calendar\api::get_top_controls() instead.
|
||||
* calendar_filter_controls_element() is deprecated, please use \core_calendar\api::get_filter_controls_element() instead.
|
||||
* calendar_filter_controls() is deprecated, please use \core_calendar\api::get_filter_controls() instead.
|
||||
* calendar_day_representation() is deprecated, please use \core_calendar\api::get_day_representation() instead.
|
||||
* calendar_time_representation() is deprecated, please use \core_calendar\api::get_time_representation() instead.
|
||||
* calendar_get_link_href() is deprecated, please use \core_calendar\api::get_link_href() instead.
|
||||
* calendar_get_link_previous() is deprecated, please use \core_calendar\api::get_link_previous() instead.
|
||||
* calendar_get_link_next() is deprecated, please use \core_calendar\api::get_link_next() instead.
|
||||
* calendar_wday_name() is deprecated and no longer used in core.
|
||||
* calendar_days_in_month() is deprecated, please use \core_calendar\api::get_days_in_month() instead.
|
||||
* calendar_get_block_upcoming() is deprecated, please use block_calendar_upcoming::get_upcoming_content() instead.
|
||||
* calendar_add_month() is deprecated, please use \core_calendar\api::get_next_month() instead.
|
||||
* calendar_sub_month() is deprecated, please use \core_calendar\api::get_prev_month() instead.
|
||||
* calendar_events_by_day() is deprecated, please use \core_calendar\api::get_events_by_day() instead.
|
||||
* calendar_set_filters() is deprecated, please use \core_calendar\api::set_filters() instead.
|
||||
* calendar_edit_event_allowed() is deprecated, please use \core_calendar\api::can_edit_event() instead.
|
||||
* calendar_get_default_courses() is deprecated, please use \core_calendar\api::get_default_courses() instead.
|
||||
* calendar_format_event_time() is deprecated, please use \core_calendar\api::get_format_event_time() instead.
|
||||
* calendar_print_month_selector() is deprecated and no longer used in core.
|
||||
* calendar_show_event_type() is deprecated, please use \core_calendar\api::show_event_type() instead.
|
||||
* calendar_set_event_type_display() is deprecated, please use \core_calendar\api::set_event_type_display() instead.
|
||||
* calendar_get_allowed_types() is deprecated, please use \core_calendar\api::get_allowed_types() instead.
|
||||
* calendar_user_can_add_event() is deprecated, please use \core_calendar\api::can_add_event_to_course() instead.
|
||||
* calendar_add_event_allowed() is deprecated, please use \core_calendar\api::can_add_event() instead.
|
||||
* calendar_get_pollinterval_choices() is deprecated, please use \core_calendar\api::get_poll_interval_choices() instead.
|
||||
* calendar_get_eventtype_choices() is deprecated, please use \core_calendar\api::get_event_type_choices() instead.
|
||||
* calendar_add_subscription() is deprecated, please use \core_calendar\api::add_subscription() instead.
|
||||
* calendar_add_icalendar_event() is deprecated, please use \core_calendar\api::add_icalendar_event() instead.
|
||||
* calendar_process_subscription_row() is deprecated, please use \core_calendar\api::process_subscription_row() instead.
|
||||
* calendar_delete_subscription() is deprecated, please use \core_calendar\api::delete_subscription() instead.
|
||||
* calendar_get_icalendar() is deprecated, please use \core_calendar\api::get_icalendar() instead.
|
||||
* calendar_import_icalendar_events() is deprecated, please use \core_calendar\api::import_icalendar_events() instead.
|
||||
* calendar_update_subscription_events() is deprecated, please use \core_calendar\api::update_subscription_events() instead.
|
||||
* calendar_update_subscription() is deprecated, please use \core_calendar\api::update_subscription() instead.
|
||||
* calendar_can_edit_subscription() is deprecated, please use \core_calendar\api::can_edit_subscription() instead.
|
||||
* calendar_get_calendar_context() is deprecated, please use \core_calendar\api::get_calendar_context() instead.
|
||||
* calendar_cron() is deprecated and should not be used. Please use the core\task\calendar_cron_task instead.
|
||||
|
||||
=== 3.2 ===
|
||||
* calendar_preferences_button() is now depreciated. Calendar preferences have been moved to the user preferences page.
|
||||
* calendar_preferences_button() is now deprecated. Calendar preferences have been moved to the user preferences page.
|
||||
|
||||
=== 2.9 ===
|
||||
default values changes in code:
|
||||
|
||||
+2
-2
@@ -91,7 +91,7 @@ if ($courseid != SITEID && !empty($courseid)) {
|
||||
navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
$courses = \core_calendar\api::get_default_courses();
|
||||
$issite = true;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ switch($view) {
|
||||
echo $OUTPUT->container_start('bottom');
|
||||
if (!empty($CFG->enablecalendarexport)) {
|
||||
echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
|
||||
if (calendar_user_can_add_event($course)) {
|
||||
if (\core_calendar\api::can_add_event_to_course($course)) {
|
||||
echo $OUTPUT->single_button(new moodle_url('/calendar/managesubscriptions.php', array('course'=>$courseid)), get_string('managesubscriptions', 'calendar'));
|
||||
}
|
||||
if (isloggedin()) {
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
*/
|
||||
namespace core\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/cronlib.php');
|
||||
|
||||
/**
|
||||
* Simple task to run the calendar cron.
|
||||
*/
|
||||
@@ -42,11 +46,32 @@ class calendar_cron_task extends scheduled_task {
|
||||
* Throw exceptions on errors (the job will be retried).
|
||||
*/
|
||||
public function execute() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
// Run calendar cron.
|
||||
require_once("{$CFG->dirroot}/calendar/lib.php");
|
||||
calendar_cron();
|
||||
require_once($CFG->libdir . '/bennu/bennu.inc.php');
|
||||
|
||||
mtrace('Updating calendar subscriptions:');
|
||||
cron_trace_time_and_memory();
|
||||
|
||||
$time = time();
|
||||
$sql = "SELECT *
|
||||
FROM {event_subscriptions}
|
||||
WHERE pollinterval > 0
|
||||
AND lastupdated + pollinterval < :time";
|
||||
$subscriptions = $DB->get_records_sql($sql, array('time' => $time));
|
||||
foreach ($subscriptions as $sub) {
|
||||
mtrace("Updating calendar subscription {$sub->name} in course {$sub->courseid}");
|
||||
try {
|
||||
$log = \core_calendar\api::update_subscription_events($sub->id);
|
||||
mtrace(trim(strip_tags($log)));
|
||||
} catch (\moodle_exception $ex) {
|
||||
mtrace('Error updating calendar subscription: ' . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
mtrace('Finished updating calendar subscriptions.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+795
-8
@@ -6457,14 +6457,14 @@ function message_get_recent_conversations($userorid, $limitfrom = 0, $limitto =
|
||||
WHERE otheruser.deleted = 0 AND message.notification = 0
|
||||
ORDER BY message.timecreated DESC";
|
||||
$params = array(
|
||||
'userid1' => $user->id,
|
||||
'userid2' => $user->id,
|
||||
'userid3' => $user->id,
|
||||
'userid4' => $user->id,
|
||||
'userid5' => $user->id,
|
||||
'userid6' => $user->id,
|
||||
'userid7' => $user->id
|
||||
);
|
||||
'userid1' => $user->id,
|
||||
'userid2' => $user->id,
|
||||
'userid3' => $user->id,
|
||||
'userid4' => $user->id,
|
||||
'userid5' => $user->id,
|
||||
'userid6' => $user->id,
|
||||
'userid7' => $user->id
|
||||
);
|
||||
$read = $DB->get_records_sql($sql, $params, $limitfrom, $limitto);
|
||||
|
||||
// We want to get the messages that have not been read. These are stored in the 'message' table. It is the
|
||||
@@ -6526,3 +6526,790 @@ function message_get_recent_conversations($userorid, $limitfrom = 0, $limitto =
|
||||
|
||||
return $conversations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display calendar preference button.
|
||||
*
|
||||
* @param stdClass $course course object
|
||||
* @deprecated since Moodle 3.2
|
||||
* @return string return preference button in html
|
||||
*/
|
||||
function calendar_preferences_button(stdClass $course) {
|
||||
debugging('This should no longer be used, the calendar preferences are now linked to the user preferences page.');
|
||||
|
||||
global $OUTPUT;
|
||||
|
||||
// Guests have no preferences.
|
||||
if (!isloggedin() || isguestuser()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $OUTPUT->single_button(new moodle_url('/user/calendar.php'), get_string("preferences", "calendar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the days of the week.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @return array array of days
|
||||
*/
|
||||
function calendar_get_days() {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_days() instead.', DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_days();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subscription from a given id.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @since Moodle 2.5
|
||||
* @param int $id id of the subscription
|
||||
* @return stdClass Subscription record from DB
|
||||
* @throws moodle_exception for an invalid id
|
||||
*/
|
||||
function calendar_get_subscription($id) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_subscription() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_subscription($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first day of the week.
|
||||
*
|
||||
* Used to be define('CALENDAR_STARTING_WEEKDAY', blah);
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @return int
|
||||
*/
|
||||
function calendar_get_starting_weekday() {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_starting_weekday() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_starting_weekday();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the HTML for a miniature calendar.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $courses list of course to list events from
|
||||
* @param array $groups list of group
|
||||
* @param array $users user's info
|
||||
* @param int|bool $calmonth calendar month in numeric, default is set to false
|
||||
* @param int|bool $calyear calendar month in numeric, default is set to false
|
||||
* @param string|bool $placement the place/page the calendar is set to appear - passed on the the controls function
|
||||
* @param int|bool $courseid id of the course the calendar is displayed on - passed on the the controls function
|
||||
* @param int $time the unixtimestamp representing the date we want to view, this is used instead of $calmonth
|
||||
* and $calyear to support multiple calendars
|
||||
* @return string $content return html table for mini calendar
|
||||
*/
|
||||
function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
|
||||
$courseid = false, $time = 0) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_mini_calendar() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_mini_calendar($courses, $groups, $users, $calmonth, $calyear, $placement,
|
||||
$courseid, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the calendar popup.
|
||||
*
|
||||
* It called at multiple points in from calendar_get_mini.
|
||||
* Copied and modified from calendar_get_mini.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param bool $today false except when called on the current day.
|
||||
* @param mixed $timestart $events[$eventid]->timestart, OR false if there are no events.
|
||||
* @param string $popupcontent content for the popup window/layout.
|
||||
* @return string eventid for the calendar_tooltip popup window/layout.
|
||||
*/
|
||||
function calendar_get_popup($today = false, $timestart, $popupcontent = '') {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_popup() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_popup($today, $timestart, $popupcontent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the calendar upcoming event.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $courses array of courses
|
||||
* @param array|int|bool $groups array of groups, group id or boolean for all/no group events
|
||||
* @param array|int|bool $users array of users, user id or boolean for all/no user events
|
||||
* @param int $daysinfuture number of days in the future we 'll look
|
||||
* @param int $maxevents maximum number of events
|
||||
* @param int $fromtime start time
|
||||
* @return array $output array of upcoming events
|
||||
*/
|
||||
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_upcoming() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a HTML link to a course.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $courseid the course id
|
||||
* @return string a link to the course (as HTML); empty if the course id is invalid
|
||||
*/
|
||||
function calendar_get_courselink($courseid) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_courselink() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_courselink($courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current module cache.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $coursecache list of course cache
|
||||
* @param string $modulename name of the module
|
||||
* @param int $instance module instance number
|
||||
* @return stdClass|bool $module information
|
||||
*/
|
||||
function calendar_get_module_cached(&$coursecache, $modulename, $instance) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_module_cached() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_module_cached($coursecache, $modulename, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current course cache.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $coursecache list of course cache
|
||||
* @param int $courseid id of the course
|
||||
* @return stdClass $coursecache[$courseid] return the specific course cache
|
||||
*/
|
||||
function calendar_get_course_cached(&$coursecache, $courseid) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_course_cached() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_course_cached($coursecache, $courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group from groupid for calendar display
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $groupid
|
||||
* @return stdClass group object with fields 'id', 'name' and 'courseid'
|
||||
*/
|
||||
function calendar_get_group_cached($groupid) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_group_cached() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_group_cached($groupid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add calendar event metadata
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $event event info
|
||||
* @return stdClass $event metadata
|
||||
*/
|
||||
function calendar_add_event_metadata($event) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::add_event_metadata() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::add_event_metadata($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calendar events.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $tstart Start time of time range for events
|
||||
* @param int $tend End time of time range for events
|
||||
* @param array|int|boolean $users array of users, user id or boolean for all/no user events
|
||||
* @param array|int|boolean $groups array of groups, group id or boolean for all/no group events
|
||||
* @param array|int|boolean $courses array of courses, course id or boolean for all/no course events
|
||||
* @param boolean $withduration whether only events starting within time range selected
|
||||
* or events in progress/already started selected as well
|
||||
* @param boolean $ignorehidden whether to select only visible events or all events
|
||||
* @return array $events of selected events or an empty array if there aren't any (or there was an error)
|
||||
*/
|
||||
function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withduration=true, $ignorehidden=true) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_events() instead.', DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_events($tstart, $tend, $users, $groups, $courses, $withduration, $ignorehidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calendar events by id.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @since Moodle 2.5
|
||||
* @param array $eventids list of event ids
|
||||
* @return array Array of event entries, empty array if nothing found
|
||||
*/
|
||||
function calendar_get_events_by_id($eventids) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_events_by_id() instead.', DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_events_by_id($eventids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get control options for calendar.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string $type of calendar
|
||||
* @param array $data calendar information
|
||||
* @return string $content return available control for the calender in html
|
||||
*/
|
||||
function calendar_top_controls($type, $data) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_top_controls() instead.', DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_top_controls($type, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a filter control element.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param moodle_url $url of the filter
|
||||
* @param int $type constant defining the type filter
|
||||
* @return string html content of the element
|
||||
*/
|
||||
function calendar_filter_controls_element(moodle_url $url, $type) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_filter_controls_element() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_filter_controls_element($url, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the controls filter for calendar.
|
||||
*
|
||||
* Filter is used to hide calendar info from the display page.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param moodle_url $returnurl return-url for filter controls
|
||||
* @return string $content return filter controls in html
|
||||
*/
|
||||
function calendar_filter_controls(moodle_url $returnurl) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_filter_controls() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_filter_controls($returnurl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the representation day.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $tstamp Timestamp in GMT
|
||||
* @param int|bool $now current Unix timestamp
|
||||
* @param bool $usecommonwords
|
||||
* @return string the formatted date/time
|
||||
*/
|
||||
function calendar_day_representation($tstamp, $now = false, $usecommonwords = true) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_day_representation() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_day_representation($tstamp, $now, $usecommonwords);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the formatted representation time.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $time the timestamp in UTC, as obtained from the database
|
||||
* @return string the formatted date/time
|
||||
*/
|
||||
function calendar_time_representation($time) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_time_representation() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_time_representation($time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds day, month, year arguments to a URL and returns a moodle_url object.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string|moodle_url $linkbase
|
||||
* @param int $d The number of the day.
|
||||
* @param int $m The number of the month.
|
||||
* @param int $y The number of the year.
|
||||
* @param int $time the unixtime, used for multiple calendar support. The values $d,
|
||||
* $m and $y are kept for backwards compatibility.
|
||||
* @return moodle_url|null $linkbase
|
||||
*/
|
||||
function calendar_get_link_href($linkbase, $d, $m, $y, $time = 0) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_link_href() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_link_href($linkbase, $d, $m, $y, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return a previous month HTML link, with an arrow.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string $text The text label.
|
||||
* @param string|moodle_url $linkbase The URL stub.
|
||||
* @param int $d The number of the date.
|
||||
* @param int $m The number of the month.
|
||||
* @param int $y year The number of the year.
|
||||
* @param bool $accesshide Default visible, or hide from all except screenreaders.
|
||||
* @param int $time the unixtime, used for multiple calendar support. The values $d,
|
||||
* $m and $y are kept for backwards compatibility.
|
||||
* @return string HTML string.
|
||||
*/
|
||||
function calendar_get_link_previous($text, $linkbase, $d, $m, $y, $accesshide = false, $time = 0) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_link_previous() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_link_previous($text, $linkbase, $d, $m, $y, $accesshide, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return a next month HTML link, with an arrow.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string $text The text label.
|
||||
* @param string|moodle_url $linkbase The URL stub.
|
||||
* @param int $d the number of the Day
|
||||
* @param int $m The number of the month.
|
||||
* @param int $y The number of the year.
|
||||
* @param bool $accesshide Default visible, or hide from all except screenreaders.
|
||||
* @param int $time the unixtime, used for multiple calendar support. The values $d,
|
||||
* $m and $y are kept for backwards compatibility.
|
||||
* @return string HTML string.
|
||||
*/
|
||||
function calendar_get_link_next($text, $linkbase, $d, $m, $y, $accesshide = false, $time = 0) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_link_next() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_link_next($text, $linkbase, $d, $m, $y, $accesshide, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the weekday
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string $englishname
|
||||
* @return string of the weekeday
|
||||
*/
|
||||
function calendar_wday_name($englishname) {
|
||||
debugging(__FUNCTION__ . '() is deprecated and no longer used in core.', DEBUG_DEVELOPER);
|
||||
return get_string(strtolower($englishname), 'calendar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of days in month.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $month the number of the month.
|
||||
* @param int $year the number of the year
|
||||
* @return int
|
||||
*/
|
||||
function calendar_days_in_month($month, $year) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_days_in_month() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_days_in_month($month, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upcoming event block.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $events list of events
|
||||
* @param moodle_url|string $linkhref link to event referer
|
||||
* @param boolean $showcourselink whether links to courses should be shown
|
||||
* @return string|null $content html block content
|
||||
*/
|
||||
function calendar_get_block_upcoming($events, $linkhref = null, $showcourselink = false) {
|
||||
global $CFG;
|
||||
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use block_calendar_upcoming::get_upcoming_content() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
|
||||
require_once($CFG->dirroot . '/blocks/calendar_upcoming/block_calendar_upcoming.php');
|
||||
return block_calendar_upcoming::get_upcoming_content($events, $linkhref, $showcourselink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next following month.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $month the number of the month.
|
||||
* @param int $year the number of the year.
|
||||
* @return array the following month
|
||||
*/
|
||||
function calendar_add_month($month, $year) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_next_month() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_next_month($month, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous month.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $month the number of the month.
|
||||
* @param int $year the number of the year.
|
||||
* @return array previous month
|
||||
*/
|
||||
function calendar_sub_month($month, $year) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_prev_month() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_prev_month($month, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get per-day basis events
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $events list of events
|
||||
* @param int $month the number of the month
|
||||
* @param int $year the number of the year
|
||||
* @param array $eventsbyday event on specific day
|
||||
* @param array $durationbyday duration of the event in days
|
||||
* @param array $typesbyday event type (eg: global, course, user, or group)
|
||||
* @param array $courses list of courses
|
||||
* @return void
|
||||
*/
|
||||
function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$durationbyday, &$typesbyday, &$courses) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_events_by_day() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
\core_calendar\api::get_events_by_day($events, $month, $year, $eventsbyday, $durationbyday, $typesbyday, $courses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the courses to load events for.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param array $courseeventsfrom An array of courses to load calendar events for
|
||||
* @param bool $ignorefilters specify the use of filters, false is set as default
|
||||
* @return array An array of courses, groups, and user to load calendar events for based upon filters
|
||||
*/
|
||||
function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::set_filters() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::set_filters($courseeventsfrom, $ignorefilters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the capability for editing calendar event.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param \core_calendar\event $event event object
|
||||
* @return bool capability to edit event
|
||||
*/
|
||||
function calendar_edit_event_allowed($event) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::can_edit_event() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::can_edit_event($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default courses to display on the calendar when there isn't a specific
|
||||
* course to display.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @return array $courses Array of courses to display
|
||||
*/
|
||||
function calendar_get_default_courses() {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_default_courses() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_default_courses();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get event format time.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param \core_calendar\event $event event object
|
||||
* @param int $now current time in gmt
|
||||
* @param array $linkparams list of params for event link
|
||||
* @param bool $usecommonwords the words as formatted date/time.
|
||||
* @param int $showtime determine the show time GMT timestamp
|
||||
* @return string $eventtime link/string for event time
|
||||
*/
|
||||
function calendar_format_event_time($event, $now, $linkparams = null, $usecommonwords = true, $showtime = 0) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_format_event_time() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_format_event_time($event, $now, $linkparams, $usecommonwords, $showtime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display month selector options.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string $name for the select element
|
||||
* @param string|array $selected options for select elements
|
||||
*/
|
||||
function calendar_print_month_selector($name, $selected) {
|
||||
debugging(__FUNCTION__ . '() is deprecated and no longer used in core.', DEBUG_DEVELOPER);
|
||||
$months = array();
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
|
||||
}
|
||||
echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide'));
|
||||
echo html_writer::select($months, $name, $selected, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the requested type of event should be shown for the given user.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $type The type to check the display for (default is to display all)
|
||||
* @param stdClass|int|null $user The user to check for - by default the current user
|
||||
* @return bool True if the tyep should be displayed false otherwise
|
||||
*/
|
||||
function calendar_show_event_type($type, $user = null) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::show_event_type() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::show_event_type($type, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display of the event type given $display.
|
||||
*
|
||||
* If $display = true the event type will be shown.
|
||||
* If $display = false the event type will NOT be shown.
|
||||
* If $display = null the current value will be toggled and saved.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $type object of CALENDAR_EVENT_XXX
|
||||
* @param bool $display option to display event type
|
||||
* @param stdClass|int $user moodle user object or id, null means current user
|
||||
*/
|
||||
function calendar_set_event_type_display($type, $display = null, $user = null) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::set_event_type_display() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
\core_calendar\api::set_event_type_display($type, $display, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calendar's allowed types.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $allowed list of allowed edit for event type
|
||||
* @param stdClass|int $course object of a course or course id
|
||||
*/
|
||||
function calendar_get_allowed_types(&$allowed, $course = null) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_allowed_types() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
\core_calendar\api::get_allowed_types($allowed, $course);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if user can add calendar entries at all used to print the "New Event" button.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $course object of a course or course id
|
||||
* @return bool has the capability to add at least one event type
|
||||
*/
|
||||
function calendar_user_can_add_event($course) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::can_add_event_to_course() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::can_add_event_to_course($course);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check wether the current user is permitted to add events.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $event object of event
|
||||
* @return bool has the capability to add event
|
||||
*/
|
||||
function calendar_add_event_allowed($event) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::can_add_event() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::can_add_event($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns option list for the poll interval setting.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @return array An array of poll interval options. Interval => description.
|
||||
*/
|
||||
function calendar_get_pollinterval_choices() {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_poll_interval_choices() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_poll_interval_choices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns option list of available options for the calendar event type, given the current user and course.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $courseid The id of the course
|
||||
* @return array An array containing the event types the user can create.
|
||||
*/
|
||||
function calendar_get_eventtype_choices($courseid) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_event_type_choices() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_event_type_choices($courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an iCalendar subscription to the database.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $sub The subscription object (e.g. from the form)
|
||||
* @return int The insert ID, if any.
|
||||
*/
|
||||
function calendar_add_subscription($sub) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::add_subscription() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::add_subscription($sub);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an iCalendar event to the Moodle calendar.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $event The RFC-2445 iCalendar event
|
||||
* @param int $courseid The course ID
|
||||
* @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') {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::add_icalendar_event() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::add_icalendar_event($event, $courseid, $subscriptionid, $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a subscription from the form data in one of the rows in the existing subscriptions table.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $subscriptionid The ID of the subscription we are acting upon.
|
||||
* @param int $pollinterval The poll interval to use.
|
||||
* @param int $action The action to be performed. One of update or remove.
|
||||
* @throws dml_exception if invalid subscriptionid is provided
|
||||
* @return string A log of the import progress, including errors
|
||||
*/
|
||||
function calendar_process_subscription_row($subscriptionid, $pollinterval, $action) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::process_subscription_row() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::process_subscription_row($subscriptionid, $pollinterval, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete subscription and all related events.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int|stdClass $subscription subscription or it's id, which needs to be deleted.
|
||||
*/
|
||||
function calendar_delete_subscription($subscription) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::delete_subscription() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
\core_calendar\api::delete_subscription($subscription);
|
||||
}
|
||||
|
||||
/**
|
||||
* From a URL, fetch the calendar and return an iCalendar object.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param string $url The iCalendar URL
|
||||
* @return iCalendar The iCalendar object
|
||||
*/
|
||||
function calendar_get_icalendar($url) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_icalendar() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_icalendar($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Import events from an iCalendar object into a course calendar.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param iCalendar $ical The iCalendar object.
|
||||
* @param int $courseid The course ID for the calendar.
|
||||
* @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) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::import_icalendar_events() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::import_icalendar_events($ical, $courseid, $subscriptionid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a calendar subscription and update the events in the calendar.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param int $subscriptionid The course ID for the calendar.
|
||||
* @return string A log of the import progress, including errors.
|
||||
*/
|
||||
function calendar_update_subscription_events($subscriptionid) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::update_subscription_events() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::update_subscription_events($subscriptionid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a calendar subscription. Also updates the associated cache.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass|array $subscription Subscription record.
|
||||
* @throws coding_exception If something goes wrong
|
||||
* @since Moodle 2.5
|
||||
*/
|
||||
function calendar_update_subscription($subscription) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::update_subscription() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
\core_calendar\api::update_subscription($subscription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the user can edit a given subscription feed.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param mixed $subscriptionorid Subscription object or id
|
||||
* @return bool true if current user can edit the subscription else false
|
||||
*/
|
||||
function calendar_can_edit_subscription($subscriptionorid) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::can_edit_subscription() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::can_edit_subscription($subscriptionorid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to determine the context of a calendar subscription.
|
||||
* Subscriptions can be created in two contexts COURSE, or USER.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @param stdClass $subscription
|
||||
* @return context instance
|
||||
*/
|
||||
function calendar_get_calendar_context($subscription) {
|
||||
debugging(__FUNCTION__ . '() is deprecated, please use \core_calendar\api::get_calendar_context() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
return \core_calendar\api::get_calendar_context($subscription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update calendar subscriptions.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @return bool
|
||||
*/
|
||||
function calendar_cron() {
|
||||
debugging(__FUNCTION__ . '() is deprecated and should not be used. Please use the core\task\calendar_cron_task instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
global $CFG, $DB;
|
||||
|
||||
// In order to execute this we need bennu.
|
||||
require_once($CFG->libdir.'/bennu/bennu.inc.php');
|
||||
|
||||
mtrace('Updating calendar subscriptions:');
|
||||
cron_trace_time_and_memory();
|
||||
|
||||
$time = time();
|
||||
$subscriptions = $DB->get_records_sql('SELECT * FROM {event_subscriptions} WHERE pollinterval > 0
|
||||
AND lastupdated + pollinterval < ?', array($time));
|
||||
foreach ($subscriptions as $sub) {
|
||||
mtrace("Updating calendar subscription {$sub->name} in course {$sub->courseid}");
|
||||
try {
|
||||
$log = calendar_update_subscription_events($sub->id);
|
||||
mtrace(trim(strip_tags($log)));
|
||||
} catch (moodle_exception $ex) {
|
||||
mtrace('Error updating calendar subscription: ' . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
mtrace('Finished updating calendar subscriptions.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the class containing unit tests for the calendar cron task.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2017 Mark Nelson <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class containing unit tests for the calendar cron task.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2017 Mark Nelson <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_cron_task_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests set up
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar cron task with a working subscription URL.
|
||||
*/
|
||||
public function test_cron_working_url() {
|
||||
// ICal URL from external test repo.
|
||||
$subscriptionurl = $this->getExternalTestFileUrl('/ical.ics');
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$subscription->url = $subscriptionurl;
|
||||
$subscription->pollinterval = 86400;
|
||||
$subscription->lastupdated = 0;
|
||||
\core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$this->expectOutputRegex('/Events imported: .* Events updated:/');
|
||||
$task = new \core\task\calendar_cron_task();
|
||||
$task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test calendar cron task with a broken subscription URL.
|
||||
*/
|
||||
public function test_cron_broken_url() {
|
||||
$subscription = new stdClass();
|
||||
$subscription->eventtype = 'site';
|
||||
$subscription->name = 'test';
|
||||
$subscription->url = 'brokenurl';
|
||||
$subscription->pollinterval = 86400;
|
||||
$subscription->lastupdated = 0;
|
||||
\core_calendar\api::add_subscription($subscription);
|
||||
|
||||
$this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/');
|
||||
$task = new \core\task\calendar_cron_task();
|
||||
$task->execute();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -46,7 +46,7 @@ if (isset($CFG->calendar_maxevents)) {
|
||||
$calendarform = new core_user\form\calendar_form(null, array('userid' => $user->id));
|
||||
|
||||
$user->timeformat = get_user_preferences('calendar_timeformat', '');
|
||||
$user->startwday = calendar_get_starting_weekday();
|
||||
$user->startwday = \core_calendar\api::get_starting_weekday();
|
||||
$user->maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
|
||||
$user->lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
|
||||
$user->persistflt = get_user_preferences('calendar_persistflt', 0);
|
||||
|
||||
Reference in New Issue
Block a user