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