41 $this->db = $DIC->database();
42 $this->
id = (int) $a_id;
61 $this->object_id = $a_object_id;
79 $this->user_id = (int) $a_user_id;
97 $this->from = (int) $a_from;
115 $this->
to = (int) $a_to;
133 if ($a_status === null) {
134 $this->status = null;
137 $this->status = (int) $a_status;
157 if (in_array($a_status,
array(self::STATUS_IN_USE, self::STATUS_CANCELLED))) {
169 $this->group_id = $a_group_id;
189 $set =
$ilDB->query(
'SELECT *' .
190 ' FROM booking_reservation' .
191 ' WHERE booking_reservation_id = ' .
$ilDB->quote($this->id,
'integer'));
214 $this->
id =
$ilDB->nextId(
'booking_reservation');
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') .
222 ',' .
$ilDB->quote($this->
getTo(),
'integer') .
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'));
263 public function delete()
268 return $ilDB->manipulate(
'DELETE FROM booking_reservation' .
269 ' WHERE booking_reservation_id = ' .
$ilDB->quote($this->id,
'integer'));
281 $ilDB = $DIC->database();
283 return $ilDB->nextId(
'booking_reservation_group');
298 $ilDB = $DIC->database();
303 $to =
$ilDB->quote($a_to,
'integer');
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');
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'];
323 foreach ($a_ids as $obj_id) {
325 if ($bobj->getScheduleId()) {
326 include_once
"Modules/BookingManager/classes/class.ilBookingSchedule.php";
329 $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
332 $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
333 ? strtotime($schedule->getAvailabilityTo()->get(
IL_CAL_DATE) .
" 23:59:59")
336 if (($av_from && $a_from < $av_from) ||
337 ($av_to && $a_to > $av_to)) {
338 $blocked[] = $obj_id;
344 $available = array_diff($a_ids, $blocked);
345 if (
sizeof($available)) {
346 if ($a_return_counter) {
347 foreach ($a_ids as
$id) {
353 } elseif ($a_return_single) {
354 return array_shift($available);
365 $ilDB = $DIC->database();
371 $a_to = strtotime(
"+1year", $a_from);
374 if ($a_from > $a_to) {
379 $to =
$ilDB->quote($a_to,
'integer');
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 .
'))');
390 $booked_in_period =
$row[
"cnt"];
393 $per_slot = $per_slot[$a_obj_id];
396 $schedule_slots =
array();
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;
411 $available_in_period = 0;
413 while ($a_from < $a_to &&
416 $day_slots = $schedule_slots[
date(
"w", $a_from)];
418 foreach ($day_slots as $slot) {
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]);
425 if ($slot_to >
time() &&
426 $slot_from >= $av_from &&
427 $slot_to <= $av_to) {
428 $available_in_period += $per_slot;
433 $a_from += (60*60*24);
436 return (
bool) ($available_in_period-$booked_in_period);
443 $ilDB = $DIC->database();
446 $all = (int) $all[$a_obj_id];
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'];
456 return (
bool) ($all-$cnt);
468 $ilDB = $DIC->database();
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');
488 $ilDB = $DIC->database();
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)');
497 return $row[
'booking_reservation_id'];
501 $res[] =
$row[
'booking_reservation_id'];
515 public static function getList($a_object_ids, $a_limit = 10, $a_offset = 0,
array $filter)
519 $ilDB = $DIC->database();
521 $sql =
'SELECT r.*,o.title' .
522 ' FROM booking_reservation r' .
523 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
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)';
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');
534 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
535 ' OR status IS NULL)';
538 if ($filter[
'from']) {
539 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
542 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
544 if (
sizeof($where)) {
545 $sql .=
' WHERE ' . implode(
' AND ', $where);
546 $count_sql .=
' WHERE ' . implode(
' AND ', $where);
549 $set =
$ilDB->query($count_sql);
553 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
555 $ilDB->setLimit($a_limit, $a_offset);
556 $set =
$ilDB->query($sql);
580 $ilDB = $DIC->database();
584 $sql =
'SELECT r.*, o.title' .
585 ' FROM booking_reservation r' .
586 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
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');
593 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
594 ' OR status IS NULL)';
597 if ($filter[
'title']) {
598 $where[] =
'(' .
$ilDB->like(
'title',
'text',
'%' . $filter[
'title'] .
'%') .
599 ' OR ' .
$ilDB->like(
'description',
'text',
'%' . $filter[
'title'] .
'%') .
')';
601 if ($a_has_schedule) {
602 if ($filter[
'from']) {
603 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
606 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
608 if (!$filter[
'past']) {
609 $where[] =
'date_to > ' .
$ilDB->quote(
time(),
'integer');
612 if ($filter[
'user_id']) {
613 $where[] =
'user_id = ' .
$ilDB->quote($filter[
'user_id'],
'integer');
621 if (
sizeof($where)) {
622 $sql .=
' WHERE ' . implode(
' AND ', $where);
625 if ($a_has_schedule) {
626 $sql .=
' ORDER BY date_from DESC';
629 $sql .=
' ORDER BY status';
632 $set =
$ilDB->query($sql);
634 $obj_id =
$row[
"object_id"];
637 if ($a_has_schedule) {
638 $slot =
$row[
"date_from"] .
"_" .
$row[
"date_to"];
639 $idx = $obj_id .
"_" .
$user_id .
"_" . $slot;
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) {
652 if (!isset(
$res[$idx])) {
656 "object_id" => $obj_id
657 ,
"title" =>
$row[
"title"]
660 ,
"user_name" => $uname[
"lastname"] .
", " . $uname[
"firstname"]
663 if ($a_has_schedule) {
664 $res[$idx][
"booking_reservation_id"] = $idx;
666 $res[$idx][
"slot"] =
date(
"H:i",
$row[
"date_from"]) .
" - " .
670 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED &&
672 $res[$idx][
"_sortdate"] =
$row[
"date_from"];
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);
679 $res[$idx][
"counter"]++;
696 $ilDB = $DIC->database();
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);
708 $res[
$row[
"usr_id"]] = $row[
"lastname"] .
", " . $row[
"firstname"] .
709 " (" . $row[
"login"] .
")";
973 $ilDB = $DIC->database();
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'));
986 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
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') .
995 " AND ce.context_id = " .
$ilDB->quote($this->
getId(),
'integer'));
997 return $row[
"cal_id"];
1013 $ilDB = $DIC->database();
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"];
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)
foreach($_POST as $key=> $value) $res
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.
__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.
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.
getUserId()
Get booking user id.
getTo()
Get booking to date.
setTo($a_to)
Set booking to date.