From f0bda2ee249086e912efd1e4ed9be8647e1b1900 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 24 Dec 2024 16:38:28 +0300 Subject: [PATCH] post filters --- .../CustomSelectFilterForAssociativeArr.php | 24 +++++++++ .../ModuleShopClientController.php | 25 +-------- .../services/ModuleShopClientService.php | 26 ++++----- kernel/modules/post/views/index.php | 53 +++++++++++++------ 4 files changed, 77 insertions(+), 51 deletions(-) create mode 100644 kernel/filters/CustomSelectFilterForAssociativeArr.php diff --git a/kernel/filters/CustomSelectFilterForAssociativeArr.php b/kernel/filters/CustomSelectFilterForAssociativeArr.php new file mode 100644 index 0000000..6a5cbd2 --- /dev/null +++ b/kernel/filters/CustomSelectFilterForAssociativeArr.php @@ -0,0 +1,24 @@ +html = ""; + return $this->html; + } +} \ No newline at end of file diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 49be935..1bb8f59 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -45,30 +45,9 @@ class ModuleShopClientController extends AdminController if ($this->moduleService->issetModuleShopToken()) { if ($this->moduleService->isServerAvailable()) { - $request = new Request(); - $filters = $request->get(); - $per_page = 8; - -// $this->moduleShopClientService->getModulesInfo($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug') - $modules = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - $modules = json_decode($modules->getBody()->getContents(), true); - if ($filters) { - $modules_info = []; - foreach ($modules as $module) { - foreach ($filters as $key => $value) { - if ($value === '') continue; - if ($module[$key] !== $value) { - break; - } - - $modules_info[] = $module; - } - } - } else { - $modules_info = $modules; - } - + $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + $modules_info = json_decode($modules_info->getBody()->getContents(), true); $module_count = count($modules_info); $modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page); diff --git a/kernel/modules/module_shop_client/services/ModuleShopClientService.php b/kernel/modules/module_shop_client/services/ModuleShopClientService.php index b33f37e..d86afca 100644 --- a/kernel/modules/module_shop_client/services/ModuleShopClientService.php +++ b/kernel/modules/module_shop_client/services/ModuleShopClientService.php @@ -6,17 +6,17 @@ use kernel\helpers\RESTClient; class ModuleShopClientService { - public function getModulesInfo(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface - { - $modules_info = RESTClient::request($url); - $modules_info = json_decode($modules_info->getBody()->getContents(), true); - return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage); - } - - public function getModulesInfoWithFilters(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface - { - $modules_info = RESTClient::request($url); - $modules_info = json_decode($modules_info->getBody()->getContents(), true); - return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage); - } +// public function getModulesInfo(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface +// { +// $modules_info = RESTClient::request($url); +// $modules_info = json_decode($modules_info->getBody()->getContents(), true); +// return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage); +// } +// +// public function getModulesInfoWithFilters(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface +// { +// $modules_info = RESTClient::request($url); +// $modules_info = json_decode($modules_info->getBody()->getContents(), true); +// return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage); +// } } \ No newline at end of file diff --git a/kernel/modules/post/views/index.php b/kernel/modules/post/views/index.php index 5cd2ee8..bed57d6 100644 --- a/kernel/modules/post/views/index.php +++ b/kernel/modules/post/views/index.php @@ -15,14 +15,19 @@ use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnEditWidget; use kernel\widgets\IconBtn\IconBtnViewWidget; +$request = (new \kernel\Request())->get(); + $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [ 'currentPage' => $page_number, 'perPage' => 3, 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/post", - 'showFiltersRow' => false, + 'searchPrefix' => "", + 'searchParams' => (new \kernel\Request())->get() ])); +//\kernel\helpers\Debug::dd((new \kernel\Request())->get()); + $view->setTitle("Список постов"); $view->setMeta([ 'description' => 'Список постов системы' @@ -37,36 +42,54 @@ foreach ($additionals as $additional) { }); } +//\kernel\helpers\Debug::dd($request); + $table->columns([ - 'created_at' => function ($data) { - if (!$data){ - return null; - } - - return (new DateTimeImmutable($data))->format("d-m-Y"); - }, + 'title' => [ + 'filter' => [ + 'class' => \Itguild\Tables\Filter\InputTextFilter::class, + 'value' => $request['title'] ?? '' + ] + ], + 'content' => [ + 'filter' => [ + 'class' => \Itguild\Tables\Filter\InputTextFilter::class, + 'value' => $request['content'] ?? '' + ] + ], + 'created_at' => [ + 'format' => 'date:d-m-Y', + ], 'updated_at' => function ($data) { - if (!$data){ + if (!$data) { return null; } return (new DateTimeImmutable($data))->format("d-m-Y"); }, - 'user_id' => (function ($data) { - return User::find($data)->username; - }) + 'user_id' => [ + 'value' => function ($data) { + return User::find($data)->username; + }, + 'filter' => [ + 'class' => \kernel\filters\CustomSelectFilterForAssociativeArr::class, + 'param' => \kernel\modules\user\service\UserService::createUsernameArr(), + 'value' => $request['user_id'] ?? '' + ] + ] ]); + $table->beforePrint(function () { return IconBtnCreateWidget::create(['url' => '/admin/post/create'])->run(); }); -$table->addAction(function($row) { +$table->addAction(function ($row) { return IconBtnViewWidget::create(['url' => '/admin/post/view/' . $row['id']])->run(); }); -$table->addAction(function($row) { +$table->addAction(function ($row) { return IconBtnEditWidget::create(['url' => '/admin/post/update/' . $row['id']])->run(); }); -$table->addAction(function($row) { +$table->addAction(function ($row) { return IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $row['id']])->run(); }); $table->create();