ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBibliographicDataSet.php
Go to the documentation of this file.
1 <?php
29 
37 {
41  protected $storage;
42  protected \ilObjBibliographicStakeholder $stakeholder;
46  protected $import_bib_object;
50  protected $user;
51  protected array $import_temp_refs = array();
52  protected array $import_temp_refs_props = array();
53 
54 
55  public function __construct()
56  {
57  global $DIC;
58  $ilDB = $DIC['ilDB'];
59  $ilUser = $DIC['ilUser'];
60  $IRSS = $DIC['resource_storage'];
62  $this->db = $ilDB;
63  $this->user = $ilUser;
64  $this->storage = $IRSS;
65  $this->stakeholder = new ilObjBibliographicStakeholder();
66  }
67 
68 
69  public function getSupportedVersions(): array
70  {
71  return array('4.5.0');
72  }
73 
74 
75  public function getXmlNamespace(string $a_entity, string $a_schema_version): string
76  {
77  return 'http://www.ilias.de/xml/Modules/Bibliographic/' . $a_entity;
78  }
79 
80 
81  public function importRecord(
82  string $a_entity,
83  array $a_types,
84  array $a_rec,
85  ilImportMapping $a_mapping,
86  string $a_schema_version
87  ): void {
88  switch ($a_entity) {
89  case 'bibl':
90  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['id'])) {
91  // container content
92  $new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
93  } else {
94  $new_obj = new ilObjBibliographic();
95  }
99  $new_obj->setTitle($a_rec['title']);
100  $new_obj->setDescription($a_rec['description']);
101  $new_obj->setFilename($a_rec['fileName']);
102  if (!$new_obj->getId()) {
103  $new_obj->create();
104  }
105  $new_obj->getObjectProperties()->storePropertyIsOnline(
106  new ilObjectPropertyIsOnline(false)
107  );
108  $this->import_bib_object = $new_obj;
109  $a_mapping->addMapping('Modules/Bibliographic', 'bibl', $a_rec['id'], $new_obj->getId());
110  $this->importLibraryFile($a_mapping);
111  break;
112  }
113  }
114 
115 
119  protected function getTypes(string $a_entity, string $a_version): array
120  {
121  switch ($a_entity) {
122  case 'bibl':
123  return array(
124  "id" => "integer",
125  "title" => "text",
126  "description" => "text",
127  "filename" => "text"
128  );
129  default:
130  return array();
131  }
132  }
133 
134 
139  protected function getDependencies(
140  string $a_entity,
141  string $a_version,
142  ?array $a_rec = null,
143  ?array $a_ids = null
144  ): array {
145  return [];
146  }
147 
148 
149  public function readData(string $a_entity, string $a_version, array $a_ids): void
150  {
151  $this->data = array();
152  if (!is_array($a_ids)) {
153  $a_ids = array($a_ids);
154  }
155  $this->_readData($a_entity, $a_ids);
156  }
157 
158 
162  protected function _readData(string $a_entity, array $a_ids): void
163  {
164  switch ($a_entity) {
165  case 'bibl':
166  foreach ($a_ids as $bibl_id) {
167  if (ilObject::_lookupType($bibl_id) === 'bibl') {
168  $obj = new ilObjBibliographic($bibl_id);
169  $data = array(
170  'id' => $bibl_id,
171  'title' => $obj->getTitle(),
172  'description' => $obj->getDescription(),
173  'fileName' => $obj->getFilename()
174  );
175  $this->data[] = $data;
176  }
177  }
178  break;
179  default:
180  }
181  }
182 
183 
184  public function exportLibraryFile(int $a_id): void
185  {
186  $obj = new ilObjBibliographic($a_id);
187  $fileAbsolutePath = $obj->getLegacyAbsolutePath();
188  copy($fileAbsolutePath, $this->absolute_export_dir . "/" . $obj->getFilename());
189  }
190 
191 
195  public function importLibraryFile(\ilImportMapping $a_mapping): void
196  {
197  $bib_id = $this->import_bib_object->getId();
198  $filename = $this->import_bib_object->getFilename();
199  $import_path = $this->getImportDirectory() . "/Modules/Bibliographic/set_1/expDir_1/" . $filename;
200 
201  // create new resource from stream
202  $stream = Streams::ofResource(@fopen($import_path, 'rb'));
203  $identification = $this->storage->manage()->stream($stream, $this->stakeholder, $filename);
204 
205  // insert rid of the new resource into the data table
206  $this->db->manipulateF(
207  'UPDATE `il_bibl_data` SET `rid` = %s WHERE `id` = %s;',
208  ['text', 'integer'],
209  [
210  $identification->serialize(),
211  $bib_id,
212  ]
213  );
214  }
215 }
importLibraryFile(\ilImportMapping $a_mapping)
readData(string $a_entity, string $a_version, array $a_ids)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Bibliographic dataset class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
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) ...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
global $DIC
Definition: feed.php:28
_readData(string $a_entity, array $a_ids)
Build data array, data is read from cache except bibl object itself.
__construct(VocabulariesInterface $vocabularies)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getTypes(string $a_entity, string $a_version)
Map XML attributes of entities to datatypes (text, integer...)
Class ilObjBibliographicStakeholder.
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.
$filename
Definition: buildRTE.php:78
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilObjBibliographicStakeholder $stakeholder
Class ilObjBibliographic.
static _lookupType(int $id, bool $reference=false)