X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Faddress.php;h=871526ae5e99bd8dfead04911a4f24ec2d42427f;hb=12160997cbae052d05f0ef4cb6fd5e9fe27eadb1;hp=0fab4edf839e3589e19358174131c9db95f44a2a;hpb=57fa97b3b0820a76b26a1d17c078c3663b161922;p=platal.git diff --git a/classes/address.php b/classes/address.php index 0fab4ed..871526a 100644 --- a/classes/address.php +++ b/classes/address.php @@ -311,6 +311,8 @@ class Address public $partial_match = false; public $componentsIds = ''; public $request = false; + public $geocoding_date = null; + public $geocoding_calls = 0; // Database's field required for both 'home' and 'job' addresses. public $pub = 'ax'; @@ -353,7 +355,7 @@ class Address array('', "\n"), $this->text)), 'CEDEX')) !== false); } } - $this->request = !is_null(AddressReq::get_request($this->pid, $this->jobid, $this->groupid, $this->type, $this->text)); + $this->request = ($this->request || !is_null(AddressReq::get_request($this->pid, $this->jobid, $this->groupid, $this->type, $this->id))); } public function setId($id) @@ -573,7 +575,7 @@ class Address public function format() { $this->text = trim($this->text); - $this->phones = Phone::formatFormArray($this->phones, $this->error, new ProfileVisibility($this->pub)); + $this->phones = Phone::formatFormArray($this->phones, $this->error, $this->pub); if ($this->removed == 1) { if (!S::user()->checkPerms('directory_private') && Phone::hasPrivate($this->phones)) { Platal::page()->trigWarning("L'adresse ne peut être supprimée car elle contient des informations pour lesquelles vous n'avez le droit d'édition."); @@ -587,13 +589,17 @@ class Address if ($this->changed == 1) { $gmapsGeocoder = new GMapsGeocoder(); $gmapsGeocoder->getGeocodedAddress($this); - } - $componants = array(); - foreach ($this->components as $component) { - $componants[] = Geocoder::getComponentId($component); + $componants = array(); + foreach ($this->components as $component) { + $componants[] = Geocoder::getComponentId($component); + } + $this->componentsIds = implode(',', $componants); + } + if ($this->componentsIds == '') { + $this->latitude = null; + $this->longitude = null; } - $this->componentsIds = implode(',', $componants); return true; } @@ -614,6 +620,8 @@ class Address 'location_type' => $this->location_type, 'partial_match' => $this->partial_match, 'componentsIds' => $this->componentsIds, + 'geocoding_date' => $this->geocoding_date, + 'geocoding_calls' => $this->geocoding_calls, 'request' => $this->request ); @@ -682,12 +690,13 @@ class Address if (!$this->isEmpty()) { 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) + southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude, + geocoding_date, geocoding_calls) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, - {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, 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->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude, $this->geocoding_calls); if ($this->componentsIds) { foreach (explode(',', $this->componentsIds) as $component_id) { @@ -695,57 +704,60 @@ class Address VALUES ({?}, {?}, {?}, {?}, {?}, {?})', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $component_id); } + } else { + // If the address was not geocoded, notifies it to the appropriate ML. + $mailer = new PlMailer('profile/no_geocoding.mail.tpl'); + $mailer->assign('text', $this->text); + $mailer->assign('primary_key', $this->pid . '-' . $this->jobid . '-' . $this->groupid . '-' . $this->type . '-' . $this->id); + $mailer->send(); } if ($this->type == self::LINK_PROFILE) { Phone::savePhones($this->phones, $this->pid, Phone::LINK_ADDRESS, $this->id); } + + if ($this->request) { + $req = new AddressReq(S::user(), $this->toFormArray(), $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); + $req->submit(); + } } } public function updateGeocoding($text) { - $id = null; - $texts = XDB::fetchAllAssoc('id', 'SELECT id, text - FROM profile_addresses - WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?}', - $this->pid, $this->jobid, $this->groupid, $this->type); - $text = preg_replace('/\s+/', ' ', $text); - foreach ($texts as $key => $value) { - if (strcmp($text, preg_replace('/\s+/', ' ', $value)) == 0) { - $id = $key; - break; - } - } - if (!is_null($id)) { - XDB::execute('UPDATE profile_addresses - SET text = {?}, postalText = {?}, types = {?}, formatted_address = {?}, - location_type = {?}, partial_match = {?}, latitude = {?}, longitude = {?}, - southwest_latitude = {?}, southwest_longitude = {?}, northeast_latitude = {?}, northeast_longitude = {?} - WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', - $this->text, $this->postalText, $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->pid, $this->jobid, $this->groupid, $this->type, $id); - - XDB::execute('DELETE FROM profile_addresses_components - WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', - $this->pid, $this->jobid, $this->groupid, $this->type, $id); - if ($this->componentsIds) { - foreach (explode(',', $this->componentsIds) as $component_id) { - XDB::execute('INSERT IGNORE INTO profile_addresses_components (pid, jobid, groupid, type, id, component_id) - VALUES ({?}, {?}, {?}, {?}, {?}, {?})', - $this->pid, $this->jobid, $this->groupid, $this->type, $id, $component_id); - } + XDB::execute('UPDATE profile_addresses + SET text = {?}, postalText = {?}, types = {?}, formatted_address = {?}, + location_type = {?}, partial_match = {?}, latitude = {?}, longitude = {?}, + southwest_latitude = {?}, southwest_longitude = {?}, northeast_latitude = {?}, northeast_longitude = {?}, + geocoding_date = NOW(), geocoding_calls = {?} + WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', + $this->text, $this->postalText, $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->pid, $this->jobid, $this->groupid, $this->type, $this->id); + + XDB::execute('DELETE FROM profile_addresses_components + WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', + $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); + if ($this->componentsIds) { + foreach (explode(',', $this->componentsIds) as $component_id) { + XDB::execute('INSERT IGNORE INTO profile_addresses_components (pid, jobid, groupid, type, id, component_id) + VALUES ({?}, {?}, {?}, {?}, {?}, {?})', + $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $component_id); } } } public function delete() { + XDB::execute('DELETE FROM profile_addresses_components + WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', + $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); XDB::execute('DELETE FROM profile_addresses WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); + + return XDB::affectedRows(); } static public function deleteAddresses($pid, $type, $jobid = null, $groupid = null, $deletePrivate = true) @@ -814,7 +826,7 @@ class Address // addresses before secondary addresses. static private function compare(array $a, array $b) { - $value = ProfileVisibility::comparePublicity($a, $b); + $value = Visibility::comparePublicity($a, $b); if ($value == 0) { if ($a['secondary'] != $b['secondary']) { $value = $a['secondary'] ? 1 : -1; @@ -866,9 +878,9 @@ class Address } static public function iterate(array $pids = array(), array $types = array(), - array $jobids = array(), array $pubs = array()) + array $jobids = array(), $visibility = null) { - return new AddressIterator($pids, $types, $jobids, $pubs); + return new AddressIterator($pids, $types, $jobids, $visibility); } } @@ -883,7 +895,7 @@ class AddressIterator implements PlIterator { private $dbiter; - public function __construct(array $pids, array $types, array $jobids, array $pubs) + public function __construct(array $pids, array $types, array $jobids, $visibility) { $where = array(); if (count($pids) != 0) { @@ -895,20 +907,30 @@ class AddressIterator implements PlIterator if (count($jobids) != 0) { $where[] = XDB::format('(pa.jobid IN {?})', $jobids); } - if (count($pubs) != 0) { - $where[] = XDB::format('(pa.pub IN {?})', $pubs); + if ($visibility == null || !($visibility instanceof Visibility)) { + $visibility = Visibility::defaultForRead(); } + $where[] = 'pve.best_display_level+0 <= pa.pub+0'; + $sql = 'SELECT pa.pid, pa.jobid, pa.groupid, pa.type, pa.id, pa.flags, pa.text, pa.postalText, pa.pub, pa.comment, pa.types, pa.formatted_address, pa.location_type, pa.partial_match, pa.latitude, pa.longitude, pa.southwest_latitude, pa.southwest_longitude, pa.northeast_latitude, pa.northeast_longitude, - GROUP_CONCAT(DISTINCT pc.component_id SEPARATOR \',\') AS componentsIds - FROM profile_addresses AS pa - LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid - AND pa.type = pc.type AND pa.id = pc.id) - ' . ((count($where) > 0) ? 'WHERE ' . implode(' AND ', $where) : '') . ' + pa.geocoding_date, pa.geocoding_calls, + GROUP_CONCAT(DISTINCT pc.component_id SEPARATOR \',\') AS componentsIds, + GROUP_CONCAT(pace1.long_name) AS postalCode, GROUP_CONCAT(pace2.long_name) AS locality, + GROUP_CONCAT(pace3.long_name) AS administrativeArea, GROUP_CONCAT(pace4.long_name) AS country + FROM profile_addresses AS pa + LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid + AND pa.type = pc.type AND pa.id = pc.id) + LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET(\'postal_code\', pace1.types) AND pace1.id = pc.component_id) + LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET(\'locality\', pace2.types) AND pace2.id = pc.component_id) + LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET(\'administrative_area_level_1\', pace3.types) AND pace3.id = pc.component_id) + LEFT JOIN profile_addresses_components_enum AS pace4 ON (FIND_IN_SET(\'country\', pace4.types) AND pace4.id = pc.component_id) + LEFT JOIN profile_visibility_enum AS pve ON (pve.access_level = {?}) + WHERE ' . implode(' AND ', $where) . ' 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); + $this->dbiter = XDB::iterator($sql, $visibility->level()); } public function next()