Skip to content

Commit 2670e6e

Browse files
committed
Sort by date + Some minor improvements
1 parent d4f243b commit 2670e6e

File tree

5 files changed

+303
-16
lines changed

5 files changed

+303
-16
lines changed

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tree by Aleksandr Vector from NounProject.com

RequestHandler.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,22 @@ public function handle(Request $request): Response
6161
function parseRequestArgs(Request $request): object
6262
{
6363
$params = $request->getQueryParams();
64+
$getValue = function ($param, $default, $exists = null) use ($params) {
65+
if (array_key_exists($param, $params)) return $exists === null ? $params[$param] : $exists($params[$param]);
66+
else return $default;
67+
};
68+
69+
$strToBool = function($str) { return $str === null || $str === "" || $str === "True"; };
70+
$strToInt = function($str) { return intval($str); };
71+
$strToArray = function($str) { return explode(',', $str); };
72+
73+
$days = $getValue("days", 7, $strToInt);
6474
return (object)[
65-
'days' => array_key_exists("days", $params) ? intval($params["days"]) : 7,
66-
'tags' => array_key_exists("tags", $params) ? explode(',', $params["tags"]) : [Individual::RECORD_TYPE, Family::RECORD_TYPE],
67-
'users' => array_key_exists("users", $params) ? explode(',', $params["users"]) : [],
68-
'imageCompatibilityMode' => array_key_exists("png", $params),
69-
'title' => array_key_exists("title", $params) ? $params["title"] : I18N::translate('Recent changes')
75+
'days' => $days,
76+
'title' => $getValue("title", I18N::plural('Changes in the last %s day', 'Changes in the last %s days', $days, $days)),
77+
'tags' => $getValue("tags", [Individual::RECORD_TYPE, Family::RECORD_TYPE], $strToArray),
78+
'users' => $getValue("users", [], $strToArray),
79+
'imageCompatibilityMode' => $getValue("png", false, $strToBool)
7080
];
7181
}
7282

@@ -76,7 +86,8 @@ function api(object $args): array
7686
foreach($this->trees->all() as $tree)
7787
$changes[$tree->name()] = $this->getChanges($tree, $args->days)
7888
->filter(static function (stdClass $row) use ($args):bool { return in_array($row->record["tag"] , $args->tags); })
79-
->groupBy(static function (stdClass $row) { return $row->time->format('Y-m-d'); });
89+
->groupBy(static function (stdClass $row) { return $row->time->format('Y-m-d'); })
90+
->sortKeys();
8091
return $changes;
8192
}
8293

resources/img/png/tree.png

3.33 KB
Loading

0 commit comments

Comments
 (0)