From 3bad2574551cdc79ea75d8adebbc3510ba187005 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 15 Mar 2010 13:24:11 +0100 Subject: [PATCH] Fixes ProfileAddresses MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/profilefields.inc.php | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index 3f452fc..c213807 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -261,6 +261,11 @@ class Address { return $this->phones; } + + public function hasFlags($flags) + { + return $flags & $this->flags; + } } // }}} @@ -429,22 +434,42 @@ class ProfileAddresses extends ProfileField { private $addresses = array(); - private function __construct(PlIterator $addrs) + public function __construct(PlIterator $it) { + if ($it instanceof PlInnerSubIterator) { + $this->pid = $it->value(); + } + while ($addr = $it->next()) { - $this->addresses[] = Address::buildFromData($addr); + $this->addresses[] = new Address($addr); + } + } + + public function get($flags, $limit = null) + { + $res = array(); + $nb = 0; + foreach ($this->addresses as $addr) { + if ($addr->hasFlags($flags)) { + $res[] = $addr; + $nb++; + } + if ($limit != null && $nb == $limit) { + break; + } } + return PlIteratorUtils::fromArray($res); } public static function fetchData(array $pids, $visibility) { - $data = XDB::iterator('SELECT text, postalCode, type, latitude, longitude, + $data = XDB::iterator('SELECT pid, text, postalCode, type, latitude, longitude, flags, type FROM profile_addresses WHERE pid in {?} AND pub IN {?} ORDER BY ' . XDB::formatCustomOrder('pid', $pids), - XDB::formatArray($pids), - XDB::formatArray($visibility) + $pids, + $visibility ); return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid')); -- 2.1.4