From d4d395bbdf6fdb819eaf5af9b8b64cbc82d7e2e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Tue, 16 Mar 2010 19:11:46 +0100 Subject: [PATCH] Add ProfileNetworking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/profile.php | 28 ++++++++++++---------------- include/profilefields.inc.php | 31 +++++++++++++++++++------------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index f3fb591..4cfc845 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -354,7 +354,7 @@ class Profile /* Educations */ - private $educations; + private $educations = null; public function setEducations(ProfileEducation $edu) { $this->educations = $edu; @@ -362,6 +362,9 @@ class Profile public function getEducations($flags, $limit = null) { + if ($this->educations == null) { + return PlIteratorUtils::fromArray(array()); + } return $this->educations->get($flags, $limit); } @@ -373,25 +376,18 @@ class Profile /** Networking */ + private $networks = null; + public function setNetworking(ProfileNetworking $nw) + { + $this->networks = $nw; + } public function getNetworking($flags, $limit = null) { - $where = XDB::format('pn.pid = {?}', $this->id()); - if ($flags & self::NETWORKING_WEB) { - $where .= ' AND pn.network_type = 0'; // XXX hardcoded reference to web site index - } - if ($this->visibility) { - $where .= ' AND pn.pub IN ' . XDB::formatArray($this->visibility); + if ($this->networks == null) { + return PlIteratorUtils::fromArray(array()); } - $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit); - return XDB::iterator('SELECT pne.name, pne.icon, - IF (LENGTH(pne.link) > 0, REPLACE(pne.link, \'%s\', pn.address), - pn.address) AS address - FROM profile_networking AS pn - INNER JOIN profile_networking_enum AS pne ON (pn.network_type = pne.network_type) - WHERE ' . $where . ' - ORDER BY pn.network_type, pn.nwid - ' . $limit); + return $this->networks->get($flags, $limit); } public function getWebSite() diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index ec64e92..44aa6e2 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -379,38 +379,45 @@ class ProfileMedals extends ProfileField class ProfileNetworking extends ProfileField { private $networks = array(); - private $visibilities = array(); private function __construct(PlIterator $it) { while ($network = $it->next()) { $this->networks[$network['nwid']] = $network['address']; - $this->visibilities[$network['nwid']] = $network['pub']; } } public static function fetchData(array $pids, $visibility) { - $data = XDB::iterator('SELECT pid, nwid, address, pub + $data = XDB::iterator('SELECT pid, nwid, address, network_type FROM profile_networking WHERE pid IN {?} AND pub IN {?} - ORDER BY ' . XDB::formatCustomOrder('pid', $pids), - XDB::formatArray($pids), - XDB::formatArray($visibility) - ); + ORDER BY ' . XDB::formatCustomOrder('pid', $pids) . ', + network_type, nwid', + $pids, $visibility); return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid')); } - public function networks() + public function get($flags, $limit = null) { $nws = array(); - foreach ($this->visibilities as $id => $vis) { - if ($this->profile->isVisible($vis)) { - $nws[$id] = $this->networks[$id]; + $nb = 0; + foreach ($this->networks as $id => $nw) { + // XXX hardcoded reference to web site index + if ( + (($flags & self::NETWORKING_WEB) && $nw['network_type'] == 0) + || + (! ($flags & self::NETWORKING_WEB)) + ) { + $nws[$id] = $nw; + ++$nb; + } + if ($nb >= $limit) { + break; } } - return $nws; + return PlIteratorUtils::fromArray($nws); } } // }}} -- 2.1.4