ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMDKeywordExposer.php
Go to the documentation of this file.
1<?php
2
7
14{
16 {
17 return $this->context_collection->repository();
18 }
19
20 public function getContentModification(CalledContexts $screen_context_stack) : ?ContentModification
21 {
22 if ($screen_context_stack->current()->hasReferenceId()) {
23 $object_id = $screen_context_stack->current()->getReferenceId()->toObjectId()->toInt();
24
25 if ($general = $this->getGeneral($object_id)) {
26 // Keywords
27 $keywords = [];
28 foreach ($general->getKeywordIds() as $keyword_id) {
29 $keyword = $general->getKeyword($keyword_id);
30 $keywords[] = $keyword->getKeyword();
31 }
32
33 $delimiter = ilMDSettings::_getInstance()->getDelimiter() ?? ",";
34
35 if (count($keywords) > 0) {
36 $this->globalScreen()->layout()->meta()->addMetaDatum('keywords', implode($delimiter, $keywords));
37 }
38 // Languages
39 $languages = [];
40 foreach ($general->getLanguageIds() as $language_id) {
41 $language = $general->getLanguage($language_id);
42 $languages[] = $language->getLanguageCode();
43 }
44 if (count($languages) > 0) {
45 $this->globalScreen()->layout()->meta()->addMetaDatum('languages', implode($delimiter, $languages));
46 }
47 }
48
49 if ($rights = $this->getRights($object_id)) {
50 // Copyright
51 $copy_right_id = ilMDCopyrightSelectionEntry::_extractEntryId($rights->getDescription());
52 if ($copy_right_id > 0) {
53 $entry = new ilMDCopyrightSelectionEntry($copy_right_id);
54 $this->globalScreen()->layout()->meta()->addMetaDatum('copyright', $entry->getTitle());
55 }
56 }
57 }
58
59 return null;
60 }
61
62 private function getGeneral(int $object_id) : ?ilMDGeneral
63 {
64 if ($id = ilMDGeneral::_getId($object_id, $object_id)) {
65 $gen = new ilMDGeneral();
66 $gen->setMetaId($id);
67
68 return $gen;
69 }
70 return null;
71 }
72
73 private function getRights(int $object_id) : ?ilMDRights
74 {
75 if ($id = ilMDRights::_getId($object_id, $object_id)) {
76 $rig = new ilMDRights();
77 $rig->setMetaId($id);
78
79 return $rig;
80 }
81 return null;
82 }
83
84}
An exception for terminatinating execution or to throw for unit testing.
static _extractEntryId($a_cp_string)
extract entry id
static _getId($a_rbac_id, $a_obj_id)
Class ilMDKeywordExposer.
getContentModification(CalledContexts $screen_context_stack)
@inheritDoc
static _getId($a_rbac_id, $a_obj_id)
static _getInstance()
get instance