28 $this->
setId($a_booking_id);
42 $this->
id = (int)$a_id;
61 $this->obj_id = (int)$a_id;
80 $this->deadline = (int)$a_hours;
99 $this->num_bookings = (int)$a_num;
118 $this->target_obj_id = (int)$a_obj_id;
138 $this->
setId($ilDB->nextId(
'booking_entry'));
139 $query =
'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,target_obj_id) '.
141 $ilDB->quote($this->
getId(),
'integer').
', '.
142 $ilDB->quote($this->
getObjId(),
'integer').
', '.
147 $ilDB->manipulate($query);
162 $query =
"UPDATE booking_entry SET ".
163 "SET obj_id = ".$ilDB->quote($this->
getObjId(),
'integer').
", ".
165 " target_obj_id = ".$ilDB->quote($this->
getTargetObjId(),
'integer').
", ".
167 $ilDB->manipulate(
$query);
175 public function delete()
179 $query =
"DELETE FROM booking_entry ".
180 "WHERE booking_id = ".$ilDB->quote($this->
getId(),
'integer');
181 $ilDB->manipulate(
$query);
198 $query =
"SELECT * FROM booking_entry ".
199 "WHERE booking_id = ".$ilDB->quote($this->
getId(),
'integer');
222 $a_user_id = $ilUser->getId();
239 $set = $ilDB->query(
'SELECT DISTINCT(context_id) FROM cal_entries e'.
240 ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)'.
243 while(
$row = $ilDB->fetchAssoc($set))
245 $used[] =
$row[
'context_id'];
248 return $ilDB->query(
'DELETE FROM booking_entry WHERE '.$ilDB->in(
'booking_id', $used,
true,
'integer'));
258 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
260 $booking_id = $cal_entry->getContextId();
263 return new self($booking_id);
274 public static function isBookable(array $a_obj_ids, $a_target_obj_id = NULL)
278 if(
sizeof($a_obj_ids))
280 $query =
'SELECT DISTINCT(obj_id) FROM booking_entry'.
281 ' WHERE '.$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer');
284 $query .=
' AND (target_obj_id = '.$ilDB->quote($a_target_obj_id,
'integer').
285 ' OR target_obj_id IS NULL)';
287 $set = $ilDB->query(
$query);
289 while(
$row = $ilDB->fetchAssoc($set))
291 $all[] =
$row[
'obj_id'];
306 $set = $ilDB->query(
'SELECT COUNT(*) AS counter FROM booking_user'.
307 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer'));
308 $row = $ilDB->fetchAssoc($set);
309 return (
int)
$row[
'counter'];
321 $set = $ilDB->query(
'SELECT user_id FROM booking_user'.
322 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer'));
324 while(
$row = $ilDB->fetchAssoc($set))
337 public function hasBooked($a_entry_id, $a_user_id = NULL)
343 $a_user_id = $ilUser->getId();
346 $set = $ilDB->query(
'SELECT COUNT(*) AS counter FROM booking_user'.
347 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
348 ' AND user_id = '.$ilDB->quote($a_user_id,
'integer'));
349 $row = $ilDB->fetchAssoc($set);
350 return (
bool)
$row[
'counter'];
359 public function isBookedOut($a_entry_id, $a_check_current_user =
false)
366 if($a_check_current_user)
372 if($ilUser->getId() == $this->
getObjId())
383 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
398 public function book($a_entry_id, $a_user_id =
false)
404 $a_user_id = $ilUser->getId();
407 if(!$this->
hasBooked($a_entry_id, $a_user_id))
409 $ilDB->manipulate(
'INSERT INTO booking_user (entry_id, user_id, tstamp)'.
410 ' VALUES ('.$ilDB->quote($a_entry_id,
'integer').
','.
411 $ilDB->quote($a_user_id,
'integer').
','.$ilDB->quote(time(),
'integer').
')');
413 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
415 $mail->setAppointmentId($a_entry_id);
416 $mail->setRecipients(array($a_user_id));
434 $a_user_id = $ilUser->getId();
437 if($this->
hasBooked($a_entry_id, $a_user_id))
439 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
441 $mail->setAppointmentId($a_entry_id);
442 $mail->setRecipients(array($a_user_id));
446 $ilDB->manipulate(
'DELETE FROM booking_user'.
447 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
448 ' AND user_id = '.$ilDB->quote($a_user_id,
'integer'));