From 70e806f0f8f3f5b839e1b024b6a4c2cbfa5ac093 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 17 Apr 2018 15:31:09 +0200 Subject: [PATCH] Add admin ContentController --- Changelog | 1 + .../Controllers/Admin/ContentController.php | 135 ++++++++++++++++++ public/admin/content-add.php | 78 ---------- public/admin/content-delete.php | 13 -- public/admin/content-list.php | 17 --- routes/web.php | 7 + 6 files changed, 143 insertions(+), 108 deletions(-) create mode 100644 app/Http/Controllers/Admin/ContentController.php delete mode 100644 public/admin/content-add.php delete mode 100644 public/admin/content-delete.php delete mode 100644 public/admin/content-list.php diff --git a/Changelog b/Changelog index c48fc8911..8c4dfef32 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-17 DariusIII + * Chg: Add admin ContentController * Chg: Add admin RoleController * Chg: Add admin SiteController * Chg: Add admin UserController diff --git a/app/Http/Controllers/Admin/ContentController.php b/app/Http/Controllers/Admin/ContentController.php new file mode 100644 index 000000000..a097d0c47 --- /dev/null +++ b/app/Http/Controllers/Admin/ContentController.php @@ -0,0 +1,135 @@ +setAdminPrefs(); + $contents = new Contents(); + $contentList = $contents->getAll(); + $this->smarty->assign('contentlist', $contentList); + + $title = 'Content List'; + + $content = $this->smarty->fetch('content-list.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @throws \Exception + */ + public function create(Request $request) + { + $this->setAdminPrefs(); + $contents = new Contents(); + + // Set the current action. + $action = $request->input('action') ?? 'view'; + + $content = [ + 'id' => '', + 'title' => '', + 'url' => '', + 'body' => '', + 'metadescription' => '', + 'metakeywords' => '', + 'contenttype' => '', + 'showinmenu' => '', + 'status' => '', + 'ordinal' => '', + 'created_at' => '', + 'role' => '', + ]; + + switch ($action) { + case 'add': + $title = 'Content Add'; + $content['showinmenu'] = '1'; + $content['status'] = '1'; + $content['contenttype'] = '2'; + break; + + case 'submit': + // Validate and add or update. + if (! $request->has('id')) { + $returnid = $contents->add($request->all()); + } else { + $content = $contents->update($request->all()); + $returnid = $content['id']; + } + return redirect('content-add.php?id='.$returnid); + break; + + case 'view': + default: + if ($request->has('id')) { + $title = 'Content Edit'; + $id = $request->input('id'); + + $content = $contents->getByID($id, User::ROLE_ADMIN); + } + break; + } + + $this->smarty->assign('status_ids', [1, 0]); + $this->smarty->assign('status_names', ['Enabled', 'Disabled']); + + $this->smarty->assign('yesno_ids', [1, 0]); + $this->smarty->assign('yesno_names', ['Yes', 'No']); + + $contenttypelist = ['1' => 'Useful Link', '2' => 'Article', '3' => 'Homepage']; + $this->smarty->assign('contenttypelist', $contenttypelist); + + $this->smarty->assign('content', $content); + + $rolelist = ['0' => 'Everyone', '1' => 'Logged in Users', '2' => 'Admins']; + $this->smarty->assign('rolelist', $rolelist); + + $content = $this->smarty->fetch('content-add.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function destroy(Request $request) + { + if ($request->has('id')) { + $contents = new Contents(); + $contents->delete($request->input('id')); + } + + $referrer = $request->server('HTTP_REFERER'); + return redirect($referrer); + } +} diff --git a/public/admin/content-add.php b/public/admin/content-add.php deleted file mode 100644 index e17dd7b39..000000000 --- a/public/admin/content-add.php +++ /dev/null @@ -1,78 +0,0 @@ -setAdminPrefs(); -$contents = new Contents(); -$id = 0; - -// Set the current action. -$action = request()->input('action') ?? 'view'; - -$content = [ - 'id' => '', - 'title' => '', - 'url' => '', - 'body' => '', - 'metadescription' => '', - 'metakeywords' => '', - 'contenttype' => '', - 'showinmenu' => '', - 'status' => '', - 'ordinal' => '', - 'created_at' => '', - 'role' => '', -]; - -switch ($action) { - case 'add': - $page->title = 'Content Add'; - $content['showinmenu'] = '1'; - $content['status'] = '1'; - $content['contenttype'] = '2'; - break; - - case 'submit': - // Validate and add or update. - $returnid = 0; - if (! request()->has('id')) { - $returnid = $contents->add(request()->all()); - } else { - $content = $contents->update(request()->all()); - $returnid = $content['id']; - } - header('Location:'.WWW_TOP.'/content-add.php?id='.$returnid); - break; - - case 'view': - default: - if (request()->has('id')) { - $page->title = 'Content Edit'; - $id = request()->input('id'); - - $content = $contents->getByID($id, User::ROLE_ADMIN); - } - break; -} - -$page->smarty->assign('status_ids', [1, 0]); -$page->smarty->assign('status_names', ['Enabled', 'Disabled']); - -$page->smarty->assign('yesno_ids', [1, 0]); -$page->smarty->assign('yesno_names', ['Yes', 'No']); - -$contenttypelist = ['1' => 'Useful Link', '2' => 'Article', '3' => 'Homepage']; -$page->smarty->assign('contenttypelist', $contenttypelist); - -$page->smarty->assign('content', $content); - -$rolelist = ['0' => 'Everyone', '1' => 'Logged in Users', '2' => 'Admins']; -$page->smarty->assign('rolelist', $rolelist); - -$page->content = $page->smarty->fetch('content-add.tpl'); -$page->adminrender(); diff --git a/public/admin/content-delete.php b/public/admin/content-delete.php deleted file mode 100644 index f2d35688d..000000000 --- a/public/admin/content-delete.php +++ /dev/null @@ -1,13 +0,0 @@ -has('id')) { - $contents = new Contents(); - $contents->delete(request()->input('id')); -} - -$referrer = request()->server('HTTP_REFERER'); -header('Location: '.$referrer); diff --git a/public/admin/content-list.php b/public/admin/content-list.php deleted file mode 100644 index ab4f4353d..000000000 --- a/public/admin/content-list.php +++ /dev/null @@ -1,17 +0,0 @@ -setAdminPrefs(); -$contents = new Contents(); -$contentlist = $contents->getAll(); -$page->smarty->assign('contentlist', $contentlist); - -$page->title = 'Content List'; - -$page->content = $page->smarty->fetch('content-list.tpl'); -$page->adminrender(); diff --git a/routes/web.php b/routes/web.php index 4d18ea95a..2047fff36 100644 --- a/routes/web.php +++ b/routes/web.php @@ -231,4 +231,11 @@ Route::prefix('admin')->group(function () { Route::post('role-edit', 'Admin\RoleController@edit'); Route::get('role-delete', 'Admin\RoleController@destroy'); Route::post('role-delete', 'Admin\RoleController@destroy'); + Route::get('content-list', 'Admin\ContentController@index'); + Route::post('content-list', 'Admin\ContentController@index'); + Route::get('content-add', 'Admin\ContentController@create'); + Route::post('content-add', 'Admin\ContentController@create'); + Route::get('content-delete', 'Admin\ContentController@destroy'); + Route::post('content-delete', 'Admin\ContentController@destroy'); + });