app module
This commit is contained in:
		| @@ -4,14 +4,17 @@ namespace app\modules\tag; | ||||
|  | ||||
| use kernel\Module; | ||||
| use kernel\modules\menu\service\MenuService; | ||||
| use kernel\services\MigrationService; | ||||
|  | ||||
| class TagModule extends Module | ||||
| { | ||||
|  | ||||
|     public MenuService $menuService; | ||||
|     public MigrationService $migrationService; | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->menuService = new MenuService(); | ||||
|         $this->migrationService = new MigrationService(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -19,6 +22,8 @@ class TagModule extends Module | ||||
|      */ | ||||
|     public function init(): void | ||||
|     { | ||||
|         $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); | ||||
|  | ||||
|         $this->menuService->createItem([ | ||||
|             "label" => "Тэги", | ||||
|             "url" => "/admin/tag", | ||||
|   | ||||
							
								
								
									
										8
									
								
								app/modules/tag/controllers/TagController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/modules/tag/controllers/TagController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace app\modules\tag\controllers; | ||||
|  | ||||
| class TagController extends \kernel\app_modules\tag\controllers\TagController | ||||
| { | ||||
|  | ||||
| } | ||||
| @@ -6,5 +6,6 @@ | ||||
|   "description": "Tags module", | ||||
|   "module_path": "{APP}/modules/{slug}", | ||||
|   "module_class": "app\\modules\\tag\\TagModule", | ||||
|   "module_class_file": "{APP}/modules/tag/TagModule.php" | ||||
|   "module_class_file": "{APP}/modules/tag/TagModule.php", | ||||
|   "routs": "routs/tag.php" | ||||
| } | ||||
							
								
								
									
										2
									
								
								app/modules/tag/routs/tag.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/modules/tag/routs/tag.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| <?php | ||||
| include KERNEL_APP_MODULES_DIR . "/tag/routs/tag.php"; | ||||
| @@ -13,6 +13,8 @@ const KERNEL_ADMIN_THEMES_DIR = __DIR__ . "/kernel/admin_themes"; | ||||
| const CONSOLE_DIR = __DIR__ . "/kernel/console"; | ||||
| const RESOURCES_DIR = __DIR__ . "/resources"; | ||||
|  | ||||
| const KERNEL_APP_MODULES_DIR = KERNEL_DIR . "/app_modules"; | ||||
|  | ||||
| const APP_DIR = ROOT_DIR . "/app"; | ||||
|  | ||||
|  | ||||
| @@ -25,6 +27,7 @@ function getConst($text): array|false|string | ||||
|         "{KERNEL_ADMIN_THEMES}" => KERNEL_ADMIN_THEMES_DIR, | ||||
|         "{KERNEL}" => KERNEL_DIR, | ||||
|         "{KERNEL_MODULES}" => KERNEL_MODULES_DIR, | ||||
|         "{KERNEL_APP_MODULES}" => KERNEL_APP_MODULES_DIR, | ||||
|         "{CONSOLE}" => CONSOLE_DIR, | ||||
|         "{APP}" => APP_DIR, | ||||
|     ]; | ||||
|   | ||||
							
								
								
									
										16
									
								
								kernel/IGTabel/action_column/ViewActionColumn.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								kernel/IGTabel/action_column/ViewActionColumn.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\IGTabel\action_column; | ||||
|  | ||||
| use Itguild\Tables\ActionColumn\ActionColumn; | ||||
|  | ||||
| class ViewActionColumn extends ActionColumn | ||||
| { | ||||
|     protected string $prefix = '/'; | ||||
|  | ||||
|     public function fetch(): string | ||||
|     { | ||||
|         $link = $this->baseUrl . $this->prefix . $this->id; | ||||
|         return " <a href='$link' class='btn btn-primary'>Просмотр</a> "; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										21
									
								
								kernel/app_modules/tag/controllers/TagController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								kernel/app_modules/tag/controllers/TagController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\app_modules\tag\controllers; | ||||
|  | ||||
| use kernel\AdminController; | ||||
| use kernel\modules\menu\service\MenuService; | ||||
|  | ||||
| class TagController extends AdminController | ||||
| { | ||||
|     protected function init(): void | ||||
|     { | ||||
|         parent::init(); | ||||
|         $this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/";; | ||||
|     } | ||||
|  | ||||
|     public function actionIndex($page_number = 1): void | ||||
|     { | ||||
|         $this->cgView->render("index.php", ['page_number' => $page_number]); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,31 @@ | ||||
| <?php | ||||
|  | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
|  | ||||
| return new class extends Migration | ||||
| { | ||||
|     /** | ||||
|      * Run the migrations. | ||||
|      */ | ||||
|     public function up(): void | ||||
|     { | ||||
|         \kernel\App::$db->schema->create('tag', function (Blueprint $table) { | ||||
|             $table->increments('id'); | ||||
|             $table->string('label', 255)->nullable(false); | ||||
|             $table->string('entity', 255)->nullable(false); | ||||
|             $table->string('slug', 255)->unique(); | ||||
|             $table->integer('status')->default(1); | ||||
|             $table->timestamps(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Reverse the migrations. | ||||
|      */ | ||||
|     public function down(): void | ||||
|     { | ||||
|         \kernel\App::$db->schema->dropIfExists('tag'); | ||||
|     } | ||||
| }; | ||||
							
								
								
									
										37
									
								
								kernel/app_modules/tag/models/Tag.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								kernel/app_modules/tag/models/Tag.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\app_modules\tag\models; | ||||
|  | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
|  | ||||
| class Tag extends Model | ||||
| { | ||||
|     const DISABLE_STATUS = 0; | ||||
|     const ACTIVE_STATUS = 1; | ||||
|  | ||||
|     protected $table = 'tag'; | ||||
|  | ||||
|     protected $fillable = ['label', 'entity', 'slug', 'status']; | ||||
|  | ||||
|     public static function labels(): array | ||||
|     { | ||||
|         return [ | ||||
|             'label' => 'Заголовок', | ||||
|             'entity' => 'Сущность', | ||||
|             'slug' => 'Slug', | ||||
|             'status' => 'Статус', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public static function getStatus(): array | ||||
|     { | ||||
|         return [ | ||||
|             self::DISABLE_STATUS => "Не активный", | ||||
|             self::ACTIVE_STATUS => "Активный", | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										18
									
								
								kernel/app_modules/tag/routs/tag.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								kernel/app_modules/tag/routs/tag.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| <?php | ||||
|  | ||||
| use kernel\App; | ||||
| use kernel\CgRouteCollector; | ||||
| use Phroute\Phroute\RouteCollector; | ||||
|  | ||||
| App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) { | ||||
|     App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ | ||||
|         App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); | ||||
| //        App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']); | ||||
| //        App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); | ||||
| //        App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); | ||||
| //        App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); | ||||
| //        App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); | ||||
| //        App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); | ||||
| //        App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); | ||||
|     }); | ||||
| }); | ||||
							
								
								
									
										31
									
								
								kernel/app_modules/tag/views/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								kernel/app_modules/tag/views/index.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @var \Illuminate\Database\Eloquent\Collection $menuItem | ||||
|  * @var int $page_number | ||||
|  */ | ||||
|  | ||||
| use Itguild\EloquentTable\EloquentDataProvider; | ||||
| use Itguild\EloquentTable\ListEloquentTable; | ||||
| use kernel\app_modules\tag\models\Tag; | ||||
| use kernel\IGTabel\btn\PrimaryBtn; | ||||
| use kernel\models\Menu; | ||||
| use kernel\modules\menu\table\columns\MenuDeleteActionColumn; | ||||
| use kernel\modules\menu\table\columns\MenuEditActionColumn; | ||||
| use kernel\modules\menu\table\columns\MenuViewActionColumn; | ||||
|  | ||||
| $table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [ | ||||
|     'currentPage' => $page_number, | ||||
|     'perPage' => 8, | ||||
|     'params' => ["class" => "table table-bordered", "border" => "2"], | ||||
|     'baseUrl' => "/admin/tag", | ||||
| ])); | ||||
|  | ||||
| $table->beforePrint(function () { | ||||
|     return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); | ||||
|     //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); | ||||
| }); | ||||
| $table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); | ||||
| //$table->addAction(MenuEditActionColumn::class); | ||||
| //$table->addAction(MenuDeleteActionColumn::class); | ||||
| $table->create(); | ||||
| $table->render(); | ||||
| @@ -6,6 +6,7 @@ use Illuminate\Database\Migrations\DatabaseMigrationRepository; | ||||
| use Illuminate\Database\Migrations\Migrator; | ||||
| use Illuminate\Filesystem\Filesystem; | ||||
| use kernel\App; | ||||
| use kernel\helpers\Debug; | ||||
|  | ||||
| class MigrationService | ||||
| { | ||||
| @@ -21,6 +22,8 @@ class MigrationService | ||||
|      */ | ||||
|     public function runAtPath(string $path = ROOT_DIR . '/migrations'): array | ||||
|     { | ||||
|         $path = getConst($path); | ||||
|  | ||||
|         try { | ||||
|             $dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration'); | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,31 @@ | ||||
| <?php | ||||
|  | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
|  | ||||
| return new class extends Migration | ||||
| { | ||||
|     /** | ||||
|      * Run the migrations. | ||||
|      */ | ||||
|     public function up(): void | ||||
|     { | ||||
|         \kernel\App::$db->schema->create('tag', function (Blueprint $table) { | ||||
|             $table->increments('id'); | ||||
|             $table->string('label', 255)->nullable(false); | ||||
|             $table->string('entity', 255)->nullable(false); | ||||
|             $table->string('slug', 255)->unique(); | ||||
|             $table->integer('status')->default(1); | ||||
|             $table->timestamps(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Reverse the migrations. | ||||
|      */ | ||||
|     public function down(): void | ||||
|     { | ||||
|         \kernel\App::$db->schema->dropIfExists('tag'); | ||||
|     } | ||||
| }; | ||||
							
								
								
									
										37
									
								
								resources/tmp/modules/tag/kernel/models/Tag.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								resources/tmp/modules/tag/kernel/models/Tag.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| namespace models; | ||||
|  | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
|  | ||||
| class Tag extends Model | ||||
| { | ||||
|     const DISABLE_STATUS = 0; | ||||
|     const ACTIVE_STATUS = 1; | ||||
|  | ||||
|     protected $table = 'tag'; | ||||
|  | ||||
|     protected $fillable = ['label', 'entity', 'slug', 'status']; | ||||
|  | ||||
|     public static function labels(): array | ||||
|     { | ||||
|         return [ | ||||
|             'label' => 'Заголовок', | ||||
|             'entity' => 'Сущность', | ||||
|             'slug' => 'Slug', | ||||
|             'status' => 'Статус', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public static function getStatus(): array | ||||
|     { | ||||
|         return [ | ||||
|             self::DISABLE_STATUS => "Не активный", | ||||
|             self::ACTIVE_STATUS => "Активный", | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user