diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index 34d0a8c..2cccbdd 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -74,9 +74,19 @@ class Posts $table = 'pengumuman'; $id = $args['id']; unset($args['id']); - if ($this->model->update($table, $args, $id)) { + if ($this->post->update($table, $args, $id)) { Session::flash('info', 'Data successfuly updated'); - return $this->index(); + return $this->edit(); + } + } + + public function delete($args = []) + { + $table = 'pengumuman'; + $id = $args['id']; + if ($this->post->delete($table, $id)) { + Session::flash('info', 'Data successfuly removed'); + return \Core\Redirect::to('/'); } } } diff --git a/App/Models/Post.php b/App/Models/Post.php index 608d77f..3ceaa4f 100644 --- a/App/Models/Post.php +++ b/App/Models/Post.php @@ -37,11 +37,16 @@ class Post extends \Core\Model try { $db = static::connectDB(); - $sql = "SELECT * FROM pengumuman ORDER BY created_at"; + $sql = "SELECT * FROM pengumuman WHERE status = ? ORDER BY created_at"; - if ($stmt = $db->query($sql)) { - $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); - return $result; + $query = $db->prepare($sql); + $query->bindValue(1, 1); + + if ($query->execute()) { + if ($query->rowCount() != 0) { + $result = $query->fetchAll(\PDO::FETCH_ASSOC); + return $result; + } } } catch (PDOException $e) { echo $e->getMessage(); diff --git a/App/Views/Data/edit_pengumuman.html b/App/Views/Data/edit_pengumuman.html index 08b0757..f06435c 100644 --- a/App/Views/Data/edit_pengumuman.html +++ b/App/Views/Data/edit_pengumuman.html @@ -72,4 +72,17 @@ + +
+ + + + + + + + + + {% endfor %} +
{% endblock %} diff --git a/Core/Model.php b/Core/Model.php index f041d48..3b6f15b 100644 --- a/Core/Model.php +++ b/Core/Model.php @@ -169,11 +169,13 @@ abstract class Model try { $db = static::connectDB(); - $sql = "DELETE FROM {$table} WHERE id = ?"; + $sql = "UPDATE {$table} SET status = ? WHERE id = ?"; $query = $db->prepare($sql); + $query->bindValue(1, 0); + $query->bindValue(2, $id); - if ($query->execute([$id])) { + if ($query->execute()) { return true; } return false;