ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFileDataCourse.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
32require_once("./Services/FileSystem/classes/class.ilFileData.php");
33
35{
42
43 private $course_id;
44
52 public function __construct($a_course_id)
53 {
54 define('COURSE_PATH', 'course');
55 parent::__construct();
56 $this->course_path = parent::getPath() . "/" . COURSE_PATH;
57 $this->course_id = $a_course_id;
58
59 // IF DIRECTORY ISN'T CREATED CREATE IT
60 if (!$this->__checkPath()) {
61 $this->__initDirectory();
62 }
63 // Check import dir
64 $this->__checkImportPath();
65 }
66
67 public function getArchiveFile($a_rel_name)
68 {
69 if (@file_exists($this->course_path . '/' . $a_rel_name . '.zip')) {
70 return $this->course_path . '/' . $a_rel_name . '.zip';
71 }
72 if (@file_exists($this->course_path . '/' . $a_rel_name . '.pdf')) {
73 return $this->course_path . '/' . $a_rel_name . '.pdf';
74 }
75 return false;
76 }
77
84 public function getMemberExportFiles()
85 {
86 $files = array();
87 $dp = opendir($this->course_path);
88
89 while ($file = readdir($dp)) {
90 if (is_dir($file)) {
91 continue;
92 }
93
94 if (preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/", $file, $matches) and $matches[3] == $this->course_id) {
95 $timest = $matches[1];
96 $file_info['name'] = $matches[0];
97 $file_info['timest'] = $matches[1];
98 $file_info['type'] = $matches[2];
99 $file_info['id'] = $matches[3];
100 $file_info['size'] = filesize($this->course_path . '/' . $file);
101
102 $files[$timest] = $file_info;
103 }
104 }
105 closedir($dp);
106 return $files ? $files : array();
107 }
108
109 public function deleteMemberExportFile($a_name)
110 {
111 $file_name = $this->course_path . '/' . $a_name;
112 if (@file_exists($file_name)) {
113 @unlink($file_name);
114 }
115 }
116
117 public function getMemberExportFile($a_name)
118 {
119 $file_name = $this->course_path . '/' . $a_name;
120 if (@file_exists($file_name)) {
121 return file_get_contents($file_name);
122 }
123 }
124
125
126 public function deleteArchive($a_rel_name)
127 {
128 $this->deleteZipFile($this->course_path . '/' . $a_rel_name . '.zip');
129 $this->deleteDirectory($this->course_path . '/' . $a_rel_name);
130 $this->deleteDirectory(CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
131 $this->deletePdf($this->course_path . '/' . $a_rel_name . '.pdf');
132
133 return true;
134 }
135 public function deleteZipFile($a_abs_name)
136 {
137 if (@file_exists($a_abs_name)) {
138 @unlink($a_abs_name);
139
140 return true;
141 }
142 return false;
143 }
144 public function deleteDirectory($a_abs_name)
145 {
146 if (file_exists($a_abs_name)) {
147 ilUtil::delDir($a_abs_name);
148
149 return true;
150 }
151 return false;
152 }
153 public function deletePdf($a_abs_name)
154 {
155 if (@file_exists($a_abs_name)) {
156 @unlink($a_abs_name);
157
158 return true;
159 }
160 return false;
161 }
162
163 public function copy($a_from, $a_to)
164 {
165 if (@file_exists($a_from)) {
166 @copy($a_from, $this->getCoursePath() . '/' . $a_to);
167
168 return true;
169 }
170 return false;
171 }
172
173 public function rCopy($a_from, $a_to)
174 {
175 ilUtil::rCopy($a_from, $this->getCoursePath() . '/' . $a_to);
176
177 return true;
178 }
179
180
181 public function addDirectory($a_rel_name)
182 {
183 ilUtil::makeDir($this->getCoursePath() . '/' . $a_rel_name);
184
185 return true;
186 }
187
188 public function writeToFile($a_data, $a_rel_name)
189 {
190 if (!$fp = @fopen($this->getCoursePath() . '/' . $a_rel_name, 'w+')) {
191 die("Cannot open file: " . $this->getCoursePath() . '/' . $a_rel_name);
192 }
193 @fwrite($fp, $a_data);
194
195 return true;
196 }
197
198 public function zipFile($a_rel_name, $a_zip_name)
199 {
200 ilUtil::zip($this->getCoursePath() . '/' . $a_rel_name, $this->getCoursePath() . '/' . $a_zip_name);
201
202 // RETURN filesize
203 return filesize($this->getCoursePath() . '/' . $a_zip_name);
204 }
205
206
212 public function getCoursePath()
213 {
214 return $this->course_path;
215 }
216
217 public function createOnlineVersion($a_rel_name)
218 {
219 ilUtil::makeDir(CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
220 ilUtil::rCopy($this->getCoursePath() . '/' . $a_rel_name, CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
221
222 return true;
223 }
224
225 public function getOnlineLink($a_rel_name)
226 {
227 return ilUtil::getWebspaceDir('filesystem') . '/courses/' . $a_rel_name . '/index.html';
228 }
229
230
231 // METHODS FOR XML IMPORT OF COURSE
232 public function createImportFile($a_tmp_name, $a_name)
233 {
234 ilUtil::makeDir($this->getCoursePath() . '/import/crs_' . $this->course_id);
235
236 ilUtil::moveUploadedFile(
237 $a_tmp_name,
238 $a_name,
239 $this->getCoursePath() . '/import/crs_' . $this->course_id . '/' . $a_name
240 );
241 $this->import_file_info = pathinfo($this->getCoursePath() . '/import/crs_' . $this->course_id . '/' . $a_name);
242 }
243
244 public function unpackImportFile()
245 {
246 return ilUtil::unzip($this->getCoursePath() . '/import/crs_' . $this->course_id . '/' . $this->import_file_info['basename']);
247 }
248
249 public function validateImportFile()
250 {
251 if (!is_dir($this->getCoursePath() . '/import/crs_' . $this->course_id) . '/' .
252 basename($this->import_file_info['basename'], '.zip')) {
253 return false;
254 }
255 if (!file_exists($this->getCoursePath() . '/import/crs_' . $this->course_id
256 . '/' . basename($this->import_file_info['basename'], '.zip')
257 . '/' . basename($this->import_file_info['basename'], '.zip') . '.xml')) {
258 return false;
259 }
260 }
261
262 public function getImportFile()
263 {
264 return $this->getCoursePath() . '/import/crs_' . $this->course_id
265 . '/' . basename($this->import_file_info['basename'], '.zip')
266 . '/' . basename($this->import_file_info['basename'], '.zip') . '.xml';
267 }
268
269
270
271
272 // PRIVATE METHODS
273 public function __checkPath()
274 {
275 if (!@file_exists($this->getCoursePath())) {
276 return false;
277 }
278 if (!@file_exists(CLIENT_WEB_DIR . '/courses')) {
279 ilUtil::makeDir(CLIENT_WEB_DIR . '/courses');
280 }
281
282
283 $this->__checkReadWrite();
284
285 return true;
286 }
287
288 public function __checkImportPath()
289 {
290 if (!@file_exists($this->getCoursePath() . '/import')) {
291 ilUtil::makeDir($this->getCoursePath() . '/import');
292 }
293
294 if (!is_writable($this->getCoursePath() . '/import') or !is_readable($this->getCoursePath() . '/import')) {
295 $this->ilias->raiseError("Course import path is not readable/writable by webserver", $this->ilias->error_obj->FATAL);
296 }
297 }
298
305 public function __checkReadWrite()
306 {
307 if (is_writable($this->course_path) && is_readable($this->course_path)) {
308 return true;
309 } else {
310 $this->ilias->raiseError("Course directory is not readable/writable by webserver", $this->ilias->error_obj->FATAL);
311 }
312 }
319 public function __initDirectory()
320 {
321 if (is_writable($this->getPath())) {
322 ilUtil::makeDir($this->getPath() . '/' . COURSE_PATH);
323 $this->course_path = $this->getPath() . '/' . COURSE_PATH;
324
325 return true;
326 }
327 return false;
328 }
329}
An exception for terminatinating execution or to throw for unit testing.
This class handles all operations of archive files for the course object.
__construct($a_course_id)
Constructor call base constructors checks if directory is writable and sets the optional obj_id.
zipFile($a_rel_name, $a_zip_name)
__checkReadWrite()
check if directory is writable overwritten method from base class @access private
writeToFile($a_data, $a_rel_name)
createOnlineVersion($a_rel_name)
createImportFile($a_tmp_name, $a_name)
__initDirectory()
init directory overwritten method @access public
getCoursePath()
get exercise path @access public
getMemberExportFiles()
Get all member export files.
This class handles all operations on files in directory /ilias_data/.
getPath()
get Path @access public
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
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 ...
$files
Definition: metarefresh.php:49
redirection script todo: (a better solution should control the processing via a xml file)