MDL-57502 calendar: add local api class for internal use
Part of MDL-55611 epic.
This commit is contained in:
committed by
Damyon Wiese
parent
1575194a5c
commit
392d6a49f8
@@ -30,6 +30,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
use core_calendar\local\api as local_api;
|
||||
|
||||
/**
|
||||
* Class containing the calendar API.
|
||||
*
|
||||
@@ -2331,7 +2333,7 @@ class api {
|
||||
* @param int|null $timesortto The end timesort value (inclusive)
|
||||
* @param int|null $aftereventid Only return events after this one
|
||||
* @param int $limitnum Limit results to this amount (between 1 and 50)
|
||||
* @return array A list of action_event objects
|
||||
* @return array A list of event type objects
|
||||
*/
|
||||
public static function get_action_events_by_timesort(
|
||||
$timesortfrom = null,
|
||||
@@ -2339,27 +2341,11 @@ class api {
|
||||
$aftereventid = null,
|
||||
$limitnum = 20
|
||||
) {
|
||||
global $USER;
|
||||
|
||||
if (is_null($timesortfrom) && is_null($timesortto)) {
|
||||
throw new \moodle_exception("Must provide a timesort to and/or from value");
|
||||
}
|
||||
|
||||
if ($limitnum < 1 || $limitnum > 50) {
|
||||
throw new \moodle_exception("Limit must be between 1 and 50 (inclusive)");
|
||||
}
|
||||
|
||||
$vault = \core_calendar\local\event\core_container::get_event_vault();
|
||||
$mapper = \core_calendar\local\event\core_container::get_event_mapper();
|
||||
$events = local_api::get_action_events_by_timesort($timesortfrom, $timesortto, $aftereventid, $limitnum);
|
||||
|
||||
$afterevent = null;
|
||||
if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
|
||||
$afterevent = $event;
|
||||
}
|
||||
|
||||
// Don't expose the new classes outside this module.
|
||||
return array_map(function($event) use ($mapper) {
|
||||
return $mapper->from_event_to_legacy_event($event);
|
||||
}, $vault->get_action_events_by_timesort($USER, $timesortfrom, $timesortto, $afterevent, $limitnum));
|
||||
return $mapper->from_event_to_legacy_event($event);
|
||||
}, $events);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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 class containing the internal calendar API.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar\local;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class containing the local calendar API.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class api {
|
||||
|
||||
/**
|
||||
* Get a list of action events for the logged in user by the given
|
||||
* timesort values.
|
||||
*
|
||||
* @param int|null $timesortfrom The start timesort value (inclusive)
|
||||
* @param int|null $timesortto The end timesort value (inclusive)
|
||||
* @param int|null $aftereventid Only return events after this one
|
||||
* @param int $limitnum Limit results to this amount (between 1 and 50)
|
||||
* @return array A list of action_event_interface objects
|
||||
*/
|
||||
public static function get_action_events_by_timesort(
|
||||
$timesortfrom = null,
|
||||
$timesortto = null,
|
||||
$aftereventid = null,
|
||||
$limitnum = 20
|
||||
) {
|
||||
global $USER;
|
||||
|
||||
if (is_null($timesortfrom) && is_null($timesortto)) {
|
||||
throw new \moodle_exception("Must provide a timesort to and/or from value");
|
||||
}
|
||||
|
||||
if ($limitnum < 1 || $limitnum > 50) {
|
||||
throw new \moodle_exception("Limit must be between 1 and 50 (inclusive)");
|
||||
}
|
||||
|
||||
$vault = \core_calendar\local\event\core_container::get_event_vault();
|
||||
|
||||
$afterevent = null;
|
||||
if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
|
||||
$afterevent = $event;
|
||||
}
|
||||
|
||||
return $vault->get_action_events_by_timesort($USER, $timesortfrom, $timesortto, $afterevent, $limitnum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user