error page is more precise with approximates address
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
|
||||
# MAP
|
||||
|
||||
questions:
|
||||
- liens vers les pages
|
||||
#### improvement suggestions:
|
||||
- add a field "more infos" to address
|
||||
- localise on map when form is filled
|
||||
|
||||
questions traitees:
|
||||
#### questions traitees:
|
||||
- bound la carte limite pour ne pas voir la zone grise
|
||||
- quelles infos on mets dans les infowindow
|
||||
- adresse en haut (surtout pour les markers avec plusieurs evenements)
|
||||
@@ -20,7 +21,7 @@ questions traitees:
|
||||
- quand c'est un cluster, on zoom,
|
||||
- quand c'est plusieurs evenements au meme endroit, on les affiche
|
||||
|
||||
todo:
|
||||
#### todo:
|
||||
- add info-window
|
||||
- add filter options
|
||||
- deal with bad address
|
||||
|
||||
@@ -25,6 +25,7 @@ require_once(dirname(__FILE__) . '/settings/mp_optionnals.php');
|
||||
require_once(dirname(__FILE__) . '/mp_get_events.php');
|
||||
require_once(dirname(__FILE__) . '/mp_sort_events.php');
|
||||
require_once(dirname(__FILE__) . '/mp_get_filters.php');
|
||||
require_once(dirname(__FILE__) . '/mp_address_errors.php');
|
||||
|
||||
|
||||
|
||||
@@ -120,6 +121,7 @@ function mp_ljdp_map() {
|
||||
|
||||
$events = mp_get_published_events();
|
||||
$locations = mp_sort_events($events);
|
||||
|
||||
$to_add = array(
|
||||
"locations" => $locations,
|
||||
);
|
||||
@@ -130,8 +132,7 @@ function mp_ljdp_map() {
|
||||
"ville",
|
||||
"categorie",
|
||||
);
|
||||
|
||||
$filters = mp_get_filters($events, $filters_fields);
|
||||
$filters = mp_get_filters($locations, $filters_fields);
|
||||
|
||||
|
||||
/* * * * * * * *
|
||||
@@ -180,31 +181,7 @@ add_shortcode('lejourduprof_map', 'mp_ljdp_map');
|
||||
*/
|
||||
|
||||
function mp_errors_map() {
|
||||
|
||||
$errors = "";
|
||||
$count = 0;
|
||||
|
||||
$get_posts_args = array(
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'post',
|
||||
);
|
||||
$posts = get_posts($get_posts_args);
|
||||
foreach ($posts as $post) {
|
||||
$id = $post->ID;
|
||||
$coordinate = get_field('coordinates', $id);
|
||||
if ($coordinate == null) {
|
||||
$count++;
|
||||
$errors .= '<br /><p>erreur :</p><p>- article : "';
|
||||
$errors .= $post->post_title . '"</p><p>- adresse : "';
|
||||
$errors .= get_field('adresse', $id) . ', ';
|
||||
$errors .= get_field('ville', $id) . ', ';
|
||||
$errors .= get_field('pays', $id) . '';
|
||||
$errors .= '"</p>';
|
||||
}
|
||||
}
|
||||
$errors = "<p>nombre d'erreurs : " . strval($count) . "</p>" . $errors;
|
||||
return $errors;
|
||||
return mp_find_address_errors();
|
||||
}
|
||||
add_shortcode('ljdp_errors_map', 'mp_errors_map');
|
||||
|
||||
@@ -219,10 +196,11 @@ add_shortcode('ljdp_errors_map', 'mp_errors_map');
|
||||
|
||||
function post_published_coordinates($id, $post) {
|
||||
|
||||
$coordinates = mp_get_coordinates($id);
|
||||
$location = mp_get_coordinates($id);
|
||||
|
||||
if ( ! add_post_meta( $id, 'location', $location, true ) )
|
||||
update_post_meta( $id, 'location', $location );
|
||||
|
||||
if ( ! add_post_meta( $id, 'coordinates', $coordinates, true ) )
|
||||
update_post_meta( $id, 'coordinates', $coordinates );
|
||||
}
|
||||
add_action( 'publish_post', 'post_published_coordinates', 10, 2 );
|
||||
|
||||
|
||||
96
srcs/plugins/map_prof/mp_address_errors.php
Normal file
96
srcs/plugins/map_prof/mp_address_errors.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
function mp_is_precise($post, $id, $location) {
|
||||
|
||||
// is presentiel but not complete address ?
|
||||
$presentiel = get_field("mode", $id);
|
||||
if ($presentiel[0] === "En présentiel") {
|
||||
if ($location->approximate) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function mp_is_address_complete($post, $id, $location) {
|
||||
|
||||
// is presentiel but not complete address ?
|
||||
$presentiel = get_field("mode", $id);
|
||||
if ($presentiel[0] === "En présentiel") {
|
||||
if (strlen($location->street) == 0) {
|
||||
return false;
|
||||
}
|
||||
if (strlen($location->city) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function mp_is_valid_address($post, $id, $location) {
|
||||
|
||||
// is coordinates ?
|
||||
if ($location->coordinates == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function mp_fill_address_message($post, $id, $location) {
|
||||
|
||||
$message = '<br /><p>article : "'
|
||||
. $post->post_title . '"</p><p>- adresse fournie : "'
|
||||
. get_field('adresse', $id) . ', '
|
||||
. get_field('ville', $id) . ', '
|
||||
. get_field('pays', $id)
|
||||
. '"</p><p>- adresse trouvée : "'
|
||||
. $location->address
|
||||
. '"</p>';
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
function mp_find_address_errors() {
|
||||
|
||||
$errors = "";
|
||||
$incompletes = "";
|
||||
$approximates = "";
|
||||
$count_errors = 0;
|
||||
$count_incompletes = 0;
|
||||
$count_approximates = 0;
|
||||
|
||||
$get_posts_args = array(
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'post',
|
||||
);
|
||||
$posts = get_posts($get_posts_args);
|
||||
foreach ($posts as $post) {
|
||||
$id = $post->ID;
|
||||
$location = get_field('location', $id);
|
||||
if (! mp_is_valid_address($post, $id, $location)) {
|
||||
$count_errors++;
|
||||
$errors .= mp_fill_address_message($post, $id, $location);
|
||||
}
|
||||
// else if (! mp_is_address_complete($post, $id, $location)) {
|
||||
// $count_incompletes++;
|
||||
// $incompletes .= mp_fill_address_message($post, $id, $location);
|
||||
// }
|
||||
else if (! mp_is_precise($post, $id, $location)) {
|
||||
$count_approximates++;
|
||||
$approximates .= mp_fill_address_message($post, $id, $location);
|
||||
}
|
||||
}
|
||||
$message = "<h2>nombre d'erreurs : " . $count_errors . "</h2>";
|
||||
// $message .= "<h2>nombre d'adresses incompletes pour des evenements en presentiels : " . $count_incompletes . "</h2>";
|
||||
$message .= "<h2>nombre d'adresses approximatives pour des evenements en presentiels : " . $count_approximates . "</h2>";
|
||||
$message .= "<br /><h2>erreurs :</h2>" . $errors;
|
||||
// $message .= "<br /><h2>adresses incompletes:</h2>" . $incompletes;
|
||||
$message .= "<br /><h2>approximatives :</h2>" . $approximates;
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -3,7 +3,13 @@
|
||||
function mp_get_coordinates($id) {
|
||||
global $mp_api_key;
|
||||
$event = (object)[];
|
||||
$coordinates = null;
|
||||
$location = (object)[];
|
||||
$location->coordinates = null;
|
||||
$location->street = "";
|
||||
$location->city = "";
|
||||
$location->country = "";
|
||||
$location->address = "";
|
||||
$location->approximate = false;
|
||||
|
||||
// get address
|
||||
$address = "";
|
||||
@@ -14,9 +20,6 @@ function mp_get_coordinates($id) {
|
||||
);
|
||||
foreach($fields as $field) {
|
||||
$address_section = get_field($field, $id);
|
||||
// if ($field == "pays")
|
||||
// if ($address_section == null)
|
||||
// //return null;
|
||||
$address .= $address_section . ",";
|
||||
}
|
||||
|
||||
@@ -27,10 +30,30 @@ function mp_get_coordinates($id) {
|
||||
$jsoncontent = file_get_contents($geolocation);
|
||||
|
||||
// extract coordinates from json
|
||||
// https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types
|
||||
$content = json_decode($jsoncontent);
|
||||
$coordinates = $content->results[0]->geometry->location;
|
||||
$location->coordinates = $content->results[0]->geometry->location;
|
||||
$location->address = $content->results[0]->formatted_address;
|
||||
foreach ($content->results[0]->address_components as $component) {
|
||||
if (in_array("street_number", $component->types))
|
||||
$location->street = " " . $component->long_name;
|
||||
else if (in_array("route", $component->types))
|
||||
$location->street .= " " . $component->long_name;
|
||||
else if (in_array("locality", $component->types))
|
||||
$location->city .= " " . $component->long_name;
|
||||
else if (in_array("postal_town", $component->types))
|
||||
$location->city .= " " . $component->long_name;
|
||||
else if (in_array("country", $component->types))
|
||||
$location->country = $component->long_name;
|
||||
}
|
||||
if ($content->results[0]->geometry->location_type == "APPROXIMATE")
|
||||
$location->approximate = true;
|
||||
foreach ($location as $value) {
|
||||
$value = trim($value, " ");
|
||||
mp_console_log($value);
|
||||
}
|
||||
|
||||
return $coordinates;
|
||||
return $location;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -99,20 +99,20 @@ function mp_get_published_posts() {
|
||||
// FOR TESTS
|
||||
// script to publish or unpublish posts
|
||||
//
|
||||
// $post_args = array(
|
||||
// 'numberposts' => -1,
|
||||
// 'post_status' => 'draft',
|
||||
// //'post_status' => 'publish',
|
||||
// 'post_type' => 'post',
|
||||
// );
|
||||
// $post_list = get_posts($post_args);
|
||||
// foreach ($post_list as $post) {
|
||||
// wp_update_post(array(
|
||||
// 'ID' => $post->ID,
|
||||
// //'post_status' => 'draft',
|
||||
// 'post_status' => 'publish',
|
||||
// ));
|
||||
// };
|
||||
$post_args = array(
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'draft',
|
||||
//'post_status' => 'publish',
|
||||
'post_type' => 'post',
|
||||
);
|
||||
$post_list = get_posts($post_args);
|
||||
foreach ($post_list as $post) {
|
||||
wp_update_post(array(
|
||||
'ID' => $post->ID,
|
||||
//'post_status' => 'draft',
|
||||
'post_status' => 'publish',
|
||||
));
|
||||
};
|
||||
|
||||
$get_posts_args = array(
|
||||
'numberposts' => -1,
|
||||
@@ -146,8 +146,7 @@ function mp_fill_fields_value($id) {
|
||||
"adresse",
|
||||
"prenom",
|
||||
"nom",
|
||||
"coordinates",
|
||||
"coordinates_valid",
|
||||
"location",
|
||||
);
|
||||
$event = (object)[];
|
||||
foreach($fields as $field) {
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
<?php
|
||||
|
||||
function mp_get_filters($events, $filters_fields) {
|
||||
function mp_add_filters(&$filter, $value) {
|
||||
if ($value == null)
|
||||
return;
|
||||
if (gettype($value) != 'string')
|
||||
return;
|
||||
if (strlen($value) == 0)
|
||||
return;
|
||||
$value = trim($value, " ");
|
||||
array_push($filter, $value);
|
||||
}
|
||||
|
||||
function mp_get_filters($locations, $filters_fields) {
|
||||
$filters = (object)[];
|
||||
foreach ($filters_fields as $field) {
|
||||
$filters->$field = [];
|
||||
foreach ($locations as $loc) {
|
||||
foreach ($loc->events as $event) {
|
||||
mp_add_filters($filters->$field, $event->$field);
|
||||
}
|
||||
}
|
||||
}
|
||||
mp_console_log("filters:");
|
||||
mp_console_log($filters);
|
||||
|
||||
@@ -10,7 +10,7 @@ function mp_coord_already_exist(&$coordinates, &$locations) {
|
||||
}
|
||||
|
||||
function mp_sort_n_insert(&$event, &$locations) {
|
||||
$coordinates = $event->coordinates;
|
||||
$coordinates = $event->location->coordinates;
|
||||
|
||||
$already_exist = mp_coord_already_exist($coordinates, $locations);
|
||||
if ($already_exist) {
|
||||
|
||||
Reference in New Issue
Block a user