42 $this->db = $DIC->database();
43 $this->
id = (int) $a_id;
62 $this->object_id = $a_object_id;
80 $this->user_id = (int) $a_user_id;
98 $this->assigner_id = (int) $a_assigner_id;
116 $this->from = (int) $a_from;
134 $this->to = (int) $a_to;
152 if ($a_status === null) {
153 $this->status = null;
156 $this->status = (int) $a_status;
176 if (in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED))) {
188 $this->group_id = $a_group_id;
208 $set =
$ilDB->query(
'SELECT *' .
209 ' FROM booking_reservation' .
210 ' WHERE booking_reservation_id = ' .
$ilDB->quote($this->id,
'integer'));
234 $this->
id =
$ilDB->nextId(
'booking_reservation');
236 return $ilDB->manipulate(
'INSERT INTO booking_reservation' .
237 ' (booking_reservation_id,user_id,assigner_id,object_id,date_from,date_to,status,group_id)' .
238 ' VALUES (' .
$ilDB->quote($this->id,
'integer') .
243 ',' .
$ilDB->quote($this->
getTo(),
'integer') .
270 return $ilDB->manipulate(
'UPDATE booking_reservation' .
271 ' SET object_id = ' .
$ilDB->quote($this->getObjectId(),
'text') .
272 ', user_id = ' .
$ilDB->quote($this->getUserId(),
'integer') .
273 ', assigner_id = ' .
$ilDB->quote($this->getAssignerId(),
'integer') .
274 ', date_from = ' .
$ilDB->quote($this->getFrom(),
'integer') .
275 ', date_to = ' .
$ilDB->quote($this->getTo(),
'integer') .
276 ', status = ' .
$ilDB->quote($this->getStatus(),
'integer') .
277 ', group_id = ' .
$ilDB->quote($this->getGroupId(),
'integer') .
278 ' WHERE booking_reservation_id = ' .
$ilDB->quote($this->id,
'integer'));
285 public function delete()
290 return $ilDB->manipulate(
'DELETE FROM booking_reservation' .
291 ' WHERE booking_reservation_id = ' .
$ilDB->quote($this->id,
'integer'));
303 $ilDB = $DIC->database();
305 return $ilDB->nextId(
'booking_reservation_group');
316 public static function getAvailableObject(array $a_ids, $a_from, $a_to, $a_return_single =
true, $a_return_counter =
false)
320 $ilDB = $DIC->database();
325 $to =
$ilDB->quote($a_to,
'integer');
327 $set =
$ilDB->query(
'SELECT count(*) cnt, object_id' .
328 ' FROM booking_reservation' .
329 ' WHERE ' .
$ilDB->in(
'object_id', $a_ids,
'',
'integer') .
330 ' AND (status IS NULL OR status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
')' .
331 ' AND ((date_from <= ' .
$from .
' AND date_to >= ' .
$from .
')' .
332 ' OR (date_from <= ' .
$to .
' AND date_to >= ' .
$to .
')' .
333 ' OR (date_from >= ' .
$from .
' AND date_to <= ' .
$to .
'))' .
334 ' GROUP BY object_id');
335 $blocked = $counter = array();
337 if (
$row[
'cnt'] >= $nr_map[
$row[
'object_id']]) {
338 $blocked[] = $row[
'object_id'];
339 } elseif ($a_return_counter) {
340 $counter[$row[
'object_id']] = (int) $nr_map[$row[
'object_id']] - (
int) $row[
'cnt'];
345 foreach ($a_ids as $obj_id) {
347 if ($bobj->getScheduleId()) {
348 include_once
"Modules/BookingManager/classes/class.ilBookingSchedule.php";
351 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
354 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
355 ? strtotime($schedule->getAvailabilityTo()->get(
IL_CAL_DATE) .
" 23:59:59")
358 if (($av_from && $a_from < $av_from) ||
359 ($av_to && $a_to > $av_to)) {
360 $blocked[] = $obj_id;
361 unset($counter[$obj_id]);
366 $available = array_diff($a_ids, $blocked);
367 if (
sizeof($available)) {
368 if ($a_return_counter) {
369 foreach ($a_ids as
$id) {
370 if (!isset($counter[$id])) {
371 $counter[
$id] = (int) $nr_map[$id];
375 } elseif ($a_return_single) {
376 return array_shift($available);
387 $ilDB = $DIC->database();
393 $a_to = strtotime(
"+1year", $a_from);
396 if ($a_from > $a_to) {
401 $to =
$ilDB->quote($a_to,
'integer');
405 $set =
$ilDB->query(
'SELECT count(*) cnt' .
406 ' FROM booking_reservation' .
407 ' WHERE object_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
408 ' AND (status IS NULL OR status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
')' .
409 ' AND date_to > ' . $now .
410 ' AND ((date_from <= ' .
$from .
' AND date_to >= ' .
$from .
')' .
411 ' OR (date_from <= ' .
$to .
' AND date_to >= ' .
$to .
')' .
412 ' OR (date_from >= ' .
$from .
' AND date_to <= ' .
$to .
'))');
414 $booked_in_period =
$row[
"cnt"];
417 $per_slot = $per_slot[$a_obj_id];
420 $schedule_slots = array();
422 $map = array_flip(array(
"su",
"mo",
"tu",
"we",
"th",
"fr",
"sa"));
423 foreach ($definition as $day => $day_slots) {
424 $schedule_slots[
$map[$day]] = $day_slots;
435 $available_in_period = 0;
437 while ($a_from < $a_to &&
440 $day_slots = $schedule_slots[date(
"w", $a_from)];
442 foreach ($day_slots as $slot) {
444 $slot = explode(
"-", $slot);
445 $slot_from = strtotime(date(
"Y-m-d", $a_from) .
" " . $slot[0]);
446 $slot_to = strtotime(date(
"Y-m-d", $a_from) .
" " . $slot[1]);
449 if ($slot_to > time() &&
450 $slot_from >= $av_from &&
451 $slot_to <= $av_to) {
452 $available_in_period += $per_slot;
457 $a_from += (60 * 60 * 24);
460 if ($available_in_period - $booked_in_period > 0) {
471 $ilDB = $DIC->database();
475 $query =
"SELECT count(user_id) total" .
476 " FROM booking_reservation" .
477 " WHERE " .
$ilDB->in(
'object_id', $booking_pool_objects,
false,
'integer') .
478 " AND user_id = " . $a_user_id .
483 return (
int)
$row[
'total'];
489 $ilDB = $DIC->database();
494 $query =
'SELECT DISTINCT bm.user_id user_id' .
495 ' FROM booking_member bm' .
496 ' WHERE bm.booking_pool_id = ' .
$ilDB->quote($pool_id,
'integer') .
497 ' AND bm.user_id NOT IN (' .
499 ' FROM booking_reservation' .
500 ' WHERE object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
514 $available = self::getNumAvailablesNoSchedule($a_obj_id);
515 return (
bool) $available;
519 $available = self::getNumAvailablesNoSchedule($a_obj_id);
520 return (
int) $available;
527 $ilDB = $DIC->database();
530 $all = (int) $all[$a_obj_id];
532 $set =
$ilDB->query(
'SELECT COUNT(*) cnt' .
533 ' FROM booking_reservation r' .
534 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)' .
535 ' WHERE (status IS NULL OR status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
')' .
536 ' AND r.object_id = ' .
$ilDB->quote($a_obj_id,
'integer'));
537 $cnt =
$ilDB->fetchAssoc($set);
538 $cnt = (int) $cnt[
'cnt'];
540 return (
int) $all - $cnt;
552 $ilDB = $DIC->database();
554 $now =
$ilDB->quote(time(),
'integer');
557 $set =
$ilDB->query(
'SELECT user_id, status, date_from, date_to' .
558 ' FROM booking_reservation' .
559 ' WHERE ((date_from <= ' . $now .
' AND date_to >= ' . $now .
')' .
560 ' OR date_from > ' . $now .
')' .
561 ' AND (status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
562 ' OR STATUS IS NULL) AND object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
563 ' ORDER BY date_from');
572 $ilDB = $DIC->database();
574 $set =
$ilDB->query(
'SELECT booking_reservation_id FROM booking_reservation' .
575 ' WHERE user_id = ' .
$ilDB->quote($a_user_id,
'integer') .
576 ' AND object_id = ' .
$ilDB->quote($a_object_id,
'integer') .
577 ' AND (status <> ' .
$ilDB->quote(self::STATUS_CANCELLED,
'integer') .
578 ' OR STATUS IS NULL)');
581 return $row[
'booking_reservation_id'];
585 $res[] =
$row[
'booking_reservation_id'];
599 public static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
603 $ilDB = $DIC->database();
605 $sql =
'SELECT r.*,o.title' .
606 ' FROM booking_reservation r' .
607 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
609 $count_sql =
'SELECT COUNT(*) AS counter' .
610 ' FROM booking_reservation r' .
611 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
613 $where = array(
$ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
614 if ($filter[
'status']) {
615 if ($filter[
'status'] > 0) {
616 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
618 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
619 ' OR status IS NULL)';
622 if ($filter[
'from']) {
623 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
626 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
628 if (
sizeof($where)) {
629 $sql .=
' WHERE ' . implode(
' AND ', $where);
630 $count_sql .=
' WHERE ' . implode(
' AND ', $where);
633 $set =
$ilDB->query($count_sql);
635 $counter =
$row[
'counter'];
637 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
639 $ilDB->setLimit($a_limit, $a_offset);
640 $set =
$ilDB->query($sql);
646 return array(
'data' =>
$res,
'counter' => $counter);
659 array $a_object_ids = null,
660 array $filter = null,
661 array $a_pool_ids = null
665 $ilDB = $DIC->database();
669 $sql =
'SELECT r.*, o.title, o.pool_id' .
670 ' FROM booking_reservation r' .
671 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
673 if ($a_pool_ids !== null) {
674 $where = array(
$ilDB->in(
'pool_id', $a_pool_ids,
'',
'integer'));
677 if ($a_object_ids !== null) {
678 $where = array(
$ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
681 if ($filter[
'status']) {
682 if ($filter[
'status'] > 0) {
683 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
685 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
686 ' OR status IS NULL)';
689 if ($filter[
'title']) {
690 $where[] =
'(' .
$ilDB->like(
'title',
'text',
'%' . $filter[
'title'] .
'%') .
691 ' OR ' .
$ilDB->like(
'description',
'text',
'%' . $filter[
'title'] .
'%') .
')';
693 if ($a_has_schedule) {
694 if ($filter[
'from']) {
695 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
698 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
700 if (!$filter[
'past']) {
701 $where[] =
'date_to > ' .
$ilDB->quote(time(),
'integer');
704 if ($filter[
'user_id']) {
705 $where[] =
'user_id = ' .
$ilDB->quote($filter[
'user_id'],
'integer');
713 if (
sizeof($where)) {
714 $sql .=
' WHERE ' . implode(
' AND ', $where);
717 if ($a_has_schedule) {
718 $sql .=
' ORDER BY date_from DESC';
721 $sql .=
' ORDER BY status';
724 $set =
$ilDB->query($sql);
726 $obj_id =
$row[
"object_id"];
729 if ($a_has_schedule) {
730 $slot =
$row[
"date_from"] .
"_" .
$row[
"date_to"];
731 $idx = $obj_id .
"_" .
$user_id .
"_" . $slot;
736 if ($a_has_schedule && $filter[
"slot"]) {
737 $slot_idx = date(
"w",
$row[
"date_from"]) .
"_" . date(
"H:i",
$row[
"date_from"]) .
738 "-" . date(
"H:i",
$row[
"date_to"] + 1);
739 if ($filter[
"slot"] != $slot_idx) {
744 if (!isset(
$res[$idx])) {
748 "object_id" => $obj_id
749 ,
"title" =>
$row[
"title"]
750 ,
"pool_id" =>
$row[
"pool_id"]
753 ,
"user_name" => $uname[
"lastname"] .
", " . $uname[
"firstname"]
756 if ($a_has_schedule) {
757 $res[$idx][
"booking_reservation_id"] = $idx;
758 $res[$idx][
"date"] = date(
"Y-m-d",
$row[
"date_from"]);
759 $res[$idx][
"slot"] = date(
"H:i",
$row[
"date_from"]) .
" - " .
760 date(
"H:i",
$row[
"date_to"] + 1);
761 $res[$idx][
"week"] = date(
"W",
$row[
"date_from"]);
762 $res[$idx][
"weekday"] = date(
"w",
$row[
"date_from"]);
763 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED &&
764 $row[
"date_from"] > time());
765 $res[$idx][
"_sortdate"] =
$row[
"date_from"];
767 $res[$idx][
"booking_reservation_id"] =
$row[
"booking_reservation_id"];
768 $res[$idx][
"status"] =
$row[
"status"];
769 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED);
772 $res[$idx][
"counter"]++;
789 $ilDB = $DIC->database();
793 $sql =
"SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
794 " FROM usr_data ud " .
795 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)" .
796 " WHERE ud.usr_id <> " .
$ilDB->quote(ANONYMOUS_USER_ID,
"integer") .
797 " AND " .
$ilDB->in(
"r.object_id", $a_object_ids,
"",
"integer") .
798 " ORDER BY ud.lastname,ud.firstname";
799 $set =
$ilDB->query($sql);
801 $res[
$row[
"usr_id"]] = $row[
"lastname"] .
", " . $row[
"firstname"] .
802 " (" . $row[
"login"] .
")";
1066 $ilDB = $DIC->database();
1068 if (self::isValidStatus($a_status)) {
1069 return $ilDB->manipulate(
'UPDATE booking_reservation' .
1070 ' SET status = ' .
$ilDB->quote($a_status,
'integer') .
1071 ' WHERE ' .
$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
1079 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
1081 $set =
$ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce" .
1082 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id" .
1083 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id" .
1084 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id" .
1085 " WHERE cc.obj_id = " .
$ilDB->quote($this->getUserId(),
'integer') .
1086 " AND br.user_id = " .
$ilDB->quote($this->getUserId(),
'integer') .
1088 " AND ce.context_id = " .
$ilDB->quote($this->
getId(),
'integer'));
1090 return $row[
"cal_id"];
1106 $ilDB = $DIC->database();
1110 $sql =
"SELECT booking_reservation_id" .
1111 " FROM booking_reservation" .
1112 " WHERE object_id = " .
$ilDB->quote($a_obj_id,
"integer") .
1113 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer") .
1114 " AND date_from = " .
$ilDB->quote($a_from,
"integer") .
1115 " AND date_to = " .
$ilDB->quote($a_to,
"integer") .
1116 " AND (status IS NULL" .
1117 " OR status <> " .
$ilDB->quote(self::STATUS_CANCELLED,
"integer") .
")";
1118 $set =
$ilDB->query($sql);
1119 while (
$row =
$ilDB->fetchAssoc($set)) {
1120 $res[] =
$row[
"booking_reservation_id"];
getAssignerId()
Get assigner user id.
static _lookupName($a_user_id)
lookup user name
setStatus($a_status)
Set booking status.
getGroupId()
Get group id.
setGroupId($a_group_id)
Set group id.
static isObjectAvailableNoSchedule($a_obj_id)
static getUserFilter(array $a_object_ids)
Get all users who have reservations for object(s)
static getNewGroupId()
Get next group id.
getAvailabilityFrom()
Get availability start.
setFrom($a_from)
Set booking from date.
schedule for booking ressource
getAvailabilityTo()
Get availability end.
getStatus()
Get booking status.
setAssignerId($a_assigner_id)
Set assigner user id.
static getObjectsForPool(int $a_pool_id)
Get all booking pool object ids from an specific booking pool.
getFrom()
Get booking from date.
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items.
static isValidStatus($a_status)
Check if given status is valid.
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
foreach($_POST as $key=> $value) $res
static getMembersWithoutReservation(int $a_object_id)
update()
Update entry in db.
static getListByDate( $a_has_schedule, array $a_object_ids=null, array $filter=null, array $a_pool_ids=null)
List all reservations by date.
getDefinition()
Get definition.
setObjectId($a_object_id)
Set object id.
static getCurrentOrUpcomingReservation($a_object_id)
Get details about object reservation.
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.
static lookupPoolId($object_id)
Lookup pool id.
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
__construct($a_id=null)
Constructor.
read()
Get dataset from db.
static isObjectAvailableInPeriod($a_obj_id, ilBookingSchedule $a_schedule, $a_from, $a_to)
static getList($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
List all reservations.
setUserId($a_user_id)
Set booking user id.
static numAvailableFromObjectNoSchedule($a_obj_id)
getObjectId()
Get object id.
save()
Create new entry in db.
static getCancelDetails($a_obj_id, $a_user_id, $a_from, $a_to)
Get reservation ids from aggregated id for cancellation.
static changeStatus(array $a_ids, $a_status)
List all reservations.
getUserId()
Get booking user id.
getTo()
Get booking to date.
setTo($a_to)
Set booking to date.
static getNumAvailablesNoSchedule($a_obj_id)