Now can reactivate a nonactive category
This commit is contained in:
parent
aa3fbd72d5
commit
882e635081
@ -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('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,21 @@
|
||||
<li>{{ cat.category }}
|
||||
<form method="post">
|
||||
<input type="hidden" name="id" value="{{ cat.id }}">
|
||||
<input type="hidden" name="_method" value="delete">
|
||||
{% if cat.status == 1 %}
|
||||
<input type="hidden" name="_method" value="delete">
|
||||
{% elseif cat.status == 0 %}
|
||||
<input type="hidden" name="_method" value="put">
|
||||
{% endif %}
|
||||
<input type="hidden" name="_addon" value="kategori">
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<button type="submit"
|
||||
{% if cat.status != 1 %}
|
||||
disabled
|
||||
{% endif %}>
|
||||
Nonaktifkan
|
||||
</button>
|
||||
{% if cat.status == 1 %}
|
||||
<button type="submit">Nonaktifkan</button>
|
||||
{% elseif cat.status == 0 %}
|
||||
<button type="submit">Aktifkan</button>
|
||||
{% else %}
|
||||
<code>Nonaktif</code>
|
||||
{% endif %}
|
||||
</form>
|
||||
</li><br>
|
||||
{% endfor %}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user