dynamic counter ok

This commit is contained in:
asus
2023-11-11 13:01:43 +01:00
parent 6e460f5347
commit 99aeaa82b0
7 changed files with 179 additions and 70 deletions

View File

@@ -57,12 +57,12 @@ function mp_ljdp_map() {
mp_enqueue_scripts_and_styles();
$events = mp_get_published_events(); // mp_get_events.php
//mp_console_log("events :");
//mp_console_log($events);
//mp_console_log("events: " . $events);
//foreach ($events as $event)
// mp_console_log($event);
$locations = mp_sort_events($events); // mp_get_locations.php
//mp_console_log("locations: " . $locations);
$filters = mp_get_filters($events); // mp_get_filters.php
@@ -72,12 +72,27 @@ function mp_ljdp_map() {
mp_add_to_scripts(array(
"locations" => $locations,
"filters" => $filters,
"jipf_events" => $events,
));
return mp_create_div($filters);
}
add_shortcode('lejourduprof_map', 'mp_ljdp_map');
/*
script in divi :
<script type="text/javascript">
console.log("events:");
console.log(events);
document.addEventListener("DOMContentLoaded", () => {
let counter = document.getElementById('jipf_activity_counter_map');
console.log(counter);
counter.dataset.numberValue = 20;
});
</script>
*/

View File

@@ -11,42 +11,42 @@ const g_world_bound = {
east: 180,
};
/*
* following variable are created by mp_add_to_script.php
* - let events
* - let locations = [
* {
* coordinates: {}
* events : [{}, ...]
* },
* ...
* ]
*
* { }
* { [ ] }
* - let filters: { - pays : [ { - _name : "" } ] }
* { [ { - villes : [] } ] }
* { [ { - categories: [] } ] }
* { [ { - indexes : [] } ] }
* { [ { - mode : [] }, ...] }
* { [ ] }
* { }
* { - villes : ... }
* { - categories: ... }
* { - mode : ... }
* { }
*
* - let coordinates_default = {lat: ,lng: }
* - let icon_color = ""
* - let icon_color_back = ""
* - let icon_size = [x, y]
* - let cluster_size_factor = Number
* - let map_zoom = x
* - let max_zoom = x
*/
function mp_init_map() {
/*
* following variable are created by mp_add_to_script.php
* - let locations = [
* {
* coordinates: {}
* events : [{}, ...]
* },
* ...
* ]
*
* { }
* { [ ] }
* - filters: { - pays : [ { - _name : "" } ] }
* { [ { - villes : [] } ] }
* { [ { - categories: [] } ] }
* { [ { - indexes : [] } ] }
* { [ { - mode : [] }, ...] }
* { [ ] }
* { }
* { - villes : ... }
* { - categories: ... }
* { - mode : ... }
* { }
*
* - let coordinates_default = {lat: ,lng: }
* - let icon_color = ""
* - let icon_color_back = ""
* - let icon_size = [x, y]
* - let cluster_size_factor = Number
* - let map_zoom = x
* - let max_zoom = x
*/
let map_div = document.getElementById("ljdp_map");
//let filters_div = document.getElementById("ljdp_map_filters");
g_infowindow = new google.maps.InfoWindow();

View File

@@ -5,9 +5,11 @@
*/
/* cle api google maps pour "Maps Javascript API" */
$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE';
//$mp_api_key = 'AIzaSyA19YahRe_mcbtc-IiLCr0U6tMwzYiQjLA'; // hugo
$mp_api_key = 'AIzaSyDAZv8QNRQjnVY6kdzJRxWmZDaNIcgYp9E';
/* cle api google maps pour "Geocoding API" */
$mp_api_key_geo = 'AIzaSyAEMZHpMxBQaovU_so_RH7p_pZbjaB2jO8';
//$mp_api_key_geo = 'AIzaSyA19YahRe_mcbtc-IiLCr0U6tMwzYiQjLA'; // hugo
$mp_api_key_geo = 'AIzaSyBskxuBhowQdLjJmIj2gc66KoP1GLO3SEg';
?>

View File

@@ -35,7 +35,7 @@ function mp_already_in_menu(&$menu, $name) {
* menu : [ { _name:"", field_1:[], field_2:[] }, ... ]
* index : index of this event in locations[] array
*/
function mp_fill_name($fields, $name, &$menu, $index) {
function mp_fill_name($fields, $name, &$menu, $index, &$event) {
if ($fields[$name] == null)
return;
if (gettype($fields[$name]) != 'string')
@@ -53,8 +53,12 @@ function mp_fill_name($fields, $name, &$menu, $index) {
continue;
if (! isset($menu_item->$key_field) )
$menu_item->$key_field = [];
if (!is_string($value))
if (!is_string($value)) {
//mp_console_log("pour l'article '$event->title', le champ '$key_field' est supposé être de type 'string', mais il est de type '" . gettype($value) . "'");
//if ( ! add_post_meta( $id, 'problem', "$value", true ) )
// update_post_meta( $id, 'problem', "" );
continue;
}
if (strlen($value) != 0) {
if (! in_array($value, $menu_item->$key_field) )
array_push($menu_item->$key_field, $value);
@@ -73,8 +77,10 @@ function mp_fill_name($fields, $name, &$menu, $index) {
if ($key_field == $name)
continue;
$menu_item->$key_field = [];
if (!is_string($value))
if (!is_string($value)) {
//mp_console_log("pour l'article '$event->title', le champ '$key_field' est supposé être de type 'string', mais il est de type '" . gettype($value) . "'");
continue;
}
if (strlen($value) != 0)
array_push($menu_item->$key_field, $value);
}
@@ -102,12 +108,14 @@ function mp_get_filters(&$events) {
"Catégories" => $event->categorie,
"mode" => ($event->irl)? "En présentiel" : "En ligne",
);
//mp_console_log("event: ");
//mp_console_log($event);
// fill all menu with other menus without doubles
foreach ($fields as $name => $value) {
if (! isset($filters->$name))
$filters->$name = [];
mp_fill_name($fields, $name, $filters->$name, $index);
mp_fill_name($fields, $name, $filters->$name, $index, $event);
}
}
@@ -132,29 +140,30 @@ filters: { - countries : [ { - _name : "" } ] }
*/
/*
event : {}
event : {}
- heure_de_debut : "";
- heure_de_fin : "";
- categorie : "";
- date : "";
- pays : "";
- ville : "";
- adresse : "";
- prenom : "";
- nom : "";
- irl : bool;
- id : x;
- index : x;
- title : "";
- location : {}
- street : "";
- city : "";
- country : "";
- address : "";
- approximate : bool;
- coordinates : {}
- lat : x;
- lng : x;
- categorie : "";
- date : "";
- pays : "";
- ville : "";
- adresse : "";
- prenom : "";
- nom : "";
- irl : bool;
- id : x;
- index : x;
- url : "";
- title : "";
- location : {}
- street : "";
- city : "";
- country : "";
- address : "";
- approximate : bool;
- coordinates : {}
- lat : x;
- lng : x;
*/
?>

View File

@@ -55,6 +55,23 @@ function mp_have_no_coordinates($posts_list) {
function mp_bad_categories($posts_list) {
$posts_bad_categories = [];
foreach ($posts_list as $post) {
$value = get_field("categorie", $post->ID);
if (! is_string($value)) {
array_push($posts_bad_categories, $post);
//mp_console_log("categorie:");
//mp_console_log($value);
}
}
return $posts_bad_categories;
}
function mp_show_list_posts_no_address($posts) {
echo <<<HTML
@@ -100,6 +117,60 @@ function mp_show_list_posts_no_address($posts) {
function mp_show_list_posts_bad_categories($posts) {
echo <<<HTML
<div style="border: 1px solid red; margin: 20px 20px 20px auto; padding: 0px 20px;">
<p style="color: red;">
<b>ATTENTION !</b>
</p>
<p>
<b>
HTML;
echo count($posts);
echo '</b>';
if (count($posts) == 1)
echo " article à sa catégorie mal formatée :";
else
echo " articles ont leur catégorie mal formatée :";
echo <<<HTML
</p>
<ul style="list-style: square inside;">
HTML;
foreach ($posts as $post) {
echo <<<HTML
<li><b>
HTML;
echo 'id: ';
echo $post->ID;
echo ' (status: ';
echo $post->post_status;
echo ') - ';
if (!empty($post->mode))
echo $post->mode[0];
echo ' : </b>';
echo $post->post_title;
echo <<<HTML
<p style="margin:0px;">
<span style="color:blue;">catégorie: </span>
HTML;
$categorie = get_field("categorie", $post->ID);
echo '<span>';
var_dump($categorie);
echo '</span>';
echo <<<HTML
</p>
</li>
HTML;
}
echo <<<HTML
</ul>
</div>
HTML;
}
function mp_show_list_posts_no_coordinates($posts) {
echo <<<HTML
@@ -229,7 +300,18 @@ function ljdp_map_plugin_content() {
//mp_console_log("posts_no_coordinates: ");
//mp_console_log($posts_no_coordinates);
$posts_bad_categories = mp_bad_categories($posts_list);
//mp_console_log("posts_bad_categories: ");
//mp_console_log($posts_bad_categories);
echo <<<HTML
<style>
li {
list-style-position: outside;
margin-left: 10px;
}
</style>
<div>
<h2>JIPF map plugin</h2>
HTML;
@@ -241,6 +323,9 @@ function ljdp_map_plugin_content() {
if (count($posts_no_address) > 0)
mp_show_list_posts_no_address($posts_no_address);
if (count($posts_bad_categories) > 0)
mp_show_list_posts_bad_categories($posts_bad_categories);
if (count($posts_no_coordinates) > 0){
mp_show_list_posts_no_coordinates($posts_no_coordinates);
}

View File

@@ -34,11 +34,9 @@ function mp_get_coordinates($id) {
. '?language=fr'
. '&address=' . urlencode($address)
. '&key=' . $mp_api_key_geo;
//mp_console_log("geolocation:");
//mp_console_log($geolocation);
//mp_console_log("geolocation: " . $geolocation);
$jsoncontent = file_get_contents($geolocation);
mp_console_log("jsoncontent:");
mp_console_log($jsoncontent);
//mp_console_log("jsoncontent: " . $jsoncontent);
// extract coordinates from json
// https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types

View File

@@ -57,12 +57,12 @@ function mp_ljdp_map() {
mp_enqueue_scripts_and_styles();
$events = mp_get_published_events(); // mp_get_events.php
mp_console_log("events: " . $events);
//mp_console_log("events: " . $events);
//foreach ($events as $event)
// mp_console_log($event);
$locations = mp_sort_events($events); // mp_get_locations.php
mp_console_log("locations: " . $locations);
//mp_console_log("locations: " . $locations);
$filters = mp_get_filters($events); // mp_get_filters.php
@@ -72,7 +72,7 @@ function mp_ljdp_map() {
mp_add_to_scripts(array(
"locations" => $locations,
"filters" => $filters,
"events" => $events,
"jipf_events" => $events,
));
return mp_create_div($filters);