X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fprofilefields.inc.php;h=d2de1326d5d7671b3425e93725b26633f63ca91a;hb=cd7a9c53f9dfb4c2d33f9340feadcc3dbcfc1876;hp=79a3b88df15805ccc5f37c9002977dad1c995b81;hpb=1f8250e4ceb455a4469266b0702c4cad5b2b4be0;p=platal.git diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index 79a3b88..d2de132 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -26,13 +26,15 @@ abstract class ProfileField { public static $fields = array( - Profile::FETCH_ADDRESSES => 'ProfileAddresses', - Profile::FETCH_CORPS => 'ProfileCorps', - Profile::FETCH_EDU => 'ProfileEducation', - Profile::FETCH_JOBS => 'ProfileJobs', - Profile::FETCH_MEDALS => 'ProfileMedals', - Profile::FETCH_NETWORKING => 'ProfileNetworking', - Profile::FETCH_PHONES => 'ProfilePhones', + Profile::FETCH_ADDRESSES => 'ProfileAddresses', + Profile::FETCH_CORPS => 'ProfileCorps', + Profile::FETCH_EDU => 'ProfileEducation', + Profile::FETCH_JOBS => 'ProfileJobs', + Profile::FETCH_MEDALS => 'ProfileMedals', + Profile::FETCH_NETWORKING => 'ProfileNetworking', + Profile::FETCH_PHONES => 'ProfilePhones', + Profile::FETCH_MENTOR_SECTOR => 'ProfileMentoringSectors', + Profile::FETCH_MENTOR_COUNTRY => 'ProfileMentoringCountries', ); /** The profile to which this field belongs @@ -149,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 @@ -293,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); } } @@ -407,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()); @@ -424,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')); @@ -445,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; @@ -501,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()); @@ -509,6 +555,59 @@ class ProfileCorps extends ProfileField } } // }}} +// {{{ class ProfileMentoringSectors [ Field ] +class ProfileMentoringSectors extends ProfileField +{ + public $sectors = array(); + + public function __construct(PlInnerSubIterator $it) + { + $this->pid = $it->value(); + while ($sector = $it->next()) { + $this->sectors[] = $sector; + } + } + + public static function fetchData(array $pids, ProfileVisibility $visibility) + { + $data = XDB::iterator('SELECT pms.pid, pjse.name AS sector, pjsse.name AS subsector + FROM profile_mentor_sector AS pms + LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pms.sectorid) + LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pms.subsectorid) + WHERE pms.pid IN {?} + ORDER BY ' . XDB::formatCustomOrder('pms.pid', $pids), + $pids); + + return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid')); + } +} +// }}} +// {{{ class ProfileMentoringCountries [ Field ] +class ProfileMentoringCountries extends ProfileField +{ + public $countries = array(); + + public function __construct(PlInnerSubIterator $it) + { + $this->pid = $it->value(); + while ($country = $it->next()) { + $this->countries[$country['id']] = $country['name']; + } + } + + public static function fetchData(array $pids, ProfileVisibility $visibility) + { + $data = XDB::iterator('SELECT pmc.pid, pmc.country AS id, gc.countryFR AS name + FROM profile_mentor_country AS pmc + LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pmc.country) + WHERE pmc.pid IN {?} + ORDER BY ' . XDB::formatCustomOrder('pmc.pid', $pids), + $pids); + + return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid')); + } +} +// }}} /** Loading of data for a Profile : * 1) load jobs, addresses, phones @@ -606,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; @@ -617,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), @@ -681,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) { @@ -691,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]; } } }