Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00036 class ilEventFile
00037 {
00038 var $ilErr;
00039 var $ilDB;
00040 var $tree;
00041 var $lng;
00042
00043 var $event_id = null;
00044 var $file_id = null;
00045
00046 function ilEventFile($a_file_id = null)
00047 {
00048 global $ilErr,$ilDB,$lng;
00049
00050 $this->ilErr =& $ilErr;
00051 $this->db =& $ilDB;
00052 $this->lng =& $lng;
00053
00054 $this->file_id = $a_file_id;
00055 $this->__read();
00056 }
00057
00058 function setFileId($a_id)
00059 {
00060 $this->file_id = $a_id;
00061 }
00062 function getFileId()
00063 {
00064 return $this->file_id;
00065 }
00066
00067 function getEventId()
00068 {
00069 return $this->event_id;
00070 }
00071 function setEventId($a_event_id)
00072 {
00073 $this->event_id = $a_event_id;
00074 }
00075
00076 function setFileName($a_name)
00077 {
00078 $this->file_name = $a_name;
00079 }
00080 function getFileName()
00081 {
00082 return $this->file_name;
00083 }
00084 function setFileType($a_type)
00085 {
00086 $this->file_type = $a_type;
00087 }
00088 function getFileType()
00089 {
00090 return $this->file_type;
00091 }
00092 function setFileSize($a_size)
00093 {
00094 $this->file_size = $a_size;
00095 }
00096 function getFileSize()
00097 {
00098 return $this->file_size;
00099 }
00100 function setTemporaryName($a_name)
00101 {
00102 $this->tmp_name = $a_name;
00103 }
00104 function getTemporaryName()
00105 {
00106 return $this->tmp_name;
00107 }
00108 function setErrorCode($a_code)
00109 {
00110 $this->error_code = $a_code;
00111 }
00112 function getErrorCode()
00113 {
00114 return $this->error_code;
00115 }
00116
00117 function getAbsolutePath()
00118 {
00119 return $this->__getDirectory()."/".$this->getFileId();
00120 }
00121
00122 function validate()
00123 {
00124 switch($this->getErrorCode())
00125 {
00126 case UPLOAD_ERR_INI_SIZE:
00127 $this->ilErr->appendMessage($this->lng->txt('file_upload_ini_size'));
00128 break;
00129 case UPLOAD_ERR_FORM_SIZE:
00130 $this->ilErr->appendMessage($this->lng->txt('file_upload_form_size'));
00131 break;
00132
00133 case UPLOAD_ERR_PARTIAL:
00134 $this->ilErr->appendMessage($this->lng->txt('file_upload_only_partial'));
00135 break;
00136
00137 case UPLOAD_ERR_NO_TMP_DIR:
00138 $this->ilErr->appendMessage($this->lng->txt('file_upload_no_tmp_dir'));
00139 break;
00140
00141 #case UPLOAD_ERR_CANT_WRITE:
00142 # $this->ilErr->appendMessage($this->lng->txt('file_upload_no_write'));
00143 # break;
00144
00145 case UPLOAD_ERR_OK:
00146 case UPLOAD_ERR_NO_FILE:
00147 default:
00148 return true;
00149 }
00150 }
00151
00152 function create()
00153 {
00154 if($this->getErrorCode() != 0)
00155 {
00156 return false;
00157 }
00158
00159 $query = "INSERT INTO event_file ".
00160 "SET event_id = '".$this->getEventId()."', ".
00161 "file_name = '".ilUtil::prepareDBString($this->getFileName())."', ".
00162 "file_size = '".ilUtil::prepareDBString($this->getFileSize())."', ".
00163 "file_type = '".ilUtil::prepareDBString($this->getFileType())."' ";
00164
00165 $res = $this->db->query($query);
00166 $this->setFileId($this->db->getLastInsertId());
00167
00168 if(!is_dir($this->__getDirectory()))
00169 {
00170 ilUtil::makeDirParents($this->__getDirectory());
00171 }
00172
00173 ilUtil::moveUploadedFile($this->getTemporaryName(),$this->getFileName(),$this->__getDirectory().'/'.$this->getFileId());
00174
00175 return true;
00176 }
00177
00178 function delete()
00179 {
00180
00181 $query = "DELETE FROM event_file ".
00182 "WHERE file_id = '".$this->getFileId()."'";
00183 $this->db->query($query);
00184
00185
00186 unlink($this->getAbsolutePath());
00187
00188 return true;
00189 }
00190
00191 function _deleteByEvent($a_event_id)
00192 {
00193 global $ilDB;
00194
00195
00196 $query = "DELETE FROM event_file ".
00197 "WHERE event_id = '".$a_event_id."'";
00198 $res = $ilDB->query($query);
00199
00200 ilUtil::delDir(ilUtil::getDataDir()."/events/event_".$a_event_id);
00201
00202 return true;
00203 }
00204
00205 function &_readFilesByEvent($a_event_id)
00206 {
00207 global $ilDB;
00208
00209 $query = "SELECT * FROM event_file ".
00210 "WHERE event_id = '".$a_event_id."'";
00211
00212 $res = $ilDB->query($query);
00213 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00214 {
00215 $files[] =& new ilEventFile($row->file_id);
00216 }
00217 return is_array($files) ? $files : array();
00218 }
00219
00220
00221
00222 function __getDirectory()
00223 {
00224 return ilUtil::getDataDir()."/events/event_".$this->getEventId();
00225 }
00226
00227 function __read()
00228 {
00229 if(!$this->file_id)
00230 {
00231 return true;
00232 }
00233
00234
00235 $query = "SELECT * FROM event_file WHERE file_id = '".$this->file_id."'";
00236 $res = $this->db->query($query);
00237 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00238 {
00239 $this->setFileName($row->file_name);
00240 $this->setFileSize($row->file_size);
00241 $this->setFileType($row->file_type);
00242 $this->setEventId($row->event_id);
00243 }
00244 return true;
00245 }
00246
00247 }
00248 ?>