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'));
258 $from = $ilDB->quote($a_from,
'integer');
259 $to = $ilDB->quote($a_to,
'integer');
261 $set = $ilDB->query(
'SELECT object_id'.
262 ' FROM booking_reservation'.
263 ' WHERE '.$ilDB->in(
'object_id', $a_ids,
'',
'integer').
264 ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
265 ' AND ((date_from <= '.$from.
' AND date_to >= '.
$from.
')'.
266 ' OR (date_from <= '.$to.
' AND date_to >= '.
$to.
')'.
267 ' OR (date_from >= '.$from.
' AND date_to <= '.
$to.
'))');
269 while(
$row = $ilDB->fetchAssoc($set))
271 $blocked[] =
$row[
'object_id'];
273 $available = array_diff($a_ids, $blocked);
274 if(
sizeof($available))
278 return array_shift($available);
296 $now = $ilDB->quote(time(),
'integer');
299 $set = $ilDB->query(
'SELECT user_id, status, date_from, date_to'.
300 ' FROM booking_reservation'.
301 ' WHERE ((date_from <= '.$now.
' AND date_to >= '.$now.
')'.
302 ' OR date_from > '.$now.
')'.
303 ' AND status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
304 ' AND object_id = '.$ilDB->quote($a_object_id,
'integer').
305 ' ORDER BY date_from');
306 $row = $ilDB->fetchAssoc($set);
318 static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
322 $sql =
'SELECT r.*,o.title'.
323 ' FROM booking_reservation r'.
324 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
326 $count_sql =
'SELECT COUNT(*) AS counter'.
327 ' FROM booking_reservation r'.
328 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
330 $where = array($ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
333 $where[] =
'type_id = '.$ilDB->quote($filter[
'type'],
'integer');
335 if($filter[
'status'])
337 if($filter[
'status'] > 0)
339 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
343 $where[] =
'status != '.$ilDB->quote(-$filter[
'status'],
'integer');
348 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
352 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
356 $sql .=
' WHERE '.implode(
' AND ', $where);
357 $count_sql .=
' WHERE '.implode(
' AND ', $where);
360 $set = $ilDB->query($count_sql);
361 $row = $ilDB->fetchAssoc($set);
362 $counter =
$row[
'counter'];
364 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
366 $ilDB->setLimit($a_limit, $a_offset);
367 $set = $ilDB->query($sql);
368 while(
$row = $ilDB->fetchAssoc($set))
373 return array(
'data'=>
$res,
'counter'=>$counter);
386 if(self::isValidStatus($a_status))
388 return $ilDB->manipulate(
'UPDATE booking_reservation'.
389 ' SET status = '.$ilDB->quote($a_status,
'integer').
390 ' WHERE '.$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));
399 include_once
'Services/Calendar/classes/class.ilCalendarCategory.php';
401 $set = $ilDB->query(
"SELECT ce.cal_id FROM cal_entries ce".
402 " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
403 " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
404 " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
405 " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),
'integer').
406 " AND br.user_id = ".$ilDB->quote($this->getUserId(),
'integer').
408 " AND ce.context_id = ".$ilDB->quote($this->
getId(),
'integer'));
409 $row = $ilDB->fetchAssoc($set);
410 return $row[
"cal_id"];