From 598c57f6857d2ab4059bbfeb51cacb6ecdad17ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 22 Mar 2010 11:13:37 +0100 Subject: [PATCH] Modify ProfileFields retrieval API : no more iterators MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit $profile->getAddresses now returns an array, use $profile->iterAddresses for a PlIterator Signed-off-by: Raphaël Barrois --- classes/profile.php | 29 +++++++++++++++++------------ include/profilefields.inc.php | 16 ++++++++-------- include/vcard.inc.php | 4 ++-- modules/carnet/contacts.pdf.inc.php | 4 ++-- templates/include/minifiche.tpl | 2 +- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index a09f3eb..f55b0a2 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -376,18 +376,23 @@ class Profile } if ($this->addresses == null) { - return PlIteratorUtils::emptyIterator(); + return array(); } return $this->addresses->get($flags, $limit); } + public function iterAddresses($flags, $limit = null) + { + return PlIteratorUtils::fromArray($this->getAddresses($flags, $limit), 1, true); + } + public function getMainAddress() { - $it = $this->getAddresses(self::ADDRESS_PERSO | self::ADDRESS_MAIN); - if ($it->total() == 0) { + $addr = $this->getAddresses(self::ADDRESS_PERSO | self::ADDRESS_MAIN); + if (count($addr) == 0) { return null; } else { - return $it->next(); + return array_pop($addr); } } @@ -407,7 +412,7 @@ class Profile } if ($this->phones == null) { - return PlIteratorUtils::emptyIterator(); + return array(); } return $this->phones->get($flags, $limit); } @@ -427,7 +432,7 @@ class Profile } if ($this->educations == null) { - return PlIteratorUtils::emptyIterator(); + return array(); } return $this->educations->get($flags, $limit); } @@ -467,7 +472,7 @@ class Profile $this->setNetworking($this->getProfileField('ProfileNetworking')); } if ($this->networks == null) { - return PlIteratorUtils::emptyIterator(); + return array(); } return $this->networks->get($flags, $limit); } @@ -475,10 +480,10 @@ class Profile public function getWebSite() { $site = $this->getNetworking(self::NETWORKING_WEB, 1); - if ($site->total() != 1) { + if (count($site) != 1) { return null; } - $site = $site->next(); + $site = array_pop($site); return $site['address']; } @@ -499,7 +504,7 @@ class Profile } if ($this->jobs == null) { - return PlIteratorUtils::emptyIterator(); + return array(); } return $this->jobs->get($flags, $limit); } @@ -507,10 +512,10 @@ class Profile public function getMainJob() { $job = $this->getJobs(self::JOBS_MAIN, 1); - if ($job->total() != 1) { + if (count($job) != 1) { return null; } - return $job->next(); + return array_pop($job); } /* Binets diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index b0b8490..0bb11ba 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -348,7 +348,7 @@ class ProfileEducation extends ProfileField break; } } - return PlIteratorUtils::fromArray($educations, 1, true); + return $educations; } public static function fetchData(array $pids, $visibility) @@ -442,7 +442,7 @@ class ProfileNetworking extends ProfileField break; } } - return PlIteratorUtils::fromArray($nws, 1, true); + return $nws; } } // }}} @@ -556,7 +556,7 @@ class ProfileAddresses extends ProfileField break; } } - return PlIteratorUtils::fromArray($res, 1, true); + return $res; } public static function fetchData(array $pids, $visibility) @@ -581,7 +581,7 @@ class ProfileAddresses extends ProfileField public function addPhones(ProfilePhones $phones) { $p = $phones->get(0); - while ($phone = $p->next()) { + 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); } @@ -613,7 +613,7 @@ class ProfilePhones extends ProfileField break; } } - return PlIteratorUtils::fromArray($phones, 1, true); + return $phones; } public static function fetchData(array $pids, $visibility) @@ -669,13 +669,13 @@ class ProfileJobs extends ProfileField break; } } - return PlIteratorUtils::fromArray($jobs, 1, true); + return $jobs; } public function addPhones(ProfilePhones $phones) { $p = $phones->get(0); - while ($phone = $p->next()) { + 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); } @@ -685,7 +685,7 @@ class ProfileJobs extends ProfileField public static function addAddresses(ProfileAddresses $addresses) { $a = $addresses->get(Profile::ADDRESS_PRO); - while ($address = $a->next()) { + 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); } diff --git a/include/vcard.inc.php b/include/vcard.inc.php index 9cbd7c0..2a1402a 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -83,7 +83,7 @@ class VCard extends PlVCard } // Homes - $adrs = $pf->getAddresses(Profile::ADDRESS_PERSO); + $adrs = $pf->iterAddresses(Profile::ADDRESS_PERSO); while ($adr = $adrs->next()) { // TODO : find a way to fetch only the "street" part of the address $group = $entry->addHome($adr['text'], null, null, $adr['postalCode'], @@ -98,7 +98,7 @@ class VCard extends PlVCard } // Pro - $adrs = $pf->getAddresses(Profile::ADDRESS_PRO); + $adrs = $pf->iterAddresses(Profile::ADDRESS_PRO); while ($adr = $adrs->next()) { // TODO : link address to company $group = $entry->addWork(null, null, null, null, diff --git a/modules/carnet/contacts.pdf.inc.php b/modules/carnet/contacts.pdf.inc.php index ff5aff9..175cbc7 100644 --- a/modules/carnet/contacts.pdf.inc.php +++ b/modules/carnet/contacts.pdf.inc.php @@ -315,7 +315,7 @@ class ContactsPDF extends FPDF $self->TableRow('mobile', utf8_decode($profile->mobile), 'Mono'); } - $it = $profile->getAddresses(Profile::ADDRESS_ALL); + $it = $profile->iterAddresses(Profile::ADDRESS_ALL); while ($a = $it->next()) { foreach ($a as &$value) { $value = utf8_decode($value); @@ -323,7 +323,7 @@ class ContactsPDF extends FPDF $self->Space(); $self->Address($a); } - $it = $profile->getAddresses(Profile::ADDRESS_PRO); + $it = $profile->iterAddresses(Profile::ADDRESS_PRO); while ($a = $it->next()) { foreach ($a as &$value) { $value = utf8_decode($value); diff --git a/templates/include/minifiche.tpl b/templates/include/minifiche.tpl index c4f0dfa..33add8f 100644 --- a/templates/include/minifiche.tpl +++ b/templates/include/minifiche.tpl @@ -64,7 +64,7 @@ {$nat}  {/foreach} {$profile->promo()}{* - *}{iterate from=$profile->getExtraEducations(4) item=edu}, {display_education edu=$edu profile=$profile}{/iterate}{* + *}{foreach from=$profile->getExtraEducations(4) item=edu}, {display_education edu=$edu profile=$profile}{/foreach}{* *}{if $dead}, {"décédé"|sex:"décédée":$profile} le {$profile->deathdate|date_format}{/if} -- 2.1.4