- $where = XDB::format('pa.pid = {?}', $this->id());
- if ($flags & self::ADDRESS_MAIN) {
- $where .= ' AND FIND_IN_SET(\'current\', pa.flags)';
- }
- if ($flags & self::ADDRESS_POSTAL) {
- $where .= ' AND FIND_IN_SET(\'mail\', pa.flags)';
- }
- if ($this->visibility) {
- $where .= ' AND pa.pub IN ' . XDB::formatArray($this->visibility);
- }
- $type = array();
- if ($flags & self::ADDRESS_PRO) {
- $type[] = 'job';
- }
- if ($flags & self::ADDRESS_PERSO) {
- $type[] = 'home';
- }
- if (count($type) > 0) {
- $where .= ' AND pa.type IN ' . XDB::formatArray($type);
- }
- $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
- return XDB::iterator('SELECT pa.text, pa.postalCode, pa.type, pa.latitude, pa.longitude,
- gl.name AS locality, gas.name AS subAdministrativeArea,
- ga.name AS administrativeArea, gc.countryFR AS country,
- ppfix.display_tel AS fixed_tel, ppfax.display_tel AS fax_tel,
- FIND_IN_SET(\'current\', pa.flags) AS current,
- FIND_IN_SET(\'temporary\', pa.flags) AS temporary,
- FIND_IN_SET(\'secondary\', pa.flags) AS secondary,
- FIND_IN_SET(\'mail\', pa.flags) AS mail, pa.type
- 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)
- LEFT JOIN profile_phones AS ppfix ON (ppfix.link_type = \'address\' AND ppfix.pid = pa.pid AND ppfix.link_id = pa.id AND ppfix.tel_type = \'fixed\')
- LEFT JOIN profile_phones AS ppfax ON (ppfax.link_type = \'address\' AND ppfax.pid = pa.pid AND ppfax.link_id = pa.id AND ppfax.tel_type = \'fax\')
- WHERE ' . $where . '
- ORDER BY pa.id
- ' . $limit);
+ if ($this->addresses == null && !$this->fetched(self::FETCH_ADDRESSES)) {
+ $addr = $this->getProfileField(self::FETCH_ADDRESSES);
+ if ($addr) {
+ $this->setAddresses($addr);
+ }
+ }
+
+ if ($this->addresses == null) {
+ return array();
+ }
+ return $this->addresses->get($flags, $limit);
+ }
+
+ public function iterAddresses($flags, $limit = null)
+ {
+ return PlIteratorUtils::fromArray($this->getAddresses($flags, $limit), 1, true);