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