ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Handler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
32 class Handler implements HandlerInterface
33 {
37 
38  public function __construct(
39  PathFactory $path_factory,
40  NavigatorFactoryInterface $navigator_factory,
41  StructureSetInterface $structure
42  ) {
43  $this->path_factory = $path_factory;
44  $this->navigator_factory = $navigator_factory;
45  $this->structure = $structure;
46  }
47 
48  public function pathForSlot(Identifier $identifier): PathInterface
49  {
50  return match ($identifier) {
51  Identifier::GENERAL_STRUCTURE => $this->buildPath('general', 'structure', 'value'),
52  Identifier::GENERAL_AGGREGATION_LEVEL => $this->buildPath('general', 'aggregationLevel', 'value'),
53  Identifier::GENERAL_COVERAGE => $this->buildPath('general', 'coverage', 'string'),
54  Identifier::GENERAL_IDENTIFIER_CATALOG => $this->buildPath('general', 'identifier', 'catalog'),
55  Identifier::LIFECYCLE_STATUS => $this->buildPath('lifeCycle', 'status', 'value'),
56  Identifier::LIFECYCLE_CONTRIBUTE_ROLE => $this->buildPath('lifeCycle', 'contribute', 'role', 'value'),
57  Identifier::LIFECYCLE_CONTRIBUTE_PUBLISHER => $this->buildPath('lifeCycle', 'contribute', 'entity'),
58  Identifier::METAMETADATA_IDENTIFIER_CATALOG => $this->buildPath('metaMetadata', 'identifier', 'catalog'),
59  Identifier::METAMETADATA_CONTRIBUTE_ROLE => $this->buildPath('metaMetadata', 'contribute', 'role', 'value'),
60  Identifier::METAMETADATA_SCHEMA => $this->buildPath('metaMetadata', 'metadataSchema'),
61  Identifier::TECHNICAL_REQUIREMENT_TYPE => $this->buildPath('technical', 'requirement', 'orComposite', 'type', 'value'),
62  Identifier::TECHNICAL_REQUIREMENT_BROWSER, Identifier::TECHNICAL_REQUIREMENT_OS => $this->buildPath('technical', 'requirement', 'orComposite', 'name', 'value'),
63  Identifier::TECHNICAL_OTHER_PLATFORM_REQUIREMENTS => $this->buildPath('technical', 'otherPlatformRequirements', 'string'),
64  Identifier::TECHNICAL_FORMAT => $this->buildPath('technical', 'format'),
65  Identifier::EDUCATIONAL_INTERACTIVITY_TYPE => $this->buildPath('educational', 'interactivityType', 'value'),
66  Identifier::EDUCATIONAL_LEARNING_RESOURCE_TYPE => $this->buildPath('educational', 'learningResourceType', 'value'),
67  Identifier::EDUCATIONAL_INTERACTIVITY_LEVEL => $this->buildPath('educational', 'interactivityLevel', 'value'),
68  Identifier::EDUCATIONAL_SEMANTIC_DENSITY => $this->buildPath('educational', 'semanticDensity', 'value'),
69  Identifier::EDCUCATIONAL_INTENDED_END_USER_ROLE => $this->buildPath('educational', 'intendedEndUserRole', 'value'),
70  Identifier::EDUCATIONAL_CONTEXT => $this->buildPath('educational', 'context', 'value'),
71  Identifier::EDUCATIONAL_DIFFICULTY => $this->buildPath('educational', 'difficulty', 'value'),
72  Identifier::EDUCATIONAL_TYPICAL_AGE_RANGE => $this->buildPath('educational', 'typicalAgeRange', 'string'),
73  Identifier::RIGHTS_COST => $this->buildPath('rights', 'cost', 'value'),
74  Identifier::RIGHTS_CP_AND_OTHER_RESTRICTIONS => $this->buildPath('rights', 'copyrightAndOtherRestrictions', 'value'),
75  Identifier::RIGHTS_DESCRIPTION => $this->buildPath('rights', 'description', 'string'),
76  Identifier::RELATION_KIND => $this->buildPath('relation', 'kind', 'value'),
77  Identifier::RELATION_RESOURCE_IDENTIFIER_CATALOG => $this->buildPath('relation', 'resource', 'identifier', 'catalog'),
78  Identifier::CLASSIFICATION_PURPOSE => $this->buildPath('classification', 'purpose', 'value'),
79  Identifier::CLASSIFICATION_KEYWORD => $this->buildPath('classification', 'keyword', 'string'),
80  Identifier::CLASSIFICATION_TAXPATH_SOURCE => $this->buildPath('classification', 'taxonPath', 'source', 'string'),
81  Identifier::CLASSIFICATION_TAXON_ENTRY => $this->buildPath('classification', 'taxonPath', 'taxon', 'entry', 'string'),
82  Identifier::NULL => $this->buildPath()
83  };
84  }
85 
86  public function isSlotConditional(Identifier $identifier): bool
87  {
88  return !is_null($this->conditionForSlot($identifier));
89  }
90 
91  public function conditionForSlot(Identifier $identifier): ?ConditionInterface
92  {
93  return match ($identifier) {
94  Identifier::LIFECYCLE_CONTRIBUTE_PUBLISHER => $this->buildCondition(
95  'publisher',
97  'role',
98  'value'
99  ),
100  Identifier::TECHNICAL_REQUIREMENT_BROWSER => $this->buildCondition(
101  'browser',
104  'type',
105  'value'
106  ),
107  Identifier::TECHNICAL_REQUIREMENT_OS => $this->buildCondition(
108  'operating system',
111  'type',
112  'value'
113  ),
114  default => null
115  };
116  }
117 
119  PathInterface $path_to_element,
120  ?PathInterface $path_to_condition,
121  ?string $condition_value
122  ): Identifier {
123  foreach (Identifier::cases() as $identifier) {
124  if ($this->pathForSlot($identifier)->toString() !== $path_to_element->toString()) {
125  continue;
126  }
127 
128  $condition = $this->conditionForSlot($identifier);
129  if (
130  $condition?->value() !== $condition_value ||
131  $condition?->path()?->toString() !== $path_to_condition?->toString()
132  ) {
133  continue;
134  }
135 
136  return $identifier;
137  }
138  return Identifier::NULL;
139  }
140 
141  public function allSlotsForPath(PathInterface $path_to_element): \Generator
142  {
143  foreach (Identifier::cases() as $identifier) {
144  if ($this->pathForSlot($identifier)->toString() === $path_to_element->toString()) {
145  yield $identifier;
146  }
147  }
148  }
149 
150  public function doesSlotExist(
151  PathInterface $path_to_element,
152  ?PathInterface $path_to_condition,
153  ?string $condition_value
154  ): bool {
155  $identifier = $this->identiferFromPathAndCondition(
156  $path_to_element,
157  $path_to_condition,
158  $condition_value
159  );
160  return $identifier !== Identifier::NULL;
161  }
162 
163  protected function buildPath(string ...$steps): PathInterface
164  {
165  $builder = $this->path_factory->custom();
166  foreach ($steps as $step) {
167  $builder = $builder->withNextStep($step);
168  }
169  return $builder->get();
170  }
171 
172  protected function buildCondition(
173  string $condition_value,
174  string|StepToken ...$steps_to_condition,
175  ): ConditionInterface {
176  $builder = $this->path_factory->custom();
177  foreach ($steps_to_condition as $step) {
178  if ($step === StepToken::SUPER) {
179  $builder = $builder->withNextStepToSuperElement();
180  continue;
181  }
182  $builder = $builder->withNextStep($step);
183  }
184  $path = $builder->withRelative(true)->get();
185 
186  return new Condition(
187  $condition_value,
188  $path
189  );
190  }
191 
192  public function dataTypeForSlot(Identifier $identifier): DataType
193  {
194  return $this->navigator_factory->structureNavigator(
195  $this->pathForSlot($identifier),
196  $this->structure->getRoot()
197  )->elementAtFinalStep()->getDefinition()->dataType();
198  }
199 }
conditionForSlot(Identifier $identifier)
Definition: Handler.php:91
__construct(PathFactory $path_factory, NavigatorFactoryInterface $navigator_factory, StructureSetInterface $structure)
Definition: Handler.php:38
doesSlotExist(PathInterface $path_to_element, ?PathInterface $path_to_condition, ?string $condition_value)
Definition: Handler.php:150
StructureSetInterface $structure
Definition: Handler.php:36
isSlotConditional(Identifier $identifier)
Definition: Handler.php:86
identiferFromPathAndCondition(PathInterface $path_to_element, ?PathInterface $path_to_condition, ?string $condition_value)
Definition: Handler.php:118
buildCondition(string $condition_value, string|StepToken ... $steps_to_condition,)
Definition: Handler.php:172
allSlotsForPath(PathInterface $path_to_element)
Definition: Handler.php:141
pathForSlot(Identifier $identifier)
Definition: Handler.php:48
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
StepToken
The string representation of these tokens must not occur as names of metadata elements.
Definition: StepToken.php:27
dataTypeForSlot(Identifier $identifier)
Definition: Handler.php:192
NavigatorFactoryInterface $navigator_factory
Definition: Handler.php:35