From 0520590230b625ca6959165692dd68accc9e45be Mon Sep 17 00:00:00 2001 From: lenovo Date: Thu, 10 Nov 2022 14:27:52 +0100 Subject: [PATCH] filters are sorted --- srcs/plugins/map_prof/mp_get_events.php | 4 ++- srcs/plugins/map_prof/mp_get_filters.php | 40 +++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/srcs/plugins/map_prof/mp_get_events.php b/srcs/plugins/map_prof/mp_get_events.php index 4e345d5..f55b790 100644 --- a/srcs/plugins/map_prof/mp_get_events.php +++ b/srcs/plugins/map_prof/mp_get_events.php @@ -151,6 +151,8 @@ function mp_fill_fields_value($id) { $event = (object)[]; foreach($fields as $field) { $value = get_field($field, $id); + if (gettype($value) == "string") + $value = trim($value, " "); $event->$field = $value; } @@ -169,7 +171,7 @@ function mp_get_published_events() { foreach ($posts_list as $post) { $event = mp_fill_fields_value($post->ID); $event->id = $post->ID; - $event->title = $post->post_title; + $event->title = trim($post->post_title, " "); array_push($events, $event); } mp_console_log("events:"); diff --git a/srcs/plugins/map_prof/mp_get_filters.php b/srcs/plugins/map_prof/mp_get_filters.php index 92a81f7..1bb1672 100644 --- a/srcs/plugins/map_prof/mp_get_filters.php +++ b/srcs/plugins/map_prof/mp_get_filters.php @@ -1,15 +1,15 @@ _name, $b->_name); } function mp_already_in_menu(&$menu, $name) { foreach ($menu as $field) { if ($field->_name == $name) - return true; + return $field; } - return false; + return null; } /* @@ -29,8 +29,10 @@ function mp_fill_name($fields, $name, &$menu) { 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); + if (strlen($value) != 0) { + if (! in_array($value, $menu_field->$key_field) ) + array_push($menu_field->$key_field, $value); + } } } else { @@ -40,7 +42,8 @@ function mp_fill_name($fields, $name, &$menu) { if ($key_field == $name) continue; $filter->$key_field = []; - array_push($filter->$key_field, $value); + if (strlen($value) != 0) + array_push($filter->$key_field, $value); } array_push($menu, $filter); } @@ -62,12 +65,35 @@ function mp_get_filters($events) { mp_fill_name($fields, $key, $filters->$key); } } - //usort(, mp_filter_compare); + + foreach ($filters as $filter) { + usort($filters->$filter, mp_filter_compare); + } mp_console_log("filters:"); mp_console_log($filters); } +/* + { [ ] } + { [ { - _name : "" } ] } + { - countries : [ { - cities : [] }, ... ] } + { [ { - categories: [] } ] } + { [ ] } + { } + { [ ] } + { [ { - _name : "" } ] } +filters: { - cities : [ { - countries : [] }, ... ] } + { [ { - categories: [] } ] } + { [ ] } + { } + { [ ] } + { [ { - _name : "" } ] } + { - categories: [ { - countries : [] }, ... ] } + { [ { - cities : [] } ] } + { [ ] } +*/ + /* $country = (object)[]; $country->_name = "";