ILIAS  release_7 Revision v7.30-3-g800a261c036
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
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
121 public function storeBookings(int $pool_id, $bookings)
122 {
123 if ($this->checkProcessHash($pool_id)) {
124 foreach ($bookings as $user_id => $obj_ids) {
125 foreach ($obj_ids as $obj_id) {
127 !ilBookingReservation::getObjectReservationForUser($obj_id, $user_id)) { // #18304
128 $reservation = new ilBookingReservation();
129 $reservation->setObjectId($obj_id);
130 $reservation->setUserId($user_id);
131 $reservation->setAssignerId($user_id);
132 $reservation->setFrom(null);
133 $reservation->setTo(null);
134 $reservation->save();
135 }
136 }
137 }
138 }
139 }
140
147 public function getBookings(array $obj_ids)
148 {
149 $bookings = [];
151 $obj_ids,
152 10000,
153 0,
155 )["data"] as $book) {
156 $bookings[$book["user_id"]][] = $book["object_id"];
157 }
158 return $bookings;
159 }
160}
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.
global $DIC
Definition: goto.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...