diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index f777a30..f94333e 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -209,6 +209,14 @@ class Posts public function put($args = []) { + if (isset($args['_addon'])) { + $table = $args['_addon']; + + $this->post->update($table, ['status' => 1], $args['id']); + + Session::flash('info', 'Data berhasil diaktifkan.'); + Redirect::to('/posts/category'); + } $args['content'] = htmlspecialchars($args['content']); $id = $args['id']; @@ -259,17 +267,26 @@ class Posts $id = $args['id']; - if ($this->post->delete($this->table, $id)) { - Session::flash('info', 'Data berhasil di nonaktifkan'); - - if ($this->table = 'kategori') { - Redirect::to('/posts/category'); - } elseif ($this->table = 'pengumuman') { - Redirect::to('/'); - } + if ($this->table == 'kategori') { + $delete = $this->post->delete($this->table, $id, 0); + } else { + $delete = $this->post->delete($this->table, $id); } + if ($delete == true) { + $info = 'Data berhasil dinonaktifkan.'; + } else { + $info = 'Terjadi kesalahan. Silahkan coba lagi dalam beberapa saat.'; + } // Return the $table back to default $this->table = 'pengumuman'; + + Session::flash('info', $info); + + if ($this->table = 'kategori') { + Redirect::to('/posts/category'); + } elseif ($this->table = 'pengumuman') { + Redirect::to('/'); + } } } diff --git a/App/Views/Data/kategori.html b/App/Views/Data/kategori.html index 100e0ff..0e03b83 100644 --- a/App/Views/Data/kategori.html +++ b/App/Views/Data/kategori.html @@ -9,16 +9,21 @@
  • {{ cat.category }}
    - + {% if cat.status == 1 %} + + {% elseif cat.status == 0 %} + + {% endif %} - + {% if cat.status == 1 %} + + {% elseif cat.status == 0 %} + + {% else %} + Nonaktif + {% endif %}

  • {% endfor %} diff --git a/Core/Model.php b/Core/Model.php index de80a74..132d877 100644 --- a/Core/Model.php +++ b/Core/Model.php @@ -220,7 +220,7 @@ abstract class Model } } - public function delete($table, $id) + public function delete($table, $id, $force = '') { try { $db = static::connectDB(); @@ -228,7 +228,11 @@ abstract class Model $sql = "UPDATE {$table} SET status = ? WHERE id = ?"; $query = $db->prepare($sql); - $query->bindValue(1, 3); + if (is_int($force)) { + $query->bindValue(1, $force); + } else { + $query->bindValue(1, 3); + } $query->bindValue(2, $id); $query->execute();