From 5b4676a4c08f5ad13ca1ab822518514e69dfa3a8 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Fri, 30 Aug 2024 12:27:46 +0300 Subject: [PATCH] widgets, widget menu --- kernel/Widget.php | 34 +++++++++++++++ kernel/models/Menu.php | 35 ++++++++++++++++ kernel/widgets/MenuWidget.php | 17 ++++++++ .../2024_08_30_083939_create_menu_table.php | 34 +++++++++++++++ views/admin/layouts/main.php | 41 +------------------ views/widgets/admin/menu.php | 28 +++++++++++++ 6 files changed, 149 insertions(+), 40 deletions(-) create mode 100644 kernel/Widget.php create mode 100644 kernel/models/Menu.php create mode 100644 kernel/widgets/MenuWidget.php create mode 100644 migrations/2024_08_30_083939_create_menu_table.php create mode 100644 views/widgets/admin/menu.php diff --git a/kernel/Widget.php b/kernel/Widget.php new file mode 100644 index 0000000..3ecbad8 --- /dev/null +++ b/kernel/Widget.php @@ -0,0 +1,34 @@ +cgView = new CgView(); + $this->cgView->viewPath = ROOT_DIR . "/views/widgets"; + + $this->data = $data; + + $this->init(); + } + + public function run() + { + } + + public static function create(array $data = []): Widget + { + return new static($data); + } + + protected function init() + { + } + +} \ No newline at end of file diff --git a/kernel/models/Menu.php b/kernel/models/Menu.php new file mode 100644 index 0000000..4429821 --- /dev/null +++ b/kernel/models/Menu.php @@ -0,0 +1,35 @@ + 'Родительский пункт меню', + 'icon_file' => 'Путь к иконке', + 'icon_font' => 'Иконка', + 'label' => 'Заголовок', + 'url' => 'URL', + 'status' => 'Статус', + ]; + } + + public static function getChild(int $id) + { + $collection = Menu::where("parent_id", $id)->get(); + if (!$collection->isEmpty()){ + return $collection; + } + + return false; + } +} \ No newline at end of file diff --git a/kernel/widgets/MenuWidget.php b/kernel/widgets/MenuWidget.php new file mode 100644 index 0000000..a0f3aaf --- /dev/null +++ b/kernel/widgets/MenuWidget.php @@ -0,0 +1,17 @@ +get(); + $this->cgView->render('/admin/menu.php', ['menu' => $menu]); + } + +} \ No newline at end of file diff --git a/migrations/2024_08_30_083939_create_menu_table.php b/migrations/2024_08_30_083939_create_menu_table.php new file mode 100644 index 0000000..99c4023 --- /dev/null +++ b/migrations/2024_08_30_083939_create_menu_table.php @@ -0,0 +1,34 @@ +schema->create('menu', function (Blueprint $table) { + $table->increments('id'); + $table->integer('parent_id')->default(0); + $table->string('icon_file', 255)->nullable(); + $table->string('icon_font', 255)->nullable(); + $table->string('label', 255); + $table->string('url', 255); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('menu'); + } +}; diff --git a/views/admin/layouts/main.php b/views/admin/layouts/main.php index a7f6f0e..c7783c9 100644 --- a/views/admin/layouts/main.php +++ b/views/admin/layouts/main.php @@ -21,46 +21,7 @@