From: Stéphane Jacob Date: Fri, 11 Feb 2011 13:19:12 +0000 (+0100) Subject: Adds comparison function based on items' publicity and uses it to order profile item... X-Git-Tag: xorg/1.1.0~1^2~28 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=b3d5464e39000e3c6fe1ba436751f85972fe9db7;p=platal.git Adds comparison function based on items' publicity and uses it to order profile item in such an order. Signed-off-by: Stéphane Jacob --- diff --git a/classes/address.php b/classes/address.php index 3be8b91..d338680 100644 --- a/classes/address.php +++ b/classes/address.php @@ -826,7 +826,9 @@ class Address } } - return self::formArrayWalk($data, 'toFormArray', $success, true); + $addresses = self::formArrayWalk($data, 'toFormArray', $success, true); + usort($addresses, 'ProfileVisibility::comparePublicity'); + return $addresses; } static public function formArrayToString(array $data) diff --git a/classes/phone.php b/classes/phone.php index 9a9f1b0..3d602be 100644 --- a/classes/phone.php +++ b/classes/phone.php @@ -375,7 +375,9 @@ class Phone // Formats an array of form phones into an array of form formatted phones. static public function formatFormArray(array $data, &$success = true, $maxPublicity = null) { - return self::formArrayWalk($data, 'toFormArray', $success, true, $maxPublicity); + $phones = self::formArrayWalk($data, 'toFormArray', $success, true, $maxPublicity); + usort($phones, 'ProfileVisibility::comparePublicity'); + return $phones; } static public function formArrayToString(array $data) diff --git a/classes/profilevisibility.php b/classes/profilevisibility.php index e7dbbd4..cf5687d 100644 --- a/classes/profilevisibility.php +++ b/classes/profilevisibility.php @@ -31,9 +31,13 @@ class ProfileVisibility private $level; - public function __construct($level = null) + public function __construct($level = null, $force = false) { - $this->setLevel($level); + if ($force) { + $this->forceLevel($level); + } else { + $this->setLevel($level); + } } public function setLevel($level = self::VIS_PUBLIC) @@ -62,6 +66,15 @@ class ProfileVisibility } } + public function forceLevel($level) + { + if ($level != self::VIS_PRIVATE && $level != self::VIS_AX && $level != self::VIS_PUBLIC) { + Platal::page()->kill('Invalid visibility: ' . $level); + } + + $this->level = $level; + } + public function level() { if ($this->level == null) { @@ -80,6 +93,14 @@ class ProfileVisibility { 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()); + } } diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 0420c84..d258517 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -248,6 +248,7 @@ class ProfileSettingJob implements ProfileSetting $success = ($success && $s); } } + usort($value, 'ProfileVisibility::comparePublicity'); return $value; }