141 lines
4.2 KiB
PHP
Raw Normal View History

2024-10-29 14:53:52 +03:00
<?php
/**
* @var array $modules_info
* @var int $module_count
* @var int $page_number
* @var int $per_page
2024-10-31 16:12:02 +03:00
* @var \kernel\services\ModuleService $moduleService
2024-12-17 12:23:45 +03:00
* @var \kernel\services\KernelService $kernelService
2024-12-18 12:27:29 +03:00
* @var \kernel\services\AdminThemeService $adminThemeService
2024-12-25 16:32:23 +03:00
* @var array $filterValues
2024-10-29 14:53:52 +03:00
*/
use Itguild\Tables\ListJsonTable;
2024-11-19 14:55:25 +03:00
use kernel\widgets\ActionButtonWidget;
2024-12-27 13:50:37 +03:00
2024-10-29 14:53:52 +03:00
$meta = [];
$meta['columns'] = [
"name" => "Название",
"author" => "Автор",
"version" => "Версия",
"type" => "Тип",
2024-10-29 14:53:52 +03:00
"description" => "Описание",
"installations" => "Установки",
"views" => "Просмотры"
];
$meta['params'] = ["class" => "table table-bordered"];
$meta['perPage'] = $per_page;
$meta['baseUrl'] = "/admin/module_shop_client";
$meta['currentPage'] = $page_number;
$meta['total'] = $module_count;
$info_to_table['meta'] = $meta;
$info_to_table['data'] = $modules_info;
$table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
2024-11-19 14:55:25 +03:00
$table->addAction(function ($row, $url) use ($moduleService) {
2024-11-20 12:45:02 +03:00
$url = "$url/view/" . $row['id'];
2024-11-19 14:55:25 +03:00
2024-11-20 12:45:02 +03:00
return \kernel\widgets\IconBtn\IconBtnViewWidget::create(['url' => $url])->run();
2024-11-19 14:55:25 +03:00
});
2024-10-29 14:53:52 +03:00
2024-12-19 15:10:29 +03:00
$table->columns([
'type' => [
'filter' => [
2024-12-27 13:50:37 +03:00
'class' => \kernel\filters\BootstrapSelectFilter::class,
'params' => [
'options' => [
'kernel' => 'kernel',
'entity' => 'entity',
],
'prompt' => 'Не выбрано'
2024-12-25 16:32:23 +03:00
],
'value' => $filterValues['type'] ?? ''
2024-12-19 15:10:29 +03:00
],
]
]);
2024-12-23 14:14:59 +03:00
$table->addAction(function ($row, $url) use ($moduleService) {
if ($row['type'] === 'entity' || $row['type'] === 'additional_property') {
2024-12-17 12:23:45 +03:00
if ($moduleService->isInstall($row['slug'])) {
$url = "$url/delete/?slug=" . $row['slug'];
2024-11-20 12:45:02 +03:00
2024-12-17 12:23:45 +03:00
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
} else {
$url = "$url/install/?id=" . $row['id'];
2024-11-20 12:45:02 +03:00
2024-12-17 12:23:45 +03:00
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
}
2024-10-31 16:12:02 +03:00
}
2024-12-23 14:14:59 +03:00
return false;
2024-10-31 16:12:02 +03:00
});
2024-10-29 14:53:52 +03:00
2024-12-18 12:27:29 +03:00
$table->addAction(function ($row, $url) use ($moduleService) {
2024-12-23 14:14:59 +03:00
if ($row['type'] === 'entity' || $row['type'] === 'additional_property') {
$slug = $row['slug'];
if ($moduleService->isInstall($slug)) {
if (!$moduleService->isLastVersion($slug)) {
$url = "$url/update/?slug=" . $slug;
2024-11-20 12:45:02 +03:00
2024-12-23 14:14:59 +03:00
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
}
2024-11-14 01:55:04 +03:00
}
}
2024-12-18 12:27:29 +03:00
return false;
});
$table->addAction(function ($row, $url) use ($kernelService) {
2024-12-23 14:14:59 +03:00
if ($row['type'] === 'kernel') {
2024-12-17 12:23:45 +03:00
if (!$kernelService->isLastVersion()) {
$url = "$url/kernel/update_form/";
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
}
}
return false;
2024-11-14 01:55:04 +03:00
});
2024-12-18 12:27:29 +03:00
$table->addAction(function ($row, $url) use ($adminThemeService) {
2024-12-23 14:14:59 +03:00
if ($row['type'] === 'admin_theme') {
$slug = $row['slug'];
2024-12-18 12:27:29 +03:00
if ($adminThemeService->isInstall($slug)) {
if (!$adminThemeService->isLastVersion($slug)) {
2025-01-09 12:17:32 +03:00
$url = "$url/admin_theme/update/?slug=" . $row['slug'];
2024-12-18 12:27:29 +03:00
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
}
}
}
return false;
});
2025-01-09 12:17:32 +03:00
$table->addAction(function ($row, $url) use ($adminThemeService) {
if ($row['type'] === 'admin_theme') {
if ($adminThemeService->isInstall($row['slug'])) {
$url = "$url/admin_theme/delete/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
} else {
$url = "$url/admin_theme/install/?id=" . $row['id'];
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
}
}
return false;
});
$table->afterPrint(function () {
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
});
2024-11-20 12:45:02 +03:00
\kernel\widgets\ModuleTabsWidget::create()->run();
2024-10-29 14:53:52 +03:00
$table->create();
$table->render();