ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjBibliographic.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
15{
16
50 protected $filename;
56 protected $entries;
62 protected $is_online;
66 protected $file_type = 0;
67
68
74 public function initType()
75 {
76 $this->type = "bibl";
77 }
78
79
87 public function __construct($existant_bibl_id = 0)
88 {
89 if ($existant_bibl_id) {
90 $this->setId($existant_bibl_id);
91 $this->doRead();
92 }
93 parent::__construct($existant_bibl_id, false);
94
95 $this->bib_type_factory = new ilBiblTypeFactory();
96 $this->bib_field_factory = new ilBiblFieldFactory($this->bib_type_factory->getInstanceForType($this->getFileType()));
97 $this->bib_overview_factory = new ilBiblOverviewModelFactory();
98 $this->bib_entry_factory = new ilBiblEntryFactory($this->bib_field_factory, $this->bib_type_factory->getInstanceForType($this->getFileType()), $this->bib_overview_factory);
99 $this->bib_filereader_factory = new ilBiblFileReaderFactory();
100 $this->bib_attribute_factory = new ilBiblAttributeFactory($this->bib_field_factory);
101 }
102
103
109 protected function doCreate()
110 {
111 global $DIC;
112
113 $upload = $DIC->upload();
114 if ($upload->hasUploads() && !$upload->hasBeenProcessed()) {
115 $upload->process();
116 $this->moveUploadedFile($upload);
117 }
118
119 $DIC->database()->insert(
120 "il_bibl_data",
121 [
122 "id" => ["integer", $this->getId()], "filename" => ["text", $this->getFilename()], "is_online" => ["integer", $this->getOnline()], "file_type" => ["integer", $this->getFilename() ? $this->determineFileTypeByFileName($this->getFilename()) : ""],
123 ]
124 );
125 }
126
127
128 protected function doRead()
129 {
130 global $DIC;
131 $ilDB = $DIC['ilDB'];
132 $ilBiblData = ilBiblData::where(array('id' => $this->getId()))->first();
133 if (!$this->getFilename()) {
134 $this->setFilename($ilBiblData->getFilename());
135 }
136 $this->setFileType($ilBiblData->getFileType());
137 $this->setOnline($ilBiblData->getIsOnline());
138 }
139
140
141 public function doUpdate()
142 {
143 global $DIC;
144
145 $upload = $DIC->upload();
146 // bugfix mantis 26050
147 $has_valid_upload = false;
148 if ($upload->hasBeenProcessed()) {
149 if (!empty($this->getFilename())) {
150 $has_valid_upload = true;
151 }
152 } else {
153 if ($upload->hasUploads()) {
154 $has_valid_upload = true;
155 }
156 }
157
158 if ($_POST['override_entries'] && $has_valid_upload) {
159 $upload->process();
160 $this->deleteFile();
161 $this->moveUploadedFile($upload);
162 }
163 if ($has_valid_upload) {
164 // Delete the object, but leave the db table 'il_bibl_data' for being able to update it using WHERE, and also leave the file
165 $this->doDelete(true, true);
166 $this->parseFileToDatabase();
167 }
168
169 $DIC->database()->update(
170 "il_bibl_data",
171 [
172 "filename" => ["text", $this->getFilename()], "is_online" => ["integer", $this->getOnline()], "file_type" => ["integer", $this->getFileType()],
173 ],
174 ["id" => ["integer", $this->getId()]]
175 );
176 }
177
178
183 protected function doDelete($leave_out_il_bibl_data = false, $leave_out_delete_file = false)
184 {
185 global $DIC;
186 $ilDB = $DIC['ilDB'];
187 if (!$leave_out_delete_file) {
188 $this->deleteFile();
189 }
190 //il_bibl_attribute
191 $ilDB->manipulate(
192 "DELETE FROM il_bibl_attribute WHERE il_bibl_attribute.entry_id IN " . "(SELECT il_bibl_entry.id FROM il_bibl_entry WHERE il_bibl_entry.data_id = " . $ilDB->quote($this->getId(), "integer") . ")"
193 );
194 //il_bibl_entry
195 $this->bib_entry_factory->deleteEntryById($this->getId());
196
197 if (!$leave_out_il_bibl_data) {
198 //il_bibl_data
199 $ilDB->manipulate(
200 "DELETE FROM il_bibl_data WHERE id = " . $ilDB->quote($this->getId(), "integer")
201 );
202 }
203 // delete history entries
205 }
206
207
211 public function getFileDirectory()
212 {
213 return "{$this->getType()}/{$this->getId()}";
214 }
215
216
220 protected function moveUploadedFile(\ILIAS\FileUpload\FileUpload $upload)
221 {
225 $result = array_values($upload->getResults())[0];
226 if ($result->getStatus() == \ILIAS\FileUpload\DTO\ProcessingStatus::OK) {
227 $this->deleteFile();
228 $upload->moveFilesTo($this->getFileDirectory(), \ILIAS\FileUpload\Location::STORAGE);
229 $this->setFilename($result->getName());
230 }
231 }
232
233
237 private function copyFile($file_to_copy)
238 {
239 $target = $this->getFileDirectory() . '/' . basename($file_to_copy);
240 $this->getFileSystem()->copy($file_to_copy, $target);
241 }
242
243
247 protected function deleteFile()
248 {
249 $path = $this->getFileDirectory();
250 try {
251 $this->getFileSystem()->deleteDir($path);
252 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
253 return false;
254 }
255
256 return true;
257 }
258
259
263 private function getFileSystem()
264 {
265 global $DIC;
266
267 return $DIC["filesystem"]->storage();
268 }
269
270
276 public function getFilePath($without_filename = false)
277 {
278 $file_name = $this->getFilename();
279
280 if ($without_filename) {
281 return substr($file_name, 0, strrpos($file_name, DIRECTORY_SEPARATOR));
282 } else {
283 return $file_name;
284 }
285 }
286
287
291 public function setFilename($filename)
292 {
293 $this->filename = $filename;
294 }
295
296
300 public function getFilename()
301 {
302 return $this->filename;
303 }
304
305
310 public function getFileAbsolutePath()
311 {
312 return $this->getFileDirectory() . DIRECTORY_SEPARATOR . $this->getFilename();
313 }
314
315
316 public function getLegacyAbsolutePath()
317 {
318 $stream = $this->getFileSystem()->readStream($this->getFileAbsolutePath());
319
320 return $stream->getMetadata('uri');
321 }
322
323
328 public function getFileTypeAsString()
329 {
330 $type = $this->getFileType();
331
332 return $this->bib_type_factory->getInstanceForType($type)->getStringRepresentation();
333 }
334
335
339 public function getFileType()
340 {
341 $filename = $this->getFilename();
342 if ($filename === null) {
344 }
345 $instance = $this->bib_type_factory->getInstanceForFileName($filename);
346
347 return $instance->getId();
348 }
349
350
360 public function doCloneObject($new_obj, $a_target_id, $a_copy_id = null, $a_omit_tree = false)
361 {
362 assert($new_obj instanceof ilObjBibliographic);
363 //copy online status if object is not the root copy object
364 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
365
366 if (!$cp_options->isRootNode($this->getRefId())) {
367 $new_obj->setOnline($this->getOnline());
368 }
369
370 $new_obj->cloneStructure($this->getId());
371
372 $new_obj->parseFileToDatabase();
373
374 return $new_obj;
375 }
376
377
387 public function cloneStructure($original_id)
388 {
389 $original = new ilObjBibliographic($original_id);
390 $this->setFilename($original->getFilename());
391 $this->copyFile($original->getFileAbsolutePath());
392 $this->setDescription($original->getDescription());
393 $this->setTitle($original->getTitle());
394 $this->setType($original->getType());
395 $this->doUpdate();
396 }
397
398
404 public function parseFileToDatabase()
405 {
406 //Read File
407 $type = $this->getFileType();
408 $reader = $this->bib_filereader_factory->getByType($type, $this->bib_entry_factory, $this->bib_field_factory, $this->bib_attribute_factory);
409 $reader->readContent($this->getFileAbsolutePath());
410 $this->entries = $reader->parseContentToEntries($this);
411 }
412
413
417 public function setFileType($file_type)
418 {
419 $this->file_type = $file_type;
420 }
421
422
426 public function setOnline($a_online)
427 {
428 $this->is_online = $a_online;
429 }
430
431
435 public function getOnline()
436 {
437 return $this->is_online;
438 }
439
440
447 {
448 return $this->bib_type_factory->getInstanceForFileName($filename)->getId();
449 }
450}
$result
$path
Definition: aliased.php:25
$_POST["username"]
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
Class ilBiblAttributeFactory.
Class ilBiblEntryFactory.
Class ilBiblFieldFactory.
Class ilBiblFileReaderFactory.
Class ilBiblOverviewModelFactory.
Class ilBiblTypeFactory.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
Class ilObjBibliographic.
doDelete($leave_out_il_bibl_data=false, $leave_out_delete_file=false)
cloneStructure($original_id)
@description Attention only use this for objects who have not yet been created (use like: $x = new il...
__construct($existant_bibl_id=0)
If bibliographic object exists, read it's data from database, otherwise create it.
parseFileToDatabase()
Reads out the source file and writes all entries to the database.
doCloneObject($new_obj, $a_target_id, $a_copy_id=null, $a_omit_tree=false)
Clone BIBL.
getFilePath($without_filename=false)
Class ilObject2 This is an intermediate progress of ilObject class.
setType($a_type)
set object type @access public
setTitle($a_title)
set object title
setDescription($a_desc)
set object description
getId()
get object id @access public
setId($a_id)
set object id @access public
$target
Definition: test.php:19
Class FlySystemFileAccessTest.
$stream
PHP stream implementation.
Class BaseForm.
global $DIC
Definition: saml.php:7
global $ilDB