Files
2023_WEBSITE_jipf/srcs/plugins/map_prof/mp_get_events.php
lenovo 7b37d30f7b cluster markers works
+ they are personalizable
+ cluster icon grow without getting fat
+ js function for errors
+ scripts dont enqueue on all pages
+ php array of event function more light without coordinates
- coordinates not yet retrieved by js
2022-11-04 21:27:39 +01:00

142 lines
2.9 KiB
PHP

<?php
/*
FORMS FIELDS
0: "engagement"
1: "fichier"
2: "liste_des_depenses"
3: "montant_demande"
4: "recettes_prevues"
5: "depenses_prevues"
6: "participation"
7: "plan_de_communication"
8: "composition_autres"
9: "composition_4"
10: "composition_3"
11: "composition_2"
12: "composition_1"
13: "composition"
14: "resultats_attendus"
15: "public_vise"
16: "activite_concerne"
17: "description_longue"
18: "description_courte"
--- 19: "categorie"
20: "se_connecter"
21: "lien_internet"
22: "adresse_courriel_de_contact"
--- 23: "heure_de_fin"
--- 24: "heure_de_debut"
--- 25: "date"
26: "map"
--- 27: "pays"
--- 28: "ville"
--- 29: "adresse"
30: "mode"
31: "fonction"
32: "institution"
33: "telephone"
34: "adresse_courriel"
--- 35: "prenom"
--- 36: "nom"
*/
// FUNCTION TO RETRIEVE FORMS FIELDS
// not used anymore
//
//function mp_get_form_fields() {
// $get_form_args = array(
// 'numberposts' => -1,
// 'post_status' => 'publish',
// 'post_type' => 'acf-field',
// );
// $forms = get_posts($get_form_args);
// $fields = [];
// foreach ($forms as $form) {
// $field = $form->post_excerpt;
// array_push($fields, $field);
// }
// return $fields;
//}
function mp_get_published_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',
// ));
// }
$get_posts_args = array(
'numberposts' => -1,
'post_status' => 'publish',
'post_type' => 'post',
);
$posts_published = get_posts($get_posts_args);
return $posts_published;
}
function mp_fill_fields_value($id) {
$fields = array(
"heure_de_debut",
"heure_de_fin",
"categorie",
"date",
"pays",
"ville",
"adresse",
"prenom",
"nom",
);
$event = (object)[];
foreach($fields as $field) {
$event->$field = get_field($field, $id);
}
$presentiel = get_field("mode", $id);
$event->irl = false;
if ($presentiel[0] === "En présentiel")
$event->irl = true;
return $event;
}
function mp_get_coordinates(&$marker) {
global $mp_api_key;
$address = $marker->adresse . ","
. $marker->ville . ","
. $marker->pays;
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
. '?address=' . urlencode($address)
. '&key=' . $mp_api_key;
$jsoncontent = file_get_contents($geolocation);
$content = json_decode($jsoncontent);
$coordinates = $content->results[0]->geometry->location;
return $coordinates;
}
function mp_get_published_events() {
$posts_list = mp_get_published_posts();
$events = [];
foreach ($posts_list as $post) {
$event = mp_fill_fields_value($post->ID);
$event->id = $post->ID;
$event->title = $post->post_title;
// $event->coordinates = mp_get_coordinates($event);
array_push($events, $event);
}
mp_console_log($events);
return $events;
}
?>