ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExportFileInfo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 protected const CURRENT_VERSION = "4.1.0";
28
29 private int $obj_id = 0;
31 private string $export_type = '';
32 private string $file_name = '';
33 private ?ilDateTime $create_date = null;
34
35 protected ilDBInterface $db;
36
37 public function __construct(int $a_obj_id, string $a_export_type = '', string $a_filename = '')
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->obj_id = $a_obj_id;
43 $this->export_type = $a_export_type;
44 $this->file_name = $a_filename;
45 if ($this->getObjId() and $this->getExportType() and $this->getFilename()) {
46 $this->read();
47 }
48 }
49
53 public static function lookupLastExport(int $a_obj_id, string $a_type, string $a_version = ''): ?ilExportFileInfo
54 {
55 global $DIC;
56
57 $ilDB = $DIC->database();
58
59 $query = "SELECT * FROM export_file_info " .
60 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . ' ' .
61 "AND export_type = " . $ilDB->quote($a_type, 'text') . ' ' .
62 "ORDER BY create_date DESC";
63 $res = $ilDB->query($query);
64 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
65 if (!$a_version || $row->version == $a_version) {
66 return new ilExportFileInfo((int) $row->obj_id, $row->export_type, $row->filename);
67 }
68 }
69 return null;
70 }
71
72 public static function deleteByObjId($a_obj_id)
73 {
74 global $DIC;
75
76 $ilDB = $DIC->database();
77 $ilDB->manipulate("DELETE FROM export_file_info WHERE obj_id = " . $ilDB->quote(
78 $a_obj_id,
80 ));
81 return true;
82 }
83
84 public function setExportType(string $a_type): void
85 {
86 $this->export_type = $a_type;
87 }
88
89 public function getExportType(): string
90 {
91 return $this->export_type;
92 }
93
94 public function setFilename(string $a_name): void
95 {
96 $this->file_name = $a_name;
97 }
98
99 public function getFilename(): string
100 {
101 return $this->file_name;
102 }
103
104 public function getBasename(string $a_ext = '.zip'): string
105 {
106 return basename($this->getFilename(), $a_ext);
107 }
108
109 public function setObjId(int $a_id): void
110 {
111 $this->obj_id = $a_id;
112 }
113
114 public function getObjId(): int
115 {
116 return $this->obj_id;
117 }
118
119 public function setVersion(string $a_version): void
120 {
121 $this->version = $a_version;
122 }
123
124 public function getVersion(): string
125 {
126 return $this->version;
127 }
128
129 public function getCreationDate(): ilDateTime
130 {
131 return $this->create_date instanceof ilDateTime ? $this->create_date : new ilDateTime(time(), IL_CAL_UNIX);
132 }
133
134 public function setCreationDate(?ilDateTime $dt = null)
135 {
136 $this->create_date = $dt;
137 }
138
139 public function create(): void
140 {
141 $exists_query = 'select * from export_file_info ' .
142 'where obj_id = ' . $this->db->quote($this->obj_id, 'integer') . ' ' .
143 'and export_type = ' . $this->db->quote($this->getExportType(), 'text') . ' ' .
144 'and filename = ' . $this->db->quote($this->getFilename(), 'text');
145 $exists_res = $this->db->query($exists_query);
146
147 if (!$exists_res->numRows()) {
148 $query = "INSERT INTO export_file_info (obj_id, export_type, filename, version, create_date) " .
149 "VALUES ( " .
150 $this->db->quote($this->getObjId(), 'integer') . ', ' .
151 $this->db->quote($this->getExportType(), 'text') . ', ' .
152 $this->db->quote($this->getFilename(), 'text') . ', ' .
153 $this->db->quote($this->getVersion(), 'text') . ', ' .
154 $this->db->quote(
156 'timestamp'
157 ) . ' ' .
158 ")";
159 $this->db->manipulate($query);
160 }
161 }
162
163 public function delete(): void
164 {
165 $this->db->manipulate(
166 'DELETE FROM export_file_info ' .
167 'WHERE obj_id = ' . $this->db->quote($this->getObjId(), 'integer') . ' ' .
168 'AND filename = ' . $this->db->quote($this->getFilename(), 'text')
169 );
170 }
171
172 protected function read(): void
173 {
174 $query = "SELECT * FROM export_file_info " .
175 "WHERE obj_id = " . $this->db->quote($this->getObjId(), 'integer') . ' ' .
176 "AND export_type = " . $this->db->quote($this->getExportType(), 'text') . ' ' .
177 "AND filename = " . $this->db->quote($this->getFilename(), 'text');
178
179 $res = $this->db->query($query);
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $this->setVersion($row->version);
182 $this->setCreationDate(new ilDateTime($row->create_date, IL_CAL_DATETIME, ilTimeZone::UTC));
183 }
184 }
185}
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
@classDescription Stores information of creation date and versions of export files
static deleteByObjId($a_obj_id)
static lookupLastExport(int $a_obj_id, string $a_type, string $a_version='')
Lookup last export.
setFilename(string $a_name)
__construct(int $a_obj_id, string $a_export_type='', string $a_filename='')
getBasename(string $a_ext='.zip')
setVersion(string $a_version)
setCreationDate(?ilDateTime $dt=null)
setExportType(string $a_type)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26