ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
460 public static function getNumberOfObjectsForPool($a_pool_id)
461 {
462 global $DIC;
463
464 $ilDB = $DIC->database();
465
466 $sql = 'SELECT count(*) as count' .
467 ' FROM booking_object' .
468 ' WHERE pool_id = ' . $ilDB->quote($a_pool_id, 'integer');
469 $set = $ilDB->query($sql);
470 $rec = $ilDB->fetchAssoc($set);
471
472 return $rec["count"];
473 }
474
480 public static function getObjectsForPool(int $a_pool_id) : array
481 {
482 global $DIC;
483 $ilDB = $DIC->database();
484
485 $set = $ilDB->query("SELECT booking_object_id" .
486 " FROM booking_object" .
487 " WHERE pool_id = " . $ilDB->quote($a_pool_id, 'integer'));
488
489 $objects = array();
490 while ($row = $ilDB->fetchAssoc($set)) {
491 $objects[] = $row['booking_object_id'];
492 }
493
494 return $objects;
495 }
496
497
502 public function delete()
503 {
505
506 if ($this->id) {
507 $this->deleteFiles();
508
509 return $ilDB->manipulate('DELETE FROM booking_object' .
510 ' WHERE booking_object_id = ' . $ilDB->quote($this->id, 'integer'));
511 }
512 }
513
519 public static function getNrOfItemsForObjects(array $a_obj_ids)
520 {
521 global $DIC;
522
523 $ilDB = $DIC->database();
524
525 $map = array();
526
527 $set = $ilDB->query("SELECT booking_object_id,nr_items" .
528 " FROM booking_object" .
529 " WHERE " . $ilDB->in("booking_object_id", $a_obj_ids, "", "integer"));
530 while ($row = $ilDB->fetchAssoc($set)) {
531 $map[$row["booking_object_id"]] = $row["nr_items"];
532 }
533
534 return $map;
535 }
536
537 public function doClone($a_pool_id, $a_schedule_map = null)
538 {
539 $new_obj = new self();
540 $new_obj->setPoolId($a_pool_id);
541 $new_obj->setTitle($this->getTitle());
542 $new_obj->setDescription($this->getDescription());
543 $new_obj->setNrOfItems($this->getNrOfItems());
544 $new_obj->setFile($this->getFile());
545 $new_obj->setPostText($this->getPostText());
546 $new_obj->setPostFile($this->getPostFile());
547
548 if ($a_schedule_map) {
549 $schedule_id = $this->getScheduleId();
550 if ($schedule_id) {
551 $new_obj->setScheduleId($a_schedule_map[$schedule_id]);
552 }
553 }
554
555 $new_obj->save();
556
557 // files
558 $source = $this->initStorage($this->getId());
559 $target = $new_obj->initStorage($new_obj->getId());
561 }
562
569 public static function lookupPoolId($object_id)
570 {
571 global $DIC;
572
573 $db = $DIC->database();
574 $set = $db->queryF(
575 "SELECT pool_id FROM booking_object " .
576 " WHERE booking_object_id = %s ",
577 array("integer"),
578 array($object_id)
579 );
580 $rec = $db->fetchAssoc($set);
581 return (int) $rec["pool_id"];
582 }
583}
$path
Definition: aliased.php:25
$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.
static getNumberOfObjectsForPool($a_pool_id)
Get number of booking objects for given booking pool id.
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 getObjectsForPool(int $a_pool_id)
Get all booking pool object ids from an specific booking pool.
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.
$target
Definition: test.php:19
$row
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB