ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilBookingObject.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 $pool_id; // int
16 protected $title; // string
17 protected $description; // string
18 protected $nr_of_items; // int
19 protected $schedule_id; // int
20 protected $info_file; // string
21 protected $post_text; // string
22 protected $post_file; // string
23
31 function __construct($a_id = NULL)
32 {
33 $this->id = (int)$a_id;
34 $this->read();
35 }
36
41 function getId()
42 {
43 return $this->id;
44 }
45
50 function setTitle($a_title)
51 {
52 $this->title = $a_title;
53 }
54
59 function getTitle()
60 {
61 return $this->title;
62 }
63
68 function setDescription($a_value)
69 {
70 $this->description = $a_value;
71 }
72
77 function getDescription()
78 {
79 return $this->description;
80 }
81
86 function setPoolId($a_pool_id)
87 {
88 $this->pool_id = (int)$a_pool_id;
89 }
90
95 function getPoolId()
96 {
97 return $this->pool_id;
98 }
99
104 function setScheduleId($a_schedule_id)
105 {
106 $this->schedule_id = (int)$a_schedule_id;
107 }
108
113 function getScheduleId()
114 {
115 return $this->schedule_id;
116 }
117
122 function setNrOfItems($a_value)
123 {
124 $this->nr_of_items = (int)$a_value;
125 }
126
131 function getNrOfItems()
132 {
133 return $this->nr_of_items;
134 }
135
140 function setFile($a_value)
141 {
142 $this->info_file = $a_value;
143 }
144
149 function getFile()
150 {
151 return $this->info_file;
152 }
153
158 {
159 if($this->id && $this->info_file)
160 {
161 $path = $this->initStorage($this->id, "file");
162 return $path.$this->info_file;
163 }
164 }
165
172 function uploadFile(array $a_upload)
173 {
174 if(!$this->id)
175 {
176 return false;
177 }
178
179 $this->deleteFile();
180
181 $path = $this->initStorage($this->id, "file");
182 $original = $a_upload["name"];
183 if (ilUtil::moveUploadedFile($a_upload["tmp_name"], $original, $path.$original))
184 {
185 chmod($path.$original, 0770);
186
187 $this->setFile($original);
188 return true;
189 }
190 return false;
191 }
192
196 public function deleteFile()
197 {
198 if($this->id)
199 {
200 $path = $this->getFileFullPath();
201 if($path)
202 {
203 @unlink($path);
204 $this->setFile(null);
205 }
206 }
207 }
208
213 function setPostText($a_value)
214 {
215 $this->post_text = $a_value;
216 }
217
222 function getPostText()
223 {
224 return $this->post_text;
225 }
226
231 function setPostFile($a_value)
232 {
233 $this->post_file = $a_value;
234 }
235
240 function getPostFile()
241 {
242 return $this->post_file;
243 }
244
249 {
250 if($this->id && $this->post_file)
251 {
252 $path = $this->initStorage($this->id, "post");
253 return $path.$this->post_file;
254 }
255 }
256
263 function uploadPostFile(array $a_upload)
264 {
265 if(!$this->id)
266 {
267 return false;
268 }
269
270 $this->deletePostFile();
271
272 $path = $this->initStorage($this->id, "post");
273 $original = $a_upload["name"];
274
275 if (ilUtil::moveUploadedFile($a_upload["tmp_name"], $original, $path.$original))
276 {
277 chmod($path.$original, 0770);
278
279 $this->setPostFile($original);
280 return true;
281 }
282 return false;
283 }
284
288 public function deletePostFile()
289 {
290 if($this->id)
291 {
292 $path = $this->getPostFileFullPath();
293 if($path)
294 {
295 @unlink($path);
296 $this->setPostFile(null);
297 }
298 }
299 }
300
304 public function deleteFiles()
305 {
306 if($this->id)
307 {
308 include_once "Modules/BookingManager/classes/class.ilFSStorageBooking.php";
309 $storage = new ilFSStorageBooking($this->id);
310 $storage->delete();
311
312 $this->setFile(null);
313 $this->setPostFile(null);
314 }
315 }
316
324 public static function initStorage($a_id, $a_subdir = null)
325 {
326 include_once "Modules/BookingManager/classes/class.ilFSStorageBooking.php";
327 $storage = new ilFSStorageBooking($a_id);
328 $storage->create();
329
330 $path = $storage->getAbsolutePath()."/";
331
332 if($a_subdir)
333 {
334 $path .= $a_subdir."/";
335
336 if(!is_dir($path))
337 {
338 mkdir($path);
339 }
340 }
341
342 return $path;
343 }
344
348 protected function read()
349 {
350 global $ilDB;
351
352 if($this->id)
353 {
354 $set = $ilDB->query('SELECT *'.
355 ' FROM booking_object'.
356 ' WHERE booking_object_id = '.$ilDB->quote($this->id, 'integer'));
357 $row = $ilDB->fetchAssoc($set);
358 $this->setTitle($row['title']);
359 $this->setDescription($row['description']);
360 $this->setPoolId($row['pool_id']);
361 $this->setScheduleId($row['schedule_id']);
362 $this->setNrOfItems($row['nr_items']);
363 $this->setFile($row['info_file']);
364 $this->setPostText($row['post_text']);
365 $this->setPostFile($row['post_file']);
366 }
367 }
368
373 protected function getDBFields()
374 {
375 $fields = array(
376 'title' => array('text', $this->getTitle()),
377 'description' => array('text', $this->getDescription()),
378 'schedule_id' => array('text', $this->getScheduleId()),
379 'nr_items' => array('text', $this->getNrOfItems()),
380 'info_file' => array('text', $this->getFile()),
381 'post_text' => array('text', $this->getPostText()),
382 'post_file' => array('text', $this->getPostFile())
383 );
384
385 return $fields;
386 }
387
392 function save()
393 {
394 global $ilDB;
395
396 if($this->id)
397 {
398 return false;
399 }
400
401 $this->id = $ilDB->nextId('booking_object');
402
403 $fields = $this->getDBFields();
404 $fields['booking_object_id'] = array('integer', $this->id);
405 $fields['pool_id'] = array('integer', $this->getPoolId());
406
407 return $ilDB->insert('booking_object', $fields);
408 }
409
414 function update()
415 {
416 global $ilDB;
417
418 if(!$this->id)
419 {
420 return false;
421 }
422
423 $fields = $this->getDBFields();
424
425 return $ilDB->update('booking_object', $fields,
426 array('booking_object_id'=>array('integer', $this->id)));
427 }
428
435 static function getList($a_pool_id, $a_title = null)
436 {
437 global $ilDB;
438
439 $sql = 'SELECT *'.
440 ' FROM booking_object'.
441 ' WHERE pool_id = '.$ilDB->quote($a_pool_id, 'integer');
442
443 if($a_title)
444 {
445 $sql .= ' AND ('.$ilDB->like('title', 'text', '%'.$a_title.'%').
446 ' OR '.$ilDB->like('description', 'text', '%'.$a_title.'%').')';
447 }
448
449 $sql .= ' ORDER BY title';
450
451 $set = $ilDB->query($sql);
452 $res = array();
453 while($row = $ilDB->fetchAssoc($set))
454 {
455 $res[] = $row;
456 }
457 return $res;
458 }
459
464 function delete()
465 {
466 global $ilDB;
467
468 if($this->id)
469 {
470 $this->deleteFiles();
471
472 return $ilDB->manipulate('DELETE FROM booking_object'.
473 ' WHERE booking_object_id = '.$ilDB->quote($this->id, 'integer'));
474 }
475 }
476
482 static function getNrOfItemsForObjects(array $a_obj_ids)
483 {
484 global $ilDB;
485
486 $map = array();
487
488 $set = $ilDB->query("SELECT booking_object_id,nr_items".
489 " FROM booking_object".
490 " WHERE ".$ilDB->in("booking_object_id", $a_obj_ids, "", "integer"));
491 while($row = $ilDB->fetchAssoc($set))
492 {
493 $map[$row["booking_object_id"]] = $row["nr_items"];
494 }
495
496 return $map;
497 }
498
499 public function doClone($a_pool_id, $a_schedule_map = null)
500 {
501 $new_obj = new self();
502 $new_obj->setPoolId($a_pool_id);
503 $new_obj->setTitle($this->getTitle());
504 $new_obj->setDescription($this->getDescription());
505 $new_obj->setNrOfItems($this->getNrOfItems());
506 $new_obj->setFile($this->getFile());
507 $new_obj->setPostText($this->getPostText());
508 $new_obj->setPostFile($this->getPostFile());
509
510 if($a_schedule_map)
511 {
512 $schedule_id = $this->getScheduleId();
513 if($schedule_id)
514 {
515 $new_obj->setScheduleId($a_schedule_map[$schedule_id]);
516 }
517 }
518
519 $new_obj->save();
520
521 // files
522 $source = $this->initStorage($this->getId());
523 $target = $new_obj->initStorage($new_obj->getId());
524 ilUtil::rCopy($source, $target);
525 }
526}
527
528?>
a bookable ressource
setScheduleId($a_schedule_id)
Set booking schedule id.
setFile($a_value)
Set info file.
uploadFile(array $a_upload)
Upload new info file.
setTitle($a_title)
Set object title.
getFile()
Get info file.
getScheduleId()
Get booking schedule id.
getPostText()
Get post text.
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items
getPostFile()
Get post file.
setPoolId($a_pool_id)
Set booking pool id.
getTitle()
Get object title.
getNrOfItems()
Get number of items.
setPostFile($a_value)
Set post file.
deleteFile()
remove existing info file
uploadPostFile(array $a_upload)
Upload new post file.
setDescription($a_value)
Set object description.
getPoolId()
Get booking pool id.
__construct($a_id=NULL)
Constructor.
doClone($a_pool_id, $a_schedule_map=null)
setNrOfItems($a_value)
Set number of items.
getFileFullPath()
Get path to info file.
setPostText($a_value)
Set post text.
getDescription()
Get object description.
deleteFiles()
remove existing files
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type
save()
Create new entry in db.
getPostFileFullPath()
Get path to post file.
getDBFields()
Parse properties for sql statements.
deletePostFile()
remove existing post file
static initStorage($a_id, $a_subdir=null)
Init file system storage.
update()
Update entry in db.
read()
Get dataset from db.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
$path
Definition: index.php:22
global $ilDB