ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ObjectsDBRepository.php
Go to the documentation of this file.
1<?php
2
20
23
29{
30 protected const NR_OF_COLORS = 9;
31 protected static $color_number = [];
32 protected static $pool_objects = [];
33 protected static array $raw_data = [];
34 protected static array $pool_loaded = [];
35
36 public function __construct(
37 protected IRSSWrapper $wrapper,
38 protected \ilDBInterface $db
39 ) {
40 }
41
42 public function loadDataOfPool(int $pool_id): void
43 {
44 $db = $this->db;
45
46 if (isset(self::$pool_loaded[$pool_id]) && self::$pool_loaded[$pool_id]) {
47 return;
48 }
49
50 $set = $db->queryF(
51 "SELECT * FROM booking_object " .
52 " WHERE pool_id = %s ORDER BY title ASC, booking_object_id ASC",
53 ["integer"],
54 [$pool_id]
55 );
56 self::$pool_objects[$pool_id] = [];
57 $cnt = 0;
58 while ($rec = $db->fetchAssoc($set)) {
59 self::$raw_data[$rec["booking_object_id"]] = $rec;
60 self::$color_number[$rec["booking_object_id"]] = ($cnt % self::NR_OF_COLORS) + 1;
61 self::$pool_objects[$pool_id][] = $rec;
62 $cnt++;
63 }
64 self::$pool_loaded[$pool_id] = true;
65 }
66
67 public function getNrOfItemsForObject(int $book_obj_id): int
68 {
69 if (!isset(self::$raw_data[$book_obj_id])) {
70 throw new \ilBookingPoolException("Data for booking object $book_obj_id not loaded.");
71 }
72 return (int) self::$raw_data[$book_obj_id]["nr_of_items"];
73 }
74
75 public function getColorNrForObject(int $book_obj_id): int
76 {
77 if (!isset(self::$raw_data[$book_obj_id])) {
78 throw new \ilBookingPoolException("Data for booking object $book_obj_id not loaded.");
79 }
80 return (int) self::$color_number[$book_obj_id];
81 }
82
83 public function getObjectDataForPool(
84 int $pool_id
85 ): array {
86 $this->loadDataOfPool($pool_id);
87 return self::$pool_objects[$pool_id] ?? [];
88 }
89
90 //
91 // Object and booking irss resrouces
92 //
93
94 protected function getObjectInfoRidForBookingObjectId(int $booking_object_id): string
95 {
96 $set = $this->db->queryF(
97 "SELECT obj_info_rid FROM booking_object " .
98 " WHERE booking_object_id = %s ",
99 ["integer"],
100 [$booking_object_id]
101 );
102 $rec = $this->db->fetchAssoc($set);
103 return ($rec["obj_info_rid"] ?? "");
104 }
105
106 public function hasObjectInfo(int $booking_object_id): bool
107 {
108 $rid = $this->getObjectInfoRidForBookingObjectId($booking_object_id);
109 return ($rid !== "");
110 }
111
112 public function deleteObjectInfo(int $booking_object_id, ResourceStakeholder $stakeholder): void
113 {
114 $rid = $this->getObjectInfoRidForBookingObjectId($booking_object_id);
115 if ($rid !== "") {
116 $this->wrapper->deleteResource($rid, $stakeholder);
117 }
118 }
119
120 public function getObjectInfoPath(int $booking_object_id): string
121 {
122 $rid = $this->getObjectInfoRidForBookingObjectId($booking_object_id);
123 return $this->wrapper->getResourcePath($rid);
124 }
125
126 public function deliverObjectInfo(int $booking_object_id): void
127 {
128 $rid = $this->getObjectInfoRidForBookingObjectId($booking_object_id);
129 $this->wrapper->deliverFile($rid);
130 }
131
132 public function getObjectInfoFilename(int $booking_object_id): string
133 {
134 $rid = $this->getObjectInfoRidForBookingObjectId($booking_object_id);
135 if ($rid !== "") {
136 $info = $this->wrapper->getResourceInfo($rid);
137 return $info->getTitle();
138 }
139 return "";
140 }
141
142
144 int $booking_object_id,
145 array $file_input,
146 ResourceStakeholder $stakeholder
147 ): string {
148 $rcid = $this->wrapper->importFileFromLegacyUpload(
149 $file_input,
150 $stakeholder
151 );
152 if ($rcid !== "") {
153 $this->db->update(
154 "booking_object",
155 [
156 "obj_info_rid" => ["text", $rcid]
157 ],
158 [ // where
159 "booking_object_id" => ["integer", $booking_object_id]
160 ]
161 );
162 }
163 return $rcid;
164 }
165
166 protected function getBookingInfoRidForBookingObjectId(int $booking_object_id): string
167 {
168 $set = $this->db->queryF(
169 "SELECT book_info_rid FROM booking_object " .
170 " WHERE booking_object_id = %s ",
171 ["integer"],
172 [$booking_object_id]
173 );
174 $rec = $this->db->fetchAssoc($set);
175 return ($rec["book_info_rid"] ?? "");
176 }
177
178 public function hasBookingInfo(int $booking_object_id): bool
179 {
180 $rid = $this->getBookingInfoRidForBookingObjectId($booking_object_id);
181 return ($rid !== "");
182 }
183
184 public function deleteBookingInfo(int $booking_object_id, ResourceStakeholder $stakeholder): void
185 {
186 $rid = $this->getBookingInfoRidForBookingObjectId($booking_object_id);
187 if ($rid !== "") {
188 $this->wrapper->deleteResource($rid, $stakeholder);
189 }
190 }
191
192 public function deliverBookingInfo(int $booking_object_id): void
193 {
194 $rid = $this->getBookingInfoRidForBookingObjectId($booking_object_id);
195 $this->wrapper->deliverFile($rid);
196 }
197
198 public function getBookingInfoPath(int $booking_object_id): string
199 {
200 $rid = $this->getBookingInfoRidForBookingObjectId($booking_object_id);
201 return $this->wrapper->getResourcePath($rid);
202 }
203
204 public function getBookingInfoFilename(int $booking_object_id): string
205 {
206 $rid = $this->getBookingInfoRidForBookingObjectId($booking_object_id);
207 if ($rid !== "") {
208 $info = $this->wrapper->getResourceInfo($rid);
209 return $info->getTitle();
210 }
211 return "";
212 }
213
214
216 int $booking_object_id,
217 array $file_input,
218 ResourceStakeholder $stakeholder
219 ): string {
220 $rcid = $this->wrapper->importFileFromLegacyUpload(
221 $file_input,
222 $stakeholder
223 );
224 if ($rcid !== "") {
225 $this->db->update(
226 "booking_object",
227 [
228 "book_info_rid" => ["text", $rcid]
229 ],
230 [ // where
231 "booking_object_id" => ["integer", $booking_object_id]
232 ]
233 );
234 }
235 return $rcid;
236 }
237
238 public function clone(
239 int $from_id,
240 int $to_id
241 ): void {
242 $from_rid = $this->getObjectInfoRidForBookingObjectId($from_id);
243 $to_rid = $this->wrapper->cloneResource($from_rid);
244 if ($to_rid !== "") {
245 $this->db->update(
246 "booking_object",
247 [
248 "obj_info_rid" => ["text", $to_rid]
249 ],
250 [ // where
251 "booking_object_id" => ["integer", $to_id]
252 ]
253 );
254 }
255 $from_rid = $this->getBookingInfoRidForBookingObjectId($from_id);
256 $to_rid = $this->wrapper->cloneResource($from_rid);
257 if ($to_rid !== "") {
258 $this->db->update(
259 "booking_object",
260 [
261 "book_info_rid" => ["text", $to_rid]
262 ],
263 [ // where
264 "booking_object_id" => ["integer", $to_id]
265 ]
266 );
267 }
268 }
269}
__construct(protected IRSSWrapper $wrapper, protected \ilDBInterface $db)
importBookingInfoFromLegacyUpload(int $booking_object_id, array $file_input, ResourceStakeholder $stakeholder)
deleteObjectInfo(int $booking_object_id, ResourceStakeholder $stakeholder)
importObjectInfoFromLegacyUpload(int $booking_object_id, array $file_input, ResourceStakeholder $stakeholder)
deleteBookingInfo(int $booking_object_id, ResourceStakeholder $stakeholder)
$info
Definition: entry_point.php:21
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...