ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilFSStorageExercise5069.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
24include_once('Services/Migration/DBUpdate_5069/classes/class.ilFileSystemStorage5069.php');
31{
37 public function __construct($a_container_id = 0, $a_ass_id = 0)
38 {
39 $this->ass_id = $a_ass_id;
40 parent::__construct(self::STORAGE_DATA,true,$a_container_id);
41 }
42
46 function init()
47 {
48 if (parent::init())
49 {
50 if ($this->ass_id > 0)
51 {
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 }
60 else
61 {
62 return false;
63 }
64 return true;
65 }
66
67
74 protected function getPathPostfix()
75 {
76 return 'exc';
77 }
78
85 protected function getPathPrefix()
86 {
87 return 'ilExercise';
88 }
89
94 {
95 return $this->submission_path;
96 }
97
101 function getTempPath()
102 {
103 return $this->tmp_path;
104 }
105
109 function getFeedbackPath($a_user_id)
110 {
111 $path = $this->feedb_path."/".$a_user_id;
112 if(!file_exists($path))
113 {
115 }
116 return $path;
117 }
118
120 {
121 $path = $this->feedb_path."/0";
122 if(!file_exists($path))
123 {
125 }
126 return $path;
127 }
128
133 function getMultiFeedbackUploadPath($a_user_id)
134 {
135 $path = $this->multi_feedback_upload_path."/".$a_user_id;
136 if(!file_exists($path))
137 {
139 }
140 return $path;
141 }
142
147 function getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
148 {
149 $path = $this->peer_review_upload_path."/".$a_peer_id."/".$a_giver_id;
150
151 if((int)$a_crit_id)
152 {
153 $path .= (int)$a_crit_id."/";
154 }
155 if(!file_exists($path))
156 {
158 }
159 return $path;
160 }
161
168 public function create()
169 {
170 parent::create();
171 if(!file_exists($this->submission_path))
172 {
173 ilUtil::makeDirParents($this->submission_path);
174 }
175 if(!file_exists($this->tmp_path))
176 {
177 ilUtil::makeDirParents($this->tmp_path);
178 }
179 if(!file_exists($this->feedb_path))
180 {
181 ilUtil::makeDirParents($this->feedb_path);
182 }
183 return true;
184 }
185
189 function getFiles()
190 {
191 $files = array();
192 if (!is_dir($this->path))
193 {
194 return $files;
195 }
196
197 $dp = opendir($this->path);
198 while($file = readdir($dp))
199 {
200 if(!is_dir($this->path.'/'.$file))
201 {
202 $files[] = array(
203 'name' => $file,
204 'size' => filesize($this->path.'/'.$file),
205 'ctime' => filectime($this->path.'/'.$file),
206 'fullpath' => $this->path.'/'.$file);
207 }
208 }
209 closedir($dp);
210 $files = ilUtil::sortArray($files, "name", "asc");
211 return $files;
212 }
213
214
218
226 function uploadFile($a_http_post_file, $user_id, $is_unziped = false)
227 {
228 $this->create();
229
230 // TODO:
231 // CHECK UPLOAD LIMIT
232 //
233 $result = false;
234 if(isset($a_http_post_file) && $a_http_post_file['size'])
235 {
236 $filename = $a_http_post_file['name'];
237 // replace whitespaces with underscores
238 $filename = preg_replace("/\s/", "_", $filename);
239 // remove all special characters
240 $filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
241
242 if(!is_dir($savepath = $this->getAbsoluteSubmissionPath()))
243 {
244 ilUtil::makeDir($savepath);
245 }
246 $savepath .= '/' .$user_id;
247 if(!is_dir($savepath))
248 {
249 ilUtil::makeDir($savepath);
250 }
251
252 // CHECK IF FILE PATH EXISTS
253 if (!is_dir($savepath))
254 {
255 ilUtil::makeDir($savepath);
256 }
257 $now = getdate();
258 $prefix = sprintf("%04d%02d%02d%02d%02d%02d", $now["year"], $now["mon"], $now["mday"], $now["hours"],
259 $now["minutes"], $now["seconds"]);
260
261 if (!$is_unziped)
262 {
263 //move_uploaded_file($a_http_post_file["tmp_name"], $savepath . $prefix . "_" . $filename);
264 ilUtil::moveUploadedFile($a_http_post_file["tmp_name"], $a_http_post_file["name"],
265 $savepath . "/" . $prefix . "_" . $filename);
266 }
267 else
268 {
269
270 rename($a_http_post_file['tmp_name'],
271 $savepath . "/" . $prefix . "_" . $filename);
272 }
273
274 require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
275
276 if (is_file($savepath . "/" . $prefix . "_" . $filename))
277 {
278 $result = array(
279 "filename" => $prefix . "_" . $filename,
280 "fullname" => $savepath . "/" . $prefix . "_" . $filename,
281 "mimetype" => ilObjMediaObject::getMimeType($savepath . "/" . $prefix . "_" . $filename)
282 );
283 }
284 }
285 return $result;
286 }
287
291 function getFeedbackFiles($a_user_id)
292 {
293 $files = array();
294
295 $dir = $this->getFeedbackPath($a_user_id);
296 if (@is_dir($dir))
297 {
298 $dp = opendir($dir);
299 while($file = readdir($dp))
300 {
301 if(!is_dir($this->path.'/'.$file) && substr($file, 0, 1) != ".")
302 {
303 $files[] = $file;
304 }
305 }
306 }
307
308 return $files;
309 }
310
314 function countFeedbackFiles($a_user_id)
315 {
316 $fbf = $this->getFeedbackFiles($a_user_id);
317 return count($fbf);
318 }
319
323 function getAssignmentFilePath($a_file)
324 {
325 return $this->getAbsolutePath()."/".$a_file;
326 }
327
331 function getFeedbackFilePath($a_user_id, $a_file)
332 {
333 $dir = $this->getFeedbackPath($a_user_id);
334 return $dir."/".$a_file;
335 }
336
341 function uploadAssignmentFiles($a_files)
342 {
343 if (is_array($a_files["name"]))
344 {
345 foreach ($a_files["name"] as $k => $name)
346 {
347 if ($name != "")
348 {
349 $type = $a_files["type"][$k];
350 $tmp_name = $a_files["tmp_name"][$k];
351 $size = $a_files["size"][$k];
352 ilUtil::moveUploadedFile($tmp_name,
353 basename($name),
354 $this->path.DIRECTORY_SEPARATOR.basename($name),
355 false);
356 }
357 }
358 }
359 }
360}
361?>
sprintf('%.4f', $callTime)
$result
$size
Definition: RandomTest.php:79
$files
Definition: add-vimline.php:18
An exception for terminatinating execution or to throw for unit testing.
init()
Append ass_<ass_id> to path (assignment id)
getFeedbackPath($a_user_id)
Get feedback path.
getFeedbackFilePath($a_user_id, $a_file)
Get path for feedback file.
uploadAssignmentFiles($a_files)
Upload assignment files (e.g.
uploadFile($a_http_post_file, $user_id, $is_unziped=false)
store delivered file in filesystem
countFeedbackFiles($a_user_id)
Count number of feedback files for a user.
getAssignmentFilePath($a_file)
Get path for assignment file.
getMultiFeedbackUploadPath($a_user_id)
Get multi feedback upload path (each uploader handled in a separate path)
getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
Get pear review upload path (each peer handled in a separate path)
getPathPrefix()
Implementation of abstract method.
getFeedbackFiles($a_user_id)
Get number of feedback files.
__construct($a_container_id=0, $a_ass_id=0)
Constructor.
getAbsoluteSubmissionPath()
Get submission path.
getPathPostfix()
Implementation of abstract method.
getAbsolutePath()
Get absolute path of storage directory.
static getMimeType($a_file, $a_external=false)
get mime type for file
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
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.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file