ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
24
30 public function __construct($a_id = 0, $a_call_by_reference = true)
31 {
32 global $DIC;
33
34 $this->db = $DIC->database();
35 $this->type = "book";
36 $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
37 parent::__construct($a_id, $a_call_by_reference);
38 }
39
43 protected function getDBFields()
44 {
45 $fields = array(
46 "schedule_type" => array("integer", $this->getScheduleType()),
47 "pool_offline" => array("integer", $this->isOffline()),
48 "public_log" => array("integer", $this->hasPublicLog()),
49 "ovlimit" => array("integer", $this->getOverallLimit()),
50 "rsv_filter_period" => array("integer", $this->getReservationFilterPeriod())
51 );
52
53 return $fields;
54 }
55
60 public function create()
61 {
63
64 $new_id = parent::create();
65
66 $fields = $this->getDBFields();
67 $fields["booking_pool_id"] = array("integer", $new_id);
68
69 $ilDB->insert("booking_settings", $fields);
70
71 return $new_id;
72 }
73
78 public function update()
79 {
81
82 if (!parent::update()) {
83 return false;
84 }
85
86 // put here object specific stuff
87 if ($this->getId()) {
88 $ilDB->update(
89 "booking_settings",
90 $this->getDBFields(),
91 array("booking_pool_id" => array("integer", $this->getId()))
92 );
93 }
94
95 return true;
96 }
97
98 public function read()
99 {
101
102 parent::read();
103
104 // put here object specific stuff
105 if ($this->getId()) {
106 $set = $ilDB->query('SELECT * FROM booking_settings' .
107 ' WHERE booking_pool_id = ' . $ilDB->quote($this->getId(), 'integer'));
108 $row = $ilDB->fetchAssoc($set);
109 $this->setOffline($row['pool_offline']);
110 $this->setPublicLog($row['public_log']);
111 $this->setScheduleType($row['schedule_type']);
112 $this->setOverallLimit($row['ovlimit']);
113 $this->setReservationFilterPeriod($row['rsv_filter_period']);
114 }
115 }
116
121 public function delete()
122 {
124
125 $id = $this->getId();
126
127 // always call parent delete function first!!
128 if (!parent::delete()) {
129 return false;
130 }
131
132 // put here your module specific stuff
133
134 $ilDB->manipulate('DELETE FROM booking_settings' .
135 ' WHERE booking_pool_id = ' . $ilDB->quote($id, 'integer'));
136
137 $ilDB->manipulate('DELETE FROM booking_schedule' .
138 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
139
140 $objects = array();
141 $set = $ilDB->query('SELECT booking_object_id FROM booking_object' .
142 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
143 while ($row = $ilDB->fetchAssoc($set)) {
144 $objects[] = $row['booking_object_id'];
145 }
146
147 if (sizeof($objects)) {
148 $ilDB->manipulate('DELETE FROM booking_reservation' .
149 ' WHERE ' . $ilDB->in('object_id', $objects, '', 'integer'));
150 }
151
152 $ilDB->manipulate('DELETE FROM booking_object' .
153 ' WHERE pool_id = ' . $ilDB->quote($id, 'integer'));
154
155 return true;
156 }
157
158 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
159 {
160 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
161
162 //copy online status if object is not the root copy object
163 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
164
165 if (!$cp_options->isRootNode($this->getRefId())) {
166 $new_obj->setOffline($this->isOffline());
167 }
168
169 $new_obj->setScheduleType($this->getScheduleType());
170 $new_obj->setPublicLog($this->hasPublicLog());
171 $new_obj->setOverallLimit($this->getOverallLimit());
172
173 $smap = null;
174 if ($this->getScheduleType() == self::TYPE_FIX_SCHEDULE) {
175 // schedules
176 include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
177 foreach (ilBookingSchedule::getList($this->getId()) as $item) {
178 $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
179 $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
180 }
181 }
182
183 // objects
184 include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
185 foreach (ilBookingObject::getList($this->getId()) as $item) {
186 $bobj = new ilBookingObject($item["booking_object_id"]);
187 $bobj->doClone($new_obj->getId(), $smap);
188 }
189
190 $new_obj->update();
191
192 return $new_obj;
193 }
194
199 public function setOffline($a_value = true)
200 {
201 $this->offline = (bool) $a_value;
202 }
203
208 public function isOffline()
209 {
210 return (bool) $this->offline;
211 }
212
217 public function setPublicLog($a_value = true)
218 {
219 $this->public_log = (bool) $a_value;
220 }
221
226 public function hasPublicLog()
227 {
228 return (bool) $this->public_log;
229 }
230
235 public function setScheduleType($a_value)
236 {
237 $this->schedule_type = (int) $a_value;
238 }
239
244 public function getScheduleType()
245 {
247 }
248
255 public static function _lookupOnline($a_obj_id)
256 {
257 global $DIC;
258
259 $ilDB = $DIC->database();
260
261 $set = $ilDB->query("SELECT pool_offline" .
262 " FROM booking_settings" .
263 " WHERE booking_pool_id = " . $ilDB->quote($a_obj_id, "integer"));
264 $row = $ilDB->fetchAssoc($set);
265 return !(bool) $row["pool_offline"];
266 }
267
273 public function setOverallLimit($a_value = null)
274 {
275 if ($a_value !== null) {
276 $a_value = (int) $a_value;
277 }
278 $this->overall_limit = $a_value;
279 }
280
286 public function getOverallLimit()
287 {
289 }
290
296 public function setReservationFilterPeriod($a_value = null)
297 {
298 if ($a_value !== null) {
299 $a_value = (int) $a_value;
300 }
301 $this->reservation_period = $a_value;
302 }
303
310 {
312 }
313
314
315 //
316 // advanced metadata
317 //
318
319 public static function getAdvancedMDFields($a_ref_id)
320 {
321 $fields = array();
322
323 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
324 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("book", $a_ref_id, "bobj");
325
326 foreach ($recs as $record_obj) {
327 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
328 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def) {
329 $fields[$def->getFieldId()] = array(
330 "id" => $def->getFieldId(),
331 "title" => $def->getTitle(),
332 "type" => $def->getType()
333 );
334 }
335 }
336
337 return $fields;
338 }
339}
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 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.
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
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
isOffline()
Get offline property.
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.
getOverallLimit()
Get overall / global booking limit.
setOverallLimit($a_value=null)
Set overall / global booking limit.
getReservationFilterPeriod()
Get reservation filter period default.
Class ilObject Basic functions for all objects.
getId()
get object id @access public
$def
Definition: croninfo.php:21
update($pash, $contents, Config $config)
global $DIC
Definition: saml.php:7
global $ilDB