X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Faddress.php;h=b3e9da97bedc9d2d50f086f0bb03a269ca0f3a94;hb=8a1f4fbfc77d96055ad3bf3e7784bd01b1bafb14;hp=af0e2f02323ec72847588f45a589ee07e78e9401;hpb=e93255ef54304c697ef7ac101247f23dc5f7b31f;p=platal.git diff --git a/classes/address.php b/classes/address.php index af0e2f0..b3e9da9 100644 --- a/classes/address.php +++ b/classes/address.php @@ -1,6 +1,6 @@ $line) { @@ -499,7 +501,8 @@ class Address $formattedLine = $this->getStreetNumberFR($line) . ' '; $limit = 32; } elseif ($this->isLocalityFR($line)) { - $formattedLine = $this->getPostalCodeFR($line) . ' '; + $postal_code = $this->getPostalCodeFR($line); + $formattedLine = $postal_code . ' '; $limit = 32; } else { $formattedLine = ''; @@ -536,6 +539,7 @@ class Address $arrayText[$lineNumber] = trim($formattedLine); } + $this->postal_code_fr = $postal_code; return implode("\n", $arrayText); } @@ -625,14 +629,16 @@ class Address 'request' => $this->request ); - if ($this->type == self::LINK_PROFILE || $this->type == self::LINK_JOB) { - $address['pub'] = $this->pub; + if ($this->type == self::LINK_JOB) { + $address['pub'] = $this->pub; + $address['mail'] = $this->flags->hasFlag('mail'); } if ($this->type == self::LINK_PROFILE) { static $flags = array('current', 'temporary', 'secondary', 'mail', 'cedex', 'deliveryIssue'); foreach ($flags as $flag) { $address[$flag] = $this->flags->hasFlag($flag); } + $address['pub'] = $this->pub; $address['comment'] = $this->comment; $address['phones'] = Phone::formatFormArray($this->phones); } @@ -691,12 +697,12 @@ class Address XDB::execute('INSERT IGNORE INTO profile_addresses (pid, jobid, groupid, type, id, flags, text, postalText, pub, comment, types, formatted_address, location_type, partial_match, latitude, longitude, southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude, - geocoding_date, geocoding_calls) + geocoding_date, geocoding_calls, postal_code_fr) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, - {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, NOW(), {?})', + {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, NOW(), {?}, {?})', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $this->flags, $this->text, $this->postalText, $this->pub, $this->comment, $this->types, $this->formatted_address, $this->location_type, $this->partial_match, $this->latitude, $this->longitude, - $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude, $this->geocoding_calls); + $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude, $this->geocoding_calls, $this->postal_code_fr); if ($this->componentsIds) { foreach (explode(',', $this->componentsIds) as $component_id) { @@ -720,6 +726,46 @@ class Address $req = new AddressReq(S::user(), $this->toFormArray(), $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); $req->submit(); } + + if ($this->pid != 0) { + $this->updateBestMail(); + } + } + } + + /** + * Upate the denormalized flag which is used to mark the best mail to use + * when sending postal mail + */ + private function updateBestMail() + { + XDB::execute("UPDATE profile_addresses + SET flags = REPLACE(flags, 'dn_best_mail', '') + WHERE pid = {?}", + $this->pid); + + /* Following order is selected to find the best mail: + * * Use addresses without the deliveryIssue flag if possible. + * * Among these, use addresses flagged as "current". + * * If there is no such addresses or several ones, prefer those + * without "secondary" flag. + * * If there are still several addresses in the selection, try not + * to select the ones with "job" type. + */ + $best_mail = XDB::fetchOneAssoc("SELECT pid, jobid, groupid, type, id + FROM profile_addresses + WHERE FIND_IN_SET('mail', flags) AND pid = {?} + ORDER BY FIND_IN_SET('deliveryIssue', flags), + NOT FIND_IN_SET('current', flags), + FIND_IN_SET('secondary', flags), type = 'job' + LIMIT 1", + $this->pid); + + if ($best_mail) { + XDB::execute("UPDATE profile_addresses + SET flags = CONCAT(flags, ',dn_best_mail') + WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}", + $best_mail['pid'], $best_mail['jobid'], $best_mail['groupid'], $best_mail['type'], $best_mail['id']); } } @@ -884,16 +930,17 @@ class Address } } -/** Iterator over a set of Phones +/** Iterator over a set of Addresses * * @param $pid, $type, $jobid, $pub * - * The iterator contains the phones that correspond to the value stored in the - * parameters' arrays. + * The iterator contains the addresses that correspond to the value stored in + * the parameters' arrays. */ class AddressIterator implements PlIterator { private $dbiter; + private $visibility; public function __construct(array $pids, array $types, array $jobids, $visibility, $_where) { @@ -934,6 +981,7 @@ class AddressIterator implements PlIterator GROUP BY pa.pid, pa.jobid, pa.groupid, pa.type, pa.id ORDER BY pa.pid, pa.jobid, pa.id'; $this->dbiter = XDB::iterator($sql, $visibility->level()); + $this->visibility = $visibility; } public function next() @@ -946,7 +994,7 @@ class AddressIterator implements PlIterator return null; } // Adds phones to addresses. - $it = Phone::iterate(array($data['pid']), array(Phone::LINK_ADDRESS), array($data['id'])); + $it = Phone::iterate(array($data['pid']), array(Phone::LINK_ADDRESS), array($data['id']), $this->visibility); while ($phone = $it->next()) { $data['phones'][$phone->id] = $phone->toFormArray(); } @@ -974,5 +1022,5 @@ class AddressIterator implements PlIterator } } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>