module shop

This commit is contained in:
Kavalar 2024-12-04 15:36:11 +03:00
parent 0a76920800
commit 0671346ce8
6 changed files with 86 additions and 13 deletions

View File

@ -11,6 +11,12 @@ class Html
return "<img src='$src' $paramsStr>"; return "<img src='$src' $paramsStr>";
} }
public static function h(string|int $type = 1, string $title = '', array $params = [])
{
$paramsStr = self::createParams($params);
return "<h$type $paramsStr>$title</h$type>";
}
/** /**
* @param array $data * @param array $data
* @return string * @return string

View File

@ -34,18 +34,30 @@ class ModuleShopClientController extends AdminController
*/ */
public function actionIndex(int $page_number = 1): void public function actionIndex(int $page_number = 1): void
{ {
$per_page = 8;
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); if ($this->moduleService->issetModuleShopToken()) {
$modules_info = json_decode($modules_info->getBody()->getContents(), true); if ($this->moduleService->isServerAvailable()) {
$module_count = count($modules_info);
$modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page); $per_page = 8;
$this->cgView->render("index.php", [ $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
'modules_info' => $modules_info, $modules_info = json_decode($modules_info->getBody()->getContents(), true);
'moduleService' => $this->moduleService, $module_count = count($modules_info);
'page_number' => $page_number, $modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page);
'module_count' => $module_count,
'per_page' => $per_page, $this->cgView->render("index.php", [
]); 'modules_info' => $modules_info,
'moduleService' => $this->moduleService,
'page_number' => $page_number,
'module_count' => $module_count,
'per_page' => $per_page,
]);
} else {
$this->cgView->render("module_shop_error_connection.php");
}
} else {
$this->cgView->render("login_at_module_shop.php");
}
} }
public function actionView(int $id): void public function actionView(int $id): void

View File

@ -0,0 +1,34 @@
<?php
use itguild\forms\ActiveForm;
\kernel\widgets\ModuleTabsWidget::create()->run();
echo \kernel\helpers\Html::h(2, "Форма авторизации");
$form = new ActiveForm();
$form->beginForm("/admin/module_shop_client/auth/");
$form->field(\itguild\forms\inputs\TextInput::class, 'key', [
'class' => "form-control",
'placeholder' => 'Email',
])
->setLabel("Email")
->render();
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -0,0 +1,6 @@
<?php
\kernel\widgets\ModuleTabsWidget::create()->run();
?>
<h1>Ошибка подключения к сервису</h1>

View File

@ -476,6 +476,10 @@ class ModuleService
if ($this->isServerAvailable()){ if ($this->isServerAvailable()){
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
if (!$this->issetModuleShopToken()){
return false;
}
$modules_info = json_decode($modules_info->getBody()->getContents(), true); $modules_info = json_decode($modules_info->getBody()->getContents(), true);
$mod_info = $this->getModuleInfoBySlug($slug); $mod_info = $this->getModuleInfoBySlug($slug);
foreach ($modules_info as $mod) { foreach ($modules_info as $mod) {
@ -516,4 +520,13 @@ class ModuleService
} }
} }
public function issetModuleShopToken(): bool
{
if (!empty($_ENV['MODULE_SHOP_TOKEN'])){
return true;
}
return false;
}
} }

View File

@ -75,9 +75,11 @@ $table->addAction(function ($row) use ($moduleService){
return false; return false;
}); });
if ($moduleService->isActive('module_shop_client') && $moduleService->isServerAvailable()) { if ($moduleService->isActive('module_shop_client')) {
ModuleTabsWidget::create()->run(); ModuleTabsWidget::create()->run();
} }
$table->create(); $table->create();
$table->render(); $table->render();