ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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  function init()
49  {
50  if (parent::init())
51  {
52  if ($this->ass_id > 0)
53  {
54  $this->submission_path = $this->path."/subm_".$this->ass_id;
55  $this->tmp_path = $this->path."/tmp_".$this->ass_id;
56  $this->feedb_path = $this->path."/feedb_".$this->ass_id;
57  $this->multi_feedback_upload_path = $this->path."/mfb_up_".$this->ass_id;
58  $this->peer_review_upload_path = $this->path."/peer_up_".$this->ass_id;
59  $this->path.= "/ass_".$this->ass_id;
60  }
61  }
62  else
63  {
64  return false;
65  }
66  return true;
67  }
68 
69 
76  protected function getPathPostfix()
77  {
78  return 'exc';
79  }
80 
87  protected function getPathPrefix()
88  {
89  return 'ilExercise';
90  }
91 
96  {
97  return $this->submission_path;
98  }
99 
103  function getTempPath()
104  {
105  return $this->tmp_path;
106  }
107 
111  function getFeedbackPath($a_user_id)
112  {
113  $path = $this->feedb_path."/".$a_user_id;
114  if(!file_exists($path))
115  {
117  }
118  return $path;
119  }
120 
122  {
123  $path = $this->feedb_path."/0";
124  if(!file_exists($path))
125  {
127  }
128  return $path;
129  }
130 
135  function getMultiFeedbackUploadPath($a_user_id)
136  {
137  $path = $this->multi_feedback_upload_path."/".$a_user_id;
138  if(!file_exists($path))
139  {
141  }
142  return $path;
143  }
144 
149  function getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
150  {
151  $path = $this->peer_review_upload_path."/".$a_peer_id."/".$a_giver_id;
152  if((int)$a_crit_id)
153  {
154  $path .= (int)$a_crit_id."/";
155  }
156  if(!file_exists($path))
157  {
159  }
160  return $path;
161  }
162 
169  public function create()
170  {
171  parent::create();
172  if(!file_exists($this->submission_path))
173  {
174  ilUtil::makeDirParents($this->submission_path);
175  }
176  if(!file_exists($this->tmp_path))
177  {
178  ilUtil::makeDirParents($this->tmp_path);
179  }
180  if(!file_exists($this->feedb_path))
181  {
182  ilUtil::makeDirParents($this->feedb_path);
183  }
184  return true;
185  }
186 
190  function getFiles()
191  {
192  $files = array();
193  if (!is_dir($this->path))
194  {
195  return $files;
196  }
197 
198  $dp = opendir($this->path);
199  while($file = readdir($dp))
200  {
201  if(!is_dir($this->path.'/'.$file))
202  {
203  $files[] = array(
204  'name' => $file,
205  'size' => filesize($this->path.'/'.$file),
206  'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->path.'/'.$file))),
207  'fullpath' => $this->path.'/'.$file);
208  }
209  }
210  closedir($dp);
211  $files = ilUtil::sortArray($files, "name", "asc");
212  return $files;
213  }
214 
215 
219 
227  function uploadFile($a_http_post_file, $user_id, $is_unziped = false)
228  {
229  $this->create();
230 
231  // TODO:
232  // CHECK UPLOAD LIMIT
233 
234 
235  //
236  $result = false;
237  if(isset($a_http_post_file) && $a_http_post_file['size'])
238  {
239  $filename = $a_http_post_file['name'];
240 
241  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
243 
244  // replace whitespaces with underscores
245  $filename = preg_replace("/\s/", "_", $filename);
246  // remove all special characters
247  $filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
248 
249  if(!is_dir($savepath = $this->getAbsoluteSubmissionPath()))
250  {
251  ilUtil::makeDir($savepath);
252  }
253  $savepath .= '/' .$user_id;
254  if(!is_dir($savepath))
255  {
256  ilUtil::makeDir($savepath);
257  }
258 
259  // CHECK IF FILE PATH EXISTS
260  if (!is_dir($savepath))
261  {
262  require_once "./Services/Utilities/classes/class.ilUtil.php";
263  #ilUtil::makeDirParents($savepath);
264  ilUtil::makeDir($savepath);
265  }
266  $now = getdate();
267  $prefix = sprintf("%04d%02d%02d%02d%02d%02d", $now["year"], $now["mon"], $now["mday"], $now["hours"],
268  $now["minutes"], $now["seconds"]);
269 
270  if (!$is_unziped)
271  {
272  ilUtil::moveUploadedFile($a_http_post_file["tmp_name"], $a_http_post_file["name"],
273  $savepath . "/" . $prefix . "_" . $filename);
274  }
275  else
276  {
277 
278  rename($a_http_post_file['tmp_name'],
279  $savepath . "/" . $prefix . "_" . $filename);
280  }
281 
282  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
283 
284  if (is_file($savepath . "/" . $prefix . "_" . $filename))
285  {
286  $result = array(
287  "filename" => $prefix . "_" . $filename,
288  "fullname" => $savepath . "/" . $prefix . "_" . $filename,
289  "mimetype" => ilObjMediaObject::getMimeType($savepath . "/" . $prefix . "_" . $filename)
290  );
291  }
292  }
293  return $result;
294  }
295 
299  function getFeedbackFiles($a_user_id)
300  {
301  $files = array();
302 
303  $dir = $this->getFeedbackPath($a_user_id);
304  if (@is_dir($dir))
305  {
306  $dp = opendir($dir);
307  while($file = readdir($dp))
308  {
309  if(!is_dir($this->path.'/'.$file) && substr($file, 0, 1) != ".")
310  {
311  $files[] = $file;
312  }
313  }
314  }
315 
316  return $files;
317  }
318 
322  function countFeedbackFiles($a_user_id)
323  {
324  $fbf = $this->getFeedbackFiles($a_user_id);
325  return count($fbf);
326  }
327 
331  function getAssignmentFilePath($a_file)
332  {
333  return $this->getAbsolutePath()."/".$a_file;
334  }
335 
339  function getFeedbackFilePath($a_user_id, $a_file)
340  {
341  $dir = $this->getFeedbackPath($a_user_id);
342  return $dir."/".$a_file;
343  }
344 
349  function uploadAssignmentFiles($a_files)
350  {
351  if (is_array($a_files["name"]))
352  {
353  foreach ($a_files["name"] as $k => $name)
354  {
355  if ($name != "")
356  {
357  $type = $a_files["type"][$k];
358  $tmp_name = $a_files["tmp_name"][$k];
359  $size = $a_files["size"][$k];
360  ilUtil::moveUploadedFile($tmp_name,
361  basename($name),
362  $this->path.DIRECTORY_SEPARATOR.basename($name),
363  false);
364  }
365  }
366  }
367  }
368 }
369 ?>
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)
print $file
$size
Definition: RandomTest.php:79
uploadFile($a_http_post_file, $user_id, $is_unziped=false)
store delivered file in filesystem
__construct($a_container_id=0, $a_ass_id=0)
Constructor.
$result
getFeedbackFiles($a_user_id)
Get number of feedback files.
getTempPath()
Get submission path.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
getAssignmentFilePath($a_file)
Get path for assignment file.
uploadAssignmentFiles($a_files)
Upload assignment files (e.g.
getFeedbackPath($a_user_id)
Get feedback path.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
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 ...
formatDate($a_date, $a_mode="datetime", $a_omit_seconds=false, $a_relative=TRUE)
format a date according to the user language shortcut for Format::fmtDateTime public ...
static getMimeType($a_file, $a_external=false)
get mime type for file
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.
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.