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')
250 ->withNextStep(
'dateTime')
253 foreach ($this->getDataValuesFromPath($set, $date_path) as $value) {
254 $this->addNamespacedChildToXML($xml,
'date', $value);
258 protected function addTypesToXML(\
SimpleXMLElement $xml, SetInterface $set): void
260 $type_path = $this->path_factory
262 ->withNextStep(
'educational')
263 ->withNextStep(
'learningResourceType')
264 ->withNextStep(
'value')
267 foreach ($this->getDataValuesFromPath($set, $type_path) as $value) {
268 $this->addNamespacedChildToXML($xml,
'type', $value);
272 protected function addFormatsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
274 $format_path = $this->path_factory
276 ->withNextStep(
'technical')
277 ->withNextStep(
'format')
280 foreach ($this->getDataValuesFromPath($set, $format_path) as $value) {
281 $this->addNamespacedChildToXML($xml,
'format', $value);
285 protected function addIdentifierToXML(
290 $type = $set->getRessourceID()->type();
295 $link = $this->link_generator->generateLinkForReference($object_ref_id, $type);
296 $this->addNamespacedChildToXML($xml,
'identifier', (
string) $link);
298 if (!$this->link_generator->doesReferenceHavePublicAccessExport($object_ref_id)) {
301 $download_link = $this->link_generator->generateLinkForPublicAccessExportOfReference($object_ref_id);
302 $this->addNamespacedChildToXML($xml,
'identifier', (
string) $download_link);
305 protected function addLanguagesToXML(\
SimpleXMLElement $xml, SetInterface $set): void
307 $language_path = $this->path_factory
309 ->withNextStep(
'general')
310 ->withNextStep(
'language')
313 foreach ($this->getDataValuesFromPath($set, $language_path) as $value) {
314 $this->addNamespacedChildToXML(
317 $value ===
'xx' ?
'none' : $value
322 protected function addSourcesAndRelationsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
324 $source_path = $this->path_factory
326 ->withNextStep(
'relation')
327 ->withNextStep(
'kind')
328 ->withNextStep(
'value')
330 ->withNextStepToSuperElement()
331 ->withNextStepToSuperElement()
332 ->withNextStep(
'resource')
333 ->withNextStep(
'identifier')
334 ->withNextStep(
'entry')
337 $any_entry_path = $this->path_factory
339 ->withNextStep(
'relation')
340 ->withNextStep(
'resource')
341 ->withNextStep(
'identifier')
342 ->withNextStep(
'entry')
346 $source_navigator = $this->navigator_factory->navigator($source_path, $set->getRoot());
347 foreach ($source_navigator->elementsAtFinalStep() as $source) {
348 $sources[] = $source;
349 $this->addNamespacedChildToXML(
352 $source->getData()->value()
356 $any_entry_navigator = $this->navigator_factory->navigator($any_entry_path, $set->getRoot());
357 foreach ($any_entry_navigator->elementsAtFinalStep() as $any_entry) {
358 if (in_array($any_entry, $sources,
true)) {
362 $this->addNamespacedChildToXML(
365 $any_entry->getData()->value()
370 protected function addCoveragesToXML(\
SimpleXMLElement $xml, SetInterface $set): void
372 $coverage_path = $this->path_factory
374 ->withNextStep(
'general')
375 ->withNextStep(
'coverage')
378 $this->addLangStringsToXML($xml, $set,
'coverage', $coverage_path);
381 protected function addRightsToXML(\
SimpleXMLElement $xml, SetInterface $set): void
383 $description_path = $this->path_factory
385 ->withNextStep(
'rights')
386 ->withNextStep(
'description')
387 ->withNextStep(
'string')
390 foreach ($this->getDataValuesFromPath($set, $description_path) as $value) {
391 $this->addNamespacedChildToXML(
394 $this->copyright_handler->copyrightAsString($value)
399 protected function addLangStringsToXML(
405 $navigator = $this->navigator_factory->navigator($path, $set->getRoot());
406 foreach ($navigator->elementsAtFinalStep() as $element) {
407 $string_element = null;
408 $lang_element = null;
409 foreach ($element->getSubElements() as $sub_element) {
410 if ($sub_element->getDefinition()->name() ===
'string') {
411 $string_element = $sub_element;
413 if ($sub_element->getDefinition()->name() ===
'language') {
414 $lang_element = $sub_element;
418 if (is_null($string_element)) {
421 $string_xml = $this->addNamespacedChildToXML(
424 $string_element->getData()->value()
426 if (!is_null($lang_element) && !is_null($string_xml)) {
427 $string_xml->addAttribute(
429 $lang_element->getData()->value(),
439 protected function getDataValuesFromPath(SetInterface $set, PathInterface $path): \
Generator 441 $navigator = $this->navigator_factory->navigator($path, $set->getRoot());
442 foreach ($navigator->elementsAtFinalStep() as $element) {
443 yield $element->getData()->value();
447 protected function addNamespacedChildToXML(
455 $child_xml = $xml->addChild($name, null,
"http://purl.org/dc/elements/1.1/");
456 $child_xml[0] = $value;
__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...