ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingPrefBasedBookGatewayRepository.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilDBInterface $db;
26
27 public function __construct(?ilDBInterface $db = null)
28 {
29 global $DIC;
30
31 $this->db = ($db)
32 ?: $DIC->database();
33 }
34
39 public function getPoolsWithOverdueBooking(): array
40 {
41 $db = $this->db;
42
43 $pool_ids = [];
44 $set = $db->queryF(
45 "SELECT booking_pool_id FROM booking_settings " .
46 " WHERE schedule_type = %s " .
47 " AND pref_deadline < %s " .
48 " AND pref_booking_hash = %s ",
49 array("integer", "integer", "text"),
51 );
52 while ($rec = $db->fetchAssoc($set)) {
53 $pool_ids[] = $rec["booking_pool_id"];
54 }
55 return $pool_ids;
56 }
57
58
63 protected function checkProcessHash(int $pool_id): bool
64 {
65 $db = $this->db;
66
67 $hash = uniqid("", true);
68
69 $db->update("booking_settings", array(
70 "pref_booking_hash" => array("text", $hash)
71 ), array( // where
72 "booking_pool_id" => array("integer", $pool_id),
73 "pref_booking_hash" => array("text", "0"),
74 ));
75
76 $set = $db->queryF(
77 "SELECT pref_booking_hash FROM booking_settings " .
78 " WHERE booking_pool_id = %s ",
79 array("integer"),
80 array($pool_id)
81 );
82 $rec = $db->fetchAssoc($set);
83
84 return $rec["pref_booking_hash"] === $hash;
85 }
86
87 public function hasRun($pool_id): bool
88 {
89 $db = $this->db;
90 $set = $db->queryF(
91 "SELECT pref_booking_hash FROM booking_settings " .
92 " WHERE booking_pool_id = %s ",
93 array("integer"),
94 array($pool_id)
95 );
96 $rec = $db->fetchAssoc($set);
97
98 if ($rec["pref_booking_hash"] !== "0") {
99 return true;
100 }
101 return false;
102 }
103
104 public function resetRun($pool_id): void
105 {
106 $db = $this->db;
107 $db->update("booking_settings", array(
108 "pref_booking_hash" => array("text", "0")
109 ), array( // where
110 "booking_pool_id" => array("integer", $pool_id)
111 ));
112 }
113
120 public function storeBookings(
121 int $pool_id,
122 array $bookings
123 ): void {
124 if ($this->checkProcessHash($pool_id)) {
125 foreach ($bookings as $user_id => $obj_ids) {
126 foreach ($obj_ids as $obj_id) {
128 count(ilBookingReservation::getObjectReservationForUser($obj_id, $user_id)) === 0) { // #18304
129 $reservation = new ilBookingReservation();
130 $reservation->setObjectId($obj_id);
131 $reservation->setUserId($user_id);
132 $reservation->setAssignerId($user_id);
133 $reservation->setFrom(0);
134 $reservation->setTo(0);
135 $reservation->save();
136 }
137 }
138 }
139 }
140 }
141
142 public function getBookings(
143 array $obj_ids
144 ): array {
145 $bookings = [];
147 $obj_ids,
148 10000,
149 0,
151 )["data"] as $book) {
152 $bookings[$book["user_id"]][] = $book["object_id"];
153 }
154 return $bookings;
155 }
156}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
storeBookings(int $pool_id, array $bookings)
Store bookings see similar code in ilObjBookingPoolGUI::confirmedBookingObject this should got to a r...
checkProcessHash(int $pool_id)
Semaphore like hash setting/checking to ensure that no other process is doing the same.
getPoolsWithOverdueBooking()
Get pools with overdue preference booking.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
static isObjectAvailableNoSchedule(int $a_obj_id)
static getList(array $a_object_ids, int $a_limit=10, int $a_offset=0, array $filter=[])
List all reservations.
Interface ilDBInterface.
update(string $table_name, array $values, array $where)
@description $where MUST contain existing columns only.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26