33 $this->
id = (int)$a_id;
52 $this->object_id = $a_object_id;
70 $this->user_id = (int)$a_user_id;
88 $this->from = (int)$a_from;
106 $this->to = (int)$a_to;
124 if($a_status === NULL)
126 $this->status = NULL;
130 $this->status = (int)$a_status;
150 if(in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED)))
166 $set = $ilDB->query(
'SELECT object_id,user_id,date_from,date_to,status'.
167 ' FROM booking_reservation'.
168 ' WHERE booking_reservation_id = '.$ilDB->quote($this->id,
'integer'));
169 $row = $ilDB->fetchAssoc($set);
191 $this->
id = $ilDB->nextId(
'booking_reservation');
193 return $ilDB->manipulate(
'INSERT INTO booking_reservation'.
194 ' (booking_reservation_id,user_id,object_id,date_from,date_to,status)'.
195 ' VALUES ('.$ilDB->quote($this->id,
'integer').
','.$ilDB->quote($this->
getUserId(),
'integer').
196 ','.$ilDB->quote($this->
getObjectId(),
'integer').
','.$ilDB->quote($this->
getFrom(),
'integer').
197 ','.$ilDB->quote($this->
getTo(),
'integer').
','.$ilDB->quote($this->
getStatus(),
'integer').
')');
214 if($this->
getStatus() == self::STATUS_IN_USE)
216 $ilDB->manipulate(
'UPDATE booking_reservation'.
217 ' SET status = '.$ilDB->quote(NULL,
'integer').
218 ' WHERE object_id = '.$ilDB->quote($this->
getObjectId(),
'integer').
219 ' AND status = '.$ilDB->quote(self::STATUS_IN_USE,
'integer'));
222 return $ilDB->manipulate(
'UPDATE booking_reservation'.
223 ' SET object_id = '.$ilDB->quote($this->getObjectId(),
'text').
224 ', user_id = '.$ilDB->quote($this->getUserId(),
'integer').
225 ', date_from = '.$ilDB->quote($this->getFrom(),
'integer').
226 ', date_to = '.$ilDB->quote($this->getTo(),
'integer').
227 ', status = '.$ilDB->quote($this->getStatus(),
'integer').
228 ' WHERE booking_reservation_id = '.$ilDB->quote($this->id,
'integer'));
241 return $ilDB->manipulate(
'DELETE FROM booking_reservation'.
242 ' WHERE booking_reservation_id = '.$ilDB->quote($this->id,
'integer'));
260 $from = $ilDB->quote($a_from,
'integer');
261 $to = $ilDB->quote($a_to,
'integer');
263 $set = $ilDB->query(
'SELECT count(*) cnt, object_id'.
264 ' FROM booking_reservation'.
265 ' WHERE '.$ilDB->in(
'object_id', $a_ids,
'',
'integer').
266 ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
267 ' AND ((date_from <= '.$from.
' AND date_to >= '.
$from.
')'.
268 ' OR (date_from <= '.$to.
' AND date_to >= '.
$to.
')'.
269 ' OR (date_from >= '.$from.
' AND date_to <= '.
$to.
'))'.
270 ' GROUP BY object_id');
272 while(
$row = $ilDB->fetchAssoc($set))
274 if(
$row[
'cnt'] >= $nr_map[
$row[
'object_id']])
276 $blocked[] = $row[
'object_id'];
279 $available = array_diff($a_ids, $blocked);
280 if(
sizeof($available))
284 return array_shift($available);
298 $all = (int)$all[$a_obj_id];
300 $set = $ilDB->query(
'SELECT COUNT(*) cnt'.
301 ' FROM booking_reservation r'.
302 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)'.
303 ' WHERE (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
304 ' AND r.object_id = '.$ilDB->quote($a_obj_id,
'integer'));
305 $cnt = $ilDB->fetchAssoc($set);
306 $cnt = (int)$cnt[
'cnt'];
308 return (
bool)($all-$cnt);
320 $now = $ilDB->quote(time(),
'integer');
323 $set = $ilDB->query(
'SELECT user_id, status, date_from, date_to'.
324 ' FROM booking_reservation'.
325 ' WHERE ((date_from <= '.$now.
' AND date_to >= '.$now.
')'.
326 ' OR date_from > '.$now.
')'.
327 ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
328 ' OR STATUS IS NULL) AND object_id = '.$ilDB->quote($a_object_id,
'integer').
329 ' ORDER BY date_from');
330 $row = $ilDB->fetchAssoc($set);
338 $set = $ilDB->query(
'SELECT booking_reservation_id FROM booking_reservation'.
339 ' WHERE user_id = '.$ilDB->quote($a_user_id,
'integer').
340 ' AND object_id = '.$ilDB->quote($a_object_id,
'integer').
341 ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
342 ' OR STATUS IS NULL)');
343 $row = $ilDB->fetchAssoc($set);
344 return $row[
'booking_reservation_id'];
355 static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
359 $sql =
'SELECT r.*,o.title'.
360 ' FROM booking_reservation r'.
361 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
363 $count_sql =
'SELECT COUNT(*) AS counter'.
364 ' FROM booking_reservation r'.
365 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
367 $where = array($ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
368 if($filter[
'status'])
370 if($filter[
'status'] > 0)
372 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
376 $where[] =
'(status != '.$ilDB->quote(-$filter[
'status'],
'integer').
377 ' OR status IS NULL)';
382 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
386 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
390 $sql .=
' WHERE '.implode(
' AND ', $where);
391 $count_sql .=
' WHERE '.implode(
' AND ', $where);
394 $set = $ilDB->query($count_sql);
395 $row = $ilDB->fetchAssoc($set);
396 $counter =
$row[
'counter'];
398 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
400 $ilDB->setLimit($a_limit, $a_offset);
401 $set = $ilDB->query($sql);
403 while(
$row = $ilDB->fetchAssoc($set))
408 return array(
'data'=>
$res,
'counter'=>$counter);
421 if(self::isValidStatus($a_status))
423 return $ilDB->manipulate(
'UPDATE booking_reservation'.
424 ' SET status = '.$ilDB->quote($a_status,
'integer').
425 ' WHERE '.$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
434 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
436 $set = $ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce".
437 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
438 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
439 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
440 " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),
'integer').
441 " AND br.user_id = ".$ilDB->quote($this->getUserId(),
'integer').
443 " AND ce.context_id = ".$ilDB->quote($this->
getId(),
'integer'));
444 $row = $ilDB->fetchAssoc($set);
445 return $row[
"cal_id"];