From 34de4b2043533a45ae47ba9a2a0d73c9a2ff2f89 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Tue, 22 Jun 2010 23:59:58 +0200 Subject: [PATCH] Breaks networking to add network_type (im, social, web) --- classes/profile.php | 2 +- include/profilefields.inc.php | 32 ++++++++++++++++------------ upgrade/newdirectory-0.0.1/02_networking.sql | 17 ++++++++------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index 9352029..fec4cfc 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -128,7 +128,7 @@ class Profile const JOBS_FINISHED = 0x00004000; const JOBS_CURRENT = 0x00008000; - const NETWORKING_ALL = 0x00000000; + const NETWORKING_ALL = 0x00070000; const NETWORKING_WEB = 0x00010000; const NETWORKING_IM = 0x00020000; const NETWORKING_SOCIAL = 0x00040000; diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index c456d04..fc18b11 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -466,20 +466,23 @@ class ProfileNetworking extends ProfileField { private $networks = array(); - public function __construct(PlIterator $it) + public function __construct(PlInnerSubIterator $it) { + $this->pid = $it->value(); while ($network = $it->next()) { - $this->networks[$network['nwid']] = $network['address']; + $network['network_type'] = new PlFlagSet($network['network_type']); + $this->networks[$network['id']] = $network; } } public static function fetchData(array $pids, ProfileVisibility $visibility) { - $data = XDB::iterator('SELECT pid, nwid, address, network_type - FROM profile_networking + $data = XDB::iterator('SELECT pid, id, address, pne.network_type, pne.filter, pne.link + FROM profile_networking AS pn + LEFT JOIN profile_networking_enum AS pne USING(nwid) WHERE pid IN {?} AND pub IN {?} ORDER BY ' . XDB::formatCustomOrder('pid', $pids) . ', - network_type, nwid', + pn.nwid, id', $pids, $visibility->levels()); return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid')); @@ -487,20 +490,21 @@ class ProfileNetworking extends ProfileField public function get($flags, $limit = null) { + if (!$flags) { + $flags = Profile::NETWORKING_ALL; + } $nws = array(); $nb = 0; foreach ($this->networks as $id => $nw) { - // XXX hardcoded reference to web site index - if ( - (($flags & Profile::NETWORKING_WEB) && $nw['network_type'] == 0) - || - (! ($flags & Profile::NETWORKING_WEB)) - ) { + if (($flags & Profile::NETWORKING_WEB) && $nw['network_type']->hasFlag('web') || + ($flags & Profile::NETWORKING_IM) && $nw['network_type']->hasFlag('im') || + ($flags & Profile::NETWORKING_SOCIAL) && $nw['network_type']->hasFlag('social') || + ($flags & Profile::NETWORKING_ALL)) { $nws[$id] = $nw; ++$nb; - } - if ($nb >= $limit) { - break; + if ($nb >= $limit) { + break; + } } } return $nws; diff --git a/upgrade/newdirectory-0.0.1/02_networking.sql b/upgrade/newdirectory-0.0.1/02_networking.sql index 57f636c..0e4667d 100644 --- a/upgrade/newdirectory-0.0.1/02_networking.sql +++ b/upgrade/newdirectory-0.0.1/02_networking.sql @@ -2,30 +2,31 @@ DROP TABLE IF EXISTS profile_networking_enum; DROP TABLE IF EXISTS profile_networking; CREATE TABLE `profile_networking_enum` ( - `network_type` tinyint unsigned NOT NULL, + `nwid` tinyint unsigned NOT NULL, `name` varchar(30) NOT NULL, `icon` varchar(50) NOT NULL COMMENT 'icon filename', `filter` enum('email','web','number','none') NOT NULL DEFAULT 'none' COMMENT 'filter type for addresses', + `network_type` enum('web','im','social','other') NOT NULL DEFAULT 'other', `link` varchar(255) NOT NULL COMMENT 'string used to forge an URL linking to the the profile page', - PRIMARY KEY (`network_type`) + PRIMARY KEY (`nwid`) ) ENGINE=InnoDB, CHARSET=utf8, COMMENT='types of networking addresses'; CREATE TABLE `profile_networking` ( `pid` int NOT NULL COMMENT 'profile id', - `nwid` tinyint unsigned NOT NULL COMMENT 'number of the address for the user', - `network_type` tinyint unsigned NOT NULL, + `id` tinyint unsigned NOT NULL COMMENT 'number of the address for the user', + `nwid` tinyint unsigned NOT NULL COMMENT 'id of network, see profile_networking_enum', `address` varchar(255) NOT NULL, `pub` enum('private','public') NOT NULL DEFAULT 'private', - PRIMARY KEY (`pid`, `nwid`), + PRIMARY KEY (`pid`, `id`), INDEX uid (pid) ) ENGINE=InnoDB, CHARSET=utf8, COMMENT='networking addresses'; -- Insert a first address type for old URLs -INSERT INTO `profile_networking_enum` (`network_type`, `name`, `icon`, `filter`) - VALUES (0, 'Page web', 'web.gif', 'web'); +INSERT INTO `profile_networking_enum` (`nwid`, `name`, `icon`, `filter`, `network_type`, `link`) + VALUES (0, 'Page web', 'web.gif', 'web', 'web', '%s'); -INSERT INTO `profile_networking` (`pid`, `nwid`, `network_type`, `address`, `pub`) +INSERT INTO `profile_networking` (`pid`, `id`, `nwid`, `address`, `pub`) SELECT `user_id`, 0, 0, `profile_web`, `profile_web_pub` FROM #x4dat#.`auth_user_quick` WHERE `profile_web` <> ""; -- 2.1.4