X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Faddresses.inc.php;h=97224767a74e7b5599b3e94cfb3aacfa34d62457;hb=ccc951d9ef4b747cf4c5b08d52e6f8938338f6de;hp=a59fa30d7e6019c5b96a16380f819ab0501ca30c;hpb=3f5cf357e7ab02c9cbf616bc8cc3a70278af62cc;p=platal.git diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index a59fa30..9722476 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -1,6 +1,6 @@ bool = new ProfileBool(); - $this->pub = new ProfilePub(); + $this->bool = new ProfileSettingBool(); + $this->pub = new ProfileSettingPub(); } private function cleanAddress(ProfilePage &$page, $addrid, array &$address) { - if (!isset($address['tel'])) { - $address['tel'] = array(); - } - $profiletel = new ProfilePhones('address', $addrid); - $address['tel'] = $profiletel->value($page, 'tel', $address['tel'], $s); + $address['tel'] = Phone::formatFormArray($address['tel'], $s); $address['current'] = $this->bool->value($page, 'current', $address['current'], $s); $address['temporary'] = $this->bool->value($page, 'temporary', $address['temporary'], $s); $address['secondary'] = $this->bool->value($page, 'secondary', $address['secondary'], $s); @@ -53,7 +49,7 @@ class ProfileAddress extends ProfileGeocoding } foreach ($value as $key => &$address) { if (isset($address['removed']) && $address['removed']) { - unset($value[$key]); + array_splice($value, $key, 1); } } $current = 0; @@ -64,7 +60,7 @@ class ProfileAddress extends ProfileGeocoding } } if ($current == 0 && count($value) > 0) { - foreach ($value as $address) { + foreach ($value as &$address) { $address['current'] = true; break; } @@ -83,38 +79,18 @@ class ProfileAddress extends ProfileGeocoding return $value; } - private function saveTel($addrid, $telid, array &$tel) - { - XDB::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, - search_tel, display_tel, pub) - VALUES ({?}, 'address', {?}, {?}, {?}, - {?}, {?}, {?})", - S::i('uid'), $addrid, $telid, $tel['type'], - format_phone_number($tel['tel']), $tel['tel'], $tel['pub']); - } - - public function saveAddress($addrid, array &$address, $type) + public function saveAddress($pid, $addrid, array &$address, $type) { - require_once "geocoding.inc.php"; + require_once 'geocoding.inc.php'; $flags = new PlFlagSet(); - if ($address['current']) { - $flags->addFlag('current'); - } - if ($address['temporary']) { - $flags->addFlag('temporary'); - } - if ($address['secondary']) { - $flags->addFlag('secondary'); - } - if ($address['mail']) { - $flags->addFlag('mail'); - } - if ($address['cedex'] = + $flags->addFlag('current', $address['current']); + $flags->addFlag('temporary', $address['temporary']); + $flags->addFlag('secondary', $address['secondary']); + $flags->addFlag('mail', $address['mail']); + $flags->addFlag('cedex', $address['cedex'] = (strpos(strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"), - array("", "\n"), $address['text'])), 'CEDEX')) !== false) { - $flags->addFlag('cedex'); - } + array("", "\n"), $address['text'])), 'CEDEX')) !== false); Geocoder::getAreaId($address, "administrativeArea"); Geocoder::getAreaId($address, "subAdministrativeArea"); Geocoder::getAreaId($address, "locality"); @@ -125,7 +101,7 @@ class ProfileAddress extends ProfileGeocoding north, south, east, west) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?}, {?}, {?})", - S::i('uid'), $type, $addrid, $flags, $address['accuracy'], + $pid, $type, $addrid, $flags, $address['accuracy'], $address['text'], $address['postalText'], $address['postalCode'], $address['localityId'], $address['subAdministrativeAreaId'], $address['administrativeAreaId'], $address['countryId'], $address['latitude'], $address['longitude'], @@ -137,26 +113,36 @@ class ProfileAddress extends ProfileGeocoding { XDB::execute("DELETE FROM profile_addresses WHERE pid = {?} AND type = 'home'", - S::i('uid')); - XDB::execute("DELETE FROM profile_phones - WHERE uid = {?} AND link_type = 'address'", - S::i('uid')); + $page->pid()); + Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS); foreach ($value as $addrid => &$address) { - $this->saveAddress($addrid, $address, 'home'); - $profiletel = new ProfilePhones('address', $addrid); - $profiletel->saveTels('tel', $address['tel']); + $this->saveAddress($page->pid(), $addrid, $address, 'home'); + Phone::savePhones($address['tel'], $page->pid(), Phone::LINK_ADDRESS, $addrid); } } + + public function getText($value) { + $addresses = array(); + foreach ($value as $addrid => $address) { + $phones = Phone::formArrayToString($address['tel']); + $addresses[] = 'Adresse : ' . $address['text'] . ', affichage : ' . $address['pub'] + . ', commentaire : ' . $address['comment'] . ', actuelle : ' . ($address['current'] ? 'oui' : 'non') + . ', temporaire : ' . ($address['temporary'] ? 'oui' : 'non') . ', secondaire : ' + . ($address['secondary'] ? 'oui' : 'non') . ', conctactable par courier : ' + . ($address['mail'] ? 'oui' : 'non') . ($phones ? ', ' . $phones : ''); + } + return implode(' ; ' , $addresses); + } } -class ProfileAddresses extends ProfilePage +class ProfileSettingAddresses extends ProfilePage { protected $pg_template = 'profile/adresses.tpl'; public function __construct(PlWizard &$wiz) { parent::__construct($wiz); - $this->settings['addresses'] = new ProfileAddress(); + $this->settings['addresses'] = new ProfileSettingAddress(); $this->watched['addresses'] = true; } @@ -174,52 +160,30 @@ class ProfileAddresses extends ProfilePage FROM profile_addresses WHERE pid = {?} AND type = 'home' ORDER BY id", - S::i('uid')); + $this->pid()); if ($res->numRows() == 0) { $this->values['addresses'] = array(); } else { $this->values['addresses'] = $res->fetchAllAssoc(); } - $res = XDB::iterator("SELECT link_id AS addrid, tel_type AS type, pub, display_tel AS tel, comment - FROM profile_phones - WHERE uid = {?} AND link_type = 'address' - ORDER BY link_id", - S::i('uid')); - $i = 0; - $adrNb = count($this->values['addresses']); - while ($tel = $res->next()) { - $adrid = $tel['addrid']; - unset($tel['addrid']); - while ($i < $adrNb && $this->values['addresses'][$i]['id'] < $adrid) { - $i++; - } - if ($i >= $adrNb) { - break; - } - $address =& $this->values['addresses'][$i]; - if (!isset($address['tel'])) { - $address['tel'] = array(); - } - if ($address['id'] == $adrid) { - $address['tel'][] = $tel; - } + // Adds phones to addresses. + $it = Phone::iterate(array($this->pid()), array(Phone::LINK_ADDRESS)); + while ($phone = $it->next()) { + $this->values['addresses'][$phone->linkId()]['tel'][$phone->id()] = $phone->toFormArray(); } + + // Properly formats addresses. foreach ($this->values['addresses'] as $id => &$address) { + $phone = new Phone(); if (!isset($address['tel'])) { - $address['tel'] = array( - 0 => array( - 'type' => 'fixed', - 'tel' => '', - 'pub' => 'private', - 'comment' => '', - ) - ); + $address['tel'] = array(0 => $phone->toFormArray()); } unset($address['id']); $address['changed'] = 0; $address['removed'] = 0; } + //var_dump($this->values['addresses']['tel']); } }