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'));
257 $from = $ilDB->quote($a_from,
'integer');
258 $to = $ilDB->quote($a_to,
'integer');
260 $set = $ilDB->query(
'SELECT object_id'.
261 ' FROM booking_reservation'.
262 ' WHERE '.$ilDB->in(
'object_id', $a_ids,
'',
'integer').
263 ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
')'.
264 ' AND ((date_from <= '.$from.
' AND date_to >= '.
$from.
')'.
265 ' OR (date_from <= '.$to.
' AND date_to >= '.
$to.
')'.
266 ' OR (date_from >= '.$from.
' AND date_to <= '.
$to.
'))');
268 while(
$row = $ilDB->fetchAssoc($set))
270 $blocked[] =
$row[
'object_id'];
272 $available = array_diff($a_ids, $blocked);
273 if(
sizeof($available))
275 return array_shift($available);
288 $now = $ilDB->quote(time(),
'integer');
291 $set = $ilDB->query(
'SELECT user_id, status, date_from, date_to'.
292 ' FROM booking_reservation'.
293 ' WHERE ((date_from <= '.$now.
' AND date_to >= '.$now.
')'.
294 ' OR date_from > '.$now.
')'.
295 ' AND status <> '.$ilDB->quote(self::STATUS_CANCELLED,
'integer').
296 ' AND object_id = '.$ilDB->quote($a_object_id,
'integer').
297 ' ORDER BY date_from');
298 $row = $ilDB->fetchAssoc($set);
310 static function getList($a_object_ids, $a_limit = 10, $a_offset = 0, array $filter)
314 $sql =
'SELECT r.*,o.title'.
315 ' FROM booking_reservation r'.
316 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
318 $count_sql =
'SELECT COUNT(*) AS counter'.
319 ' FROM booking_reservation r'.
320 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
322 $where = array($ilDB->in(
'r.object_id', $a_object_ids,
'',
'integer'));
325 $where[] =
'type_id = '.$ilDB->quote($filter[
'type'],
'integer');
327 if($filter[
'status'])
329 if($filter[
'status'] > 0)
331 $where[] =
'status = '.$ilDB->quote($filter[
'status'],
'integer');
335 $where[] =
'status != '.$ilDB->quote(-$filter[
'status'],
'integer');
340 $where[] =
'date_from >= '.$ilDB->quote($filter[
'from'],
'integer');
344 $where[] =
'date_to <= '.$ilDB->quote($filter[
'to'],
'integer');
348 $sql .=
' WHERE '.implode(
' AND ', $where);
349 $count_sql .=
' WHERE '.implode(
' AND ', $where);
352 $set = $ilDB->query($count_sql);
353 $row = $ilDB->fetchAssoc($set);
354 $counter =
$row[
'counter'];
356 $sql .=
' ORDER BY date_from DESC, booking_reservation_id DESC';
358 $ilDB->setLimit($a_limit, $a_offset);
359 $set = $ilDB->query($sql);
360 while(
$row = $ilDB->fetchAssoc($set))
365 return array(
'data'=>
$res,
'counter'=>$counter);
378 if(self::isValidStatus($a_status))
380 return $ilDB->manipulate(
'UPDATE booking_reservation'.
381 ' SET status = '.$ilDB->quote($a_status,
'integer').
382 ' WHERE '.$ilDB->in(
'booking_reservation_id', $a_ids,
'',
'integer'));