ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMemberViewSettings.php
Go to the documentation of this file.
1<?php
2
19use Psr\Http\Message\RequestInterface;
21
27{
28 public const SESSION_MEMBER_VIEW_CONTAINER = 'member_view_container';
29 protected ilLogger $logger;
30 protected RequestInterface $request;
31 protected ilCtrl $ctrl;
32 protected ilTree $tree;
34 private static ?ilMemberViewSettings $instance = null;
35 private bool $active = false;
36 private bool $enabled = false;
37 private ?int $container = null;
38 private array $container_items = [];
39 private int $current_ref_id = 0;
41
42 private function __construct()
43 {
44 global $DIC;
45
46 $this->tree = $DIC->repositoryTree();
47 $this->settings = $DIC->settings();
48 $this->request = $DIC->http()->request();
49 $this->ctrl = $DIC->ctrl();
50 $this->logger = $DIC->logger()->cont();
51 $this->read();
52 $this->container_service = $DIC->container();
53 }
54
55 public static function getInstance(): ilMemberViewSettings
56 {
57 return self::$instance ?? (self::$instance = new ilMemberViewSettings());
58 }
59
60 public function getContainer(): ?int
61 {
62 return $this->container;
63 }
64
65 public function getCurrentRefId(): int
66 {
68 }
69
70 public function setContainer(int $container): void
71 {
72 $this->container = $container;
73 ilSession::set(self::SESSION_MEMBER_VIEW_CONTAINER, $this->container);
76 $this->container_service
77 ->internal()
78 ->domain()
79 ->content()
80 ->mode($my_container)
81 ->setContentMode();
82 }
83
87 public function isActive(): bool
88 {
89 static $mv_status;
90 if (!isset($mv_status)) {
91 if (!$this->active) {
92 // Not active
93 return $mv_status = false;
94 }
95
96 if (!$this->getCurrentRefId()) {
97 // No ref id given => mail, search, personal desktop menu in other tab
98 return $mv_status = false;
99 }
100
101 if (!in_array($this->getCurrentRefId(), $this->container_items) &&
102 $this->getContainer() !== $this->getCurrentRefId()
103 ) {
104 // outside of course
105 return $mv_status = false;
106 }
107 return $mv_status = true;
108 }
109
110 return $mv_status;
111 }
112
116 public function isActiveForRefId(int $a_ref_id): bool
117 {
118 if (!$this->active || !$a_ref_id) {
119 return false;
120 }
121
122 if (
123 !in_array($a_ref_id, $this->container_items) &&
124 $this->getContainer() !== $a_ref_id) {
125 return false;
126 }
127 return true;
128 }
129
133 public function activate(int $a_ref_id): void
134 {
135 $this->active = true;
136 $this->setContainer($a_ref_id);
137 }
138
139 public function deactivate(): void
140 {
141 $this->active = false;
142 $this->container = null;
143 ilSession::clear(self::SESSION_MEMBER_VIEW_CONTAINER);
144 }
145
149 public function toggleActivation(int $a_ref_id, bool $a_activation): void
150 {
151 if ($a_activation) {
152 $this->activate($a_ref_id);
153 } else {
154 $this->deactivate();
155 }
156 }
157
161 public function isEnabled(): bool
162 {
163 return $this->enabled;
164 }
165
169 protected function read(): void
170 {
172
173 // member view is always enabled
174 // (2013-06-18, http://www.ilias.de/docu/goto_docu_wiki_1357_Reorganising_Administration.html)
175
176 // $this->enabled = $ilSetting->get('preview_learner');
177 $this->enabled = true;
178
179 if (ilSession::get(self::SESSION_MEMBER_VIEW_CONTAINER)) {
180 $this->active = true;
181 $this->container = (int) ilSession::get(self::SESSION_MEMBER_VIEW_CONTAINER);
182 $this->container_items = $this->tree->getSubTreeIds($this->getContainer());
183
184 // deactivate if out of scope
185 if (
186 $this->getCurrentRefId() &&
187 !in_array($this->getCurrentRefId(), $this->container_items) &&
188 $this->getCurrentRefId() !== $this->getContainer()
189 ) {
190 $this->deactivate();
191 }
192 }
193 }
194
198 protected function findEffectiveRefId(): int
199 {
200 // re-enable asynchronous request due to #41218
201 $ref_id = (int) ($this->request->getQueryParams()['ref_id'] ?? 0);
202 if ($ref_id) {
203 return $this->current_ref_id = $ref_id;
204 }
205 $target_str = (string) ($this->request->getQueryParams()['target'] ?? '');
206 if ($target_str !== '') {
207 $target_arr = explode('_', $target_str);
208 if (isset($target_arr[1]) && (int) $target_arr[1]) {
209 $this->current_ref_id = (int) $target_arr[1];
210 }
211 }
212 return 0;
213 }
214}
Class ilCtrl provides processing control methods.
Component logger with individual log levels by component id.
Settings for members view.
static ilMemberViewSettings $instance
isActive()
Check if member view currently enabled.
findEffectiveRefId()
Find effective ref_id for request.
isEnabled()
Check if members view is enabled in the administration.
Container Service $container_service
isActiveForRefId(int $a_ref_id)
Check if member view is currently enabled for given ref id.
activate(int $a_ref_id)
Enable member view for this session and container.
toggleActivation(int $a_ref_id, bool $a_activation)
Toggle activation status.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
ILIAS Setting Class.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26