ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningSequenceFilesystem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const IMG_ABSTRACT = 'abstract';
27 public const IMG_EXTRO = 'extro';
28 public const PATH_PRE = 'LSO';
29 public const PATH_POST = 'Images';
30
31 public function __construct()
32 {
33 parent::__construct(self::STORAGE_WEB, false, 0);
34 if (!is_dir($this->getAbsolutePath())) {
35 $this->create();
36 }
37 }
38
39 public function moveUploaded(
40 string $which,
41 array $file_info,
44 $target = $this->getStoragePathFor(
45 $which,
46 $settings->getObjId(),
47 $this->getSuffix($file_info['name'])
48 );
49 move_uploaded_file($file_info['tmp_name'], $target);
50
51 if ($which === self::IMG_ABSTRACT) {
52 $settings = $settings->withAbstractImage($target);
53 }
54 if ($which === self::IMG_EXTRO) {
55 $settings = $settings->withExtroImage($target);
56 }
57 return $settings;
58 }
59
60
61 public function delete_image(string $which, ilLearningSequenceSettings $settings): ilLearningSequenceSettings
62 {
63 $delete = '';
64 if ($which === self::IMG_ABSTRACT) {
65 $delete = $settings->getAbstractImage();
66 $settings = $settings->withAbstractImage();
67 }
68 if ($which === self::IMG_EXTRO) {
69 $delete = $settings->getExtroImage();
70 $settings = $settings->withExtroImage();
71 }
72 if ($delete !== '' && str_starts_with($delete, $this->getStoragePath())) {
73 $this->deleteFile($delete);
74 }
75 return $settings;
76 }
77
78 public function getStoragePathFor(string $which, int $obj_id, string $suffix): string
79 {
80 return $this->getStoragePath()
81 . $which
82 . '_'
83 . $obj_id
84 . '.'
85 . $suffix;
86 }
87
88 public function getSuffix(string $file_name): string
89 {
90 return pathinfo($file_name, PATHINFO_EXTENSION);
91 }
92
93 protected function getStoragePath(): string
94 {
95 return $this->getAbsolutePath() . '/';
96 }
97
101 protected function getPathPrefix(): string
102 {
103 return self::PATH_PRE;
104 }
105
109 protected function getPathPostfix(): string
110 {
111 return self::PATH_POST;
112 }
113}
getAbsolutePath()
Calculates the full path on the filesystem.
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
getStoragePathFor(string $which, int $obj_id, string $suffix)
moveUploaded(string $which, array $file_info, ilLearningSequenceSettings $settings)
Settings for an LSO (like abstract, extro)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc