ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBookingPrefBaseBookGatewayRepository.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $db;
16
20 public function __construct(ilDBInterface $db = null)
21 {
22 global $DIC;
23
24 $this->db = ($db)
25 ? $db
26 : $DIC->database();
27 }
28
35 {
36 $db = $this->db;
37
38 $pool_ids = [];
39 $set = $db->queryF(
40 "SELECT booking_pool_id FROM booking_settings " .
41 " WHERE schedule_type = %s " .
42 " AND pref_deadline < %s " .
43 " AND pref_booking_hash = %s ",
44 array("integer", "integer", "text"),
46 );
47 while ($rec = $db->fetchAssoc($set)) {
48 $pool_ids[] = $rec["booking_pool_id"];
49 }
50 return $pool_ids;
51 }
52
53
60 protected function checkProcessHash($pool_id)
61 {
62 $db = $this->db;
63
64 $hash = uniqid("", true);
65
66 $db->update("booking_settings", array(
67 "pref_booking_hash" => array("text", $hash)
68 ), array( // where
69 "booking_pool_id" => array("integer", $pool_id),
70 "pref_booking_hash" => array("text", "0"),
71 ));
72
73 $set = $db->queryF(
74 "SELECT pref_booking_hash FROM booking_settings " .
75 " WHERE booking_pool_id = %s ",
76 array("integer"),
77 array($pool_id)
78 );
79 $rec = $db->fetchAssoc($set);
80
81 if ($rec["pref_booking_hash"] == $hash) {
82 return true;
83 }
84 return false;
85 }
86
94 public function storeBookings(int $pool_id, $bookings)
95 {
96 if ($this->checkProcessHash($pool_id)) {
97 foreach ($bookings as $user_id => $obj_ids) {
98 foreach ($obj_ids as $obj_id) {
100 !ilBookingReservation::getObjectReservationForUser($obj_id, $user_id)) { // #18304
101 $reservation = new ilBookingReservation();
102 $reservation->setObjectId($obj_id);
103 $reservation->setUserId($user_id);
104 $reservation->setAssignerId($user_id);
105 $reservation->setFrom(null);
106 $reservation->setTo(null);
107 $reservation->save();
108 }
109 }
110 }
111 }
112 }
113
120 public function getBookings(array $obj_ids)
121 {
122 $bookings = [];
124 $obj_ids,
125 10000,
126 0,
128 )["data"] as $book) {
129 $bookings[$book["user_id"]][] = $book["object_id"];
130 }
131 return $bookings;
132 }
133}
An exception for terminatinating execution or to throw for unit testing.
Manages the booking storage of the preference based calculated bookings.
storeBookings(int $pool_id, $bookings)
Store bookings see similar code in ilObjBookingPoolGUI::confirmedBookingObject this should got to a r...
checkProcessHash($pool_id)
Semaphore like hash setting/checking to ensure that no other process is doing the same.
getPoolsWithOverdueBooking()
Get pools with overdue preference booking.
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
static isObjectAvailableNoSchedule($a_obj_id)
static getList($a_object_ids, $a_limit=10, $a_offset=0, array $filter=[])
List all reservations.
Interface ilDBInterface.
$DIC
Definition: xapitoken.php:46