mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-60587 calendar: Switch WS to use new helper
This commit is contained in:
parent
7f14def230
commit
6607c5ffb6
@ -899,41 +899,15 @@ class core_calendar_external extends external_api {
|
||||
'includenavigation' => $includenavigation,
|
||||
]);
|
||||
|
||||
// TODO: Copy what we do in calendar/view.php.
|
||||
$context = \context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
$PAGE->set_url('/calendar/');
|
||||
|
||||
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];
|
||||
|
||||
$coursecat = \coursecat::get($course->category);
|
||||
$category = $coursecat->get_db_record();
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
$category = null;
|
||||
|
||||
if ($categoryid) {
|
||||
self::validate_context(context_coursecat::instance($categoryid));
|
||||
$ids = [$categoryid];
|
||||
$category = \coursecat::get($categoryid);
|
||||
$ids += $category->get_parents();
|
||||
$categories = \coursecat::get_many($ids);
|
||||
$courses = array_filter($courses, function($course) use ($categories) {
|
||||
return array_search($course->category, $categories) !== false;
|
||||
});
|
||||
$category = $category->get_db_record();
|
||||
}
|
||||
}
|
||||
|
||||
$type = \core_calendar\type_factory::get_calendar_instance();
|
||||
|
||||
$time = $type->convert_to_timestamp($year, $month, 1);
|
||||
$calendar = new calendar_information(0, 0, 0, $time);
|
||||
$calendar->set_sources($course, $courses, $category);
|
||||
$time = $type->convert_to_timestamp($params['year'], $params['month'], 1);
|
||||
$calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
|
||||
self::validate_context($calendar->context);
|
||||
|
||||
list($data, $template) = calendar_get_view($calendar, 'month', $params['includenavigation']);
|
||||
|
||||
@ -994,40 +968,14 @@ class core_calendar_external extends external_api {
|
||||
'categoryid' => $categoryid,
|
||||
]);
|
||||
|
||||
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];
|
||||
|
||||
$coursecat = \coursecat::get($course->category);
|
||||
$category = $coursecat->get_db_record();
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
$category = null;
|
||||
|
||||
if ($categoryid) {
|
||||
self::validate_context(context_coursecat::instance($categoryid));
|
||||
$ids = [$categoryid];
|
||||
$category = \coursecat::get($categoryid);
|
||||
$ids += $category->get_parents();
|
||||
$categories = \coursecat::get_many($ids);
|
||||
$courses = array_filter($courses, function($course) use ($categories) {
|
||||
return array_search($course->category, $categories) !== false;
|
||||
});
|
||||
$category = $category->get_db_record();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Copy what we do in calendar/view.php.
|
||||
$context = \context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
$type = \core_calendar\type_factory::get_calendar_instance();
|
||||
|
||||
$time = $type->convert_to_timestamp($year, $month, $day);
|
||||
$calendar = new calendar_information(0, 0, 0, $time);
|
||||
$calendar->set_sources($course, $courses, $category);
|
||||
$time = $type->convert_to_timestamp($params['year'], $params['month'], $params['day']);
|
||||
$calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
|
||||
self::validate_context($calendar->context);
|
||||
|
||||
list($data, $template) = calendar_get_view($calendar, 'day', $params['includenavigation']);
|
||||
|
||||
@ -1153,38 +1101,17 @@ class core_calendar_external extends external_api {
|
||||
require_once($CFG->dirroot."/calendar/lib.php");
|
||||
|
||||
// Parameter validation.
|
||||
self::validate_parameters(self::get_calendar_upcoming_view_parameters(), [
|
||||
$params = self::validate_parameters(self::get_calendar_upcoming_view_parameters(), [
|
||||
'courseid' => $courseid,
|
||||
'categoryid' => $categoryid,
|
||||
]);
|
||||
$PAGE->set_url('/calendar/');
|
||||
|
||||
$category = null;
|
||||
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 if (!empty($categoryid)) {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
|
||||
$category = \coursecat::get($categoryid);
|
||||
$ids += $category->get_parents();
|
||||
$categories = \coursecat::get_many($ids);
|
||||
$courses = array_filter($courses, function($course) use ($categories) {
|
||||
return array_search($course->category, $categories) !== false;
|
||||
});
|
||||
$category = $category->get_db_record();
|
||||
} else {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses();
|
||||
}
|
||||
|
||||
$context = \context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
$PAGE->set_url('/calendar/');
|
||||
|
||||
$calendar = new calendar_information(0, 0, 0, time());
|
||||
$calendar->set_sources($course, $courses, $category);
|
||||
$calendar = \calendar_information::create(time(), $params['courseid'], $params['categoryid']);
|
||||
self::validate_context($calendar->context);
|
||||
|
||||
list($data, $template) = calendar_get_view($calendar, 'upcoming');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user