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