diff --git a/app/controllers/AnswerController.php b/app/controllers/AnswerController.php deleted file mode 100644 index 3482afa..0000000 --- a/app/controllers/AnswerController.php +++ /dev/null @@ -1,32 +0,0 @@ -$answer,'question_id'=>$question_id,'user_id'=>$user_id]); - } - public static function actionUpvoteAnswer($answer_id,$user_id) - { - return Upvote::create(['answer_id'=>$answer_id,'user_id'=>$user_id]); - } - - public function actionUpdateAnswer($answer_id,$new_answer) - { - $answer = Answer::find($answer_id); - $answer->answer = $new_answer; - return $answer->save(); - } - - public function actionViewAllAnswers(): void - { - foreach (Answer::all() as $answer) - { - echo $answer->answer . "
"; - } - } -} \ No newline at end of file diff --git a/app/controllers/MenuController.php b/app/controllers/MenuController.php deleted file mode 100644 index 75145bb..0000000 --- a/app/controllers/MenuController.php +++ /dev/null @@ -1,106 +0,0 @@ -cgView->viewPath = ROOT_DIR . "/views/admin/"; - $this->cgView->layout = "layouts/main.php"; - } - - public function actionCreate(): void - { - $this->cgView->render("menu/form.php"); - } - - #[NoReturn] public function actionAdd(): void - { - $menuForm = new CreateMenuForm(); - $menuService = new MenuService(); - $menuForm->load($_REQUEST); - if ($menuForm->validate()){ - $menuItem = $menuService->create($menuForm); - if ($menuItem){ - $this->redirect("/admin/menu/" . $menuItem->id); - } - } - $this->redirect("/admin/menu/create"); - } - - /** - * @throws Exception - */ - public function actionIndex($page_number = 1): void - { - $this->cgView->render("menu/index.php", ['page_number' => $page_number]); - } - - /** - * @throws Exception - */ - public function actionView($id): void - { - $menuItem = Menu::find($id); - - if (!$menuItem){ - throw new Exception(message: "The menu item not found"); - } - $this->cgView->render("menu/view.php", ['menu' => $menuItem]); - } - - /** - * @throws RuntimeError - * @throws SyntaxError - * @throws LoaderError|Exception - */ - public function actionUpdate($id): void - { - $model = Menu::find($id); - if (!$model){ - throw new Exception(message: "The menu item not found"); - } - - $this->cgView->render("menu/form.php", ['model' => $model]); - } - - /** - * @throws Exception - */ - public function actionEdit($id): void - { - $menuItem = Menu::find($id); - if (!$menuItem){ - throw new Exception(message: "The menu item not found"); - } - $menuForm = new CreateMenuForm(); - $menuService = new MenuService(); - $menuForm->load($_REQUEST); - if ($menuForm->validate()){ - $menuItem = $menuService->update($menuForm, $menuItem); - if ($menuItem){ - $this->redirect("/admin/menu/" . $menuItem->id); - } - } - $this->redirect("/admin/menu/update/" . $id); - } - - #[NoReturn] public function actionDelete($id): void - { - Menu::find($id)->delete(); - $this->redirect("/admin/menu/"); - } - -} \ No newline at end of file diff --git a/app/controllers/QuestionController.php b/app/controllers/QuestionController.php deleted file mode 100644 index 2dfaf3a..0000000 --- a/app/controllers/QuestionController.php +++ /dev/null @@ -1,36 +0,0 @@ -twig->render('question_create.html.twig'); - } - - public function actionGetQuestionsWithAnswers(): array - { - return Question::with('AnswerController')->get()->toArray(); - } - - public function actionGetQuestionsWithUsers(): array - { - return Question::with('user')->get()->toArray(); - } - - public function actionGetQuestionAnswersUpvotes($question_id) - { - return Question::find($question_id)->answers()->with('upvotes')->get()->toArray(); - } - - public function actionViewAllQuestions() - { - foreach (Question::all() as $question) - { - echo $question->question. "
"; - } - } -} \ No newline at end of file diff --git a/app/models/Answer.php b/app/models/Answer.php deleted file mode 100644 index 593e156..0000000 --- a/app/models/Answer.php +++ /dev/null @@ -1,14 +0,0 @@ -hasMany('\Models\Upvote'); - } -} \ No newline at end of file diff --git a/app/models/Question.php b/app/models/Question.php deleted file mode 100644 index 4f3b28d..0000000 --- a/app/models/Question.php +++ /dev/null @@ -1,22 +0,0 @@ -hasMany('\Models\Answer'); - } - - public function user() - { - return $this->belongsTo('\Models\User'); - } -} \ No newline at end of file diff --git a/kernel/FileUpload.php b/kernel/FileUpload.php new file mode 100644 index 0000000..1f72ec6 --- /dev/null +++ b/kernel/FileUpload.php @@ -0,0 +1,51 @@ +fileTmpPath = $file['tmp_name']; + $this->fileName = $file['name']; + $this->fileSize = $file['size']; + $this->fileType = $file['type']; + $this->fileNameCmps = explode('.', $this->fileName); + $this->fileExtension = strtolower(end($this->fileNameCmps)); + } + + public function setNewFileName(): void + { + $this->newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension; + } + + public function checkExtension(): void + { + + } + + public function upload(): void + { + $this->newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension; + if (in_array($this->fileExtension, $this->allowedFileExtensions)) { + mkdir('./resources/upload/' . mb_substr($this->newFileName, 0, 2) . '/' . mb_substr($this->newFileName, 2, 2) . '/', 0777, true); + $uploadFileDir = './resources/upload/' . mb_substr($this->newFileName, 0, 2) . '/' . mb_substr($this->newFileName, 2, 2) . '/'; + $dest_path = $uploadFileDir . $this->newFileName; + move_uploaded_file($this->fileTmpPath, $dest_path); + } else { + echo "Ниченр не получилочь :("; + } + } + +} \ No newline at end of file diff --git a/kernel/IGTabel/EloquentDataProvider.php b/kernel/IGTabel/EloquentDataProvider.php deleted file mode 100644 index 2efe235..0000000 --- a/kernel/IGTabel/EloquentDataProvider.php +++ /dev/null @@ -1,78 +0,0 @@ -queryBuilder = $source::query(); -// $model = new $source(); -// } elseif (is_object($source)) { -// $this->queryBuilder = $source; -// $model = $source->getModel(); -// } else { -// throw new Exception(message: "source is not valid"); -// } -// $this->options = $options; -// $this->currentPage = $this->options['currentPage'] ?? 1; -// $this->perPage = $this->options['perPage'] ?? 10; -// $this->meta['total'] = $model->count(); -// $this->meta['totalWithFilters'] = $this->queryBuilder->count(); -// $this->meta['columns'] = $options['columns'] ?? $model->labels(); -// $this->meta['perPage'] = $options['perPage'] ?? 10; -// $this->meta['currentPage'] = $options['currentPage'] ?? 1; -// $this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table; -// $this->meta['params'] = $options['params'] ?? []; -// $this->meta['actions'] = $options['actions'] ?? []; -// $this->createQuery(); -// -// $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray()))->getJson(); -// -// } -// -// public function createQuery(): void -// { -// if ($this->currentPage > 1) { -// $this->queryBuilder->skip(($this->currentPage - 1) * $this->perPage)->take($this->perPage); -// } else { -// $this->queryBuilder->take($this->perPage); -// } -// } -// -// public function getCollection() -// { -// return $this->queryBuilder->get(); -// } -// -// /** -// * @return string|null -// */ -// public function getJson(): string|null -// { -// return $this->jsonStr; -// } -// -//} \ No newline at end of file diff --git a/kernel/IGTabel/JSONCreator.php b/kernel/IGTabel/JSONCreator.php deleted file mode 100644 index 8a8da5a..0000000 --- a/kernel/IGTabel/JSONCreator.php +++ /dev/null @@ -1,40 +0,0 @@ - "table table-bordered", "border" => "1"] : $meta['params']; -// if ($meta) { -// $this->informationArray = [ -// "meta" => $meta, -// "data" => $data ?? [] -// ]; -// } -// } -// -// /** -// * @param array $infArr -// * @return string|null -// */ -// protected function toJson(array $infArr): ?string -// { -// if ($infArr) -// return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); -// return null; -// } -// -// /** -// * @return string|null -// */ -// public function getJson(): ?string -// { -// return $this->toJson($this->informationArray); -// } -//} \ No newline at end of file diff --git a/kernel/IGTabel/ListJsonTableEloquentCollection.php b/kernel/IGTabel/ListJsonTableEloquentCollection.php deleted file mode 100644 index 32c86a9..0000000 --- a/kernel/IGTabel/ListJsonTableEloquentCollection.php +++ /dev/null @@ -1,42 +0,0 @@ -meta['columns'] = $params['columns'] ?? $model->labels(); -// $this->meta['perPage'] = $params['perPage'] ?? 10; -// $this->meta['currentPage'] = $params['currentPage'] ?? 1; -// $this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table; -// $this->meta['params'] = $params['params'] ?? []; -// $this->meta['actions'] = $params['actions'] ?? []; -// -// $this->jsonStr = (new JSONCreator($this->meta, $collection->toArray()))->getJson(); -// } -// -// /** -// * @return string|null -// */ -// public function getJson(): string|null -// { -// return $this->jsonStr; -// } -// -//} \ No newline at end of file diff --git a/kernel/IGTabel/ViewJsonTableEloquentModel.php b/kernel/IGTabel/ViewJsonTableEloquentModel.php deleted file mode 100644 index 8915be7..0000000 --- a/kernel/IGTabel/ViewJsonTableEloquentModel.php +++ /dev/null @@ -1,37 +0,0 @@ -meta['rows'] = $params['rows'] ?? $model->labels(); -// $this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table; -// $this->meta['params'] = $params['params'] ?? []; -// $this->meta['actions'] = $params['actions'] ?? []; -// -//// $this->jsonStr = (new JSONCreator($this->meta, $model->toArray()))->getJson(); -// $model = $model->toArray(); -// if(isset($model['user_id'])) -// { -// $model['user_id'] = User::find($model['user_id'])->username; -// } -// -// $this->jsonStr = (new JSONCreator($this->meta, $model))->getJson(); -// } -// -// public function getJson(): ?string -// { -// return $this->jsonStr; -// } -// -//} \ No newline at end of file diff --git a/kernel/modules/menu/controllers/MenuController.php b/kernel/modules/menu/controllers/MenuController.php index 3c8b239..8075d3d 100644 --- a/kernel/modules/menu/controllers/MenuController.php +++ b/kernel/modules/menu/controllers/MenuController.php @@ -4,22 +4,26 @@ namespace kernel\modules\menu\controllers; use app\helpers\Debug; use app\models\forms\CreateMenuForm; -use app\services\MenuService; +use kernel\FileUpload; +use kernel\modules\menu\service\MenuService; use Exception; use JetBrains\PhpStorm\NoReturn; +use kernel\AdminController; use kernel\Controller; use kernel\models\Menu; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; -class MenuController extends Controller +class MenuController extends AdminController { + private MenuService $menuService; + protected function init(): void { + parent::init(); $this->cgView->viewPath = KERNEL_MODULES_DIR . "/menu/views/"; - $this->cgView->layoutPath = ROOT_DIR . "/views/admin/"; - $this->cgView->layout = "layouts/main.php"; + $this->menuService = new MenuService(); } public function actionCreate(): void @@ -29,11 +33,15 @@ class MenuController extends Controller #[NoReturn] public function actionAdd(): void { + if (isset($_FILES['icon_file']) && $_FILES['icon_file']['error'] === UPLOAD_ERR_OK) { + $file = new FileUpload($_FILES['icon_file']); + $file->upload(); + } + $menuForm = new CreateMenuForm(); - $menuService = new MenuService(); $menuForm->load($_REQUEST); if ($menuForm->validate()){ - $menuItem = $menuService->create($menuForm); + $menuItem = $this->menuService->create($menuForm); if ($menuItem){ $this->redirect("/admin/settings/menu/" . $menuItem->id); } @@ -82,15 +90,20 @@ class MenuController extends Controller */ public function actionEdit($id): void { +// Debug::prn($_REQUEST); +// Debug::prn($_FILES); $menuItem = Menu::find($id); if (!$menuItem){ throw new Exception(message: "The menu item not found"); } + if (isset($_FILES['icon_file']) && $_FILES['icon_file']['error'] === UPLOAD_ERR_OK) { + $file = new FileUpload($_FILES['icon_file']); + $file->upload(); + } $menuForm = new CreateMenuForm(); - $menuService = new MenuService(); $menuForm->load($_REQUEST); if ($menuForm->validate()){ - $menuItem = $menuService->update($menuForm, $menuItem); + $menuItem = $this->menuService->update($menuForm, $menuItem); if ($menuItem){ $this->redirect("/admin/settings/menu/" . $menuItem->id); } diff --git a/app/services/MenuService.php b/kernel/modules/menu/service/MenuService.php similarity index 59% rename from app/services/MenuService.php rename to kernel/modules/menu/service/MenuService.php index 5dce0b6..6101f63 100644 --- a/app/services/MenuService.php +++ b/kernel/modules/menu/service/MenuService.php @@ -1,14 +1,13 @@ get(); + if (!$collection->isEmpty()){ + return $collection; + } + return false; + } + + public static function hasActiveChild(int $id): bool + { + $child = self::getChild($id); + if (!$child->isEmpty()){ + foreach ($child as $item){ +// if ($item->url === \kernel\Request::getUrlPath()){ +// return true; +// } + if (strripos(Request::getUrlPath(), $item->url) !== false) { + return true; + } + } + } + + return false; + } + + public static function isActive($url): bool + { + if ($url === Request::getUrlPath()){ + return true; + } else { + if (strripos(\kernel\Request::getUrlPath(), ($url . "/page")) !== false) { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/kernel/modules/menu/views/form.php b/kernel/modules/menu/views/form.php index bd4bc63..dc35eef 100644 --- a/kernel/modules/menu/views/form.php +++ b/kernel/modules/menu/views/form.php @@ -13,7 +13,7 @@ $form->field(class: \itguild\forms\inputs\Select::class, name: "parent_id", para 'value' => $model->parent_id ?? '' ]) ->setLabel("Родительский пункт меню") - ->setOptions(\app\services\MenuService::createLabelArr()) + ->setOptions(\kernel\modules\menu\service\MenuService::createLabelArr()) ->render(); $form->field(class: \itguild\forms\inputs\File::class, name: "icon_file", params: [ diff --git a/app/controllers/PostController.php b/kernel/modules/post/controllers/PostController.php similarity index 64% rename from app/controllers/PostController.php rename to kernel/modules/post/controllers/PostController.php index 1a309da..10c10c7 100644 --- a/app/controllers/PostController.php +++ b/kernel/modules/post/controllers/PostController.php @@ -1,37 +1,36 @@ cgView->viewPath = ROOT_DIR . "/views/admin/"; - $this->cgView->layout = "layouts/main.php"; + $this->cgView->viewPath = KERNEL_MODULES_DIR . "/post/views/"; + $this->postService = new PostService(); } public function actionCreate(): void { - $this->cgView->render("post/form.php"); + $this->cgView->render("form.php"); } #[NoReturn] public function actionAdd(): void { $postForm = new CreatePostForm(); - $postService = new PostService(); $postForm->load($_REQUEST); if ($postForm->validate()) { - $post = $postService->create($postForm); + $post = $this->postService->create($postForm); if ($post) { $this->redirect("/admin/post/" . $post->id); } @@ -45,7 +44,7 @@ class PostController extends Controller public function actionIndex($page_number = 1): void { - $this->cgView->render("post/index.php", ['page_number' => $page_number]); + $this->cgView->render("index.php", ['page_number' => $page_number]); } /** @@ -58,7 +57,7 @@ class PostController extends Controller if (!$content){ throw new Exception(message: "The post not found"); } - $this->cgView->render("post/view.php", ['content' => $content]); + $this->cgView->render("view.php", ['content' => $content]); } /** @@ -71,7 +70,7 @@ class PostController extends Controller throw new Exception(message: "The post not found"); } - $this->cgView->render("post/form.php", ['model' => $model]); + $this->cgView->render("form.php", ['model' => $model]); } /** @@ -86,12 +85,10 @@ class PostController extends Controller $postForm = new CreatePostForm(); $postService = new PostService(); $postForm->load($_REQUEST); - if((new UserService)->check($_REQUEST['user_id'])) { - if ($postForm->validate()) { - $post = $postService->update($postForm, $post); - if ($post) { - $this->redirect("/admin/post/" . $post->id); - } + if ($postForm->validate()) { + $post = $postService->update($postForm, $post); + if ($post) { + $this->redirect("/admin/post/" . $post->id); } } $this->redirect("/admin/post/update/" . $id); diff --git a/app/models/Post.php b/kernel/modules/post/models/Post.php similarity index 94% rename from app/models/Post.php rename to kernel/modules/post/models/Post.php index 175edc7..c2ae704 100644 --- a/app/models/Post.php +++ b/kernel/modules/post/models/Post.php @@ -1,6 +1,6 @@ beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post"); @@ -21,7 +21,7 @@ $form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params 'value' => $model->user_id ?? '' ]) ->setLabel("Пользователи") - ->setOptions(\app\services\UserService::createUsernameArr()) + ->setOptions(\kernel\modules\user\service\UserService::createUsernameArr()) ->render(); ?> diff --git a/views/admin/post/index.php b/kernel/modules/post/views/index.php similarity index 93% rename from views/admin/post/index.php rename to kernel/modules/post/views/index.php index c2b760b..8b29982 100644 --- a/views/admin/post/index.php +++ b/kernel/modules/post/views/index.php @@ -5,8 +5,8 @@ * @var int $page_number */ -use app\models\Post; -use app\models\User; +use kernel\modules\post\models\Post; +use kernel\modules\user\models\User; use app\tables\columns\post\PostDeleteActionColumn; use app\tables\columns\post\PostEditActionColumn; use app\tables\columns\post\PostViewActionColumn; diff --git a/views/admin/post/view.php b/kernel/modules/post/views/view.php similarity index 95% rename from views/admin/post/view.php rename to kernel/modules/post/views/view.php index 410201f..13837b1 100644 --- a/views/admin/post/view.php +++ b/kernel/modules/post/views/view.php @@ -4,7 +4,7 @@ * @var \Illuminate\Database\Eloquent\Collection $content */ -use app\models\User; +use kernel\modules\user\models\User; use Itguild\EloquentTable\ViewEloquentTable; use Itguild\EloquentTable\ViewJsonTableEloquentModel; use kernel\IGTabel\btn\DangerBtn; diff --git a/app/controllers/UserController.php b/kernel/modules/user/controllers/UserController.php similarity index 72% rename from app/controllers/UserController.php rename to kernel/modules/user/controllers/UserController.php index 76fa475..dff504b 100644 --- a/app/controllers/UserController.php +++ b/kernel/modules/user/controllers/UserController.php @@ -1,11 +1,11 @@ cgView->viewPath = ROOT_DIR . "/views/admin/"; - $this->cgView->layout = "layouts/main.php"; + parent::init(); + $this->cgView->viewPath = KERNEL_MODULES_DIR . "/user/views/"; + $this->userService = new UserService(); } public function actionCreate(): void { - $this->cgView->render("user/form.php"); + $this->cgView->render("form.php"); } #[NoReturn] public function actionAdd(): void { $userForm = new CreateUserForm(); - $userService = new UserService(); $userForm->load($_REQUEST); if ($userForm->validate()){ - $user = $userService->create($userForm); + $user = $this->userService->create($userForm); if ($user){ $this->redirect("/admin/user/" . $user->id); } @@ -39,17 +43,12 @@ class UserController extends Controller{ $this->redirect("/admin/user/create"); } - public function actionQuestionCount($user_id) - { - return Question::where('user_id', $user_id)->count(); - } - /** * @throws \Exception */ public function actionIndex($page_number = 1): void { - $this->cgView->render("user/index.php", ['page_number' => $page_number]); + $this->cgView->render("index.php", ['page_number' => $page_number]); } /** @@ -62,7 +61,7 @@ class UserController extends Controller{ if (!$user){ throw new Exception(message: "The user not found"); } - $this->cgView->render("user/view.php", ['user' => $user]); + $this->cgView->render("view.php", ['user' => $user]); } /** @@ -77,7 +76,7 @@ class UserController extends Controller{ throw new Exception(message: "The user not found"); } - $this->cgView->render("user/form.php", ['model' => $model]); + $this->cgView->render("form.php", ['model' => $model]); } /** diff --git a/app/models/User.php b/kernel/modules/user/models/User.php similarity index 94% rename from app/models/User.php rename to kernel/modules/user/models/User.php index 546cc93..f6a37c7 100644 --- a/app/models/User.php +++ b/kernel/modules/user/models/User.php @@ -1,5 +1,5 @@ beginForm(isset($model) ? "/admin/user/edit/" . $model->id : "/admin/user"); diff --git a/views/admin/user/index.php b/kernel/modules/user/views/index.php similarity index 96% rename from views/admin/user/index.php rename to kernel/modules/user/views/index.php index 4723cc2..d551c89 100644 --- a/views/admin/user/index.php +++ b/kernel/modules/user/views/index.php @@ -4,13 +4,13 @@ * @var int $page_number */ -use app\models\User; use app\tables\columns\user\UserDeleteActionColumn; use app\tables\columns\user\UserEditActionColumn; use app\tables\columns\user\UserViewActionColumn; use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\ListEloquentTable; use kernel\IGTabel\btn\PrimaryBtn; +use kernel\modules\user\models\User; $table = new ListEloquentTable(new EloquentDataProvider(User::class, [ 'currentPage' => $page_number, diff --git a/views/admin/user/view.php b/kernel/modules/user/views/view.php similarity index 95% rename from views/admin/user/view.php rename to kernel/modules/user/views/view.php index 67fee01..fc8293b 100644 --- a/views/admin/user/view.php +++ b/kernel/modules/user/views/view.php @@ -4,7 +4,7 @@ * @var \Illuminate\Database\Eloquent\Collection $user */ -use app\models\User; +use kernel\modules\user\models\User; use Itguild\EloquentTable\ViewEloquentTable; use Itguild\EloquentTable\ViewJsonTableEloquentModel; use kernel\IGTabel\btn\DangerBtn; diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php index aa9e7fc..9c8c18a 100644 --- a/kernel/routs/admin.php +++ b/kernel/routs/admin.php @@ -8,24 +8,24 @@ use Phroute\Phroute\RouteCollector; App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){ - App::$collector->get('/', [\app\controllers\UserController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\controllers\UserController::class, 'actionIndex']); - App::$collector->get('/create', [\app\controllers\UserController::class, 'actionCreate']); - App::$collector->post("/", [\app\controllers\UserController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\controllers\UserController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\controllers\UserController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\controllers\UserController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']); + App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']); }); App::$collector->group(["prefix" => "post"], function (RouteCollector $router){ - App::$collector->get('/', [\app\controllers\PostController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\controllers\PostController::class, 'actionIndex']); - App::$collector->get('/create', [\app\controllers\PostController::class, 'actionCreate']); - App::$collector->post("/", [\app\controllers\PostController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\controllers\PostController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\controllers\PostController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\controllers\PostController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\controllers\PostController::class, 'actionDelete']); + App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']); }); App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){ App::$collector->group(["prefix" => "menu"], function (RouteCollector $router){ diff --git a/kernel/services/MenuService.php b/kernel/services/MenuService.php deleted file mode 100644 index 3b26c4e..0000000 --- a/kernel/services/MenuService.php +++ /dev/null @@ -1,49 +0,0 @@ -get(); - if (!$collection->isEmpty()){ - return $collection; - } - - return false; - } - - public static function hasActiveChild(int $id): bool - { - $child = self::getChild($id); - if (!$child->isEmpty()){ - foreach ($child as $item){ -// if ($item->url === \kernel\Request::getUrlPath()){ -// return true; -// } - if (strripos(Request::getUrlPath(), $item->url) !== false) { - return true; - } - } - } - - return false; - } - - public static function isActive($url): bool - { - if ($url === Request::getUrlPath()){ - return true; - } else { - if (strripos(\kernel\Request::getUrlPath(), ($url . "/page")) !== false) { - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/resources/upload/5c/40/5c4044ac0df8411aaf0dbdb41846dc29.png b/resources/upload/5c/40/5c4044ac0df8411aaf0dbdb41846dc29.png new file mode 100644 index 0000000..212a06c Binary files /dev/null and b/resources/upload/5c/40/5c4044ac0df8411aaf0dbdb41846dc29.png differ diff --git a/resources/upload/71/bb/71bbe61dded4fb0ba8269540c6989974.png b/resources/upload/71/bb/71bbe61dded4fb0ba8269540c6989974.png new file mode 100644 index 0000000..aa15e6c Binary files /dev/null and b/resources/upload/71/bb/71bbe61dded4fb0ba8269540c6989974.png differ diff --git a/views/admin/menu/form.php b/views/admin/menu/form.php deleted file mode 100644 index 30a9c9c..0000000 --- a/views/admin/menu/form.php +++ /dev/null @@ -1,78 +0,0 @@ -beginForm(isset($model) ? "/admin/menu/edit/" . $model->id : "/admin/menu"); - -$form->field(class: \itguild\forms\inputs\Select::class, name: "parent_id", params: [ - 'class' => "form-control", - 'value' => $model->parent_id ?? '' -]) - ->setLabel("Родительский пункт меню") - ->setOptions(\app\services\MenuService::createLabelArr()) - ->render(); - -$form->field(class: \itguild\forms\inputs\File::class, name: "icon_file", params: [ - 'class' => "form-control", - 'value' => $model->icon_file ?? '' -]) - ->setLabel("Путь к иконке") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "icon_font", params: [ - 'class' => "form-control", - 'value' => $model->icon_font ?? '' -]) - ->setLabel("Иконка") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ - 'class' => "form-control", - 'value' => $model->label ?? '' -]) - ->setLabel("Заголовок") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "url", params: [ - 'class' => "form-control", - 'value' => $model->url ?? '' -]) - ->setLabel("URL") - ->render(); - -$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [ - 'class' => "form-control", - 'value' => $model->status ?? '1' -]) - ->setLabel("Статус") - ->setOptions(Menu::getStatus()) - ->render(); -?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ - 'class' => "btn btn-primary ", - 'value' => 'Отправить', - 'typeInput' => 'submit' - ]) - ->render(); - ?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ - 'class' => "btn btn-warning", - 'value' => 'Сбросить', - 'typeInput' => 'reset' - ]) - ->render(); - ?> -
-
-endForm(); diff --git a/views/admin/menu/index.php b/views/admin/menu/index.php deleted file mode 100644 index d5f55c3..0000000 --- a/views/admin/menu/index.php +++ /dev/null @@ -1,35 +0,0 @@ - $page_number, - 'perPage' => 8, - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/menu", -])); -$table->columns([ - 'parent_id' => (function ($data) { - if ($data == 0) return null; - return Menu::find($data)->label; - }) -]); -$table->beforePrint(function () { - return PrimaryBtn::create("Создать", "/admin/menu/create")->fetch(); - //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); -}); -$table->addAction(MenuViewActionColumn::class); -$table->addAction(MenuEditActionColumn::class); -$table->addAction(MenuDeleteActionColumn::class); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/views/admin/menu/view.php b/views/admin/menu/view.php deleted file mode 100644 index 92aac76..0000000 --- a/views/admin/menu/view.php +++ /dev/null @@ -1,46 +0,0 @@ - ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/menu", -])); -$table->beforePrint(function () use ($menu) { - $btn = PrimaryBtn::create("Список", "/admin/menu")->fetch(); - $btn .= SuccessBtn::create("Редактировать", "/admin/menu/update/" . $menu->id)->fetch(); - $btn .= DangerBtn::create("Удалить", "/admin/menu/delete/" . $menu->id)->fetch(); - return $btn; -}); -$table->rows([ - 'parent_id' => (function ($data) { - if ($data == 0) return null; - return Menu::find($data)->label; - }), - 'created_at' => function ($data) { - if (!$data){ - return null; - } - - return (new DateTimeImmutable($data))->format("d-m-Y"); - }, - 'updated_at' => function ($data) { - if (!$data){ - return null; - } - - return (new DateTimeImmutable($data))->format("d-m-Y"); - } -]); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/views/main_layout.html.twig b/views/main_layout.html.twig deleted file mode 100644 index 1601dbd..0000000 --- a/views/main_layout.html.twig +++ /dev/null @@ -1,19 +0,0 @@ - - - - - Примеры шаблонизатора Twig - - - -
-
-

HEADER

- {% block content %} - {% endblock %} -

FOOTER

-
-
- - - \ No newline at end of file diff --git a/views/question_create.html.twig b/views/question_create.html.twig deleted file mode 100644 index afd7928..0000000 --- a/views/question_create.html.twig +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "main_layout.html.twig" %} - -{% block content %} -
- Вопрос:
-

- - - -
-{% endblock %} \ No newline at end of file diff --git a/views/user_create.html.twig b/views/user_create.html.twig deleted file mode 100644 index 45d4e71..0000000 --- a/views/user_create.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "main_layout.html.twig" %} - -{% block content %} -
- Логин:
-

- - Пароль:
-

- - Email адрес:
-

- - - -
-{% endblock %} \ No newline at end of file diff --git a/views/user_table.html.twig b/views/user_table.html.twig deleted file mode 100644 index 32b5450..0000000 --- a/views/user_table.html.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "main_layout.html.twig" %} - -{% block content %} - {{ table() }} -{% endblock %} \ No newline at end of file diff --git a/views/user_update.html.twig b/views/user_update.html.twig deleted file mode 100644 index 65a46f6..0000000 --- a/views/user_update.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "main_layout.html.twig" %} - -{% block content %} -
- Логин:
-

- - Пароль:
-

- - Email адрес:
-

- - - -
-{% endblock %} \ No newline at end of file diff --git a/views/widgets/admin/menu.php b/views/widgets/admin/menu.php index 54ddc6d..fe5773b 100644 --- a/views/widgets/admin/menu.php +++ b/views/widgets/admin/menu.php @@ -5,13 +5,13 @@ ?>