ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
184 if(@move_uploaded_file($a_upload["tmp_name"], $path.$original))
185 {
186 chmod($path.$original, 0770);
187
188 $this->setFile($original);
189 return true;
190 }
191 return false;
192 }
193
197 public function deleteFile()
198 {
199 if($this->id)
200 {
201 $path = $this->getFileFullPath();
202 if($path)
203 {
204 @unlink($path);
205 $this->setFile(null);
206 }
207 }
208 }
209
214 function setPostText($a_value)
215 {
216 $this->post_text = $a_value;
217 }
218
223 function getPostText()
224 {
225 return $this->post_text;
226 }
227
232 function setPostFile($a_value)
233 {
234 $this->post_file = $a_value;
235 }
236
241 function getPostFile()
242 {
243 return $this->post_file;
244 }
245
250 {
251 if($this->id && $this->post_file)
252 {
253 $path = $this->initStorage($this->id, "post");
254 return $path.$this->post_file;
255 }
256 }
257
264 function uploadPostFile(array $a_upload)
265 {
266 if(!$this->id)
267 {
268 return false;
269 }
270
271 $this->deletePostFile();
272
273 $path = $this->initStorage($this->id, "post");
274 $original = $a_upload["name"];
275
276 if(@move_uploaded_file($a_upload["tmp_name"], $path.$original))
277 {
278 chmod($path.$original, 0770);
279
280 $this->setPostFile($original);
281 return true;
282 }
283 return false;
284 }
285
289 public function deletePostFile()
290 {
291 if($this->id)
292 {
293 $path = $this->getPostFileFullPath();
294 if($path)
295 {
296 @unlink($path);
297 $this->setPostFile(null);
298 }
299 }
300 }
301
305 public function deleteFiles()
306 {
307 if($this->id)
308 {
309 include_once "Modules/BookingManager/classes/class.ilFSStorageBooking.php";
310 $storage = new ilFSStorageBooking($this->id);
311 $storage->delete();
312
313 $this->setFile(null);
314 $this->setPostFile(null);
315 }
316 }
317
325 public static function initStorage($a_id, $a_subdir = null)
326 {
327 include_once "Modules/BookingManager/classes/class.ilFSStorageBooking.php";
328 $storage = new ilFSStorageBooking($a_id);
329 $storage->create();
330
331 $path = $storage->getAbsolutePath()."/";
332
333 if($a_subdir)
334 {
335 $path .= $a_subdir."/";
336
337 if(!is_dir($path))
338 {
339 mkdir($path);
340 }
341 }
342
343 return $path;
344 }
345
349 protected function read()
350 {
351 global $ilDB;
352
353 if($this->id)
354 {
355 $set = $ilDB->query('SELECT *'.
356 ' FROM booking_object'.
357 ' WHERE booking_object_id = '.$ilDB->quote($this->id, 'integer'));
358 $row = $ilDB->fetchAssoc($set);
359 $this->setTitle($row['title']);
360 $this->setDescription($row['description']);
361 $this->setPoolId($row['pool_id']);
362 $this->setScheduleId($row['schedule_id']);
363 $this->setNrOfItems($row['nr_items']);
364 $this->setFile($row['info_file']);
365 $this->setPostText($row['post_text']);
366 $this->setPostFile($row['post_file']);
367 }
368 }
369
374 protected function getDBFields()
375 {
376 $fields = array(
377 'title' => array('text', $this->getTitle()),
378 'description' => array('text', $this->getDescription()),
379 'schedule_id' => array('text', $this->getScheduleId()),
380 'nr_items' => array('text', $this->getNrOfItems()),
381 'info_file' => array('text', $this->getFile()),
382 'post_text' => array('text', $this->getPostText()),
383 'post_file' => array('text', $this->getPostFile())
384 );
385
386 return $fields;
387 }
388
393 function save()
394 {
395 global $ilDB;
396
397 if($this->id)
398 {
399 return false;
400 }
401
402 $this->id = $ilDB->nextId('booking_object');
403
404 $fields = $this->getDBFields();
405 $fields['booking_object_id'] = array('integer', $this->id);
406 $fields['pool_id'] = array('integer', $this->getPoolId());
407
408 return $ilDB->insert('booking_object', $fields);
409 }
410
415 function update()
416 {
417 global $ilDB;
418
419 if(!$this->id)
420 {
421 return false;
422 }
423
424 $fields = $this->getDBFields();
425
426 return $ilDB->update('booking_object', $fields,
427 array('booking_object_id'=>array('integer', $this->id)));
428 }
429
435 static function getList($a_pool_id)
436 {
437 global $ilDB;
438
439 $set = $ilDB->query('SELECT *'.
440 ' FROM booking_object'.
441 ' WHERE pool_id = '.$ilDB->quote($a_pool_id, 'integer').
442 ' ORDER BY title');
443 $res = array();
444 while($row = $ilDB->fetchAssoc($set))
445 {
446 $res[] = $row;
447 }
448 return $res;
449 }
450
455 function delete()
456 {
457 global $ilDB;
458
459 if($this->id)
460 {
461 $this->deleteFiles();
462
463 return $ilDB->manipulate('DELETE FROM booking_object'.
464 ' WHERE booking_object_id = '.$ilDB->quote($this->id, 'integer'));
465 }
466 }
467
473 static function getNrOfItemsForObjects(array $a_obj_ids)
474 {
475 global $ilDB;
476
477 $map = array();
478
479 $set = $ilDB->query("SELECT booking_object_id,nr_items".
480 " FROM booking_object".
481 " WHERE ".$ilDB->in("booking_object_id", $a_obj_ids, "", "integer"));
482 while($row = $ilDB->fetchAssoc($set))
483 {
484 $map[$row["booking_object_id"]] = $row["nr_items"];
485 }
486
487 return $map;
488 }
489
490 public function doClone($a_pool_id, $a_schedule_map = null)
491 {
492 $new_obj = new self();
493 $new_obj->setPoolId($a_pool_id);
494 $new_obj->setTitle($this->getTitle());
495 $new_obj->setDescription($this->getDescription());
496 $new_obj->setNrOfItems($this->getNrOfItems());
497 $new_obj->setFile($this->getFile());
498 $new_obj->setPostText($this->getPostText());
499 $new_obj->setPostFile($this->getPostFile());
500
501 if($a_schedule_map)
502 {
503 $schedule_id = $this->getScheduleId();
504 if($schedule_id)
505 {
506 $new_obj->setScheduleId($a_schedule_map[$schedule_id]);
507 }
508 }
509
510 $new_obj->save();
511
512 // files
513 $source = $this->initStorage($this->getId());
514 $target = $new_obj->initStorage($new_obj->getId());
515 ilUtil::rCopy($source, $target);
516 }
517}
518
519?>
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.
static getList($a_pool_id)
Get list of booking objects for given type
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
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 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