ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_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 
22  const TYPE_FIX_SCHEDULE = 1;
23  const TYPE_NO_SCHEDULE = 2;
24 
30  function __construct($a_id = 0,$a_call_by_reference = true)
31  {
32  $this->type = "book";
33  $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
34  parent::__construct($a_id,$a_call_by_reference);
35  }
36 
40  protected function getDBFields()
41  {
42  $fields = array(
43  "schedule_type" => array("integer", $this->getScheduleType()),
44  "pool_offline" => array("integer", $this->isOffline()),
45  "public_log" => array("integer", $this->hasPublicLog()),
46  "ovlimit" => array("integer", $this->getOverallLimit()),
47  "rsv_filter_period" => array("integer", $this->getReservationFilterPeriod())
48  );
49 
50  return $fields;
51  }
52 
57  function create()
58  {
59  global $ilDB;
60 
61  $new_id = parent::create();
62 
63  $fields = $this->getDBFields();
64  $fields["booking_pool_id"] = array("integer", $new_id);
65 
66  $ilDB->insert("booking_settings", $fields);
67 
68  return $new_id;
69  }
70 
75  function update()
76  {
77  global $ilDB;
78 
79  if (!parent::update())
80  {
81  return false;
82  }
83 
84  // put here object specific stuff
85  if($this->getId())
86  {
87  $ilDB->update("booking_settings", $this->getDBFields(),
88  array("booking_pool_id" => array("integer", $this->getId())));
89  }
90 
91  return true;
92  }
93 
94  function read()
95  {
96  global $ilDB;
97 
98  parent::read();
99 
100  // put here object specific stuff
101  if($this->getId())
102  {
103  $set = $ilDB->query('SELECT * FROM booking_settings'.
104  ' WHERE booking_pool_id = '.$ilDB->quote($this->getId(), 'integer'));
105  $row = $ilDB->fetchAssoc($set);
106  $this->setOffline($row['pool_offline']);
107  $this->setPublicLog($row['public_log']);
108  $this->setScheduleType($row['schedule_type']);
109  $this->setOverallLimit($row['ovlimit']);
110  $this->setReservationFilterPeriod($row['rsv_filter_period']);
111  }
112  }
113 
118  function delete()
119  {
120  global $ilDB;
121 
122  $id = $this->getId();
123 
124  // always call parent delete function first!!
125  if (!parent::delete())
126  {
127  return false;
128  }
129 
130  // put here your module specific stuff
131 
132  $ilDB->manipulate('DELETE FROM booking_settings'.
133  ' WHERE booking_pool_id = '.$ilDB->quote($id, 'integer'));
134 
135  $ilDB->manipulate('DELETE FROM booking_schedule'.
136  ' WHERE pool_id = '.$ilDB->quote($id, 'integer'));
137 
138  $objects = array();
139  $set = $ilDB->query('SELECT booking_object_id FROM booking_object'.
140  ' WHERE pool_id = '.$ilDB->quote($id, 'integer'));
141  while($row = $ilDB->fetchAssoc($set))
142  {
143  $objects[] = $row['booking_object_id'];
144  }
145 
146  if(sizeof($objects))
147  {
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  {
167  $new_obj->setOffline($this->isOffline());
168  }
169 
170  $new_obj->setScheduleType($this->getScheduleType());
171  $new_obj->setPublicLog($this->hasPublicLog());
172  $new_obj->setOverallLimit($this->getOverallLimit());
173 
174  $smap = null;
175  if($this->getScheduleType() == self::TYPE_FIX_SCHEDULE)
176  {
177  // schedules
178  include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
179  foreach(ilBookingSchedule::getList($this->getId()) as $item)
180  {
181  $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
182  $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
183  }
184  }
185 
186  // objects
187  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
188  foreach(ilBookingObject::getList($this->getId()) as $item)
189  {
190  $bobj = new ilBookingObject($item["booking_object_id"]);
191  $bobj->doClone($new_obj->getId(), $smap);
192  }
193 
194  $new_obj->update();
195 
196  return $new_obj;
197  }
198 
203  function setOffline($a_value = true)
204  {
205  $this->offline = (bool)$a_value;
206  }
207 
212  function isOffline()
213  {
214  return (bool)$this->offline;
215  }
216 
221  function setPublicLog($a_value = true)
222  {
223  $this->public_log = (bool)$a_value;
224  }
225 
230  function hasPublicLog()
231  {
232  return (bool)$this->public_log;
233  }
234 
239  function setScheduleType($a_value)
240  {
241  $this->schedule_type = (int)$a_value;
242  }
243 
248  function getScheduleType()
249  {
250  return $this->schedule_type;
251  }
252 
259  public static function _lookupOnline($a_obj_id)
260  {
261  global $ilDB;
262 
263  $set = $ilDB->query("SELECT pool_offline".
264  " FROM booking_settings".
265  " WHERE booking_pool_id = ".$ilDB->quote($a_obj_id, "integer"));
266  $row = $ilDB->fetchAssoc($set);
267  return !(bool)$row["pool_offline"];
268  }
269 
275  public function setOverallLimit($a_value = null)
276  {
277  if($a_value !== null)
278  {
279  $a_value = (int)$a_value;
280  }
281  $this->overall_limit = $a_value;
282  }
283 
289  public function getOverallLimit()
290  {
291  return $this->overall_limit;
292  }
293 
299  public function setReservationFilterPeriod($a_value = null)
300  {
301  if($a_value !== null)
302  {
303  $a_value = (int)$a_value;
304  }
305  $this->reservation_period = $a_value;
306  }
307 
313  public function getReservationFilterPeriod()
314  {
316  }
317 
318 
319  //
320  // advanced metadata
321  //
322 
323  public static function getAdvancedMDFields($a_glossary_id)
324  {
325  $fields = array();
326 
327  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
328  $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("book", $a_glossary_id, "bobj");
329 
330  foreach($recs as $record_obj)
331  {
332  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
333  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_obj->getRecordId()) as $def)
334  {
335  $fields[$def->getFieldId()] = array(
336  "id" => $def->getFieldId(),
337  "title" => $def->getTitle(),
338  "type" => $def->getType()
339  );
340  }
341  }
342 
343  return $fields;
344  }
345 }
346 
347 ?>
a bookable ressource
getDBFields()
Parse properties for sql statements.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
update()
update object data
getScheduleType()
Get schedule type.
Class ilObject Basic functions for all objects.
__construct($a_id=0, $a_call_by_reference=true)
Constructor.
schedule for booking ressource
hasPublicLog()
Get public log property.
setOffline($a_value=true)
Toggle offline property.
Class ilObjBookingPool.
setScheduleType($a_value)
Set schedule type.
static getAdvancedMDFields($a_glossary_id)
static _lookupOnline($a_obj_id)
Check object status.
setPublicLog($a_value=true)
Toggle public log property.
setReservationFilterPeriod($a_value=null)
Set reservation filter period default.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
getId()
get object id public
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
Create styles array
The data for the language used.
getReservationFilterPeriod()
Get reservation filter period default.
isOffline()
Get offline property.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
global $ilDB
getOverallLimit()
Get overall / global booking limit.
static getList($a_pool_id)
Get list of booking objects for given pool.
setOverallLimit($a_value=null)
Set overall / global booking limit.