ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
24 include_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  public function init()
47  {
48  if (parent::init()) {
49  if ($this->ass_id > 0) {
50  $this->submission_path = $this->path . "/subm_" . $this->ass_id;
51  $this->tmp_path = $this->path . "/tmp_" . $this->ass_id;
52  $this->feedb_path = $this->path . "/feedb_" . $this->ass_id;
53  $this->multi_feedback_upload_path = $this->path . "/mfb_up_" . $this->ass_id;
54  $this->peer_review_upload_path = $this->path . "/peer_up_" . $this->ass_id;
55  $this->path .= "/ass_" . $this->ass_id;
56  }
57  } else {
58  return false;
59  }
60  return true;
61  }
62 
63 
70  protected function getPathPostfix()
71  {
72  return 'exc';
73  }
74 
81  protected function getPathPrefix()
82  {
83  return 'ilExercise';
84  }
85 
89  public function getAbsoluteSubmissionPath()
90  {
91  return $this->submission_path;
92  }
93 
97  public function getTempPath()
98  {
99  return $this->tmp_path;
100  }
101 
105  public function getFeedbackPath($a_user_id)
106  {
107  $path = $this->feedb_path . "/" . $a_user_id;
108  if (!file_exists($path)) {
110  }
111  return $path;
112  }
113 
114  public function getGlobalFeedbackPath()
115  {
116  $path = $this->feedb_path . "/0";
117  if (!file_exists($path)) {
119  }
120  return $path;
121  }
122 
127  public function getMultiFeedbackUploadPath($a_user_id)
128  {
129  $path = $this->multi_feedback_upload_path . "/" . $a_user_id;
130  if (!file_exists($path)) {
132  }
133  return $path;
134  }
135 
140  public function getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
141  {
142  $path = $this->peer_review_upload_path . "/" . $a_peer_id . "/" . $a_giver_id;
143 
144  if ((int) $a_crit_id) {
145  $path .= (int) $a_crit_id . "/";
146  }
147  if (!file_exists($path)) {
149  }
150  return $path;
151  }
152 
159  public function create()
160  {
161  parent::create();
162  if (!file_exists($this->submission_path)) {
163  ilUtil::makeDirParents($this->submission_path);
164  }
165  if (!file_exists($this->tmp_path)) {
166  ilUtil::makeDirParents($this->tmp_path);
167  }
168  if (!file_exists($this->feedb_path)) {
169  ilUtil::makeDirParents($this->feedb_path);
170  }
171  return true;
172  }
173 
177  public function getFiles()
178  {
179  $files = array();
180  if (!is_dir($this->path)) {
181  return $files;
182  }
183 
184  $dp = opendir($this->path);
185  while ($file = readdir($dp)) {
186  if (!is_dir($this->path . '/' . $file)) {
187  $files[] = array(
188  'name' => $file,
189  'size' => filesize($this->path . '/' . $file),
190  'ctime' => filectime($this->path . '/' . $file),
191  'fullpath' => $this->path . '/' . $file);
192  }
193  }
194  closedir($dp);
195  $files = ilUtil::sortArray($files, "name", "asc");
196  return $files;
197  }
198 
199 
203 
211  public function uploadFile($a_http_post_file, $user_id, $is_unziped = false)
212  {
213  $this->create();
214 
215  // TODO:
216  // CHECK UPLOAD LIMIT
217  //
218  $result = false;
219  if (isset($a_http_post_file) && $a_http_post_file['size']) {
220  $filename = $a_http_post_file['name'];
221  // replace whitespaces with underscores
222  $filename = preg_replace("/\s/", "_", $filename);
223  // remove all special characters
224  $filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
225 
226  if (!is_dir($savepath = $this->getAbsoluteSubmissionPath())) {
227  ilUtil::makeDir($savepath);
228  }
229  $savepath .= '/' . $user_id;
230  if (!is_dir($savepath)) {
231  ilUtil::makeDir($savepath);
232  }
233 
234  // CHECK IF FILE PATH EXISTS
235  if (!is_dir($savepath)) {
236  ilUtil::makeDir($savepath);
237  }
238  $now = getdate();
239  $prefix = sprintf(
240  "%04d%02d%02d%02d%02d%02d",
241  $now["year"],
242  $now["mon"],
243  $now["mday"],
244  $now["hours"],
245  $now["minutes"],
246  $now["seconds"]
247  );
248 
249  if (!$is_unziped) {
250  //move_uploaded_file($a_http_post_file["tmp_name"], $savepath . $prefix . "_" . $filename);
251  ilUtil::moveUploadedFile(
252  $a_http_post_file["tmp_name"],
253  $a_http_post_file["name"],
254  $savepath . "/" . $prefix . "_" . $filename
255  );
256  } else {
257  rename(
258  $a_http_post_file['tmp_name'],
259  $savepath . "/" . $prefix . "_" . $filename
260  );
261  }
262 
263  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
264 
265  if (is_file($savepath . "/" . $prefix . "_" . $filename)) {
266  $result = array(
267  "filename" => $prefix . "_" . $filename,
268  "fullname" => $savepath . "/" . $prefix . "_" . $filename,
269  "mimetype" => ilObjMediaObject::getMimeType($savepath . "/" . $prefix . "_" . $filename)
270  );
271  }
272  }
273  return $result;
274  }
275 
279  public function getFeedbackFiles($a_user_id)
280  {
281  $files = array();
282 
283  $dir = $this->getFeedbackPath($a_user_id);
284  if (@is_dir($dir)) {
285  $dp = opendir($dir);
286  while ($file = readdir($dp)) {
287  if (!is_dir($this->path . '/' . $file) && substr($file, 0, 1) != ".") {
288  $files[] = $file;
289  }
290  }
291  }
292 
293  return $files;
294  }
295 
299  public function countFeedbackFiles($a_user_id)
300  {
301  $fbf = $this->getFeedbackFiles($a_user_id);
302  return count($fbf);
303  }
304 
308  public function getAssignmentFilePath($a_file)
309  {
310  return $this->getAbsolutePath() . "/" . $a_file;
311  }
312 
316  public function getFeedbackFilePath($a_user_id, $a_file)
317  {
318  $dir = $this->getFeedbackPath($a_user_id);
319  return $dir . "/" . $a_file;
320  }
321 
326  public function uploadAssignmentFiles($a_files)
327  {
328  if (is_array($a_files["name"])) {
329  foreach ($a_files["name"] as $k => $name) {
330  if ($name != "") {
331  $type = $a_files["type"][$k];
332  $tmp_name = $a_files["tmp_name"][$k];
333  $size = $a_files["size"][$k];
334  ilUtil::moveUploadedFile(
335  $tmp_name,
336  basename($name),
337  $this->path . DIRECTORY_SEPARATOR . basename($name),
338  false
339  );
340  }
341  }
342  }
343  }
344 }
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.
$size
Definition: RandomTest.php:84
static getMimeType($a_file, $a_external=null)
get mime type for file
$files
Definition: metarefresh.php:49
$result
getFeedbackPath($a_user_id)
Get feedback path.
getPathPrefix()
Implementation of abstract method.
$type
getPathPostfix()
Implementation of abstract method.
getFeedbackFiles($a_user_id)
Get number of feedback files.
getAbsoluteSubmissionPath()
Get submission path.
countFeedbackFiles($a_user_id)
Count number of feedback files for a user.
init()
Append ass_<ass_id> to path (assignment id)
__construct($a_container_id=0, $a_ass_id=0)
Constructor.
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.
uploadAssignmentFiles($a_files)
Upload assignment files (e.g.
$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 ...
uploadFile($a_http_post_file, $user_id, $is_unziped=false)
store delivered file in filesystem
getAssignmentFilePath($a_file)
Get path for assignment file.
getMultiFeedbackUploadPath($a_user_id)
Get multi feedback upload path (each uploader handled in a separate path)
while(count($oldTaskList) > 0) foreach(array_keys($newTaskList) as $task) init()
Definition: build.php:77
getFeedbackFilePath($a_user_id, $a_file)
Get path for feedback file.