@@ -61,12 +61,22 @@ public function handle(Request $request): Response
61
61
function parseRequestArgs (Request $ request ): object
62
62
{
63
63
$ 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 );
64
74
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 )
70
80
];
71
81
}
72
82
@@ -76,7 +86,8 @@ function api(object $args): array
76
86
foreach ($ this ->trees ->all () as $ tree )
77
87
$ changes [$ tree ->name ()] = $ this ->getChanges ($ tree , $ args ->days )
78
88
->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 ();
80
91
return $ changes ;
81
92
}
82
93
0 commit comments