ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMemberViewSettings.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24use Psr\Http\Message\RequestInterface;
25
32{
33 public const SESSION_MEMBER_VIEW_CONTAINER = 'member_view_container';
34
38 protected $logger;
39
43 protected $request;
44
48 protected $ctrl;
49
53 protected $tree;
54
58 protected $settings;
59
63 private static $instance = null;
64
68 private $active = false;
69
73 private $enabled = false;
74
78 private $container = null;
79
83 private $container_items = array();
84
88 private $current_ref_id = 0;
89
93 private function __construct()
94 {
95 global $DIC;
96
97 $this->tree = $DIC->repositoryTree();
98 $this->settings = $DIC->settings();
99 $this->request = $DIC->http()->request();
100 $this->ctrl = $DIC->ctrl();
101 $this->logger = $DIC->logger()->cont();
102 $this->read();
103 }
104
105
109 public static function getInstance() : ilMemberViewSettings
110 {
111 if (self::$instance != null) {
112 return self::$instance;
113 }
114 return self::$instance = new ilMemberViewSettings();
115 }
116
120 public function getContainer() : ?int
121 {
122 return $this->container;
123 }
124
128 public function getCurrentRefId() : int
129 {
131 }
132
136 public function setContainer(int $container)
137 {
138 $this->container = $container;
139 ilSession::set(self::SESSION_MEMBER_VIEW_CONTAINER, $this->container);
140 ilSession::set('il_cont_admin_panel', false);
141 }
142
147 public function isActive() : bool
148 {
149 static $mv_status;
150 if (!isset($mv_status)) {
151 if (!$this->active) {
152 // Not active
153 return $mv_status = false;
154 }
155
156 if (!$this->getCurrentRefId()) {
157 // No ref id given => mail, search, personal desktop menu in other tab
158 return $mv_status = false;
159 }
160
161 if (!in_array($this->getCurrentRefId(), $this->container_items) and
162 $this->getContainer() != $this->getCurrentRefId()
163 ) {
164 // outside of course
165 return $mv_status = false;
166 }
167 return $mv_status = true;
168 }
169
170 return $mv_status;
171 }
172
178 public function isActiveForRefId(int $a_ref_id) : bool
179 {
180 if (!$this->active || !(int) $a_ref_id) {
181 return false;
182 }
183
184 if (
185 !in_array($a_ref_id, $this->container_items) &&
186 $this->getContainer() != $a_ref_id) {
187 return false;
188 }
189 return true;
190 }
191
196 public function activate(int $a_ref_id) : void
197 {
198 $this->active = true;
199 $this->setContainer($a_ref_id);
200 }
201
206 public function deactivate() : void
207 {
208 $this->active = false;
209 $this->container = null;
210 ilSession::clear(self::SESSION_MEMBER_VIEW_CONTAINER);
211 }
212
218 public function toggleActivation(int $a_ref_id, bool $a_activation) : void
219 {
220 if ($a_activation) {
221 $this->activate($a_ref_id);
222 } else {
223 $this->deactivate($a_ref_id);
224 }
225 }
226
231 public function isEnabled() : bool
232 {
233 return (bool) $this->enabled;
234 }
235
239 protected function read() : void
240 {
242
243 // member view is always enabled
244 // (2013-06-18, http://www.ilias.de/docu/goto_docu_wiki_1357_Reorganising_Administration.html)
245
246 // $this->enabled = $ilSetting->get('preview_learner');
247 $this->enabled = true;
248
249 if (ilSession::get(self::SESSION_MEMBER_VIEW_CONTAINER)) {
250 $this->active = true;
251 $this->container = (int) ilSession::get(self::SESSION_MEMBER_VIEW_CONTAINER);
252 $this->container_items = $this->tree->getSubTreeIds($this->getContainer());
253
254 // deactivate if out of scope
255 if (
256 $this->getCurrentRefId() &&
257 !in_array($this->getCurrentRefId(), $this->container_items) &&
258 $this->getCurrentRefId() != $this->getContainer()
259 ) {
260 $this->deactivate();
261 }
262 }
263 }
264
268 protected function findEffectiveRefId()
269 {
270 if ($this->ctrl->isAsynch()) {
271 // Ignore asynchronous requests
272 return;
273 }
274
275 $ref_id = (int) $this->request->getQueryParams()['ref_id'] ?? 0;
276 if ($ref_id) {
277 return $this->current_ref_id = $ref_id;
278 }
279 $target_str = (string) $this->request->getQueryParams()['target'] ?? '';
280 if (strlen($target_str)) {
281 $target_arr = explode('_', (string) $target_str);
282 if (isset($target_arr[1]) && (int) $target_arr[1]) {
283 $this->current_ref_id = (int) $target_arr[1];
284 }
285 }
286 }
287}
An exception for terminatinating execution or to throw for unit testing.
@classDescription Settings for members view
isActive()
Check if member view currently enabled.
findEffectiveRefId()
Find effective ref_id for request.
isEnabled()
Check if members view is enabled in the administration.
isActiveForRefId(int $a_ref_id)
Check if member view is currently enabled for given ref id.
__construct()
Constructor (singleton)
activate(int $a_ref_id)
Enable member view for this session and container.
toggleActivation(int $a_ref_id, bool $a_activation)
Toggle activation status.
deactivate()
Deactivate member view.
static set($a_var, $a_val)
Set a value.
static clear($a_var)
Unset a value.
static get($a_var)
Get a value.
global $DIC
Definition: goto.php:24
$target_arr
Definition: goto.php:49
settings()
Definition: settings.php:2