From b3d5464e39000e3c6fe1ba436751f85972fe9db7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 11 Feb 2011 14:19:12 +0100 Subject: [PATCH] Adds comparison function based on items' publicity and uses it to order profile item in such an order. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/address.php | 4 +++- classes/phone.php | 4 +++- classes/profilevisibility.php | 25 +++++++++++++++++++++++-- modules/profile/jobs.inc.php | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) 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; } -- 2.1.4