Can't see anything * public => Can see public data * ax => Can see AX and public data * private => Can see private, AX and public data * hidden => Can only be seen by admins */ const VIS_NONE = 'none'; const VIS_PUBLIC = 'public'; const VIS_AX = 'ax'; const VIS_PRIVATE = 'private'; const VIS_HIDDEN = 'hidden'; private $level; static private $v_levels = array( self::VIS_NONE => array(), self::VIS_PUBLIC => array(self::VIS_PUBLIC), self::VIS_AX => array(self::VIS_AX, self::VIS_PUBLIC), self::VIS_PRIVATE => array(self::VIS_PRIVATE, self::VIS_AX, self::VIS_PUBLIC), self::VIS_HIDDEN => array(self::VIS_HIDDEN, self::VIS_PRIVATE, self::VIS_AX, self::VIS_PUBLIC), ); public function __construct($level = null) { $this->level = $level; } public function level() { if ($this->level == null) { return self::VIS_PUBLIC; } else { return $this->level; } } public static function defaultForRead($max_level = null) { if (!S::logged()) { $vis = new ProfileVisibility(self::VIS_PUBLIC); } else { $vis = S::user()->readVisibility(); } if ($max_level != null) { return $vis->restrict($max_level); } else { return $vis; } } public static function defaultForEdit($max_level = null) { if (!S::logged()) { $vis = new ProfileVisibility(self::VIS_NONE); } else { $vis = S::user()->editVisibility(); } if ($max_level != null) { return $vis->restrict($max_level); } else { return $vis; } } /** Retrieve a 'restricted' version of the current ProfileVisibility. * * @param $level The visibility level to restrict to * @return A new ProfileVisibility instance, whose level is min($this->level, $level) */ public function restrict($level = null) { if ($level != null && !$this->isVisible($level)) { $level = $this->level(); } else { $level = $this->level(); } return new ProfileVisibility($level); } public function levels() { return self::$v_levels[$this->level()]; } public function isVisible($visibility) { return in_array($visibility, $this->levels()); } static public function comparePublicity($a, $b) { $a_pub = new ProfileVisibility($a['pub'], true); $b_pub = new ProfileVisibility($b['pub'], true); return !$a_pub->isVisible($b_pub->level()); } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>