ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFSStorageCourse.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');
25 
35 {
36  const MEMBER_EXPORT_DIR = 'memberExport';
37  const INFO_DIR = 'info';
38  const ARCHIVE_DIR = 'archives';
39 
40  private $log;
47  public function __construct($a_container_id = 0)
48  {
49  global $log;
50 
51  $this->log = $log;
53  }
54 
64  public static function _clone($a_source_id,$a_target_id)
65  {
66  $source = new ilFSStorageCourse($a_source_id);
67  $target = new ilFSStorageCourse($a_target_id);
68 
69  $target->create();
70  ilFileSystemStorage::_copyDirectory($source->getAbsolutePath(),$target->getAbsolutePath());
71 
72  // Delete member export files
73  $target->deleteDirectory($target->getMemberExportDirectory());
74 
75  unset($source);
76  unset($target);
77  return true;
78  }
79 
80  // Info files
87  public function initInfoDirectory()
88  {
90  }
91 
98  public function getInfoDirectory()
99  {
100  return $this->getAbsolutePath().'/'.self::INFO_DIR;
101  }
102 
103 
110  public function initMemberExportDirectory()
111  {
113  }
114 
121  public function getMemberExportDirectory()
122  {
123  return $this->getAbsolutePath().'/'.self::MEMBER_EXPORT_DIR;
124  }
125 
134  public function addMemberExportFile($a_data,$a_rel_name)
135  {
136  $this->initMemberExportDirectory();
137  if(!$this->writeToFile($a_data,$this->getMemberExportDirectory().'/'.$a_rel_name))
138  {
139  $this->log->write('Cannot write to file: '.$this->getMemberExportDirectory().'/'.$a_rel_name);
140  return false;
141  }
142 
143  return true;
144 
145  }
146 
153  public function getMemberExportFiles()
154  {
155  if(!@is_dir($this->getMemberExportDirectory()))
156  {
157  return array();
158  }
159 
160  $files = array();
161  $dp = @opendir($this->getMemberExportDirectory());
162 
163  while($file = readdir($dp))
164  {
165  if(is_dir($file))
166  {
167  continue;
168  }
169 
170  if(preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/",$file,$matches) and $matches[3] == $this->getContainerId())
171  {
172  $timest = $matches[1];
173  $file_info['name'] = $matches[0];
174  $file_info['timest'] = $matches[1];
175  $file_info['type'] = $matches[2];
176  $file_info['id'] = $matches[3];
177  $file_info['size'] = filesize($this->getMemberExportDirectory().'/'.$file);
178 
179  $files[$timest] = $file_info;
180  }
181  }
182  closedir($dp);
183  return $files ? $files : array();
184  }
185 
186  public function getMemberExportFile($a_name)
187  {
188  $file_name = $this->getMemberExportDirectory().'/'.$a_name;
189 
190  if(@file_exists($file_name))
191  {
192  return file_get_contents($file_name);
193  }
194  }
195 
203  public function deleteMemberExportFile($a_export_name)
204  {
205  return $this->deleteFile($this->getMemberExportDirectory().'/'.$a_export_name);
206  }
207 
208  // ARCHIVE Methods
216  public function initArchiveDirectory()
217  {
219  }
220 
227  public function getArchiveDirectory()
228  {
229  return $this->getAbsolutePath().'/'.self::ARCHIVE_DIR;
230  }
231 
239  public function addArchiveSubDirectory($a_name)
240  {
241  ilUtil::makeDirParents($this->getArchiveDirectory().'/'.$a_name);
242  }
243 
251  public function writeArchiveFile($a_data,$a_rel_name)
252  {
253  if(!$this->writeToFile($a_data,$this->getArchiveDirectory().'/'.$a_rel_name))
254  {
255  $this->log->write('Cannot write to file: '.$this->getArchiveDirectory().'/'.$a_rel_name);
256  return false;
257  }
258  return true;
259  }
260 
270  public function zipArchive($a_rel_name,$a_zip_name)
271  {
272  if(ilUtil::zip($this->getArchiveDirectory().'/'.$a_rel_name,$this->getArchiveDirectory().'/'.$a_zip_name))
273  {
274  return filesize($this->getArchiveDirectory().'/'.$a_zip_name);
275  }
276  return 0;
277  }
278 
286  public function deleteArchive($a_rel_name)
287  {
288  $this->deleteFile($this->getArchiveDirectory().'/'.$a_rel_name.'.zip');
289  $this->deleteDirectory($this->getArchiveDirectory().'/'.$a_rel_name);
290  }
291 
292  public function createArchiveOnlineVersion($a_rel_name)
293  {
294  ilUtil::makeDirParents(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
295  ilUtil::rCopy($this->getArchiveDirectory().'/'.$a_rel_name,CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
296 
297  return true;
298  }
299 
300  public function getOnlineLink($a_rel_name)
301  {
302  return ilUtil::getWebspaceDir('filesystem').'/courses/'.$a_rel_name.'/index.html';
303  }
304 
305 
312  protected function getPathPostfix()
313  {
314  return 'crs';
315  }
316 
323  protected function getPathPrefix()
324  {
325  return 'ilCourse';
326  }
327 
328 }
329 
330 
331 
332 
333 ?>