From 8fec9af2fa76f34d0d6e958d4c2ac4ffbb72a971 Mon Sep 17 00:00:00 2001 From: filip <25711588+Filip10@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:29:05 +0100 Subject: [PATCH] =?UTF-8?q?=C3=BAprava=20n=C3=A1zvu=20triedy=20aby=20to=20?= =?UTF-8?q?fungovalo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Controllers/PostController.php | 63 ++++++++++++++++++++++-- App/Models/Post.php | 11 +++++ App/Views/Admin/edit.view.php | 48 ++++++++++++++++++ App/Views/Admin/pridajPrispevok.view.php | 20 -------- App/Views/Home/ostatne.view.php | 6 ++- public/js/negative-number.js | 18 +++++++ 6 files changed, 142 insertions(+), 24 deletions(-) create mode 100644 App/Views/Admin/edit.view.php delete mode 100644 App/Views/Admin/pridajPrispevok.view.php create mode 100644 public/js/negative-number.js diff --git a/App/Controllers/PostController.php b/App/Controllers/PostController.php index 15f6e2f..3d94933 100644 --- a/App/Controllers/PostController.php +++ b/App/Controllers/PostController.php @@ -3,7 +3,10 @@ namespace App\Controllers; use App\Core\AControllerBase; +use App\Core\HTTPException; +use App\Core\Responses\RedirectResponse; use App\Core\Responses\Response; +use App\Helpers\FileStorage; use App\Models\Post; class PostController extends AControllerBase @@ -12,7 +15,36 @@ public function index(): Response { return $this->html(); } - public function add() : Response + + public function authorize(string $action) + { + $id = $this->request()->getValue('id'); + + if ($id && ($action == "save" || $action == "delete")) { + + $post = Post::getOne($id); + return $this->app->getAuth()->getLoggedUserName() == $post->getAuthor(); + + + } + + return $this->app->getAuth()->isLogged(); + } + + public function save() + { + $id = (int)$this->request()->getValue('id'); + + + $post = new Post(); + $post->setAutor($this->app->getAuth()->getLoggedUserName()); + $post->setNazov($this->request()->getValue('nazov')); + $post->setPopis($this->request()->getValue('popis')); + $post->setDatumPublikovania($this->request()->getValue('datumPublikovania')); + $post->setZdroj($this->request()->getValue('zdroj')); + } + + public function add(): Response { if ($this->request()->getValue('text')) { @@ -29,8 +61,33 @@ public function add() : Response return $this->html(); } - public function edit() : response { + public function edit(): Response + { + $id = (int)$this->request()->getValue('id'); + $post = Post::getOne($id); - return $this->html(); + if (is_null($post)) { + throw new HTTPException(404); + } + + return $this->html( + [ + 'post' => $post + ] + ); + } + + public function delete() + { + $id = (int)$this->request()->getValue('id'); + $post = Post::getOne($id); + +// if (is_null($post)) { +// throw new HTTPException(404); +// } else { +// FileStorage::deleteFile($post->getPicture()); +// $post->delete(); +// return new RedirectResponse($this->url("home.index")); +// } } } \ No newline at end of file diff --git a/App/Models/Post.php b/App/Models/Post.php index 09c33fd..fdf184c 100644 --- a/App/Models/Post.php +++ b/App/Models/Post.php @@ -12,6 +12,17 @@ class Post extends Model protected string $popis; protected string $datumPublikovania; protected string $zdroj; + protected string $autor; + + public function getAutor(): string + { + return $this->autor; + } + + public function setAutor(string $autor): void + { + $this->autor = $autor; + } public function getId(): int { diff --git a/App/Views/Admin/edit.view.php b/App/Views/Admin/edit.view.php new file mode 100644 index 0000000..d6a173f --- /dev/null +++ b/App/Views/Admin/edit.view.php @@ -0,0 +1,48 @@ + + + + + + +
+ + + + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
diff --git a/App/Views/Admin/pridajPrispevok.view.php b/App/Views/Admin/pridajPrispevok.view.php deleted file mode 100644 index 5b71e06..0000000 --- a/App/Views/Admin/pridajPrispevok.view.php +++ /dev/null @@ -1,20 +0,0 @@ - - -
-
-
-
- - - - - - -
-
-
-
-
\ No newline at end of file diff --git a/App/Views/Home/ostatne.view.php b/App/Views/Home/ostatne.view.php index 2a73f05..f51af23 100644 --- a/App/Views/Home/ostatne.view.php +++ b/App/Views/Home/ostatne.view.php @@ -1,8 +1,9 @@ + isLogged() && $auth->getLoggedUserName()) { ?> + Upraviť +