31 protected \ilDBInterface
$db;
36 ?array $preload_context_obj_ids =
null
39 if (is_array($preload_context_obj_ids)) {
50 $il_db_statement = $this->db->query(
51 "SELECT * FROM booking_reservation WHERE booking_reservation_id = {$this->db->quote($id, \ilDBConstants::T_INTEGER)}"
53 return $this->db->fetchAssoc($il_db_statement) ?? [];
72 $id =
$ilDB->nextId(
'booking_reservation');
73 $ilDB->manipulate(
'INSERT INTO booking_reservation' .
74 ' (booking_reservation_id,user_id,assigner_id,object_id,context_obj_id,date_from,date_to,status,group_id,message)' .
75 ' VALUES (' .
$ilDB->quote(
$id,
'integer') .
77 ',' .
$ilDB->quote($assigner_id,
'integer') .
78 ',' .
$ilDB->quote($object_id,
'integer') .
79 ',' .
$ilDB->quote($context_obj_id,
'integer') .
80 ',' .
$ilDB->quote($from,
'integer') .
81 ',' .
$ilDB->quote($to,
'integer') .
82 ',' .
$ilDB->quote($status,
'integer') .
83 ',' .
$ilDB->quote($group_id,
'integer') .
104 return $ilDB->manipulate(
'UPDATE booking_reservation' .
105 ' SET object_id = ' .
$ilDB->quote($object_id,
'text') .
107 ', assigner_id = ' .
$ilDB->quote($assigner_id,
'integer') .
108 ', date_from = ' .
$ilDB->quote($from,
'integer') .
109 ', date_to = ' .
$ilDB->quote($to,
'integer') .
110 ', status = ' .
$ilDB->quote($status,
'integer') .
111 ', group_id = ' .
$ilDB->quote($group_id,
'integer') .
112 ', context_obj_id = ' .
$ilDB->quote($context_obj_id,
'integer') .
114 ' WHERE booking_reservation_id = ' .
$ilDB->quote(
$id,
'integer'));
117 public function delete(
int $id):
void
122 $ilDB->manipulate(
'DELETE FROM booking_reservation' .
123 ' WHERE booking_reservation_id = ' .
$ilDB->quote(
$id,
'integer'));
132 return $this->db->nextId(
'booking_reservation_group');
144 bool $only_not_over_yet =
false
146 $date = $only_not_over_yet
147 ?
" AND date_to > {$this->db->quote(time(), ilDBConstants::T_INTEGER)}"
150 $set = $this->db->query(
151 'SELECT count(*) cnt, object_id FROM booking_reservation'
152 .
" WHERE {$this->db->in('object_id', $ids, '', ilDBConstants::T_INTEGER)}{$date}"
153 .
" AND (status IS NULL OR status <> {$this->db->quote(ilBookingReservation::STATUS_CANCELLED, ilDBConstants::T_INTEGER)})"
154 .
" AND date_from = {$this->db->quote($from, ilDBConstants::T_INTEGER)} AND date_to = {$this->db->quote($to, ilDBConstants::T_INTEGER)}"
155 .
' GROUP BY object_id'
159 while ($row = $this->db->fetchAssoc($set)) {
160 $res[$row[
'object_id']] = $row;
169 bool $a_has_schedule,
170 ?array $a_object_ids =
null,
171 ?array $filter =
null,
172 ?array $a_pool_ids =
null
178 $sql =
'SELECT r.*, o.title, o.pool_id, o.post_text, o.post_file' .
179 ' FROM booking_reservation r' .
180 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
183 if ($a_pool_ids !==
null) {
184 $where = array(
$ilDB->in(
'pool_id', $a_pool_ids,
'',
'integer'));
187 if ($a_object_ids !==
null) {
188 $where = array(
$ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
191 if (isset($filter[
'context_obj_ids']) && count($filter[
'context_obj_ids']) > 0) {
192 $where = array(
$ilDB->in(
'context_obj_id', $filter[
'context_obj_ids'],
'',
'integer'));
195 if ($filter[
'status'] ??
false) {
196 if ($filter[
'status'] > 0) {
197 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
199 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
200 ' OR status IS NULL)';
203 if (isset($filter[
'title']) && is_string($filter[
'title'])) {
204 $where[] =
'(' .
$ilDB->like(
'title',
'text',
'%' . $filter[
'title'] .
'%') .
205 ' OR ' .
$ilDB->like(
'description',
'text',
'%' . $filter[
'title'] .
'%') .
')';
207 if ($a_has_schedule) {
208 if (isset($filter[
'from']) && (
int) $filter[
'from'] > 0) {
209 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
211 if (isset($filter[
'to']) && (
int) $filter[
'to'] > 0) {
212 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
214 if (!isset($filter[
'past']) || !$filter[
'past']) {
215 $where[] =
'date_to > ' .
$ilDB->quote(time(),
'integer');
218 if (isset($filter[
'user_id']) && is_numeric($filter[
'user_id'])) {
219 $where[] =
'user_id = ' .
$ilDB->quote($filter[
'user_id'],
'integer');
221 if (count($where) > 0) {
222 $sql .=
' WHERE ' . implode(
' AND ', $where);
225 if ($a_has_schedule) {
226 $sql .=
' ORDER BY date_from DESC';
229 $sql .=
' ORDER BY status';
231 $set =
$ilDB->query($sql);
232 while ($row =
$ilDB->fetchAssoc($set)) {
233 $obj_id = $row[
"object_id"];
236 if ($a_has_schedule) {
237 $slot = $row[
"date_from"] .
"_" . $row[
"date_to"];
238 $idx = $obj_id .
"_" .
$user_id .
"_" . $slot;
242 $idx .=
"_" . $row[
"context_obj_id"];
244 if ($a_has_schedule && ($filter[
"slot"] ??
false)) {
245 $slot_idx =
date(
"w", $row[
"date_from"]) .
"_" .
date(
"H:i", $row[
"date_from"]) .
246 "-" .
date(
"H:i", $row[
"date_to"] + 1);
247 if ($filter[
"slot"] != $slot_idx) {
252 if (!isset(
$res[$idx])) {
256 "object_id" => $obj_id
257 ,
"title" => $row[
"title"]
258 ,
"post_text" => $row[
"post_text"]
259 ,
"post_file" => $row[
"post_file"]
260 ,
"pool_id" => $row[
"pool_id"]
261 ,
"context_obj_id" => (
int) $row[
"context_obj_id"]
263 ,
"message" => (
string) $row[
"message"]
265 ,
"user_name" => $uname[
"lastname"] .
", " . $uname[
"firstname"]
266 ,
"login" => $uname[
"login"]
269 if ($a_has_schedule) {
270 $res[$idx][
"booking_reservation_id"] = $idx;
271 $res[$idx][
"date"] =
date(
"Y-m-d", $row[
"date_from"]);
272 $res[$idx][
"slot"] =
date(
"H:i", $row[
"date_from"]) .
" - " .
273 date(
"H:i", $row[
"date_to"] + 1);
274 $res[$idx][
"week"] =
date(
"W", $row[
"date_from"]);
275 $res[$idx][
"weekday"] =
date(
"w", $row[
"date_from"]);
277 $row[
"date_from"] > time());
278 $res[$idx][
"_sortdate"] = $row[
"date_from"];
281 $res[$idx][
"status"] = $row[
"status"];
283 $res[$idx][
"booking_reservation_id"] = $row[
"booking_reservation_id"];
284 $res[$idx][
"status"] = $row[
"status"];
288 $res[$idx][
"counter"]++;
304 array $context_obj_ids
306 $filter = [
"context_obj_ids" => ($context_obj_ids)];
307 $filter[
'past'] =
true;
309 $list = $this->getListByDate(
true,
null, $filter);
323 if (!is_array($this->preloaded_by_context_list)) {
324 throw new \ilBookingReservationException(
"Repo not initilialized.");
326 return array_filter($this->preloaded_by_context_list,
static function ($row) use ($context_obj_id) {
327 return ($row[
"context_obj_id"] == $context_obj_id);
333 $set = $this->db->queryF(
334 "SELECT booking_reservation_id FROM booking_reservation " .
335 " WHERE object_id = %s ",
340 while ($row = $this->db->fetchAssoc($set)) {
341 $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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const int STATUS_CANCELLED
static _lookupName(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($_POST as $key=> $value) $res
if(!file_exists('../ilias.ini.php'))