Administrator can remove posts
This commit is contained in:
parent
086edebd41
commit
94d4a76ec6
@ -154,7 +154,9 @@ class Posts
|
|||||||
['id', '=', $editor]
|
['id', '=', $editor]
|
||||||
], $table);
|
], $table);
|
||||||
|
|
||||||
$editor_now = Session::get('userid');
|
$editor_now = $this->model->showAll([
|
||||||
|
['id', '=', Session::get('userid')]
|
||||||
|
], $table);
|
||||||
|
|
||||||
$date = new \DateTime();
|
$date = new \DateTime();
|
||||||
$timestamp = $date->format("Y-m-d");
|
$timestamp = $date->format("Y-m-d");
|
||||||
@ -310,4 +312,18 @@ class Posts
|
|||||||
}
|
}
|
||||||
die();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,4 +241,20 @@ class Post extends \Core\Model
|
|||||||
throw new \Exception($e->getMessage(), 444);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
{{ editor.full_name }}
|
{{ editor.full_name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
<input type="hidden" name="editor" value="{{ editor_now }}">
|
<input type="hidden" name="editor" value="{{ editor_now.id }}">
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -101,7 +101,7 @@
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
{% if (post.status == 0 or post.status == 3 or editor_now != creator.id) %}
|
{% if (post.status == 0 or post.status == 3 or editor_now.id != creator.id) %}
|
||||||
disabled
|
disabled
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>
|
>
|
||||||
@ -109,7 +109,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if (post.status == 1 and editor_now == creator.id) %}
|
{% if (post.status == 1 and editor_now.id == creator.id) %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<input type="hidden" name="id" value="{{ post.id }}">
|
<input type="hidden" name="id" value="{{ post.id }}">
|
||||||
|
|
||||||
@ -122,4 +122,18 @@
|
|||||||
<button type="submit">Nonaktifkan</button>
|
<button type="submit">Nonaktifkan</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if editor_now.privilage == 1 %}
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="id" value="{{ post.id }}">
|
||||||
|
|
||||||
|
<!-- Method -->
|
||||||
|
<input type="hidden" name="_method" value="remove">
|
||||||
|
|
||||||
|
<!-- Token -->
|
||||||
|
<input type="hidden" name="_token" value="{{ token }}">
|
||||||
|
|
||||||
|
<button type="submit" style="background-color: red; color: #FFF;">Remove</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
{% if status %}
|
{% if status %}
|
||||||
<a href="/posts/entry">+ Tambah Pengumuman</a>
|
<a href="/posts/entry">+ Tambah Pengumuman</a>
|
||||||
<a href="/posts/category">+ Tambah Kategori</a>
|
<a href="/posts/category">+ Tambah Kategori</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user