ILIAS  release_8 Revision v8.24
ContextCollection.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
21
24
30{
35 protected array $stack = [];
36
41 public function __construct(ContextRepository $context_repository)
42 {
43 $this->repo = $context_repository;
44 }
45
49 public function push(ScreenContext $context): void
50 {
51 $this->stack[] = $context;
52 }
53
57 public function getLast(): ?ScreenContext
58 {
59 $last = end($this->stack);
60 if ($last) {
61 return $last;
62 }
63 return null;
64 }
65
69 public function getStack(): array
70 {
71 return $this->stack;
72 }
73
77 public function getStackAsArray(): array
78 {
79 $return = [];
80 foreach ($this->stack as $item) {
81 $return[] = $item->getUniqueContextIdentifier();
82 }
83
84 return $return;
85 }
86
91 public function hasMatch(ContextCollection $other_collection): bool
92 {
93 $mapper = function (ScreenContext $c): string {
94 return $c->getUniqueContextIdentifier();
95 };
96 $mine = array_map($mapper, $this->getStack());
97 $theirs = array_map($mapper, $other_collection->getStack());
98
99 return (count(array_intersect($mine, $theirs)) > 0);
100 }
101
102 public function main(): self
103 {
104 $context = $this->repo->main();
105 $this->push($context);
106
107 return $this;
108 }
109
110 public function desktop(): self
111 {
112 $this->push($this->repo->desktop());
113
114 return $this;
115 }
116
117 public function repository(): self
118 {
119 $this->push($this->repo->repository());
120
121 return $this;
122 }
123
124 public function administration(): self
125 {
126 $this->push($this->repo->administration());
127
128 return $this;
129 }
130
131 public function internal(): self
132 {
133 $this->push($this->repo->internal());
134
135 return $this;
136 }
137
138 public function external(): self
139 {
140 $this->push($this->repo->external());
141
142 return $this;
143 }
144
145 public function lti(): self
146 {
147 $this->push($this->repo->lti());
148 return $this;
149 }
150}
Class ContextRepository The Collection of all available Contexts in the System.
__construct(ContextRepository $context_repository)
ContextCollection constructor.
$c
Definition: cli.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$context
Definition: webdav.php:29