ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
Presentation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
33 {
34  protected CopyrightBridge $copyright;
35  protected ControlledRepository $controlled;
36  protected StandardRepository $standard;
37 
38  public function __construct(
39  CopyrightBridge $copyright,
40  ControlledRepository $controlled,
41  StandardRepository $standard
42  ) {
43  $this->copyright = $copyright;
44  $this->controlled = $controlled;
45  $this->standard = $standard;
46  }
47 
51  public function presentableLabels(
52  PresentationUtilities $presentation_utilities,
53  SlotIdentifier $slot,
54  bool $with_unknown_vocab_flag,
55  string ...$values
56  ): \Generator {
57  $labelled_values = array_fill_keys($values, null);
58 
59  foreach ($this->copyright->labelsForValues($slot, ...$values) as $label) {
60  if (!array_key_exists($label->value(), $labelled_values)) {
61  continue;
62  }
63  $labelled_values[$label->value()] = $label;
64  }
65 
66  foreach ($this->controlled->getLabelsForValues($slot, true, ...$values) as $label) {
67  if (
68  !array_key_exists($label->value(), $labelled_values) ||
69  !is_null($labelled_values[$label->value()])
70  ) {
71  continue;
72  }
73  if ($label->label() === '') {
74  $label = new LabelledValue($label->value(), $label->value());
75  }
76  $labelled_values[$label->value()] = $label;
77  }
78 
79  foreach ($this->standard->getLabelsForValues(
80  $presentation_utilities,
81  $slot,
82  true,
83  ...$values
84  ) as $label) {
85  if (
86  !array_key_exists($label->value(), $labelled_values) ||
87  !is_null($labelled_values[$label->value()])
88  ) {
89  continue;
90  }
91  $labelled_values[$label->value()] = $label;
92  }
93 
94  foreach ($labelled_values as $value => $labelled_value) {
95  if (!is_null($labelled_value)) {
96  yield $labelled_value;
97  continue;
98  }
99  $label = (string) $value;
100  if ($with_unknown_vocab_flag) {
101  $label .= ' ' . $presentation_utilities->txt('md_unknown_vocabulary_flag');
102  }
103  yield new LabelledValue((string) $value, $label);
104  }
105  }
106 
110  public function labelsForVocabulary(
111  PresentationUtilities $presentation_utilities,
112  VocabularyInterface $vocabulary
113  ): \Generator {
114  switch ($vocabulary->type()) {
115  case Type::STANDARD:
116  yield from $this->standard->getLabelsForValues(
117  $presentation_utilities,
118  $vocabulary->slot(),
119  false,
120  ...$vocabulary->values()
121  );
122  break;
123 
124  case Type::CONTROLLED_STRING:
125  case Type::CONTROLLED_VOCAB_VALUE:
126  yield from $this->controlled->getLabelsForValues(
127  $vocabulary->slot(),
128  false,
129  ...$vocabulary->values()
130  );
131  break;
132 
133  case Type::COPYRIGHT:
134  yield from $this->copyright->labelsForValues(
135  $vocabulary->slot(),
136  ...$vocabulary->values()
137  );
138  break;
139 
140  default:
141  yield from [];
142  break;
143  }
144  }
145 }
labelsForVocabulary(PresentationUtilities $presentation_utilities, VocabularyInterface $vocabulary)
__construct(CopyrightBridge $copyright, ControlledRepository $controlled, StandardRepository $standard)
standard()
description: > This is an example, of how the Notification Slate is generated by assigning Notificat...
Definition: standard.php:38
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
presentableLabels(PresentationUtilities $presentation_utilities, SlotIdentifier $slot, bool $with_unknown_vocab_flag, string ... $values)