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');
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');
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;
346 $available = array_diff($a_ids, $blocked);
347 if(
sizeof($available))
349 if($a_return_counter)
351 foreach($a_ids as
$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);
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))
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');
636 $where[] =
'date_to > '.$ilDB->quote(
time(),
'integer');
639 if($filter[
'user_id'])
641 $where[] =
'user_id = '.$ilDB->quote($filter[
'user_id'],
'integer');
651 $sql .=
' WHERE '.implode(
' AND ', $where);
656 $sql .=
' ORDER BY date_from DESC';
661 $sql .=
' ORDER BY status';
664 $set = $ilDB->query($sql);
665 while(
$row = $ilDB->fetchAssoc($set))
667 $obj_id =
$row[
"object_id"];
672 $slot =
$row[
"date_from"].
"_".
$row[
"date_to"];
673 $idx = $obj_id.
"_".
$user_id.
"_".$slot;
680 if($a_has_schedule && $filter[
"slot"])
682 $slot_idx =
date(
"w",
$row[
"date_from"]).
"_".
date(
"H:i",
$row[
"date_from"]).
683 "-".date(
"H:i",
$row[
"date_to"]+1);
684 if($filter[
"slot"] != $slot_idx)
690 if(!isset(
$res[$idx]))
695 "object_id" => $obj_id
696 ,
"title" =>
$row[
"title"]
699 ,
"user_name" => $uname[
"lastname"].
", ".$uname[
"firstname"]
704 $res[$idx][
"booking_reservation_id"] = $idx;
706 $res[$idx][
"slot"] =
date(
"H:i",
$row[
"date_from"]).
" - ".
710 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED &&
712 $res[$idx][
"_sortdate"] =
$row[
"date_from"];
716 $res[$idx][
"booking_reservation_id"] =
$row[
"booking_reservation_id"];
717 $res[$idx][
"status"] =
$row[
"status"];
718 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED);
723 $res[$idx][
"counter"]++;
742 $sql =
"SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login".
743 " FROM usr_data ud ".
744 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)".
745 " WHERE ud.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer").
746 " AND ".$ilDB->in(
"r.object_id", $a_object_ids,
"",
"integer").
747 " ORDER BY ud.lastname,ud.firstname";
748 $set = $ilDB->query($sql);
749 while(
$row = $ilDB->fetchAssoc($set))
751 $res[
$row[
"usr_id"]] = $row[
"lastname"].
", ".$row[
"firstname"].
752 " (".$row[
"login"].
")";
1016 if(self::isValidStatus($a_status))
1018 return $ilDB->manipulate(
'UPDATE booking_reservation'.
1019 ' SET status = '.$ilDB->quote($a_status,
'integer').
1020 ' WHERE '.$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
1029 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
1031 $set = $ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce".
1032 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
1033 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
1034 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
1035 " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),
'integer').
1036 " AND br.user_id = ".$ilDB->quote($this->getUserId(),
'integer').
1038 " AND ce.context_id = ".$ilDB->quote($this->
getId(),
'integer'));
1039 $row = $ilDB->fetchAssoc($set);
1040 return $row[
"cal_id"];
1058 $sql =
"SELECT booking_reservation_id".
1059 " FROM booking_reservation".
1060 " WHERE object_id = ".$ilDB->quote($a_obj_id,
"integer").
1061 " AND user_id = ".$ilDB->quote($a_user_id,
"integer").
1062 " AND date_from = ".$ilDB->quote($a_from,
"integer").
1063 " AND date_to = ".$ilDB->quote($a_to,
"integer").
1064 " AND (status IS NULL".
1065 " OR status <> ".$ilDB->quote(self::STATUS_CANCELLED,
"integer").
")";
1066 $set = $ilDB->query($sql);
1067 while(
$row = $ilDB->fetchAssoc($set))
1069 $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)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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.
Create styles array
The data for the language used.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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.