aboutsummaryrefslogtreecommitdiff
path: root/app/genealogy/search/city/data.json/index.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-05 16:38:49 +0100
committerMinteck <contact@minteck.org>2021-12-05 16:38:49 +0100
commit879a6237b186768356f99caf992f0d25d5ec8612 (patch)
tree733aacd4845e918b484d8f46951d925f05f91b4c /app/genealogy/search/city/data.json/index.php
parent4bad8bcfb984cf017495b8fd31f174c32cebe805 (diff)
downloadcore-879a6237b186768356f99caf992f0d25d5ec8612.tar.gz
core-879a6237b186768356f99caf992f0d25d5ec8612.tar.bz2
core-879a6237b186768356f99caf992f0d25d5ec8612.zip
Commit
Diffstat (limited to 'app/genealogy/search/city/data.json/index.php')
-rw-r--r--app/genealogy/search/city/data.json/index.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/genealogy/search/city/data.json/index.php b/app/genealogy/search/city/data.json/index.php
new file mode 100644
index 0000000..e61fd04
--- /dev/null
+++ b/app/genealogy/search/city/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"]["city"])) {
+ if (isset($counts[$person["birth"]["place"]["city"]])) {
+ $counts[$person["birth"]["place"]["city"]]++;
+ } else {
+ $counts[$person["birth"]["place"]["city"]] = 1;
+ }
+ if (!in_array($person["birth"]["place"]["city"], $names)) {
+ $names[] = $person["birth"]["place"]["city"];
+ }
+ }
+}
+
+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