ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
30{
34 protected $tree;
35
39 protected $settings;
40
41 private static $instance = null;
42
43 private $active = false;
44 private $enabled = false;
45 private $container = null;
46 private $container_items = array();
47
48 private $current_ref_id = 0;
49
54 private function __construct()
55 {
56 global $DIC;
57
58 $this->tree = $DIC->repositoryTree();
59 $this->settings = $DIC->settings();
60 $this->read();
61 }
62
63
67 public static function getInstance() : ilMemberViewSettings
68 {
69 if (self::$instance != null) {
70 return self::$instance;
71 }
72 return self::$instance = new ilMemberViewSettings();
73 }
74
79 public function getContainer()
80 {
81 return $this->container;
82 }
83
88 public function getCurrentRefId()
89 {
91 }
92
98 public function setContainer($container)
99 {
100 $this->container = $container;
101 $_SESSION['member_view_container'] = $this->container;
102 $_SESSION['il_cont_admin_panel'] = false;
103 }
104
109 public function isActive() : bool
110 {
111 static $mv_status;
112 if (!isset($mv_status)) {
113 if (!$this->active) {
114 // Not active
115 return $mv_status = false;
116 }
117
118 if (!$this->getCurrentRefId()) {
119 // No ref id given => mail, search, personal desktop menu in other tab
120 return $mv_status = false;
121 }
122
123 if (!in_array($this->getCurrentRefId(), $this->container_items) and
124 $this->getContainer() != $this->getCurrentRefId()
125 ) {
126 // outside of course
127 return $mv_status = false;
128 }
129 return $mv_status = true;
130 }
131
132 return $mv_status;
133 }
134
140 public function isActiveForRefId($a_ref_id)
141 {
142 if (!$this->active || !(int) $a_ref_id) {
143 // Not active
144 return false;
145 }
146
147 if (!in_array($a_ref_id, $this->container_items) and
148 $this->getContainer() != $a_ref_id) {
149 // outside of course
150 return false;
151 }
152 return true;
153 }
154
161 public function activate($a_ref_id)
162 {
163 $this->active = true;
164 $this->setContainer($a_ref_id);
165 }
166
171 public function deactivate()
172 {
173 $this->active = false;
174 $this->container = null;
175 unset($_SESSION['member_view_container']);
176 }
177
184 public function toggleActivation($a_ref_id, $a_activation)
185 {
186 if ($a_activation) {
187 return $this->activate($a_ref_id);
188 } else {
189 return $this->deactivate($a_ref_id);
190 }
191 }
192
197 public function isEnabled()
198 {
199 return (bool) $this->enabled;
200 }
201
206 protected function read()
207 {
210
211 $this->findEffectiveRefId();
212
213 // member view is always enabled
214 // (2013-06-18, http://www.ilias.de/docu/goto_docu_wiki_1357_Reorganising_Administration.html)
215
216 // $this->enabled = $ilSetting->get('preview_learner');
217 $this->enabled = true;
218
219 if (isset($_SESSION['member_view_container'])) {
220 $this->active = true;
221 $this->container = (int) $_SESSION['member_view_container'];
222 $this->container_items = $tree->getSubTreeIds($this->getContainer());
223 }
224 }
225
229 protected function findEffectiveRefId()
230 {
231 if ((int) $_GET['ref_id']) {
232 return $this->current_ref_id = (int) $_GET['ref_id'];
233 }
234
235 $target_arr = explode('_', (string) $_GET['target']);
236 if (isset($target_arr[1]) and (int) $target_arr[1]) {
237 $this->current_ref_id = (int) $target_arr[1];
238 }
239 }
240}
$_GET["client_id"]
$_SESSION["AccountId"]
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.
getCurrentRefId()
Get current ref_id of request.
isActiveForRefId($a_ref_id)
Check if member view is currently enabled for given ref id.
activate($a_ref_id)
Enable member view for this session and container.
__construct()
Constructor (singleton)
getContainer()
Returns $container.
setContainer($container)
Sets $container.
toggleActivation($a_ref_id, $a_activation)
Toggle activation status.
deactivate()
Deactivate member view.
$target_arr
Definition: goto.php:47
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46