ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Checker.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
31
32class Checker implements CheckerInterface
33{
34 protected SlotsHandler $slots_handler;
35 protected PathFactory $path_factory;
36 protected NavigatorFactory $navigator_factory;
37
38 public function __construct(
39 SlotsHandler $slots_handler,
40 PathFactory $path_factory,
41 NavigatorFactory $navigator_factory
42 ) {
43 $this->slots_handler = $slots_handler;
44 $this->path_factory = $path_factory;
45 $this->navigator_factory = $navigator_factory;
46 }
47
48 public function doesElementFitSlot(
49 ElementInterface $element,
50 SlotIdentifier $slot,
51 bool $ignore_markers = true
52 ): bool {
53 $slot_path = $this->slots_handler->pathForSlot($slot);
54 $path_to_element = $this->path_factory->toElement($element);
55
56 if ($slot_path->toString() !== $path_to_element->toString()) {
57 return false;
58 }
59
60 if (!$this->slots_handler->isSlotConditional($slot)) {
61 return true;
62 }
63
64 $condition = $this->slots_handler->conditionForSlot($slot);
65 return $this->checkCondition($element, $condition, $ignore_markers);
66 }
67
68 protected function checkCondition(
69 ElementInterface $element,
70 ConditionInterface $condition,
71 bool $ignore_markers
72 ): bool {
73 $value = $this->getDataValueFromRelativePath(
74 $element,
75 $condition->path(),
76 $ignore_markers
77 );
78 return $value === $condition->value();
79 }
80
81 protected function getDataValueFromRelativePath(
82 ElementInterface $start,
84 bool $ignore_marker
85 ): ?string {
86 $element = $this->navigator_factory->navigator(
87 $path,
88 $start
89 )->lastElementAtFinalStep();
90
91 if (!isset($element)) {
92 return null;
93 }
94 if (
95 !$ignore_marker &&
96 ($element instanceof MarkableInterface) &&
97 $element->isMarked()
98 ) {
99 return $element->getMarker()->dataValue();
100 }
101 return $element->getData()->value();
102 }
103}
doesElementFitSlot(ElementInterface $element, SlotIdentifier $slot, bool $ignore_markers=true)
Definition: Checker.php:48
__construct(SlotsHandler $slots_handler, PathFactory $path_factory, NavigatorFactory $navigator_factory)
Definition: Checker.php:38
getDataValueFromRelativePath(ElementInterface $start, PathInterface $path, bool $ignore_marker)
Definition: Checker.php:81
checkCondition(ElementInterface $element, ConditionInterface $condition, bool $ignore_markers)
Definition: Checker.php:68
isMarked()
Elements can be marked to be created, updated or deleted.
$path
Definition: ltiservices.php:30