72 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace kernel\modules\module_shop_client\controllers;
 | |
| 
 | |
| use GuzzleHttp\Client;
 | |
| use kernel\AdminController;
 | |
| use kernel\helpers\Debug;
 | |
| use kernel\modules\module_shop_client\services\ModuleShopClientService;
 | |
| use kernel\services\ModuleService;
 | |
| 
 | |
| class ModuleShopClientController extends AdminController
 | |
| {
 | |
| 
 | |
|     protected Client $client;
 | |
|     protected ModuleService $moduleService;
 | |
| 
 | |
|     protected function init(): void
 | |
|     {
 | |
|         parent::init();
 | |
|         $this->cgView->viewPath = KERNEL_MODULES_DIR . "/module_shop_client/views/";
 | |
| 
 | |
|         $this->client = new Client();
 | |
|         $this->moduleService = new ModuleService();
 | |
|     }
 | |
|     public function actionIndex(int $page_number = 1): void
 | |
|     {
 | |
|         $per_page = 8;
 | |
| 
 | |
|         $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.W10.POQZmGB7EZIayINtYhzu5r1rdgZhF9qPJpaQkl_g6pU';
 | |
|         $modules_info = $this->client->request('GET', 'http://igfs.loc/api/module_shop/gb_slug', [
 | |
|             'headers' => [
 | |
|                 'Authorization' => 'Bearer ' . $token,
 | |
|             ]
 | |
|         ]);
 | |
|         $modules_info = json_decode($modules_info->getBody()->getContents(), true);
 | |
|         $module_count = count($modules_info);
 | |
|         $modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page);
 | |
|         $this->cgView->render("index.php", [
 | |
|             'modules_info' => $modules_info,
 | |
|             'page_number' => $page_number,
 | |
|             'module_count' => $module_count,
 | |
|             'per_page' => $per_page,
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function actionView(int $id): void
 | |
|     {
 | |
|         $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.W10.POQZmGB7EZIayINtYhzu5r1rdgZhF9qPJpaQkl_g6pU';
 | |
|         $module_info = $this->client->request('GET', 'http://igfs.loc/api/module_shop/' . $id, [
 | |
|             'headers' => [
 | |
|                 'Authorization' => 'Bearer ' . $token,
 | |
|             ]
 | |
|         ]);
 | |
|         $module_info = json_decode($module_info->getBody()->getContents(), true);
 | |
|         $this->cgView->render("view.php", ['data' => $module_info]);
 | |
|     }
 | |
| 
 | |
|     public function actionInstall(int $id): void
 | |
|     {
 | |
|         $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.W10.POQZmGB7EZIayINtYhzu5r1rdgZhF9qPJpaQkl_g6pU';
 | |
|         $module_info = $this->client->request('GET', 'http://igfs.loc/api/module_shop/' . $id, [
 | |
|             'headers' => [
 | |
|                 'Authorization' => 'Bearer ' . $token,
 | |
|             ]
 | |
|         ]);
 | |
|         $module_info = json_decode($module_info->getBody()->getContents(), true);
 | |
|         Debug::dd($module_info['path_to_archive']);
 | |
|         $this->moduleService->installModule($module_info['path_to_archive']);
 | |
| 
 | |
|     }
 | |
| 
 | |
| } |