2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileVisibility
24 static private $v_values = array(self
::VIS_PUBLIC
=> array(self
::VIS_PUBLIC
),
25 self
::VIS_AX
=> array(self
::VIS_AX
, self
::VIS_PUBLIC
),
26 self
::VIS_PRIVATE
=> array(self
::VIS_PRIVATE
, self
::VIS_AX
, self
::VIS_PUBLIC
));
28 const VIS_PUBLIC
= 'public';
30 const VIS_PRIVATE
= 'private';
34 public function __construct($level = null
)
36 $this->setLevel($level);
39 public function setLevel($level = self
::VIS_PUBLIC
)
41 if ($level != null
&& $level != self
::VIS_PRIVATE
&& $level != self
::VIS_AX
&& $level != self
::VIS_PUBLIC
) {
42 Platal
::page()->kill("Invalid visibility: " . $level);
45 // Unlogged or not allowed to view directory_ax or requesting public
47 if (!S
::logged() ||
!S
::user()->checkPerms('directory_ax') ||
$level == self
::VIS_PUBLIC
) {
48 $level = self
::VIS_PUBLIC
;
49 // Not allowed to view directory_private or requesting ax
50 } else if (!S
::user()->checkPerms('directory_private') ||
$level == self
::VIS_AX
) {
51 $level = self
::VIS_AX
;
53 $level = self
::VIS_PRIVATE
;
56 if ($this->level
== null ||
$this->level
== self
::VIS_PRIVATE
) {
57 $this->level
= $level;
58 } else if ($this->level
== self
::VIS_AX
&& $level == self
::VIS_PRIVATE
) {
61 $this->level
= self
::VIS_PUBLIC
;
65 public function level()
67 if ($this->level
== null
) {
68 return self
::VIS_PUBLIC
;
74 public function levels()
76 return self
::$v_values[$this->level()];
79 public function isVisible($visibility)
81 return in_array($visibility, $this->levels());
86 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: