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