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'];
320 $available = array_diff($a_ids, $blocked);
321 if(
sizeof($available))
323 if($a_return_counter)
325 foreach($a_ids as
$id)
327 if(!isset($counter[$id]))
329 $counter[
$id] = (int)$nr_map[$id];
334 else if($a_return_single)
336 return array_shift($available);
350 $all = (int)$all[$a_obj_id];
352 $set = $ilDB->query(
'SELECT COUNT(*) cnt'.
353 ' FROM booking_reservation r'.
354 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)'.
355 ' WHERE (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
356 ' AND r.object_id = '.$ilDB->quote($a_obj_id,
'integer'));
357 $cnt = $ilDB->fetchAssoc($set);
358 $cnt = (int)$cnt[
'cnt'];
360 return (
bool)($all-$cnt);
372 $now = $ilDB->quote(time(),
'integer');
375 $set = $ilDB->query(
'SELECT user_id, status, date_from, date_to'.
376 ' FROM booking_reservation'.
377 ' WHERE ((date_from <= '.$now.
' AND date_to >= '.$now.
')'.
378 ' OR date_from > '.$now.
')'.
379 ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
380 ' OR STATUS IS NULL) AND object_id = '.$ilDB->quote($a_object_id,
'integer').
381 ' ORDER BY date_from');
382 $row = $ilDB->fetchAssoc($set);
390 $set = $ilDB->query(
'SELECT booking_reservation_id FROM booking_reservation'.
391 ' WHERE user_id = '.$ilDB->quote($a_user_id,
'integer').
392 ' AND object_id = '.$ilDB->quote($a_object_id,
'integer').
393 ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
394 ' OR STATUS IS NULL)');
397 $row = $ilDB->fetchAssoc($set);
398 return $row[
'booking_reservation_id'];
403 while(
$row = $ilDB->fetchAssoc($set))
405 $res[] =
$row[
'booking_reservation_id'];
419 static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
423 $sql =
'SELECT r.*,o.title'.
424 ' FROM booking_reservation r'.
425 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
427 $count_sql =
'SELECT COUNT(*) AS counter'.
428 ' FROM booking_reservation r'.
429 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
431 $where = array($ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
432 if($filter[
'status'])
434 if($filter[
'status'] > 0)
436 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
440 $where[] =
'(status != '.$ilDB->quote(-$filter[
'status'],
'integer').
441 ' OR status IS NULL)';
446 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
450 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
454 $sql .=
' WHERE '.implode(
' AND ', $where);
455 $count_sql .=
' WHERE '.implode(
' AND ', $where);
458 $set = $ilDB->query($count_sql);
459 $row = $ilDB->fetchAssoc($set);
460 $counter =
$row[
'counter'];
462 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
464 $ilDB->setLimit($a_limit, $a_offset);
465 $set = $ilDB->query($sql);
467 while(
$row = $ilDB->fetchAssoc($set))
472 return array(
'data'=>
$res,
'counter'=>$counter);
486 static function getListByDate($a_has_schedule, array $a_object_ids, $a_order_field, $a_order_direction, $a_offset, $a_limit, array $filter = null)
492 $sql =
'SELECT r.*, o.title'.
493 ' FROM booking_reservation r'.
494 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
496 $where = array($ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
497 if($filter[
'status'])
499 if($filter[
'status'] > 0)
501 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
505 $where[] =
'(status != '.$ilDB->quote(-$filter[
'status'],
'integer').
506 ' OR status IS NULL)';
513 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
517 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
520 if($filter[
'user_id'])
522 $where[] =
'user_id = '.$ilDB->quote($filter[
'user_id'],
'integer');
532 $sql .=
' WHERE '.implode(
' AND ', $where);
537 $sql .=
' ORDER BY date_from DESC';
542 $sql .=
' ORDER BY status';
545 $set = $ilDB->query($sql);
546 while(
$row = $ilDB->fetchAssoc($set))
548 $obj_id =
$row[
"object_id"];
553 $slot =
$row[
"date_from"].
"_".
$row[
"date_to"];
554 $idx = $obj_id.
"_".
$user_id.
"_".$slot;
561 if($a_has_schedule && $filter[
"slot"])
563 $slot_idx = date(
"w",
$row[
"date_from"]).
"_".date(
"H:i",
$row[
"date_from"]).
564 "-".date(
"H:i",
$row[
"date_to"]+1);
565 if($filter[
"slot"] != $slot_idx)
571 if(!isset(
$res[$idx]))
576 "object_id" => $obj_id
577 ,
"title" =>
$row[
"title"]
580 ,
"user_name" => $uname[
"lastname"].
", ".$uname[
"firstname"]
585 $res[$idx][
"booking_reservation_id"] = $idx;
586 $res[$idx][
"date"] = date(
"Y-m-d",
$row[
"date_from"]);
587 $res[$idx][
"slot"] = date(
"H:i",
$row[
"date_from"]).
" - ".
588 date(
"H:i",
$row[
"date_to"]+1);
589 $res[$idx][
"week"] = date(
"W",
$row[
"date_from"]);
590 $res[$idx][
"weekday"] = date(
"w",
$row[
"date_from"]);
591 $res[$idx][
"can_be_cancelled"] = (
$row[
"status"] != self::STATUS_CANCELLED &&
592 $row[
"date_from"] > time());
593 $res[$idx][
"_sortdate"] =
$row[
"date_from"];
597 $res[$idx][
"booking_reservation_id"] =
$row[
"booking_reservation_id"];
598 $res[$idx][
"status"] =
$row[
"status"];
604 $res[$idx][
"counter"]++;
611 $numeric = in_array($a_order_field, array(
"counter",
"date",
"week",
"weekday"));
614 if($a_has_schedule &&
615 in_array($a_order_field, array(
"date",
"week")))
617 $a_order_field =
"_sortdate";
623 $res = array_splice(
$res, $a_offset, $a_limit);
625 return array(
"data"=>
$res,
"counter"=>
$size);
640 $sql =
"SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login".
641 " FROM usr_data ud ".
642 " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)".
643 " WHERE ud.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer").
644 " AND ".$ilDB->in(
"r.object_id", $a_object_ids,
"",
"integer").
645 " ORDER BY ud.lastname,ud.firstname";
646 $set = $ilDB->query($sql);
647 while(
$row = $ilDB->fetchAssoc($set))
649 $res[
$row[
"usr_id"]] = $row[
"lastname"].
", ".$row[
"firstname"].
650 " (".$row[
"login"].
")";
914 if(self::isValidStatus($a_status))
916 return $ilDB->manipulate(
'UPDATE booking_reservation'.
917 ' SET status = '.$ilDB->quote($a_status,
'integer').
918 ' WHERE '.$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
927 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
929 $set = $ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce".
930 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
931 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
932 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
933 " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),
'integer').
934 " AND br.user_id = ".$ilDB->quote($this->getUserId(),
'integer').
936 " AND ce.context_id = ".$ilDB->quote($this->
getId(),
'integer'));
937 $row = $ilDB->fetchAssoc($set);
938 return $row[
"cal_id"];
956 $sql =
"SELECT booking_reservation_id".
957 " FROM booking_reservation".
958 " WHERE object_id = ".$ilDB->quote($a_obj_id,
"integer").
959 " AND user_id = ".$ilDB->quote($a_user_id,
"integer").
960 " AND date_from = ".$ilDB->quote($a_from,
"integer").
961 " AND date_to = ".$ilDB->quote($a_to,
"integer").
962 " AND (status IS NULL".
963 " OR status <> ".$ilDB->quote(self::STATUS_CANCELLED,
"integer").
")";
964 $set = $ilDB->query($sql);
965 while(
$row = $ilDB->fetchAssoc($set))
967 $res[] =
$row[
"booking_reservation_id"];