ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
50
51 $query = "SELECT * FROM export_file_info " .
52 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . ' ' .
53 "AND export_type = " . $ilDB->quote($a_type, 'text') . ' ' .
54 "ORDER BY create_date DESC";
55 $res = $ilDB->query($query);
56 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
57 if (!$a_version or $row->version == $a_version) {
58 return new ilExportFileInfo($row->obj_id, $row->export_type, $row->filename);
59 }
60 }
61 return null;
62 }
63
64
70 public static function deleteByObjId($a_obj_id)
71 {
72 global $ilDB;
73
74 $ilDB->manipulate("DELETE FROM export_file_info WHERE obj_id = " . $ilDB->quote($a_obj_id));
75 return true;
76 }
77
78
79
85 public function setExportType($a_type)
86 {
87 $this->export_type = $a_type;
88 }
89
94 public function getExportType()
95 {
96 return $this->export_type;
97 }
98
104 public function setFilename($a_name)
105 {
106 $this->file_name = $a_name;
107 }
108
113 public function getFilename()
114 {
115 return $this->file_name;
116 }
117
118 public function getBasename($a_ext = '.zip')
119 {
120 return basename($this->getFilename(), $a_ext);
121 }
122
128 public function setObjId($a_id)
129 {
130 $this->obj_id = $a_id;
131 }
132
137 public function getObjId()
138 {
139 return $this->obj_id;
140 }
141
146 public function setVersion($a_version)
147 {
148 $this->version = $a_version;
149 }
150
155 public function getVersion()
156 {
157 return $this->version;
158 }
159
164 public function getCreationDate()
165 {
166 return $this->create_date instanceof ilDateTime ? $this->create_date : new ilDateTime(time(), IL_CAL_UNIX);
167 }
168
174 public function setCreationDate(ilDateTime $dt = null)
175 {
176 $this->create_date = $dt;
177 }
178
182 public function create()
183 {
184 global $DIC;
185
186 $db = $DIC->database();
187
188 $exists_query = 'select * from export_file_info ' .
189 'where obj_id = ' . $db->quote($this->obj_id, 'integer') . ' ' .
190 'and export_type = ' . $db->quote($this->getExportType(), 'text') . ' ' .
191 'and filename = ' . $db->quote($this->getFilename(), 'text');
192 $exists_res = $db->query($exists_query);
193
194 if (!$exists_res->numRows()) {
195 $query = "INSERT INTO export_file_info (obj_id, export_type, filename, version, create_date) " .
196 "VALUES ( " .
197 $db->quote($this->getObjId(), 'integer') . ', ' .
198 $db->quote($this->getExportType(), 'text') . ', ' .
199 $db->quote($this->getFilename(), 'text') . ', ' .
200 $db->quote($this->getVersion(), 'text') . ', ' .
201 $db->quote($this->getCreationDate()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
202 ")";
203 $db->manipulate($query);
204 }
205 }
206
211 public function delete()
212 {
213 global $ilDB;
214
215 $ilDB->manipulate(
216 'DELETE FROM export_file_info ' .
217 'WHERE obj_id = ' . $ilDB->quote($this->getObjId(), 'integer') . ' ' .
218 'AND filename = ' . $ilDB->quote($this->getFilename(), 'text')
219 );
220 return true;
221 }
222
227 protected function read()
228 {
229 global $ilDB;
230
231 $query = "SELECT * FROM export_file_info " .
232 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . ' ' .
233 "AND export_type = " . $ilDB->quote($this->getExportType(), 'text') . ' ' .
234 "AND filename = " . $ilDB->quote($this->getFilename(), 'text');
235
236 $res = $ilDB->query($query);
237 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
238 $this->setVersion($row->version);
240 }
241 return true;
242 }
243}
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.
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92