resolve some errors in php logic, like strlen with str containing space that is interpreted as array instead of string
This commit is contained in:
34
plug/map_prof/srcs/map/mp_add_to_scripts.php
Normal file
34
plug/map_prof/srcs/map/mp_add_to_scripts.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
function mp_php_to_js($php_var, $js_var_name) {
|
||||
$js_var = 'let ' . $js_var_name . ' = ';
|
||||
$js_var .= json_encode($php_var);
|
||||
$js_var .= ';';
|
||||
return $js_var;
|
||||
}
|
||||
|
||||
function mp_add_to_scripts($to_add) {
|
||||
global $mp_icon_size;
|
||||
global $mp_icon_color;
|
||||
global $mp_icon_color_back;
|
||||
global $mp_icon_size_factor;
|
||||
global $mp_zoom;
|
||||
global $mp_coordinates_default;
|
||||
global $mp_icon_stroke_width;
|
||||
global $mp_max_zoom;
|
||||
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size, 'icon_size'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color, 'icon_color'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color_back, 'icon_color_back'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size_factor, 'icon_size_factor'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_zoom, 'map_zoom'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_coordinates_default, 'coordinates_default'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_stroke_width, 'icon_stroke_width'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_max_zoom, 'max_zoom'), 'before');
|
||||
|
||||
foreach ($to_add as $key => $var) {
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($var, $key), 'before');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
135
plug/map_prof/srcs/map/mp_create_div.php
Normal file
135
plug/map_prof/srcs/map/mp_create_div.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
function mp_filter_drop_down($key, &$filter) {
|
||||
/*
|
||||
onfocusin="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
|
||||
onclick="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
|
||||
onfocus="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
|
||||
onclick="filter_show_only_selection(this, '.json_encode(array()).', '."'".$key."'".')"
|
||||
onchange="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
|
||||
|
||||
onchange="filter_show_only_selection(this, '.json_encode(array()).', '."'".$key."'".')"
|
||||
onchange="filter_event(this, this.options[this.selectedIndex], \''.$key.'\')"
|
||||
*/
|
||||
$menu_name_class = 'filter_menu_'.str_replace(" ", "_", $key).'';
|
||||
$id = "filter_"
|
||||
. $key
|
||||
. "_"
|
||||
. $key
|
||||
;
|
||||
$content = '
|
||||
<select
|
||||
form="ljdp_form"
|
||||
class="filter_menu filter_menu_drop"
|
||||
onchange="filter_show_only(this.options[this.selectedIndex], \''.$key.'\')"
|
||||
>
|
||||
<option
|
||||
selected
|
||||
id="'.$id.'"
|
||||
class="filter_menu_item '.$menu_name_class.'"
|
||||
data-menu_index="menu_name"
|
||||
>
|
||||
'.$key.'
|
||||
</option>
|
||||
';
|
||||
foreach ($filter as $key_filter => $value) {
|
||||
$id = "filter_"
|
||||
. $key
|
||||
. "_"
|
||||
. str_replace( " ", "_", $value->_name)
|
||||
;
|
||||
$content .= '
|
||||
<option
|
||||
id="'.$id.'"
|
||||
class="filter_menu_item '.$menu_name_class.'"
|
||||
data-menu_index="'.$key_filter.'"
|
||||
>
|
||||
'.$value->_name.'
|
||||
</option>
|
||||
';
|
||||
}
|
||||
$content .= '
|
||||
</select>
|
||||
';
|
||||
|
||||
return $content;
|
||||
};
|
||||
|
||||
function mp_filter_buttons($key, &$filter) {
|
||||
|
||||
/*
|
||||
onclick="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".', true)"
|
||||
*/
|
||||
$menu_name_class = 'filter_menu_'.str_replace(" ", "_", $key).'';
|
||||
$content = '';
|
||||
foreach ($filter as $key_filter => $value) {
|
||||
$id = "filter_"
|
||||
. $key
|
||||
. "_"
|
||||
. str_replace( " ", "_", $value->_name)
|
||||
;
|
||||
$content .= '
|
||||
<input
|
||||
type="checkbox"
|
||||
form="ljdp_form"
|
||||
id="'.$id.'"
|
||||
class="filter_menu_checkbox filter_menu_item '.$menu_name_class.'"
|
||||
onclick="filter_show_only(this, \''.$key.'\')"
|
||||
style="display:none;"
|
||||
data-menu_index="'.$key_filter.'",
|
||||
>
|
||||
<label
|
||||
for="'.$id.'"
|
||||
class="filter_menu filter_menu_checkbox"
|
||||
>
|
||||
<p>'.$value->_name.'</p>
|
||||
</label>
|
||||
';
|
||||
}
|
||||
|
||||
return $content;
|
||||
};
|
||||
|
||||
function mp_create_div(&$filters) {
|
||||
$mp_map_div = '
|
||||
<div id="ljdp_map_wrapper">
|
||||
<form id="ljdp_form" style="display:none;"></form>
|
||||
<div id="ljdp_map_filters">
|
||||
';
|
||||
|
||||
foreach ($filters as $key => $filter) {
|
||||
|
||||
if ($key == "mode")
|
||||
$mp_map_div .= mp_filter_buttons($key, $filter);
|
||||
else
|
||||
$mp_map_div .= mp_filter_drop_down($key, $filter);
|
||||
};
|
||||
|
||||
$mp_map_div .= '
|
||||
<input
|
||||
type="reset"
|
||||
form="ljdp_form"
|
||||
id="filter_menu_reset"
|
||||
class="filter_menu_button"
|
||||
onclick="filter_show_all()"
|
||||
style="display:none;"
|
||||
>
|
||||
<label
|
||||
for="filter_menu_reset"
|
||||
class="filter_menu filter_menu_reset"
|
||||
>
|
||||
<p>Effacer</p>
|
||||
</label>
|
||||
';
|
||||
|
||||
$mp_map_div .= '
|
||||
</div>
|
||||
<div id="ljdp_map"></div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $mp_map_div;
|
||||
};
|
||||
|
||||
|
||||
?>
|
||||
212
plug/map_prof/srcs/map/mp_get_events.php
Normal file
212
plug/map_prof/srcs/map/mp_get_events.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
GET_POST :
|
||||
|
||||
1 ID: 29693
|
||||
2 comment_count: "0"
|
||||
3 comment_status: "closed"
|
||||
4 filter: "raw"
|
||||
5 guid: "https://local_lejourduprof.com/?p=29693"
|
||||
6 menu_order: 0
|
||||
7 ping_status: "closed"
|
||||
8 pinged: ""
|
||||
9 post_author: "1"
|
||||
10 post_content: ""
|
||||
11 post_content_filtered: ""
|
||||
12 post_date: "2022-11-04 18:05:49"
|
||||
13 post_date_gmt: "2022-11-04 17:05:49"
|
||||
14 post_excerpt: "Les enseignants vont présenter les projets développés dans leurs classes et partager leurs pratiques et expériences."
|
||||
15 post_mime_type: ""
|
||||
16 post_modified: "2022-11-05 09:39:46"
|
||||
17 post_modified_gmt: "2022-11-05 08:39:46"
|
||||
18 post_name: "construisons-ensemble-lavenir"
|
||||
19 post_parent: 0
|
||||
20 post_password: ""
|
||||
21 post_status: "draft"
|
||||
22 post_title: "Construisons ensemble l'avenir"
|
||||
23 post_type: "post"
|
||||
24 to_ping: ""
|
||||
*/
|
||||
|
||||
/*
|
||||
GET_POST_CUSTOM :
|
||||
|
||||
1 _cf7_2_post_form_submitted : "yes"
|
||||
2 _edit_last : "3"
|
||||
3 _edit_lock : "1695215530:3"
|
||||
4 _encloseme : "1"
|
||||
5 _et_builder_dynamic_assets_loading_attr_threshold : "3"
|
||||
6 _pingme : "1"
|
||||
7 _thumbnail_id : "32583"
|
||||
8 _wp_old_date : "2023-09-06"
|
||||
|
||||
1 activite_concerne : "les enseignants de français langue étrangère ou français langue seconde"
|
||||
2 adresse : ""
|
||||
3 adresse_courriel : "ivan.centre@gmail.com"
|
||||
4 adresse_courriel_de_contact : "ivan.centre@gmail.com"
|
||||
5 categorie : "Conférence/Table ronde/Salon"
|
||||
6 composition : `a:4:{i:0;s:62:"Association de professeurs de français membre du réseau FIPF";i:1;s:38:"Ambassade de France/Institut français";i:2;s:27:"Université membre de l'AUF";i:3;s:23:"Organe de presse locale";}`
|
||||
7 composition_1 : "Association des professeurs de français de Serbie"
|
||||
8 composition_2 : "Institut français de Serbie"
|
||||
9 composition_3 : "Faculté de philosophie de l'Université de Nis"
|
||||
10 composition_4 : "Média et Reforme Centre"
|
||||
11 composition_autres : ""
|
||||
12 date : "2023-11-23"
|
||||
13 depenses_prevues : "4000"
|
||||
14 description_courte : `L'activité prévue: "Pensez vert, sauvez la Terre". Mettre FLE au service de l'écologie!`
|
||||
15 description_longue : `L'activité "Pensez vert, sauvez la Terre" est composée de deux segments: a) concours national destiné aux professeurs de FLE qui auront pour tâche de concevoir les fiches pédagogiques à partir de trois films écologiques courts métrages: https://vimeo.com/124807861; https://vimeo.com/120562699; https://vimeo.com/63528500; b) conférences nationales qui se feront en ligne et en présentiel. L'objectif est de faire prendre conscience de la problématique relative au changement climatique et à la biodiversité mais aussi d’encourager les enseignants d'intégrer le FLE au service de l'écologie! \r\n`
|
||||
16 fichier : "https://local_lejourduprof.com/wp-content/uploads/2023/09/Budget_previsionnel_JIPF_2023-1.docx"
|
||||
17 financement : 'a:1:{i:0;s:3:"oui";}'
|
||||
18 fonction : "Président"
|
||||
19 heure_de_debut : "10:00"
|
||||
20 heure_de_fin : "18:00"
|
||||
21 institution : "Association des professeurs de français de Serbie"
|
||||
22 lien_internet : "http://www.apfs.edu.rs"
|
||||
23 liste_des_depenses : ""
|
||||
24 mode : 'a:1:{i:0;s:8:"En ligne";}'
|
||||
25 montant_demande : "2000"
|
||||
26 nom : "JOVANOVIĆ"
|
||||
27 participation : "1000"
|
||||
28 pays : "Serbie"
|
||||
29 plan_de_communication : "Avant le projet: organisation d'une conférence de presse pour parler de l'activité; création des affiches de l'activité; annoncer le projet dans les médias et sur les réseaux sociaux ainsi que sur les sites des partenaires concernés.\r\n\r\nPendant le projet: communication sur les réseaux sociaux et sur les sites des partenaires concernés.\r\n\r\nAprès le projet: médias, réseaux sociaux et les sites des partenaires concernés."
|
||||
30 prenom : "Ivan"
|
||||
31 public_vise : "1000, enseignants de FLE, étudiants, lycéens bilingues"
|
||||
32 recettes_prevues : "0"
|
||||
33 resultat_attendu : "Les enseignants seront mobilisés face à la langue française et le mettront au service de l'écologie globale! Grâce à leur engagement et leur dévouement auprès des élèves ils seront motivés de les faire sensibiliser sur les causes et les effets de l’érosion de la biodiversité, de leur monter le rôle important de l'apprentissage du français dans la préservation de la Terre et de sa population. Aussi, Cette activité a pour l’ambition de construire la nécessité d’acquérir les compétences à leur activité future à une citoyenneté éco active. On développera chez eux des compétences de communication, d’expression orale, d’expression écrite, d’argumentation, de justification."
|
||||
34 resultats_attendus : "Les enseignants seront mobilisés face à la langue française et le mettront au service de l'écologie globale! Grâce à leur engagement et leur dévouement auprès des élèves ils seront motivés de les faire sensibiliser sur les causes et les effets de l’érosion de la biodiversité, de leur monter le rôle important de l'apprentissage du français dans la préservation de la Terre et de sa population. Aussi, Cette activité a pour l’ambition de construire la nécessité d’acquérir les compétences à leur activité future à une citoyenneté éco active. On développera chez eux des compétences de communication, d’expression orale, d’expression écrite, d’argumentation, de justification."
|
||||
35 se_connecter : "meet.google.com/mnu-czps-rrh "
|
||||
36 telephone : "+381649997389"
|
||||
*/
|
||||
|
||||
function mp_get_published_posts() {
|
||||
|
||||
$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) {
|
||||
|
||||
/*
|
||||
* get_field is an ACF function
|
||||
* in "pure" worpdress use :
|
||||
* get_post_meta or get_post_custom
|
||||
* - https://developer.wordpress.org/reference/functions/get_post_meta/
|
||||
* - https://developer.wordpress.org/reference/functions/get_post_custom/
|
||||
* if you try to use `get_fields(id)` to retrieve all the acf7 custom fields,
|
||||
* sometimes it fails eventhough you can get a specific value with `get_field(value, id)`,
|
||||
* it's because acf7 didn´t insert the field itself and so some hidden data is not there :
|
||||
* - https://coreysalzano.com/wordpress/acf-get_fields-not-working-but-get_field-does/
|
||||
*/
|
||||
|
||||
// add fields
|
||||
$fields = array(
|
||||
"heure_de_debut",
|
||||
"heure_de_fin",
|
||||
"categorie",
|
||||
"date",
|
||||
"pays",
|
||||
"ville",
|
||||
"adresse",
|
||||
"prenom",
|
||||
"nom",
|
||||
"location",
|
||||
);
|
||||
$event = (object)[];
|
||||
foreach($fields as $field) {
|
||||
$value = get_field($field, $id);
|
||||
if ($value === "↓")
|
||||
$value = "Autre";
|
||||
if (gettype($value) === "string")
|
||||
$value = trim($value, " ");
|
||||
$event->$field = $value;
|
||||
}
|
||||
|
||||
// add mode irl or online (irl: true | false)
|
||||
$presentiel = get_field("mode", $id);
|
||||
$event->irl = false;
|
||||
if ($presentiel[0] === "En présentiel")
|
||||
$event->irl = true;
|
||||
|
||||
// add post url
|
||||
$event->url = get_post_permalink($id);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
function mp_get_published_events() {
|
||||
$posts_list = mp_get_published_posts();
|
||||
|
||||
// mp_console_log("posts :");
|
||||
// mp_console_log($posts_list);
|
||||
// foreach ($posts_list as $post) {
|
||||
// mp_console_log("--------------- post :");
|
||||
// $id = $post->ID;
|
||||
// mp_console_log("id: " . $id);
|
||||
// mp_console_log("adresse: " . $event->adresse);
|
||||
// mp_console_log("pays: " . $event->pays);
|
||||
// mp_console_log("ville: " . $event->ville);
|
||||
// mp_console_log("irl: " . $event->irl);
|
||||
// mp_console_log($event);
|
||||
//
|
||||
// $fields = get_fields($id);
|
||||
// mp_console_log("fields:");
|
||||
// mp_console_log($fields);
|
||||
// $field_heure = get_field("heure_de_debut", $id);
|
||||
// mp_console_log("field_heure: " . $field_heure);
|
||||
// $post_metas = get_post_meta($id);
|
||||
// mp_console_log("post_metas:");
|
||||
// mp_console_log($post_metas);
|
||||
// $post_custom = get_post_custom($id);
|
||||
// mp_console_log("post_custom:");
|
||||
// mp_console_log($post_custom);
|
||||
// foreach( $fields as $name => $value )
|
||||
// mp_console_log($name . " : " . $value);
|
||||
// }
|
||||
|
||||
$events = [];
|
||||
foreach ($posts_list as $post) {
|
||||
$event = mp_fill_fields_value($post->ID);
|
||||
$event->id = $post->ID;
|
||||
$event->title = trim($post->post_title, " ");
|
||||
$event->index = null;
|
||||
array_push($events, $event);
|
||||
}
|
||||
return $events;
|
||||
}
|
||||
|
||||
/*
|
||||
event : {}
|
||||
- heure_de_debut : "";
|
||||
- heure_de_fin : "";
|
||||
- categorie : "";
|
||||
- date : "";
|
||||
- pays : "";
|
||||
- ville : "";
|
||||
- adresse : "";
|
||||
- prenom : "";
|
||||
- nom : "";
|
||||
- irl : bool;
|
||||
- id : x;
|
||||
- index : x (default null);
|
||||
- title : "";
|
||||
- url : "";
|
||||
- location : {}
|
||||
- street : "";
|
||||
- city : "";
|
||||
- country : "";
|
||||
- address : "";
|
||||
- approximate : bool;
|
||||
- coordinates : {}
|
||||
- lat : x;
|
||||
- lng : x;
|
||||
*/
|
||||
|
||||
|
||||
?>
|
||||
160
plug/map_prof/srcs/map/mp_get_filters.php
Normal file
160
plug/map_prof/srcs/map/mp_get_filters.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
function mp_filter_compare($a, $b) {
|
||||
|
||||
$compare = strcmp($a->_name, $b->_name);
|
||||
|
||||
if ($a->_name === "Autre") {
|
||||
if ($compare !== 0)
|
||||
return 1;
|
||||
}
|
||||
if ($b->_name === "Autre") {
|
||||
if ($compare !== 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $compare;
|
||||
}
|
||||
|
||||
function mp_already_in_menu(&$menu, $name) {
|
||||
foreach ($menu as $field) {
|
||||
if ($field->_name == $name)
|
||||
return $field;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* creates the menus
|
||||
* from the events fields
|
||||
* and add the index of the event as it is in location (events when they are sorted)
|
||||
*
|
||||
* fields: [ countries:"", cities:"", categories:"", ... ]
|
||||
* name : field's values -> countries, cities, categories, ...
|
||||
* menu : [ { _name:"", field_1:[], field_2:[] }, ... ]
|
||||
* index : index of this event in locations[] array
|
||||
*/
|
||||
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_item, ex: for menu "countries" -> france
|
||||
$menu_item = mp_already_in_menu($menu, $fields[$name]);
|
||||
if ($menu_item != null) {
|
||||
// add to this menu item, eg "Austria", the infos of this
|
||||
// event, like "city" or "category", if not there already
|
||||
foreach ($fields as $key_field => $value) {
|
||||
// no need to add name if already exist
|
||||
if ($key_field == $name)
|
||||
continue;
|
||||
if (! isset($menu_item->$key_field) )
|
||||
$menu_item->$key_field = [];
|
||||
if (!is_string($value))
|
||||
continue;
|
||||
if (strlen($value) != 0) {
|
||||
if (! in_array($value, $menu_item->$key_field) )
|
||||
array_push($menu_item->$key_field, $value);
|
||||
}
|
||||
}
|
||||
// add location index, if not there already
|
||||
if (! in_array($index, $menu_item->indexes) ) {
|
||||
array_push($menu_item->indexes, $index);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$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;
|
||||
$menu_item->$key_field = [];
|
||||
if (!is_string($value))
|
||||
continue;
|
||||
if (strlen($value) != 0)
|
||||
array_push($menu_item->$key_field, $value);
|
||||
}
|
||||
// add list of location index
|
||||
$menu_item->indexes = [$index];
|
||||
|
||||
// and add this item to list of menu
|
||||
array_push($menu, $menu_item);
|
||||
}
|
||||
}
|
||||
|
||||
function mp_get_filters(&$events) {
|
||||
$filters = (object)[];
|
||||
|
||||
foreach ($events as $event) {
|
||||
|
||||
// no index means no coordinates
|
||||
$index = $event->index;
|
||||
if ($index === null)
|
||||
continue;
|
||||
|
||||
// create array of menus
|
||||
$fields = array(
|
||||
"Pays" => $event->location->country,
|
||||
"Catégories" => $event->categorie,
|
||||
"mode" => ($event->irl)? "En présentiel" : "En ligne",
|
||||
);
|
||||
|
||||
// fill all menu with other menus without doubles
|
||||
foreach ($fields as $name => $value) {
|
||||
if (! isset($filters->$name))
|
||||
$filters->$name = [];
|
||||
mp_fill_name($fields, $name, $filters->$name, $index);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
usort($filters->$key, 'mp_filter_compare');
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/*
|
||||
{ }
|
||||
{ [ ] }
|
||||
filters: { - countries : [ { - _name : "" } ] }
|
||||
{ [ { - categories: [] } ] }
|
||||
{ [ { - indexes : [] }, ... ] }
|
||||
{ [ ] }
|
||||
{ }
|
||||
{ - categories: }
|
||||
{ - modes : }
|
||||
{ }
|
||||
*/
|
||||
|
||||
/*
|
||||
event : {}
|
||||
- heure_de_debut : "";
|
||||
- heure_de_fin : "";
|
||||
- categorie : "";
|
||||
- date : "";
|
||||
- pays : "";
|
||||
- ville : "";
|
||||
- adresse : "";
|
||||
- prenom : "";
|
||||
- nom : "";
|
||||
- irl : bool;
|
||||
- id : x;
|
||||
- index : x;
|
||||
- title : "";
|
||||
- location : {}
|
||||
- street : "";
|
||||
- city : "";
|
||||
- country : "";
|
||||
- address : "";
|
||||
- approximate : bool;
|
||||
- coordinates : {}
|
||||
- lat : x;
|
||||
- lng : x;
|
||||
*/
|
||||
|
||||
?>
|
||||
66
plug/map_prof/srcs/map/mp_get_locations.php
Normal file
66
plug/map_prof/srcs/map/mp_get_locations.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
function mp_coord_already_exist(&$coordinates, &$locations) {
|
||||
foreach ($locations as $location) {
|
||||
if ($location->coordinates->lat == $coordinates->lat)
|
||||
if ($location->coordinates->lng == $coordinates->lng)
|
||||
return $location;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function mp_sort_n_insert(&$event, &$locations) {
|
||||
$coordinates = $event->location->coordinates;
|
||||
if ($coordinates == null)
|
||||
return;
|
||||
|
||||
$already_exist = mp_coord_already_exist($coordinates, $locations);
|
||||
if ($already_exist) {
|
||||
// add index to the event
|
||||
$index = $already_exist->index;
|
||||
$event->index = $index;
|
||||
// add event to events[]
|
||||
array_push($already_exist->events, $event);
|
||||
}
|
||||
else {
|
||||
// create new location object
|
||||
$location = (object)[];
|
||||
$location->events = [];
|
||||
|
||||
// add index to the location and event
|
||||
$index = count($locations);
|
||||
$location->index = $index;
|
||||
$event->index = $index;
|
||||
// add coordinates to the location
|
||||
$location->coordinates = $coordinates;
|
||||
// add first event to events[]
|
||||
array_push($location->events, $event);
|
||||
// add this location to locations[]
|
||||
array_push($locations, $location);
|
||||
}
|
||||
}
|
||||
|
||||
function mp_sort_events(&$events) {
|
||||
$locations = [];
|
||||
|
||||
foreach ($events as $event) {
|
||||
mp_sort_n_insert($event, $locations);
|
||||
};
|
||||
|
||||
return $locations;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
locations = [
|
||||
{
|
||||
index : x
|
||||
coordinates: {}
|
||||
events : [{}, ...]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
*/
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user