ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilIndividualAssessmentFileStorage.php
Go to the documentation of this file.
1 <?php
2 require_once("Modules/IndividualAssessment/interfaces/FileStorage/interface.IndividualAssessmentFileStorage.php");
3 include_once('Services/FileSystem/classes/class.ilFileSystemStorage.php');
11 {
12  public static function getInstance($a_container_id = 0)
13  {
14  return new self(self::STORAGE_WEB, true, $a_container_id);
15  }
16 
22  protected function getPathPostfix()
23  {
24  return 'iass';
25  }
26 
32  protected function getPathPrefix()
33  {
34  return 'IASS';
35  }
36 
42  public function isEmpty()
43  {
44  $files = $this->readDir();
45 
46  return (count($files) == 0) ? true : false;
47  }
48 
54  public function setUserId($user_id)
55  {
56  $this->user_id = $user_id;
57  }
58 
64  public function create()
65  {
66  if (!file_exists($this->getAbsolutePath())) {
68  }
69  return true;
70  }
71 
77  public function getAbsolutePath()
78  {
79  $path = parent::getAbsolutePath();
80 
81  if ($this->user_id) {
82  $path .= "/user_" . $this->user_id;
83  }
84 
85  return $path;
86  }
87 
93  public function readDir()
94  {
95  if (!is_dir($this->getAbsolutePath())) {
96  $this->create();
97  }
98 
99  $fh = opendir($this->getAbsolutePath());
100  $files = array();
101  while ($file = readdir($fh)) {
102  if ($file != "." && $file != ".." && !is_dir($this->getAbsolutePath() . "/" . $file)) {
103  $files[] = $file;
104  }
105  }
106  closedir($fh);
107 
108  return $files;
109  }
110 
118  public function uploadFile($file)
119  {
120  $path = $this->getAbsolutePath();
121 
122  $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $file["name"]);
123  $new_file = $path . "/" . $clean_name;
124 
125  ilUtil::moveUploadedFile(
126  $file["tmp_name"],
127  $clean_name, // This parameter does not do a thing
128  $new_file
129  );
130 
131  return true;
132  }
133 
137  public function deleteCurrentFile()
138  {
139  $files = $this->readDir();
140  $this->deleteFile($this->getAbsolutePath() . "/" . $files[0]);
141  }
142 
148  public function getFilePath()
149  {
150  $files = $this->readDir();
151  return $this->getAbsolutePath() . "/" . $files[0];
152  }
153 
159  public function deleteFileByName($file_name)
160  {
161  $this->deleteFile($this->getAbsolutePath() . "/" . $file_name);
162  }
163 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$files
Definition: metarefresh.php:49
setUserId($user_id)
Set the user id for an extra folder of each participant in the IA.
isEmpty()
Is the webdir folder for this IA empty.
getPathPostfix()
part of the folder structure in ILIAS webdir.
getPathPrefix()
part of the folder structure in ILIAS webdir.
Handles the fileupload and folder creation for files uploaded in grading form.
deleteFile($a_abs_name)
Delete file.