55 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace kernel\app_modules\tgbot;
 | |
| 
 | |
| use kernel\Module;
 | |
| use kernel\modules\menu\service\MenuService;
 | |
| use kernel\services\MigrationService;
 | |
| 
 | |
| class TgbotModule extends Module
 | |
| {
 | |
|     public MenuService $menuService;
 | |
|     public MigrationService $migrationService;
 | |
| 
 | |
|     public function __construct()
 | |
|     {
 | |
|         $this->menuService = new MenuService();
 | |
|         $this->migrationService = new MigrationService();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @throws \Exception
 | |
|      */
 | |
|     public function init(): void
 | |
|     {
 | |
|         $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tgbot/migrations");
 | |
| 
 | |
|         $this->menuService->createItem([
 | |
|             "label" => "TG bot",
 | |
|             "url" => "/admin/tg-bot",
 | |
|             "slug" => "tg-bot",
 | |
|         ]);
 | |
| 
 | |
|         $this->menuService->createItem([
 | |
|             "label" => "Диалоги",
 | |
|             "url" => "/admin/tg-bot",
 | |
|             "slug" => "tg-bot-dialogs",
 | |
|             "parent_slug" => "tg-bot",
 | |
|         ]);
 | |
| 
 | |
|         $this->menuService->createItem([
 | |
|             "label" => "Уведомления",
 | |
|             "url" => "/admin/tg-bot-notification",
 | |
|             "slug" => "tg-bot-notification",
 | |
|             "parent_slug" => "tg-bot",
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function deactivate()
 | |
|     {
 | |
|         $this->menuService->removeItemBySlug("tg-bot");
 | |
|         $this->menuService->removeItemBySlug("tg-bot-dialogs");
 | |
|         $this->menuService->removeItemBySlug("tg-bot-notification");
 | |
|         $this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tgbot/migrations");
 | |
|     }
 | |
| } |