ILIAS  release_8 Revision v8.24
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);
74 $this->container_service
75 ->internal()
76 ->domain()
77 ->content()
78 ->view()
79 ->setContentView();
80 }
81
85 public function isActive(): bool
86 {
87 static $mv_status;
88 if (!isset($mv_status)) {
89 if (!$this->active) {
90 // Not active
91 return $mv_status = false;
92 }
93
94 if (!$this->getCurrentRefId()) {
95 // No ref id given => mail, search, personal desktop menu in other tab
96 return $mv_status = false;
97 }
98
99 if (!in_array($this->getCurrentRefId(), $this->container_items) &&
100 $this->getContainer() !== $this->getCurrentRefId()
101 ) {
102 // outside of course
103 return $mv_status = false;
104 }
105 return $mv_status = true;
106 }
107
108 return $mv_status;
109 }
110
114 public function isActiveForRefId(int $a_ref_id): bool
115 {
116 if (!$this->active || !$a_ref_id) {
117 return false;
118 }
119
120 if (
121 !in_array($a_ref_id, $this->container_items) &&
122 $this->getContainer() !== $a_ref_id) {
123 return false;
124 }
125 return true;
126 }
127
131 public function activate(int $a_ref_id): void
132 {
133 $this->active = true;
134 $this->setContainer($a_ref_id);
135 }
136
137 public function deactivate(): void
138 {
139 $this->active = false;
140 $this->container = null;
141 ilSession::clear(self::SESSION_MEMBER_VIEW_CONTAINER);
142 }
143
147 public function toggleActivation(int $a_ref_id, bool $a_activation): void
148 {
149 if ($a_activation) {
150 $this->activate($a_ref_id);
151 } else {
152 $this->deactivate();
153 }
154 }
155
159 public function isEnabled(): bool
160 {
161 return $this->enabled;
162 }
163
167 protected function read(): void
168 {
170
171 // member view is always enabled
172 // (2013-06-18, http://www.ilias.de/docu/goto_docu_wiki_1357_Reorganising_Administration.html)
173
174 // $this->enabled = $ilSetting->get('preview_learner');
175 $this->enabled = true;
176
177 if (ilSession::get(self::SESSION_MEMBER_VIEW_CONTAINER)) {
178 $this->active = true;
179 $this->container = (int) ilSession::get(self::SESSION_MEMBER_VIEW_CONTAINER);
180 $this->container_items = $this->tree->getSubTreeIds($this->getContainer());
181
182 // deactivate if out of scope
183 if (
184 $this->getCurrentRefId() &&
185 !in_array($this->getCurrentRefId(), $this->container_items) &&
186 $this->getCurrentRefId() !== $this->getContainer()
187 ) {
188 $this->deactivate();
189 }
190 }
191 }
192
196 protected function findEffectiveRefId(): int
197 {
198 if ($this->ctrl->isAsynch()) {
199 // Ignore asynchronous requests
200 return 0;
201 }
202
203 $ref_id = (int) ($this->request->getQueryParams()['ref_id'] ?? 0);
204 if ($ref_id) {
205 return $this->current_ref_id = $ref_id;
206 }
207 $target_str = (string) ($this->request->getQueryParams()['target'] ?? '');
208 if ($target_str !== '') {
209 $target_arr = explode('_', $target_str);
210 if (isset($target_arr[1]) && (int) $target_arr[1]) {
211 $this->current_ref_id = (int) $target_arr[1];
212 }
213 }
214 return 0;
215 }
216}
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 get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$target_arr
Definition: goto.php:50
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...