From 94d4a76ec62d3e687ee3dad6f3807541af3f684b Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Putra Date: Sat, 9 Sep 2017 14:07:53 +0700 Subject: [PATCH] Administrator can remove posts --- App/Controllers/Posts.php | 18 +++++++++++++++++- App/Models/Post.php | 16 ++++++++++++++++ App/Views/Data/edit_pengumuman.html | 20 +++++++++++++++++--- App/Views/Data/pengumuman.html | 2 ++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index 44fe10e..f54ec05 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -154,7 +154,9 @@ class Posts ['id', '=', $editor] ], $table); - $editor_now = Session::get('userid'); + $editor_now = $this->model->showAll([ + ['id', '=', Session::get('userid')] + ], $table); $date = new \DateTime(); $timestamp = $date->format("Y-m-d"); @@ -310,4 +312,18 @@ class Posts } die(); } + + public function remove($args = []) + { + $id = $args['id']; + if ($this->model->remove($id) == true) { + $info = 'Data berhasil dihapus'; + } else { + $info = 'Terjadi kesalahan. Silahkan coba lagi dalam beberapa saat.'; + } + + Session::flash('info', $info); + Redirect::to('/'); + die(); + } } diff --git a/App/Models/Post.php b/App/Models/Post.php index 7870c2d..716cceb 100644 --- a/App/Models/Post.php +++ b/App/Models/Post.php @@ -241,4 +241,20 @@ class Post extends \Core\Model throw new \Exception($e->getMessage(), 444); } } + + public function remove($id) { + try { + $db = static::connectDB(); + + $sql = "DELETE FROM pengumuman WHERE id = ?"; + + $query = $db->prepare($sql); + $query->bindValue(1, $id); + $query->execute(); + return true; + } catch (PDOException $e) { + throw new \Exception($e->getMessage(), 444); + } + + } } diff --git a/App/Views/Data/edit_pengumuman.html b/App/Views/Data/edit_pengumuman.html index fa7a93a..06724f9 100644 --- a/App/Views/Data/edit_pengumuman.html +++ b/App/Views/Data/edit_pengumuman.html @@ -74,7 +74,7 @@ {{ editor.full_name }} {% endif %} - +
@@ -101,7 +101,7 @@
- {% if (post.status == 1 and editor_now == creator.id) %} + {% if (post.status == 1 and editor_now.id == creator.id) %}
@@ -122,4 +122,18 @@
{% endif %} + + {% if editor_now.privilage == 1 %} +
+ + + + + + + + + +
+ {% endif %} {% endblock %} diff --git a/App/Views/Data/pengumuman.html b/App/Views/Data/pengumuman.html index 082a7e4..20a125f 100644 --- a/App/Views/Data/pengumuman.html +++ b/App/Views/Data/pengumuman.html @@ -27,6 +27,8 @@ {% endif %} {% endfor %} +
+ {% if status %} + Tambah Pengumuman + Tambah Kategori