ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBookingSchedule.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  protected $id; // int
15  protected $title; // string
16  protected $pool_id; // int
17  protected $raster; // int
18  protected $rent_min; // int
19  protected $rent_max; // int
20  protected $auto_break; // int
21  protected $deadline; // int
22  protected $definition; // array
23  protected $av_from; // ildatetime
24  protected $av_to; // ildatetime
25 
33  function __construct($a_id = NULL)
34  {
35  $this->id = (int)$a_id;
36  $this->read();
37  }
38 
43  function setTitle($a_title)
44  {
45  $this->title = $a_title;
46  }
47 
52  function getTitle()
53  {
54  return $this->title;
55  }
56 
61  function setPoolId($a_pool_id)
62  {
63  $this->pool_id = (int)$a_pool_id;
64  }
65 
70  function getPoolId()
71  {
72  return $this->pool_id;
73  }
74 
79  function setRaster($a_raster)
80  {
81  $this->raster = (int)$a_raster;
82  }
83 
88  function getRaster()
89  {
90  return $this->raster;
91  }
92 
97  function setMinRental($a_min)
98  {
99  $this->rent_min = (int)$a_min;
100  }
101 
106  function getMinRental()
107  {
108  return $this->rent_min;
109  }
110 
115  function setMaxRental($a_max)
116  {
117  $this->rent_max = (int)$a_max;
118  }
119 
124  function getMaxRental()
125  {
126  return $this->rent_max;
127  }
128 
133  function setAutoBreak($a_break)
134  {
135  $this->auto_break = (int)$a_break;
136  }
137 
142  function getAutoBreak()
143  {
144  return $this->auto_break;
145  }
146 
151  function setDeadline($a_deadline)
152  {
153  $this->deadline = (int)$a_deadline;
154  }
155 
160  function getDeadline()
161  {
162  return $this->deadline;
163  }
164 
169  function setDefinition($a_definition)
170  {
171  $this->definition = $a_definition;
172  }
173 
178  function getDefinition()
179  {
180  return $this->definition;
181  }
182 
188  function setAvailabilityFrom(ilDateTime $a_date = null)
189  {
190  $this->av_from = $a_date;
191  }
192 
199  {
200  return $this->av_from;
201  }
202 
208  function setAvailabilityTo(ilDateTime $a_date = null)
209  {
210  $this->av_to = $a_date;
211  }
212 
218  function getAvailabilityTo()
219  {
220  return $this->av_to;
221  }
222 
226  protected function read()
227  {
228  global $ilDB;
229 
230  if($this->id)
231  {
232  $set = $ilDB->query('SELECT title,raster,rent_min,rent_max,auto_break,'.
233  'deadline,av_from,av_to'.
234  ' FROM booking_schedule'.
235  ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
236  $row = $ilDB->fetchAssoc($set);
237  $this->setTitle($row['title']);
238  $this->setDeadline($row['deadline']);
239  $this->setAvailabilityFrom($row['av_from'] ? new ilDateTime($row['av_from'], IL_CAL_UNIX) : null);
240  $this->setAvailabilityTo($row['av_to'] ? new ilDateTime($row['av_to'], IL_CAL_UNIX) : null);
241  if($row['raster'])
242  {
243  $this->setRaster($row['raster']);
244  $this->setMinRental($row['rent_min']);
245  $this->setMaxRental($row['rent_max']);
246  $this->setAutoBreak($row['auto_break']);
247  }
248 
249  // load definition
250  $definition = array();
251  $set = $ilDB->query('SELECT day_id,slot_id,times'.
252  ' FROM booking_schedule_slot'.
253  ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
254  while($row = $ilDB->fetchAssoc($set))
255  {
256  $definition[$row["day_id"]][$row["slot_id"]] = $row["times"];
257  }
258  $this->setDefinition($definition);
259  }
260  }
261 
266  function save()
267  {
268  global $ilDB;
269 
270  if($this->id)
271  {
272  return false;
273  }
274 
275  $this->id = $ilDB->nextId('booking_schedule');
276 
277  $av_from = ($this->getAvailabilityFrom() && !$this->getAvailabilityFrom()->isNull())
278  ? $this->getAvailabilityFrom()->get(IL_CAL_UNIX)
279  : null;
280  $av_to = ($this->getAvailabilityTo() && !$this->getAvailabilityTo()->isNull())
281  ? $this->getAvailabilityTo()->get(IL_CAL_UNIX)
282  : null;
283 
284  $ilDB->manipulate('INSERT INTO booking_schedule'.
285  ' (booking_schedule_id,title,pool_id,raster,rent_min,rent_max,auto_break,'.
286  'deadline,av_from,av_to)'.
287  ' VALUES ('.$ilDB->quote($this->id, 'integer').','.$ilDB->quote($this->getTitle(), 'text').
288  ','.$ilDB->quote($this->getPoolId(), 'integer').','.$ilDB->quote($this->getRaster(), 'integer').
289  ','.$ilDB->quote($this->getMinRental(), 'integer').','.$ilDB->quote($this->getMaxRental(), 'integer').
290  ','.$ilDB->quote($this->getAutoBreak(), 'integer').','.$ilDB->quote($this->getDeadline(), 'integer').
291  ','.$ilDB->quote($av_from, 'integer').','.$ilDB->quote($av_to, 'integer').')');
292 
293  $this->saveDefinition();
294 
295  return $this->id;
296  }
297 
302  function update()
303  {
304  global $ilDB;
305 
306  if(!$this->id)
307  {
308  return false;
309  }
310 
311  $av_from = ($this->getAvailabilityFrom() && !$this->getAvailabilityFrom()->isNull())
312  ? $this->getAvailabilityFrom()->get(IL_CAL_UNIX)
313  : null;
314  $av_to = ($this->getAvailabilityTo() && !$this->getAvailabilityTo()->isNull())
315  ? $this->getAvailabilityTo()->get(IL_CAL_UNIX)
316  : null;
317 
318  $ilDB->manipulate('UPDATE booking_schedule'.
319  ' SET title = '.$ilDB->quote($this->getTitle(), 'text').
320  ', pool_id = '.$ilDB->quote($this->getPoolId(), 'integer').
321  ', raster = '.$ilDB->quote($this->getRaster(), 'integer').
322  ', rent_min = '.$ilDB->quote($this->getMinRental(), 'integer').
323  ', rent_max = '.$ilDB->quote($this->getMaxRental(), 'integer').
324  ', auto_break = '.$ilDB->quote($this->getAutoBreak(), 'integer').
325  ', deadline = '.$ilDB->quote($this->getDeadline(), 'integer').
326  ', av_from = '.$ilDB->quote($av_from, 'integer').
327  ', av_to = '.$ilDB->quote($av_to, 'integer').
328  ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
329 
330  $this->saveDefinition();
331  }
332 
333  public function doClone($a_pool_id)
334  {
335  $new_obj = new self();
336  $new_obj->setPoolId($a_pool_id);
337  $new_obj->setTitle($this->getTitle());
338  $new_obj->setRaster($this->getRaster());
339  $new_obj->setMinRental($this->getMinRental());
340  $new_obj->setMaxRental($this->getMaxRental());
341  $new_obj->setAutoBreak($this->getAutoBreak());
342  $new_obj->setDeadline($this->getDeadline());
343  $new_obj->setDefinition($this->getDefinition());
344  $new_obj->setAvailabilityFrom($this->getAvailabilityFrom());
345  $new_obj->setAvailabilityTo($this->getAvailabilityTo());
346  return $new_obj->save();
347  }
348 
352  protected function saveDefinition()
353  {
354  global $ilDB;
355 
356  if(!$this->id)
357  {
358  return false;
359  }
360 
361  $ilDB->manipulate('DELETE FROM booking_schedule_slot'.
362  ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
363 
364  $definition = $this->getDefinition();
365  if($definition)
366  {
367  foreach($definition as $day_id => $slots)
368  {
369  foreach($slots as $slot_id => $times)
370  {
371  $fields = array(
372  "booking_schedule_id" => array('integer', $this->id),
373  "day_id" => array('text', $day_id),
374  "slot_id" => array('integer', $slot_id),
375  "times" => array('text', $times)
376  );
377  $ilDB->insert('booking_schedule_slot', $fields);
378  }
379  }
380 
381  }
382  }
383 
389  static function hasExistingSchedules($a_pool_id)
390  {
391  global $ilDB;
392 
393  $set = $ilDB->query("SELECT booking_schedule_id".
394  " FROM booking_schedule".
395  " WHERE pool_id = ".$ilDB->quote($a_pool_id, 'integer'));
396  return (bool)$ilDB->numRows($set);
397  }
398 
404  static function getList($a_pool_id)
405  {
406  global $ilDB;
407 
408  $set = $ilDB->query('SELECT s.booking_schedule_id,s.title,'.
409  'MAX(o.schedule_id) AS object_has_schedule'.
410  ' FROM booking_schedule s'.
411  ' LEFT JOIN booking_object o ON (s.booking_schedule_id = o.schedule_id)'.
412  ' WHERE s.pool_id = '.$ilDB->quote($a_pool_id, 'integer').
413  ' GROUP BY s.booking_schedule_id,s.title'.
414  ' ORDER BY s.title');
415  $res = array();
416  while($row = $ilDB->fetchAssoc($set))
417  {
418  if(!$row['object_has_schedule'])
419  {
420  $row['is_used'] = false;
421  }
422  else
423  {
424  $row['is_used'] = true;
425  }
426  $res[] = $row;
427  }
428  return $res;
429  }
430 
435  function delete()
436  {
437  global $ilDB;
438 
439  if($this->id)
440  {
441  return $ilDB->manipulate('DELETE FROM booking_schedule'.
442  ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
443  }
444  }
445 
452  {
453  $def = $this->getDefinition();
454  $slots = array();
455  foreach($def as $day => $times)
456  {
457  foreach($times as $time)
458  {
459  $slots[$time][] = $day;
460  }
461  }
462  foreach($slots as $time => $days)
463  {
464  $slots[$time] = array_unique($days);
465  }
466  ksort($slots);
467  return $slots;
468  }
469 
470  function setDefinitionBySlots(array $a_def)
471  {
472  $slots = array();
473  foreach($a_def as $time => $days)
474  {
475  foreach($days as $day)
476  {
477  $slots[$day][] = $time;
478  }
479  }
480  $this->setDefinition($slots);
481  }
482 }
483 
484 ?>
getAutoBreak()
Get break time.
setRaster($a_raster)
Set booking raster (in minutes)
setDefinition($a_definition)
Set definition.
getDefinitionBySlots()
Return definition grouped by slots (not days)
static hasExistingSchedules($a_pool_id)
Check if given pool has any defined schedules.
setAvailabilityFrom(ilDateTime $a_date=null)
Set availability start.
setMinRental($a_min)
Set minimum rental time.
getAvailabilityFrom()
Get availability start.
schedule for booking ressource
getRaster()
Get booking raster.
getAvailabilityTo()
Get availability end.
update()
Update entry in db.
__construct($a_id=NULL)
Constructor.
getMinRental()
Get minimum rental time.
setAutoBreak($a_break)
Set break time.
const IL_CAL_UNIX
setMaxRental($a_max)
Set maximum rental time.
setDeadline($a_deadline)
Set deadline.
setDefinitionBySlots(array $a_def)
getPoolId()
Get booking pool id.
Date and time handling
getDefinition()
Get definition.
Create styles array
The data for the language used.
saveDefinition()
Save current definition.
getTitle()
Get object title.
global $ilDB
setPoolId($a_pool_id)
Set booking pool id (aka parent obj ref id)
setTitle($a_title)
Set object title.
setAvailabilityTo(ilDateTime $a_date=null)
Set availability end.
static getList($a_pool_id)
Get list of booking objects for given pool.
save()
Create new entry in db.
getMaxRental()
Get maximum rental time.
read()
Get dataset from db.