Added function to deactivate post
This commit is contained in:
parent
61060dd393
commit
1381593163
@ -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('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,12 +37,17 @@ 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);
|
||||
$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();
|
||||
}
|
||||
|
@ -72,4 +72,17 @@
|
||||
|
||||
<button type="submit">Edit</button>
|
||||
</form>
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" name="id" value="{{ post.id }}">
|
||||
|
||||
<!-- Method -->
|
||||
<input type="hidden" name="_method" value="delete">
|
||||
|
||||
<!-- Token -->
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<button type="submit">Nonaktif</button>
|
||||
{% endfor %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user