ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ContextCollection.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
31 {
36  protected array $stack = [];
37 
38  public function __construct(ContextRepository $context_repository)
39  {
40  $this->repo = $context_repository;
41  }
42 
43  public function push(ScreenContext $context): void
44  {
45  $current = end($this->stack);
46  if ($current instanceof ScreenContext) {
47  if($current->hasReferenceId()) {
48  $reference_id = $current->getReferenceId();
49  $ref_id = $reference_id->toInt();
50  $context = $context->withReferenceId($reference_id);
51  }
52  $context = $context->withAdditionalData($current->getAdditionalData());
53  }
54 
55  $this->stack[] = $context;
56  }
57 
58  public function getLast(): ?ScreenContext
59  {
60  $last = end($this->stack);
61  if ($last instanceof ScreenContext) {
62  return $last;
63  }
64  return null;
65  }
66 
70  public function getStack(): array
71  {
72  return $this->stack;
73  }
74 
75  public function getStackAsArray(): array
76  {
77  $return = [];
78  foreach ($this->stack as $item) {
79  $return[] = $item->getUniqueContextIdentifier();
80  }
81 
82  return $return;
83  }
84 
85  public function hasMatch(ContextCollection $other_collection): bool
86  {
87  $mapper = static function (ScreenContext $c): string {
88  return $c->getUniqueContextIdentifier();
89  };
90  $mine = array_map($mapper, $this->getStack());
91  $theirs = array_map($mapper, $other_collection->getStack());
92 
93  return (count(array_intersect($mine, $theirs)) > 0);
94  }
95 
96  public function main(): self
97  {
98  $context = $this->repo->main();
99  $this->push($context);
100 
101  return $this;
102  }
103 
104  public function desktop(): self
105  {
106  $this->push($this->repo->desktop());
107 
108  return $this;
109  }
110 
111  public function repository(): self
112  {
113  $this->push($this->repo->repository());
114 
115  return $this;
116  }
117 
118  public function administration(): self
119  {
120  $this->push($this->repo->administration());
121 
122  return $this;
123  }
124 
125  public function internal(): self
126  {
127  $this->push($this->repo->internal());
128 
129  return $this;
130  }
131 
132  public function external(): self
133  {
134  $this->push($this->repo->external());
135 
136  return $this;
137  }
138 
139  public function lti(): self
140  {
141  $this->push($this->repo->lti());
142  return $this;
143  }
144 }
$context
Definition: webdav.php:31
$c
Definition: deliver.php:9
withReferenceId(ReferenceId $reference_id)
The Collection of all available Contexts in the System.
$ref_id
Definition: ltiauth.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ContextRepository $context_repository)