diff --git a/README.md b/README.md
index 7b37954..f1c774d 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php
index b9017d0..e984563 100644
--- a/srcs/plugins/map_prof/map_prof_hooks.php
+++ b/srcs/plugins/map_prof/map_prof_hooks.php
@@ -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 .= '
erreur :
- article : "'; - $errors .= $post->post_title . '"
- adresse : "'; - $errors .= get_field('adresse', $id) . ', '; - $errors .= get_field('ville', $id) . ', '; - $errors .= get_field('pays', $id) . ''; - $errors .= '"
'; - } - } - $errors = "nombre d'erreurs : " . strval($count) . "
" . $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 ); diff --git a/srcs/plugins/map_prof/mp_address_errors.php b/srcs/plugins/map_prof/mp_address_errors.php new file mode 100644 index 0000000..93ef820 --- /dev/null +++ b/srcs/plugins/map_prof/mp_address_errors.php @@ -0,0 +1,96 @@ +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 = 'article : "' + . $post->post_title . '"
- adresse fournie : "' + . get_field('adresse', $id) . ', ' + . get_field('ville', $id) . ', ' + . get_field('pays', $id) + . '"
- adresse trouvée : "' + . $location->address + . '"
'; + + 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 = "