19 declare(strict_types=1);
33 class SimpleDC
implements SimpleDCInterface
36 protected NavigatorFactoryInterface $navigator_factory;
38 protected CopyrightHandlerInterface $copyright_handler;
39 protected LinkGeneratorInterface $link_generator;
43 NavigatorFactoryInterface $navigator_factory,
45 CopyrightHandlerInterface $copyright_handler,
46 LinkGeneratorInterface $link_generator
48 $this->path_factory = $path_factory;
49 $this->navigator_factory = $navigator_factory;
50 $this->data_factory = $data_factory;
51 $this->copyright_handler = $copyright_handler;
52 $this->link_generator = $link_generator;
55 public function write(
59 $xml = new \SimpleXMLElement(<<<XML
61 xmlns:oai_dc=
"http://www.openarchives.org/OAI/2.0/oai_dc/" 62 xmlns:dc=
"http://purl.org/dc/elements/1.1/" 63 xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" 64 xsi:schemaLocation=
"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
68 $this->addTitleToXML($xml, $set);
69 $this->addCreatorsPublishersAndContributorsToXML($xml, $set);
70 $this->addSubjectsToXML($xml, $set);
71 $this->addDescriptionsToXML($xml, $set);
72 $this->addDateToXML($xml, $set);
73 $this->addTypesToXML($xml, $set);
74 $this->addFormatsToXML($xml, $set);
75 $this->addIdentifierToXML($xml, $set, $object_ref_id);
76 $this->addSourcesAndRelationsToXML($xml, $set);
77 $this->addLanguagesToXML($xml, $set);
78 $this->addCoveragesToXML($xml, $set);
79 $this->addRightsToXML($xml, $set);
84 protected function addTitleToXML(\
SimpleXMLElement $xml, SetInterface $set): void
86 $title_path = $this->path_factory
88 ->withNextStep(
'general')
89 ->withNextStep(
'title')
92 $this->addLangStringsToXML($xml, $set,
'title', $title_path);
95 protected function addCreatorsPublishersAndContributorsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
97 $creator_path = $this->path_factory
99 ->withNextStep(
'lifeCycle')
100 ->withNextStep(
'contribute')
101 ->withNextStep(
'role')
102 ->withNextStep(
'value')
104 ->withNextStepToSuperElement()
105 ->withNextStepToSuperElement()
106 ->withNextStep(
'entity')
109 $publisher_path = $this->path_factory
111 ->withNextStep(
'lifeCycle')
112 ->withNextStep(
'contribute')
113 ->withNextStep(
'role')
114 ->withNextStep(
'value')
116 ->withNextStepToSuperElement()
117 ->withNextStepToSuperElement()
118 ->withNextStep(
'entity')
121 $any_contributor_path = $this->path_factory
123 ->withNextStep(
'lifeCycle')
124 ->withNextStep(
'contribute')
125 ->withNextStep(
'entity')
128 $path_from_entity_to_role = $this->path_factory
131 ->withNextStepToSuperElement()
132 ->withNextStep(
'role')
133 ->withNextStep(
'value')
137 $creator_navigator = $this->navigator_factory->navigator($creator_path, $set->getRoot());
138 foreach ($creator_navigator->elementsAtFinalStep() as $creator) {
139 $creators[] = $creator;
140 $this->addNamespacedChildToXML(
143 $creator->getData()->value()
148 $publisher_navigator = $this->navigator_factory->navigator($publisher_path, $set->getRoot());
149 foreach ($publisher_navigator->elementsAtFinalStep() as $publisher) {
150 $publishers[] = $publisher;
151 $this->addNamespacedChildToXML(
154 $publisher->getData()->value()
158 $any_contributor_navigator = $this->navigator_factory->navigator($any_contributor_path, $set->getRoot());
159 foreach ($any_contributor_navigator->elementsAtFinalStep() as $any_contributor) {
161 in_array($any_contributor, $creators,
true) ||
162 in_array($any_contributor, $publishers,
true)
167 $role = $this->navigator_factory
168 ->navigator($path_from_entity_to_role, $any_contributor)
169 ->lastElementAtFinalStep()?->getData()?->value() ??
'';
170 $contributor = $any_contributor->getData()->value();
172 $contributor .=
' (' . $role .
')';
174 $this->addNamespacedChildToXML(
182 protected function addSubjectsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
184 $keyword_path = $this->path_factory
186 ->withNextStep(
'general')
187 ->withNextStep(
'keyword')
190 $this->addLangStringsToXML($xml, $set,
'subject', $keyword_path);
192 $taxon_entry_string_path = $this->path_factory
194 ->withNextStep(
'classification')
195 ->withNextStep(
'purpose')
196 ->withNextStep(
'value')
198 ->withNextStepToSuperElement()
199 ->withNextStepToSuperElement()
200 ->withNextStep(
'taxonPath')
201 ->withNextStep(
'taxon')
202 ->withNextStep(
'entry')
203 ->withNextStep(
'string')
206 $navigator = $this->navigator_factory->navigator($taxon_entry_string_path, $set->getRoot());
208 $current_taxon_path =
null;
210 foreach ($navigator->elementsAtFinalStep() as $entry_string) {
211 $taxon_path = $entry_string->getSuperElement()->getSuperElement()->getSuperElement();
212 if ($current_taxon_path !== $taxon_path) {
213 if (!empty($strings)) {
214 $this->addNamespacedChildToXML($xml,
'subject', implode(
': ', $strings));
217 $current_taxon_path = $taxon_path;
221 if ($entry_string->getData()->value() !==
'') {
222 $strings[] = $entry_string->getData()->value();
226 if (!empty($strings)) {
227 $this->addNamespacedChildToXML($xml,
'subject', implode(
': ', $strings));
231 protected function addDescriptionsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
233 $description_path = $this->path_factory
235 ->withNextStep(
'general')
236 ->withNextStep(
'description')
239 $this->addLangStringsToXML($xml, $set,
'description', $description_path);
242 protected function addDateToXML(\
SimpleXMLElement $xml, SetInterface $set): void
244 $date_path = $this->path_factory
246 ->withNextStep(
'lifeCycle')
247 ->withNextStep(
'contribute')
248 ->withNextStep(
'date')
249 ->withAdditionalFilterAtCurrentStep(FilterType::INDEX,
'0')
252 foreach ($this->getDataValuesFromPath($set, $date_path) as $value) {
253 $this->addNamespacedChildToXML($xml,
'date', $value);
257 protected function addTypesToXML(\
SimpleXMLElement $xml, SetInterface $set): void
259 $type_path = $this->path_factory
261 ->withNextStep(
'educational')
262 ->withNextStep(
'learningResourceType')
263 ->withNextStep(
'value')
266 foreach ($this->getDataValuesFromPath($set, $type_path) as $value) {
267 $this->addNamespacedChildToXML($xml,
'type', $value);
271 protected function addFormatsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
273 $format_path = $this->path_factory
275 ->withNextStep(
'technical')
276 ->withNextStep(
'format')
279 foreach ($this->getDataValuesFromPath($set, $format_path) as $value) {
280 $this->addNamespacedChildToXML($xml,
'format', $value);
284 protected function addIdentifierToXML(
289 $type = $set->getRessourceID()->type();
294 $link = $this->link_generator->generateLinkForReference($object_ref_id, $type);
295 $this->addNamespacedChildToXML($xml,
'identifier', (
string) $link);
297 if (!$this->link_generator->doesReferenceHavePublicAccessExport($object_ref_id)) {
300 $download_link = $this->link_generator->generateLinkForPublicAccessExportOfReference($object_ref_id);
301 $this->addNamespacedChildToXML($xml,
'identifier', (
string) $download_link);
304 protected function addLanguagesToXML(\
SimpleXMLElement $xml, SetInterface $set): void
306 $language_path = $this->path_factory
308 ->withNextStep(
'general')
309 ->withNextStep(
'language')
312 foreach ($this->getDataValuesFromPath($set, $language_path) as $value) {
313 $this->addNamespacedChildToXML(
316 $value ===
'xx' ?
'none' : $value
321 protected function addSourcesAndRelationsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
323 $source_path = $this->path_factory
325 ->withNextStep(
'relation')
326 ->withNextStep(
'kind')
327 ->withNextStep(
'value')
329 ->withNextStepToSuperElement()
330 ->withNextStepToSuperElement()
331 ->withNextStep(
'resource')
332 ->withNextStep(
'identifier')
333 ->withNextStep(
'entry')
336 $any_entry_path = $this->path_factory
338 ->withNextStep(
'relation')
339 ->withNextStep(
'resource')
340 ->withNextStep(
'identifier')
341 ->withNextStep(
'entry')
345 $source_navigator = $this->navigator_factory->navigator($source_path, $set->getRoot());
346 foreach ($source_navigator->elementsAtFinalStep() as $source) {
347 $sources[] = $source;
348 $this->addNamespacedChildToXML(
351 $source->getData()->value()
355 $any_entry_navigator = $this->navigator_factory->navigator($any_entry_path, $set->getRoot());
356 foreach ($any_entry_navigator->elementsAtFinalStep() as $any_entry) {
357 if (in_array($any_entry, $sources,
true)) {
361 $this->addNamespacedChildToXML(
364 $any_entry->getData()->value()
369 protected function addCoveragesToXML(\
SimpleXMLElement $xml, SetInterface $set): void
371 $coverage_path = $this->path_factory
373 ->withNextStep(
'general')
374 ->withNextStep(
'coverage')
377 $this->addLangStringsToXML($xml, $set,
'coverage', $coverage_path);
380 protected function addRightsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
382 $description_path = $this->path_factory
384 ->withNextStep(
'rights')
385 ->withNextStep(
'description')
386 ->withNextStep(
'string')
389 foreach ($this->getDataValuesFromPath($set, $description_path) as $value) {
390 $this->addNamespacedChildToXML(
393 $this->copyright_handler->copyrightAsString($value)
398 protected function addLangStringsToXML(
404 $navigator = $this->navigator_factory->navigator($path, $set->getRoot());
405 foreach ($navigator->elementsAtFinalStep() as $element) {
406 $string_element =
null;
407 $lang_element =
null;
408 foreach ($element->getSubElements() as $sub_element) {
409 if ($sub_element->getDefinition()->name() ===
'string') {
410 $string_element = $sub_element;
412 if ($sub_element->getDefinition()->name() ===
'language') {
413 $lang_element = $sub_element;
417 if (is_null($string_element)) {
420 $string_xml = $this->addNamespacedChildToXML(
423 $string_element->getData()->value()
425 if (!is_null($lang_element) && !is_null($string_xml)) {
426 $string_xml->addAttribute(
428 $lang_element->getData()->value(),
438 protected function getDataValuesFromPath(SetInterface $set, PathInterface $path): \
Generator 440 $navigator = $this->navigator_factory->navigator($path, $set->getRoot());
441 foreach ($navigator->elementsAtFinalStep() as $element) {
442 yield $element->getData()->value();
446 protected function addNamespacedChildToXML(
454 $child_xml = $xml->addChild($name,
null,
"http://purl.org/dc/elements/1.1/");
455 $child_xml[0] = $value;
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...