diff --git a/kernel/AdminController.php b/kernel/AdminController.php index 33918e7..a1e8fcf 100755 --- a/kernel/AdminController.php +++ b/kernel/AdminController.php @@ -5,14 +5,17 @@ namespace kernel; use kernel\Controller; use kernel\helpers\Debug; use kernel\services\AdminThemeService; +use kernel\services\ThemeService; class AdminController extends Controller { protected AdminThemeService $adminThemeService; + protected ThemeService $themeService; protected function init(): void { $this->adminThemeService = new AdminThemeService(); + $this->themeService = new ThemeService(); $active_theme = $this->adminThemeService->getActiveAdminThemeInfo(); $this->cgView->layoutPath = getConst($active_theme['layout_path']); $this->cgView->layout = "/" . $active_theme['layout']; diff --git a/kernel/App.php b/kernel/App.php index f185ce8..7ce9803 100755 --- a/kernel/App.php +++ b/kernel/App.php @@ -7,6 +7,7 @@ namespace kernel; use kernel\helpers\Debug; use kernel\modules\user\models\User; use kernel\services\ModuleService; +use kernel\services\ThemeService; use Phroute\Phroute\Dispatcher; class App @@ -24,6 +25,8 @@ class App public ModuleService $moduleService; + public ThemeService $themeService; + public static Database $db; public function run(): void @@ -53,6 +56,12 @@ class App foreach ($modules_routs as $rout){ include "$rout"; } + + $themeService = new ThemeService(); + $activeTheme = getConst($themeService->getActiveTheme()); + if (!empty($activeTheme)){ + include $activeTheme . "/" . $themeService->getThemeRout($activeTheme); + } } public static function create(): App diff --git a/kernel/Assets.php b/kernel/Assets.php new file mode 100644 index 0000000..30c2c8b --- /dev/null +++ b/kernel/Assets.php @@ -0,0 +1,66 @@ +setResourceURI($resourceURI); + $this->createCSS(); + $this->createJS(); + } + + protected function createCSS(){} + protected function createJS(){} + + public function setResourceURI(string $resourceURI): void + { + $this->resourceURI = $resourceURI; + } + + public function registerJS(string $slug, string $resource, bool $body = true, bool $addResourceURI = true): void + { + $resource = $addResourceURI ? $this->resourceURI . $resource : $resource; + if ($body) { + $this->jsBody[$slug] = $resource; + } else { + $this->jsHeader[$slug] = $resource; + } + } + + public function registerCSS(string $slug, string $resource, bool $addResourceURI = true): void + { + $resource = $addResourceURI ? $this->resourceURI . $resource : $resource; + $this->css[$slug] = $resource; + } + + public function getJSAsStr(bool $body = true): void + { + if ($body) { + foreach ($this->jsBody as $key => $item){ + echo ""; + } + } + else { + foreach ($this->jsHeader as $key => $item){ + echo ""; + } + } + } + + public function getCSSAsSTR(): void + { + foreach ($this->css as $key => $item){ + echo ""; + } + } + +} \ No newline at end of file diff --git a/kernel/CgView.php b/kernel/CgView.php index 5934f82..68237bb 100755 --- a/kernel/CgView.php +++ b/kernel/CgView.php @@ -2,6 +2,8 @@ namespace kernel; +use kernel\helpers\Debug; + class CgView { public string $viewPath = ''; @@ -61,6 +63,13 @@ class CgView private function createContent(string $viewFile, array $data = []): false|string { ob_start(); + + if ($this->varToLayout){ + foreach ($this->varToLayout as $key => $datum) { + ${"$key"} = $datum; + } + } + $view = $this; foreach ($data as $key => $datum) { ${"$key"} = $datum; diff --git a/kernel/RestController.php b/kernel/RestController.php index 2d7596d..99ba279 100755 --- a/kernel/RestController.php +++ b/kernel/RestController.php @@ -17,13 +17,32 @@ class RestController return []; } + protected function filters(): array + { + return []; + } + #[NoReturn] public function actionIndex(): void { $request = new Request(); + $get = $request->get(); $page = $request->get('page') ?? 1; $perPage = $request->get('per_page') ?? 10; $query = $this->model->query(); + if ($this->filters()) { + foreach ($this->filters() as $filter){ + if (key_exists($filter, $get)){ + if (is_numeric($get[$filter])){ + $query->where($filter, $get[$filter]); + } + elseif (is_string($get[$filter])){ + $query->where($filter,'like', '%' . $get[$filter] . '%'); + } + } + } + } + if ($page > 1) { $query->skip(($page - 1) * $perPage)->take($perPage); } else { @@ -31,7 +50,7 @@ class RestController } $expand = $this->expand(); - $expandParams = explode( ",", $request->get('expand') ?? ""); + $expandParams = explode(",", $request->get('expand') ?? ""); $finalExpand = array_intersect($expandParams, $expand); if ($finalExpand) { $res = $query->get()->load($finalExpand)->toArray(); @@ -46,14 +65,14 @@ class RestController { $expand = $this->expand(); $request = new Request(); - $expandParams = explode( ",", $request->get('expand') ?? ""); + $expandParams = explode(",", $request->get('expand') ?? ""); $model = $this->model->where("id", $id)->first(); $finalExpand = array_intersect($expandParams, $expand); - if ($finalExpand){ + if ($finalExpand) { $model->load($finalExpand); } $res = []; - if ($model){ + if ($model) { $res = $model->toArray(); } @@ -64,7 +83,7 @@ class RestController { $model = $this->model->where("id", $id)->first(); $res = []; - if ($model){ + if ($model) { $res = $model->toArray(); } @@ -78,7 +97,7 @@ class RestController { $request = new Request(); $data = $request->post(); - foreach ($this->model->getFillable() as $item){ + foreach ($this->model->getFillable() as $item) { $this->model->{$item} = $data[$item] ?? null; } $this->model->save(); @@ -93,8 +112,8 @@ class RestController $model = $this->model->where('id', $id)->first(); - foreach ($model->getFillable() as $item){ - if (!empty($data[$item])){ + foreach ($model->getFillable() as $item) { + if (!empty($data[$item])) { $model->{$item} = $data[$item] ?? null; } } @@ -117,5 +136,4 @@ class RestController } - } \ No newline at end of file diff --git a/kernel/admin_themes/default/DefaultAdminThemeAssets.php b/kernel/admin_themes/default/DefaultAdminThemeAssets.php new file mode 100644 index 0000000..7c5cf70 --- /dev/null +++ b/kernel/admin_themes/default/DefaultAdminThemeAssets.php @@ -0,0 +1,25 @@ +registerJS(slug: "jquery", resource: "/js/jquery.min.js"); + $this->registerJS(slug: "popper", resource: "/js/popper.js"); + $this->registerJS(slug: "bootstrap", resource: "/js/bootstrap.min.js"); + $this->registerJS(slug: "main", resource: "/js/main.js"); + } + + protected function createCSS() + { + $this->registerCSS(slug: "font-awesome", resource: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css", addResourceURI: false); + $this->registerCSS(slug: "bootstrap", resource: "/css/bootstrap.min.css"); + $this->registerCSS(slug: "style", resource: "/css/style.css"); + } + +} \ No newline at end of file diff --git a/kernel/admin_themes/default/layout/main.php b/kernel/admin_themes/default/layout/main.php index 98be7fb..a015dda 100755 --- a/kernel/admin_themes/default/layout/main.php +++ b/kernel/admin_themes/default/layout/main.php @@ -6,6 +6,7 @@ * @var \kernel\CgView $view */ \Josantonius\Session\Facades\Session::start(); +$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources) ?> @@ -17,9 +18,8 @@ - - - + getCSSAsSTR(); ?> + getJSAsStr(body: false); ?>
@@ -92,9 +92,6 @@ - - - - +getJSAsStr(); ?>