ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $this->parseFileToDatabase();
118 }
119
120 $DIC->database()->insert(
121 "il_bibl_data",
122 [
123 "id" => ["integer", $this->getId()],
124 "filename" => ["text", $this->getFilename()],
125 "is_online" => ["integer", $this->getOnline()],
126 "file_type" => ["integer", $this->getFilename() ? $this->determineFileTypeByFileName($this->getFilename()) : ""],
127 ]
128 );
129 }
130
131
132 protected function doRead()
133 {
134 global $DIC;
135 $ilDB = $DIC['ilDB'];
136 $ilBiblData = ilBiblData::where(array('id' => $this->getId()))->first();
137 if (!$this->getFilename()) {
138 $this->setFilename($ilBiblData->getFilename());
139 }
140 $this->setFileType($ilBiblData->getFileType());
141 $this->setOnline($ilBiblData->getIsOnline());
142 }
143
144
145 public function doUpdate()
146 {
147 global $DIC;
148
149 $upload = $DIC->upload();
150 $has_valid_upload = $upload->hasUploads() && !$upload->hasBeenProcessed();
151 if ($_POST['override_entries'] && $has_valid_upload) {
152 $upload->process();
153 $this->deleteFile();
154 $this->moveUploadedFile($upload);
155 }
156 if ($has_valid_upload) {
157 // Delete the object, but leave the db table 'il_bibl_data' for being able to update it using WHERE, and also leave the file
158 $this->doDelete(true, true);
159 $this->parseFileToDatabase();
160 }
161
162 $DIC->database()->update(
163 "il_bibl_data",
164 [
165 "filename" => ["text", $this->getFilename()],
166 "is_online" => ["integer", $this->getOnline()],
167 "file_type" => ["integer", $this->getFileType()],
168 ],
169 ["id" => ["integer", $this->getId()]]
170 );
171 }
172
173
178 protected function doDelete($leave_out_il_bibl_data = false, $leave_out_delete_file = false)
179 {
180 global $DIC;
181 $ilDB = $DIC['ilDB'];
182 if (!$leave_out_delete_file) {
183 $this->deleteFile();
184 }
185 //il_bibl_attribute
186 $ilDB->manipulate(
187 "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(
188 $this->getId(),
189 "integer"
190 ) . ")"
191 );
192 //il_bibl_entry
193 $this->bib_entry_factory->deleteEntryById($this->getId());
194
195 if (!$leave_out_il_bibl_data) {
196 //il_bibl_data
197 $ilDB->manipulate(
198 "DELETE FROM il_bibl_data WHERE id = " . $ilDB->quote($this->getId(), "integer")
199 );
200 }
201 // delete history entries
203 }
204
205
209 public function getFileDirectory()
210 {
211 return "{$this->getType()}/{$this->getId()}";
212 }
213
214
218 protected function moveUploadedFile(\ILIAS\FileUpload\FileUpload $upload)
219 {
223 $result = array_values($upload->getResults())[0];
224 if ($result->getStatus() == \ILIAS\FileUpload\DTO\ProcessingStatus::OK) {
225 $this->deleteFile();
226 $upload->moveFilesTo($this->getFileDirectory(), \ILIAS\FileUpload\Location::STORAGE);
227 $this->setFilename($result->getName());
228 }
229 }
230
231
235 private function copyFile($file_to_copy)
236 {
237 $target = $this->getFileDirectory() . '/' . basename($file_to_copy);
238 $this->getFileSystem()->copy($file_to_copy, $target);
239 }
240
241
245 protected function deleteFile()
246 {
247 $path = $this->getFileDirectory();
248 try {
249 $this->getFileSystem()->deleteDir($path);
250 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
251 return false;
252 }
253
254 return true;
255 }
256
257
261 private function getFileSystem()
262 {
263 global $DIC;
264
265 return $DIC["filesystem"]->storage();
266 }
267
268
274 public function getFilePath($without_filename = false)
275 {
276 $file_name = $this->getFilename();
277
278 if ($without_filename) {
279 return substr($file_name, 0, strrpos($file_name, DIRECTORY_SEPARATOR));
280 } else {
281 return $file_name;
282 }
283 }
284
285
289 public function setFilename($filename)
290 {
291 $this->filename = $filename;
292 }
293
294
298 public function getFilename()
299 {
300 return $this->filename;
301 }
302
303
308 public function getFileAbsolutePath()
309 {
310 return $this->getFileDirectory() . DIRECTORY_SEPARATOR . $this->getFilename();
311 }
312
313
314 public function getLegacyAbsolutePath()
315 {
316 $stream = $this->getFileSystem()->readStream($this->getFileAbsolutePath());
317
318 return $stream->getMetadata('uri');
319 }
320
321
326 public function getFileTypeAsString()
327 {
328 $type = $this->getFileType();
329
330 return $this->bib_type_factory->getInstanceForType($type)->getStringRepresentation();
331 }
332
333
337 public function getFileType()
338 {
339 $filename = $this->getFilename();
340 if ($filename === null) {
342 }
343 $instance = $this->bib_type_factory->getInstanceForFileName($filename);
344
345 return $instance->getId();
346 }
347
348
358 public function doCloneObject($new_obj, $a_target_id, $a_copy_id = null, $a_omit_tree = false)
359 {
360 assert($new_obj instanceof ilObjBibliographic);
361 //copy online status if object is not the root copy object
362 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
363
364 if (!$cp_options->isRootNode($this->getRefId())) {
365 $new_obj->setOnline($this->getOnline());
366 }
367
368 $new_obj->cloneStructure($this->getId());
369
370 $new_obj->parseFileToDatabase();
371
372 return $new_obj;
373 }
374
375
385 public function cloneStructure($original_id)
386 {
387 $original = new ilObjBibliographic($original_id);
388 $this->setFilename($original->getFilename());
389 $this->copyFile($original->getFileAbsolutePath());
390 $this->setDescription($original->getDescription());
391 $this->setTitle($original->getTitle());
392 $this->setType($original->getType());
393 $this->doUpdate();
394 }
395
396
402 public function parseFileToDatabase()
403 {
404 //Read File
405 $type = $this->getFileType();
406 $reader = $this->bib_filereader_factory->getByType($type, $this->bib_entry_factory, $this->bib_field_factory, $this->bib_attribute_factory);
407 $reader->readContent($this->getFileAbsolutePath());
408 $this->entries = $reader->parseContentToEntries($this);
409 }
410
411
415 public function setFileType($file_type)
416 {
417 $this->file_type = $file_type;
418 }
419
420
424 public function setOnline($a_online)
425 {
426 $this->is_online = $a_online;
427 }
428
429
433 public function getOnline()
434 {
435 return $this->is_online;
436 }
437
438
445 {
446 return $this->bib_type_factory->getInstanceForFileName($filename)->getId();
447 }
448}
$result
$_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
setId($a_id)
set object id @access public
getId()
get object id @access public
global $DIC
Definition: goto.php:24
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
global $ilDB