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';
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)
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;
}
'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
);
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) {
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)
$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)
-
+ 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)
' . ((count($where) > 0) ? 'WHERE ' . implode(' AND ', $where) : '') . '
GROUP BY pa.pid, pa.jobid, pa.groupid, pa.type, pa.id
ORDER BY pa.pid, pa.jobid, pa.id';