wip create filters but values are unique for sub cateegories
This commit is contained in:
@@ -67,15 +67,16 @@ function mp_ljdp_map() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$events = mp_get_published_events();
|
$events = mp_get_published_events();
|
||||||
|
|
||||||
$locations = mp_sort_events($events);
|
$locations = mp_sort_events($events);
|
||||||
|
$filters = mp_get_filters($events);
|
||||||
|
|
||||||
$to_add = array(
|
$to_add = array(
|
||||||
"locations" => $locations,
|
"locations" => $locations,
|
||||||
|
"filters" => $filters,
|
||||||
);
|
);
|
||||||
mp_add_to_scripts($to_add);
|
mp_add_to_scripts($to_add);
|
||||||
|
|
||||||
$filters = mp_get_filters($locations);
|
|
||||||
|
|
||||||
|
|
||||||
/* * * * * * * *
|
/* * * * * * * *
|
||||||
* ADD FILTERS
|
* ADD FILTERS
|
||||||
|
|||||||
@@ -32,25 +32,25 @@ function mp_get_coordinates($id) {
|
|||||||
// extract coordinates from json
|
// extract coordinates from json
|
||||||
// https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types
|
// https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types
|
||||||
$content = json_decode($jsoncontent);
|
$content = json_decode($jsoncontent);
|
||||||
$location->coordinates = $content->results[0]->geometry->location;
|
$location->coordinates = trim($content->results[0]->geometry->location, " ");
|
||||||
$location->address = $content->results[0]->formatted_address;
|
$location->address = trim($content->results[0]->formatted_address, " ");
|
||||||
foreach ($content->results[0]->address_components as $component) {
|
foreach ($content->results[0]->address_components as $component) {
|
||||||
if (in_array("street_number", $component->types))
|
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)) {
|
else if (in_array("route", $component->types)) {
|
||||||
if (strlen($location->street) != 0)
|
if (strlen($location->street) != 0)
|
||||||
$location->street .= " ";
|
$location->street .= " ";
|
||||||
$location->street .= $component->long_name;
|
$location->street .= trim($component->long_name, " ");
|
||||||
}
|
}
|
||||||
else if (in_array("locality", $component->types))
|
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)) {
|
else if (in_array("postal_town", $component->types)) {
|
||||||
if (strlen($location->city) != 0)
|
if (strlen($location->city) != 0)
|
||||||
$location->city .= "/";
|
$location->city .= "/";
|
||||||
$location->city .= $component->long_name;
|
$location->city .= trim($component->long_name, " ");
|
||||||
}
|
}
|
||||||
else if (in_array("country", $component->types))
|
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")
|
if ($content->results[0]->geometry->location_type == "APPROXIMATE")
|
||||||
$location->approximate = true;
|
$location->approximate = true;
|
||||||
|
|||||||
@@ -172,7 +172,8 @@ function mp_get_published_events() {
|
|||||||
$event->title = $post->post_title;
|
$event->title = $post->post_title;
|
||||||
array_push($events, $event);
|
array_push($events, $event);
|
||||||
}
|
}
|
||||||
mp_console_log("nombre de posts: " . count($events));
|
mp_console_log("events:");
|
||||||
|
mp_console_log($events);
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,113 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function mp_add_filters(&$filter, $value) {
|
function mp_filter_compare($a, $b) {
|
||||||
if ($value == null)
|
return strcmp($a, $b);
|
||||||
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_get_filters($locations) {
|
function mp_already_in_menu(&$menu, $name) {
|
||||||
$filters = (object)[];
|
foreach ($menu as $field) {
|
||||||
$filters->country = [];
|
if ($field->_name == $name)
|
||||||
$filters->city = [];
|
return true;
|
||||||
$filters->category = [];
|
|
||||||
|
|
||||||
foreach ($locations as $loc) {
|
|
||||||
$country = $loc->events[0]->location->country;
|
|
||||||
mp_add_filters($filters->country, $country);
|
|
||||||
}
|
}
|
||||||
|
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:");
|
||||||
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;
|
||||||
|
*/
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user