Finishes advanced search on addresses to our new geocoding engine (gmaps v3).
[platal.git] / classes / profilevisibility.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
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, $force = false)
35 {
36 if ($force) {
37 $this->forceLevel($level);
38 } else {
39 $this->setLevel($level);
40 }
41 }
42
43 public function setLevel($level = self::VIS_PUBLIC)
44 {
45 if ($level != null && $level != self::VIS_PRIVATE && $level != self::VIS_AX && $level != self::VIS_PUBLIC) {
46 Platal::page()->kill("Invalid visibility: " . $level);
47 }
48
49 // Unlogged or not allowed to view directory_ax or requesting public
50 // => public view
51 if (!S::logged() || !S::user()->checkPerms('directory_ax') || $level == self::VIS_PUBLIC) {
52 $level = self::VIS_PUBLIC;
53 // Not allowed to view directory_private or requesting ax
54 } else if (!S::user()->checkPerms('directory_private') || $level == self::VIS_AX) {
55 $level = self::VIS_AX;
56 } else {
57 $level = self::VIS_PRIVATE;
58 }
59
60 if ($this->level == null || $this->level == self::VIS_PRIVATE) {
61 $this->level = $level;
62 } else if ($this->level == self::VIS_AX && $level == self::VIS_PRIVATE) {
63 return;
64 } else {
65 $this->level = self::VIS_PUBLIC;
66 }
67 }
68
69 public function forceLevel($level)
70 {
71 if ($level != self::VIS_PRIVATE && $level != self::VIS_AX && $level != self::VIS_PUBLIC) {
72 Platal::page()->kill('Invalid visibility: ' . $level);
73 }
74
75 $this->level = $level;
76 }
77
78 public function level()
79 {
80 if ($this->level == null) {
81 return self::VIS_PUBLIC;
82 } else {
83 return $this->level;
84 }
85 }
86
87 public function levels()
88 {
89 return self::$v_values[$this->level()];
90 }
91
92 public function isVisible($visibility)
93 {
94 return in_array($visibility, $this->levels());
95 }
96
97 static public function comparePublicity($a, $b)
98 {
99 $a_pub = new ProfileVisibility($a['pub'], true);
100 $b_pub = new ProfileVisibility($b['pub'], true);
101
102 return !$a_pub->isVisible($b_pub->level());
103 }
104 }
105
106
107 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
108 ?>