From c24b2bbfb12c33b0114d36cf27561ef3a457a027 Mon Sep 17 00:00:00 2001 From: Mh-Asmi Date: Wed, 18 Dec 2024 04:25:36 +0400 Subject: [PATCH] change category limit --- .../Queries/FetchAllCategoriesQuery.php | 1 + .../V5/Http/Resources/CategoryResource.php | 4 ++- .../Modules/V5/Traits/HasPaginate.php | 30 ++++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Ushahidi/Modules/V5/Actions/Category/Queries/FetchAllCategoriesQuery.php b/src/Ushahidi/Modules/V5/Actions/Category/Queries/FetchAllCategoriesQuery.php index 769d0a690..3d8b4e2cf 100644 --- a/src/Ushahidi/Modules/V5/Actions/Category/Queries/FetchAllCategoriesQuery.php +++ b/src/Ushahidi/Modules/V5/Actions/Category/Queries/FetchAllCategoriesQuery.php @@ -21,6 +21,7 @@ class FetchAllCategoriesQuery implements Query public static function fromRequest(Request $request): self { $query = new self(); + $query->setDefaultLimit(1000); $query->setPaging($request); $query->setSearchFields(new CategorySearchFields($request)); $query->addOnlyParameteresFromRequest( diff --git a/src/Ushahidi/Modules/V5/Http/Resources/CategoryResource.php b/src/Ushahidi/Modules/V5/Http/Resources/CategoryResource.php index ba100a593..59172a84e 100644 --- a/src/Ushahidi/Modules/V5/Http/Resources/CategoryResource.php +++ b/src/Ushahidi/Modules/V5/Http/Resources/CategoryResource.php @@ -54,7 +54,9 @@ public function toArray($request) 'available' => $this->translations->groupBy('language')->keys() ]; } - $data['allowed_privileges']= $this->getResourcePrivileges(); + // To Do: this call cause an infinit loop , need to be checked + // note: it was not found before last commit , so it will not disable it it will not affect the work of front end + //$data['allowed_privileges']= $this->getResourcePrivileges(); return $data; } diff --git a/src/Ushahidi/Modules/V5/Traits/HasPaginate.php b/src/Ushahidi/Modules/V5/Traits/HasPaginate.php index 70d16d0cb..61e35b0ed 100644 --- a/src/Ushahidi/Modules/V5/Traits/HasPaginate.php +++ b/src/Ushahidi/Modules/V5/Traits/HasPaginate.php @@ -13,13 +13,14 @@ trait HasPaginate private $paging; private $default_order; private $default_sort_by = 'id'; - private $default_limit = '20'; + private $default_limit = 20; + private $default_page = 1; public function getPaging(): Paging { return $this->paging; } - + public function setPaging( Request $request, $default_sort_by = null, @@ -29,15 +30,28 @@ public function setPaging( ) { $this->paging = Paging::fromRequest( $request, - $default_sort_by, - $default_order, - $default_limit, - $default_page + $default_sort_by ?? $this->default_sort_by, + $default_order ?? $this->default_order, + $default_limit ?? $this->default_limit, + $default_page ?? $this->default_page ); } - public function setDefaultOrder(): void + public function setDefaultOrder($order): void + { + $this->default_order = $order; + } + public function setDefaultSort($sort): void + { + $this->default_sort_by = $sort; + } + public function setDefaultLimit($limit): void + { + $this->default_limit = $limit; + } + + public function setDefaultPage($page): void { - $this->paging; + $this->page = $page; } }