ILIAS  release_8 Revision v8.24
class.ilObjBookingPool.php
Go to the documentation of this file.
1<?php
2
25{
26 public const TYPE_FIX_SCHEDULE = 1;
27 public const TYPE_NO_SCHEDULE = 2;
29
30 protected bool $offline = true;
31 protected bool $public_log = false;
32 protected int $schedule_type = 0;
33 protected ?int $overall_limit = null;
34 protected ?int $reservation_period = null;
35 protected int $reminder_status = 0;
36 protected int $reminder_day = 1;
37 protected int $pref_deadline = 0;
38 protected int $preference_nr = 0;
39
40
41 public function __construct(
42 int $a_id = 0,
43 bool $a_call_by_reference = true
44 ) {
45 global $DIC;
46
47 $this->db = $DIC->database();
48 $this->type = "book";
49 $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
50 parent::__construct($a_id, $a_call_by_reference);
51 }
52
56 protected function getDBFields(): array
57 {
58 return array(
59 "schedule_type" => array("integer", $this->getScheduleType()),
60 "pool_offline" => array("integer", $this->isOffline()),
61 "public_log" => array("integer", $this->hasPublicLog()),
62 "ovlimit" => array("integer", $this->getOverallLimit()),
63 "reminder_status" => array("integer", $this->getReminderStatus()),
64 "reminder_day" => array("integer", $this->getReminderDay()),
65 "rsv_filter_period" => array("integer", $this->getReservationFilterPeriod()),
66 "preference_nr" => array("integer", $this->getPreferenceNumber()),
67 "pref_deadline" => array("integer", $this->getPreferenceDeadline())
68 );
69 }
70
71 public function create(): int
72 {
74
75 $new_id = parent::create();
76
77 $fields = $this->getDBFields();
78 $fields["booking_pool_id"] = array("integer", $new_id);
79
80 $ilDB->insert("booking_settings", $fields);
81
82 return $new_id;
83 }
84
85 public function update(): bool
86 {
88
89 if (!parent::update()) {
90 return false;
91 }
92
93 // put here object specific stuff
94 if ($this->getId()) {
95 $ilDB->update(
96 "booking_settings",
97 $this->getDBFields(),
98 array("booking_pool_id" => array("integer", $this->getId()))
99 );
100 }
101
102 return true;
103 }
104
105 public function read(): void
106 {
108
109 parent::read();
110
111 // put here object specific stuff
112 if ($this->getId()) {
113 $set = $ilDB->query('SELECT * FROM booking_settings' .
114 ' WHERE booking_pool_id = ' . $ilDB->quote($this->getId(), 'integer'));
115 $row = $ilDB->fetchAssoc($set);
116 $this->setOffline($row['pool_offline']);
117 $this->setPublicLog($row['public_log']);
118 $this->setScheduleType($row['schedule_type']);
119 $this->setOverallLimit($row['ovlimit']);
120 $this->setReminderStatus($row['reminder_status']);
121 $this->setReminderDay($row['reminder_day']);
122 $this->setReservationFilterPeriod($row['rsv_filter_period']);
123 $this->setPreferenceNumber($row['preference_nr']);
124 $this->setPreferenceDeadline($row['pref_deadline']);
125 }
126 }
127
131 public static function getPoolsWithReminders(): array
132 {
133 global $DIC;
134
135 $db = $DIC->database();
136 $pools = [];
137 $set = $db->queryF(
138 "SELECT * FROM booking_settings " .
139 " WHERE reminder_status = %s " .
140 " AND reminder_day > %s " .
141 " AND pool_offline = %s ",
142 array("integer","integer","integer"),
143 array(1,0,0)
144 );
145 while ($rec = $db->fetchAssoc($set)) {
146 $pools[] = $rec;
147 }
148 return $pools;
149 }
150
155 public static function writeLastReminderTimestamp(
156 int $a_obj_id,
157 int $a_ts
158 ): void {
159 global $DIC;
160 $db = $DIC->database();
161 $db->update("booking_settings", array(
162 "last_remind_ts" => array("integer", $a_ts)
163 ), array( // where
164 "booking_pool_id" => array("integer", $a_obj_id)
165 ));
166 }
167
168 public function delete(): bool
169 {
170 $ilDB = $this->db;
171
172 $id = $this->getId();
173
174 if ($this->referenced) {
175 $use_repo = new ilObjUseBookDBRepository($ilDB);
176 $use_repo->deleteEntriesOfBookRefId($this->getRefId());
177 }
178
179 // always call parent delete function first!!
180 if (!parent::delete()) {
181 return false;
182 }
183
184 // put here your module specific stuff
185
186 $ilDB->manipulate('DELETE FROM booking_settings' .
187 ' WHERE booking_pool_id = ' . $ilDB->quote($id, 'integer'));
188
189 $ilDB->manipulate('DELETE FROM booking_schedule' .
190 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
191
192 $objects = array();
193 $set = $ilDB->query('SELECT booking_object_id FROM booking_object' .
194 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
195 while ($row = $ilDB->fetchAssoc($set)) {
196 $objects[] = $row['booking_object_id'];
197 }
198
199 if (count($objects)) {
200 $ilDB->manipulate('DELETE FROM booking_reservation' .
201 ' WHERE ' . $ilDB->in('object_id', $objects, '', 'integer'));
202 }
203
204 $ilDB->manipulate('DELETE FROM booking_object' .
205 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
206
207 return true;
208 }
209
210 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
211 {
212 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
213
214 if ($new_obj !== null) {
215 //copy online status if object is not the root copy object
216 $cp_options = ilCopyWizardOptions::_getInstance($copy_id);
217
218 if (!$cp_options->isRootNode($this->getRefId())) {
219 $new_obj->setOffline($this->isOffline());
220 }
221
222 $new_obj->setScheduleType($this->getScheduleType());
223 $new_obj->setPublicLog($this->hasPublicLog());
224 $new_obj->setOverallLimit($this->getOverallLimit());
225 $new_obj->setReminderStatus($this->getReminderStatus());
226 $new_obj->setReminderDay($this->getReminderDay());
227 $new_obj->setPreferenceNumber($this->getPreferenceNumber());
228 $new_obj->setPreferenceDeadline($this->getPreferenceDeadline());
229
230 $smap = null;
231 if ($this->getScheduleType() === self::TYPE_FIX_SCHEDULE) {
232 // schedules
233 foreach (ilBookingSchedule::getList($this->getId()) as $item) {
234 $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
235 $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
236 }
237 }
238
239 // objects
240 foreach (ilBookingObject::getList($this->getId()) as $item) {
241 $bobj = new ilBookingObject($item["booking_object_id"]);
242 $bobj->doClone($new_obj->getId(), $smap);
243 }
244
245 $new_obj->update();
246
247 return $new_obj;
248 }
249 return null;
250 }
251
252 public function setOffline(
253 bool $a_value = true
254 ): void {
255 $this->offline = $a_value;
256 }
257
258 public function isOffline(): bool
259 {
260 return $this->offline;
261 }
262
266 public function setPublicLog(
267 bool $a_value = true
268 ): void {
269 $this->public_log = $a_value;
270 }
271
272 public function hasPublicLog(): bool
273 {
274 return $this->public_log;
275 }
276
277 public function setScheduleType(int $a_value): void
278 {
279 $this->schedule_type = $a_value;
280 }
281
282 public function getScheduleType(): int
283 {
284 return $this->schedule_type;
285 }
286
287 public function setReminderStatus(int $a_val): void
288 {
289 $this->reminder_status = $a_val;
290 }
291
292 public function getReminderStatus(): int
293 {
294 return $this->reminder_status;
295 }
296
297 public function setReminderDay(int $a_val): void
298 {
299 $this->reminder_day = $a_val;
300 }
301
302 public function getReminderDay(): int
303 {
304 return $this->reminder_day;
305 }
306
307 public function setPreferenceNumber(int $a_val): void
308 {
309 $this->preference_nr = $a_val;
310 }
311
312 public function getPreferenceNumber(): int
313 {
314 return $this->preference_nr;
315 }
316
320 public function setPreferenceDeadline(int $a_val): void
321 {
322 $this->pref_deadline = $a_val;
323 }
324
328 public function getPreferenceDeadline(): int
329 {
330 return $this->pref_deadline;
331 }
332
333 public static function _lookupOnline(int $a_obj_id): bool
334 {
335 global $DIC;
336
337 $ilDB = $DIC->database();
338
339 $set = $ilDB->query("SELECT pool_offline" .
340 " FROM booking_settings" .
341 " WHERE booking_pool_id = " . $ilDB->quote($a_obj_id, "integer"));
342 $row = $ilDB->fetchAssoc($set);
343 return !$row["pool_offline"];
344 }
345
349 public function setOverallLimit(?int $a_value = null): void
350 {
351 $this->overall_limit = $a_value;
352 }
353
354 public function getOverallLimit(): ?int
355 {
356 return $this->overall_limit;
357 }
358
363 ?int $a_value = null
364 ): void {
365 $this->reservation_period = $a_value;
366 }
367
368 public function getReservationFilterPeriod(): ?int
369 {
370 return $this->reservation_period;
371 }
372
373
374 //
375 // advanced metadata
376 //
377
378 public static function getAdvancedMDFields(
379 int $a_ref_id
380 ): array {
381 $fields = array();
382
383 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("book", $a_ref_id, "bobj");
384
385 foreach ($recs as $record_obj) {
386 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
387 $field_id = $def->getFieldId();
388 $fields[$field_id] = array(
389 "id" => $field_id,
390 "title" => $def->getTitle(),
391 "type" => $def->getType()
392 );
393 }
394 }
395
396 return $fields;
397 }
398}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getList(int $a_pool_id, string $a_title=null)
Get list of booking objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getList(int $a_pool_id)
Get list of booking objects for given pool.
static _getInstance(int $a_copy_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static writeLastReminderTimestamp(int $a_obj_id, int $a_ts)
__construct(int $a_id=0, bool $a_call_by_reference=true)
static getAdvancedMDFields(int $a_ref_id)
setOffline(bool $a_value=true)
getDBFields()
Parse properties for sql statements.
create()
note: title, description and type should be set when this function is called
static _lookupOnline(int $a_obj_id)
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
setReservationFilterPeriod(?int $a_value=null)
Set reservation filter period default.
setOverallLimit(?int $a_value=null)
Set overall / global booking limit.
setPublicLog(bool $a_value=true)
Toggle public log property.
static getPoolsWithReminders()
Get pools with reminders.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilDBInterface $db
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
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)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc