post filters
This commit is contained in:
parent
04bd134e3e
commit
f0bda2ee24
24
kernel/filters/CustomSelectFilterForAssociativeArr.php
Normal file
24
kernel/filters/CustomSelectFilterForAssociativeArr.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\filters;
|
||||
|
||||
use Itguild\Tables\Filter\Filter;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class CustomSelectFilterForAssociativeArr extends Filter
|
||||
{
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$this->html = "<td><select class='form-control' name='$this->name'>";
|
||||
foreach ($this->param as $key => $value) {
|
||||
if ($key == $this->value) {
|
||||
$this->html .= "<option value='$key' selected>$value</option>";
|
||||
} else {
|
||||
$this->html .= "<option value='$key'>$value</option>";
|
||||
}
|
||||
}
|
||||
$this->html .= "value='$this->value'</select></td>";
|
||||
return $this->html;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
// }
|
||||
}
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user