From dc953a0c9234074471ece73cce091ed1dd02d70f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Thu, 24 Jun 2010 01:24:34 +0200 Subject: [PATCH] Fix display of pro phones (Closes #1092, #1148) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/profilefields.inc.php | 38 ++++++++++++++++++++++++++------------ templates/profile/profile.tpl | 7 ++++++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index d2de132..edeb6cb 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 */ @@ -320,7 +322,7 @@ class Address public function addPhone(Phone &$phone) { if ($phone->link_type == Phone::LINK_ADDRESS && $phone->link_id == $this->id && $phone->pid == $this->pid) { - $this->phones[] = $phone; + $this->phones[$phone->id] = $phone; } } @@ -627,7 +629,7 @@ class ProfileAddresses extends ProfileField } while ($addr = $it->next()) { - $this->addresses[] = new Address($addr); + $this->addresses[$addr['id']] = new Address($addr); } } @@ -637,15 +639,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++; @@ -678,7 +678,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 +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, 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 +774,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 +828,28 @@ 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 + $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; } diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index 3056871..0525acd 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -230,7 +230,12 @@ function chgMainWinLoc(strPage) {if $i neq 0}
{/if} {include file="include/emploi.tpl" job=$job} {if $job->address()} - {include file="geoloc/address.tpl" address=$job->address titre="Adresse : " for=$job->company->name pos="left"} + {include file="geoloc/address.tpl" address=$job->address() titre="Adresse : " for=$job->company->name pos="left"} + {elseif $job->company->address} + {include file="geoloc/address.tpl" address=$job->company->address titre="Addresse : " for=$job->company->name pos="left"} + {/if} + {if $job->phones()} + {display_phones tels=$job->phones()} {/if}
 
{/foreach} -- 2.1.4