ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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/FileSystemStorage/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->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 
125  public function create()
126  {
127  parent::create();
128  if(!file_exists($this->submission_path))
129  {
130  ilUtil::makeDirParents($this->submission_path);
131  }
132  if(!file_exists($this->tmp_path))
133  {
134  ilUtil::makeDirParents($this->tmp_path);
135  }
136  if(!file_exists($this->feedb_path))
137  {
138  ilUtil::makeDirParents($this->feedb_path);
139  }
140  return true;
141  }
142 
146  function getFiles()
147  {
148  $files = array();
149  if (!is_dir($this->path))
150  {
151  return $files;
152  }
153 
154  $dp = opendir($this->path);
155  while($file = readdir($dp))
156  {
157  if(!is_dir($this->path.'/'.$file))
158  {
159  $files[] = array(
160  'name' => $file,
161  'size' => filesize($this->path.'/'.$file),
162  'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->path.'/'.$file))),
163  'fullpath' => $this->path.'/'.$file);
164  }
165  }
166  closedir($dp);
167  $files = ilUtil::sortArray($files, "name", "asc");
168  return $files;
169  }
170 
171 
175 
183  function deliverFile($a_http_post_file, $user_id, $is_unziped = false)
184  {
185  $this->create();
186 
187  // TODO:
188  // CHECK UPLOAD LIMIT
189  //
190  $result = false;
191  if(isset($a_http_post_file) && $a_http_post_file['size'])
192  {
193  $filename = $a_http_post_file['name'];
194  // replace whitespaces with underscores
195  $filename = preg_replace("/\s/", "_", $filename);
196  // remove all special characters
197  $filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
198 
199  if(!is_dir($savepath = $this->getAbsoluteSubmissionPath()))
200  {
201  ilUtil::makeDir($savepath);
202  }
203  $savepath .= '/' .$user_id;
204  if(!is_dir($savepath))
205  {
206  ilUtil::makeDir($savepath);
207  }
208 
209  // CHECK IF FILE PATH EXISTS
210  if (!is_dir($savepath))
211  {
212  require_once "./Services/Utilities/classes/class.ilUtil.php";
213  #ilUtil::makeDirParents($savepath);
214  ilUtil::makeDir($savepath);
215  }
216  $now = getdate();
217  $prefix = sprintf("%04d%02d%02d%02d%02d%02d", $now["year"], $now["mon"], $now["mday"], $now["hours"],
218  $now["minutes"], $now["seconds"]);
219 
220  if (!$is_unziped)
221  {
222  //move_uploaded_file($a_http_post_file["tmp_name"], $savepath . $prefix . "_" . $filename);
223  ilUtil::moveUploadedFile($a_http_post_file["tmp_name"], $a_http_post_file["name"],
224  $savepath . "/" . $prefix . "_" . $filename);
225  }
226  else
227  {
228 
229  rename($a_http_post_file['tmp_name'],
230  $savepath . "/" . $prefix . "_" . $filename);
231  }
232 
233  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
234 
235  if (is_file($savepath . "/" . $prefix . "_" . $filename))
236  {
237  $result = array(
238  "filename" => $prefix . "_" . $filename,
239  "fullname" => $savepath . "/" . $prefix . "_" . $filename,
240  "mimetype" => ilObjMediaObject::getMimeType($savepath . "/" . $prefix . "_" . $filename)
241  );
242  }
243  }
244  return $result;
245  }
246 
250  function getFeedbackFiles($a_user_id)
251  {
252  $dir = $this->getFeedbackPath($a_user_id);
253  $files = array();
254  if (@is_dir($dir))
255  {
256  $dp = opendir($dir);
257  while($file = readdir($dp))
258  {
259  if(!is_dir($this->path.'/'.$file) && substr($file, 0, 1) != ".")
260  {
261  $files[] = $file;
262  }
263  }
264  }
265  return $files;
266  }
267 
271  function countFeedbackFiles($a_user_id)
272  {
273  $fbf = $this->getFeedbackFiles($a_user_id);
274  return count($fbf);
275  }
276 
280  function getAssignmentFilePath($a_file)
281  {
282  return $this->getAbsolutePath()."/".$a_file;
283  }
284 
288  function getFeedbackFilePath($a_user_id, $a_file)
289  {
290  $dir = $this->getFeedbackPath($a_user_id);
291  return $dir."/".$a_file;
292  }
293 
298  function uploadAssignmentFiles($a_files)
299  {
300  if (is_array($a_files["name"]))
301  {
302  foreach ($a_files["name"] as $k => $name)
303  {
304  if ($name != "")
305  {
306  $type = $a_files["type"][$k];
307  $tmp_name = $a_files["tmp_name"][$k];
308  $size = $a_files["size"][$k];
309  ilUtil::moveUploadedFile($tmp_name,
310  basename($name),
311  $this->path.DIRECTORY_SEPARATOR.basename($name),
312  false);
313  }
314  }
315  }
316  }
317 }
318 ?>