ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
31 function __construct($a_id = NULL)
32 {
33 $this->id = (int)$a_id;
34 $this->read();
35 }
36
41 function setTitle($a_title)
42 {
43 $this->title = $a_title;
44 }
45
50 function getTitle()
51 {
52 return $this->title;
53 }
54
59 function setPoolId($a_pool_id)
60 {
61 $this->pool_id = (int)$a_pool_id;
62 }
63
68 function getPoolId()
69 {
70 return $this->pool_id;
71 }
72
77 function setRaster($a_raster)
78 {
79 $this->raster = (int)$a_raster;
80 }
81
86 function getRaster()
87 {
88 return $this->raster;
89 }
90
95 function setMinRental($a_min)
96 {
97 $this->rent_min = (int)$a_min;
98 }
99
104 function getMinRental()
105 {
106 return $this->rent_min;
107 }
108
113 function setMaxRental($a_max)
114 {
115 $this->rent_max = (int)$a_max;
116 }
117
122 function getMaxRental()
123 {
124 return $this->rent_max;
125 }
126
131 function setAutoBreak($a_break)
132 {
133 $this->auto_break = (int)$a_break;
134 }
135
140 function getAutoBreak()
141 {
142 return $this->auto_break;
143 }
144
149 function setDeadline($a_deadline)
150 {
151 $this->deadline = (int)$a_deadline;
152 }
153
158 function getDeadline()
159 {
160 return $this->deadline;
161 }
162
167 function setDefinition($a_definition)
168 {
169 $this->definition = $a_definition;
170 }
171
176 function getDefinition()
177 {
178 return $this->definition;
179 }
180
184 protected function read()
185 {
186 global $ilDB;
187
188 if($this->id)
189 {
190 $set = $ilDB->query('SELECT title,raster,rent_min,rent_max,auto_break,'.
191 'deadline'.
192 ' FROM booking_schedule'.
193 ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
194 $row = $ilDB->fetchAssoc($set);
195 $this->setTitle($row['title']);
196 $this->setDeadline($row['deadline']);
197 if($row['raster'])
198 {
199 $this->setRaster($row['raster']);
200 $this->setMinRental($row['rent_min']);
201 $this->setMaxRental($row['rent_max']);
202 $this->setAutoBreak($row['auto_break']);
203 }
204
205 // load definition
206 $definition = array();
207 $set = $ilDB->query('SELECT day_id,slot_id,times'.
208 ' FROM booking_schedule_slot'.
209 ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
210 while($row = $ilDB->fetchAssoc($set))
211 {
212 $definition[$row["day_id"]][$row["slot_id"]] = $row["times"];
213 }
215 }
216 }
217
222 function save()
223 {
224 global $ilDB;
225
226 if($this->id)
227 {
228 return false;
229 }
230
231 $this->id = $ilDB->nextId('booking_schedule');
232
233 $ilDB->manipulate('INSERT INTO booking_schedule'.
234 ' (booking_schedule_id,title,pool_id,raster,rent_min,rent_max,auto_break,'.
235 'deadline)'.
236 ' VALUES ('.$ilDB->quote($this->id, 'integer').','.$ilDB->quote($this->getTitle(), 'text').
237 ','.$ilDB->quote($this->getPoolId(), 'integer').','.$ilDB->quote($this->getRaster(), 'integer').
238 ','.$ilDB->quote($this->getMinRental(), 'integer').','.$ilDB->quote($this->getMaxRental(), 'integer').
239 ','.$ilDB->quote($this->getAutoBreak(), 'integer').','.$ilDB->quote($this->getDeadline(), 'integer').')');
240
241 $this->saveDefinition();
242
243 return $this->id;
244 }
245
250 function update()
251 {
252 global $ilDB;
253
254 if(!$this->id)
255 {
256 return false;
257 }
258
259 $ilDB->manipulate('UPDATE booking_schedule'.
260 ' SET title = '.$ilDB->quote($this->getTitle(), 'text').
261 ', pool_id = '.$ilDB->quote($this->getPoolId(), 'integer').
262 ', raster = '.$ilDB->quote($this->getRaster(), 'integer').
263 ', rent_min = '.$ilDB->quote($this->getMinRental(), 'integer').
264 ', rent_max = '.$ilDB->quote($this->getMaxRental(), 'integer').
265 ', auto_break = '.$ilDB->quote($this->getAutoBreak(), 'integer').
266 ', deadline = '.$ilDB->quote($this->getDeadline(), 'integer').
267 ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
268
269 $this->saveDefinition();
270 }
271
272 public function doClone($a_pool_id)
273 {
274 $new_obj = new self();
275 $new_obj->setPoolId($a_pool_id);
276 $new_obj->setTitle($this->getTitle());
277 $new_obj->setRaster($this->getRaster());
278 $new_obj->setMinRental($this->getMinRental());
279 $new_obj->setMaxRental($this->getMaxRental());
280 $new_obj->setAutoBreak($this->getAutoBreak());
281 $new_obj->setDeadline($this->getDeadline());
282 $new_obj->setDefinition($this->getDefinition());
283 return $new_obj->save();
284 }
285
289 protected function saveDefinition()
290 {
291 global $ilDB;
292
293 if(!$this->id)
294 {
295 return false;
296 }
297
298 $ilDB->manipulate('DELETE FROM booking_schedule_slot'.
299 ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
300
301 $definition = $this->getDefinition();
302 if($definition)
303 {
304 foreach($definition as $day_id => $slots)
305 {
306 foreach($slots as $slot_id => $times)
307 {
308 $fields = array(
309 "booking_schedule_id" => array('integer', $this->id),
310 "day_id" => array('text', $day_id),
311 "slot_id" => array('integer', $slot_id),
312 "times" => array('text', $times)
313 );
314 $ilDB->insert('booking_schedule_slot', $fields);
315 }
316 }
317
318 }
319 }
320
326 static function hasExistingSchedules($a_pool_id)
327 {
328 global $ilDB;
329
330 $set = $ilDB->query("SELECT booking_schedule_id".
331 " FROM booking_schedule".
332 " WHERE pool_id = ".$ilDB->quote($a_pool_id, 'integer'));
333 return (bool)$ilDB->numRows($set);
334 }
335
341 static function getList($a_pool_id)
342 {
343 global $ilDB;
344
345 $set = $ilDB->query('SELECT s.booking_schedule_id,s.title,'.
346 'MAX(o.schedule_id) AS object_has_schedule'.
347 ' FROM booking_schedule s'.
348 ' LEFT JOIN booking_object o ON (s.booking_schedule_id = o.schedule_id)'.
349 ' WHERE s.pool_id = '.$ilDB->quote($a_pool_id, 'integer').
350 ' GROUP BY s.booking_schedule_id,s.title'.
351 ' ORDER BY s.title');
352 $res = array();
353 while($row = $ilDB->fetchAssoc($set))
354 {
355 if(!$row['object_has_schedule'])
356 {
357 $row['is_used'] = false;
358 }
359 else
360 {
361 $row['is_used'] = true;
362 }
363 $res[] = $row;
364 }
365 return $res;
366 }
367
372 function delete()
373 {
374 global $ilDB;
375
376 if($this->id)
377 {
378 return $ilDB->manipulate('DELETE FROM booking_schedule'.
379 ' WHERE booking_schedule_id = '.$ilDB->quote($this->id, 'integer'));
380 }
381 }
382
389 {
390 $def = $this->getDefinition();
391 $slots = array();
392 foreach($def as $day => $times)
393 {
394 foreach($times as $time)
395 {
396 $slots[$time][] = $day;
397 }
398 }
399 foreach($slots as $time => $days)
400 {
401 $slots[$time] = array_unique($days);
402 }
403 ksort($slots);
404 return $slots;
405 }
406
407 function setDefinitionBySlots(array $a_def)
408 {
409 $slots = array();
410 foreach($a_def as $time => $days)
411 {
412 foreach($days as $day)
413 {
414 $slots[$day][] = $time;
415 }
416 }
417 $this->setDefinition($slots);
418 }
419}
420
421?>
schedule for booking ressource
getAutoBreak()
Get break time.
setTitle($a_title)
Set object title.
getRaster()
Get booking raster.
setDefinitionBySlots(array $a_def)
setDeadline($a_deadline)
Set deadline.
__construct($a_id=NULL)
Constructor.
static hasExistingSchedules($a_pool_id)
Check if given pool has any defined schedules.
setPoolId($a_pool_id)
Set booking pool id (aka parent obj ref id)
saveDefinition()
Save current definition.
getMaxRental()
Get maximum rental time.
save()
Create new entry in db.
setRaster($a_raster)
Set booking raster (in minutes)
update()
Update entry in db.
setDefinition($a_definition)
Set definition.
getMinRental()
Get minimum rental time.
getDefinition()
Get definition.
getDefinitionBySlots()
Return definition grouped by slots (not days)
setAutoBreak($a_break)
Set break time.
setMaxRental($a_max)
Set maximum rental time.
static getList($a_pool_id)
Get list of booking objects for given pool.
setMinRental($a_min)
Set minimum rental time.
read()
Get dataset from db.
getTitle()
Get object title.
getPoolId()
Get booking pool id.
global $ilDB