wip create filters but values are unique for sub cateegories

This commit is contained in:
lenovo
2022-11-10 11:47:40 +01:00
parent 4e7fa55234
commit 0f4eb2bd84
4 changed files with 114 additions and 31 deletions

View File

@@ -67,15 +67,16 @@ function mp_ljdp_map() {
*/
$events = mp_get_published_events();
$locations = mp_sort_events($events);
$filters = mp_get_filters($events);
$to_add = array(
"locations" => $locations,
"filters" => $filters,
);
mp_add_to_scripts($to_add);
$filters = mp_get_filters($locations);
/* * * * * * * *
* ADD FILTERS

View File

@@ -32,25 +32,25 @@ function mp_get_coordinates($id) {
// extract coordinates from json
// https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types
$content = json_decode($jsoncontent);
$location->coordinates = $content->results[0]->geometry->location;
$location->address = $content->results[0]->formatted_address;
$location->coordinates = trim($content->results[0]->geometry->location, " ");
$location->address = trim($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;
$location->street = trim($component->long_name, " ");
else if (in_array("route", $component->types)) {
if (strlen($location->street) != 0)
$location->street .= " ";
$location->street .= $component->long_name;
$location->street .= trim($component->long_name, " ");
}
else if (in_array("locality", $component->types))
$location->city .= $component->long_name;
$location->city = trim($component->long_name, " ");
else if (in_array("postal_town", $component->types)) {
if (strlen($location->city) != 0)
$location->city .= "/";
$location->city .= $component->long_name;
$location->city .= trim($component->long_name, " ");
}
else if (in_array("country", $component->types))
$location->country = $component->long_name;
$location->country = trim($component->long_name, " ");
}
if ($content->results[0]->geometry->location_type == "APPROXIMATE")
$location->approximate = true;

View File

@@ -172,7 +172,8 @@ function mp_get_published_events() {
$event->title = $post->post_title;
array_push($events, $event);
}
mp_console_log("nombre de posts: " . count($events));
mp_console_log("events:");
mp_console_log($events);
return $events;
}

View File

@@ -1,32 +1,113 @@
<?php
function mp_add_filters(&$filter, $value) {
if ($value == null)
return;
if (gettype($value) != 'string')
return;
if (strlen($value) == 0)
return;
$value = trim($value, " ");
//mp_filter_insert_sort($filter, $value);
array_push($filter, $value);
$filter = array_unique($filter);
sort($filter);
function mp_filter_compare($a, $b) {
return strcmp($a, $b);
}
function mp_get_filters($locations) {
$filters = (object)[];
$filters->country = [];
$filters->city = [];
$filters->category = [];
foreach ($locations as $loc) {
$country = $loc->events[0]->location->country;
mp_add_filters($filters->country, $country);
function mp_already_in_menu(&$menu, $name) {
foreach ($menu as $field) {
if ($field->_name == $name)
return true;
}
return false;
}
/*
menu: [ { _name:"", field_1:[], field_2:[] }, ... ]
fields: [ countries:"", cities:"", categories:"", ... ]
*/
function mp_fill_name($fields, $name, &$menu) {
if ($fields[$name] == null)
return;
if (gettype($fields[$name]) != 'string')
return;
if (strlen($fields[$name]) == 0)
return;
$menu_field = mp_already_in_menu($menu, $fields[$name]);
if ($menu_field != null) {
foreach ($fields as $key_field => $value) {
if ($key_field == $name)
continue;
if (! in_array($value, $menu_field->$key_field) )
array_push($menu_field->$key_field, $value);
}
}
else {
$filter = (object)[];
$filter->_name = $fields[$name];
foreach ($fields as $key_field => $value) {
if ($key_field == $name)
continue;
$filter->$key_field = [];
array_push($filter->$key_field, $value);
}
array_push($menu, $filter);
}
}
function mp_get_filters($events) {
$filters = (object)[];
$filters->countries = [];
$filters->cities = [];
$filters->categories = [];
foreach ($events as $event) {
$fields = array(
"countries" => $event->location->country,
"cities" => $event->location->city,
"categories" => $event->categorie,
);
foreach ($fields as $key => $value) {
mp_fill_name($fields, $key, $filters->$key);
}
}
//usort(, mp_filter_compare);
mp_console_log("filters:");
mp_console_log($filters);
}
/*
$country = (object)[];
$country->_name = "";
$country->cities = [];
$country->categories = [];
$city = (object)[];
$city->_name = "";
$city->countries = [];
$city->categories = [];
$category = (object)[];
$category->_name = "";
$category->countries = [];
$category->cities = [];
*/
/*
event : {}
- heure_de_debut : "";
- heure_de_fin : "";
- categorie : "";
- date : "";
- pays : "";
- ville : "";
- adresse : "";
- prenom : "";
- nom : "";
- irl : bool;
- id : x;
- title : "";
- location : {}
- street : "";
- city : "";
- country : "";
- address : "";
- approximate : bool;
- coordinates : {}
- lat : x;
- lng : x;
*/
?>