Commit | Line | Data |
---|---|---|
3c60ccca RB |
1 | <?php |
2 | /*************************************************************************** | |
5e1513f6 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
3c60ccca RB |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | class ProfileVisibility | |
23 | { | |
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)); | |
27 | ||
28 | const VIS_PUBLIC = 'public'; | |
29 | const VIS_AX = 'ax'; | |
30 | const VIS_PRIVATE = 'private'; | |
31 | ||
32 | private $level; | |
33 | ||
34 | public function __construct($level = null) | |
35 | { | |
36 | $this->setLevel($level); | |
37 | } | |
38 | ||
39 | public function setLevel($level = self::VIS_PUBLIC) | |
40 | { | |
41 | if ($level != null && $level != self::VIS_PRIVATE && $level != self::VIS_AX && $level != self::VIS_PUBLIC) { | |
42 | Platal::page()->kill("Invalid visibility: " . $level); | |
43 | } | |
44 | ||
45 | // Unlogged or not allowed to view directory_ax or requesting public | |
46 | // => public view | |
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; | |
52 | } else { | |
53 | $level = self::VIS_PRIVATE; | |
54 | } | |
55 | ||
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) { | |
59 | return; | |
60 | } else { | |
61 | $this->level = self::VIS_PUBLIC; | |
62 | } | |
63 | } | |
64 | ||
65 | public function level() | |
66 | { | |
67 | if ($this->level == null) { | |
68 | return self::VIS_PUBLIC; | |
69 | } else { | |
70 | return $this->level; | |
71 | } | |
72 | } | |
73 | ||
74 | public function levels() | |
75 | { | |
76 | return self::$v_values[$this->level()]; | |
77 | } | |
78 | ||
79 | public function isVisible($visibility) | |
80 | { | |
81 | return in_array($visibility, $this->levels()); | |
82 | } | |
83 | } | |
84 | ||
85 | ||
86 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
87 | ?> |