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').
", ".
175 public function delete()
177 $query =
"DELETE FROM booking_entry ".
178 "WHERE booking_id = ".$ilDB->quote($this->
getId(),
'integer');
196 $query =
"SELECT * FROM booking_entry ".
197 "WHERE booking_id = ".$ilDB->quote($this->
getId(),
'integer');
220 $a_user_id = $ilUser->getId();
237 $set = $ilDB->query(
'SELECT DISTINCT(context_id) FROM cal_entries e'.
238 ' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)'.
241 while(
$row = $ilDB->fetchAssoc($set))
243 $used[] =
$row[
'context_id'];
246 return $ilDB->query(
'DELETE FROM booking_entry WHERE '.$ilDB->in(
'booking_id', $used,
true,
'integer'));
256 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
258 $booking_id = $cal_entry->getContextId();
261 return new self($booking_id);
272 public static function isBookable(array $a_obj_ids, $a_target_obj_id = NULL)
276 if(
sizeof($a_obj_ids))
278 $query =
'SELECT DISTINCT(obj_id) FROM booking_entry'.
279 ' WHERE '.$ilDB->in(
'obj_id', $a_obj_ids,
false,
'integer');
282 $query .=
' AND (target_obj_id = '.$ilDB->quote($a_target_obj_id,
'integer').
283 ' OR target_obj_id IS NULL)';
285 $set = $ilDB->query(
$query);
287 while(
$row = $ilDB->fetchAssoc($set))
289 $all[] =
$row[
'obj_id'];
304 $set = $ilDB->query(
'SELECT COUNT(*) AS counter FROM booking_user'.
305 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer'));
306 $row = $ilDB->fetchAssoc($set);
307 return (
int)
$row[
'counter'];
319 $set = $ilDB->query(
'SELECT user_id FROM booking_user'.
320 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer'));
322 while(
$row = $ilDB->fetchAssoc($set))
335 public function hasBooked($a_entry_id, $a_user_id = NULL)
337 global $ilUser,
$ilDB;
341 $a_user_id = $ilUser->getId();
344 $set = $ilDB->query(
'SELECT COUNT(*) AS counter FROM booking_user'.
345 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
346 ' AND user_id = '.$ilDB->quote($a_user_id,
'integer'));
347 $row = $ilDB->fetchAssoc($set);
348 return (
bool)
$row[
'counter'];
357 public function isBookedOut($a_entry_id, $a_check_current_user =
false)
364 if($a_check_current_user)
370 if($ilUser->getId() == $this->
getObjId())
381 include_once
'Services/Calendar/classes/class.ilCalendarEntry.php';
396 public function book($a_entry_id, $a_user_id =
false)
398 global $ilUser,
$ilDB;
402 $a_user_id = $ilUser->getId();
405 if(!$this->
hasBooked($a_entry_id, $a_user_id))
407 $ilDB->manipulate(
'INSERT INTO booking_user (entry_id, user_id, tstamp)'.
408 ' VALUES ('.$ilDB->quote($a_entry_id,
'integer').
','.
409 $ilDB->quote($a_user_id,
'integer').
','.$ilDB->quote(time(),
'integer').
')');
411 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
413 $mail->setAppointmentId($a_entry_id);
414 $mail->setRecipients(array($a_user_id));
428 global $ilUser,
$ilDB;
432 $a_user_id = $ilUser->getId();
435 if($this->
hasBooked($a_entry_id, $a_user_id))
437 include_once
'Services/Calendar/classes/class.ilCalendarMailNotification.php';
439 $mail->setAppointmentId($a_entry_id);
440 $mail->setRecipients(array($a_user_id));
444 $ilDB->manipulate(
'DELETE FROM booking_user'.
445 ' WHERE entry_id = '.$ilDB->quote($a_entry_id,
'integer').
446 ' AND user_id = '.$ilDB->quote($a_user_id,
'integer'));