MDL-58424 core_calendar: removed unused get_action_events_* functions
[moodle.git] / calendar / classes / local / api.php
CommitLineData
392d6a49
RW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Contains class containing the internal calendar API.
19 *
20 * @package core_calendar
21 * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace core_calendar\local;
26
27defined('MOODLE_INTERNAL') || die();
28
e62cd85f
RW
29use core_calendar\local\event\exceptions\limit_invalid_parameter_exception;
30
392d6a49
RW
31/**
32 * Class containing the local calendar API.
33 *
34 * @package core_calendar
35 * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class api {
258a5705
CB
39 /**
40 * Get all events restricted by various parameters, taking in to account user and group overrides.
41 *
20592f5f
JP
42 * @param int|null $timestartfrom Events with timestart from this value (inclusive).
43 * @param int|null $timestartto Events with timestart until this value (inclusive).
44 * @param int|null $timesortfrom Events with timesort from this value (inclusive).
45 * @param int|null $timesortto Events with timesort until this value (inclusive).
46 * @param int|null $timestartaftereventid Restrict the events in the timestart range to ones after this ID.
47 * @param int|null $timesortaftereventid Restrict the events in the timesort range to ones after this ID.
48 * @param int $limitnum Return at most this number of events.
49 * @param int|null $type Return only events of this type.
50 * @param array|null $usersfilter Return only events for these users.
51 * @param array|null $groupsfilter Return only events for these groups.
52 * @param array|null $coursesfilter Return only events for these courses.
53 * @param bool $withduration If true return only events starting within specified
54 * timestart otherwise return in progress events as well.
55 * @param bool $ignorehidden If true don't return hidden events.
258a5705
CB
56 * @return \core_calendar\local\interfaces\event_interface[] Array of event_interfaces.
57 */
58 public static function get_events(
59 $timestartfrom = null,
60 $timestartto = null,
61 $timesortfrom = null,
62 $timesortto = null,
63 $timestartaftereventid = null,
64 $timesortaftereventid = null,
65 $limitnum = 20,
66 $type = null,
67 array $usersfilter = null,
68 array $groupsfilter = null,
69 array $coursesfilter = null,
70 $withduration = true,
71 $ignorehidden = true
72 ) {
73 global $USER;
74
75 $vault = \core_calendar\local\event\core_container::get_event_vault();
76
77 $timestartafterevent = null;
78 $timesortafterevent = null;
79
80 if ($timestartaftereventid && $event = $vault->get_event_by_id($timestartaftereventid)) {
81 $timestartafterevent = $event;
82 }
83
84 if ($timesortaftereventid && $event = $vault->get_event_by_id($timesortaftereventid)) {
85 $timesortafterevent = $event;
86 }
87
88 return $vault->get_events(
89 $timestartfrom,
90 $timestartto,
91 $timesortfrom,
92 $timesortto,
93 $timestartafterevent,
94 $timesortafterevent,
95 $limitnum,
96 $type,
97 $usersfilter,
98 $groupsfilter,
99 $coursesfilter,
100 $withduration,
101 $ignorehidden
102 );
103 }
392d6a49
RW
104
105 /**
106 * Get a list of action events for the logged in user by the given
107 * timesort values.
108 *
109 * @param int|null $timesortfrom The start timesort value (inclusive)
110 * @param int|null $timesortto The end timesort value (inclusive)
111 * @param int|null $aftereventid Only return events after this one
112 * @param int $limitnum Limit results to this amount (between 1 and 50)
113 * @return array A list of action_event_interface objects
20592f5f 114 * @throws \moodle_exception
392d6a49
RW
115 */
116 public static function get_action_events_by_timesort(
117 $timesortfrom = null,
118 $timesortto = null,
119 $aftereventid = null,
120 $limitnum = 20
121 ) {
122 global $USER;
123
124 if (is_null($timesortfrom) && is_null($timesortto)) {
125 throw new \moodle_exception("Must provide a timesort to and/or from value");
126 }
127
128 if ($limitnum < 1 || $limitnum > 50) {
129 throw new \moodle_exception("Limit must be between 1 and 50 (inclusive)");
130 }
131
132 $vault = \core_calendar\local\event\core_container::get_event_vault();
133
134 $afterevent = null;
135 if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
136 $afterevent = $event;
137 }
138
139 return $vault->get_action_events_by_timesort($USER, $timesortfrom, $timesortto, $afterevent, $limitnum);
140 }
e62cd85f
RW
141
142 /**
143 * Get a list of action events for the logged in user by the given
144 * course and timesort values.
145 *
146 * @param \stdClass $course The course the events must belong to
147 * @param int|null $timesortfrom The start timesort value (inclusive)
148 * @param int|null $timesortto The end timesort value (inclusive)
149 * @param int|null $aftereventid Only return events after this one
150 * @param int $limitnum Limit results to this amount (between 1 and 50)
151 * @return array A list of action_event_interface objects
20592f5f 152 * @throws limit_invalid_parameter_exception
e62cd85f
RW
153 */
154 public static function get_action_events_by_course(
155 $course,
156 $timesortfrom = null,
157 $timesortto = null,
158 $aftereventid = null,
159 $limitnum = 20
160 ) {
161 global $USER;
162
163 if ($limitnum < 1 || $limitnum > 50) {
164 throw new limit_invalid_parameter_exception(
165 "Limit must be between 1 and 50 (inclusive)");
166 }
167
168 $vault = \core_calendar\local\event\core_container::get_event_vault();
169
170 $afterevent = null;
171 if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
172 $afterevent = $event;
173 }
174
175 return $vault->get_action_events_by_course(
176 $USER, $course, $timesortfrom, $timesortto, $afterevent, $limitnum);
177 }
8a082024
RW
178
179 /**
180 * Get a list of action events for the logged in user by the given
181 * courses and timesort values.
182 *
183 * The limit number applies per course, not for the result set as a whole.
184 * E.g. Requesting 3 courses with a limit of 10 will result in up to 30
185 * events being returned (up to 10 per course).
186 *
187 * @param array $courses The courses the events must belong to
188 * @param int|null $timesortfrom The start timesort value (inclusive)
189 * @param int|null $timesortto The end timesort value (inclusive)
190 * @param int $limitnum Limit results per course to this amount (between 1 and 50)
191 * @return array A list of action_event_interface objects indexed by course id
192 */
193 public static function get_action_events_by_courses(
194 $courses = [],
195 $timesortfrom = null,
196 $timesortto = null,
197 $limitnum = 20
198 ) {
199 $return = [];
200
201 foreach ($courses as $course) {
202 $return[$course->id] = self::get_action_events_by_course(
203 $course,
204 $timesortfrom,
205 $timesortto,
206 null,
207 $limitnum
208 );
209 }
210
211 return $return;
212 }
392d6a49 213}