ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
31  private static $instance = null;
32 
33  private $active = false;
34  private $enabled = false;
35  private $container = null;
36  private $container_items = array();
37 
38  private $current_ref_id = 0;
39 
44  private function __construct()
45  {
46  $this->read();
47  }
48 
53  public static function getInstance()
54  {
55  if(self::$instance != null)
56  {
57  return self::$instance;
58  }
59  return self::$instance = new ilMemberViewSettings();
60  }
61 
66  public function getContainer()
67  {
68  return $this->container;
69  }
70 
75  public function getCurrentRefId()
76  {
77  return $this->current_ref_id;
78  }
79 
85  public function setContainer($container)
86  {
87  $this->container = $container;
88  $_SESSION['member_view_container'] = $this->container;
89  $_SESSION['il_cont_admin_panel'] = false;
90  }
91 
96  public function isActive()
97  {
98  global $tree;
99 
100  if(!$this->active)
101  {
102  // Not active
103  return false;
104  }
105 
106 
107  if(!$this->getCurrentRefId())
108  {
109  // No ref id given => mail, search, personal desktop menu in other tab
110  return false;
111  }
112 
113  if(!in_array($this->getCurrentRefId(),$this->container_items) and
114  $this->getContainer() != $this->getCurrentRefId())
115  {
116  // outside of course
117  return false;
118  }
119  return true;
120  }
121 
127  public function isActiveForRefId($a_ref_id)
128  {
129  if(!$this->active || !(int)$a_ref_id)
130  {
131  // Not active
132  return false;
133  }
134 
135  if(!in_array($a_ref_id,$this->container_items) and
136  $this->getContainer() != $a_ref_id)
137  {
138  // outside of course
139  return false;
140  }
141  return true;
142  }
143 
150  public function activate($a_ref_id)
151  {
152  $this->active = true;
153  $this->setContainer($a_ref_id);
154  }
155 
160  public function deactivate()
161  {
162  $this->active = false;
163  $this->container = null;
164  unset($_SESSION['member_view_container']);
165  }
166 
173  public function toggleActivation($a_ref_id,$a_activation)
174  {
175  if($a_activation)
176  {
177  return $this->activate($a_ref_id);
178  }
179  else
180  {
181  return $this->deactivate($a_ref_id);
182  }
183  }
184 
189  public function isEnabled()
190  {
191  return (bool) $this->enabled;
192  }
193 
198  protected function read()
199  {
200  global $ilSetting,$tree;
201 
202  $this->findEffectiveRefId();
203 
204  // member view is always enabled
205  // (2013-06-18, http://www.ilias.de/docu/goto_docu_wiki_1357_Reorganising_Administration.html)
206 
207  // $this->enabled = $ilSetting->get('preview_learner');
208  $this->enabled = true;
209 
210  if(isset($_SESSION['member_view_container']))
211  {
212  $this->active = true;
213  $this->container = (int) $_SESSION['member_view_container'];
214  $this->container_items = $tree->getSubTreeIds($this->getContainer());
215  }
216  }
217 
221  protected function findEffectiveRefId()
222  {
223  if((int) $_GET['ref_id'])
224  {
225  return $this->current_ref_id = (int) $_GET['ref_id'];
226  }
227 
228  $target_arr = explode('_',(string) $_GET['target']);
229  if(isset($target_arr[1]) and (int) $target_arr[1])
230  {
231  $this->current_ref_id = (int) $target_arr[1];
232  }
233  }
234 }
235 ?>