ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
67  public static function getInstance()
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  {
90  return $this->current_ref_id;
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()
110  {
111  $tree = $this->tree;
112 
113  if (!$this->active) {
114  // Not active
115  return false;
116  }
117 
118 
119  if (!$this->getCurrentRefId()) {
120  // No ref id given => mail, search, personal desktop menu in other tab
121  return false;
122  }
123 
124  if (!in_array($this->getCurrentRefId(), $this->container_items) and
125  $this->getContainer() != $this->getCurrentRefId()) {
126  // outside of course
127  return false;
128  }
129  return true;
130  }
131 
137  public function isActiveForRefId($a_ref_id)
138  {
139  if (!$this->active || !(int) $a_ref_id) {
140  // Not active
141  return false;
142  }
143 
144  if (!in_array($a_ref_id, $this->container_items) and
145  $this->getContainer() != $a_ref_id) {
146  // outside of course
147  return false;
148  }
149  return true;
150  }
151 
158  public function activate($a_ref_id)
159  {
160  $this->active = true;
161  $this->setContainer($a_ref_id);
162  }
163 
168  public function deactivate()
169  {
170  $this->active = false;
171  $this->container = null;
172  unset($_SESSION['member_view_container']);
173  }
174 
181  public function toggleActivation($a_ref_id, $a_activation)
182  {
183  if ($a_activation) {
184  return $this->activate($a_ref_id);
185  } else {
186  return $this->deactivate($a_ref_id);
187  }
188  }
189 
194  public function isEnabled()
195  {
196  return (bool) $this->enabled;
197  }
198 
203  protected function read()
204  {
206  $tree = $this->tree;
207 
208  $this->findEffectiveRefId();
209 
210  // member view is always enabled
211  // (2013-06-18, http://www.ilias.de/docu/goto_docu_wiki_1357_Reorganising_Administration.html)
212 
213  // $this->enabled = $ilSetting->get('preview_learner');
214  $this->enabled = true;
215 
216  if (isset($_SESSION['member_view_container'])) {
217  $this->active = true;
218  $this->container = (int) $_SESSION['member_view_container'];
219  $this->container_items = $tree->getSubTreeIds($this->getContainer());
220  }
221  }
222 
226  protected function findEffectiveRefId()
227  {
228  if ((int) $_GET['ref_id']) {
229  return $this->current_ref_id = (int) $_GET['ref_id'];
230  }
231 
232  $target_arr = explode('_', (string) $_GET['target']);
233  if (isset($target_arr[1]) and (int) $target_arr[1]) {
234  $this->current_ref_id = (int) $target_arr[1];
235  }
236  }
237 }
getContainer()
Returns $container.
$target_arr
Definition: goto.php:47
$_SESSION["AccountId"]
toggleActivation($a_ref_id, $a_activation)
Toggle activation status.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
setContainer($container)
Sets $container.
activate($a_ref_id)
Enable member view for this session and container.
getCurrentRefId()
Get current ref_id of request.
isActiveForRefId($a_ref_id)
Check if member view is currently enabled for given ref id.
Create styles array
The data for the language used.
isActive()
Check if member view currently enabled.
isEnabled()
Check if members view is enabled in the administration.
settings()
Definition: settings.php:2
findEffectiveRefId()
Find effective ref_id for request.
__construct()
Constructor (singleton)
global $ilSetting
Definition: privfeed.php:17
static getInstance()
Get instance.
deactivate()
Deactivate member view.