34 $this->
id = (int)$a_id;
53 $this->object_id = $a_object_id;
71 $this->user_id = (int)$a_user_id;
89 $this->from = (int)$a_from;
107 $this->to = (int)$a_to;
125 if($a_status === NULL)
127 $this->status = NULL;
131 $this->status = (int)$a_status;
151 if(in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED)))
164 $this->group_id = $a_group_id;
185 $set = $ilDB->query(
'SELECT *'.
186 ' FROM booking_reservation'.
187 ' WHERE booking_reservation_id = '.$ilDB->quote($this->id,
'integer'));
188 $row = $ilDB->fetchAssoc($set);
211 $this->
id = $ilDB->nextId(
'booking_reservation');
213 return $ilDB->manipulate(
'INSERT INTO booking_reservation'.
214 ' (booking_reservation_id,user_id,object_id,date_from,date_to,status,group_id)'.
215 ' VALUES ('.$ilDB->quote($this->id,
'integer').
216 ','.$ilDB->quote($this->
getUserId(),
'integer').
218 ','.$ilDB->quote($this->
getFrom(),
'integer').
219 ','.$ilDB->quote($this->
getTo(),
'integer').
220 ','.$ilDB->quote($this->
getStatus(),
'integer').
221 ','.$ilDB->quote($this->
getGroupId(),
'integer').
')');
247 return $ilDB->manipulate(
'UPDATE booking_reservation'.
248 ' SET object_id = '.$ilDB->quote($this->getObjectId(),
'text').
249 ', user_id = '.$ilDB->quote($this->getUserId(),
'integer').
250 ', date_from = '.$ilDB->quote($this->getFrom(),
'integer').
251 ', date_to = '.$ilDB->quote($this->getTo(),
'integer').
252 ', status = '.$ilDB->quote($this->getStatus(),
'integer').
253 ', group_id = '.$ilDB->quote($this->getGroupId(),
'integer').
254 ' WHERE booking_reservation_id = '.$ilDB->quote($this->id,
'integer'));
267 return $ilDB->manipulate(
'DELETE FROM booking_reservation'.
268 ' WHERE booking_reservation_id = '.$ilDB->quote($this->id,
'integer'));
280 return $ilDB->nextId(
'booking_reservation_group');
291 static function getAvailableObject(array $a_ids, $a_from, $a_to, $a_return_single =
true, $a_return_counter =
false)
297 $from = $ilDB->quote($a_from,
'integer');
298 $to = $ilDB->quote($a_to,
'integer');
300 $set = $ilDB->query(
'SELECT count(*) cnt, object_id'.
301 ' FROM booking_reservation'.
302 ' WHERE '.$ilDB->in(
'object_id', $a_ids,
'',
'integer').
303 ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
304 ' AND ((date_from <= '.$from.
' AND date_to >= '.
$from.
')'.
305 ' OR (date_from <= '.$to.
' AND date_to >= '.
$to.
')'.
306 ' OR (date_from >= '.$from.
' AND date_to <= '.
$to.
'))'.
307 ' GROUP BY object_id');
308 $blocked = $counter = array();
309 while(
$row = $ilDB->fetchAssoc($set))
311 if(
$row[
'cnt'] >= $nr_map[
$row[
'object_id']])
313 $blocked[] = $row[
'object_id'];
315 else if($a_return_counter)
317 $counter[$row[
'object_id']] = (int)$nr_map[$row[
'object_id']]-(
int)$row[
'cnt'];
322 foreach($a_ids as $obj_id)
325 if($bobj->getScheduleId())
327 include_once
"Modules/BookingManager/classes/class.ilBookingSchedule.php";
330 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
333 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
334 ? strtotime($schedule->getAvailabilityTo()->get(
IL_CAL_DATE).
" 23:59:59")
337 if(($av_from && $a_from < $av_from) ||
338 ($av_to && $a_to > $av_to))
340 $blocked[] = $obj_id;
341 unset($counter[$obj_id]);
346 $available = array_diff($a_ids, $blocked);
347 if(
sizeof($available))
349 if($a_return_counter)
351 foreach($a_ids as
$id)
353 if(!isset($counter[$id]))
355 $counter[
$id] = (int)$nr_map[$id];
360 else if($a_return_single)
362 return array_shift($available);
381 $a_to = strtotime(
"+1year", $a_from);
389 $from = $ilDB->quote($a_from,
'integer');
390 $to = $ilDB->quote($a_to,
'integer');
393 $set = $ilDB->query(
'SELECT count(*) cnt'.
394 ' FROM booking_reservation'.
395 ' WHERE object_id = '.$ilDB->quote($a_obj_id,
'integer').
396 ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
397 ' AND ((date_from <= '.$from.
' AND date_to >= '.
$from.
')'.
398 ' OR (date_from <= '.$to.
' AND date_to >= '.
$to.
')'.
399 ' OR (date_from >= '.$from.
' AND date_to <= '.
$to.
'))');
400 $row = $ilDB->fetchAssoc($set);
401 $booked_in_period =
$row[
"cnt"];
404 $per_slot = $per_slot[$a_obj_id];
407 $schedule_slots = array();
409 $map = array_flip(array(
"su",
"mo",
"tu",
"we",
"th",
"fr",
"sa"));
410 foreach($definition as $day => $day_slots)
412 $schedule_slots[$map[$day]] = $day_slots;
423 $available_in_period = 0;
425 while($a_from < $a_to &&
429 $day_slots = $schedule_slots[date(
"w", $a_from)];
432 foreach($day_slots as $slot)
435 $slot = explode(
"-", $slot);
436 $slot_from = strtotime(date(
"Y-m-d", $a_from).
" ".$slot[0]);
437 $slot_to = strtotime(date(
"Y-m-d", $a_from).
" ".$slot[1]);
440 if($slot_to > time() &&
441 $slot_from >= $av_from &&
444 $available_in_period += $per_slot;
449 $a_from += (60*60*24);
452 return (
bool)($available_in_period-$booked_in_period);
460 $all = (int)$all[$a_obj_id];
462 $set = $ilDB->query(
'SELECT COUNT(*) cnt'.
463 ' FROM booking_reservation r'.
464 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)'.
465 ' WHERE (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
466 ' AND r.object_id = '.$ilDB->quote($a_obj_id,
'integer'));
467 $cnt = $ilDB->fetchAssoc($set);
468 $cnt = (int)$cnt[
'cnt'];
470 return (
bool)($all-$cnt);
482 $now = $ilDB->quote(time(),
'integer');
485 $set = $ilDB->query(
'SELECT user_id, status, date_from, date_to'.
486 ' FROM booking_reservation'.
487 ' WHERE ((date_from <= '.$now.
' AND date_to >= '.$now.
')'.
488 ' OR date_from > '.$now.
')'.
489 ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
490 ' OR STATUS IS NULL) AND object_id = '.$ilDB->quote($a_object_id,
'integer').
491 ' ORDER BY date_from');
492 $row = $ilDB->fetchAssoc($set);
500 $set = $ilDB->query(
'SELECT booking_reservation_id FROM booking_reservation'.
501 ' WHERE user_id = '.$ilDB->quote($a_user_id,
'integer').
502 ' AND object_id = '.$ilDB->quote($a_object_id,
'integer').
503 ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
504 ' OR STATUS IS NULL)');
507 $row = $ilDB->fetchAssoc($set);
508 return $row[
'booking_reservation_id'];
513 while(
$row = $ilDB->fetchAssoc($set))
515 $res[] =
$row[
'booking_reservation_id'];
529 static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
533 $sql =
'SELECT r.*,o.title'.
534 ' FROM booking_reservation r'.
535 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
537 $count_sql =
'SELECT COUNT(*) AS counter'.
538 ' FROM booking_reservation r'.
539 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
541 $where = array($ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
542 if($filter[
'status'])
544 if($filter[
'status'] > 0)
546 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
550 $where[] =
'(status != '.$ilDB->quote(-$filter[
'status'],
'integer').
551 ' OR status IS NULL)';
556 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
560 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
564 $sql .=
' WHERE '.implode(
' AND ', $where);
565 $count_sql .=
' WHERE '.implode(
' AND ', $where);
568 $set = $ilDB->query($count_sql);
569 $row = $ilDB->fetchAssoc($set);
570 $counter =
$row[
'counter'];
572 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
574 $ilDB->setLimit($a_limit, $a_offset);
575 $set = $ilDB->query($sql);
577 while(
$row = $ilDB->fetchAssoc($set))
582 return array(
'data'=>
$res,
'counter'=>$counter);
596 static function getListByDate($a_has_schedule, array $a_object_ids, array $filter = null)
602 $sql =
'SELECT r.*, o.title'.
603 ' FROM booking_reservation r'.
604 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
606 $where = array($ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
607 if($filter[
'status'])
609 if($filter[
'status'] > 0)
611 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
615 $where[] =
'(status != '.$ilDB->quote(-$filter[
'status'],
'integer').
616 ' OR status IS NULL)';
621 $where[] =
'('.$ilDB->like(
'title',
'text',
'%'.$filter[
'title'].
'%').
622 ' OR '.$ilDB->like(
'description',
'text',
'%'.$filter[
'title'].
'%').
')';
628 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
632 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
635 if($filter[
'user_id'])
637 $where[] =
'user_id = '.$ilDB->quote($filter[
'user_id'],
'integer');
647 $sql .=
' WHERE '.implode(
' AND ', $where);
652 $sql .=
' ORDER BY date_from DESC';
657 $sql .=
' ORDER BY status';
660 $set = $ilDB->query($sql);
661 while(
$row = $ilDB->fetchAssoc($set))
663 $obj_id =
$row[
"object_id"];
668 $slot =
$row[
"date_from"].
"_".
$row[
"date_to"];
669 $idx = $obj_id.
"_".
$user_id.
"_".$slot;
676 if($a_has_schedule && $filter[
"slot"])
678 $slot_idx = date(
"w",
$row[
"date_from"]).
"_".date(
"H:i",
$row[
"date_from"]).
679 "-".date(
"H:i",
$row[
"date_to"]+1);
680 if($filter[
"slot"] != $slot_idx)
686 if(!isset(
$res[$idx]))
691 "object_id" => $obj_id
692 ,
"title" =>
$row[
"title"]
695 ,
"user_name" => $uname[
"lastname"].
", ".$uname[
"firstname"]
700 $res[$idx][
"booking_reservation_id"] = $idx;
701 $res[$idx][
"date"] = date(
"Y-m-d",
$row[
"date_from"]);
702 $res[$idx][
"slot"] = date(
"H:i",
$row[
"date_from"]).
" - ".
703 date(
"H:i",
$row[
"date_to"]+1);
704 $res[$idx][
"week"] = date(
"W",
$row[
"date_from"]);
705 $res[$idx][
"weekday"] = date(
"w",
$row[
"date_from"]);
706 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED &&
707 $row[
"date_from"] > time());
708 $res[$idx][
"_sortdate"] =
$row[
"date_from"];
712 $res[$idx][
"booking_reservation_id"] =
$row[
"booking_reservation_id"];
713 $res[$idx][
"status"] =
$row[
"status"];
714 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED);
719 $res[$idx][
"counter"]++;
738 $sql =
"SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login".
739 " FROM usr_data ud ".
740 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)".
741 " WHERE ud.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer").
742 " AND ".$ilDB->in(
"r.object_id", $a_object_ids,
"",
"integer").
743 " ORDER BY ud.lastname,ud.firstname";
744 $set = $ilDB->query($sql);
745 while(
$row = $ilDB->fetchAssoc($set))
747 $res[
$row[
"usr_id"]] = $row[
"lastname"].
", ".$row[
"firstname"].
748 " (".$row[
"login"].
")";
1012 if(self::isValidStatus($a_status))
1014 return $ilDB->manipulate(
'UPDATE booking_reservation'.
1015 ' SET status = '.$ilDB->quote($a_status,
'integer').
1016 ' WHERE '.$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
1025 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
1027 $set = $ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce".
1028 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
1029 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
1030 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
1031 " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),
'integer').
1032 " AND br.user_id = ".$ilDB->quote($this->getUserId(),
'integer').
1034 " AND ce.context_id = ".$ilDB->quote($this->
getId(),
'integer'));
1035 $row = $ilDB->fetchAssoc($set);
1036 return $row[
"cal_id"];
1054 $sql =
"SELECT booking_reservation_id".
1055 " FROM booking_reservation".
1056 " WHERE object_id = ".$ilDB->quote($a_obj_id,
"integer").
1057 " AND user_id = ".$ilDB->quote($a_user_id,
"integer").
1058 " AND date_from = ".$ilDB->quote($a_from,
"integer").
1059 " AND date_to = ".$ilDB->quote($a_to,
"integer").
1060 " AND (status IS NULL".
1061 " OR status <> ".$ilDB->quote(self::STATUS_CANCELLED,
"integer").
")";
1062 $set = $ilDB->query($sql);
1063 while(
$row = $ilDB->fetchAssoc($set))
1065 $res[] =
$row[
"booking_reservation_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.
static getListByDate($a_has_schedule, array $a_object_ids, array $filter=null)
List all reservations by date.
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)
update()
Update entry in db.
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.
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.
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.
__construct($a_id=NULL)
Constructor.
getUserId()
Get booking user id.
getTo()
Get booking to date.
setTo($a_to)
Set booking to date.