ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFSStorageExercise.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('Services/FileSystem/classes/class.ilFileSystemStorage.php');
33 {
39  public function __construct($a_container_id = 0, $a_ass_id = 0)
40  {
41  $this->ass_id = $a_ass_id;
42  parent::__construct(self::STORAGE_DATA, true, $a_container_id);
43  }
44 
48  public function init()
49  {
50  if (parent::init()) {
51  if ($this->ass_id > 0) {
52  $this->submission_path = $this->path . "/subm_" . $this->ass_id;
53  $this->tmp_path = $this->path . "/tmp_" . $this->ass_id;
54  $this->feedb_path = $this->path . "/feedb_" . $this->ass_id;
55  $this->multi_feedback_upload_path = $this->path . "/mfb_up_" . $this->ass_id;
56  $this->peer_review_upload_path = $this->path . "/peer_up_" . $this->ass_id;
57  $this->path .= "/ass_" . $this->ass_id;
58  }
59  } else {
60  return false;
61  }
62  return true;
63  }
64 
65 
72  protected function getPathPostfix()
73  {
74  return 'exc';
75  }
76 
83  protected function getPathPrefix()
84  {
85  return 'ilExercise';
86  }
87 
91  public function getAbsoluteSubmissionPath()
92  {
93  return $this->submission_path;
94  }
95 
99  public function getTempPath()
100  {
101  return $this->tmp_path;
102  }
103 
107  public function getFeedbackPath($a_user_id)
108  {
109  $path = $this->feedb_path . "/" . $a_user_id;
110  if (!file_exists($path)) {
112  }
113  return $path;
114  }
115 
116  public function getGlobalFeedbackPath()
117  {
118  $path = $this->feedb_path . "/0";
119  if (!file_exists($path)) {
121  }
122  return $path;
123  }
124 
129  public function getMultiFeedbackUploadPath($a_user_id)
130  {
131  $path = $this->multi_feedback_upload_path . "/" . $a_user_id;
132  if (!file_exists($path)) {
134  }
135  return $path;
136  }
137 
142  public function getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
143  {
144  $path = $this->peer_review_upload_path . "/" . $a_peer_id . "/" . $a_giver_id . "/";
145 
146  if ((int) $a_crit_id) {
147  $path .= (int) $a_crit_id . "/";
148  }
149  if (!file_exists($path)) {
151  }
152  return $path;
153  }
154 
161  public function create()
162  {
163  parent::create();
164  if (!file_exists($this->submission_path)) {
165  ilUtil::makeDirParents($this->submission_path);
166  }
167  if (!file_exists($this->tmp_path)) {
168  ilUtil::makeDirParents($this->tmp_path);
169  }
170  if (!file_exists($this->feedb_path)) {
171  ilUtil::makeDirParents($this->feedb_path);
172  }
173  return true;
174  }
175 
179  public function getFiles()
180  {
181  $files = array();
182  if (!is_dir($this->path)) {
183  return $files;
184  }
185 
186  $dp = opendir($this->path);
187  while ($file = readdir($dp)) {
188  if (!is_dir($this->path . '/' . $file)) {
189  $files[] = array(
190  'name' => $file,
191  'size' => filesize($this->path . '/' . $file),
192  'ctime' => filectime($this->path . '/' . $file),
193  'fullpath' => $this->path . '/' . $file);
194  }
195  }
196  closedir($dp);
197  $files = ilUtil::sortArray($files, "name", "asc");
198  return $files;
199  }
200 
201 
205 
213  public function uploadFile($a_http_post_file, $user_id, $is_unziped = false)
214  {
215  $this->create();
216  // TODO:
217  // CHECK UPLOAD LIMIT
218 
219 
220  //
221  $result = false;
222  if (isset($a_http_post_file) && $a_http_post_file['size']) {
223  $filename = $a_http_post_file['name'];
224 
225  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
227 
228  // replace whitespaces with underscores
229  $filename = preg_replace("/\s/", "_", $filename);
230  // remove all special characters
231  $filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
232 
233  if (!is_dir($savepath = $this->getAbsoluteSubmissionPath())) {
234  ilUtil::makeDir($savepath);
235  }
236  $savepath .= '/' . $user_id;
237  if (!is_dir($savepath)) {
238  ilUtil::makeDir($savepath);
239  }
240 
241  // CHECK IF FILE PATH EXISTS
242  if (!is_dir($savepath)) {
243  ilUtil::makeDir($savepath);
244  }
245  $now = getdate();
246  $prefix = sprintf(
247  "%04d%02d%02d%02d%02d%02d",
248  $now["year"],
249  $now["mon"],
250  $now["mday"],
251  $now["hours"],
252  $now["minutes"],
253  $now["seconds"]
254  );
255 
256  if (!$is_unziped) {
257  ilUtil::moveUploadedFile(
258  $a_http_post_file["tmp_name"],
259  $prefix . "_" . $filename,
260  $savepath . "/" . $prefix . "_" . $filename
261  );
262  } else {
263  rename(
264  $a_http_post_file['tmp_name'],
265  $savepath . "/" . $prefix . "_" . $filename
266  );
267  }
268 
269  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
270  if (is_file($savepath . "/" . $prefix . "_" . $filename)) {
271  $result = array(
272  "filename" => $prefix . "_" . $filename,
273  "fullname" => $savepath . "/" . $prefix . "_" . $filename,
274  "mimetype" => ilObjMediaObject::getMimeType($savepath . "/" . $prefix . "_" . $filename)
275  );
276  }
277  }
278  return $result;
279  }
280 
284  public function getFeedbackFiles($a_user_id)
285  {
286  $files = array();
287 
288  $dir = $this->getFeedbackPath($a_user_id);
289  if (@is_dir($dir)) {
290  $dp = opendir($dir);
291  while ($file = readdir($dp)) {
292  if (!is_dir($this->path . '/' . $file) && substr($file, 0, 1) != ".") {
293  $files[] = $file;
294  }
295  }
296  }
297 
298  return $files;
299  }
300 
304  public function countFeedbackFiles($a_user_id)
305  {
306  $fbf = $this->getFeedbackFiles($a_user_id);
307  return count($fbf);
308  }
309 
313  public function getAssignmentFilePath($a_file)
314  {
315  return $this->getAbsolutePath() . "/" . $a_file;
316  }
317 
321  public function getFeedbackFilePath($a_user_id, $a_file)
322  {
323  $dir = $this->getFeedbackPath($a_user_id);
324  return $dir . "/" . $a_file;
325  }
326 
331  public function uploadAssignmentFiles($a_files)
332  {
333  if (is_array($a_files["name"])) {
334  foreach ($a_files["name"] as $k => $name) {
335  if ($name != "") {
336  $type = $a_files["type"][$k];
337  $tmp_name = $a_files["tmp_name"][$k];
338  $size = $a_files["size"][$k];
339  ilUtil::moveUploadedFile(
340  $tmp_name,
341  basename($name),
342  $this->path . DIRECTORY_SEPARATOR . basename($name),
343  false
344  );
345  }
346  }
347  }
348  }
349 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getAbsoluteSubmissionPath()
Get submission path.
init()
Append ass_<ass_id> to path (assignment id)
$size
Definition: RandomTest.php:84
static getMimeType($a_file, $a_external=null)
get mime type for file
uploadFile($a_http_post_file, $user_id, $is_unziped=false)
store delivered file in filesystem
$files
Definition: metarefresh.php:49
__construct($a_container_id=0, $a_ass_id=0)
Constructor.
$result
$type
getFeedbackFiles($a_user_id)
Get number of feedback files.
getTempPath()
Get submission path.
getAssignmentFilePath($a_file)
Get path for assignment file.
uploadAssignmentFiles($a_files)
Upload assignment files (e.g.
getFeedbackPath($a_user_id)
Get feedback path.
getFiles()
Get assignment files.
getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
Get pear review upload path (each peer handled in a separate path)
getAbsolutePath()
Get absolute path of storage directory.
$filename
Definition: buildRTE.php:89
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
getMultiFeedbackUploadPath($a_user_id)
Get multi feedback upload path (each uploader handled in a separate path)
countFeedbackFiles($a_user_id)
Count number of feedback files for a user.
while(count($oldTaskList) > 0) foreach(array_keys($newTaskList) as $task) init()
Definition: build.php:77
getPathPostfix()
Implementation of abstract method.
static getValidFilename($a_filename)
Get valid filename.
getFeedbackFilePath($a_user_id, $a_file)
Get path for feedback file.
getPathPrefix()
Implementation of abstract method.