X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fprofilefields.inc.php;h=d2de1326d5d7671b3425e93725b26633f63ca91a;hb=1f5cd0048509cf752b1a95106367ca0b1a75683c;hp=9af88ff4978636f9933944030dac43d5489e4d46;hpb=4d1f0f6bd236c719cf3bc2119767424dbf86616f;p=platal.git diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index 9af88ff..d2de132 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -151,6 +151,42 @@ class Phone $this->$key = $val; } } + + public function hasFlags($flags) { + return $this->hasType($flags) && $this->hasLink($flags); + } + + /** Returns true if this phone's type matches the flags + */ + public function hasType($flags) { + $flags = $flags & Profile::PHONE_TYPE_ANY; + return ( + ($flags == Profile::PHONE_TYPE_ANY) + || + (($flags & Profile::PHONE_TYPE_FAX) && $this->type == self::TYPE_FAX) + || + (($flags & Profile::PHONE_TYPE_FIXED) && $this->type == self::TYPE_FIXED) + || + (($flags & Profile::PHONE_TYPE_MOBILE) && $this->type == self::TYPE_MOBILE) + ); + } + + /** Returns true if this phone's link matches the flags + */ + public function hasLink($flags) { + $flags = $flags & Profile::PHONE_LINK_ANY; + return ( + ($flags == Profile::PHONE_LINK_ANY) + || + (($flags & Profile::PHONE_LINK_COMPANY) && $this->link_type == self::LINK_COMPANY) + || + (($flags & Profile::PHONE_LINK_JOB) && $this->link_type == self::LINK_JOB) + || + (($flags & Profile::PHONE_LINK_ADDRESS) && $this->link_type == self::LINK_ADDRESS) + || + (($flags & Profile::PHONE_LINK_PROFILE) && $this->link_type == self::LINK_PROFILE) + ); + } } // }}} // {{{ class Company @@ -295,6 +331,9 @@ class Address public function hasFlag($flag) { + if (!$this->flags instanceof PlFlagSet) { + $this->flags = new PlFlagSet($this->flags); + } return $this->flags->hasFlag($flag); } } @@ -409,10 +448,11 @@ class ProfileMedals extends ProfileField public static function fetchData(array $pids, ProfileVisibility $visibility) { - $data = XDB::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img + $data = XDB::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade FROM profile_medals AS pm LEFT JOIN profiles AS p ON (pm.pid = p.pid) LEFT JOIN profile_medal_enum AS pme ON (pme.id = pm.mid) + LEFT JOIN profile_medal_grade_enum AS pmge ON (pmge.mid = pm.mid AND pmge.gid = pm.gid) WHERE pm.pid IN {?} AND p.medals_pub IN {?} ORDER BY ' . XDB::formatCustomOrder('pm.pid', $pids), $pids, $visibility->levels()); @@ -426,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.nwid, pne.network_type, pne.link, pne.name + 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')); @@ -447,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 & self::NETWORKING_WEB) && $nw['network_type'] == 0) - || - (! ($flags & self::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 (isset($limit) && $nb >= $limit) { + break; + } } } return $nws; @@ -503,7 +547,7 @@ class ProfileCorps extends ProfileField LEFT JOIN profile_corps_enum AS pceo ON (pceo.id = pc.original_corpsid) LEFT JOIN profile_corps_enum AS pcec ON (pcec.id = pc.current_corpsid) LEFT JOIN profile_corps_rank_enum AS pcrec ON (pcrec.id = pc.rankid) - WHERE pc.pid IN {?} AND pc.corps_pub IN {?} + WHERE pc.pid IN {?} AND pc.corps_pub IN {?} AND pceo.id != 1 ORDER BY ' . XDB::formatCustomOrder('pid', $pids), $pids, $visibility->levels()); @@ -661,10 +705,12 @@ class ProfilePhones extends ProfileField $phones = array(); $nb = 0; foreach ($this->phones as $id => $phone) { - $phones[$id] = $phone; - ++$nb; - if ($limit != null && $nb == $limit) { - break; + if ($phone->hasFlags($flags)) { + $phones[$id] = $phone; + ++$nb; + if ($limit != null && $nb == $limit) { + break; + } } } return $phones; @@ -672,7 +718,7 @@ class ProfilePhones extends ProfileField public static function fetchData(array $pids, ProfileVisibility $visibility) { - $data = XDB::iterator('SELECT tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment + $data = XDB::iterator('SELECT tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment, pid FROM profile_phones WHERE pid IN {?} AND pub IN {?} ORDER BY ' . XDB::formatCustomOrder('pid', $pids), @@ -736,7 +782,7 @@ class ProfileJobs extends ProfileField } } - public static function addAddresses(ProfileAddresses $addresses) + public function addAddresses(ProfileAddresses $addresses) { $a = $addresses->get(Profile::ADDRESS_PRO); foreach ($a as $address) { @@ -746,11 +792,10 @@ class ProfileJobs extends ProfileField } } - public static function addCompanies(array $companies) + public function addCompanies(array $companies) { - foreach ($this->jobs as $job) - { - $job->company = $companies[$job->jobid]; + foreach ($this->jobs as $job) { + $this->company = $companies[$job->jobid]; } } }