ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  protected $offline; // bool
16  protected $public_log; // bool
17  protected $schedule_type; // int
18 
19  const TYPE_FIX_SCHEDULE = 1;
20  const TYPE_NO_SCHEDULE = 2;
21 
27  function __construct($a_id = 0,$a_call_by_reference = true)
28  {
29  $this->type = "book";
30  $this->setScheduleType(self::TYPE_FIX_SCHEDULE);
31  $this->ilObject($a_id,$a_call_by_reference);
32  }
33 
37  protected function getDBFields()
38  {
39  $fields = array(
40  "schedule_type" => array("integer", $this->getScheduleType()),
41  "pool_offline" => array("integer", $this->isOffline()),
42  "public_log" => array("integer", $this->hasPublicLog())
43  );
44 
45  return $fields;
46  }
47 
52  function create()
53  {
54  global $ilDB;
55 
56  $new_id = parent::create();
57 
58  $fields = $this->getDBFields();
59  $fields["booking_pool_id"] = array("integer", $new_id);
60 
61  $ilDB->insert("booking_settings", $fields);
62 
63  return $new_id;
64  }
65 
70  function update()
71  {
72  global $ilDB;
73 
74  if (!parent::update())
75  {
76  return false;
77  }
78 
79  // put here object specific stuff
80  if($this->getId())
81  {
82  $ilDB->update("booking_settings", $this->getDBFields(),
83  array("booking_pool_id" => array("integer", $this->getId())));
84  }
85 
86  return true;
87  }
88 
89  function read()
90  {
91  global $ilDB;
92 
93  parent::read();
94 
95  // put here object specific stuff
96  if($this->getId())
97  {
98  $set = $ilDB->query('SELECT * FROM booking_settings'.
99  ' WHERE booking_pool_id = '.$ilDB->quote($this->getId(), 'integer'));
100  $row = $ilDB->fetchAssoc($set);
101  $this->setOffline($row['pool_offline']);
102  $this->setPublicLog($row['public_log']);
103  $this->setScheduleType($row['schedule_type']);
104  }
105  }
106 
111  function delete()
112  {
113  global $ilDB;
114 
115  $id = $this->getId();
116 
117  // always call parent delete function first!!
118  if (!parent::delete())
119  {
120  return false;
121  }
122 
123  // put here your module specific stuff
124 
125  $ilDB->manipulate('DELETE FROM booking_settings'.
126  ' WHERE booking_pool_id = '.$ilDB->quote($id, 'integer'));
127 
128  $ilDB->manipulate('DELETE FROM booking_schedule'.
129  ' WHERE pool_id = '.$ilDB->quote($id, 'integer'));
130 
131  $objects = array();
132  $set = $ilDB->query('SELECT booking_object_id FROM booking_object'.
133  ' WHERE pool_id = '.$ilDB->quote($id, 'integer'));
134  while($row = $ilDB->fetchAssoc($set))
135  {
136  $objects[] = $row['booking_object_id'];
137  }
138 
139  if(sizeof($objects))
140  {
141  $ilDB->manipulate('DELETE FROM booking_reservation'.
142  ' WHERE '.$ilDB->in('object_id', $objects, '', 'integer'));
143  }
144 
145  $ilDB->manipulate('DELETE FROM booking_object'.
146  ' WHERE pool_id = '.$ilDB->quote($id, 'integer'));
147 
148  return true;
149  }
150 
151  public function cloneObject($a_target_id,$a_copy_id = 0,$a_omit_tree = false)
152  {
153  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
154 
155  $new_obj->setOffline($this->isOffline());
156  $new_obj->setScheduleType($this->getScheduleType());
157  $new_obj->setPublicLog($this->hasPublicLog());
158 
159  $smap = null;
160  if($this->getScheduleType() == self::TYPE_FIX_SCHEDULE)
161  {
162  // schedules
163  include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
164  foreach(ilBookingSchedule::getList($this->getId()) as $item)
165  {
166  $schedule = new ilBookingSchedule($item["booking_schedule_id"]);
167  $smap[$item["booking_schedule_id"]] = $schedule->doClone($new_obj->getId());
168  }
169  }
170 
171  // objects
172  include_once "Modules/BookingManager/classes/class.ilBookingObject.php";
173  foreach(ilBookingObject::getList($this->getId()) as $item)
174  {
175  $bobj = new ilBookingObject($item["booking_object_id"]);
176  $bobj->doClone($new_obj->getId(), $smap);
177  }
178 
179  $new_obj->update();
180 
181  return $new_obj;
182  }
183 
192  function initDefaultRoles()
193  {
194  global $rbacadmin;
195 
196  // create a local role folder
197  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
198 
199  // create moderator role and assign role to rolefolder...
200  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
201  //$roles[] = $roleObj->getId();
202 
203  //unset($rfoldObj);
204  //unset($roleObj);
205 
206  return $roles ? $roles : array();
207  }
208 
221  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
222  {
223  global $tree;
224 
225  switch ($a_event)
226  {
227  case "link":
228 
229  //var_dump("<pre>",$a_params,"</pre>");
230  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
231  //exit;
232  break;
233 
234  case "cut":
235 
236  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
237  //exit;
238  break;
239 
240  case "copy":
241 
242  //var_dump("<pre>",$a_params,"</pre>");
243  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
244  //exit;
245  break;
246 
247  case "paste":
248 
249  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
250  //exit;
251  break;
252 
253  case "new":
254 
255  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
256  //exit;
257  break;
258  }
259 
260  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
261  if ($a_node_id==$_GET["ref_id"])
262  {
263  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
264  $parent_type = $parent_obj->getType();
265  if($parent_type == $this->getType())
266  {
267  $a_node_id = (int) $tree->getParentId($a_node_id);
268  }
269  }
270 
271  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
272  }
273 
278  function setOffline($a_value = true)
279  {
280  $this->offline = (bool)$a_value;
281  }
282 
287  function isOffline()
288  {
289  return (bool)$this->offline;
290  }
291 
296  function setPublicLog($a_value = true)
297  {
298  $this->public_log = (bool)$a_value;
299  }
300 
305  function hasPublicLog()
306  {
307  return (bool)$this->public_log;
308  }
309 
314  function setScheduleType($a_value)
315  {
316  $this->schedule_type = (int)$a_value;
317  }
318 
323  function getScheduleType()
324  {
325  return $this->schedule_type;
326  }
327 
334  public static function _lookupOnline($a_obj_id)
335  {
336  global $ilDB;
337 
338  $set = $ilDB->query("SELECT pool_offline".
339  " FROM booking_settings".
340  " WHERE booking_pool_id = ".$ilDB->quote($a_obj_id, "integer"));
341  $row = $ilDB->fetchAssoc($set);
342  return !(bool)$row["pool_offline"];
343  }
344 }
345 
346 ?>