* @param $pids An array of pids
* @param $visibility The level of visibility fetched fields must have
* @return a PlIterator yielding data suitable for a "new ProfileBlah($data)"
+ * XXX MUST be reimplemented for each kind of ProfileField
*/
- abstract public static function fetchData(array $pids, $visibility);
+ public static function fetchData(array $pids, $visibility)
+ {
+ return PlIteratorUtils::emptyIterator();
+ }
public static function buildForPID($cls, $pid, $visibility)
{
}
return $res;
}
+
+ public static function getForPID($cls, $pid, $visibility)
+ {
+ $it = new ProfileFieldIterator($cls, array($pid), $visibility);
+ return $it->next();
+ }
}
// }}}
/** Fields are:
* $id, $name, $acronym, $url
*/
- public function __construct($date)
+ public function __construct($data)
{
foreach ($data as $key => $val) {
$this->$key = $val;
public $pid;
public $id;
- private $company = null;
+ public $company = null;
private $phones = array();
private $address = null;
- public $company_id;
+ public $jobid;
public $description;
- public $url;
- public $email;
+ public $user_site;
+ public $user_email;
+
+ public $sector;
+ public $subsector;
+ public $subsubsector;
/** Fields are:
* pid, id, company_id, description, url, email
foreach ($data as $key => $val) {
$this->$key = $val;
}
+ $this->company = CompanyList::get($this->jobid);
}
public function phones()
return $this->phones;
}
- public function company()
- {
- return $this->company;
- }
-
public function addPhone(Phone &$phone)
{
if ($phone->link_type == Phone::LINK_JOB && $phone->link_id == $this->id && $phone->pid == $this->pid) {
$this->address = $address;
}
}
-
- public function setCompany(Company $company)
- {
- $this->company = $company;
- }
}
// }}}
// {{{ class Address
const LINK_COMPANY = 'hq';
const LINK_PROFILE = 'home';
+ public $flags;
public $link_id;
public $link_type;
- public $flags;
public $text;
- public $postcode;
+ public $postalCode;
+ public $latitude;
+ public $longitude;
+
+ public $locality;
+ public $subAdministrativeArea;
+ public $administrativeArea;
public $country;
private $phones = array();
}
}
// }}}
+// {{{ class Education
+class Education
+{
+ public $id;
+ public $pid;
+
+ public $entry_year;
+ public $grad_year;
+ public $program;
+ public $flags;
+
+ public $school;
+ public $school_short;
+ public $school_url;
+ public $country;
+
+ public $degree;
+ public $degree_short;
+ public $degree_level;
+
+ public function __construct(array $data)
+ {
+ foreach ($data as $key => $val) {
+ $this->$key = $val;
+ }
+ $this->flags = new PlFlagSet($this->flags);
+ }
+}
+// }}}
// {{{ class ProfileEducation [ Field ]
class ProfileEducation extends ProfileField
{
- public $schools = array();
+ private $educations = array();
- private function __construct(PlIterator $it)
+ public function __construct(PlInnerSubIterator $it)
{
+ $this->pid = $it->value();
$this->visibility = Profile::VISIBILITY_PUBLIC;
while ($edu = $it->next()) {
- $this->schools[$edu['id']] = $edu;
+ $this->educations[$edu['id']] = new Education($edu);
}
}
+ public function get($flags, $limit)
+ {
+ $educations = array();
+ $year = getdate();
+ $year = $year['year'];
+ $nb = 0;
+ foreach ($this->educations as $id => $edu) {
+ if (
+ (($flags & Profile::EDUCATION_MAIN) && $edu->flags->hasFlag('primary'))
+ ||
+ (($flags & Profile::EDUCATION_EXTRA) && !$edu->flags->hasFlag('primary'))
+ ||
+ (($flags & Profile::EDUCATION_FINISHED) && $edu->grad_year <= $year)
+ ||
+ (($flags & Profile::EDUCATION_CURRENT) && $edu->grad_year > $year)
+ ||
+ ($flags & Profile::EDUCATION_ALL)
+ ) {
+ $educations[$id] = $edu;
+ ++$nb;
+ }
+ if ($limit != null && $nb >= $limit) {
+ break;
+ }
+ }
+ return $educations;
+ }
+
public static function fetchData(array $pids, $visibility)
{
- $data = XDB::iterator('SELECT *
- FROM profile_education
- WHERE pid IN {?}
- ORDER BY ' . XDB::formatCustomOrder('pid', $pids),
- $pids);
+ $data = XDB::iterator('SELECT pe.id, pe.pid,
+ pe.entry_year, pe.grad_year, pe.program, pe.flags,
+ pee.name AS school, pee.abbreviation AS school_short,
+ pee.url AS school_url, gc.countryFR AS country,
+ pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level,
+ pefe.field
+ FROM profile_education AS pe
+ LEFT JOIN profile_education_enum AS pee ON (pee.id = pe.eduid)
+ LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
+ LEFT JOIN profile_education_degree_enum AS pede ON (pede.id = pe.degreeid)
+ LEFT JOIN profile_education_field_enum AS pefe ON (pefe.id = pe.fieldid)
+ WHERE pe.pid IN {?}
+ ORDER BY ' . XDB::formatCustomOrder('pid', $pids) . ',
+ NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id',
+ $pids);
return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
}
{
public $medals = array();
- private function __construct(PlIterator $it)
+ public function __construct(PlInnerSubIterator $it)
{
+ $this->pid = $it->value();
while ($medal = $it->next()) {
- $this->medals[$medal['mid']] = $medal['gid'];
+ $this->medals[$medal['mid']] = $medal;
}
}
public static function fetchData(array $pids, $visibility)
{
- $data = XDB::iterator('SELECT pm.pid, pm.mid, pm.gid
+ $data = XDB::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img
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)
WHERE pm.pid IN {?} AND p.medals_pub IN {?}
ORDER BY ' . XDB::formatCustomOrder('pm.pid', $pids),
- XDB::formatArray($pids),
- XDB::formatArray($visibility)
- );
+ $pids, $visibility);
return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
}
class ProfileNetworking extends ProfileField
{
private $networks = array();
- private $visibilities = array();
- private function __construct(PlIterator $it)
+ public 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;
FROM profile_photos
WHERE pid IN {?} AND attachmime IN (\'jpeg\', \'png\') AND pub IN {?}
ORDER BY ' . XDB::formatCustomOrder('pid', $pids),
- $pids,
- $visibility
- );
+ $pids, $visibility);
return $data;
}
{
public $original;
public $current;
- public $rank;
- private function __construct(array $data)
+ public $original_name;
+ public $original_abbrev;
+ public $original_still_exists;
+
+ public $current_name;
+ public $current_abbrev;
+ public $current_still_exists;
+ public $current_rank;
+ public $current_rank_abbrev;
+
+ public function __construct(array $data)
{
- $this->original = $data['original_corpsid'];
- $this->current = $data['current_corpsid'];
- $this->rank = $data['rankid'];
- $this->visibility = $data['corps_pub'];
+ foreach ($data as $key => $val) {
+ $this->$key = $val;
+ }
}
public static function fetchData(array $pids, $visibility)
{
- $data = XDB::iterator('SELECT pid, original_corpsid, current_corpsid,
+ $data = XDB::iterator('SELECT pc.pid, pc.original_corpsid AS original, pc.current_corpsid AS current,
+ pceo.name AS original_name, pceo.abbreviation AS original_abbrev,
+ pceo.still_exists AS original_still_exists,
+ pcec.name AS current_name, pcec.abbreviation AS current_abbrev,
+ pcec.still_exists AS current_still_exists,
+ pcrec.name AS current_rank, pcrec.abbreviation AS current_rank_abbrev,
rankid
- FROM profile_corps
- WHERE pid IN {?} AND corps_pub IN {?}
+ FROM profile_corps AS pc
+ 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 {?}
ORDER BY ' . XDB::formatCustomOrder('pid', $pids),
- XDB::formatArray($pids),
- XDB::formatArray($visibility)
- );
+ $pids, $visibility);
return $data;
}
break;
}
}
- return PlIteratorUtils::fromArray($res);
+ return $res;
}
public static function fetchData(array $pids, $visibility)
{
- $data = XDB::iterator('SELECT pid, text, postalCode, type, latitude, longitude,
- flags, type
- FROM profile_addresses
- WHERE pid in {?} AND pub IN {?}
+ $data = XDB::iterator('SELECT pa.id, pa.pid, pa.flags, pa.type AS link_type,
+ IF(pa.type = \'home\', pid, jobid) AS link_id,
+ pa.text, pa.postalCode, pa.latitude, pa.longitude,
+ gl.name AS locality, gas.name AS subAdministrativeArea,
+ ga.name AS administrativeArea, gc.countryFR AS country
+ FROM profile_addresses AS pa
+ LEFT JOIN geoloc_localities AS gl ON (gl.id = pa.localityId)
+ LEFT JOIN geoloc_administrativeareas AS ga ON (ga.id = pa.administrativeAreaId)
+ LEFT JOIN geoloc_administrativeareas AS gas ON (gas.id = pa.subAdministrativeAreaId)
+ LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
+ WHERE pa.pid in {?} AND pa.pub IN {?}
ORDER BY ' . XDB::formatCustomOrder('pid', $pids),
- $pids,
- $visibility
- );
+ $pids, $visibility);
return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
}
- public static function addPhones(array $addresses, $phones)
+ public function addPhones(ProfilePhones $phones)
{
- foreach ($phones as $phone) {
- if ($phone->link_type == Phone::LINK_ADDRESS) {
- $addresses[$phone->link_id]->addPhone($phone);
+ $p = $phones->get(0);
+ foreach ($p as $phone) {
+ if ($phone->link_type == Phone::LINK_ADDRESS && array_key_exists($phone->link_id, $this->addresses)) {
+ $this->addresses[$phone->link_id]->addPhone($phone);
}
}
- return $addresses;
}
}
// }}}
{
private $phones = array();
- private function __construct(PlIterator $phones)
+ public function __construct(PlInnerSubIterator $it)
{
+ $this->pid = $it->value();
while ($phone = $it->next()) {
- $this->phones[] = Phone::buildFromData($phone);
+ $this->phones[] = new Phone($phone);
+ }
+ }
+
+ public function get($flags, $limit = null)
+ {
+ $phones = array();
+ $nb = 0;
+ foreach ($this->phones as $id => $phone) {
+ $phones[$id] = $phone;
+ ++$nb;
+ if ($limit != null && $nb == $limit) {
+ break;
+ }
}
+ return $phones;
}
public static function fetchData(array $pids, $visibility)
{
- $data = XDB::iterator('SELECT type, search, display, link_type, comment
+ $data = XDB::iterator('SELECT tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment
FROM profile_phones
WHERE pid IN {?} AND pub IN {?}
ORDER BY ' . XDB::formatCustomOrder('pid', $pids),
- XDB::formatArray($pids),
- XDB::formatArray($visibility)
- );
+ $pids, $visibility);
return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
}
}
{
private $jobs = array();
- private function __construct(PlIterator $jobs)
+ public function __construct(PlInnerSubIterator $jobs)
{
+ $this->pid = $jobs->value();
while ($job = $jobs->next()) {
- $this->jobs[] = Jobs::buildFromData($job);
+ $this->jobs[$job['id']] = new Job($job);
}
}
public static function fetchData(array $pids, $visibility)
{
- $data = XDB::iterator('SELECT description, url, jobid, IF(email_pub IN {?}, email, NULL) AS email
- FROM profile_job
- WHERE pid IN {?} AND pub IN {?}
- ORDER BY ' . XDB::formatCustomOrder('pid', $pids),
- XDB::formatArray($visibility),
- XDB::formatArray($pids),
- XDB::formatArray($visibility)
- );
+ CompanyList::preload($pids);
+ $data = XDB::iterator('SELECT pj.id, pj.pid, pj.description, pj.url as user_site,
+ IF(pj.email_pub IN {?}, pj.email, NULL) AS user_email,
+ pj.jobid, pjse.name AS sector, pjsse.name AS subsector,
+ pjssse.name AS subsubsector
+ FROM profile_job AS pj
+ LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pj.sectorid)
+ LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pj.subsectorid)
+ LEFT JOIN profile_job_subsubsector_enum AS pjssse ON (pjssse.id = pj.subsubsectorid)
+ WHERE pj.pid IN {?} AND pj.pub IN {?}
+ ORDER BY ' . XDB::formatCustomOrder('pid', $pids) . ',
+ pj.id',
+ $visibility, $pids, $visibility);
return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
}
- public static function addPhones(array $jobs, array $phones)
+ public function get($flags, $limit = null)
{
- foreach ($phones as $phone)
- {
- if ($phone->link_type == Phone::LINK_JOB) {
- $jobs[$phone->link_id]->addPhones($phone);
+ $jobs = array();
+ $nb = 0;
+ foreach ($this->jobs as $id => $job) {
+ $jobs[$id] = $job;
+ ++$nb;
+ if ($limit != null && $nb >= $limit) {
+ break;
}
}
return $jobs;
}
- public static function addAddresses(array $jobs, array $addresses)
+ public function addPhones(ProfilePhones $phones)
{
- foreach ($addresses as $address)
- {
- if ($address->link_type == Address::LINK_JOB) {
- $jobs[$address->link_id]->setAddress($address);
+ $p = $phones->get(0);
+ foreach ($p as $phone) {
+ if ($phone->link_type == Phone::LINK_JOB && array_key_exists($phone->link_id, $this->jobs)) {
+ $this->jobs[$phone->link_id]->addPhones($phone);
+ }
+ }
+ }
+
+ public static function addAddresses(ProfileAddresses $addresses)
+ {
+ $a = $addresses->get(Profile::ADDRESS_PRO);
+ foreach ($a as $address) {
+ if ($address->link_type == Address::LINK_JOB && array_key_exists($address->link_id, $this->jobs)) {
+ $this->jobs[$address->link_id]->setAddress($address);
}
}
- return $jobs;
}
- public static function addCompanies(array $jobs, array $companies)
+ public static function addCompanies(array $companies)
{
- foreach ($jobs as $job)
+ foreach ($this->jobs as $job)
{
- $job->setCompany($companies[$job->company_id]);
+ $job->company = $companies[$job->jobid];
}
- return $jobs;
}
}
// }}}
}
// Load raw data
if (count($pids)) {
- $join = 'LEFT JOIN profile_jobs ON (profile_job.jobid = profile_job_enum.id)';
- $where = 'profile_jobs.pid IN ' . XDB::formatArray($pids);
+ $join = 'LEFT JOIN profile_job ON (profile_job.jobid = pje.id)';
+ $where = 'WHERE profile_job.pid IN ' . XDB::formatArray($pids);
} else {
$join = '';
$where = '';
}
- $it = XDB::iterator('SELECT pje.id, pje.name, pje.acronmy, pje.url,
- pa.flags, pa.text, pa.postcode, pa.country,
- pa.link_type, pa.pub
+ $it = XDB::iterator('SELECT pje.id, pje.name, pje.acronym, pje.url,
+ pa.flags, pa.text, pa.postalCode, pa.countryId,
+ pa.type, pa.pub
FROM profile_job_enum AS pje
LEFT JOIN profile_addresses AS pa ON (pje.id = pa.jobid AND pa.type = \'hq\')
' . $join . '
' . $where);
while ($row = $it->next()) {
- $cp = Company::buildFromData($row);
- $addr = Address::buildFromData($row);
+ $cp = new Company($row);
+ $addr = new Address($row);
$cp->setAddress($addr);
self::$companies[$row['id']] = $cp;
}
}
}
- static public function getCompany($id)
+ static public function get($id)
{
if (!array_key_exists($id, self::$companies)) {
self::preload();