/* Educations
*/
- private $educations;
+ private $educations = null;
public function setEducations(ProfileEducation $edu)
{
$this->educations = $edu;
public function getEducations($flags, $limit = null)
{
+ if ($this->educations == null) {
+ return PlIteratorUtils::fromArray(array());
+ }
return $this->educations->get($flags, $limit);
}
/** 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()
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);
}
}
// }}}