ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
ElementHelper.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
29 {
33  protected ConditionChecker $condition_checker;
34 
35  public function __construct(
36  HandlerInterface $slot_handler,
37  PathFactory $path_factory,
38  NavigatorFactoryInterface $navigator_factory,
39  ConditionChecker $condition_checker
40  ) {
41  $this->slot_handler = $slot_handler;
42  $this->path_factory = $path_factory;
43  $this->navigator_factory = $navigator_factory;
44  $this->condition_checker = $condition_checker;
45  }
46 
47  public function slotForElement(ElementInterface $element): Identifier
48  {
49  foreach ($this->slotsForElementWithoutCondition($element) as $slot) {
50  if ($this->condition_checker->doesElementFitSlot($element, $slot)) {
51  return $slot;
52  }
53  }
54  return Identifier::NULL;
55  }
56 
61  {
62  yield from $this->slot_handler->allSlotsForPath($this->path_factory->toElement($element));
63  }
64 
66  ElementInterface $element,
67  ElementInterface $element_in_condition,
68  string $value
69  ): Identifier {
70  return $this->slot_handler->identiferFromPathAndCondition(
71  $this->path_factory->toElement($element),
72  $this->path_factory->betweenElements($element, $element_in_condition),
73  $value,
74  );
75  }
76 
77  public function findElementOfCondition(
78  Identifier $slot,
79  ElementInterface $element,
80  ElementInterface ...$all_elements
81  ): ?ElementInterface {
82  if (!$this->slot_handler->isSlotConditional($slot)) {
83  return null;
84  }
85 
86  $condition_path = $this->slot_handler->conditionForSlot($slot)->path();
87  $potential_result = $this->navigator_factory->navigator($condition_path, $element)
88  ->lastElementAtFinalStep();
89 
90  return in_array($potential_result, $all_elements, true) ? $potential_result : null;
91  }
92 }
potentialSlotForElementByCondition(ElementInterface $element, ElementInterface $element_in_condition, string $value)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(HandlerInterface $slot_handler, PathFactory $path_factory, NavigatorFactoryInterface $navigator_factory, ConditionChecker $condition_checker)
slotsForElementWithoutCondition(ElementInterface $element)
findElementOfCondition(Identifier $slot, ElementInterface $element, ElementInterface ... $all_elements)