ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjBookingPool.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13 //offline default should be true
14 protected $offline = true; // [bool]
15 protected $public_log; // [bool]
16 protected $schedule_type; // [int]
17 protected $overall_limit; // [int]
18 protected $reservation_period; // [int]
19 protected $reminder_status = 0; // [int]
20 protected $reminder_day = 1; // [int]
21
25 protected $pref_deadline;
26
30 protected $preference_nr;
31
35
41 public function __construct($a_id = 0, $a_call_by_reference = true)
42 {
43 global $DIC;
44
45 $this->db = $DIC->database();
46 $this->type = "book";
47 $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
48 parent::__construct($a_id, $a_call_by_reference);
49 }
50
54 protected function getDBFields()
55 {
56 $fields = array(
57 "schedule_type" => array("integer", $this->getScheduleType()),
58 "pool_offline" => array("integer", $this->isOffline()),
59 "public_log" => array("integer", $this->hasPublicLog()),
60 "ovlimit" => array("integer", $this->getOverallLimit()),
61 "reminder_status" => array("integer", $this->getReminderStatus()),
62 "reminder_day" => array("integer", $this->getReminderDay()),
63 "rsv_filter_period" => array("integer", $this->getReservationFilterPeriod()),
64 "preference_nr" => array("integer", (int) $this->getPreferenceNumber()),
65 "pref_deadline" => array("integer", (int) $this->getPreferenceDeadline())
66 );
67
68 return $fields;
69 }
70
75 public function create()
76 {
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
93 public function update()
94 {
96
97 if (!parent::update()) {
98 return false;
99 }
100
101 // put here object specific stuff
102 if ($this->getId()) {
103 $ilDB->update(
104 "booking_settings",
105 $this->getDBFields(),
106 array("booking_pool_id" => array("integer", $this->getId()))
107 );
108 }
109
110 return true;
111 }
112
113 public function read()
114 {
116
117 parent::read();
118
119 // put here object specific stuff
120 if ($this->getId()) {
121 $set = $ilDB->query('SELECT * FROM booking_settings' .
122 ' WHERE booking_pool_id = ' . $ilDB->quote($this->getId(), 'integer'));
123 $row = $ilDB->fetchAssoc($set);
124 $this->setOffline($row['pool_offline']);
125 $this->setPublicLog($row['public_log']);
126 $this->setScheduleType($row['schedule_type']);
127 $this->setOverallLimit($row['ovlimit']);
128 $this->setReminderStatus($row['reminder_status']);
129 $this->setReminderDay($row['reminder_day']);
130 $this->setReservationFilterPeriod($row['rsv_filter_period']);
131 $this->setPreferenceNumber($row['preference_nr']);
132 $this->setPreferenceDeadline($row['pref_deadline']);
133 }
134 }
135
141 public static function getPoolsWithReminders()
142 {
143 global $DIC;
144
145 $db = $DIC->database();
146 $pools = [];
147 $set = $db->queryF(
148 "SELECT * FROM booking_settings " .
149 " WHERE reminder_status = %s " .
150 " AND reminder_day > %s " .
151 " AND pool_offline = %s ",
152 array("integer","integer","integer"),
153 array(1,0,0)
154 );
155 while ($rec = $db->fetchAssoc($set)) {
156 $pools[] = $rec;
157 }
158 return $pools;
159 }
160
167 public static function writeLastReminderTimestamp($a_obj_id, $a_ts)
168 {
169 global $DIC;
170 $db = $DIC->database();
171 $db->update("booking_settings", array(
172 "last_remind_ts" => array("integer", $a_ts)
173 ), array( // where
174 "booking_pool_id" => array("integer", $a_obj_id)
175 ));
176 }
177
178
183 public function delete()
184 {
186
187 $id = $this->getId();
188
189 // always call parent delete function first!!
190 if (!parent::delete()) {
191 return false;
192 }
193
194 // put here your module specific stuff
195
196 $ilDB->manipulate('DELETE FROM booking_settings' .
197 ' WHERE booking_pool_id = ' . $ilDB->quote($id, 'integer'));
198
199 $ilDB->manipulate('DELETE FROM booking_schedule' .
200 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
201
202 $objects = array();
203 $set = $ilDB->query('SELECT booking_object_id FROM booking_object' .
204 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
205 while ($row = $ilDB->fetchAssoc($set)) {
206 $objects[] = $row['booking_object_id'];
207 }
208
209 if (sizeof($objects)) {
210 $ilDB->manipulate('DELETE FROM booking_reservation' .
211 ' WHERE ' . $ilDB->in('object_id', $objects, '', 'integer'));
212 }
213
214 $ilDB->manipulate('DELETE FROM booking_object' .
215 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
216
217 return true;
218 }
219
220 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
221 {
222 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
223
224 //copy online status if object is not the root copy object
225 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
226
227 if (!$cp_options->isRootNode($this->getRefId())) {
228 $new_obj->setOffline($this->isOffline());
229 }
230
231 $new_obj->setScheduleType($this->getScheduleType());
232 $new_obj->setPublicLog($this->hasPublicLog());
233 $new_obj->setOverallLimit($this->getOverallLimit());
234 $new_obj->setReminderStatus($this->getReminderStatus());
235 $new_obj->setReminderDay($this->getReminderDay());
236 $new_obj->setPreferenceNumber($this->getPreferenceNumber());
237 $new_obj->setPreferenceDeadline($this->getPreferenceDeadline());
238
239 $smap = null;
240 if ($this->getScheduleType() == self::TYPE_FIX_SCHEDULE) {
241 // schedules
242 foreach (ilBookingSchedule::getList($this->getId()) as $item) {
243 $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
244 $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
245 }
246 }
247
248 // objects
249 foreach (ilBookingObject::getList($this->getId()) as $item) {
250 $bobj = new ilBookingObject($item["booking_object_id"]);
251 $bobj->doClone($new_obj->getId(), $smap);
252 }
253
254 $new_obj->update();
255
256 return $new_obj;
257 }
258
263 public function setOffline($a_value = true)
264 {
265 $this->offline = (bool) $a_value;
266 }
267
272 public function isOffline()
273 {
274 return (bool) $this->offline;
275 }
276
281 public function setPublicLog($a_value = true)
282 {
283 $this->public_log = (bool) $a_value;
284 }
285
290 public function hasPublicLog()
291 {
292 return (bool) $this->public_log;
293 }
294
299 public function setScheduleType($a_value)
300 {
301 $this->schedule_type = (int) $a_value;
302 }
303
308 public function getScheduleType()
309 {
311 }
312
318 public function setReminderStatus($a_val)
319 {
320 $this->reminder_status = $a_val;
321 }
322
328 public function getReminderStatus()
329 {
331 }
332
338 public function setReminderDay($a_val)
339 {
340 $this->reminder_day = $a_val;
341 }
342
348 public function getReminderDay()
349 {
350 return $this->reminder_day;
351 }
352
358 public function setPreferenceNumber($a_val)
359 {
360 $this->preference_nr = $a_val;
361 }
362
368 public function getPreferenceNumber()
369 {
371 }
372
378 public function setPreferenceDeadline($a_val)
379 {
380 $this->pref_deadline = $a_val;
381 }
382
388 public function getPreferenceDeadline()
389 {
391 }
392
393
394
401 public static function _lookupOnline($a_obj_id)
402 {
403 global $DIC;
404
405 $ilDB = $DIC->database();
406
407 $set = $ilDB->query("SELECT pool_offline" .
408 " FROM booking_settings" .
409 " WHERE booking_pool_id = " . $ilDB->quote($a_obj_id, "integer"));
410 $row = $ilDB->fetchAssoc($set);
411 return !(bool) $row["pool_offline"];
412 }
413
419 public function setOverallLimit($a_value = null)
420 {
421 if ($a_value !== null) {
422 $a_value = (int) $a_value;
423 }
424 $this->overall_limit = $a_value;
425 }
426
432 public function getOverallLimit()
433 {
435 }
436
442 public function setReservationFilterPeriod($a_value = null)
443 {
444 if ($a_value !== null) {
445 $a_value = (int) $a_value;
446 }
447 $this->reservation_period = $a_value;
448 }
449
456 {
458 }
459
460
461 //
462 // advanced metadata
463 //
464
465 public static function getAdvancedMDFields($a_ref_id)
466 {
467 $fields = array();
468
469 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("book", $a_ref_id, "bobj");
470
471 foreach ($recs as $record_obj) {
472 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
473 $fields[$def->getFieldId()] = array(
474 "id" => $def->getFieldId(),
475 "title" => $def->getTitle(),
476 "type" => $def->getType()
477 );
478 }
479 }
480
481 return $fields;
482 }
483}
An exception for terminatinating execution or to throw for unit testing.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static _getSelectedRecordsByObject($a_obj_type, $a_ref_id, $a_sub_type="")
Get selected records by object.
a bookable ressource
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
schedule for booking ressource
static getList($a_pool_id)
Get list of booking objects for given pool.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Class ilObjBookingPool.
static writeLastReminderTimestamp($a_obj_id, $a_ts)
Write last reminder timestamp.
static getAdvancedMDFields($a_ref_id)
setOffline($a_value=true)
Toggle offline property.
setScheduleType($a_value)
Set schedule type.
__construct($a_id=0, $a_call_by_reference=true)
Constructor.
getReminderDay()
Get reminder day.
getPreferenceNumber()
Get preference number.
getDBFields()
Parse properties for sql statements.
setReservationFilterPeriod($a_value=null)
Set reservation filter period default.
getScheduleType()
Get schedule type.
read()
read object data from db into object
setReminderStatus($a_val)
Set reminder status.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
isOffline()
Get offline property.
setReminderDay($a_val)
Set reminder day.
update()
update object data
setPublicLog($a_value=true)
Toggle public log property.
getPreferenceDeadline()
Get preference deadline.
setPreferenceNumber($a_val)
Set preference number.
hasPublicLog()
Get public log property.
static _lookupOnline($a_obj_id)
Check object status.
getReminderStatus()
Get reminder status.
getOverallLimit()
Get overall / global booking limit.
setOverallLimit($a_value=null)
Set overall / global booking limit.
getReservationFilterPeriod()
Get reservation filter period default.
setPreferenceDeadline($a_val)
Set preference deadline.
static getPoolsWithReminders()
Get poos with reminders.
Class ilObject Basic functions for all objects.
getId()
get object id @access public
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB