From df85e426c5e61301d2ccfd539bb8b2873b7f4d71 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 19 Mar 2010 00:33:09 +0100 Subject: [PATCH] Minor bugfixes in ProfileField (addPhones, addAddresses) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/profilefields.inc.php | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index b8a2098..b1f0f59 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -150,7 +150,7 @@ class Company /** Fields are: * $id, $name, $acronym, $url */ - public function __construct($date) + public function __construct($data) { foreach ($data as $key => $val) { $this->$key = $val; @@ -197,6 +197,7 @@ class Job foreach ($data as $key => $val) { $this->$key = $val; } + $this->setCompany(CompanyList::get($this->jobid)); } public function phones() @@ -241,7 +242,7 @@ class Address public $flags; public $text; - public $postcode; + public $postalCode; public $country; private $phones = array(); @@ -538,9 +539,10 @@ class ProfileAddresses extends ProfileField return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid')); } - public function addPhones($phones) + public function addPhones(ProfilePhones $phones) { - foreach ($phones as $phone) { + $p = $phones->get(0); + while ($phone = $p->next()) { if ($phone->link_type == Phone::LINK_ADDRESS && array_key_exists($phone->link_id, $this->addresses)) { $this->addresses[$phone->link_id]->addPhone($phone); } @@ -560,6 +562,20 @@ class ProfilePhones extends ProfileField } } + 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 PlIteratorUtils::fromArray($phones); + } + public static function fetchData(array $pids, $visibility) { $data = XDB::iterator('SELECT type, search, display, link_type, comment @@ -612,20 +628,20 @@ class ProfileJobs extends ProfileField return PlIteratorUtils::fromArray($jobs); } - public function addPhones(array $phones) + public function addPhones(ProfilePhones $phones) { - foreach ($phones as $phone) - { + $p = $phones->get(0); + while ($phone = $p->next()) { 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(array $addresses) + public static function addAddresses(ProfileAddresses $addresses) { - foreach ($addresses as $address) - { + $a = $addresses->get(Profile::ADDRESS_PRO); + while ($address = $a->next()) { if ($address->link_type == Address::LINK_JOB && array_key_exists($address->link_id, $this->jobs)) { $this->jobs[$address->link_id]->setAddress($address); } @@ -662,16 +678,16 @@ class CompanyList $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; } @@ -682,7 +698,7 @@ class CompanyList } } - static public function getCompany($id) + static public function get($id) { if (!array_key_exists($id, self::$companies)) { self::preload(); -- 2.1.4