widgets, widget menu

This commit is contained in:
2024-08-30 12:27:46 +03:00
parent 4c90d86509
commit 5b4676a4c0
6 changed files with 149 additions and 40 deletions

34
kernel/Widget.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace kernel;
class Widget
{
protected CgView $cgView;
protected array $data;
public function __construct(array $data = [])
{
$this->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()
{
}
}

35
kernel/models/Menu.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace kernel\models;
use app\helpers\Debug;
use Illuminate\Database\Eloquent\Model;
class Menu extends Model
{
protected $table = 'menu';
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status'];
protected array $dates = ['deleted_at'];
public static function labels(): array
{
return [
'parent_id' => 'Родительский пункт меню',
'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;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace kernel\widgets;
use kernel\models\Menu;
use kernel\Widget;
class MenuWidget extends Widget
{
public function run(): void
{
$menu = Menu::where("parent_id", 0)->get();
$this->cgView->render('/admin/menu.php', ['menu' => $menu]);
}
}