X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fprofilefields.inc.php;h=27ffeb222b70202cf67ae0df523e09724fe52440;hb=28c20b86be8b40cecba0d83080879f81c49e07ad;hp=fc18b116571e9c6edb1f7b2b162b89874525498a;hpb=34de4b2043533a45ae47ba9a2a0d73c9a2ff2f89;p=platal.git diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index fc18b11..27ffeb2 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -135,13 +135,15 @@ class Phone public $display; public $comment = ''; - const LINK_JOB = 'job'; + const LINK_JOB = 'pro'; const LINK_ADDRESS = 'address'; const LINK_PROFILE = 'user'; const LINK_COMPANY = 'hq'; public $link_type; public $link_id; + public $id; + /** Fields are : * $type, $search, $display, $link_type, $link_id, $comment, $pid, $id */ @@ -152,6 +154,15 @@ class Phone } } + /** Returns the unique ID of a phone + * This ID will allow to link it to an address, a user or a job + * The format is address_addressId_phoneId (where phoneId is the id + * of the phone in the list of those associated with the address) + */ + public function uid() { + return $this->link_type . '_' . $this->link_id . '_' . $this->id; + } + public function hasFlags($flags) { return $this->hasType($flags) && $this->hasLink($flags); } @@ -171,6 +182,22 @@ class Phone ); } + /** User accessible version of the type + */ + public function displayType($short = false) + { + switch ($this->type) { + case Phone::TYPE_FIXED: + return $short ? 'Tél' : 'Fixe'; + case Phone::TYPE_FAX: + return 'Fax'; + case Phone::TYPE_MOBILE: + return $short ? 'Mob' : 'Mobile'; + default: + return $this->type; + } + } + /** Returns true if this phone's link matches the flags */ public function hasLink($flags) { @@ -269,13 +296,13 @@ class Job public function addPhone(Phone &$phone) { if ($phone->link_type == Phone::LINK_JOB && $phone->link_id == $this->id && $phone->pid == $this->pid) { - $this->phones[] = $phone; + $this->phones[$phone->uid()] = $phone; } } public function setAddress(Address $address) { - if ($address->link_id == Address::LINK_JOB && $address->link_id == $this->id && $address->pid == $this->pid) { + if ($address->link_type == Address::LINK_JOB && $address->link_id == $this->id && $address->pid == $this->pid) { $this->address = $address; } } @@ -289,7 +316,8 @@ class Address const LINK_PROFILE = 'home'; public $flags; - public $link_id; + public $id; // The ID of the address among those associated with its link + public $link_id; // The ID of the object to which the address is linked (profile, job, company) public $link_type; public $text; @@ -317,10 +345,20 @@ class Address $this->flags = new PlFlagSet($this->flags); } + public function uid() { + $uid = $this->link_type . '_'; + if ($this->link_type != self::LINK_COMPANY) { + $uid .= $this->pid . '_'; + } + $uid .= $this->link_id . '_' . $this->id; + } + public function addPhone(Phone &$phone) { - if ($phone->link_type == Phone::LINK_ADDRESS && $phone->link_id == $this->id && $phone->pid == $this->pid) { - $this->phones[] = $phone; + if ( + $phone->link_type == Phone::LINK_ADDRESS && $phone->link_id == $this->id && + ($this->link_type == self::LINK_COMPANY || $phone->pid == $this->pid) ) { + $this->phones[$phone->uid()] = $phone; } } @@ -477,7 +515,7 @@ class ProfileNetworking extends ProfileField public static function fetchData(array $pids, ProfileVisibility $visibility) { - $data = XDB::iterator('SELECT pid, id, address, pne.network_type, pne.filter, pne.link + $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 {?} @@ -490,19 +528,16 @@ 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) { 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)) { + ($flags == Profile::NETWORKING_ALL)) { $nws[$id] = $nw; ++$nb; - if ($nb >= $limit) { + if (isset($limit) && $nb >= $limit) { break; } } @@ -615,6 +650,64 @@ class ProfileMentoringCountries extends ProfileField * 3) attach addresses to jobs and profiles */ +// {{{ Database schema (profile_address, profile_phones, profile_jobs) +/** The database for this is very unclear, so here is a little schema : + * profile_job describes a Job, links to: + * - a Profile, through `pid` + * - a Company, through `jobid` + * The `id` field is the id of this job in the list of the jobs of its profile + * + * profile_addresses describes an Address, which + * related to either a Profile, a Job or a Company: + * - for a Profile: + * - `type` is set to 'home' + * - `pid` is set to the related profile pid + * - `id` is the id of the address in the list of those related to that profile + * - `jobid` is empty + * + * - for a Company: + * - `type` is set to 'hq' + * - `pid` is set to 0 + * - `jobid` is set to the id of the company + * - `id` is set to 0 (only one address per Company) + * + * - for a Job: + * - `type` is set to 'job' + * - `pid` is set to the pid of the Profile of the related Job + * - `jobid` is set to the Company of the job (this information is redundant + * with that of the row of profile_job for the related job) + * - `id` is the id of the job to which we refer (i.e `profile_job.id`) + * + * profile_phone describes a Phone, which can be related to an Address, + * a Job, a Profile or a Company: + * - for a Profile: + * - `link_type` is set to 'user' + * - `link_id` is set to 0 + * - `pid` is set to the id of the related Profile + * + * - for a Company: + * - `link_type` is set to 'hq' + * - `link_id` is set to the id of the related Company + * - `pid` is set to 0 + * + * - for an Address (this is only possible for a *personal* address) + * - `link_type` is set to 'address' + * - `link_id` is set to the related Address `id` + * - `pid` is set to the related Address `pid` + * + * - for a Job: + * - `link_type` is set to 'pro' + * - `link_id` is set to the related Job `id` (not `jobid`) + * - `pid` is set to the related Job `pid` + * + * + * The possible relations are as follow: + * An Address can be linked to a Company, a Profile, a Job + * A Job is linked to a Company and a Profile + * A Phone can be linked to a Company, a Profile, a Job, or a Profile-related Address + */ +// }}} + // {{{ class ProfileAddresses [ Field ] class ProfileAddresses extends ProfileField { @@ -637,15 +730,13 @@ class ProfileAddresses extends ProfileField $nb = 0; foreach ($this->addresses as $addr) { if ( - ($flags & Profile::ADDRESS_ALL) - || (($flags & Profile::ADDRESS_MAIN) && $addr->hasFlag('current')) || (($flags & Profile::ADDRESS_POSTAL) && $addr->hasFlag('mail')) || - (($flags & Profile::ADDRESS_PERSO) && $addr->link_type == 'home') + (($flags & Profile::ADDRESS_PERSO) && $addr->link_type == Address::LINK_PROFILE) || - (($flags & Profile::ADDRESS_PRO) && $addr->link_type == 'job') + (($flags & Profile::ADDRESS_PRO) && $addr->link_type == Address::LINK_JOB) ) { $res[] = $addr; $nb++; @@ -660,7 +751,7 @@ class ProfileAddresses extends ProfileField public static function fetchData(array $pids, ProfileVisibility $visibility) { $data = XDB::iterator('SELECT pa.id, pa.pid, pa.flags, pa.type AS link_type, - IF(pa.type = \'home\', pid, jobid) AS link_id, + IF(pa.type = \'home\', pid, IF(pa.type = \'job\', pa.id, jobid)) AS link_id, pa.text, pa.postalCode, pa.latitude, pa.longitude, pa.comment, gl.name AS locality, gas.name AS subAdministrativeArea, ga.name AS administrativeArea, gc.countryFR AS country @@ -678,7 +769,7 @@ class ProfileAddresses extends ProfileField public function addPhones(ProfilePhones $phones) { - $p = $phones->get(0); + $p = $phones->get(Profile::PHONE_LINK_ADDRESS | Profile::PHONE_TYPE_ANY); 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); @@ -718,7 +809,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, pid + $data = XDB::iterator('SELECT tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment, pid, link_id, tel_id AS id FROM profile_phones WHERE pid IN {?} AND pub IN {?} ORDER BY ' . XDB::formatCustomOrder('pid', $pids), @@ -774,10 +865,10 @@ class ProfileJobs extends ProfileField public function addPhones(ProfilePhones $phones) { - $p = $phones->get(0); + $p = $phones->get(Profile::PHONE_LINK_JOB | Profile::PHONE_TYPE_ANY); 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); + $this->jobs[$phone->link_id]->addPhone($phone); } } } @@ -828,14 +919,30 @@ class CompanyList LEFT JOIN profile_addresses AS pa ON (pje.id = pa.jobid AND pa.type = \'hq\') ' . $join . ' ' . $where); + $newcompanies = array(); while ($row = $it->next()) { $cp = new Company($row); $addr = new Address($row); $cp->setAddress($addr); + if (!array_key_exists($row['id'], self::$companies)) { + $newcompanies[] = $row['id']; + } self::$companies[$row['id']] = $cp; } - // TODO: add phones to addresses + // TODO: determine whether there can be phones attached to a hq's address + // Add phones to hq + if (count($newcompanies)) { + $it = XDB::iterator('SELECT search_tel AS search, display_tel AS display, comment, link_id, tel_type AS type, link_type, tel_id AS id + FROM profile_phones + WHERE link_id IN {?} AND link_type = \'hq\'', + $newcompanies); + while ($row = $it->next()) { + $p = new Phone($row); + self::$companies[$row['link_id']]->setPhone($p); + } + } + if (count($pids) == 0) { self::$fullload = true; }