ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilBookingReservation Class Reference

a booking reservation More...

+ Collaboration diagram for ilBookingReservation:

Public Member Functions

 __construct ($a_id=null)
 Constructor. More...
 
 getId ()
 Get id. More...
 
 setObjectId ($a_object_id)
 Set object id. More...
 
 getObjectId ()
 Get object id. More...
 
 setUserId ($a_user_id)
 Set booking user id. More...
 
 getUserId ()
 Get booking user id. More...
 
 setFrom ($a_from)
 Set booking from date. More...
 
 getFrom ()
 Get booking from date. More...
 
 setTo ($a_to)
 Set booking to date. More...
 
 getTo ()
 Get booking to date. More...
 
 setStatus ($a_status)
 Set booking status. More...
 
 getStatus ()
 Get booking status. More...
 
 setGroupId ($a_group_id)
 Set group id. More...
 
 getGroupId ()
 Get group id. More...
 
 save ()
 Create new entry in db. More...
 
 update ()
 Update entry in db. More...
 
 delete ()
 Delete single entry. More...
 
 getCalendarEntry ()
 

Static Public Member Functions

static isValidStatus ($a_status)
 Check if given status is valid. More...
 
static getNewGroupId ()
 Get next group id. More...
 
static getAvailableObject (array $a_ids, $a_from, $a_to, $a_return_single=true, $a_return_counter=false)
 Check if any of given objects are bookable. More...
 
static isObjectAvailableInPeriod ($a_obj_id, ilBookingSchedule $a_schedule, $a_from, $a_to)
 
static isObjectAvailableNoSchedule ($a_obj_id)
 
static getCurrentOrUpcomingReservation ($a_object_id)
 Get details about object reservation. More...
 
static getObjectReservationForUser ($a_object_id, $a_user_id, $a_multi=false)
 
static getList ($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
 List all reservations. More...
 
static getListByDate ($a_has_schedule, array $a_object_ids, array $filter=null)
 List all reservations by date. More...
 
static getUserFilter (array $a_object_ids)
 Get all users who have reservations for object(s) More...
 
static changeStatus (array $a_ids, $a_status)
 List all reservations. More...
 
static getCancelDetails ($a_obj_id, $a_user_id, $a_from, $a_to)
 Get reservation ids from aggregated id for cancellation. More...
 

Data Fields

const STATUS_IN_USE = 2
 
const STATUS_CANCELLED = 5
 

Protected Member Functions

 read ()
 Get dataset from db. More...
 

Protected Attributes

 $db
 
 $id
 
 $object_id
 
 $user_id
 
 $from
 
 $to
 
 $status
 
 $group_id
 

Detailed Description

a booking reservation

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 12 of file class.ilBookingReservation.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingReservation::__construct (   $a_id = null)

Constructor.

if id is given will read dataset from db

Parameters
int$a_id

Definition at line 37 of file class.ilBookingReservation.php.

38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->id = (int) $a_id;
43 $this->read();
44 }
global $DIC
Definition: saml.php:7

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ changeStatus()

static ilBookingReservation::changeStatus ( array  $a_ids,
  $a_status 
)
static

List all reservations.

Parameters
array$a_object_ids
int$a_limit
int$a_offset
array$filter
array$a_group_id
Returns
array Batch update reservation status
Parameters
array$a_ids
int$a_status
Returns
bool

Definition at line 969 of file class.ilBookingReservation.php.

970 {
971 global $DIC;
972
973 $ilDB = $DIC->database();
974
975 if (self::isValidStatus($a_status)) {
976 return $ilDB->manipulate('UPDATE booking_reservation' .
977 ' SET status = ' . $ilDB->quote($a_status, 'integer') .
978 ' WHERE ' . $ilDB->in('booking_reservation_id', $a_ids, '', 'integer'));
979 }
980 }
global $ilDB

References $DIC, and $ilDB.

Referenced by ilObjBookingPoolGUI\changeStatusObject().

+ Here is the caller graph for this function:

◆ delete()

ilBookingReservation::delete ( )

Delete single entry.

Returns
bool

Definition at line 263 of file class.ilBookingReservation.php.

264 {
266
267 if ($this->id) {
268 return $ilDB->manipulate('DELETE FROM booking_reservation' .
269 ' WHERE booking_reservation_id = ' . $ilDB->quote($this->id, 'integer'));
270 }
271 }

References $db, and $ilDB.

◆ getAvailableObject()

static ilBookingReservation::getAvailableObject ( array  $a_ids,
  $a_from,
  $a_to,
  $a_return_single = true,
  $a_return_counter = false 
)
static

Check if any of given objects are bookable.

Parameters
array$a_ids
int$a_from
int$a_to
int$a_return_single
Returns
int

Definition at line 294 of file class.ilBookingReservation.php.

295 {
296 global $DIC;
297
298 $ilDB = $DIC->database();
299
301
302 $from = $ilDB->quote($a_from, 'integer');
303 $to = $ilDB->quote($a_to, 'integer');
304
305 $set = $ilDB->query('SELECT count(*) cnt, object_id' .
306 ' FROM booking_reservation' .
307 ' WHERE ' . $ilDB->in('object_id', $a_ids, '', 'integer') .
308 ' AND (status IS NULL OR status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') . ')' .
309 ' AND ((date_from <= ' . $from . ' AND date_to >= ' . $from . ')' .
310 ' OR (date_from <= ' . $to . ' AND date_to >= ' . $to . ')' .
311 ' OR (date_from >= ' . $from . ' AND date_to <= ' . $to . '))' .
312 ' GROUP BY object_id');
313 $blocked = $counter = array();
314 while ($row = $ilDB->fetchAssoc($set)) {
315 if ($row['cnt'] >= $nr_map[$row['object_id']]) {
316 $blocked[] = $row['object_id'];
317 } elseif ($a_return_counter) {
318 $counter[$row['object_id']] = (int) $nr_map[$row['object_id']]-(int) $row['cnt'];
319 }
320 }
321
322 // #17868 - validate against schedule availability
323 foreach ($a_ids as $obj_id) {
324 $bobj = new ilBookingObject($obj_id);
325 if ($bobj->getScheduleId()) {
326 include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
327 $schedule = new ilBookingSchedule($bobj->getScheduleId());
328
329 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
330 ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
331 : null;
332 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
333 ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
334 : null;
335
336 if (($av_from && $a_from < $av_from) ||
337 ($av_to && $a_to > $av_to)) {
338 $blocked[] = $obj_id;
339 unset($counter[$obj_id]);
340 }
341 }
342 }
343
344 $available = array_diff($a_ids, $blocked);
345 if (sizeof($available)) {
346 if ($a_return_counter) {
347 foreach ($a_ids as $id) {
348 if (!isset($counter[$id])) {
349 $counter[$id] = (int) $nr_map[$id];
350 }
351 }
352 return $counter;
353 } elseif ($a_return_single) {
354 return array_shift($available);
355 } else {
356 return $available;
357 }
358 }
359 }
const IL_CAL_DATE
const IL_CAL_UNIX
a bookable ressource
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items.
schedule for booking ressource
$counter

References $counter, $DIC, $from, $id, $ilDB, $row, $to, ilBookingObject\getNrOfItemsForObjects(), IL_CAL_DATE, and IL_CAL_UNIX.

Referenced by ilObjBookingPoolGUI\buildDatesBySchedule(), ilObjBookingPoolGUI\confirmedBookingNumbersObject(), and ilObjBookingPoolGUI\confirmedBookingObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCalendarEntry()

ilBookingReservation::getCalendarEntry ( )

Definition at line 982 of file class.ilBookingReservation.php.

983 {
985
986 include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
987
988 $set = $ilDB->query("SELECT ce.cal_id FROM cal_entries ce" .
989 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
990 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
991 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id" .
992 " WHERE cc.obj_id = " . $ilDB->quote($this->getUserId(), 'integer') .
993 " AND br.user_id = " . $ilDB->quote($this->getUserId(), 'integer') .
994 " AND cc.type = " . $ilDB->quote(ilCalendarCategory::TYPE_BOOK, 'integer') .
995 " AND ce.context_id = " . $ilDB->quote($this->getId(), 'integer'));
996 $row = $ilDB->fetchAssoc($set);
997 return $row["cal_id"];
998 }

References $db, $ilDB, $row, and ilCalendarCategory\TYPE_BOOK.

◆ getCancelDetails()

static ilBookingReservation::getCancelDetails (   $a_obj_id,
  $a_user_id,
  $a_from,
  $a_to 
)
static

Get reservation ids from aggregated id for cancellation.

Parameters
int$a_obj_id
int$a_user_id
int$a_from
int$a_to
Returns
array

Definition at line 1009 of file class.ilBookingReservation.php.

1010 {
1011 global $DIC;
1012
1013 $ilDB = $DIC->database();
1014
1015 $res = array();
1016
1017 $sql = "SELECT booking_reservation_id" .
1018 " FROM booking_reservation" .
1019 " WHERE object_id = " . $ilDB->quote($a_obj_id, "integer") .
1020 " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
1021 " AND date_from = " . $ilDB->quote($a_from, "integer") .
1022 " AND date_to = " . $ilDB->quote($a_to, "integer") .
1023 " AND (status IS NULL" .
1024 " OR status <> " . $ilDB->quote(self::STATUS_CANCELLED, "integer") . ")";
1025 $set = $ilDB->query($sql);
1026 while ($row = $ilDB->fetchAssoc($set)) {
1027 $res[] = $row["booking_reservation_id"];
1028 }
1029
1030 return $res;
1031 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $res, and $row.

Referenced by ilObjBookingPoolGUI\rsvConfirmCancelObject().

+ Here is the caller graph for this function:

◆ getCurrentOrUpcomingReservation()

static ilBookingReservation::getCurrentOrUpcomingReservation (   $a_object_id)
static

Get details about object reservation.

Parameters
int$a_object_id
Returns
array

Definition at line 464 of file class.ilBookingReservation.php.

465 {
466 global $DIC;
467
468 $ilDB = $DIC->database();
469
470 $now = $ilDB->quote(time(), 'integer');
471
472 $ilDB->setLimit(1);
473 $set = $ilDB->query('SELECT user_id, status, date_from, date_to' .
474 ' FROM booking_reservation' .
475 ' WHERE ((date_from <= ' . $now . ' AND date_to >= ' . $now . ')' .
476 ' OR date_from > ' . $now . ')' .
477 ' AND (status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') .
478 ' OR STATUS IS NULL) AND object_id = ' . $ilDB->quote($a_object_id, 'integer') .
479 ' ORDER BY date_from');
480 $row = $ilDB->fetchAssoc($set);
481 return $row;
482 }

References $DIC, $ilDB, and $row.

◆ getFrom()

ilBookingReservation::getFrom ( )

Get booking from date.

Returns
int

Definition at line 104 of file class.ilBookingReservation.php.

105 {
106 return $this->from;
107 }

References $from.

◆ getGroupId()

ilBookingReservation::getGroupId ( )

Get group id.

Returns
int

Definition at line 176 of file class.ilBookingReservation.php.

References $group_id.

◆ getId()

ilBookingReservation::getId ( )

Get id.

Returns
int

Definition at line 50 of file class.ilBookingReservation.php.

51 {
52 return $this->id;
53 }

References $id.

◆ getList()

static ilBookingReservation::getList (   $a_object_ids,
  $a_limit = 10,
  $a_offset = 0,
array  $filter 
)
static

List all reservations.

Parameters
array$a_object_ids
int$a_limit
int$a_offset
array$a_offset
Returns
array

Definition at line 515 of file class.ilBookingReservation.php.

516 {
517 global $DIC;
518
519 $ilDB = $DIC->database();
520
521 $sql = 'SELECT r.*,o.title' .
522 ' FROM booking_reservation r' .
523 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
524
525 $count_sql = 'SELECT COUNT(*) AS counter' .
526 ' FROM booking_reservation r' .
527 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
528
529 $where = array($ilDB->in('r.object_id', $a_object_ids, '', 'integer'));
530 if ($filter['status']) {
531 if ($filter['status'] > 0) {
532 $where[] = 'status = ' . $ilDB->quote($filter['status'], 'integer');
533 } else {
534 $where[] = '(status != ' . $ilDB->quote(-$filter['status'], 'integer') .
535 ' OR status IS NULL)';
536 }
537 }
538 if ($filter['from']) {
539 $where[] = 'date_from >= ' . $ilDB->quote($filter['from'], 'integer');
540 }
541 if ($filter['to']) {
542 $where[] = 'date_to <= ' . $ilDB->quote($filter['to'], 'integer');
543 }
544 if (sizeof($where)) {
545 $sql .= ' WHERE ' . implode(' AND ', $where);
546 $count_sql .= ' WHERE ' . implode(' AND ', $where);
547 }
548
549 $set = $ilDB->query($count_sql);
550 $row = $ilDB->fetchAssoc($set);
551 $counter = $row['counter'];
552
553 $sql .= ' ORDER BY date_from DESC, booking_reservation_id DESC';
554
555 $ilDB->setLimit($a_limit, $a_offset);
556 $set = $ilDB->query($sql);
557 $res = array();
558 while ($row = $ilDB->fetchAssoc($set)) {
559 $res[] = $row;
560 }
561
562 return array('data'=>$res, 'counter'=>$counter);
563 }

References $counter, $DIC, $ilDB, $res, and $row.

Referenced by ilBookingObjectsTableGUI\getItems().

+ Here is the caller graph for this function:

◆ getListByDate()

static ilBookingReservation::getListByDate (   $a_has_schedule,
array  $a_object_ids,
array  $filter = null 
)
static

List all reservations by date.

Parameters
bool$a_has_schedule
array$a_object_ids
string$a_order_field
string$a_order_direction
int$a_offset
int$a_limit
array$filter
Returns
array

Definition at line 576 of file class.ilBookingReservation.php.

577 {
578 global $DIC;
579
580 $ilDB = $DIC->database();
581
582 $res = array();
583
584 $sql = 'SELECT r.*, o.title' .
585 ' FROM booking_reservation r' .
586 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
587
588 $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
589 if ($filter['status']) {
590 if ($filter['status'] > 0) {
591 $where[] = 'status = ' . $ilDB->quote($filter['status'], 'integer');
592 } else {
593 $where[] = '(status != ' . $ilDB->quote(-$filter['status'], 'integer') .
594 ' OR status IS NULL)';
595 }
596 }
597 if ($filter['title']) {
598 $where[] = '(' . $ilDB->like('title', 'text', '%' . $filter['title'] . '%') .
599 ' OR ' . $ilDB->like('description', 'text', '%' . $filter['title'] . '%') . ')';
600 }
601 if ($a_has_schedule) {
602 if ($filter['from']) {
603 $where[] = 'date_from >= ' . $ilDB->quote($filter['from'], 'integer');
604 }
605 if ($filter['to']) {
606 $where[] = 'date_to <= ' . $ilDB->quote($filter['to'], 'integer');
607 }
608 if (!$filter['past']) {
609 $where[] = 'date_to > ' . $ilDB->quote(time(), 'integer');
610 }
611 }
612 if ($filter['user_id']) { // #16584
613 $where[] = 'user_id = ' . $ilDB->quote($filter['user_id'], 'integer');
614 }
615 /*
616 if($a_group_id)
617 {
618 $where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
619 }
620 */
621 if (sizeof($where)) {
622 $sql .= ' WHERE ' . implode(' AND ', $where);
623 }
624
625 if ($a_has_schedule) {
626 $sql .= ' ORDER BY date_from DESC';
627 } else {
628 // #16155 - could be cancelled and re-booked
629 $sql .= ' ORDER BY status';
630 }
631
632 $set = $ilDB->query($sql);
633 while ($row = $ilDB->fetchAssoc($set)) {
634 $obj_id = $row["object_id"];
635 $user_id = $row["user_id"];
636
637 if ($a_has_schedule) {
638 $slot = $row["date_from"] . "_" . $row["date_to"];
639 $idx = $obj_id . "_" . $user_id . "_" . $slot;
640 } else {
641 $idx = $obj_id . "_" . $user_id;
642 }
643
644 if ($a_has_schedule && $filter["slot"]) {
645 $slot_idx = date("w", $row["date_from"]) . "_" . date("H:i", $row["date_from"]) .
646 "-" . date("H:i", $row["date_to"]+1);
647 if ($filter["slot"] != $slot_idx) {
648 continue;
649 }
650 }
651
652 if (!isset($res[$idx])) {
654
655 $res[$idx] = array(
656 "object_id" => $obj_id
657 ,"title" => $row["title"]
658 ,"user_id" => $user_id
659 ,"counter" => 1
660 ,"user_name" => $uname["lastname"] . ", " . $uname["firstname"] // #17862
661 );
662
663 if ($a_has_schedule) {
664 $res[$idx]["booking_reservation_id"] = $idx;
665 $res[$idx]["date"] = date("Y-m-d", $row["date_from"]);
666 $res[$idx]["slot"] = date("H:i", $row["date_from"]) . " - " .
667 date("H:i", $row["date_to"]+1);
668 $res[$idx]["week"] = date("W", $row["date_from"]);
669 $res[$idx]["weekday"] = date("w", $row["date_from"]);
670 $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED &&
671 $row["date_from"] > time());
672 $res[$idx]["_sortdate"] = $row["date_from"];
673 } else {
674 $res[$idx]["booking_reservation_id"] = $row["booking_reservation_id"];
675 $res[$idx]["status"] = $row["status"];
676 $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED);
677 }
678 } else {
679 $res[$idx]["counter"]++;
680 }
681 }
682
683 return $res;
684 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static _lookupName($a_user_id)
lookup user name

References $DIC, $ilDB, $res, $row, $user_id, ilObjUser\_lookupName(), date, and STATUS_CANCELLED.

Referenced by ilBookingReservationsTableGUI\getItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewGroupId()

static ilBookingReservation::getNewGroupId ( )
static

Get next group id.

Returns
int

Definition at line 277 of file class.ilBookingReservation.php.

278 {
279 global $DIC;
280
281 $ilDB = $DIC->database();
282
283 return $ilDB->nextId('booking_reservation_group');
284 }

References $DIC, and $ilDB.

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

+ Here is the caller graph for this function:

◆ getObjectId()

ilBookingReservation::getObjectId ( )

Get object id.

Returns
int

Definition at line 68 of file class.ilBookingReservation.php.

References $object_id.

◆ getObjectReservationForUser()

static ilBookingReservation::getObjectReservationForUser (   $a_object_id,
  $a_user_id,
  $a_multi = false 
)
static

Definition at line 484 of file class.ilBookingReservation.php.

485 {
486 global $DIC;
487
488 $ilDB = $DIC->database();
489
490 $set = $ilDB->query('SELECT booking_reservation_id FROM booking_reservation' .
491 ' WHERE user_id = ' . $ilDB->quote($a_user_id, 'integer') .
492 ' AND object_id = ' . $ilDB->quote($a_object_id, 'integer') .
493 ' AND (status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') .
494 ' OR STATUS IS NULL)');
495 if (!$a_multi) {
496 $row = $ilDB->fetchAssoc($set);
497 return $row['booking_reservation_id'];
498 } else {
499 $res = array();
500 while ($row = $ilDB->fetchAssoc($set)) {
501 $res[] = $row['booking_reservation_id'];
502 }
503 return $res;
504 }
505 }

References $DIC, $ilDB, $res, and $row.

Referenced by ilObjBookingPoolGUI\confirmedBookingObject(), ilBookingObjectGUI\deliverPostFile(), ilBookingObjectGUI\displayPostInfo(), and ilBookingObjectGUI\rsvCancelUser().

+ Here is the caller graph for this function:

◆ getStatus()

ilBookingReservation::getStatus ( )

Get booking status.

Returns
int

Definition at line 145 of file class.ilBookingReservation.php.

References $status.

◆ getTo()

ilBookingReservation::getTo ( )

Get booking to date.

Returns
int

Definition at line 122 of file class.ilBookingReservation.php.

123 {
124 return $this->to;
125 }

References $to.

◆ getUserFilter()

static ilBookingReservation::getUserFilter ( array  $a_object_ids)
static

Get all users who have reservations for object(s)

Parameters
array$a_object_ids
Returns
array

Definition at line 692 of file class.ilBookingReservation.php.

693 {
694 global $DIC;
695
696 $ilDB = $DIC->database();
697
698 $res = array();
699
700 $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
701 " FROM usr_data ud " .
702 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)" .
703 " WHERE ud.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
704 " AND " . $ilDB->in("r.object_id", $a_object_ids, "", "integer") .
705 " ORDER BY ud.lastname,ud.firstname";
706 $set = $ilDB->query($sql);
707 while ($row = $ilDB->fetchAssoc($set)) {
708 $res[$row["usr_id"]] = $row["lastname"] . ", " . $row["firstname"] .
709 " (" . $row["login"] . ")";
710 }
711
712 return $res;
713 }

References $DIC, $ilDB, $res, and $row.

Referenced by ilBookingReservationsTableGUI\initFilter().

+ Here is the caller graph for this function:

◆ getUserId()

ilBookingReservation::getUserId ( )

Get booking user id.

Returns
int

Definition at line 86 of file class.ilBookingReservation.php.

87 {
88 return $this->user_id;
89 }

References $user_id.

◆ isObjectAvailableInPeriod()

static ilBookingReservation::isObjectAvailableInPeriod (   $a_obj_id,
ilBookingSchedule  $a_schedule,
  $a_from,
  $a_to 
)
static

Definition at line 361 of file class.ilBookingReservation.php.

362 {
363 global $DIC;
364
365 $ilDB = $DIC->database();
366
367 if (!$a_from) {
368 $a_from = time();
369 }
370 if (!$a_to) {
371 $a_to = strtotime("+1year", $a_from);
372 }
373
374 if ($a_from > $a_to) {
375 return;
376 }
377
378 $from = $ilDB->quote($a_from, 'integer');
379 $to = $ilDB->quote($a_to, 'integer');
380
381 // all bookings in period
382 $set = $ilDB->query('SELECT count(*) cnt' .
383 ' FROM booking_reservation' .
384 ' WHERE object_id = ' . $ilDB->quote($a_obj_id, 'integer') .
385 ' AND (status IS NULL OR status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') . ')' .
386 ' AND ((date_from <= ' . $from . ' AND date_to >= ' . $from . ')' .
387 ' OR (date_from <= ' . $to . ' AND date_to >= ' . $to . ')' .
388 ' OR (date_from >= ' . $from . ' AND date_to <= ' . $to . '))');
389 $row = $ilDB->fetchAssoc($set);
390 $booked_in_period = $row["cnt"];
391
392 $per_slot = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
393 $per_slot = $per_slot[$a_obj_id];
394
395 // max available nr of items per (week)day
396 $schedule_slots = array();
397 $definition = $a_schedule->getDefinition();
398 $map = array_flip(array("su", "mo", "tu", "we", "th", "fr", "sa"));
399 foreach ($definition as $day => $day_slots) {
400 $schedule_slots[$map[$day]] = $day_slots;
401 }
402
403 $av_from = ($a_schedule->getAvailabilityFrom() && !$a_schedule->getAvailabilityFrom()->isNull())
404 ? $a_schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
405 : null;
406 $av_to = ($a_schedule->getAvailabilityTo() && !$a_schedule->getAvailabilityTo()->isNull())
407 ? strtotime($a_schedule->getAvailabilityTo()->get(IL_CAL_DATE) . " 23:59:59")
408 : null;
409
410 // sum up max available items in period per (week)day
411 $available_in_period = 0;
412 $loop = 0;
413 while ($a_from < $a_to &&
414 ++$loop < 1000) {
415 // any slots for current weekday?
416 $day_slots = $schedule_slots[date("w", $a_from)];
417 if ($day_slots) {
418 foreach ($day_slots as $slot) {
419 // convert slot to current datetime
420 $slot = explode("-", $slot);
421 $slot_from = strtotime(date("Y-m-d", $a_from) . " " . $slot[0]);
422 $slot_to = strtotime(date("Y-m-d", $a_from) . " " . $slot[1]);
423
424 // slot has to be in the future and part of schedule availability
425 if ($slot_to > time() &&
426 $slot_from >= $av_from &&
427 $slot_to <= $av_to) {
428 $available_in_period += $per_slot;
429 }
430 }
431 }
432
433 $a_from += (60*60*24);
434 }
435
436 return (bool) ($available_in_period-$booked_in_period);
437 }
getAvailabilityTo()
Get availability end.
getAvailabilityFrom()
Get availability start.
getDefinition()
Get definition.

References $DIC, $from, $ilDB, $row, $to, date, ilBookingSchedule\getAvailabilityFrom(), ilBookingSchedule\getAvailabilityTo(), ilBookingSchedule\getDefinition(), ilBookingObject\getNrOfItemsForObjects(), IL_CAL_DATE, and IL_CAL_UNIX.

Referenced by ilBookingObjectsTableGUI\getItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObjectAvailableNoSchedule()

static ilBookingReservation::isObjectAvailableNoSchedule (   $a_obj_id)
static

Definition at line 439 of file class.ilBookingReservation.php.

440 {
441 global $DIC;
442
443 $ilDB = $DIC->database();
444
445 $all = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
446 $all = (int) $all[$a_obj_id];
447
448 $set = $ilDB->query('SELECT COUNT(*) cnt' .
449 ' FROM booking_reservation r' .
450 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)' .
451 ' WHERE (status IS NULL OR status <> ' . $ilDB->quote(self::STATUS_CANCELLED, 'integer') . ')' .
452 ' AND r.object_id = ' . $ilDB->quote($a_obj_id, 'integer'));
453 $cnt = $ilDB->fetchAssoc($set);
454 $cnt = (int) $cnt['cnt'];
455
456 return (bool) ($all-$cnt); // #11864
457 }

References $DIC, $ilDB, and ilBookingObject\getNrOfItemsForObjects().

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidStatus()

static ilBookingReservation::isValidStatus (   $a_status)
static

Check if given status is valid.

Parameters
int$a_status
Returns
bool

Definition at line 155 of file class.ilBookingReservation.php.

156 {
157 if (in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED))) {
158 return true;
159 }
160 return false;
161 }

Referenced by setStatus().

+ Here is the caller graph for this function:

◆ read()

ilBookingReservation::read ( )
protected

Get dataset from db.

Definition at line 184 of file class.ilBookingReservation.php.

185 {
187
188 if ($this->id) {
189 $set = $ilDB->query('SELECT *' .
190 ' FROM booking_reservation' .
191 ' WHERE booking_reservation_id = ' . $ilDB->quote($this->id, 'integer'));
192 $row = $ilDB->fetchAssoc($set);
193 $this->setUserId($row['user_id']);
194 $this->setObjectId($row['object_id']);
195 $this->setFrom($row['date_from']);
196 $this->setTo($row['date_to']);
197 $this->setStatus($row['status']);
198 $this->setGroupId($row['group_id']);
199 }
200 }
setTo($a_to)
Set booking to date.
setObjectId($a_object_id)
Set object id.
setFrom($a_from)
Set booking from date.
setGroupId($a_group_id)
Set group id.
setStatus($a_status)
Set booking status.
setUserId($a_user_id)
Set booking user id.

References $db, $ilDB, $row, setFrom(), setGroupId(), setObjectId(), setStatus(), setTo(), and setUserId().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBookingReservation::save ( )

Create new entry in db.

Returns
bool

Definition at line 206 of file class.ilBookingReservation.php.

207 {
209
210 if ($this->id) {
211 return false;
212 }
213
214 $this->id = $ilDB->nextId('booking_reservation');
215
216 return $ilDB->manipulate('INSERT INTO booking_reservation' .
217 ' (booking_reservation_id,user_id,object_id,date_from,date_to,status,group_id)' .
218 ' VALUES (' . $ilDB->quote($this->id, 'integer') .
219 ',' . $ilDB->quote($this->getUserId(), 'integer') .
220 ',' . $ilDB->quote($this->getObjectId(), 'integer') .
221 ',' . $ilDB->quote($this->getFrom(), 'integer') .
222 ',' . $ilDB->quote($this->getTo(), 'integer') .
223 ',' . $ilDB->quote($this->getStatus(), 'integer') .
224 ',' . $ilDB->quote($this->getGroupId(), 'integer') . ')');
225 }

References $db, and $ilDB.

◆ setFrom()

ilBookingReservation::setFrom (   $a_from)

Set booking from date.

Parameters
int$a_from

Definition at line 95 of file class.ilBookingReservation.php.

96 {
97 $this->from = (int) $a_from;
98 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setGroupId()

ilBookingReservation::setGroupId (   $a_group_id)

Set group id.

Parameters
int$a_group_id

Definition at line 167 of file class.ilBookingReservation.php.

168 {
169 $this->group_id = $a_group_id;
170 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setObjectId()

ilBookingReservation::setObjectId (   $a_object_id)

Set object id.

Parameters
int$a_object_id

Definition at line 59 of file class.ilBookingReservation.php.

60 {
61 $this->object_id = $a_object_id;
62 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setStatus()

ilBookingReservation::setStatus (   $a_status)

Set booking status.

Parameters
int$a_status

Definition at line 131 of file class.ilBookingReservation.php.

132 {
133 if ($a_status === null) {
134 $this->status = null;
135 }
136 if ($this->isValidStatus((int) $a_status)) {
137 $this->status = (int) $a_status;
138 }
139 }
static isValidStatus($a_status)
Check if given status is valid.

References isValidStatus().

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTo()

ilBookingReservation::setTo (   $a_to)

Set booking to date.

Parameters
int$a_to

Definition at line 113 of file class.ilBookingReservation.php.

114 {
115 $this->to = (int) $a_to;
116 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setUserId()

ilBookingReservation::setUserId (   $a_user_id)

Set booking user id.

Parameters
int$a_user_id

Definition at line 77 of file class.ilBookingReservation.php.

78 {
79 $this->user_id = (int) $a_user_id;
80 }

Referenced by read().

+ Here is the caller graph for this function:

◆ update()

ilBookingReservation::update ( )

Update entry in db.

Returns
bool

Definition at line 231 of file class.ilBookingReservation.php.

232 {
234
235 if (!$this->id) {
236 return false;
237 }
238
239 /* there can only be 1
240 if($this->getStatus() == self::STATUS_IN_USE)
241 {
242 $ilDB->manipulate('UPDATE booking_reservation'.
243 ' SET status = '.$ilDB->quote(NULL, 'integer').
244 ' WHERE object_id = '.$ilDB->quote($this->getObjectId(), 'integer').
245 ' AND status = '.$ilDB->quote(self::STATUS_IN_USE, 'integer'));
246 }
247 */
248
249 return $ilDB->manipulate('UPDATE booking_reservation' .
250 ' SET object_id = ' . $ilDB->quote($this->getObjectId(), 'text') .
251 ', user_id = ' . $ilDB->quote($this->getUserId(), 'integer') .
252 ', date_from = ' . $ilDB->quote($this->getFrom(), 'integer') .
253 ', date_to = ' . $ilDB->quote($this->getTo(), 'integer') .
254 ', status = ' . $ilDB->quote($this->getStatus(), 'integer') .
255 ', group_id = ' . $ilDB->quote($this->getGroupId(), 'integer') .
256 ' WHERE booking_reservation_id = ' . $ilDB->quote($this->id, 'integer'));
257 }

References $db, and $ilDB.

Field Documentation

◆ $db

ilBookingReservation::$db
protected

Definition at line 17 of file class.ilBookingReservation.php.

Referenced by delete(), getCalendarEntry(), read(), save(), and update().

◆ $from

ilBookingReservation::$from
protected

◆ $group_id

ilBookingReservation::$group_id
protected

Definition at line 25 of file class.ilBookingReservation.php.

Referenced by getGroupId().

◆ $id

ilBookingReservation::$id
protected

Definition at line 19 of file class.ilBookingReservation.php.

Referenced by getAvailableObject(), and getId().

◆ $object_id

ilBookingReservation::$object_id
protected

Definition at line 20 of file class.ilBookingReservation.php.

Referenced by getObjectId().

◆ $status

ilBookingReservation::$status
protected

Definition at line 24 of file class.ilBookingReservation.php.

Referenced by getStatus().

◆ $to

ilBookingReservation::$to
protected

◆ $user_id

ilBookingReservation::$user_id
protected

Definition at line 21 of file class.ilBookingReservation.php.

Referenced by getListByDate(), and getUserId().

◆ STATUS_CANCELLED

◆ STATUS_IN_USE


The documentation for this class was generated from the following file: