ILIAS  Release_4_1_x_branch Revision 61804
 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 
42  private function __construct()
43  {
44  $this->read();
45  }
46 
51  public static function getInstance()
52  {
53  if(self::$instance != null)
54  {
55  return self::$instance;
56  }
57  return self::$instance = new ilMemberViewSettings();
58  }
59 
64  public function getContainer()
65  {
66  return $this->container;
67  }
68 
74  public function setContainer($container)
75  {
76  $this->container = $container;
77  $_SESSION['member_view_container'] = $this->container;
78  $_SESSION['il_cont_admin_panel'] = false;
79  }
80 
85  public function isActive()
86  {
87  global $tree;
88 
89  if(!$this->active)
90  {
91  // Not active
92  return false;
93  }
94 
95  $ref_id = $_GET['ref_id'] ? $_GET['ref_id'] : null;
96  if(!$ref_id)
97  {
98  $target_arr = explode('_',(string) $_GET['target']);
99  $ref_id = $target_arr[1] ? $target_arr[1] : null;
100  }
101 
102  if(!$ref_id)
103  {
104  // No ref id given => mail, search, personal desktop menu in other tab
105  return false;
106  }
107 
108  if(!in_array($ref_id,$this->container_items) and
109  $this->getContainer() != $ref_id)
110  {
111  // outside of course
112  return false;
113  }
114  return true;
115  }
116 
123  public function activate($a_ref_id)
124  {
125  $this->active = true;
126  $this->setContainer($a_ref_id);
127  }
128 
133  public function deactivate()
134  {
135  $this->active = false;
136  $this->container = null;
137  unset($_SESSION['member_view_container']);
138  }
139 
146  public function toggleActivation($a_ref_id,$a_activation)
147  {
148  if($a_activation)
149  {
150  return $this->activate($a_ref_id);
151  }
152  else
153  {
154  return $this->deactivate($a_ref_id);
155  }
156  }
157 
162  public function isEnabled()
163  {
164  return (bool) $this->enabled;
165  }
166 
171  protected function read()
172  {
173  global $ilSetting,$tree;
174 
175  $this->enabled = $ilSetting->get('preview_learner');
176 
177  if(isset($_SESSION['member_view_container']))
178  {
179  $this->active = true;
180  $this->container = (int) $_SESSION['member_view_container'];
181  $this->container_items = $tree->getSubTreeIds($this->getContainer());
182  }
183  }
184 }
185 ?>