ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 protected \ILIAS\BookingManager\InternalDomainService $domain;
30
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 protected bool $messages = false;
40
41
42 public function __construct(
43 int $a_id = 0,
44 bool $a_call_by_reference = true
45 ) {
46 global $DIC;
47
48 $this->db = $DIC->database();
49 $this->type = "book";
50 $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
51 parent::__construct($a_id, $a_call_by_reference);
52 $this->domain = $DIC->bookingManager()->internal()->domain();
53 }
54
58 protected function getDBFields(): array
59 {
60 return array(
61 "schedule_type" => array("integer", $this->getScheduleType()),
62 "public_log" => array("integer", $this->hasPublicLog()),
63 "ovlimit" => array("integer", $this->getOverallLimit()),
64 "reminder_status" => array("integer", $this->getReminderStatus()),
65 "reminder_day" => array("integer", $this->getReminderDay()),
66 "rsv_filter_period" => array("integer", $this->getReservationFilterPeriod()),
67 "preference_nr" => array("integer", $this->getPreferenceNumber()),
68 "pref_deadline" => array("integer", $this->getPreferenceDeadline()),
69 "messages" => array("integer", $this->usesMessages())
70 );
71 }
72
73 public function create(): int
74 {
76
77 $new_id = parent::create();
78
79 $fields = $this->getDBFields();
80 $fields["booking_pool_id"] = array("integer", $new_id);
81
82 $ilDB->insert("booking_settings", $fields);
83
84 return $new_id;
85 }
86
87 public function update(): bool
88 {
90
91 if (!parent::update()) {
92 return false;
93 }
94
95 // put here object specific stuff
96 if ($this->getId()) {
97 $ilDB->update(
98 "booking_settings",
99 $this->getDBFields(),
100 array("booking_pool_id" => array("integer", $this->getId()))
101 );
102 }
103
104 return true;
105 }
106
107 public function read(): void
108 {
110
111 parent::read();
112
113 // put here object specific stuff
114 if ($this->getId()) {
115 $set = $ilDB->query('SELECT * FROM booking_settings' .
116 ' WHERE booking_pool_id = ' . $ilDB->quote($this->getId(), 'integer'));
117 $row = $ilDB->fetchAssoc($set);
118 $this->setPublicLog($row['public_log']);
119 $this->setScheduleType($row['schedule_type']);
120 $this->setOverallLimit($row['ovlimit']);
121 $this->setReminderStatus($row['reminder_status']);
122 $this->setReminderDay($row['reminder_day']);
123 $this->setReservationFilterPeriod($row['rsv_filter_period']);
124 $this->setPreferenceNumber($row['preference_nr']);
125 $this->setPreferenceDeadline($row['pref_deadline']);
126 $this->setMessages((bool) ((int) ($row['messages'] ?? 0)));
127 }
128 }
129
133 public static function getPoolsWithReminders(): array
134 {
135 global $DIC;
136
137 $db = $DIC->database();
138 $pools = [];
139 $set = $db->queryF(
140 "SELECT * FROM booking_settings " .
141 " WHERE reminder_status = %s " .
142 " AND reminder_day > %s ",
143 array("integer","integer","integer"),
144 array(1,0,0)
145 );
146 while ($rec = $db->fetchAssoc($set)) {
147 if (!ilObject::lookupOfflineStatus($rec["booking_pool_id"])) {
148 $pools[] = $rec;
149 }
150 }
151 return $pools;
152 }
153
158 public static function writeLastReminderTimestamp(
159 int $a_obj_id,
160 int $a_ts
161 ): void {
162 global $DIC;
163 $db = $DIC->database();
164 $db->update("booking_settings", array(
165 "last_remind_ts" => array("integer", $a_ts)
166 ), array( // where
167 "booking_pool_id" => array("integer", $a_obj_id)
168 ));
169 }
170
171 public function delete(): bool
172 {
173 $ilDB = $this->db;
174
175 $id = $this->getId();
176
177 if ($this->referenced) {
178 $use_repo = new ilObjUseBookDBRepository($ilDB);
179 $use_repo->deleteEntriesOfBookRefId($this->getRefId());
180 }
181
182 // always call parent delete function first!!
183 if (!parent::delete()) {
184 return false;
185 }
186
187 // put here your module specific stuff
188
189 $ilDB->manipulate('DELETE FROM booking_settings' .
190 ' WHERE booking_pool_id = ' . $ilDB->quote($id, 'integer'));
191
192 $ilDB->manipulate('DELETE FROM booking_schedule' .
193 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
194
195 $objects = array();
196 $set = $ilDB->query('SELECT booking_object_id FROM booking_object' .
197 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
198 while ($row = $ilDB->fetchAssoc($set)) {
199 $objects[] = $row['booking_object_id'];
200 }
201
202 if (count($objects)) {
203 $ilDB->manipulate('DELETE FROM booking_reservation' .
204 ' WHERE ' . $ilDB->in('object_id', $objects, '', 'integer'));
205 }
206
207 $ilDB->manipulate('DELETE FROM booking_object' .
208 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
209
210 return true;
211 }
212
213 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
214 {
215 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
216
217 $schedule_manager = $this->domain->schedules($this->getId());
218
219 if ($new_obj !== null) {
220 //copy online status if object is not the root copy object
221 $cp_options = ilCopyWizardOptions::_getInstance($copy_id);
222
223 /*
224 if (!$cp_options->isRootNode($this->getRefId())) {
225 $new_obj->setOffline($this->isOffline());
226 }*/
227
228 $new_obj->setScheduleType($this->getScheduleType());
229 $new_obj->setPublicLog($this->hasPublicLog());
230 $new_obj->setOverallLimit($this->getOverallLimit());
231 $new_obj->setReminderStatus($this->getReminderStatus());
232 $new_obj->setReminderDay($this->getReminderDay());
233 $new_obj->setPreferenceNumber($this->getPreferenceNumber());
234 $new_obj->setPreferenceDeadline($this->getPreferenceDeadline());
235 $new_obj->setMessages($this->usesMessages());
236
237 $smap = null;
238 if ($this->getScheduleType() === self::TYPE_FIX_SCHEDULE) {
239 // schedules
240 foreach ($schedule_manager->getScheduleList() as $schedule_id => $title) {
241 $schedule = new ilBookingSchedule($schedule_id);
242 $smap[$schedule_id] = $schedule->doClone($new_obj->getId());
243 }
244 }
245
246 // objects
247 foreach (ilBookingObject::getList($this->getId()) as $item) {
248 $bobj = new ilBookingObject($item["booking_object_id"]);
249 $bobj->doClone($new_obj->getId(), $smap);
250 }
251
252 $new_obj->update();
253
254 return $new_obj;
255 }
256 return null;
257 }
258
259 public function setMessages(
260 bool $a_value = true
261 ): void {
262 $this->messages = $a_value;
263 }
264
265 public function usesMessages(): bool
266 {
267 return $this->messages;
268 }
269
273 public function setPublicLog(
274 bool $a_value = true
275 ): void {
276 $this->public_log = $a_value;
277 }
278
279 public function hasPublicLog(): bool
280 {
281 return $this->public_log;
282 }
283
284 public function setScheduleType(int $a_value): void
285 {
286 $this->schedule_type = $a_value;
287 }
288
289 public function getScheduleType(): int
290 {
291 return $this->schedule_type;
292 }
293
294 public function setReminderStatus(int $a_val): void
295 {
296 $this->reminder_status = $a_val;
297 }
298
299 public function getReminderStatus(): int
300 {
301 return $this->reminder_status;
302 }
303
304 public function setReminderDay(int $a_val): void
305 {
306 $this->reminder_day = $a_val;
307 }
308
309 public function getReminderDay(): int
310 {
311 return $this->reminder_day;
312 }
313
314 public function setPreferenceNumber(int $a_val): void
315 {
316 $this->preference_nr = $a_val;
317 }
318
319 public function getPreferenceNumber(): int
320 {
321 return $this->preference_nr;
322 }
323
327 public function setPreferenceDeadline(int $a_val): void
328 {
329 $this->pref_deadline = $a_val;
330 }
331
335 public function getPreferenceDeadline(): int
336 {
337 return $this->pref_deadline;
338 }
339
340
344 public function setOverallLimit(?int $a_value = null): void
345 {
346 $this->overall_limit = $a_value;
347 }
348
349 public function getOverallLimit(): ?int
350 {
351 return $this->overall_limit;
352 }
353
358 ?int $a_value = null
359 ): void {
360 $this->reservation_period = $a_value;
361 }
362
363 public function getReservationFilterPeriod(): ?int
364 {
365 return $this->reservation_period;
366 }
367
368
369 //
370 // advanced metadata
371 //
372
373 public static function getAdvancedMDFields(
374 int $a_ref_id
375 ): array {
376 $fields = array();
377
378 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("book", $a_ref_id, "bobj");
379
380 foreach ($recs as $record_obj) {
381 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
382 $field_id = $def->getFieldId();
383 $fields[$field_id] = array(
384 "id" => $field_id,
385 "title" => $def->getTitle(),
386 "type" => $def->getType()
387 );
388 }
389 }
390
391 return $fields;
392 }
393}
$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 _getInstance(int $a_copy_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS BookingManager InternalDomainService $domain
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)
getDBFields()
Parse properties for sql statements.
create()
note: title, description and type should be set when this function is called
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
setReservationFilterPeriod(?int $a_value=null)
Set reservation filter period default.
setMessages(bool $a_value=true)
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...
Class ilObject Basic functions for all objects.
ilDBInterface $db
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.
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
global $DIC
Definition: shib_login.php:26
$messages
Definition: xapiexit.php:21