Commit e8306438 authored by Simey Lameze's avatar Simey Lameze
Browse files

MDL-59751 core_calendar: add get_calendar_upcoming_view webservice

parent 02150c9a
......@@ -1051,4 +1051,61 @@ class core_calendar_external extends external_api {
)
);
}
/**
* Get data for the monthly calendar view.
*
* @param int $courseid The course to be included
* @return array
*/
public static function get_calendar_upcoming_view($courseid) {
global $CFG, $DB, $USER, $PAGE;
require_once($CFG->dirroot."/calendar/lib.php");
// Parameter validation.
self::validate_parameters(self::get_calendar_upcoming_view_parameters(), [
'courseid' => $courseid,
]);
if ($courseid != SITEID && !empty($courseid)) {
// Course ID must be valid and existing.
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$courses = [$course->id => $course];
} else {
$course = get_site();
$courses = calendar_get_default_courses();
}
$context = \context_user::instance($USER->id);
self::validate_context($context);
$calendar = new calendar_information(0, 0, 0, time());
$calendar->set_sources($course, $courses);
list($data, $template) = calendar_get_view($calendar, 'upcoming');
return $data;
}
/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function get_calendar_upcoming_view_parameters() {
return new external_function_parameters(
[
'courseid' => new external_value(PARAM_INT, 'Course being viewed', VALUE_DEFAULT, SITEID, NULL_ALLOWED),
]
);
}
/**
* Returns description of method result value.
*
* @return external_description
*/
public static function get_calendar_upcoming_view_returns() {
return \core_calendar\external\calendar_upcoming_exporter::get_read_structure();
}
}
......@@ -68,6 +68,16 @@ $functions = array(
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_calendar_get_calendar_upcoming_view' => array(
'classname' => 'core_calendar_external',
'methodname' => 'get_calendar_upcoming_view',
'description' => 'Fetch the upcoming view data for a calendar',
'classpath' => 'calendar/externallib.php',
'type' => 'read',
'capabilities' => '',
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_calendar_update_event_start_day' => array(
'classname' => 'core_calendar_external',
'methodname' => 'update_event_start_day',
......
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017092900.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017092900.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment