ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMDKeywordExposer.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
24 use ILIAS\MetaData\Services\Services as Metadata;
26 
33 {
34  protected Metadata $md;
35 
36  public function __construct(\ILIAS\DI\Container $dic)
37  {
38  $this->md = $dic->learningObjectMetadata();
39  parent::__construct($dic);
40  }
41 
43  {
44  return $this->context_collection->repository();
45  }
46 
47  public function getContentModification(CalledContexts $screen_context_stack): ?ContentModification
48  {
49  if ($screen_context_stack->current()->hasReferenceId()) {
50  $object_id = $screen_context_stack->current()->getReferenceId()->toObjectId()->toInt();
51  $paths = $this->md->paths();
52  $reader = $this->generalReader($object_id);
53 
54  // Keywords
55  $keywords = [];
56  foreach ($reader->allData($paths->keywords()) as $keyword) {
57  $keywords[] = $keyword->value();
58  }
59  if (count($keywords) > 0) {
60  $this->globalScreen()->layout()->meta()->addMetaDatum(
61  $this->data->htmlMetadata()->userDefined('keywords', implode(',', $keywords))
62  );
63  }
64 
65  // Languages
66  $languages = [];
67  foreach ($reader->allData($paths->languages()) as $language) {
68  $languages[] = $language->value();
69  }
70  if (count($languages) > 0) {
71  $this->globalScreen()->layout()->meta()->addMetaDatum(
72  $this->data->htmlMetadata()->userDefined('languages', implode(',', $languages))
73  );
74  }
75 
76  if ($settings = ilMDSettings::_getInstance()->isCopyrightSelectionActive()) {
77  $reader = $this->copyrightReader($object_id);
78  // Copyright
79  $copyright = $reader->firstData($paths->copyright())->value();
80  $copyright_id = ilMDCopyrightSelectionEntry::_extractEntryId($copyright);
81  if ($copyright_id > 0) {
82  $entry = new ilMDCopyrightSelectionEntry($copyright_id);
83  $copyright = $entry->getTitle();
84  }
85  if ($copyright === '') {
87  $copyright = $entry->getTitle();
88  }
89  $this->globalScreen()->layout()->meta()->addMetaDatum(
90  $this->data->htmlMetadata()->userDefined('copyright', $copyright)
91  );
92  }
93  }
94 
95  return null;
96  }
97 
98  protected function generalReader(int $object_id): Reader
99  {
100  $path = $this->md->paths()->custom()->withNextStep('general')->get();
101  return $this->md->read(
102  $object_id,
103  $object_id,
104  ilObject::_lookupType($object_id),
105  $path
106  );
107  }
108 
109  protected function copyrightReader(int $object_id): Reader
110  {
111  $path = $this->md->paths()->custom()
112  ->withNextStep('rights')
113  ->withNextStep('description')
114  ->withNextStep('string')
115  ->get();
116  return $this->md->read(
117  $object_id,
118  $object_id,
119  ilObject::_lookupType($object_id),
120  $path
121  );
122  }
123 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ChatMainBarProvider .
__construct(\ILIAS\DI\Container $dic)
$path
Definition: ltiservices.php:32
__construct(VocabulariesInterface $vocabularies)
Class HTTPServicesTest.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getContentModification(CalledContexts $screen_context_stack)
Class ilMDKeywordExposer.
static _lookupType(int $id, bool $reference=false)