28 protected \ilDBInterface
$db;
33 ?array $preload_context_obj_ids =
null
36 if (is_array($preload_context_obj_ids)) {
47 $il_db_statement = $this->db->query(
48 "SELECT * FROM booking_reservation WHERE booking_reservation_id = {$this->db->quote($id, \ilDBConstants::T_INTEGER)}"
50 return $this->db->fetchAssoc($il_db_statement) ?? [];
69 $id =
$ilDB->nextId(
'booking_reservation');
70 $ilDB->manipulate(
'INSERT INTO booking_reservation' .
71 ' (booking_reservation_id,user_id,assigner_id,object_id,context_obj_id,date_from,date_to,status,group_id,message)' .
72 ' VALUES (' .
$ilDB->quote(
$id,
'integer') .
74 ',' .
$ilDB->quote($assigner_id,
'integer') .
75 ',' .
$ilDB->quote($object_id,
'integer') .
76 ',' .
$ilDB->quote($context_obj_id,
'integer') .
77 ',' .
$ilDB->quote($from,
'integer') .
78 ',' .
$ilDB->quote($to,
'integer') .
79 ',' .
$ilDB->quote($status,
'integer') .
80 ',' .
$ilDB->quote($group_id,
'integer') .
81 ',' .
$ilDB->quote($message,
'text') .
')');
101 return $ilDB->manipulate(
'UPDATE booking_reservation' .
102 ' SET object_id = ' .
$ilDB->quote($object_id,
'text') .
104 ', assigner_id = ' .
$ilDB->quote($assigner_id,
'integer') .
105 ', date_from = ' .
$ilDB->quote($from,
'integer') .
106 ', date_to = ' .
$ilDB->quote($to,
'integer') .
107 ', status = ' .
$ilDB->quote($status,
'integer') .
108 ', group_id = ' .
$ilDB->quote($group_id,
'integer') .
109 ', context_obj_id = ' .
$ilDB->quote($context_obj_id,
'integer') .
110 ', message = ' .
$ilDB->quote($message,
'text') .
111 ' WHERE booking_reservation_id = ' .
$ilDB->quote(
$id,
'integer'));
114 public function delete(
int $id):
void
119 $ilDB->manipulate(
'DELETE FROM booking_reservation' .
120 ' WHERE booking_reservation_id = ' .
$ilDB->quote(
$id,
'integer'));
129 return $this->db->nextId(
'booking_reservation_group');
141 bool $only_not_over_yet =
false
145 $from =
$ilDB->quote($from,
'integer');
146 $to =
$ilDB->quote($to,
'integer');
148 $date = $only_not_over_yet
149 ?
' AND date_to > ' .
$ilDB->quote(time(),
"integer")
152 $set =
$ilDB->query(
'SELECT count(*) cnt, object_id' .
153 ' FROM booking_reservation' .
154 ' WHERE ' .
$ilDB->in(
'object_id', $ids,
'',
'integer') . $date .
155 ' AND (status IS NULL OR status <> ' .
$ilDB->quote(
159 ' AND date_from <= ' . $to .
' AND date_to >= ' . $from .
160 ' GROUP BY object_id');
162 while ($row =
$ilDB->fetchAssoc($set)) {
163 $res[$row[
"object_id"]] = $row;
172 bool $a_has_schedule,
173 ?array $a_object_ids =
null,
174 ?array $filter =
null,
175 ?array $a_pool_ids =
null
181 $sql =
'SELECT r.*, o.title, o.pool_id, o.post_text, o.post_file' .
182 ' FROM booking_reservation r' .
183 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
186 if ($a_pool_ids !==
null) {
187 $where = array(
$ilDB->in(
'pool_id', $a_pool_ids,
'',
'integer'));
190 if ($a_object_ids !==
null) {
191 $where = array(
$ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
194 if (isset($filter[
'context_obj_ids']) && count($filter[
'context_obj_ids']) > 0) {
195 $where = array(
$ilDB->in(
'context_obj_id', $filter[
'context_obj_ids'],
'',
'integer'));
198 if ($filter[
'status'] ??
false) {
199 if ($filter[
'status'] > 0) {
200 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
202 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
203 ' OR status IS NULL)';
206 if (isset($filter[
'title']) && is_string($filter[
'title'])) {
207 $where[] =
'(' .
$ilDB->like(
'title',
'text',
'%' . $filter[
'title'] .
'%') .
208 ' OR ' .
$ilDB->like(
'description',
'text',
'%' . $filter[
'title'] .
'%') .
')';
210 if ($a_has_schedule) {
211 if (isset($filter[
'from']) && (
int) $filter[
'from'] > 0) {
212 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
214 if (isset($filter[
'to']) && (
int) $filter[
'to'] > 0) {
215 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
217 if (!isset($filter[
'past']) || !$filter[
'past']) {
218 $where[] =
'date_to > ' .
$ilDB->quote(time(),
'integer');
221 if (isset($filter[
'user_id']) && is_numeric($filter[
'user_id'])) {
222 $where[] =
'user_id = ' .
$ilDB->quote($filter[
'user_id'],
'integer');
224 if (count($where) > 0) {
225 $sql .=
' WHERE ' . implode(
' AND ', $where);
228 if ($a_has_schedule) {
229 $sql .=
' ORDER BY date_from DESC';
232 $sql .=
' ORDER BY status';
234 $set =
$ilDB->query($sql);
235 while ($row =
$ilDB->fetchAssoc($set)) {
236 $obj_id = $row[
"object_id"];
239 if ($a_has_schedule) {
240 $slot = $row[
"date_from"] .
"_" . $row[
"date_to"];
241 $idx = $obj_id .
"_" .
$user_id .
"_" . $slot;
245 $idx .=
"_" . $row[
"context_obj_id"];
247 if ($a_has_schedule && ($filter[
"slot"] ??
false)) {
248 $slot_idx = date(
"w", $row[
"date_from"]) .
"_" . date(
"H:i", $row[
"date_from"]) .
249 "-" . date(
"H:i", $row[
"date_to"] + 1);
250 if ($filter[
"slot"] != $slot_idx) {
255 if (!isset(
$res[$idx])) {
259 "object_id" => $obj_id
260 ,
"title" => $row[
"title"]
261 ,
"post_text" => $row[
"post_text"]
262 ,
"post_file" => $row[
"post_file"]
263 ,
"pool_id" => $row[
"pool_id"]
264 ,
"context_obj_id" => (
int) $row[
"context_obj_id"]
266 ,
"message" => (
string) $row[
"message"]
268 ,
"user_name" => $uname[
"lastname"] .
", " . $uname[
"firstname"]
269 ,
"login" => $uname[
"login"]
272 if ($a_has_schedule) {
273 $res[$idx][
"booking_reservation_id"] = $idx;
274 $res[$idx][
"date"] = date(
"Y-m-d", $row[
"date_from"]);
275 $res[$idx][
"slot"] = date(
"H:i", $row[
"date_from"]) .
" - " .
276 date(
"H:i", $row[
"date_to"] + 1);
277 $res[$idx][
"week"] = date(
"W", $row[
"date_from"]);
278 $res[$idx][
"weekday"] = date(
"w", $row[
"date_from"]);
280 $row[
"date_from"] > time());
281 $res[$idx][
"_sortdate"] = $row[
"date_from"];
284 $res[$idx][
"status"] = $row[
"status"];
286 $res[$idx][
"booking_reservation_id"] = $row[
"booking_reservation_id"];
287 $res[$idx][
"status"] = $row[
"status"];
291 $res[$idx][
"counter"]++;
307 array $context_obj_ids
309 $filter = [
"context_obj_ids" => ($context_obj_ids)];
310 $filter[
'past'] =
true;
312 $list = $this->getListByDate(
true,
null, $filter);
326 if (!is_array($this->preloaded_by_context_list)) {
327 throw new \ilBookingReservationException(
"Repo not initilialized.");
329 return array_filter($this->preloaded_by_context_list,
static function ($row) use ($context_obj_id) {
330 return ($row[
"context_obj_id"] == $context_obj_id);
336 $set = $this->db->queryF(
337 "SELECT booking_reservation_id FROM booking_reservation " .
338 " WHERE object_id = %s ",
343 while ($row = $this->db->fetchAssoc($set)) {
344 $ret[] = (
int) $row[
'booking_reservation_id'];
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Repo class for reservations Acts on tables booking_reservation (rw), booking_reservation_group (rw) a...
array $preloaded_by_context_list
getListByDate(bool $a_has_schedule, ?array $a_object_ids=null, ?array $filter=null, ?array $a_pool_ids=null)
List all reservations by date.
preloadByContextIds(array $context_obj_ids)
Preload reservation information for context obj ids.
create(int $user_id, int $assigner_id, int $object_id, int $context_obj_id, int $from, int $to, int $status, int $group_id, string $message="")
getNumberOfReservations(array $ids, int $from, int $to, bool $only_not_over_yet=false)
Get number of uncancelled reservations in time frame.
getCachedContextObjBookingInfo(int $context_obj_id)
Get context object properties info.
update(int $id, int $user_id, int $assigner_id, int $object_id, int $context_obj_id, int $from, int $to, int $status, int $group_id, string $message="")
getForId(int $id)
Get reservation data for id.
__construct(\ilDBInterface $db, ?array $preload_context_obj_ids=null)
getReservationIdsByBookingObjectId(int $booking_object_id)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
static _lookupName(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))