Repo class for reservations.
More...
|
| __construct (ilDBInterface $db, $preload_context_obj_ids=null) |
| Constructor. More...
|
|
| getForId (int $id) |
| Get reservation data for id. More...
|
|
| create (int $user_id, int $assigner_id, int $object_id, $context_obj_id, int $from, int $to, $status, $group_id) |
| Insert. More...
|
|
| update (int $id, int $user_id, int $assigner_id, int $object_id, $context_obj_id, int $from, int $to, $status, $group_id) |
| Update. More...
|
|
| delete (int $id) |
| Delete. More...
|
|
| getNewGroupId () |
| Get next group id. More...
|
|
| getNumberOfReservations (array $ids, int $from, int $to, $only_not_over_yet=false) |
| Get number of uncancelled reservations in time frame. More...
|
|
| getListByDate ( $a_has_schedule, array $a_object_ids=null, array $filter=null, array $a_pool_ids=null) |
| List all reservations by date. More...
|
|
| getCachedContextObjBookingInfo ($context_obj_id) |
| Get context object properties info. More...
|
|
Repo class for reservations.
Acts on tables booking_reservation (rw), booking_reservation_group (rw) and booking_object (r)
- Author
- killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de
Definition at line 13 of file class.ilBookingReservationDBRepository.php.
◆ __construct()
ilBookingReservationDBRepository::__construct |
( |
ilDBInterface |
$db, |
|
|
|
$preload_context_obj_ids = null |
|
) |
| |
◆ create()
ilBookingReservationDBRepository::create |
( |
int |
$user_id, |
|
|
int |
$assigner_id, |
|
|
int |
$object_id, |
|
|
|
$context_obj_id, |
|
|
int |
$from, |
|
|
int |
$to, |
|
|
|
$status, |
|
|
|
$group_id |
|
) |
| |
Insert.
- Parameters
-
int | $user_id | |
int | $assigner_id | |
int | $object_id | |
int | $context_obj_id | |
int | $from | |
int | $to | |
int | $status | |
int | $group_id | |
- Returns
- int
Definition at line 68 of file class.ilBookingReservationDBRepository.php.
References $db, and $ilDB.
80 $id =
$ilDB->nextId(
'booking_reservation');
81 $ilDB->manipulate(
'INSERT INTO booking_reservation' .
82 ' (booking_reservation_id,user_id,assigner_id,object_id,context_obj_id,date_from,date_to,status,group_id)' .
83 ' VALUES (' .
$ilDB->quote($id,
'integer') .
84 ',' .
$ilDB->quote($user_id,
'integer') .
85 ',' .
$ilDB->quote($assigner_id,
'integer') .
86 ',' .
$ilDB->quote($object_id,
'integer') .
87 ',' .
$ilDB->quote($context_obj_id,
'integer') .
88 ',' .
$ilDB->quote($from,
'integer') .
89 ',' .
$ilDB->quote($to,
'integer') .
90 ',' .
$ilDB->quote($status,
'integer') .
91 ',' .
$ilDB->quote($group_id,
'integer') .
')');
◆ delete()
ilBookingReservationDBRepository::delete |
( |
int |
$id | ) |
|
◆ getCachedContextObjBookingInfo()
ilBookingReservationDBRepository::getCachedContextObjBookingInfo |
( |
|
$context_obj_id | ) |
|
Get context object properties info.
- Parameters
-
- Returns
- array|null
- Exceptions
-
Definition at line 362 of file class.ilBookingReservationDBRepository.php.
364 if (!is_array($this->preloaded_by_context_list)) {
367 return array_filter($this->preloaded_by_context_list,
function ($row) use ($context_obj_id) {
368 return ($row[
"context_obj_id"] == $context_obj_id);
Booking reservation exception.
◆ getForId()
ilBookingReservationDBRepository::getForId |
( |
int |
$id | ) |
|
◆ getListByDate()
ilBookingReservationDBRepository::getListByDate |
( |
|
$a_has_schedule, |
|
|
array |
$a_object_ids = null , |
|
|
array |
$filter = null , |
|
|
array |
$a_pool_ids = null |
|
) |
| |
List all reservations by date.
- Parameters
-
bool | $a_has_schedule | has schedule |
array | $a_object_ids | object ids |
array | $filter | filter |
array | $a_pool_ids | pool ids |
- Returns
- array
Definition at line 203 of file class.ilBookingReservationDBRepository.php.
References $db, $ilDB, $res, ilObjUser\_lookupName(), and ilBookingReservation\STATUS_CANCELLED.
213 $sql =
'SELECT r.*, o.title, o.pool_id' .
214 ' FROM booking_reservation r' .
215 ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
217 if ($a_pool_ids !== null) {
218 $where = array(
$ilDB->in(
'pool_id', $a_pool_ids,
'',
'integer'));
221 if ($a_object_ids !== null) {
222 $where = array(
$ilDB->in(
'object_id', $a_object_ids,
'',
'integer'));
225 if (is_array($filter[
'context_obj_ids']) && count($filter[
'context_obj_ids']) > 0) {
226 $where = array(
$ilDB->in(
'context_obj_id', $filter[
'context_obj_ids'],
'',
'integer'));
229 if ($filter[
'status']) {
230 if ($filter[
'status'] > 0) {
231 $where[] =
'status = ' .
$ilDB->quote($filter[
'status'],
'integer');
233 $where[] =
'(status != ' .
$ilDB->quote(-$filter[
'status'],
'integer') .
234 ' OR status IS NULL)';
237 if ($filter[
'title']) {
238 $where[] =
'(' .
$ilDB->like(
'title',
'text',
'%' . $filter[
'title'] .
'%') .
239 ' OR ' .
$ilDB->like(
'description',
'text',
'%' . $filter[
'title'] .
'%') .
')';
241 if ($a_has_schedule) {
242 if ($filter[
'from']) {
243 $where[] =
'date_from >= ' .
$ilDB->quote($filter[
'from'],
'integer');
246 $where[] =
'date_to <= ' .
$ilDB->quote($filter[
'to'],
'integer');
248 if (!$filter[
'past']) {
249 $where[] =
'date_to > ' .
$ilDB->quote(time(),
'integer');
252 if ($filter[
'user_id']) {
253 $where[] =
'user_id = ' .
$ilDB->quote($filter[
'user_id'],
'integer');
261 if (
sizeof($where)) {
262 $sql .=
' WHERE ' . implode(
' AND ', $where);
265 if ($a_has_schedule) {
266 $sql .=
' ORDER BY date_from DESC';
269 $sql .=
' ORDER BY status';
272 $set =
$ilDB->query($sql);
273 while ($row =
$ilDB->fetchAssoc($set)) {
274 $obj_id = $row[
"object_id"];
275 $user_id = $row[
"user_id"];
277 if ($a_has_schedule) {
278 $slot = $row[
"date_from"] .
"_" . $row[
"date_to"];
279 $idx = $obj_id .
"_" . $user_id .
"_" . $slot;
281 $idx = $obj_id .
"_" . $user_id;
283 $idx .=
"_" . $row[
"context_obj_id"];
285 if ($a_has_schedule && $filter[
"slot"]) {
286 $slot_idx = date(
"w", $row[
"date_from"]) .
"_" . date(
"H:i", $row[
"date_from"]) .
287 "-" . date(
"H:i", $row[
"date_to"] + 1);
288 if ($filter[
"slot"] != $slot_idx) {
293 if (!isset(
$res[$idx])) {
297 "object_id" => $obj_id
298 ,
"title" => $row[
"title"]
299 ,
"pool_id" => $row[
"pool_id"]
300 ,
"context_obj_id" => (
int) $row[
"context_obj_id"]
301 ,
"user_id" => $user_id
303 ,
"user_name" => $uname[
"lastname"] .
", " . $uname[
"firstname"]
306 if ($a_has_schedule) {
307 $res[$idx][
"booking_reservation_id"] = $idx;
308 $res[$idx][
"date"] = date(
"Y-m-d", $row[
"date_from"]);
309 $res[$idx][
"slot"] = date(
"H:i", $row[
"date_from"]) .
" - " .
310 date(
"H:i", $row[
"date_to"] + 1);
311 $res[$idx][
"week"] = date(
"W", $row[
"date_from"]);
312 $res[$idx][
"weekday"] = date(
"w", $row[
"date_from"]);
314 $row[
"date_from"] > time());
315 $res[$idx][
"_sortdate"] = $row[
"date_from"];
318 $res[$idx][
"status"] = $row[
"status"];
320 $res[$idx][
"booking_reservation_id"] = $row[
"booking_reservation_id"];
321 $res[$idx][
"status"] = $row[
"status"];
325 $res[$idx][
"counter"]++;
static _lookupName($a_user_id)
lookup user name
foreach($_POST as $key=> $value) $res
◆ getNewGroupId()
ilBookingReservationDBRepository::getNewGroupId |
( |
| ) |
|
◆ getNumberOfReservations()
ilBookingReservationDBRepository::getNumberOfReservations |
( |
array |
$ids, |
|
|
int |
$from, |
|
|
int |
$to, |
|
|
|
$only_not_over_yet = false |
|
) |
| |
Get number of uncancelled reservations in time frame.
- Parameters
-
| int[] | $ids |
int | $from | |
int | $to | |
- Returns
- array
Definition at line 168 of file class.ilBookingReservationDBRepository.php.
References $db, $ilDB, $res, and ilBookingReservation\STATUS_CANCELLED.
172 $from =
$ilDB->quote($from,
'integer');
173 $to =
$ilDB->quote($to,
'integer');
175 $date = $only_not_over_yet
176 ?
' AND date_to > ' .
$ilDB->quote(time(),
"integer")
179 $set =
$ilDB->query(
'SELECT count(*) cnt, object_id' .
180 ' FROM booking_reservation' .
181 ' WHERE ' .
$ilDB->in(
'object_id', $ids,
'',
'integer') . $date .
182 ' AND (status IS NULL OR status <> ' .
$ilDB->quote(
186 ' AND date_from <= ' . $to .
' AND date_to >= ' . $from .
187 ' GROUP BY object_id');
189 while ($row =
$ilDB->fetchAssoc($set)) {
190 $res[$row[
"object_id"]] = $row;
foreach($_POST as $key=> $value) $res
◆ preloadByContextIds()
ilBookingReservationDBRepository::preloadByContextIds |
( |
|
$context_obj_ids | ) |
|
|
protected |
Preload reservation information for context obj ids.
- Parameters
-
Definition at line 341 of file class.ilBookingReservationDBRepository.php.
References Vendor\Package\$f, ilUtil\sortArray(), ilUtil\stableSortArray(), and ilBookingReservation\STATUS_CANCELLED.
Referenced by __construct().
343 $filter = [
"context_obj_ids" => ($context_obj_ids)];
344 $filter[
'past'] =
true;
347 $repo =
$f->getRepo();
348 $list = $repo->getListByDate(
true, null, $filter);
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static stableSortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
Factory for reservation repo.
◆ update()
ilBookingReservationDBRepository::update |
( |
int |
$id, |
|
|
int |
$user_id, |
|
|
int |
$assigner_id, |
|
|
int |
$object_id, |
|
|
|
$context_obj_id, |
|
|
int |
$from, |
|
|
int |
$to, |
|
|
|
$status, |
|
|
|
$group_id |
|
) |
| |
Update.
- Parameters
-
int | $id | |
int | $user_id | |
int | $assigner_id | |
int | $object_id | |
int | $context_obj_id | |
int | $from | |
int | $to | |
int | $status | |
int | $group_id | |
- Returns
- int
Definition at line 109 of file class.ilBookingReservationDBRepository.php.
References $db, and $ilDB.
121 return $ilDB->manipulate(
'UPDATE booking_reservation' .
122 ' SET object_id = ' .
$ilDB->quote($object_id,
'text') .
123 ', user_id = ' .
$ilDB->quote($user_id,
'integer') .
124 ', assigner_id = ' .
$ilDB->quote($assigner_id,
'integer') .
125 ', date_from = ' .
$ilDB->quote($from,
'integer') .
126 ', date_to = ' .
$ilDB->quote($to,
'integer') .
127 ', status = ' .
$ilDB->quote($status,
'integer') .
128 ', group_id = ' .
$ilDB->quote($group_id,
'integer') .
129 ', context_obj_id = ' .
$ilDB->quote($context_obj_id,
'integer') .
130 ' WHERE booking_reservation_id = ' .
$ilDB->quote($id,
'integer'));
◆ $db
ilBookingReservationDBRepository::$db |
|
protected |
◆ $preloaded_by_context_list
ilBookingReservationDBRepository::$preloaded_by_context_list = null |
|
protected |
The documentation for this class was generated from the following file: