ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMDKeywordExposer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27
34{
35 protected Metadata $md;
36
37 public function __construct(\ILIAS\DI\Container $dic)
38 {
39 $this->md = $dic->learningObjectMetadata();
41 }
42
44 {
45 return $this->context_collection->repository();
46 }
47
48 public function getContentModification(CalledContexts $screen_context_stack): ?ContentModification
49 {
50 if ($screen_context_stack->current()->hasReferenceId()) {
51 $object_id = $screen_context_stack->current()->getReferenceId()->toObjectId()->toInt();
52 $paths = $this->md->paths();
53 $reader = $this->generalReader($object_id);
54
55 // Keywords
56 $keywords = [];
57 foreach ($reader->allData($paths->keywords()) as $keyword) {
58 $keywords[] = $keyword->value();
59 }
60 if (count($keywords) > 0) {
61 $this->globalScreen()->layout()->meta()->addMetaDatum(
62 $this->data->htmlMetadata()->userDefined('keywords', implode(',', $keywords))
63 );
64 }
65
66 // Languages
67 $languages = [];
68 foreach ($reader->allData($paths->languages()) as $language) {
69 $languages[] = $language->value();
70 }
71 if (count($languages) > 0) {
72 $this->globalScreen()->layout()->meta()->addMetaDatum(
73 $this->data->htmlMetadata()->userDefined('languages', implode(',', $languages))
74 );
75 }
76
77 // Copyright
78 if ($this->md->copyrightHelper()->isCopyrightSelectionActive()) {
79 $reader = $this->copyrightReader($object_id);
80 if ($this->md->copyrightHelper()->hasPresetCopyright($reader)) {
81 $copyright = $this->md->copyrightHelper()->readPresetCopyright($reader)->presentAsString();
82 } else {
83 $copyright = $this->md->copyrightHelper()->readCustomCopyright($reader);
84 }
85 $this->globalScreen()->layout()->meta()->addMetaDatum(
86 $this->data->htmlMetadata()->userDefined('copyright', $copyright)
87 );
88 }
89 }
90
91 return null;
92 }
93
94 protected function generalReader(int $object_id): Reader
95 {
96 $path = $this->md->paths()->custom()->withNextStep('general')->get();
97 return $this->md->read(
98 $object_id,
99 $object_id,
100 ilObject::_lookupType($object_id),
101 $path
102 );
103 }
104
105 protected function copyrightReader(int $object_id): Reader
106 {
107 $path = $this->md->paths()->custom()
108 ->withNextStep('rights')
109 ->withNextStep('description')
110 ->withNextStep('string')
111 ->get();
112 return $this->md->read(
113 $object_id,
114 $object_id,
115 ilObject::_lookupType($object_id),
116 $path
117 );
118 }
119}
Class ilMDKeywordExposer.
getContentModification(CalledContexts $screen_context_stack)
@inheritDoc
__construct(\ILIAS\DI\Container $dic)
static _lookupType(int $id, bool $reference=false)
$dic
Definition: ltiresult.php:33
$path
Definition: ltiservices.php:30
Class HTTPServicesTest.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.