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