ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
17 protected $db;
18
19 protected $id; // int
20 protected $pool_id; // int
21 protected $title; // string
22 protected $description; // string
23 protected $nr_of_items; // int
24 protected $schedule_id; // int
25 protected $info_file; // string
26 protected $post_text; // string
27 protected $post_file; // string
28
36 public function __construct($a_id = null)
37 {
38 global $DIC;
39
40 $this->db = $DIC->database();
41 $this->id = (int) $a_id;
42 $this->read();
43 }
44
49 public function getId()
50 {
51 return $this->id;
52 }
53
58 public function setTitle($a_title)
59 {
60 $this->title = $a_title;
61 }
62
67 public function getTitle()
68 {
69 return $this->title;
70 }
71
76 public function setDescription($a_value)
77 {
78 $this->description = $a_value;
79 }
80
85 public function getDescription()
86 {
87 return $this->description;
88 }
89
94 public function setPoolId($a_pool_id)
95 {
96 $this->pool_id = (int) $a_pool_id;
97 }
98
103 public function getPoolId()
104 {
105 return $this->pool_id;
106 }
107
112 public function setScheduleId($a_schedule_id)
113 {
114 $this->schedule_id = (int) $a_schedule_id;
115 }
116
121 public function getScheduleId()
122 {
123 return $this->schedule_id;
124 }
125
130 public function setNrOfItems($a_value)
131 {
132 $this->nr_of_items = (int) $a_value;
133 }
134
139 public function getNrOfItems()
140 {
141 return $this->nr_of_items;
142 }
143
148 public function setFile($a_value)
149 {
150 $this->info_file = $a_value;
151 }
152
157 public function getFile()
158 {
159 return $this->info_file;
160 }
161
165 public function getFileFullPath()
166 {
167 if ($this->id && $this->info_file) {
168 $path = $this->initStorage($this->id, "file");
169 return $path . $this->info_file;
170 }
171 }
172
179 public function uploadFile(array $a_upload)
180 {
181 if (!$this->id) {
182 return false;
183 }
184
185 $this->deleteFile();
186
187 $path = $this->initStorage($this->id, "file");
188 $original = $a_upload["name"];
189 if (ilUtil::moveUploadedFile($a_upload["tmp_name"], $original, $path . $original)) {
190 chmod($path . $original, 0770);
191
192 $this->setFile($original);
193 return true;
194 }
195 return false;
196 }
197
201 public function deleteFile()
202 {
203 if ($this->id) {
204 $path = $this->getFileFullPath();
205 if ($path) {
206 @unlink($path);
207 $this->setFile(null);
208 }
209 }
210 }
211
216 public function setPostText($a_value)
217 {
218 $this->post_text = $a_value;
219 }
220
225 public function getPostText()
226 {
227 return $this->post_text;
228 }
229
234 public function setPostFile($a_value)
235 {
236 $this->post_file = $a_value;
237 }
238
243 public function getPostFile()
244 {
245 return $this->post_file;
246 }
247
251 public function getPostFileFullPath()
252 {
253 if ($this->id && $this->post_file) {
254 $path = $this->initStorage($this->id, "post");
255 return $path . $this->post_file;
256 }
257 }
258
265 public function uploadPostFile(array $a_upload)
266 {
267 if (!$this->id) {
268 return false;
269 }
270
271 $this->deletePostFile();
272
273 $path = $this->initStorage($this->id, "post");
274 $original = $a_upload["name"];
275
276 if (ilUtil::moveUploadedFile($a_upload["tmp_name"], $original, $path . $original)) {
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 $path = $this->getPostFileFullPath();
292 if ($path) {
293 @unlink($path);
294 $this->setPostFile(null);
295 }
296 }
297 }
298
302 public function deleteFiles()
303 {
304 if ($this->id) {
305 include_once "Modules/BookingManager/classes/class.ilFSStorageBooking.php";
306 $storage = new ilFSStorageBooking($this->id);
307 $storage->delete();
308
309 $this->setFile(null);
310 $this->setPostFile(null);
311 }
312 }
313
321 public static function initStorage($a_id, $a_subdir = null)
322 {
323 include_once "Modules/BookingManager/classes/class.ilFSStorageBooking.php";
324 $storage = new ilFSStorageBooking($a_id);
325 $storage->create();
326
327 $path = $storage->getAbsolutePath() . "/";
328
329 if ($a_subdir) {
330 $path .= $a_subdir . "/";
331
332 if (!is_dir($path)) {
333 mkdir($path);
334 }
335 }
336
337 return $path;
338 }
339
343 protected function read()
344 {
346
347 if ($this->id) {
348 $set = $ilDB->query('SELECT *' .
349 ' FROM booking_object' .
350 ' WHERE booking_object_id = ' . $ilDB->quote($this->id, 'integer'));
351 $row = $ilDB->fetchAssoc($set);
352 $this->setTitle($row['title']);
353 $this->setDescription($row['description']);
354 $this->setPoolId($row['pool_id']);
355 $this->setScheduleId($row['schedule_id']);
356 $this->setNrOfItems($row['nr_items']);
357 $this->setFile($row['info_file']);
358 $this->setPostText($row['post_text']);
359 $this->setPostFile($row['post_file']);
360 }
361 }
362
367 protected function getDBFields()
368 {
369 $fields = array(
370 'title' => array('text', $this->getTitle()),
371 'description' => array('text', $this->getDescription()),
372 'schedule_id' => array('text', $this->getScheduleId()),
373 'nr_items' => array('text', $this->getNrOfItems()),
374 'info_file' => array('text', $this->getFile()),
375 'post_text' => array('text', $this->getPostText()),
376 'post_file' => array('text', $this->getPostFile())
377 );
378
379 return $fields;
380 }
381
386 public function save()
387 {
389
390 if ($this->id) {
391 return false;
392 }
393
394 $this->id = $ilDB->nextId('booking_object');
395
396 $fields = $this->getDBFields();
397 $fields['booking_object_id'] = array('integer', $this->id);
398 $fields['pool_id'] = array('integer', $this->getPoolId());
399
400 return $ilDB->insert('booking_object', $fields);
401 }
402
407 public function update()
408 {
410
411 if (!$this->id) {
412 return false;
413 }
414
415 $fields = $this->getDBFields();
416
417 return $ilDB->update(
418 'booking_object',
419 $fields,
420 array('booking_object_id'=>array('integer', $this->id))
421 );
422 }
423
430 public static function getList($a_pool_id, $a_title = null)
431 {
432 global $DIC;
433
434 $ilDB = $DIC->database();
435
436 $sql = 'SELECT *' .
437 ' FROM booking_object' .
438 ' WHERE pool_id = ' . $ilDB->quote($a_pool_id, 'integer');
439
440 if ($a_title) {
441 $sql .= ' AND (' . $ilDB->like('title', 'text', '%' . $a_title . '%') .
442 ' OR ' . $ilDB->like('description', 'text', '%' . $a_title . '%') . ')';
443 }
444
445 $sql .= ' ORDER BY title';
446
447 $set = $ilDB->query($sql);
448 $res = array();
449 while ($row = $ilDB->fetchAssoc($set)) {
450 $res[] = $row;
451 }
452 return $res;
453 }
454
459 public function delete()
460 {
462
463 if ($this->id) {
464 $this->deleteFiles();
465
466 return $ilDB->manipulate('DELETE FROM booking_object' .
467 ' WHERE booking_object_id = ' . $ilDB->quote($this->id, 'integer'));
468 }
469 }
470
476 public static function getNrOfItemsForObjects(array $a_obj_ids)
477 {
478 global $DIC;
479
480 $ilDB = $DIC->database();
481
482 $map = array();
483
484 $set = $ilDB->query("SELECT booking_object_id,nr_items" .
485 " FROM booking_object" .
486 " WHERE " . $ilDB->in("booking_object_id", $a_obj_ids, "", "integer"));
487 while ($row = $ilDB->fetchAssoc($set)) {
488 $map[$row["booking_object_id"]] = $row["nr_items"];
489 }
490
491 return $map;
492 }
493
494 public function doClone($a_pool_id, $a_schedule_map = null)
495 {
496 $new_obj = new self();
497 $new_obj->setPoolId($a_pool_id);
498 $new_obj->setTitle($this->getTitle());
499 $new_obj->setDescription($this->getDescription());
500 $new_obj->setNrOfItems($this->getNrOfItems());
501 $new_obj->setFile($this->getFile());
502 $new_obj->setPostText($this->getPostText());
503 $new_obj->setPostFile($this->getPostFile());
504
505 if ($a_schedule_map) {
506 $schedule_id = $this->getScheduleId();
507 if ($schedule_id) {
508 $new_obj->setScheduleId($a_schedule_map[$schedule_id]);
509 }
510 }
511
512 $new_obj->save();
513
514 // files
515 $source = $this->initStorage($this->getId());
516 $target = $new_obj->initStorage($new_obj->getId());
518 }
519
526 public static function lookupPoolId($object_id)
527 {
528 global $DIC;
529
530 $db = $DIC->database();
531 $set = $db->queryF(
532 "SELECT pool_id FROM booking_object " .
533 " WHERE booking_object_id = %s ",
534 array("integer"),
535 array($object_id)
536 );
537 $rec = $db->fetchAssoc($set);
538 return (int) $rec["pool_id"];
539 }
540}
$source
Definition: linkback.php:22
An exception for terminatinating execution or to throw for unit testing.
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 lookupPoolId($object_id)
Lookup pool id.
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.
__construct($a_id=null)
Constructor.
deleteFile()
remove existing info file
uploadPostFile(array $a_upload)
Upload new post file.
setDescription($a_value)
Set object description.
getPoolId()
Get booking pool id.
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 rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB