X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Faddress.php;h=af0e2f02323ec72847588f45a589ee07e78e9401;hb=47712f77e9718652c516c85cde99a58d142f67c9;hp=7bea442e391df8ed6a5ec799411ca1ec48def5ed;hpb=72a4c6a8987a0a1d34e3d76f8c9673f3e3ad3ebf;p=platal.git diff --git a/classes/address.php b/classes/address.php index 7bea442..af0e2f0 100644 --- a/classes/address.php +++ b/classes/address.php @@ -355,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) @@ -575,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."); @@ -589,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; } @@ -681,7 +685,7 @@ class Address return (!$this->text || $this->text == ''); } - public function save() + public function save($notify_ungeocoded = true) { if (!$this->isEmpty()) { XDB::execute('INSERT IGNORE INTO profile_addresses (pid, jobid, groupid, type, id, flags, text, postalText, pub, comment, @@ -700,58 +704,60 @@ class Address VALUES ({?}, {?}, {?}, {?}, {?}, {?})', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $component_id); } + } elseif ($notify_ungeocoded) { + // 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 = {?}, - geocoding_date = {?}, geocoding_calls = NOW() - 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, $this->geocoding_calls); - - 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) @@ -820,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; @@ -872,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, $where = null) { - return new AddressIterator($pids, $types, $jobids, $pubs); + return new AddressIterator($pids, $types, $jobids, $visibility, $where); } } @@ -889,9 +895,12 @@ 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) { $where = array(); + if (!is_null($_where)) { + $where[] = $_where; + } if (count($pids) != 0) { $where[] = XDB::format('(pa.pid IN {?})', $pids); } @@ -901,35 +910,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, pa.geocoding_date, pa.geocoding_calls, GROUP_CONCAT(DISTINCT pc.component_id SEPARATOR \',\') AS componentsIds, - pace1.long_name AS postalCode, pace2.long_name AS locality, pace3.long_name AS administrativeArea, pace4.long_name AS country + 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)) - LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET(\'locality\', pace2.types)) - LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET(\'administrative_area_level_1\', pace3.types)) - LEFT JOIN profile_addresses_components_enum AS pace4 ON (FIND_IN_SET(\'country\', pace4.types)) - LEFT JOIN profile_addresses_components AS pac1 ON (pa.pid = pac1.pid AND pa.jobid = pac1.jobid AND pa.groupid = pac1.groupid - AND pa.id = pac1.id AND pa.type = pac1.type AND pace1.id = pac1.component_id) - LEFT JOIN profile_addresses_components AS pac2 ON (pa.pid = pac2.pid AND pa.jobid = pac2.jobid AND pa.groupid = pac2.groupid - AND pa.id = pac2.id AND pa.type = pac2.type AND pace2.id = pac2.component_id) - LEFT JOIN profile_addresses_components AS pac3 ON (pa.pid = pac3.pid AND pa.jobid = pac3.jobid AND pa.groupid = pac3.groupid - AND pa.id = pac3.id AND pa.type = pac3.type AND pace3.id = pac3.component_id) - LEFT JOIN profile_addresses_components AS pac4 ON (pa.pid = pac4.pid AND pa.jobid = pac4.jobid AND pa.groupid = pac4.groupid - AND pa.id = pac4.id AND pa.type = pac4.type AND pace4.id = pac4.component_id) - - ' . ((count($where) > 0) ? 'WHERE ' . implode(' AND ', $where) : '') . ' + 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()