ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PathConditionsChecker.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
30 {
33 
34  public function __construct(
35  PathConditionsCollectionInterface $path_conditions_collection,
36  NavigatorFactoryInterface $navigator_factory
37  ) {
38  $this->path_conditions_collection = $path_conditions_collection;
39  $this->navigator_factory = $navigator_factory;
40  }
41 
42  public function getRootsThatMeetPathCondition(StepInterface $step, ElementInterface ...$roots): \Generator
43  {
47  $elements = [];
48  foreach ($roots as $root) {
49  if ($this->isPathConditionMet($step, $root)) {
50  $elements[] = $root;
51  }
52  }
53  yield from $elements;
54  }
55 
56  public function allPathConditionsAreMet(StepInterface $step, ElementInterface ...$roots): bool
57  {
58  foreach ($roots as $root) {
59  if (!$this->isPathConditionMet($step, $root)) {
60  return false;
61  }
62  }
63  return true;
64  }
65 
66  public function atLeastOnePathConditionIsMet(StepInterface $step, ElementInterface ...$roots): bool
67  {
68  foreach ($roots as $root) {
69  if ($this->isPathConditionMet($step, $root)) {
70  return true;
71  }
72  }
73  return false;
74  }
75 
76  public function isPathConditionMet(StepInterface $step, ElementInterface $root): bool
77  {
78  $navigator = $this->navigator_factory->navigator(
79  $condition_path = $this->path_conditions_collection->getConditionPathByStepName($step->name()),
80  $root
81  );
82  while (!is_null($navigator)) {
83  if (!$navigator->hasElements()) {
84  return false;
85  }
86  $navigator = $navigator->nextStep();
87  }
88  return true;
89  }
90 }
allPathConditionsAreMet(StepInterface $step, ElementInterface ... $roots)
atLeastOnePathConditionIsMet(StepInterface $step, ElementInterface ... $roots)
getRootsThatMeetPathCondition(StepInterface $step, ElementInterface ... $roots)
name()
Steps are identified by the names of LOM elements, or a token to specify a step to the super-element...
isPathConditionMet(StepInterface $step, ElementInterface $root)
__construct(PathConditionsCollectionInterface $path_conditions_collection, NavigatorFactoryInterface $navigator_factory)
PathConditionsCollectionInterface $path_conditions_collection