diff options
Diffstat (limited to 'search/dept/data.json')
-rw-r--r-- | search/dept/data.json/index.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/search/dept/data.json/index.php b/search/dept/data.json/index.php new file mode 100644 index 0000000..5a0ed2a --- /dev/null +++ b/search/dept/data.json/index.php @@ -0,0 +1,39 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/../session.php"; + +/** @var string $_FULLNAME + * @var string $_USER + * @var array $_PROFILE + * @var array $_CONFIG + */ + +$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/data/people.json"), true); + +header("Content-Type: application/json"); + +$arr = []; +$names = []; +$counts = []; + +foreach ($data as $id => $person) { + if (isset($person["birth"]["place"]) && isset($person["birth"]["place"]["dept"])) { + if (isset($counts[$person["birth"]["place"]["dept"]])) { + $counts[$person["birth"]["place"]["dept"]]++; + } else { + $counts[$person["birth"]["place"]["dept"]] = 1; + } + if (!in_array($person["birth"]["place"]["dept"], $names)) { + $names[] = $person["birth"]["place"]["dept"]; + } + } +} + +foreach ($names as $name) { + $arr[] = [ + 'name' => $name, + 'occurrences' => $counts[$name] . " personne" . ($counts[$name] > 1 ? "s" : "") + ]; +} + +echo(json_encode($arr));
\ No newline at end of file |