ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilIndividualAssessmentFileStorage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 public const PATH_POSTFIX = "iass";
29 public const PATH_PREFIX = "IASS";
30
31 protected ?int $user_id = null;
32
33 public static function getInstance(int $container_id = 0): ilIndividualAssessmentFileStorage
34 {
35 return new self(self::STORAGE_WEB, true, $container_id);
36 }
37
41 protected function getPathPostfix(): string
42 {
43 return self::PATH_POSTFIX;
44 }
45
49 protected function getPathPrefix(): string
50 {
51 return self::PATH_PREFIX;
52 }
53
57 public function setUserId(int $user_id): void
58 {
59 $this->user_id = $user_id;
60 }
61
65 public function create(): void
66 {
67 if (!file_exists($this->getAbsolutePath())) {
69 }
70 }
71
75 public function getAbsolutePath(): string
76 {
77 $path = parent::getAbsolutePath();
78
79 if ($this->user_id) {
80 $path .= "/user_" . $this->user_id;
81 }
82
83 return $path;
84 }
85
91 public function readDir(): array
92 {
93 if (!is_dir($this->getAbsolutePath())) {
94 $this->create();
95 }
96
97 $fh = opendir($this->getAbsolutePath());
98 $files = array();
99 while ($file = readdir($fh)) {
100 if ($file != "." && $file != ".." && !is_dir($this->getAbsolutePath() . "/" . $file)) {
101 $files[] = $file;
102 }
103 }
104 closedir($fh);
105
106 return $files;
107 }
108
112 public function uploadFile(UploadResult $file): string
113 {
114 $path = $this->getAbsolutePath();
115
116 $clean_name = ilFileUtils::getValidFilename($file->getName());
117 $new_file = $path . "/" . $clean_name;
118
120 $file->getPath(),
121 $clean_name, // This parameter does not do a thing
122 $new_file
123 );
124
125 return $clean_name;
126 }
127
131 public function deleteAllFilesBut(?string $filename): void
132 {
133 $files = $this->readDir();
134 foreach ($files as $file) {
135 if ($file === $filename) {
136 continue;
137 }
138 $this->deleteFile($this->getAbsolutePath() . "/" . $file);
139 }
140 }
141}
$filename
Definition: buildRTE.php:78
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static getValidFilename(string $a_filename)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
getPathPostfix()
part of the folder structure in ILIAS webdir.
getPathPrefix()
part of the folder structure in ILIAS webdir.
setUserId(int $user_id)
Set the user id for an extra folder of each participant in the IA.
deleteAllFilesBut(?string $filename)
Delete the existing file.