33 if (is_array($preload_context_obj_ids)) {
48 $set =
$ilDB->query(
'SELECT *' .
49 ' FROM booking_reservation' .
50 ' WHERE booking_reservation_id = ' .
$ilDB->quote($id,
'integer'));
51 $row =
$ilDB->fetchAssoc($set);
80 $id =
$ilDB->nextId(
'booking_reservation');
81 $ilDB->manipulate(
'INSERT INTO booking_reservation' .
82 ' (booking_reservation_id,user_id,assigner_id,object_id,context_obj_id,date_from,date_to,status,group_id)' .
83 ' VALUES (' .
$ilDB->quote($id,
'integer') .
84 ',' .
$ilDB->quote($user_id,
'integer') .
85 ',' .
$ilDB->quote($assigner_id,
'integer') .
86 ',' .
$ilDB->quote($object_id,
'integer') .
87 ',' .
$ilDB->quote($context_obj_id,
'integer') .
88 ',' .
$ilDB->quote($from,
'integer') .
89 ',' .
$ilDB->quote($to,
'integer') .
90 ',' .
$ilDB->quote($status,
'integer') .
91 ',' .
$ilDB->quote($group_id,
'integer') .
')');
121 return $ilDB->manipulate(
'UPDATE booking_reservation' .
122 ' SET object_id = ' .
$ilDB->quote($object_id,
'text') .
123 ', user_id = ' .
$ilDB->quote($user_id,
'integer') .
124 ', assigner_id = ' .
$ilDB->quote($assigner_id,
'integer') .
125 ', date_from = ' .
$ilDB->quote($from,
'integer') .
126 ', date_to = ' .
$ilDB->quote($to,
'integer') .
127 ', status = ' .
$ilDB->quote($status,
'integer') .
128 ', group_id = ' .
$ilDB->quote($group_id,
'integer') .
129 ', context_obj_id = ' .
$ilDB->quote($context_obj_id,
'integer') .
130 ' WHERE booking_reservation_id = ' .
$ilDB->quote($id,
'integer'));
138 public function delete(
int $id)
143 $ilDB->manipulate(
'DELETE FROM booking_reservation' .
144 ' WHERE booking_reservation_id = ' .
$ilDB->quote($id,
'integer'));
156 return $ilDB->nextId(
'booking_reservation_group');
172 $from =
$ilDB->quote($from,
'integer');
173 $to =
$ilDB->quote($to,
'integer');
175 $date = $only_not_over_yet
176 ?
' AND date_to > ' .
$ilDB->quote(time(),
"integer")
179 $set =
$ilDB->query(
'SELECT count(*) cnt, object_id' .
180 ' FROM booking_reservation' .
181 ' WHERE ' .
$ilDB->in(
'object_id', $ids,
'',
'integer') . $date .
182 ' AND (status IS NULL OR status <> ' .
$ilDB->quote(
186 ' AND date_from <= ' . $to .
' AND date_to >= ' . $from .
187 ' GROUP BY object_id');
189 while ($row =
$ilDB->fetchAssoc($set)) {
190 $res[$row[
"object_id"]] = $row;
205 array $a_object_ids = null,
206 array $filter = null,
207 array $a_pool_ids = null
213 $sql =
'SELECT r.*, o.title, o.pool_id' .
214 ' FROM booking_reservation r' .
215 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
217 if ($a_pool_ids !== null) {
218 $where = array(
$ilDB->in(
'pool_id', $a_pool_ids,
'',
'integer'));
221 if ($a_object_ids !== null) {
222 $where = array(
$ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
225 if (is_array($filter[
'context_obj_ids']) && count($filter[
'context_obj_ids']) > 0) {
226 $where = array(
$ilDB->in(
'context_obj_id', $filter[
'context_obj_ids'],
'',
'integer'));
229 if ($filter[
'status']) {
230 if ($filter[
'status'] > 0) {
231 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
233 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
234 ' OR status IS NULL)';
237 if ($filter[
'title']) {
238 $where[] =
'(' .
$ilDB->like(
'title',
'text',
'%' . $filter[
'title'] .
'%') .
239 ' OR ' .
$ilDB->like(
'description',
'text',
'%' . $filter[
'title'] .
'%') .
')';
241 if ($a_has_schedule) {
242 if ($filter[
'from']) {
243 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
246 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
248 if (!$filter[
'past']) {
249 $where[] =
'date_to > ' .
$ilDB->quote(time(),
'integer');
252 if ($filter[
'user_id']) {
253 $where[] =
'user_id = ' .
$ilDB->quote($filter[
'user_id'],
'integer');
261 if (
sizeof($where)) {
262 $sql .=
' WHERE ' . implode(
' AND ', $where);
265 if ($a_has_schedule) {
266 $sql .=
' ORDER BY date_from DESC';
269 $sql .=
' ORDER BY status';
272 $set =
$ilDB->query($sql);
273 while ($row =
$ilDB->fetchAssoc($set)) {
274 $obj_id = $row[
"object_id"];
275 $user_id = $row[
"user_id"];
277 if ($a_has_schedule) {
278 $slot = $row[
"date_from"] .
"_" . $row[
"date_to"];
279 $idx = $obj_id .
"_" . $user_id .
"_" . $slot;
281 $idx = $obj_id .
"_" . $user_id;
283 $idx .=
"_" . $row[
"context_obj_id"];
285 if ($a_has_schedule && $filter[
"slot"]) {
286 $slot_idx = date(
"w", $row[
"date_from"]) .
"_" . date(
"H:i", $row[
"date_from"]) .
287 "-" . date(
"H:i", $row[
"date_to"] + 1);
288 if ($filter[
"slot"] != $slot_idx) {
293 if (!isset(
$res[$idx])) {
297 "object_id" => $obj_id
298 ,
"title" => $row[
"title"]
299 ,
"pool_id" => $row[
"pool_id"]
300 ,
"context_obj_id" => (
int) $row[
"context_obj_id"]
301 ,
"user_id" => $user_id
303 ,
"user_name" => $uname[
"lastname"] .
", " . $uname[
"firstname"]
306 if ($a_has_schedule) {
307 $res[$idx][
"booking_reservation_id"] = $idx;
308 $res[$idx][
"date"] = date(
"Y-m-d", $row[
"date_from"]);
309 $res[$idx][
"slot"] = date(
"H:i", $row[
"date_from"]) .
" - " .
310 date(
"H:i", $row[
"date_to"] + 1);
311 $res[$idx][
"week"] = date(
"W", $row[
"date_from"]);
312 $res[$idx][
"weekday"] = date(
"w", $row[
"date_from"]);
314 $row[
"date_from"] > time());
315 $res[$idx][
"_sortdate"] = $row[
"date_from"];
318 $res[$idx][
"status"] = $row[
"status"];
320 $res[$idx][
"booking_reservation_id"] = $row[
"booking_reservation_id"];
321 $res[$idx][
"status"] = $row[
"status"];
325 $res[$idx][
"counter"]++;
343 $filter = [
"context_obj_ids" => ($context_obj_ids)];
344 $filter[
'past'] =
true;
347 $repo =
$f->getRepo();
348 $list = $repo->getListByDate(
true, null, $filter);
364 if (!is_array($this->preloaded_by_context_list)) {
367 return array_filter($this->preloaded_by_context_list,
function ($row) use ($context_obj_id) {
368 return ($row[
"context_obj_id"] == $context_obj_id);
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static _lookupName($a_user_id)
lookup user name
update(int $id, int $user_id, int $assigner_id, int $object_id, $context_obj_id, int $from, int $to, $status, $group_id)
Update.
Booking reservation exception.
getListByDate( $a_has_schedule, array $a_object_ids=null, array $filter=null, array $a_pool_ids=null)
List all reservations by date.
__construct(ilDBInterface $db, $preload_context_obj_ids=null)
Constructor.
$preloaded_by_context_list
create(int $user_id, int $assigner_id, int $object_id, $context_obj_id, int $from, int $to, $status, $group_id)
Insert.
getCachedContextObjBookingInfo($context_obj_id)
Get context object properties info.
getNewGroupId()
Get next group id.
foreach($_POST as $key=> $value) $res
static stableSortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
Repo class for reservations.
getNumberOfReservations(array $ids, int $from, int $to, $only_not_over_yet=false)
Get number of uncancelled reservations in time frame.
getForId(int $id)
Get reservation data for id.
preloadByContextIds($context_obj_ids)
Preload reservation information for context obj ids.
Factory for reservation repo.