ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilFileDataImportGroup.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 require_once("./Services/FileSystem/classes/class.ilFileDataImport.php");
13 
15 {
22 
23  var $files;
24  var $xml_file;
25 
26 
35  {
36  define('GROUP_IMPORT_PATH','group');
37  parent::ilFileDataImport();
38  $this->group_path = parent::getPath()."/".GROUP_IMPORT_PATH;
39 
40  // IF DIRECTORY ISN'T CREATED CREATE IT
41  // CALL STATIC TO AVOID OVERWRITE PROBLEMS
43  $this->__readFiles();
44  }
45 
46  function getFiles()
47  {
48  return $this->files ? $this->files : array();
49  }
50 
51  function getXMLFile()
52  {
53  return $this->xml_file;
54  }
55 
56  function getObjectFile()
57  {
58  return $this->object_file;
59  }
60 
67  function storeUploadedFile($a_http_post_file)
68  {
69  // TODO:
70  // CHECK UPLOAD LIMIT
71  //
72 
73  if(isset($a_http_post_file) && $a_http_post_file['size'])
74  {
75  // DELETE OLD FILES
76  $this->unlinkLast();
77 
78  ilUtil::moveUploadedFile($a_http_post_file['tmp_name'],
79  $a_http_post_file['name'], $this->getPath().'/'.$a_http_post_file['name']);
80 
81 
82  // UPDATE FILES LIST
83  $this->__readFiles();
84  return true;
85  }
86  else
87  {
88  return false;
89  }
90  }
91  function findXMLFile($a_dir = '')
92  {
93  $a_dir = $a_dir ? $a_dir : $this->getPath();
94 
95  $this->__readFiles($a_dir);
96 
97  foreach($this->getFiles() as $file_data)
98  {
99  if(is_dir($file_data["abs_path"]))
100  {
101  $this->findXMLFile($file_data["abs_path"]);
102  }
103  if(($tmp = explode(".",$file_data["name"])) !== false)
104  {
105  if($tmp[count($tmp) - 1] == "xml")
106  {
107  return $this->xml_file = $file_data["abs_path"];
108  }
109  }
110  }
111  return $this->xml_file;
112  }
113 
114  function findObjectFile($a_file,$a_dir = '')
115  {
116  $a_dir = $a_dir ? $a_dir : $this->getPath();
117 
118  $this->__readFiles($a_dir);
119 
120  foreach($this->getFiles() as $file_data)
121  {
122  if(is_dir($file_data["abs_path"]))
123  {
124  $this->findObjectFile($a_file,$file_data["abs_path"]);
125  }
126  if($file_data["name"] == $a_file)
127  {
128  return $this->object_file = $file_data["abs_path"];
129  }
130  }
131  return $this->object_file;
132  }
133 
134 
135 
136  function unzip()
137  {
138  foreach($this->getFiles() as $file_data)
139  {
140  ilUtil::unzip($file_data["abs_path"]);
141 
142  return true;
143  }
144  return false;
145  }
146 
152  function getPath()
153  {
154  return $this->group_path;
155  }
156 
157  function unlinkLast()
158  {
159  foreach($this->getFiles() as $file_data)
160  {
161  if(is_dir($file_data["abs_path"]))
162  {
163  ilUtil::delDir($file_data["abs_path"]);
164  }
165  else
166  {
167  unlink($file_data["abs_path"]);
168  }
169  }
170  return true;
171  }
172  // PRIVATE METHODS
173  function __readFiles($a_dir = '')
174  {
175  $a_dir = $a_dir ? $a_dir : $this->getPath();
176 
177  $this->files = array();
178  $dp = opendir($a_dir);
179 
180  while($file = readdir($dp))
181  {
182  if($file == "." or $file == "..")
183  {
184  continue;
185  }
186  $this->files[] = array(
187  'name' => $file,
188  'abs_path' => $a_dir."/".$file,
189  'size' => filesize($a_dir."/".$file),
190  'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($a_dir.'/'.$file))));
191  }
192  closedir($dp);
193 
194  return true;
195  }
196 
203  function __checkReadWrite()
204  {
205  if(is_writable($this->group_path) && is_readable($this->group_path))
206  {
207  return true;
208  }
209  else
210  {
211  $this->ilias->raiseError("Group import directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
212  }
213  }
221  function _initDirectory()
222  {
223  if(!@file_exists($this->group_path))
224  {
225  ilUtil::makeDir($this->group_path);
226  }
227  return true;
228  }
229 }
print $file
This class handles all operations on files for the exercise object.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
ilFileDataImportGroup()
Constructor call base constructors checks if directory is writable and sets the optional obj_id...
getPath()
get exercise path public
__checkReadWrite()
check if directory is writable overwritten method from base class private
This class handles all operations on files for the exercise object.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
redirection script todo: (a better solution should control the processing via a xml file) ...
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
storeUploadedFile($a_http_post_file)
store uploaded file in filesystem
_initDirectory()
init directory overwritten method public
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 delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively