diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php index 187c657..09e5b42 100644 --- a/srcs/plugins/map_prof/map_prof_hooks.php +++ b/srcs/plugins/map_prof/map_prof_hooks.php @@ -81,14 +81,9 @@ function mp_ljdp_map() { //mp_console_log("php locations:"); //mp_console_log($locations); - mp_console_log("php events:"); - mp_console_log($events); - mp_console_log("php locations:"); - mp_console_log($locations); - $filters = mp_get_filters($events); - //mp_console_log("php filters:"); - //mp_console_log($filters); + mp_console_log("php filters:"); + mp_console_log($filters); $to_add = array( "locations" => $locations, diff --git a/srcs/plugins/map_prof/mp_get_events.php b/srcs/plugins/map_prof/mp_get_events.php index 1bb0f7b..e9ab16a 100644 --- a/srcs/plugins/map_prof/mp_get_events.php +++ b/srcs/plugins/map_prof/mp_get_events.php @@ -190,6 +190,7 @@ function mp_get_published_events() { - nom : ""; - irl : bool; - id : x; + (- index : x;) // not there for now - title : ""; - location : {} - street : ""; diff --git a/srcs/plugins/map_prof/mp_get_filters.php b/srcs/plugins/map_prof/mp_get_filters.php index 8507e66..d94af02 100644 --- a/srcs/plugins/map_prof/mp_get_filters.php +++ b/srcs/plugins/map_prof/mp_get_filters.php @@ -17,37 +17,48 @@ function mp_already_in_menu(&$menu, $name) { fields: [ countries:"", cities:"", categories:"", ... ] */ -function mp_fill_name($fields, $name, &$menu) { +function mp_fill_name($fields, $name, &$menu, $index) { 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) { + $menu_item = mp_already_in_menu($menu, $fields[$name]); + if ($menu_item != null) { + // no need to add name if already exist + // add to lists of event info (cities, countries, ...) foreach ($fields as $key_field => $value) { if ($key_field == $name) continue; - if (! isset($menu_field->$key_field) ) - $menu_field->$key_field = []; + if (! isset($menu_item->$key_field) ) + $menu_item->$key_field = []; if (strlen($value) != 0) { - if (! in_array($value, $menu_field->$key_field) ) - array_push($menu_field->$key_field, $value); + if (! in_array($value, $menu_item->$key_field) ) + array_push($menu_item->$key_field, $value); } } + // add to list of location index + if (! in_array($index, $menu_item->indexes) ) + array_push($menu_item->indexes, $index); } else { - $filter = (object)[]; - $filter->_name = $fields[$name]; + $menu_item = (object)[]; + $menu_item->_name = $fields[$name]; + // add lists of event info (cities, countries, ...) foreach ($fields as $key_field => $value) { if ($key_field == $name) continue; - $filter->$key_field = []; + $menu_item->$key_field = []; if (strlen($value) != 0) - array_push($filter->$key_field, $value); + array_push($menu_item->$key_field, $value); } - array_push($menu, $filter); + // add list of location index + $menu_item->indexes = []; + array_push($menu_item->indexes, $index); + + // and add this item to list of menu + array_push($menu, $menu_item); } } @@ -61,10 +72,11 @@ function mp_get_filters(&$events) { "categories" => $event->categorie, "mode" => ($event->irl)? "En présentiel" : "En ligne", ); + $index = $event->index; foreach ($fields as $key => $value) { if (! isset($filters->$key)) $filters->$key = []; - mp_fill_name($fields, $key, $filters->$key); + mp_fill_name($fields, $key, $filters->$key, $index); } } @@ -78,23 +90,15 @@ function mp_get_filters(&$events) { /* { } { [ ] } - { [ { - _name : "" } ] } - { - countries : [ { - cities : [] }, ... ] } - { [ { - categories: [] } ] } - { [ ] } - { } - { [ ] } - { [ { - _name : "" } ] } -filters: { - cities : [ { - countries : [] }, ... ] } - { [ { - categories: [] } ] } - { [ ] } - { } - { [ ] } - { [ { - _name : "" } ] } - { - categories: [ { - countries : [] }, ... ] } +filters: { - countries : [ { - _name : "" } ] } { [ { - cities : [] } ] } + { [ { - categories: [] } ] } + { [ { - indexes : [] }, ... ] } { [ ] } { } + { - cities : } + { - categories: } + { } */ /* @@ -110,6 +114,7 @@ filters: { - cities : [ { - countries : [] }, ... ] } - nom : ""; - irl : bool; - id : x; + - index : x; - title : ""; - location : {} - street : "";