ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilMDKeywordExposer.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
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  // Copyright
77  if ($this->md->copyrightHelper()->isCopyrightSelectionActive()) {
78  $reader = $this->copyrightReader($object_id);
79  if ($this->md->copyrightHelper()->hasPresetCopyright($reader)) {
80  $copyright = $this->md->copyrightHelper()->readPresetCopyright($reader)->presentAsString();
81  } else {
82  $copyright = $this->md->copyrightHelper()->readCustomCopyright($reader);
83  }
84  $this->globalScreen()->layout()->meta()->addMetaDatum(
85  $this->data->htmlMetadata()->userDefined('copyright', $copyright)
86  );
87  }
88  }
89 
90  return null;
91  }
92 
93  protected function generalReader(int $object_id): Reader
94  {
95  $path = $this->md->paths()->custom()->withNextStep('general')->get();
96  return $this->md->read(
97  $object_id,
98  $object_id,
99  ilObject::_lookupType($object_id),
100  $path
101  );
102  }
103 
104  protected function copyrightReader(int $object_id): Reader
105  {
106  $path = $this->md->paths()->custom()
107  ->withNextStep('rights')
108  ->withNextStep('description')
109  ->withNextStep('string')
110  ->get();
111  return $this->md->read(
112  $object_id,
113  $object_id,
114  ilObject::_lookupType($object_id),
115  $path
116  );
117  }
118 }
Interface Observer Contains several chained tasks and infos about them.
__construct(\ILIAS\DI\Container $dic)
$path
Definition: ltiservices.php:30
Class HTTPServicesTest.
getContentModification(CalledContexts $screen_context_stack)
Class ilMDKeywordExposer.
__construct(Container $dic, ilPlugin $plugin)
$dic
Definition: ltiresult.php:33
static _lookupType(int $id, bool $reference=false)