• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

course/classes/class.ilFileDataCourse.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00033 require_once("classes/class.ilFileData.php");
00034                                 
00035 class ilFileDataCourse extends ilFileData
00036 {
00042         var $course_path;
00043 
00051         function ilFileDataCourse(&$course_obj)
00052         {
00053                 define('COURSE_PATH','course');
00054                 parent::ilFileData();
00055                 $this->course_path = parent::getPath()."/".COURSE_PATH;
00056                 
00057                 // IF DIRECTORY ISN'T CREATED CREATE IT
00058                 if(!$this->__checkPath())
00059                 {
00060                         $this->__initDirectory();
00061                 }
00062         }
00063         
00064         function getArchiveFile($a_rel_name)
00065         {
00066                 if(@file_exists($this->course_path.'/'.$a_rel_name.'.zip'))
00067                 {
00068                         return $this->course_path.'/'.$a_rel_name.'.zip';
00069                 }
00070                 if(@file_exists($this->course_path.'/'.$a_rel_name.'.pdf'))
00071                 {
00072                         return $this->course_path.'/'.$a_rel_name.'.pdf';
00073                 }
00074                 return false;
00075         }
00076 
00077 
00078 
00079         function deleteArchive($a_rel_name)
00080         {
00081                 $this->deleteZipFile($this->course_path.'/'.$a_rel_name.'.zip');
00082                 $this->deleteDirectory($this->course_path.'/'.$a_rel_name);
00083                 $this->deleteDirectory(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00084                 $this->deletePdf($this->course_path.'/'.$a_rel_name.'.pdf');
00085 
00086                 return true;
00087         }
00088         function deleteZipFile($a_abs_name)
00089         {
00090                 if(@file_exists($a_abs_name))
00091                 {
00092                         @unlink($a_abs_name);
00093 
00094                         return true;
00095                 }
00096                 return false;
00097         }
00098         function deleteDirectory($a_abs_name)
00099         {
00100                 if(file_exists($a_abs_name))
00101                 {
00102                         ilUtil::delDir($a_abs_name);
00103                         
00104                         return true;
00105                 }
00106                 return false;
00107         }
00108         function deletePdf($a_abs_name)
00109         {
00110                 if(@file_exists($a_abs_name))
00111                 {
00112                         @unlink($a_abs_name);
00113 
00114                         return true;
00115                 }
00116                 return false;
00117         }
00118 
00119         function copy($a_from,$a_to)
00120         {
00121                 if(@file_exists($a_from))
00122                 {
00123                         @copy($a_from,$this->getCoursePath().'/'.$a_to);
00124 
00125                         return true;
00126                 }
00127                 return false;
00128         }
00129 
00130         function rCopy($a_from,$a_to)
00131         {
00132                 ilUtil::rCopy($a_from,$this->getCoursePath().'/'.$a_to);
00133 
00134                 return true;
00135         }
00136 
00137 
00138         function addDirectory($a_rel_name)
00139         {
00140                 ilUtil::makeDir($this->getCoursePath().'/'.$a_rel_name);
00141 
00142                 return true;
00143         }
00144 
00145         function writeToFile($a_data,$a_rel_name)
00146         {
00147                 if(!$fp = @fopen($this->getCoursePath().'/'.$a_rel_name,'w+'))
00148                 {
00149                         die("Cannot open file: ".$this->getCoursePath().'/'.$a_rel_name);
00150                 }
00151                 @fwrite($fp,$a_data);
00152 
00153                 return true;
00154         }
00155 
00156         function zipFile($a_rel_name,$a_zip_name)
00157         {
00158                 ilUtil::zip($this->getCoursePath().'/'.$a_rel_name,$this->getCoursePath().'/'.$a_zip_name);
00159 
00160                 // RETURN filesize
00161                 return filesize($this->getCoursePath().'/'.$a_zip_name);
00162         }
00163 
00164 
00170         function getCoursePath()
00171         {
00172                 return $this->course_path;
00173         }
00174 
00175         function createOnlineVersion($a_rel_name)
00176         {
00177                 ilUtil::makeDir(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00178                 ilUtil::rCopy($this->getCoursePath().'/'.$a_rel_name,CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00179 
00180                 return true;
00181         }
00182 
00183         function getOnlineLink($a_rel_name)
00184         {
00185                 return ilUtil::getWebspaceDir('filesystem').'/courses/'.$a_rel_name.'/index.html';
00186         }
00187 
00188 
00189 
00190         // PRIVATE METHODS
00191         function __checkPath()
00192         {
00193                 if(!@file_exists($this->getCoursePath()))
00194                 {
00195                         return false;
00196                 }
00197                 if(!@file_exists(CLIENT_WEB_DIR.'/courses'))
00198                 {
00199                         ilUtil::makeDir(CLIENT_WEB_DIR.'/courses');
00200                 }
00201 
00202                         
00203                 $this->__checkReadWrite();
00204 
00205                 return true;
00206         }
00213         function __checkReadWrite()
00214         {
00215                 if(is_writable($this->course_path) && is_readable($this->course_path))
00216                 {
00217                         return true;
00218                 }
00219                 else
00220                 {
00221                         $this->ilias->raiseError("Exercise directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00222                 }
00223         }
00230         function __initDirectory()
00231         {
00232                 if(is_writable($this->getPath()))
00233                 {
00234                         ilUtil::makeDir($this->getPath().'/'.COURSE_PATH);
00235                         $this->course_path = $this->getPath().'/'.COURSE_PATH;
00236                         
00237                         return true;
00238                 }
00239                 return false;
00240         }
00241 }

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1