diff --git a/app/modules/tgbot/controllers/TgBotRestController.php b/app/modules/tgbot/controllers/TgBotRestController.php index e9797ca..e7e1be2 100644 --- a/app/modules/tgbot/controllers/TgBotRestController.php +++ b/app/modules/tgbot/controllers/TgBotRestController.php @@ -3,6 +3,8 @@ namespace app\modules\tgbot\controllers; use app\modules\tgbot\models\Tgbot; +use kernel\app_modules\tag\service\TagService; +use kernel\modules\post\models\Post; class TgBotRestController extends \kernel\app_modules\tgbot\controllers\TgBotRestController { @@ -12,9 +14,15 @@ class TgBotRestController extends \kernel\app_modules\tgbot\controllers\TgBotRes $dialog = Tgbot::where("dialog_id", $id)->first(); if ($dialog){ $this->renderApi([ - 'html' => 'Сканировать', + 'html' => 'Сканировать', ]); } } + + public function actionGetNews(): void + { + + } + } \ No newline at end of file diff --git a/app/modules/tgbot/controllers/TgMainController.php b/app/modules/tgbot/controllers/TgMainController.php index f887af0..9acd7dd 100644 --- a/app/modules/tgbot/controllers/TgMainController.php +++ b/app/modules/tgbot/controllers/TgMainController.php @@ -3,7 +3,9 @@ namespace app\modules\tgbot\controllers; use app\modules\tgbot\models\Tgbot; +use app\modules\tgbot\services\TgBotService; use Cassandra\Decimal; +use kernel\app_modules\card\models\Card; use kernel\app_modules\tag\service\TagService; use kernel\Controller; use kernel\helpers\Debug; @@ -40,4 +42,16 @@ class TgMainController extends Controller $this->cgView->render("news.php", ['news' => $news]); } + public function actionScanner(): void + { + $this->cgView->render("scanner.php"); + } + + public function actionCardAction(int $cardId): void + { + $card = Card::where("id", $cardId)->first(); + + $this->cgView->render("card_action.php", ['card' => $card]); + } + } \ No newline at end of file diff --git a/app/modules/tgbot/middlewares/TgBotAuthMiddleware.php b/app/modules/tgbot/middlewares/TgBotAuthMiddleware.php new file mode 100644 index 0000000..68f6752 --- /dev/null +++ b/app/modules/tgbot/middlewares/TgBotAuthMiddleware.php @@ -0,0 +1,26 @@ +first(); + if ($model){ + TgBotService::$currentDialog = $model; + + return; + } + } + + exit(); + } +} \ No newline at end of file diff --git a/app/modules/tgbot/routs/tgbot.php b/app/modules/tgbot/routs/tgbot.php index 55a8a5f..43a0f44 100644 --- a/app/modules/tgbot/routs/tgbot.php +++ b/app/modules/tgbot/routs/tgbot.php @@ -5,9 +5,14 @@ use kernel\CgRouteCollector; include KERNEL_APP_MODULES_DIR . "/tgbot/routs/tgbot.php"; +App::$collector->filter("tg_bot_auth", [\app\modules\tgbot\middlewares\TgBotAuthMiddleware::class, "handler"]); App::$collector->group(["prefix" => "miniapp"], function (CGRouteCollector $router) { App::$collector->get('/', [\app\modules\tgbot\controllers\TgMainController::class, 'actionMain']); - App::$collector->get('/news', [\app\modules\tgbot\controllers\TgMainController::class, 'actionNews']); - App::$collector->get('/promo', [\app\modules\tgbot\controllers\TgMainController::class, 'actionPromo']); + App::$collector->group(["before" => "tg_bot_auth"], function (CGRouteCollector $router){ + App::$collector->get('/news', [\app\modules\tgbot\controllers\TgMainController::class, 'actionNews']); + App::$collector->get('/promo', [\app\modules\tgbot\controllers\TgMainController::class, 'actionPromo']); + App::$collector->get('/scanner', [\app\modules\tgbot\controllers\TgMainController::class, 'actionScanner']); + App::$collector->get('/card_action/{cardId}', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardAction']); + }); }); \ No newline at end of file diff --git a/app/modules/tgbot/services/TgBotService.php b/app/modules/tgbot/services/TgBotService.php index 585c18b..f74292d 100644 --- a/app/modules/tgbot/services/TgBotService.php +++ b/app/modules/tgbot/services/TgBotService.php @@ -12,4 +12,6 @@ use kernel\services\ModuleService; class TgBotService extends \kernel\app_modules\tgbot\services\TgBotService { + public static null|Tgbot $currentDialog = null; + } \ No newline at end of file diff --git a/app/modules/tgbot/views/tgbot/layout/main.php b/app/modules/tgbot/views/tgbot/layout/main.php index 6296109..e933957 100644 --- a/app/modules/tgbot/views/tgbot/layout/main.php +++ b/app/modules/tgbot/views/tgbot/layout/main.php @@ -22,6 +22,7 @@ +
diff --git a/app/modules/tgbot/views/tgbot/main/card_action.php b/app/modules/tgbot/views/tgbot/main/card_action.php new file mode 100644 index 0000000..956604e --- /dev/null +++ b/app/modules/tgbot/views/tgbot/main/card_action.php @@ -0,0 +1,23 @@ + + +