ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
12require_once("./Services/FileSystem/classes/class.ilFileDataImport.php");
13
15{
22
23 var $files;
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 // CHECK IF FILE WITH SAME NAME EXISTS
82 //move_uploaded_file($a_http_post_file['tmp_name'],$this->getPath().'/'.$a_http_post_file['name']);
83
84 // UPDATE FILES LIST
85 $this->__readFiles();
86 return true;
87 }
88 else
89 {
90 return false;
91 }
92 }
93 function findXMLFile($a_dir = '')
94 {
95 $a_dir = $a_dir ? $a_dir : $this->getPath();
96
97 $this->__readFiles($a_dir);
98
99 foreach($this->getFiles() as $file_data)
100 {
101 if(is_dir($file_data["abs_path"]))
102 {
103 $this->findXMLFile($file_data["abs_path"]);
104 }
105 if(($tmp = explode(".",$file_data["name"])) !== false)
106 {
107 if($tmp[count($tmp) - 1] == "xml")
108 {
109 return $this->xml_file = $file_data["abs_path"];
110 }
111 }
112 }
113 return $this->xml_file;
114 }
115
116 function findObjectFile($a_file,$a_dir = '')
117 {
118 $a_dir = $a_dir ? $a_dir : $this->getPath();
119
120 $this->__readFiles($a_dir);
121
122 foreach($this->getFiles() as $file_data)
123 {
124 if(is_dir($file_data["abs_path"]))
125 {
126 $this->findObjectFile($a_file,$file_data["abs_path"]);
127 }
128 if($file_data["name"] == $a_file)
129 {
130 return $this->object_file = $file_data["abs_path"];
131 }
132 }
133 return $this->object_file;
134 }
135
136
137
138 function unzip()
139 {
140 foreach($this->getFiles() as $file_data)
141 {
142 ilUtil::unzip($file_data["abs_path"]);
143
144 return true;
145 }
146 return false;
147 }
148
154 function getPath()
155 {
156 return $this->group_path;
157 }
158
159 function unlinkLast()
160 {
161 foreach($this->getFiles() as $file_data)
162 {
163 if(is_dir($file_data["abs_path"]))
164 {
165 ilUtil::delDir($file_data["abs_path"]);
166 }
167 else
168 {
169 unlink($file_data["abs_path"]);
170 }
171 }
172 return true;
173 }
174 // PRIVATE METHODS
175 function __readFiles($a_dir = '')
176 {
177 $a_dir = $a_dir ? $a_dir : $this->getPath();
178
179 $this->files = array();
180 $dp = opendir($a_dir);
181
182 while($file = readdir($dp))
183 {
184 if($file == "." or $file == "..")
185 {
186 continue;
187 }
188 $this->files[] = array(
189 'name' => $file,
190 'abs_path' => $a_dir."/".$file,
191 'size' => filesize($a_dir."/".$file),
192 'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($a_dir.'/'.$file))));
193 }
194 closedir($dp);
195
196 return true;
197 }
198
206 {
207 if(is_writable($this->group_path) && is_readable($this->group_path))
208 {
209 return true;
210 }
211 else
212 {
213 $this->ilias->raiseError("Group import directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
214 }
215 }
223 function _initDirectory()
224 {
225 if(!@file_exists($this->group_path))
226 {
227 ilUtil::makeDir($this->group_path);
228 }
229 return true;
230 }
231}
print $file
This class handles all operations on files for the exercise object.
getPath()
get exercise path @access public
_initDirectory()
init directory overwritten method @access public
__checkReadWrite()
check if directory is writable overwritten method from base class @access private
ilFileDataImportGroup()
Constructor call base constructors checks if directory is writable and sets the optional obj_id.
storeUploadedFile($a_http_post_file)
store uploaded file in filesystem
This class handles all operations on files for the exercise object.
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 @access public
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
redirection script todo: (a better solution should control the processing via a xml file)