diff --git a/app/modules/photo/PhotoModule.php b/app/modules/photo/PhotoModule.php
index ff86533..3cededd 100644
--- a/app/modules/photo/PhotoModule.php
+++ b/app/modules/photo/PhotoModule.php
@@ -2,7 +2,31 @@
namespace app\modules\photo;
+use Illuminate\Database\Eloquent\Model;
+use kernel\app_modules\photo\models\Photo;
+
class PhotoModule extends \kernel\app_modules\photo\PhotoModule
{
+ public function getItems(string $entity, Model $model): array|string
+ {
+ $photos = Photo::where("entity", $entity)->where("entity_id", $model->id)->get();
+ $photoArr = [];
+ foreach ($photos as $photo) {
+ $photoArr[] =$photo->image;
+ }
+
+ return $photoArr;
+ }
+
+ public function getItem(string $entity, string $entity_id): string
+ {
+ $photos = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
+ if ($photos){
+ return $photos->image;
+ }
+
+ return "";
+ }
+
}
\ No newline at end of file
diff --git a/app/modules/tgbot/controllers/TgMainController.php b/app/modules/tgbot/controllers/TgMainController.php
index 1e27073..751a20a 100644
--- a/app/modules/tgbot/controllers/TgMainController.php
+++ b/app/modules/tgbot/controllers/TgMainController.php
@@ -2,7 +2,9 @@
namespace app\modules\tgbot\controllers;
+use kernel\app_modules\tag\service\TagService;
use kernel\Controller;
+use kernel\modules\post\models\Post;
class TgMainController extends Controller
{
@@ -21,4 +23,18 @@ class TgMainController extends Controller
$this->cgView->render("index.php");
}
+ public function actionNews(): void
+ {
+ $news = TagService::getEntityByTagId(2, Post::class);
+
+ $this->cgView->render("news.php", ['news' => $news]);
+ }
+
+ public function actionPromo(): void
+ {
+ $news = TagService::getEntityByTagId(1, Post::class);
+
+ $this->cgView->render("news.php", ['news' => $news]);
+ }
+
}
\ No newline at end of file
diff --git a/app/modules/tgbot/routs/tgbot.php b/app/modules/tgbot/routs/tgbot.php
index dfe53f5..55a8a5f 100644
--- a/app/modules/tgbot/routs/tgbot.php
+++ b/app/modules/tgbot/routs/tgbot.php
@@ -8,4 +8,6 @@ include KERNEL_APP_MODULES_DIR . "/tgbot/routs/tgbot.php";
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']);
});
\ 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 c3c76ed..868e618 100644
--- a/app/modules/tgbot/views/tgbot/layout/main.php
+++ b/app/modules/tgbot/views/tgbot/layout/main.php
@@ -41,10 +41,10 @@
diff --git a/app/modules/tgbot/views/tgbot/main/news.php b/app/modules/tgbot/views/tgbot/main/news.php
new file mode 100644
index 0000000..92ac9f9
--- /dev/null
+++ b/app/modules/tgbot/views/tgbot/main/news.php
@@ -0,0 +1,20 @@
+
+
+ getAdditionalPropertyByEntityId("post", $new['id'], 'photo');
+ ?>
+
+
+
+
+
+
= $new['title'] ?>
+
= $new['content'] ?>
+
+
+
\ No newline at end of file
diff --git a/bootstrap/secure.php b/bootstrap/secure.php
index b57765e..a8baf09 100644
--- a/bootstrap/secure.php
+++ b/bootstrap/secure.php
@@ -1,7 +1,7 @@
'login_password', // login_password, email_code
+ 'web_auth_type' => 'email_code', // login_password, email_code
'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT
'token_expired_time' => "+30 days", // +1 day
];
diff --git a/kernel/app_modules/card/CardModule.php b/kernel/app_modules/card/CardModule.php
index fbe306d..7535c73 100644
--- a/kernel/app_modules/card/CardModule.php
+++ b/kernel/app_modules/card/CardModule.php
@@ -50,6 +50,20 @@ class CardModule extends Module
"slug" => "card_template",
"parent_slug" => "card"
]);
+
+ $this->menuService->createItem([
+ "label" => "Программы",
+ "url" => "/admin/card_program",
+ "slug" => "card_program",
+ "parent_slug" => "card"
+ ]);
+
+ $this->menuService->createItem([
+ "label" => "Условия",
+ "url" => "/admin/card_program_conditions",
+ "slug" => "card_program_conditions",
+ "parent_slug" => "card"
+ ]);
}
/**
@@ -60,6 +74,8 @@ class CardModule extends Module
$this->menuService->removeItemBySlug("card");
$this->menuService->removeItemBySlug("card_list");
$this->menuService->removeItemBySlug("card_template");
+ $this->menuService->removeItemBySlug("card_program");
+ $this->menuService->removeItemBySlug("card_program_conditions");
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/card/migrations");
$this->consoleService->runComposerRemove("dragon-code/card-number");
$this->consoleService->runComposerRemove("endroid/qr-code");
diff --git a/kernel/app_modules/card/controllers/CardProgramConditionsController.php b/kernel/app_modules/card/controllers/CardProgramConditionsController.php
new file mode 100644
index 0000000..45c7e74
--- /dev/null
+++ b/kernel/app_modules/card/controllers/CardProgramConditionsController.php
@@ -0,0 +1,120 @@
+cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_program_conditions/";
+ $this->cardProgramConditionsService = new CardProgramConditionsService();
+ }
+
+ public function actionCreate(): void
+ {
+ $this->cgView->render("form.php");
+ }
+
+ #[NoReturn] public function actionAdd(): void
+ {
+ $cardForm = new CreateCardProgramConditionsForm();
+ $cardForm->load($_REQUEST);
+
+ if ($cardForm->validate()){
+ $cardProgramConditions = $this->cardProgramConditionsService->create($cardForm);
+ if ($cardProgramConditions){
+ Flash::setMessage("success", "Card program conditions created " . $cardProgramConditions->title);
+ $this->redirect("/admin/card_program_conditions/" . $cardProgramConditions->id);
+ }
+ }
+
+ Flash::setMessage("error", $cardForm->getErrorsStr());
+ $this->redirect("/admin/card_program_conditions/create");
+ }
+
+ public function actionIndex($page_number = 1): void
+ {
+ $this->cgView->render("index.php", ['page_number' => $page_number]);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function actionView($id): void
+ {
+ $card_program = CardProgramConditions::find($id);
+
+ if (!$card_program){
+ throw new Exception(message: "The card program conditions not found");
+ }
+ $this->cgView->render("view.php", ['card_program_conditions' => $card_program]);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function actionUpdate($id): void
+ {
+ $model = CardProgramConditions::find($id);
+ if (!$model){
+ throw new Exception(message: "The card program conditions not found");
+ }
+
+ $this->cgView->render("form.php", ['model' => $model]);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function actionEdit($id): void
+ {
+ $cardProgramConditions = CardProgramConditions::find($id);
+ if (!$cardProgramConditions){
+ throw new Exception(message: "The card program conditions not found");
+ }
+ $cardProgramConditionsForm = new CreateCardProgramConditionsForm();
+ $cardProgramConditionsForm->load($_REQUEST);
+
+ if ($cardProgramConditionsForm->validate()) {
+ $card = $this->cardProgramConditionsService->update($cardProgramConditionsForm, $cardProgramConditions);
+ if ($card) {
+ Flash::setMessage("success", "Card program updated " . $cardProgramConditions->title);
+ $this->redirect("/admin/card_program_conditions/" . $card->id);
+ }
+ }
+ Flash::setMessage("error", $cardProgramConditionsForm->getErrorsStr());
+
+ $this->redirect("/admin/card_program_conditions/update/" . $id);
+ }
+
+ #[NoReturn] public function actionDelete($id): void
+ {
+ $card_program = CardProgramConditions::where("id", $id)->first();
+ if (!$card_program){
+ Flash::setMessage("error", "Card program conditions not found");
+ }
+ else {
+ Flash::setMessage("success", "Card program conditions deleted");
+ $card_program->delete();
+ }
+
+ $this->redirect("/admin/card_program_conditions/");
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/controllers/CardProgramController.php b/kernel/app_modules/card/controllers/CardProgramController.php
new file mode 100644
index 0000000..e7f5e96
--- /dev/null
+++ b/kernel/app_modules/card/controllers/CardProgramController.php
@@ -0,0 +1,123 @@
+cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_program/";
+ $this->cardService = new CardService();
+ $this->cardProgramService = new CardProgramService();
+ }
+
+ public function actionCreate(): void
+ {
+ $this->cgView->render("form.php");
+ }
+
+ #[NoReturn] public function actionAdd(): void
+ {
+ $cardForm = new CreateCardProgramForm();
+ $cardForm->load($_REQUEST);
+
+ if ($cardForm->validate()){
+ $cardProgram = $this->cardProgramService->create($cardForm);
+ if ($cardProgram){
+ Flash::setMessage("success", "Card program creates " . $cardProgram->title);
+ $this->redirect("/admin/card_program/" . $cardProgram->id);
+ }
+ }
+
+ Flash::setMessage("error", $cardForm->getErrorsStr());
+ $this->redirect("/admin/card_program/create");
+ }
+
+ public function actionIndex($page_number = 1): void
+ {
+ $this->cgView->render("index.php", ['page_number' => $page_number]);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function actionView($id): void
+ {
+ $card_program = CardProgram::find($id);
+
+ if (!$card_program){
+ throw new Exception(message: "The card program not found");
+ }
+ $this->cgView->render("view.php", ['card_program' => $card_program]);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function actionUpdate($id): void
+ {
+ $model = CardProgram::find($id);
+ if (!$model){
+ throw new Exception(message: "The card program not found");
+ }
+
+ $this->cgView->render("form.php", ['model' => $model]);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function actionEdit($id): void
+ {
+ $cardProgram = CardProgram::find($id);
+ if (!$cardProgram){
+ throw new Exception(message: "The card not found");
+ }
+ $cardProgramForm = new CreateCardProgramForm();
+ $cardProgramForm->load($_REQUEST);
+
+ if ($cardProgramForm->validate()) {
+ $card = $this->cardProgramService->update($cardProgramForm, $cardProgram);
+ if ($card) {
+ Flash::setMessage("success", "Card program updated " . $cardProgram->title);
+ $this->redirect("/admin/card_program/" . $card->id);
+ }
+ }
+ Flash::setMessage("error", $cardProgramForm->getErrorsStr());
+
+ $this->redirect("/admin/card_program/update/" . $id);
+ }
+
+ #[NoReturn] public function actionDelete($id): void
+ {
+ $card_program = CardProgram::where("id", $id)->first();
+ if (!$card_program){
+ Flash::setMessage("error", "Card program not found");
+ }
+ else {
+ Flash::setMessage("success", "Card program deleted");
+ $card_program->delete();
+ }
+
+ $this->redirect("/admin/card_program/");
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/migrations/2024_12_23_171228_create_card_table.php b/kernel/app_modules/card/migrations/2024_12_23_171228_create_card_table.php
index a226858..a05bf1d 100644
--- a/kernel/app_modules/card/migrations/2024_12_23_171228_create_card_table.php
+++ b/kernel/app_modules/card/migrations/2024_12_23_171228_create_card_table.php
@@ -16,6 +16,7 @@ return new class extends Migration
$table->increments('id')->from(105545);
$table->string('path')->nullable(false);
$table->string('title')->nullable(false);
+ $table->text('settings')->nullable();
$table->integer('status')->default(1);
$table->timestamps();
@@ -30,6 +31,35 @@ return new class extends Migration
$table->timestamps();
});
+ \kernel\App::$db->schema->create('card_program', function (Blueprint $table) {
+ $table->increments('id')->from(71);
+ $table->string('slug')->nullable(false)->unique();
+ $table->string('title')->nullable(false);
+
+ $table->integer('status')->default(1);
+ $table->timestamps();
+ });
+
+ \kernel\App::$db->schema->create('card_program_conditions', function (Blueprint $table) {
+ $table->increments('id');
+ $table->integer("card_program_id")->nullable(false);
+ $table->string('slug')->nullable(false)->unique();
+ $table->string('title')->nullable(false);
+ $table->string('type')->nullable(false);
+ $table->string('value');
+
+ $table->integer('status')->default(1);
+ $table->timestamps();
+ });
+
+ \kernel\App::$db->schema->create('card_card_program', function (Blueprint $table) {
+ $table->increments('id');
+ $table->string('card_program_id')->nullable(false);
+ $table->string('card_id')->nullable(false);
+
+ $table->timestamps();
+ });
+
\kernel\App::$db->schema->create('card', function (Blueprint $table) {
$table->increments('id')->from(105545);
$table->integer('user_id')->nullable(false);
@@ -56,6 +86,9 @@ return new class extends Migration
{
\kernel\App::$db->schema->dropIfExists('card');
\kernel\App::$db->schema->dropIfExists('card_template');
+ \kernel\App::$db->schema->dropIfExists('card_card_program');
+ \kernel\App::$db->schema->dropIfExists('card_program_conditions');
+ \kernel\App::$db->schema->dropIfExists('card_program');
\kernel\App::$db->schema->dropIfExists('card_file');
}
};
diff --git a/kernel/app_modules/card/models/CardProgram.php b/kernel/app_modules/card/models/CardProgram.php
new file mode 100644
index 0000000..bd5472a
--- /dev/null
+++ b/kernel/app_modules/card/models/CardProgram.php
@@ -0,0 +1,51 @@
+ 'Заголовок',
+ // 'entity' => 'Сущность',
+ // 'slug' => 'Slug',
+ // 'status' => 'Статус',
+ // ]
+
+ return [
+ 'slug' => 'Slug',
+ 'title' => 'Название',
+ 'status' => 'Статус',
+ ];
+ }
+
+ /**
+ * @return string[]
+ */
+ public static function getStatus(): array
+ {
+ return [
+ self::DISABLE_STATUS => "Не активный",
+ self::ACTIVE_STATUS => "Активный",
+ ];
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/models/CardProgramConditions.php b/kernel/app_modules/card/models/CardProgramConditions.php
new file mode 100644
index 0000000..ac0173f
--- /dev/null
+++ b/kernel/app_modules/card/models/CardProgramConditions.php
@@ -0,0 +1,57 @@
+ 'Заголовок',
+ // 'entity' => 'Сущность',
+ // 'slug' => 'Slug',
+ // 'status' => 'Статус',
+ // ]
+
+ return [
+ 'card_program_id' => 'Программа',
+ 'slug' => 'Slug',
+ 'title' => 'Название',
+ 'value' => 'Условия',
+ 'type' => 'Тип',
+ 'status' => 'Статус',
+ ];
+ }
+
+ /**
+ * @return string[]
+ */
+ public static function getStatus(): array
+ {
+ return [
+ self::DISABLE_STATUS => "Не активный",
+ self::ACTIVE_STATUS => "Активный",
+ ];
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/models/CardTemplate.php b/kernel/app_modules/card/models/CardTemplate.php
index 3a8cb47..59b0193 100644
--- a/kernel/app_modules/card/models/CardTemplate.php
+++ b/kernel/app_modules/card/models/CardTemplate.php
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
/**
* @property string $path
* @property string $title
+ * @property string $settings
* @property int $status
*/
class CardTemplate extends Model
@@ -17,7 +18,7 @@ class CardTemplate extends Model
protected $table = 'card_template';
- protected $fillable = ['path', 'title', 'status'];
+ protected $fillable = ['path', 'title', 'status', 'settings'];
public static function labels(): array
{
@@ -32,6 +33,7 @@ class CardTemplate extends Model
return [
'path' => 'Шаблон',
'title' => 'Название',
+ 'settings' => 'Настройки',
'status' => 'Статус',
];
}
diff --git a/kernel/app_modules/card/models/forms/CreateCardProgramConditionsForm.php b/kernel/app_modules/card/models/forms/CreateCardProgramConditionsForm.php
new file mode 100644
index 0000000..ba0f88e
--- /dev/null
+++ b/kernel/app_modules/card/models/forms/CreateCardProgramConditionsForm.php
@@ -0,0 +1,30 @@
+ 'required|min-str-len:5|max-str-len:30',
+ // 'entity' => 'required',
+ // 'slug' => '',
+ // 'status' => ''
+ // ];
+ return [
+ 'card_program_id' => 'required|alpha-numeric',
+ 'slug' => 'required|min-str-len:4',
+ 'title' => 'required',
+ 'type' => 'required',
+ 'value' => '',
+ 'status' => ''
+ ];
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/models/forms/CreateCardProgramForm.php b/kernel/app_modules/card/models/forms/CreateCardProgramForm.php
new file mode 100644
index 0000000..a521e80
--- /dev/null
+++ b/kernel/app_modules/card/models/forms/CreateCardProgramForm.php
@@ -0,0 +1,27 @@
+ 'required|min-str-len:5|max-str-len:30',
+ // 'entity' => 'required',
+ // 'slug' => '',
+ // 'status' => ''
+ // ];
+ return [
+ 'slug' => 'required|min-str-len:4',
+ 'title' => 'required',
+ 'status' => ''
+ ];
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/models/forms/CreateCardTemplateForm.php b/kernel/app_modules/card/models/forms/CreateCardTemplateForm.php
index 02b9f58..ea80ccb 100644
--- a/kernel/app_modules/card/models/forms/CreateCardTemplateForm.php
+++ b/kernel/app_modules/card/models/forms/CreateCardTemplateForm.php
@@ -20,6 +20,7 @@ class CreateCardTemplateForm extends FormModel
return [
'path' => 'required|min-str-len:4',
'title' => 'required',
+ 'settings' => 'min-str-len:4',
'status' => ''
];
}
@@ -29,6 +30,7 @@ class CreateCardTemplateForm extends FormModel
return [
'path' => '',
'title' => 'required',
+ 'settings' => 'min-str-len:4',
'status' => ''
];
}
diff --git a/kernel/app_modules/card/routs/card.php b/kernel/app_modules/card/routs/card.php
index 96a39c4..800c48f 100644
--- a/kernel/app_modules/card/routs/card.php
+++ b/kernel/app_modules/card/routs/card.php
@@ -34,6 +34,36 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
});
});
+App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
+ App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
+ App::$collector->group(["prefix" => "card_program"], function (CGRouteCollector $router) {
+ App::$collector->get('/', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionIndex']);
+ App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionIndex']);
+ App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionCreate']);
+ App::$collector->post("/", [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionAdd']);
+ App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionView']);
+ App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionUpdate']);
+ App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionEdit']);
+ App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionDelete']);
+ });
+ });
+});
+
+App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
+ App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
+ App::$collector->group(["prefix" => "card_program_conditions"], function (CGRouteCollector $router) {
+ App::$collector->get('/', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionIndex']);
+ App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionIndex']);
+ App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionCreate']);
+ App::$collector->post("/", [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionAdd']);
+ App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionView']);
+ App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionUpdate']);
+ App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionEdit']);
+ App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionDelete']);
+ });
+ });
+});
+
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
App::$collector->group(['before' => 'bearer'], function (CgRouteCollector $router){
$router->rest("card", [\kernel\app_modules\card\controllers\CardRestController::class]);
diff --git a/kernel/app_modules/card/services/CardFileService.php b/kernel/app_modules/card/services/CardFileService.php
index f528c07..ddbb10d 100644
--- a/kernel/app_modules/card/services/CardFileService.php
+++ b/kernel/app_modules/card/services/CardFileService.php
@@ -8,6 +8,7 @@ use DragonCode\CardNumber\Formatters\BankFormatter;
use kernel\app_modules\card\models\Card;
use kernel\app_modules\card\models\CardFile;
use kernel\FormModel;
+use kernel\helpers\Debug;
use kernel\helpers\ImageGD;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
@@ -68,22 +69,45 @@ class CardFileService
umask($oldMask);
$uploadFileDir = ROOT_DIR . $uploadDirUri;
- $img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
- $font = RESOURCES_DIR . "/arialmt.ttf"; // Ссылка на шрифт
+ $cardSettings = json_decode($card->cardTemplate->settings ?? "", true);
- $qr = self::createQr($card->id);
+ $img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
+ $font = RESOURCES_DIR . "/Montserrat-SemiBold.ttf"; // Ссылка на шрифт
+
+ $qr = self::createQr($card->id, $cardSettings['qr_size'] ?? 131);
$qrImg = new ImageGD($qr->getDataUri());
$img = new ImageGD($img);
$pngFilePath = RESOURCES_DIR . "/tmp/" . $card->id . ".png";
$pngFileUrl = "/resources/tmp/" . $card->id . ".png";
- $img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
- $img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
- $img->addText(font_size: 14, degree: 0, x: 15, y: 65, color: "#000000", font: $font, text: $card->cardTemplate->title . " card");
- $img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
- $img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
- $img->addImg($qrImg->getImg(), 200, 15, 0, 0, 124, 124, 100);
+ $img->addText(
+ font_size: 20,
+ degree: 0,
+ x: 15,
+ y: 190,
+ color: $cardSettings['card_number_color'] ?? "#ffffff",
+ font: $font,
+ text: $cardNumber
+ );
+ $img->addText(
+ font_size: 12,
+ degree: 0,
+ x: 15,
+ y: 210,
+ color: $cardSettings['card_name_color'] ?? "#FEE62F",
+ font: $font,
+ text: $card->username
+ );
+ $img->addImg($qrImg->getImg(),
+ $cardSettings['qr_location_x'] ?? 190,
+ $cardSettings['qr_location_y'] ?? 20,
+ 0,
+ 0,
+ $cardSettings['qr_box_width'] ?? 135,
+ $cardSettings['qr_box_height'] ?? 135,
+ 100
+ );
$img->save($uploadFileDir . $newFileName);
return $uploadDirUri . $newFileName;
@@ -92,7 +116,7 @@ class CardFileService
return false;
}
- public static function createQr(string|int $text): \Endroid\QrCode\Writer\Result\ResultInterface
+ public static function createQr(string|int $text, int $size = 131): \Endroid\QrCode\Writer\Result\ResultInterface
{
$writer = new PngWriter();
@@ -100,7 +124,7 @@ class CardFileService
data: $text,
encoding: new Encoding('UTF-8'),
errorCorrectionLevel: ErrorCorrectionLevel::Low,
- size: 120,
+ size: $size,
margin: 2,
roundBlockSizeMode: RoundBlockSizeMode::Margin,
foregroundColor: new Color(0, 0, 0),
diff --git a/kernel/app_modules/card/services/CardProgramConditionsService.php b/kernel/app_modules/card/services/CardProgramConditionsService.php
new file mode 100644
index 0000000..2cff36f
--- /dev/null
+++ b/kernel/app_modules/card/services/CardProgramConditionsService.php
@@ -0,0 +1,48 @@
+card_program_id = $form_model->getItem('card_program_id');
+ $model->slug = $form_model->getItem('slug');
+ $model->status = $form_model->getItem('status');
+ $model->type = $form_model->getItem('type');
+ $model->title = $form_model->getItem('title');
+ $model->value = $form_model->getItem('value');
+ // $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
+
+ if ($model->save()) {
+ return $model;
+ }
+
+ return false;
+ }
+
+ public function update(FormModel $form_model, CardProgramConditions $cardProgramConditions): false|CardProgramConditions
+ {
+ // Пример обновления:
+ $cardProgramConditions->title = $form_model->getItem('title');
+ $cardProgramConditions->slug = $form_model->getItem('slug');
+ $cardProgramConditions->status = $form_model->getItem('status');
+ $cardProgramConditions->type = $form_model->getItem('type');
+ $cardProgramConditions->card_program_id = $form_model->getItem('card_program_id');
+ $cardProgramConditions->value = $form_model->getItem('value');
+
+ if ($cardProgramConditions->save()) {
+ return $cardProgramConditions;
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/services/CardProgramService.php b/kernel/app_modules/card/services/CardProgramService.php
new file mode 100644
index 0000000..e059a32
--- /dev/null
+++ b/kernel/app_modules/card/services/CardProgramService.php
@@ -0,0 +1,55 @@
+slug = $form_model->getItem('slug');
+ $model->status = $form_model->getItem('status');
+ $model->title = $form_model->getItem('title');
+ // $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
+
+ if ($model->save()) {
+ return $model;
+ }
+
+ return false;
+ }
+
+ public function update(FormModel $form_model, CardProgram $cardProgram): false|CardProgram
+ {
+ // Пример обновления:
+ $cardProgram->title = $form_model->getItem('title');
+ $cardProgram->slug = $form_model->getItem('slug');
+ $cardProgram->status = $form_model->getItem('status');
+
+ if ($cardProgram->save()) {
+ return $cardProgram;
+ }
+
+ return false;
+ }
+
+ public static function getProgramList(): array
+ {
+ $arr = [];
+ foreach (CardProgram::all()->toArray() as $cardTemplate){
+ $arr[$cardTemplate['id']] = $cardTemplate['title'];
+ }
+ if (!empty($arr)) {
+ return $arr;
+ }
+
+ return [];
+ }
+
+}
\ No newline at end of file
diff --git a/kernel/app_modules/card/services/CardService.php b/kernel/app_modules/card/services/CardService.php
index 0a613ec..96b54e1 100644
--- a/kernel/app_modules/card/services/CardService.php
+++ b/kernel/app_modules/card/services/CardService.php
@@ -97,8 +97,8 @@ class CardService
$img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
$img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
- $img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
- $img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
+ $img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#ffffff", font: $font, text: $cardNumber);
+ $img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#ffffff", font: $font, text: $card->username);
$img->save($pngFilePath);
return $pngFileUrl;
diff --git a/kernel/app_modules/card/services/CardTemplateService.php b/kernel/app_modules/card/services/CardTemplateService.php
index 88c71f6..b43946e 100644
--- a/kernel/app_modules/card/services/CardTemplateService.php
+++ b/kernel/app_modules/card/services/CardTemplateService.php
@@ -14,6 +14,7 @@ class CardTemplateService
$model = new CardTemplate();
// Пример заполнения:
$model->path = $form_model->getItem('path');
+ $model->settings = $form_model->getItem('settings');
$model->status = $form_model->getItem('status');
$model->title = $form_model->getItem('title');
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
@@ -29,6 +30,7 @@ class CardTemplateService
{
// Пример обновления:
$cardTemplate->title = $form_model->getItem('title');
+ $cardTemplate->settings = $form_model->getItem('settings');
$cardTemplate->path = $form_model->getItem('path') ?? $cardTemplate->path;
$cardTemplate->status = $form_model->getItem('status');
diff --git a/kernel/app_modules/card/views/card_program/form.php b/kernel/app_modules/card/views/card_program/form.php
new file mode 100644
index 0000000..acf0db1
--- /dev/null
+++ b/kernel/app_modules/card/views/card_program/form.php
@@ -0,0 +1,64 @@
+beginForm(isset($model) ? "/admin/card_program/edit/" . $model->id : "/admin/card_program", 'multipart/form-data');
+
+// Пример формы:
+
+
+$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
+ 'class' => "form-control",
+ 'placeholder' => 'Название',
+ 'value' => $model->title ?? ''
+])
+ ->setLabel("Заголовок")
+ ->render();
+
+$form->field(\itguild\forms\inputs\TextInput::class, 'slug', [
+ 'class' => "form-control",
+ 'placeholder' => 'Slug',
+ 'value' => $model->slug ?? ''
+])
+ ->setLabel("Slug")
+ ->render();
+
+
+$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
+ 'class' => "form-control",
+ 'value' => $model->status ?? ''
+])
+ ->setLabel("Статус")
+ ->setOptions(\kernel\app_modules\card\models\CardTemplate::getStatus())
+ ->render();
+
+
+?>
+
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
+ 'class' => "btn btn-primary ",
+ 'value' => 'Отправить',
+ 'typeInput' => 'submit'
+ ])
+ ->render();
+ ?>
+
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
+ 'class' => "btn btn-warning",
+ 'value' => 'Сбросить',
+ 'typeInput' => 'reset'
+ ])
+ ->render();
+ ?>
+
+
+endForm();
diff --git a/kernel/app_modules/card/views/card_program/index.php b/kernel/app_modules/card/views/card_program/index.php
new file mode 100644
index 0000000..a8e4d35
--- /dev/null
+++ b/kernel/app_modules/card/views/card_program/index.php
@@ -0,0 +1,77 @@
+setTitle("Список шаблонов card");
+$view->setMeta([
+ 'description' => 'Список шаблонов card системы'
+]);
+
+//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
+$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\card\models\CardProgram::class, [
+ 'currentPage' => $page_number,
+ 'perPage' => 8,
+ 'params' => ["class" => "table table-bordered", "border" => "2"],
+ 'baseUrl' => "/admin/card_program"
+]));
+
+
+//$table = new \Itguild\Tables\ListJsonTable(json_encode(
+// [
+// 'meta' => [
+// 'total' => 0,
+// 'totalWithFilters' => 0,
+// 'columns' => [
+// 'title',
+// 'slug',
+// 'status',
+// ],
+// 'perPage' => 5,
+// 'currentPage' => 1,
+// 'baseUrl' => '/admin/some',
+// 'params' => [
+// 'class' => 'table table-bordered',
+// 'border' => 2
+// ]
+// ],
+// 'filters' => [],
+// 'data' => [],
+// ]
+//));
+
+$table->beforePrint(function () {
+ return IconBtnCreateWidget::create(['url' => '/admin/card_program/create'])->run();
+});
+
+$table->columns([
+ 'status' => [
+ 'value' => function ($data) {
+ return \kernel\app_modules\card\models\CardProgram::getStatus()[$data];
+ }
+ ],
+
+]);
+
+$table->addAction(function($row) {
+ return IconBtnViewWidget::create(['url' => '/admin/card_program/' . $row['id']])->run();
+});
+$table->addAction(function($row) {
+ return IconBtnEditWidget::create(['url' => '/admin/card_program/update/' . $row['id']])->run();
+});
+$table->addAction(function($row) {
+ return IconBtnDeleteWidget::create(['url' => '/admin/card_program/delete/' . $row['id']])->run();
+});
+$table->create();
+$table->render();
\ No newline at end of file
diff --git a/kernel/app_modules/card/views/card_program/view.php b/kernel/app_modules/card/views/card_program/view.php
new file mode 100644
index 0000000..03638cd
--- /dev/null
+++ b/kernel/app_modules/card/views/card_program/view.php
@@ -0,0 +1,34 @@
+ ["class" => "table table-bordered", "border" => "2"],
+ 'baseUrl' => "/admin/card_program",
+]));
+
+$table->rows([
+ 'status' => [
+ 'value' => function ($data) {
+ return \kernel\app_modules\card\models\CardProgram::getStatus()[$data];
+ }
+ ]
+]);
+
+$table->beforePrint(function () use ($card_program) {
+ $btn = IconBtnListWidget::create(['url' => '/admin/card_program'])->run();
+ $btn .= IconBtnEditWidget::create(['url' => '/admin/card_program/update/' . $card_program->id])->run();
+ $btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_program/delete/' . $card_program->id])->run();
+ return $btn;
+});
+
+$table->create();
+$table->render();
\ No newline at end of file
diff --git a/kernel/app_modules/card/views/card_program_conditions/form.php b/kernel/app_modules/card/views/card_program_conditions/form.php
new file mode 100644
index 0000000..5783e18
--- /dev/null
+++ b/kernel/app_modules/card/views/card_program_conditions/form.php
@@ -0,0 +1,87 @@
+beginForm(isset($model) ? "/admin/card_program_conditions/edit/" . $model->id : "/admin/card_program_conditions", 'multipart/form-data');
+
+// Пример формы:
+
+
+$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
+ 'class' => "form-control",
+ 'placeholder' => 'Название',
+ 'value' => $model->title ?? ''
+])
+ ->setLabel("Заголовок")
+ ->render();
+
+$form->field(\itguild\forms\inputs\TextInput::class, 'slug', [
+ 'class' => "form-control",
+ 'placeholder' => 'Slug',
+ 'value' => $model->slug ?? ''
+])
+ ->setLabel("Slug")
+ ->render();
+
+$form->field(\itguild\forms\inputs\TextInput::class, 'type', [
+ 'class' => "form-control",
+ 'placeholder' => 'Тип',
+ 'value' => $model->type ?? ''
+])
+ ->setLabel("Тип")
+ ->render();
+
+$form->field(\itguild\forms\inputs\TextInput::class, 'value', [
+ 'class' => "form-control",
+ 'placeholder' => 'Значение',
+ 'value' => $model->value ?? ''
+])
+ ->setLabel("Значение")
+ ->render();
+
+$form->field(class: \itguild\forms\inputs\Select::class, name: "card_program_id", params: [
+ 'class' => "form-control",
+ 'value' => $model->card_program_id ?? ''
+])
+ ->setLabel("Программа")
+ ->setOptions(\kernel\app_modules\card\services\CardProgramService::getProgramList())
+ ->render();
+
+$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
+ 'class' => "form-control",
+ 'value' => $model->status ?? ''
+])
+ ->setLabel("Статус")
+ ->setOptions(\kernel\app_modules\card\models\CardTemplate::getStatus())
+ ->render();
+
+
+?>
+
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
+ 'class' => "btn btn-primary ",
+ 'value' => 'Отправить',
+ 'typeInput' => 'submit'
+ ])
+ ->render();
+ ?>
+
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
+ 'class' => "btn btn-warning",
+ 'value' => 'Сбросить',
+ 'typeInput' => 'reset'
+ ])
+ ->render();
+ ?>
+
+
+endForm();
diff --git a/kernel/app_modules/card/views/card_program_conditions/index.php b/kernel/app_modules/card/views/card_program_conditions/index.php
new file mode 100644
index 0000000..864aa54
--- /dev/null
+++ b/kernel/app_modules/card/views/card_program_conditions/index.php
@@ -0,0 +1,77 @@
+setTitle("Список условий");
+$view->setMeta([
+ 'description' => 'Список условий системы'
+]);
+
+//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
+$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\card\models\CardProgramConditions::class, [
+ 'currentPage' => $page_number,
+ 'perPage' => 8,
+ 'params' => ["class" => "table table-bordered", "border" => "2"],
+ 'baseUrl' => "/admin/card_program_conditions"
+]));
+
+
+//$table = new \Itguild\Tables\ListJsonTable(json_encode(
+// [
+// 'meta' => [
+// 'total' => 0,
+// 'totalWithFilters' => 0,
+// 'columns' => [
+// 'title',
+// 'slug',
+// 'status',
+// ],
+// 'perPage' => 5,
+// 'currentPage' => 1,
+// 'baseUrl' => '/admin/some',
+// 'params' => [
+// 'class' => 'table table-bordered',
+// 'border' => 2
+// ]
+// ],
+// 'filters' => [],
+// 'data' => [],
+// ]
+//));
+
+$table->beforePrint(function () {
+ return IconBtnCreateWidget::create(['url' => '/admin/card_program_conditions/create'])->run();
+});
+
+$table->columns([
+ 'status' => [
+ 'value' => function ($data) {
+ return \kernel\app_modules\card\models\CardProgramConditions::getStatus()[$data];
+ }
+ ],
+
+]);
+
+$table->addAction(function($row) {
+ return IconBtnViewWidget::create(['url' => '/admin/card_program_conditions/' . $row['id']])->run();
+});
+$table->addAction(function($row) {
+ return IconBtnEditWidget::create(['url' => '/admin/card_program_conditions/update/' . $row['id']])->run();
+});
+$table->addAction(function($row) {
+ return IconBtnDeleteWidget::create(['url' => '/admin/card_program_conditions/delete/' . $row['id']])->run();
+});
+$table->create();
+$table->render();
\ No newline at end of file
diff --git a/kernel/app_modules/card/views/card_program_conditions/view.php b/kernel/app_modules/card/views/card_program_conditions/view.php
new file mode 100644
index 0000000..dcdb859
--- /dev/null
+++ b/kernel/app_modules/card/views/card_program_conditions/view.php
@@ -0,0 +1,34 @@
+ ["class" => "table table-bordered", "border" => "2"],
+ 'baseUrl' => "/admin/card_program_conditions",
+]));
+
+$table->rows([
+ 'status' => [
+ 'value' => function ($data) {
+ return \kernel\app_modules\card\models\CardProgramConditions::getStatus()[$data];
+ }
+ ]
+]);
+
+$table->beforePrint(function () use ($card_program_conditions) {
+ $btn = IconBtnListWidget::create(['url' => '/admin/card_program_conditions'])->run();
+ $btn .= IconBtnEditWidget::create(['url' => '/admin/card_program_conditions/update/' . $card_program_conditions->id])->run();
+ $btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_program_conditions/delete/' . $card_program_conditions->id])->run();
+ return $btn;
+});
+
+$table->create();
+$table->render();
\ No newline at end of file
diff --git a/kernel/app_modules/card/views/card_template/form.php b/kernel/app_modules/card/views/card_template/form.php
index fffb840..69dc53c 100644
--- a/kernel/app_modules/card/views/card_template/form.php
+++ b/kernel/app_modules/card/views/card_template/form.php
@@ -19,6 +19,14 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'title', [
->setLabel("Заголовок")
->render();
+$form->field(\itguild\forms\inputs\TextInput::class, 'settings', [
+ 'class' => "form-control",
+ 'placeholder' => 'Настройки',
+ 'value' => $model->settings ?? ''
+])
+ ->setLabel("Настройки")
+ ->render();
+
$form->field(\itguild\forms\inputs\File::class, 'path', [
'class' => "form-control",
'placeholder' => 'Путь к файлу',
diff --git a/kernel/app_modules/card/views/form.php b/kernel/app_modules/card/views/form.php
index ba6c749..fcfb6b1 100644
--- a/kernel/app_modules/card/views/form.php
+++ b/kernel/app_modules/card/views/form.php
@@ -58,12 +58,12 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'info', [
->setLabel("Информация")
->render();
-$form->field(\itguild\forms\inputs\TextInput::class, 'program', [
+$form->field(class: \itguild\forms\inputs\Select::class, name: "program", params: [
'class' => "form-control",
- 'placeholder' => 'Программа',
'value' => $model->program ?? ''
])
->setLabel("Программа")
+ ->setOptions(\kernel\app_modules\card\services\CardProgramService::getProgramList())
->render();
$form->field(\itguild\forms\inputs\TextInput::class, 'cvc', [
diff --git a/kernel/app_modules/card/views/view.php b/kernel/app_modules/card/views/view.php
index 7ebfc9e..46d3c4b 100644
--- a/kernel/app_modules/card/views/view.php
+++ b/kernel/app_modules/card/views/view.php
@@ -39,6 +39,8 @@ $table->rows([
$table->create();
$table->render();
+echo \kernel\helpers\Html::img(\kernel\app_modules\card\services\CardFileService::createCardPNG($card));
+
//$writer = new PngWriter();
//
//// Create QR code
diff --git a/kernel/app_modules/tag/service/TagService.php b/kernel/app_modules/tag/service/TagService.php
index 1a69ba6..d4eb6b1 100755
--- a/kernel/app_modules/tag/service/TagService.php
+++ b/kernel/app_modules/tag/service/TagService.php
@@ -2,7 +2,9 @@
namespace kernel\app_modules\tag\service;
+use Illuminate\Database\Eloquent\Model;
use kernel\app_modules\tag\models\Tag;
+use kernel\app_modules\tag\models\TagEntity;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
@@ -40,4 +42,19 @@ class TagService
return false;
}
+
+ public static function getEntityByTagId(int $tagId, $model)
+ {
+ $tagEntity = TagEntity::where("tag_id", $tagId)->get();
+ if ($tagEntity){
+ $entityIdArr = [];
+ foreach ($tagEntity as $item){
+ $entityIdArr[] = $item['entity_id'];
+ }
+ }
+ $queryBuilder = $model::query();
+
+ return $queryBuilder->whereIn("id", $entityIdArr)->get();
+ }
+
}
\ No newline at end of file
diff --git a/kernel/app_modules/tgbot/routs/tgbot.php b/kernel/app_modules/tgbot/routs/tgbot.php
index 30f8959..31af746 100644
--- a/kernel/app_modules/tgbot/routs/tgbot.php
+++ b/kernel/app_modules/tgbot/routs/tgbot.php
@@ -17,10 +17,6 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
App::$collector->any("/edit/{id}", [\app\modules\tgbot\controllers\TgbotController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionDelete']);
});
- App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
- App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
- App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
- });
});
});
diff --git a/kernel/helpers/ImageGD.php b/kernel/helpers/ImageGD.php
index 3b15b05..2178786 100644
--- a/kernel/helpers/ImageGD.php
+++ b/kernel/helpers/ImageGD.php
@@ -40,9 +40,43 @@ class ImageGD
imagedestroy($this->img);
}
+ public function makeCornersForImage($radius, $background): void
+ {
+ // включаем режим сопряжения цветов
+ imagealphablending($this->img, true);
+ // размер исходной картинки
+ $width = imagesx($this->img);
+ $height = imagesy($this->img);
+ // создаем изображение для углов
+ $corner = imagecreatetruecolor($radius, $radius);
+ imagealphablending($corner, false);
+ // прозрачный цвет
+ $trans = imagecolorallocatealpha($corner, 255, 255, 255, 127);
+ // заливаем картинку для углов
+ imagefill($corner, 0, 0, $background);
+ // рисуем прозрачный эллипс
+ imagefilledellipse($corner, $radius, $radius, $radius * 2, $radius * 2, $trans);
+ // массив положений. Для расположения по углам
+ $positions = array(
+ array(0, 0),
+ array($width - $radius, 0),
+ array($width - $radius, $height - $radius),
+ array(0, $height - $radius),
+ );
+ // накладываем на углы картинки изображение с прозрачными эллипсами
+ foreach ($positions as $pos) {
+ imagecopyresampled($this->img, $corner, $pos[0], $pos[1], 0, 0, $radius, $radius, $radius, $radius);
+ // поворачиваем картинку с эллипсов каждый раз на 90 градусов
+ $corner = imagerotate($corner, -90, $background);
+ }
+
+ }
+
protected function hexToRgb(string $hex)
{
return sscanf($hex, "#%02x%02x%02x");
}
+
+
}
\ No newline at end of file
diff --git a/kernel/manifest.json b/kernel/manifest.json
index e19c591..bc1217e 100644
--- a/kernel/manifest.json
+++ b/kernel/manifest.json
@@ -1,6 +1,6 @@
{
"name": "Kernel",
- "version": "0.1.2",
+ "version": "0.1.3",
"author": "ITGuild",
"slug": "kernel",
"type": "kernel",
diff --git a/kernel/modules/secure/services/SecureService.php b/kernel/modules/secure/services/SecureService.php
index b47f4d4..1699b6a 100644
--- a/kernel/modules/secure/services/SecureService.php
+++ b/kernel/modules/secure/services/SecureService.php
@@ -13,21 +13,28 @@ use kernel\services\TokenService;
class SecureService
{
- public static function createSecretCode(User $user): void
+ public static function createSecretCode(User $user): SecretCode
{
$secretCode = new SecretCode();
$secretCode->user_id = $user->id;
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
+
+ return $secretCode;
}
- public static function updateSecretCode(User $user): void
+ public static function updateSecretCode(User $user): SecretCode
{
$secretCode = SecretCode::where('user_id', $user->id)->first();
+ if(!$secretCode){
+ return self::createSecretCode($user);
+ }
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
+
+ return $secretCode;
}
public static function getCodeByUserId(int $user_id)
diff --git a/resources/Montserrat-Medium.ttf b/resources/Montserrat-Medium.ttf
new file mode 100644
index 0000000..db5b1af
Binary files /dev/null and b/resources/Montserrat-Medium.ttf differ
diff --git a/resources/Montserrat-SemiBold.ttf b/resources/Montserrat-SemiBold.ttf
new file mode 100644
index 0000000..0ecc667
Binary files /dev/null and b/resources/Montserrat-SemiBold.ttf differ
diff --git a/resources/main/js/tg.js b/resources/main/js/tg.js
index 9db6bd0..3c779f4 100644
--- a/resources/main/js/tg.js
+++ b/resources/main/js/tg.js
@@ -1,7 +1,18 @@
import {TgApp} from "./tg_app/TgApp.js";
+import Router from "./tg_app/Router.js";
document.addEventListener("DOMContentLoaded", () => {
let tg = window.Telegram.WebApp;
let tgApp = new TgApp("tg_app", tg.initDataUnsafe.user.id);
+ const router = new Router({
+ mode: 'hash',
+ root: '/miniapp'
+ });
+
+ router
+ .add('', () => {
+ tgApp.actionMain();
+ });
+
});
\ No newline at end of file
diff --git a/resources/main/js/tg_app/Router.js b/resources/main/js/tg_app/Router.js
new file mode 100644
index 0000000..26b0666
--- /dev/null
+++ b/resources/main/js/tg_app/Router.js
@@ -0,0 +1,84 @@
+class Router {
+ routes = [];
+
+ mode = null;
+
+ root = '/';
+
+ constructor(options) {
+ this.mode = window.history.pushState ? 'history' : 'hash';
+ if (options.mode) this.mode = options.mode;
+ if (options.root) this.root = options.root;
+ this.listen();
+ }
+
+ add = (path, cb) => {
+ this.routes.push({ path, cb });
+ return this;
+ };
+
+ remove = path => {
+ for (let i = 0; i < this.routes.length; i += 1) {
+ if (this.routes[i].path === path) {
+ this.routes.slice(i, 1);
+ return this;
+ }
+ }
+ return this;
+ };
+
+ flush = () => {
+ this.routes = [];
+ return this;
+ };
+
+ clearSlashes = path =>
+ path
+ .toString()
+ .replace(/\/$/, '')
+ .replace(/^\//, '');
+
+ getFragment = () => {
+ let fragment = '';
+ if (this.mode === 'history') {
+ fragment = this.clearSlashes(decodeURI(window.location.pathname + window.location.search));
+ fragment = fragment.replace(/\?(.*)$/, '');
+ fragment = this.root !== '/' ? fragment.replace(this.root, '') : fragment;
+ } else {
+ const match = window.location.href.match(/#(.*)$/);
+ fragment = match ? match[1] : '';
+ }
+ return this.clearSlashes(fragment);
+ };
+
+ navigate = (path = '') => {
+ if (this.mode === 'history') {
+ window.history.pushState(null, null, this.root + this.clearSlashes(path));
+ } else {
+ window.location.href = `${window.location.href.replace(/#(.*)$/, '')}#${path}`;
+ }
+ return this;
+ };
+
+ listen = () => {
+ clearInterval(this.interval);
+ this.interval = setInterval(this.interval, 50);
+ };
+
+ interval = () => {
+ if (this.current === this.getFragment()) return;
+ this.current = this.getFragment();
+
+ this.routes.some(route => {
+ const match = this.current.match(route.path);
+ if (match) {
+ match.shift();
+ route.cb.apply({}, match);
+ return match;
+ }
+ return false;
+ });
+ };
+}
+
+export default Router;
\ No newline at end of file
diff --git a/resources/main/js/tg_app/TgApp.js b/resources/main/js/tg_app/TgApp.js
index 22daa15..a6c993c 100644
--- a/resources/main/js/tg_app/TgApp.js
+++ b/resources/main/js/tg_app/TgApp.js
@@ -3,13 +3,17 @@ import config from "./config_local.js";
class TgApp {
constructor(containerId, userId) {
this.container = document.getElementById(containerId);
+ this.userId = userId;
+ }
+
+ actionMain(){
+ console.log("main 123")
this.createCardBox();
this.createDefaultBox();
- this.userId = userId;
this.getCard();
}
- setUserId(userId){
+ setUserId(userId) {
this.userId = userId;
}
@@ -31,7 +35,7 @@ class TgApp {
this.container.appendChild(this.defaultBox);
}
- getCard(){
+ getCard() {
let botId = config.config.botId;
fetch(config.config.apiUrl + `api/tg-bot/get-card-by-dialog/${this.userId}/${botId}`, {
method: 'GET', // Здесь так же могут быть GET, PUT, DELETE
@@ -47,6 +51,15 @@ class TgApp {
})
}
+ getAction(action){
+ if (action === "actionMain"){
+ return this.actionMain;
+ }
+
+ return false;
+ }
+
+
}
const templates =
@@ -68,7 +81,7 @@ const templates =
return `
-
Баланс: ${balance}
+ Баланс: ${balance}
`;
}