ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSessionFile.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
24include_once('Modules/Session/classes/class.ilFSStorageSession.php');
25
37{
38 var $ilErr;
39 var $ilDB;
40 var $tree;
41 var $lng;
42
43 var $event_id = null;
44 var $file_id = null;
45
46 private $fss_storage = null;
47
52 public function __construct($a_file_id = null)
53 {
54 global $ilErr,$ilDB,$lng;
55
56 $this->ilErr = $ilErr;
57 $this->db = $ilDB;
58 $this->lng = $lng;
59
60 $this->file_id = $a_file_id;
61 $this->__read();
62 }
63
64 function setFileId($a_id)
65 {
66 $this->file_id = $a_id;
67 }
68 function getFileId()
69 {
70 return $this->file_id;
71 }
72
73 function getSessionId()
74 {
75 return $this->event_id;
76 }
77 function setSessionId($a_event_id)
78 {
79 $this->event_id = $a_event_id;
80 }
81
82 function setFileName($a_name)
83 {
84 $this->file_name = $a_name;
85 }
86 function getFileName()
87 {
88 return $this->file_name;
89 }
91 {
92 $this->file_type = $a_type;
93 }
94 function getFileType()
95 {
96 return $this->file_type;
97 }
98 function setFileSize($a_size)
99 {
100 $this->file_size = $a_size;
101 }
102 function getFileSize()
103 {
104 return $this->file_size;
105 }
106 function setTemporaryName($a_name)
107 {
108 $this->tmp_name = $a_name;
109 }
111 {
112 return $this->tmp_name;
113 }
114 function setErrorCode($a_code)
115 {
116 $this->error_code = $a_code;
117 }
118 function getErrorCode()
119 {
120 return $this->error_code;
121 }
122
124 {
125 return $this->fss_storage->getAbsolutePath()."/".$this->getFileId();
126 }
127
128 function validate()
129 {
130 switch($this->getErrorCode())
131 {
132 case UPLOAD_ERR_INI_SIZE:
133 $this->ilErr->appendMessage($this->lng->txt('file_upload_ini_size'));
134 break;
135 case UPLOAD_ERR_FORM_SIZE:
136 $this->ilErr->appendMessage($this->lng->txt('file_upload_form_size'));
137 break;
138
139 case UPLOAD_ERR_PARTIAL:
140 $this->ilErr->appendMessage($this->lng->txt('file_upload_only_partial'));
141 break;
142
143 case UPLOAD_ERR_NO_TMP_DIR:
144 $this->ilErr->appendMessage($this->lng->txt('file_upload_no_tmp_dir'));
145 break;
146
147 #case UPLOAD_ERR_CANT_WRITE:
148 # $this->ilErr->appendMessage($this->lng->txt('file_upload_no_write'));
149 # break;
150
151 case UPLOAD_ERR_OK:
152 case UPLOAD_ERR_NO_FILE:
153 default:
154 return true;
155 }
156 }
157
165 public function cloneFiles($a_target_event_id)
166 {
167 $file = new ilSessionFile();
168 $file->setSessionId($a_target_event_id);
169 $file->setFileName($this->getFileName());
170 $file->setFileType($this->getFileType());
171 $file->setFileSize($this->getFileSize());
172 $file->create(false);
173
174 // Copy file
175 $source = new ilFSStorageSession($this->getSessionId());
176 $source->copyFile($this->getAbsolutePath(),$file->getAbsolutePath());
177 }
178
179 function create($a_upload = true)
180 {
181 global $ilDB;
182
183 if($this->getErrorCode() != 0)
184 {
185 return false;
186 }
187
188 $next_id = $ilDB->nextId('event_file');
189 $query = "INSERT INTO event_file (file_id,event_id,file_name,file_size,file_type) ".
190 "VALUES( ".
191 $ilDB->quote($next_id ,'integer').", ".
192 $ilDB->quote($this->getSessionId() ,'integer').", ".
193 $ilDB->quote($this->getFileName() ,'text').", ".
194 $ilDB->quote($this->getFileSize() ,'integer').", ".
195 $ilDB->quote($this->getFileType() ,'text')." ".
196 ")";
197
198 $res = $ilDB->manipulate($query);
199 $this->setFileId($next_id);
200
201 $this->fss_storage = new ilFSStorageSession($this->getSessionId());
202 $this->fss_storage->createDirectory();
203
204 if($a_upload)
205 {
206 // now create file
208 $this->getFileName(),
209 $this->fss_storage->getAbsolutePath().'/'.$this->getFileId());
210
211 }
212
213 return true;
214 }
215
216 function delete()
217 {
218 global $ilDB;
219
220 // Delete db entry
221 $query = "DELETE FROM event_file ".
222 "WHERE file_id = ".$ilDB->quote($this->getFileId() ,'integer')." ";
223 $res = $ilDB->manipulate($query);
224
225 // Delete file
226 $this->fss_storage->deleteFile($this->getAbsolutePath());
227 return true;
228 }
229
230 function _deleteByEvent($a_event_id)
231 {
232 global $ilDB;
233
234 // delete all event ids and delete assigned files
235 $query = "DELETE FROM event_file ".
236 "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')."";
237 $res = $ilDB->manipulate($query);
238
239 #$this->fss_storage->delete();
240 return true;
241 }
242
243 static function _readFilesByEvent($a_event_id)
244 {
245 global $ilDB;
246
247 $query = "SELECT * FROM event_file ".
248 "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')."";
249
250 $res = $ilDB->query($query);
251 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
252 {
253 $files[] = new ilSessionFile($row->file_id);
254 }
255 return is_array($files) ? $files : array();
256 }
257
258 function __read()
259 {
260 global $ilDB;
261
262 if(!$this->file_id)
263 {
264 return true;
265 }
266
267 // read file data
268 $query = "SELECT * FROM event_file WHERE file_id = ".$ilDB->quote($this->file_id ,'integer')."";
269 $res = $this->db->query($query);
270 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
271 {
272 $this->setFileName($row->file_name);
273 $this->setFileSize($row->file_size);
274 $this->setFileType($row->file_type);
275 $this->setSessionId($row->event_id);
276 }
277 $this->fss_storage = new ilFSStorageSession($this->getSessionId());
278 return true;
279 }
280
281}
282?>
$files
Definition: add-vimline.php:18
An exception for terminatinating execution or to throw for unit testing.
_deleteByEvent($a_event_id)
static _readFilesByEvent($a_event_id)
cloneFiles($a_target_event_id)
Clone files.
create($a_upload=true)
__construct($a_file_id=null)
Constructor.
setSessionId($a_event_id)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$a_type
Definition: workflow.php:93