• 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 
00044         var $course_obj = null;
00045 
00053         function ilFileDataCourse(&$course_obj)
00054         {
00055                 define('COURSE_PATH','course');
00056                 parent::ilFileData();
00057                 $this->course_path = parent::getPath()."/".COURSE_PATH;
00058                 $this->course_obj =& $course_obj;
00059 
00060                 // IF DIRECTORY ISN'T CREATED CREATE IT
00061                 if(!$this->__checkPath())
00062                 {
00063                         $this->__initDirectory();
00064                 }
00065                 // Check import dir
00066                 $this->__checkImportPath();
00067         }
00068         
00069         function getArchiveFile($a_rel_name)
00070         {
00071                 if(@file_exists($this->course_path.'/'.$a_rel_name.'.zip'))
00072                 {
00073                         return $this->course_path.'/'.$a_rel_name.'.zip';
00074                 }
00075                 if(@file_exists($this->course_path.'/'.$a_rel_name.'.pdf'))
00076                 {
00077                         return $this->course_path.'/'.$a_rel_name.'.pdf';
00078                 }
00079                 return false;
00080         }
00081 
00082 
00083 
00084         function deleteArchive($a_rel_name)
00085         {
00086                 $this->deleteZipFile($this->course_path.'/'.$a_rel_name.'.zip');
00087                 $this->deleteDirectory($this->course_path.'/'.$a_rel_name);
00088                 $this->deleteDirectory(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00089                 $this->deletePdf($this->course_path.'/'.$a_rel_name.'.pdf');
00090 
00091                 return true;
00092         }
00093         function deleteZipFile($a_abs_name)
00094         {
00095                 if(@file_exists($a_abs_name))
00096                 {
00097                         @unlink($a_abs_name);
00098 
00099                         return true;
00100                 }
00101                 return false;
00102         }
00103         function deleteDirectory($a_abs_name)
00104         {
00105                 if(file_exists($a_abs_name))
00106                 {
00107                         ilUtil::delDir($a_abs_name);
00108                         
00109                         return true;
00110                 }
00111                 return false;
00112         }
00113         function deletePdf($a_abs_name)
00114         {
00115                 if(@file_exists($a_abs_name))
00116                 {
00117                         @unlink($a_abs_name);
00118 
00119                         return true;
00120                 }
00121                 return false;
00122         }
00123 
00124         function copy($a_from,$a_to)
00125         {
00126                 if(@file_exists($a_from))
00127                 {
00128                         @copy($a_from,$this->getCoursePath().'/'.$a_to);
00129 
00130                         return true;
00131                 }
00132                 return false;
00133         }
00134 
00135         function rCopy($a_from,$a_to)
00136         {
00137                 ilUtil::rCopy($a_from,$this->getCoursePath().'/'.$a_to);
00138 
00139                 return true;
00140         }
00141 
00142 
00143         function addDirectory($a_rel_name)
00144         {
00145                 ilUtil::makeDir($this->getCoursePath().'/'.$a_rel_name);
00146 
00147                 return true;
00148         }
00149 
00150         function writeToFile($a_data,$a_rel_name)
00151         {
00152                 if(!$fp = @fopen($this->getCoursePath().'/'.$a_rel_name,'w+'))
00153                 {
00154                         die("Cannot open file: ".$this->getCoursePath().'/'.$a_rel_name);
00155                 }
00156                 @fwrite($fp,$a_data);
00157 
00158                 return true;
00159         }
00160 
00161         function zipFile($a_rel_name,$a_zip_name)
00162         {
00163                 ilUtil::zip($this->getCoursePath().'/'.$a_rel_name,$this->getCoursePath().'/'.$a_zip_name);
00164 
00165                 // RETURN filesize
00166                 return filesize($this->getCoursePath().'/'.$a_zip_name);
00167         }
00168 
00169 
00175         function getCoursePath()
00176         {
00177                 return $this->course_path;
00178         }
00179 
00180         function createOnlineVersion($a_rel_name)
00181         {
00182                 ilUtil::makeDir(CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00183                 ilUtil::rCopy($this->getCoursePath().'/'.$a_rel_name,CLIENT_WEB_DIR.'/courses/'.$a_rel_name);
00184 
00185                 return true;
00186         }
00187 
00188         function getOnlineLink($a_rel_name)
00189         {
00190                 return ilUtil::getWebspaceDir('filesystem').'/courses/'.$a_rel_name.'/index.html';
00191         }
00192 
00193 
00194         // METHODS FOR XML IMPORT OF COURSE
00195         function createImportFile($a_tmp_name,$a_name)
00196         {
00197                 ilUtil::makeDir($this->getCoursePath().'/import/crs_'.$this->course_obj->getId());
00198 
00199                 ilUtil::moveUploadedFile($a_tmp_name,
00200                                                                  $a_name, 
00201                                                                  $this->getCoursePath().'/import/crs_'.$this->course_obj->getId().'/'.$a_name);
00202                 $this->import_file_info = pathinfo($this->getCoursePath().'/import/crs_'.$this->course_obj->getId().'/'.$a_name);
00203 
00204         }
00205 
00206         function unpackImportFile()
00207         {
00208                 return ilUtil::unzip($this->getCoursePath().'/import/crs_'.$this->course_obj->getId().'/'.$this->import_file_info['basename']);
00209         }
00210 
00211         function validateImportFile()
00212         {
00213                 if(!is_dir($this->getCoursePath().'/import/crs_'.$this->course_obj->getId()).'/'.
00214                    basename($this->import_file_info['basename'],'.zip'))
00215                 {
00216                         return false;
00217                 }
00218                 if(!file_exists($this->getCoursePath().'/import/crs_'.$this->course_obj->getId()
00219                                                 .'/'.basename($this->import_file_info['basename'],'.zip')
00220                                                 .'/'.basename($this->import_file_info['basename'],'.zip').'.xml'))
00221                 {
00222                         return false;
00223                 }
00224         }
00225 
00226         function getImportFile()
00227         {
00228                 return $this->getCoursePath().'/import/crs_'.$this->course_obj->getId()
00229                         .'/'.basename($this->import_file_info['basename'],'.zip')
00230                         .'/'.basename($this->import_file_info['basename'],'.zip').'.xml';
00231         }
00232         
00233 
00234 
00235 
00236         // PRIVATE METHODS
00237         function __checkPath()
00238         {
00239                 if(!@file_exists($this->getCoursePath()))
00240                 {
00241                         return false;
00242                 }
00243                 if(!@file_exists(CLIENT_WEB_DIR.'/courses'))
00244                 {
00245                         ilUtil::makeDir(CLIENT_WEB_DIR.'/courses');
00246                 }
00247 
00248                         
00249                 $this->__checkReadWrite();
00250 
00251                 return true;
00252         }
00253         
00254         function __checkImportPath()
00255         {
00256                 if(!@file_exists($this->getCoursePath().'/import'))
00257                 {
00258                         ilUtil::makeDir($this->getCoursePath().'/import');
00259                 }
00260 
00261                 if(!is_writable($this->getCoursePath().'/import') or !is_readable($this->getCoursePath().'/import'))
00262                 {
00263                         $this->ilias->raiseError("Course import path is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00264                 }
00265         }
00266 
00273         function __checkReadWrite()
00274         {
00275                 if(is_writable($this->course_path) && is_readable($this->course_path))
00276                 {
00277                         return true;
00278                 }
00279                 else
00280                 {
00281                         $this->ilias->raiseError("Course directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
00282                 }
00283         }
00290         function __initDirectory()
00291         {
00292                 if(is_writable($this->getPath()))
00293                 {
00294                         ilUtil::makeDir($this->getPath().'/'.COURSE_PATH);
00295                         $this->course_path = $this->getPath().'/'.COURSE_PATH;
00296                         
00297                         return true;
00298                 }
00299                 return false;
00300         }
00301 }

Generated on Fri Dec 13 2013 11:57:58 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1