ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExportFileInfo.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15 const CURRENT_VERSION = "4.1.0";
16
17
18 private $obj_id = 0;
20 private $export_type = '';
21 private $file_name = '';
22 private $create_date = null;
23
30 public function __construct($a_obj_id, $a_export_type = '', $a_filename = '')
31 {
32 $this->obj_id = $a_obj_id;
33 $this->export_type = $a_export_type;
34 $this->file_name = $a_filename;
35 if ($this->getObjId() and $this->getExportType() and $this->getFilename()) {
36 $this->read();
37 }
38 }
39
47 public static function lookupLastExport($a_obj_id, $a_type, $a_version = '')
48 {
49 global $DIC;
50
51 $ilDB = $DIC['ilDB'];
52
53 $query = "SELECT * FROM export_file_info " .
54 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . ' ' .
55 "AND export_type = " . $ilDB->quote($a_type, 'text') . ' ' .
56 "ORDER BY create_date DESC";
57 $res = $ilDB->query($query);
58 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
59 if (!$a_version or $row->version == $a_version) {
60 return new ilExportFileInfo($row->obj_id, $row->export_type, $row->filename);
61 }
62 }
63 return null;
64 }
65
66
72 public static function deleteByObjId($a_obj_id)
73 {
74 global $DIC;
75
76 $ilDB = $DIC['ilDB'];
77
78 $ilDB->manipulate("DELETE FROM export_file_info WHERE obj_id = " . $ilDB->quote($a_obj_id));
79 return true;
80 }
81
82
83
89 public function setExportType($a_type)
90 {
91 $this->export_type = $a_type;
92 }
93
98 public function getExportType()
99 {
100 return $this->export_type;
101 }
102
108 public function setFilename($a_name)
109 {
110 $this->file_name = $a_name;
111 }
112
117 public function getFilename()
118 {
119 return $this->file_name;
120 }
121
122 public function getBasename($a_ext = '.zip')
123 {
124 return basename($this->getFilename(), $a_ext);
125 }
126
132 public function setObjId($a_id)
133 {
134 $this->obj_id = $a_id;
135 }
136
141 public function getObjId()
142 {
143 return $this->obj_id;
144 }
145
150 public function setVersion($a_version)
151 {
152 $this->version = $a_version;
153 }
154
159 public function getVersion()
160 {
161 return $this->version;
162 }
163
168 public function getCreationDate()
169 {
170 return $this->create_date instanceof ilDateTime ? $this->create_date : new ilDateTime(time(), IL_CAL_UNIX);
171 }
172
178 public function setCreationDate(ilDateTime $dt = null)
179 {
180 $this->create_date = $dt;
181 }
182
186 public function create()
187 {
188 global $DIC;
189
190 $db = $DIC->database();
191
192 $exists_query = 'select * from export_file_info ' .
193 'where obj_id = ' . $db->quote($this->obj_id, 'integer') . ' ' .
194 'and export_type = ' . $db->quote($this->getExportType(), 'text') . ' ' .
195 'and filename = ' . $db->quote($this->getFilename(), 'text');
196 $exists_res = $db->query($exists_query);
197
198 if (!$exists_res->numRows()) {
199 $query = "INSERT INTO export_file_info (obj_id, export_type, filename, version, create_date) " .
200 "VALUES ( " .
201 $db->quote($this->getObjId(), 'integer') . ', ' .
202 $db->quote($this->getExportType(), 'text') . ', ' .
203 $db->quote($this->getFilename(), 'text') . ', ' .
204 $db->quote($this->getVersion(), 'text') . ', ' .
205 $db->quote($this->getCreationDate()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
206 ")";
207 $db->manipulate($query);
208 }
209 }
210
215 public function delete()
216 {
217 global $DIC;
218
219 $ilDB = $DIC['ilDB'];
220
221 $ilDB->manipulate(
222 'DELETE FROM export_file_info ' .
223 'WHERE obj_id = ' . $ilDB->quote($this->getObjId(), 'integer') . ' ' .
224 'AND filename = ' . $ilDB->quote($this->getFilename(), 'text')
225 );
226 return true;
227 }
228
233 protected function read()
234 {
235 global $DIC;
236
237 $ilDB = $DIC['ilDB'];
238
239 $query = "SELECT * FROM export_file_info " .
240 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . ' ' .
241 "AND export_type = " . $ilDB->quote($this->getExportType(), 'text') . ' ' .
242 "AND filename = " . $ilDB->quote($this->getFilename(), 'text');
243
244 $res = $ilDB->query($query);
245 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
246 $this->setVersion($row->version);
248 }
249 return true;
250 }
251}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
@classDescription Stores information of creation date and versions of export files
setExportType($a_type)
set export type
setCreationDate(ilDateTime $dt=null)
set creation date
static deleteByObjId($a_obj_id)
Delete all export entries by obj_id.
create()
Create new export entry.
getExportType()
get export type
setFilename($a_name)
set filename
static lookupLastExport($a_obj_id, $a_type, $a_version='')
Lookup last export.
__construct($a_obj_id, $a_export_type='', $a_filename='')
ilExportFileInfo constructor.
getCreationDate()
get creation date
setVersion($a_version)
set version
setObjId($a_id)
Set obj id.
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92