ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceFilesystem.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
11{
12 const IMG_ABSTRACT = 'abstract';
13 const IMG_EXTRO = 'extro';
14
15 public function __construct()
16 {
17 parent::__construct(self::STORAGE_WEB, false, 0);
18 if (!is_dir($this->getAbsolutePath())) {
19 $this->create();
20 }
21 }
22
23 public function moveUploaded(
24 string $which,
25 array $file_info,
29 $which,
30 $settings->getObjId(),
31 $this->getSuffix($file_info['name'])
32 );
33 move_uploaded_file($file_info['tmp_name'], $target);
34
35 if ($which === self::IMG_ABSTRACT) {
36 $settings = $settings->withAbstractImage($target);
37 }
38 if ($which === self::IMG_EXTRO) {
39 $settings = $settings->withExtroImage($target);
40 }
41 return $settings;
42 }
43
44
45 public function delete_image(string $which, ilLearningSequenceSettings $settings)
46 {
47 if ($which === self::IMG_ABSTRACT) {
48 $delete = $settings->getAbstractImage();
49 $settings = $settings->withAbstractImage(null);
50 }
51 if ($which === self::IMG_EXTRO) {
52 $delete = $settings->getExtroImage();
53 $settings = $settings->withExtroImage(null);
54 }
55
56 $this->deleteFile($delete);
57 return $settings;
58 }
59
60 public function getStoragePathFor(string $which, int $obj_id, string $suffix)
61 {
62 return $this->getStoragePath()
63 . $which
64 . '_'
65 . (string) $obj_id
66 . '.'
67 . $suffix;
68 }
69
70 public function getSuffix(string $file_name) : string
71 {
72 return pathinfo($file_name, PATHINFO_EXTENSION);
73 }
74
78 protected function getStoragePath()
79 {
80 return $this->getAbsolutePath() . '/';
81 }
82
86 protected function getPathPrefix()
87 {
88 return 'LSO';
89 }
90
94 protected function getPathPostfix()
95 {
96 return 'Images';
97 }
98}
An exception for terminatinating execution or to throw for unit testing.
getAbsolutePath()
Get absolute path of storage directory.
getPathPostfix()
Get directory name.E.g for files => file Only relative path, no trailing slash '_<obj_id>' will be ap...
delete_image(string $which, ilLearningSequenceSettings $settings)
getPathPrefix()
Get path prefix.Prefix that will be prepended to the path No trailing slash. E.g ilFiles for files@ab...
getStoragePathFor(string $which, int $obj_id, string $suffix)
moveUploaded(string $which, array $file_info, ilLearningSequenceSettings $settings)
Settings for an LSO (like abstract, extro)
$target
Definition: test.php:19