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 include_once('Modules/Course/classes/Event/class.ilFSStorageEvent.php');
00025
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 private $fss_storage = null;
00047
00048 function ilEventFile($a_file_id = null)
00049 {
00050 global $ilErr,$ilDB,$lng;
00051
00052 $this->ilErr =& $ilErr;
00053 $this->db =& $ilDB;
00054 $this->lng =& $lng;
00055
00056 $this->file_id = $a_file_id;
00057 $this->__read();
00058 }
00059
00060 function setFileId($a_id)
00061 {
00062 $this->file_id = $a_id;
00063 }
00064 function getFileId()
00065 {
00066 return $this->file_id;
00067 }
00068
00069 function getEventId()
00070 {
00071 return $this->event_id;
00072 }
00073 function setEventId($a_event_id)
00074 {
00075 $this->event_id = $a_event_id;
00076 }
00077
00078 function setFileName($a_name)
00079 {
00080 $this->file_name = $a_name;
00081 }
00082 function getFileName()
00083 {
00084 return $this->file_name;
00085 }
00086 function setFileType($a_type)
00087 {
00088 $this->file_type = $a_type;
00089 }
00090 function getFileType()
00091 {
00092 return $this->file_type;
00093 }
00094 function setFileSize($a_size)
00095 {
00096 $this->file_size = $a_size;
00097 }
00098 function getFileSize()
00099 {
00100 return $this->file_size;
00101 }
00102 function setTemporaryName($a_name)
00103 {
00104 $this->tmp_name = $a_name;
00105 }
00106 function getTemporaryName()
00107 {
00108 return $this->tmp_name;
00109 }
00110 function setErrorCode($a_code)
00111 {
00112 $this->error_code = $a_code;
00113 }
00114 function getErrorCode()
00115 {
00116 return $this->error_code;
00117 }
00118
00119 function getAbsolutePath()
00120 {
00121 return $this->fss_storage->getAbsolutePath()."/".$this->getFileId();
00122 }
00123
00124 function validate()
00125 {
00126 switch($this->getErrorCode())
00127 {
00128 case UPLOAD_ERR_INI_SIZE:
00129 $this->ilErr->appendMessage($this->lng->txt('file_upload_ini_size'));
00130 break;
00131 case UPLOAD_ERR_FORM_SIZE:
00132 $this->ilErr->appendMessage($this->lng->txt('file_upload_form_size'));
00133 break;
00134
00135 case UPLOAD_ERR_PARTIAL:
00136 $this->ilErr->appendMessage($this->lng->txt('file_upload_only_partial'));
00137 break;
00138
00139 case UPLOAD_ERR_NO_TMP_DIR:
00140 $this->ilErr->appendMessage($this->lng->txt('file_upload_no_tmp_dir'));
00141 break;
00142
00143 #case UPLOAD_ERR_CANT_WRITE:
00144 # $this->ilErr->appendMessage($this->lng->txt('file_upload_no_write'));
00145 # break;
00146
00147 case UPLOAD_ERR_OK:
00148 case UPLOAD_ERR_NO_FILE:
00149 default:
00150 return true;
00151 }
00152 }
00153
00161 public function cloneFiles($a_target_event_id)
00162 {
00163 $file = new ilEventFile();
00164 $file->setEventId($a_target_event_id);
00165 $file->setFileName($this->getFileName());
00166 $file->setFileType($this->getFileType());
00167 $file->setFileSize($this->getFileSize());
00168 $file->create(false);
00169
00170
00171 $source = new ilFSStorageEvent($this->getEventId());
00172 $source->copyFile($this->getAbsolutePath(),$file->getAbsolutePath());
00173 }
00174
00175 function create($a_upload = true)
00176 {
00177 global $ilDB;
00178
00179 if($this->getErrorCode() != 0)
00180 {
00181 return false;
00182 }
00183
00184 $query = "INSERT INTO event_file ".
00185 "SET event_id = ".$ilDB->quote($this->getEventId()).", ".
00186 "file_name = ".$ilDB->quote($this->getFileName()).", ".
00187 "file_size = ".$ilDB->quote($this->getFileSize()).", ".
00188 "file_type = ".$ilDB->quote($this->getFileType())." ";
00189
00190 $res = $this->db->query($query);
00191 $this->setFileId($this->db->getLastInsertId());
00192
00193 $this->fss_storage = new ilFSStorageEvent($this->getEventId());
00194 $this->fss_storage->createDirectory();
00195
00196 if($a_upload)
00197 {
00198
00199 ilUtil::moveUploadedFile($this->getTemporaryName(),
00200 $this->getFileName(),
00201 $this->fss_storage->getAbsolutePath().'/'.$this->getFileId());
00202
00203 }
00204
00205 return true;
00206 }
00207
00208 function delete()
00209 {
00210 global $ilDB;
00211
00212
00213 $query = "DELETE FROM event_file ".
00214 "WHERE file_id = ".$this->getFileId()." ";
00215 $this->db->query($query);
00216
00217
00218 $this->fss_storage->deleteFile($this->getAbsolutePath());
00219 return true;
00220 }
00221
00222 function _deleteByEvent($a_event_id)
00223 {
00224 global $ilDB;
00225
00226
00227 $query = "DELETE FROM event_file ".
00228 "WHERE event_id = ".$ilDB->quote($a_event_id)."";
00229 $res = $ilDB->query($query);
00230
00231 #$this->fss_storage->delete();
00232 return true;
00233 }
00234
00235 function &_readFilesByEvent($a_event_id)
00236 {
00237 global $ilDB;
00238
00239 $query = "SELECT * FROM event_file ".
00240 "WHERE event_id = ".$ilDB->quote($a_event_id)."";
00241
00242 $res = $ilDB->query($query);
00243 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00244 {
00245 $files[] =& new ilEventFile($row->file_id);
00246 }
00247 return is_array($files) ? $files : array();
00248 }
00249
00250 function __read()
00251 {
00252 global $ilDB;
00253
00254 if(!$this->file_id)
00255 {
00256 return true;
00257 }
00258
00259
00260 $query = "SELECT * FROM event_file WHERE file_id = ".$ilDB->quote($this->file_id)."";
00261 $res = $this->db->query($query);
00262 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00263 {
00264 $this->setFileName($row->file_name);
00265 $this->setFileSize($row->file_size);
00266 $this->setFileType($row->file_type);
00267 $this->setEventId($row->event_id);
00268 }
00269 $this->fss_storage = new ilFSStorageEvent($this->getEventId());
00270 return true;
00271 }
00272
00273 }
00274 ?>