MDL-57888 core_calendar: moved functions from calendar/lib.php

Part of MDL-55611 epic.
This commit is contained in:
Mark Nelson
2017-04-03 11:35:38 +08:00
committed by Damyon Wiese
parent e46efe3a72
commit 12cbce0aa3
24 changed files with 3555 additions and 2734 deletions
+795 -8
View File
@@ -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;
}