ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBibliographicDataSet.php
Go to the documentation of this file.
1<?php
2
22
30{
34 private const EXP_DIRECTORY = "/Modules/Bibliographic/set_1/expDir_1/";
38 private const EXP_DIRECTORY_NEW = "/components/ILIAS/Bibliographic/set_1/expDir_1/";
42 protected $storage;
43 protected \ilObjBibliographicStakeholder $stakeholder;
51 protected $user;
52 protected array $import_temp_refs = [];
53 protected array $import_temp_refs_props = [];
54
55
56 public function __construct()
57 {
58 global $DIC;
59 $ilDB = $DIC['ilDB'];
60 $ilUser = $DIC['ilUser'];
61 $IRSS = $DIC['resource_storage'];
63 $this->db = $ilDB;
64 $this->user = $ilUser;
65 $this->storage = $IRSS;
66 $this->stakeholder = new ilObjBibliographicStakeholder();
67 }
68
69
70
71 public function getSupportedVersions(): array
72 {
73 return ['4.5.0'];
74 }
75
76
77 public function getXmlNamespace(string $a_entity, string $a_schema_version): string
78 {
79 return 'http://www.ilias.de/xml/Modules/Bibliographic/' . $a_entity;
80 }
81
82
83 public function importRecord(
84 string $a_entity,
85 array $a_types,
86 array $a_rec,
87 ilImportMapping $a_mapping,
88 string $a_schema_version
89 ): void {
90 if ($a_entity === 'bibl') {
91 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['id'])) {
92 // container content
93 $new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
94 } else {
95 $new_obj = new ilObjBibliographic();
96 }
100 $new_obj->setTitle($a_rec['title']);
101 $new_obj->setDescription($a_rec['description']);
102 $new_obj->setFilename($a_rec['fileName']);
103 if ($new_obj->getId() === 0) {
104 $new_obj->create();
105 }
106 $new_obj->getObjectProperties()->storePropertyIsOnline(
107 new Online(false)
108 );
109 $this->import_bib_object = $new_obj;
110 $a_mapping->addMapping('components/ILIAS/Bibliographic', 'bibl', $a_rec['id'], $new_obj->getId());
111 $this->importLibraryFile($a_mapping);
112 }
113 }
114
115
119 protected function getTypes(string $a_entity, string $a_version): array
120 {
121 return match ($a_entity) {
122 'bibl' => ["id" => "integer", "title" => "text", "description" => "text", "filename" => "text"],
123 default => [],
124 };
125 }
126
127
132 #[\Override]
133 protected function getDependencies(
134 string $a_entity,
135 string $a_version,
136 ?array $a_rec = null,
137 ?array $a_ids = null
138 ): array {
139 return [];
140 }
141
142
143 public function readData(string $a_entity, string $a_version, array $a_ids): void
144 {
145 $this->data = [];
146 if (!is_array($a_ids)) {
147 $a_ids = [$a_ids];
148 }
149 $this->_readData($a_entity, $a_ids);
150 }
151
152
156 protected function _readData(string $a_entity, array $a_ids): void
157 {
158 switch ($a_entity) {
159 case 'bibl':
160 foreach ($a_ids as $bibl_id) {
161 if (ilObject::_lookupType($bibl_id) === 'bibl') {
162 $obj = new ilObjBibliographic($bibl_id);
163 $data = ['id' => $bibl_id, 'title' => $obj->getTitle(), 'description' => $obj->getDescription(), 'fileName' => $obj->getFilename()];
164 $this->data[] = $data;
165 }
166 }
167 break;
168 default:
169 }
170 }
171
172
173 public function exportLibraryFile(int $a_id, string $absolute_export_dir): void
174 {
175 $obj = new ilObjBibliographic($a_id);
176 if (($rid = $obj->getResourceId()) === null) {
177 return;
178 }
179 $fileAbsolutePath = $this->irss->consume()->stream($rid)->getStream()->getMetadata()['uri'] ?? null;
180 ilFileUtils::makeDirParents($absolute_export_dir . self::EXP_DIRECTORY_NEW);
181 copy($fileAbsolutePath, $absolute_export_dir . self::EXP_DIRECTORY_NEW . $obj->getFilename());
182 }
183
184
188 public function importLibraryFile(\ilImportMapping $a_mapping): void
189 {
190 $bib_id = $this->import_bib_object->getId();
191 $filename = $this->import_bib_object->getFilename();
192 $import_path_legacy = $this->getImportDirectory() . self::EXP_DIRECTORY . $filename;
193 $import_path_new = $this->getImportDirectory() . self::EXP_DIRECTORY_NEW . $filename;
194 if (file_exists($import_path_legacy)) {
195 $import_path = $import_path_legacy;
196 } elseif (file_exists($import_path_new)) {
197 $import_path = $import_path_new;
198 } else {
199 return;
200 }
201
202 // create new resource from stream
203 $resource = @fopen($import_path, 'rb');
204
205 $stream = Streams::ofResource($resource);
206 $identification = $this->storage->manage()->stream($stream, $this->stakeholder, $filename);
207
208 // insert rid of the new resource into the data table
209 $this->db->manipulateF(
210 'UPDATE `il_bibl_data` SET `rid` = %s WHERE `id` = %s;',
211 ['text', 'integer'],
212 [
213 $identification->serialize(),
214 $bib_id,
215 ]
216 );
217 $this->import_bib_object->setResourceId($identification);
218 $this->import_bib_object->setMigrated(true);
219 $this->import_bib_object->update();
220 $this->import_bib_object->parseFileToDatabase();
221 }
222}
$filename
Definition: buildRTE.php:78
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
Bibliographic dataset class.
importLibraryFile(\ilImportMapping $a_mapping)
ilObjBibliographicStakeholder $stakeholder
_readData(string $a_entity, array $a_ids)
Build data array, data is read from cache except bibl object itself.
exportLibraryFile(int $a_id, string $absolute_export_dir)
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Return dependencies form entities to other entities (in our case these are all the DB relations)
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
Map XML attributes of entities to datatypes (text, integer...)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
Class ilObjBibliographicStakeholder.
Class ilObjBibliographic.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$data
Definition: storeScorm.php:45