File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/services/mongodb/tools Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace gcgov \framework \services \mongodb \tools ;
4
+
5
+ class getAllStdQueryParams {
6
+
7
+ public int $ limit ;
8
+ public int $ page ;
9
+
10
+ /**
11
+ * @var array<string, int>
12
+ */
13
+ public array $ sort ;
14
+
15
+
16
+ public function __construct ( int $ defaultLimit = 10 , int $ defaultPage = 1 ) {
17
+ $ this ->limit = $ defaultLimit ;
18
+ $ this ->page = $ defaultPage ;
19
+ }
20
+
21
+
22
+ public static function get ( int $ defaultLimit = 10 , int $ defaultPage = 1 ): static {
23
+ $ params = new self ( $ defaultLimit , $ defaultPage );
24
+ $ params ->limit = $ _GET [ 'limit ' ] ?? $ defaultLimit ;
25
+ $ params ->page = $ _GET [ 'page ' ] ?? $ defaultPage ;
26
+
27
+ if ( isset ( $ _GET [ 'sortBy ' ] ) && is_array ( $ _GET [ 'sortBy ' ] ) ) {
28
+ foreach ( $ _GET [ 'sortBy ' ] as $ sortBy ) {
29
+ $ parts = explode ( '| ' , $ sortBy );
30
+ $ params ->sort [ $ parts [ 0 ] ] = $ parts [ 1 ]=='desc ' || $ parts [ 0 ]=='false ' || $ parts [ 0 ]==0 ? -1 : 1 ;
31
+ }
32
+ }
33
+
34
+ return $ params ;
35
+ }
36
+
37
+ }
You can’t perform that action at this time.
0 commit comments