ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4require_once "./Services/Object/classes/class.ilObject.php";
5
14{
15 //offline default should be true
16 protected $offline = true; // [bool]
17 protected $public_log; // [bool]
18 protected $schedule_type; // [int]
19 protected $overall_limit; // [int]
20 protected $reservation_period; // [int]
21 protected $reminder_status = 0; // [int]
22 protected $reminder_day = 1; // [int]
23
26
32 public function __construct($a_id = 0, $a_call_by_reference = true)
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 $this->type = "book";
38 $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
39 parent::__construct($a_id, $a_call_by_reference);
40 }
41
45 protected function getDBFields()
46 {
47 $fields = array(
48 "schedule_type" => array("integer", $this->getScheduleType()),
49 "pool_offline" => array("integer", $this->isOffline()),
50 "public_log" => array("integer", $this->hasPublicLog()),
51 "ovlimit" => array("integer", $this->getOverallLimit()),
52 "reminder_status" => array("integer", $this->getReminderStatus()),
53 "reminder_day" => array("integer", $this->getReminderDay()),
54 "rsv_filter_period" => array("integer", $this->getReservationFilterPeriod())
55 );
56
57 return $fields;
58 }
59
64 public function create()
65 {
67
68 $new_id = parent::create();
69
70 $fields = $this->getDBFields();
71 $fields["booking_pool_id"] = array("integer", $new_id);
72
73 $ilDB->insert("booking_settings", $fields);
74
75 return $new_id;
76 }
77
82 public function update()
83 {
85
86 if (!parent::update()) {
87 return false;
88 }
89
90 // put here object specific stuff
91 if ($this->getId()) {
92 $ilDB->update(
93 "booking_settings",
94 $this->getDBFields(),
95 array("booking_pool_id" => array("integer", $this->getId()))
96 );
97 }
98
99 return true;
100 }
101
102 public function read()
103 {
105
106 parent::read();
107
108 // put here object specific stuff
109 if ($this->getId()) {
110 $set = $ilDB->query('SELECT * FROM booking_settings' .
111 ' WHERE booking_pool_id = ' . $ilDB->quote($this->getId(), 'integer'));
112 $row = $ilDB->fetchAssoc($set);
113 $this->setOffline($row['pool_offline']);
114 $this->setPublicLog($row['public_log']);
115 $this->setScheduleType($row['schedule_type']);
116 $this->setOverallLimit($row['ovlimit']);
117 $this->setReminderStatus($row['reminder_status']);
118 $this->setReminderDay($row['reminder_day']);
119 $this->setReservationFilterPeriod($row['rsv_filter_period']);
120 }
121 }
122
128 public static function getPoolsWithReminders()
129 {
130 global $DIC;
131
132 $db = $DIC->database();
133 $pools = [];
134 $set = $db->queryF(
135 "SELECT * FROM booking_settings " .
136 " WHERE reminder_status = %s " .
137 " AND reminder_day > %s " .
138 " AND pool_offline = %s ",
139 array("integer","integer","integer"),
140 array(1,0,0)
141 );
142 while ($rec = $db->fetchAssoc($set)) {
143 $pools[] = $rec;
144 }
145 return $pools;
146 }
147
154 public static function writeLastReminderTimestamp($a_obj_id, $a_ts)
155 {
156 global $DIC;
157 $db = $DIC->database();
158 $db->update("booking_settings", array(
159 "last_remind_ts" => array("integer", $a_ts)
160 ), array( // where
161 "booking_pool_id" => array("integer", $a_obj_id)
162 ));
163 }
164
165
170 public function delete()
171 {
173
174 $id = $this->getId();
175
176 // always call parent delete function first!!
177 if (!parent::delete()) {
178 return false;
179 }
180
181 // put here your module specific stuff
182
183 $ilDB->manipulate('DELETE FROM booking_settings' .
184 ' WHERE booking_pool_id = ' . $ilDB->quote($id, 'integer'));
185
186 $ilDB->manipulate('DELETE FROM booking_schedule' .
187 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
188
189 $objects = array();
190 $set = $ilDB->query('SELECT booking_object_id FROM booking_object' .
191 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
192 while ($row = $ilDB->fetchAssoc($set)) {
193 $objects[] = $row['booking_object_id'];
194 }
195
196 if (sizeof($objects)) {
197 $ilDB->manipulate('DELETE FROM booking_reservation' .
198 ' WHERE ' . $ilDB->in('object_id', $objects, '', 'integer'));
199 }
200
201 $ilDB->manipulate('DELETE FROM booking_object' .
202 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
203
204 return true;
205 }
206
207 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
208 {
209 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
210
211 //copy online status if object is not the root copy object
212 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
213
214 if (!$cp_options->isRootNode($this->getRefId())) {
215 $new_obj->setOffline($this->isOffline());
216 }
217
218 $new_obj->setScheduleType($this->getScheduleType());
219 $new_obj->setPublicLog($this->hasPublicLog());
220 $new_obj->setOverallLimit($this->getOverallLimit());
221 $new_obj->setReminderStatus($this->getReminderStatus());
222 $new_obj->setReminderDay($this->getReminderDay());
223
224 $smap = null;
225 if ($this->getScheduleType() == self::TYPE_FIX_SCHEDULE) {
226 // schedules
227 include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
228 foreach (ilBookingSchedule::getList($this->getId()) as $item) {
229 $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
230 $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
231 }
232 }
233
234 // objects
235 include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
236 foreach (ilBookingObject::getList($this->getId()) as $item) {
237 $bobj = new ilBookingObject($item["booking_object_id"]);
238 $bobj->doClone($new_obj->getId(), $smap);
239 }
240
241 $new_obj->update();
242
243 return $new_obj;
244 }
245
250 public function setOffline($a_value = true)
251 {
252 $this->offline = (bool) $a_value;
253 }
254
259 public function isOffline()
260 {
261 return (bool) $this->offline;
262 }
263
268 public function setPublicLog($a_value = true)
269 {
270 $this->public_log = (bool) $a_value;
271 }
272
277 public function hasPublicLog()
278 {
279 return (bool) $this->public_log;
280 }
281
286 public function setScheduleType($a_value)
287 {
288 $this->schedule_type = (int) $a_value;
289 }
290
295 public function getScheduleType()
296 {
298 }
299
305 public function setReminderStatus($a_val)
306 {
307 $this->reminder_status = $a_val;
308 }
309
315 public function getReminderStatus()
316 {
318 }
319
325 public function setReminderDay($a_val)
326 {
327 $this->reminder_day = $a_val;
328 }
329
335 public function getReminderDay()
336 {
337 return $this->reminder_day;
338 }
339
346 public static function _lookupOnline($a_obj_id)
347 {
348 global $DIC;
349
350 $ilDB = $DIC->database();
351
352 $set = $ilDB->query("SELECT pool_offline" .
353 " FROM booking_settings" .
354 " WHERE booking_pool_id = " . $ilDB->quote($a_obj_id, "integer"));
355 $row = $ilDB->fetchAssoc($set);
356 return !(bool) $row["pool_offline"];
357 }
358
364 public function setOverallLimit($a_value = null)
365 {
366 if ($a_value !== null) {
367 $a_value = (int) $a_value;
368 }
369 $this->overall_limit = $a_value;
370 }
371
377 public function getOverallLimit()
378 {
380 }
381
387 public function setReservationFilterPeriod($a_value = null)
388 {
389 if ($a_value !== null) {
390 $a_value = (int) $a_value;
391 }
392 $this->reservation_period = $a_value;
393 }
394
401 {
403 }
404
405
406 //
407 // advanced metadata
408 //
409
410 public static function getAdvancedMDFields($a_ref_id)
411 {
412 $fields = array();
413
414 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
415 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("book", $a_ref_id, "bobj");
416
417 foreach ($recs as $record_obj) {
418 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
419 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
420 $fields[$def->getFieldId()] = array(
421 "id" => $def->getFieldId(),
422 "title" => $def->getTitle(),
423 "type" => $def->getType()
424 );
425 }
426 }
427
428 return $fields;
429 }
430}
An exception for terminatinating execution or to throw for unit testing.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
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.
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.
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.
static getPoolsWithReminders()
Get poos with reminders.
Class ilObject Basic functions for all objects.
getId()
get object id @access public
$def
Definition: croninfo.php:21
$row
update($pash, $contents, Config $config)
global $DIC
Definition: saml.php:7
global $ilDB