Added admin privilages
This commit is contained in:
parent
a4db3c8391
commit
57dc4ca0b9
@ -41,4 +41,11 @@ class Home
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
if ($this->access->logout()) {
|
||||||
|
Redirect::to('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,17 @@ class Posts
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$posts = $this->post->showAll();
|
$posts = $this->post->showAll(['status' => 1]);
|
||||||
|
$url = 'Data/pengumuman.html';
|
||||||
|
$status = '';
|
||||||
// echo "This is index of posts."; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
// echo "This is index of posts."; // Nanti di replace sama twig view ke App\Views\Data\pengumuman.html
|
||||||
View::render('Data/pengumuman.html', [
|
if (Session::exists('userid')) {
|
||||||
'posts' => $posts
|
$posts = $this->post->showAll();
|
||||||
|
$status = 'admin';
|
||||||
|
}
|
||||||
|
View::render($url, [
|
||||||
|
'posts' => $posts,
|
||||||
|
'status' => $status
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -99,4 +99,21 @@ class Access extends \Core\Model
|
|||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
$id = \Core\Session::get('userid');
|
||||||
|
if ($this->update(
|
||||||
|
'user',
|
||||||
|
['status' => 0],
|
||||||
|
$id
|
||||||
|
)) {
|
||||||
|
\Core\Session::delete('userid');
|
||||||
|
\Core\Session::delete('username');
|
||||||
|
\Core\Session::delete('name');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,24 @@ class Post extends \Core\Model
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showAll()
|
public function showAll($conds = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$db = static::connectDB();
|
$db = static::connectDB();
|
||||||
|
|
||||||
$sql = "SELECT * FROM pengumuman ORDER BY created_at";
|
$sql = "SELECT * FROM pengumuman";
|
||||||
|
|
||||||
|
if ($conds) {
|
||||||
|
$key = implode('', array_keys($conds));
|
||||||
|
$sql .= " WHERE {$key} = ?";
|
||||||
|
}
|
||||||
|
|
||||||
$query = $db->prepare($sql);
|
$query = $db->prepare($sql);
|
||||||
|
|
||||||
|
if ($conds) {
|
||||||
|
$query->bindValue(1, implode('', array_values($conds)));
|
||||||
|
}
|
||||||
|
|
||||||
if ($query->execute()) {
|
if ($query->execute()) {
|
||||||
if ($query->rowCount() != 0) {
|
if ($query->rowCount() != 0) {
|
||||||
$result = $query->fetchAll(\PDO::FETCH_ASSOC);
|
$result = $query->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<h3>Pengumuman {{ post.id }}</h3>
|
<h3>Pengumuman {{ post.id }}</h3>
|
||||||
|
{% if status %}
|
||||||
<a href="/posts/edit/{{ post.id }}">
|
<a href="/posts/edit/{{ post.id }}">
|
||||||
{% if post.status == 1 %}
|
{% if post.status == 1 %}
|
||||||
Edit
|
Edit
|
||||||
@ -15,8 +16,12 @@
|
|||||||
<strike>Edit</strike>
|
<strike>Edit</strike>
|
||||||
</a> (Nonaktif)
|
</a> (Nonaktif)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
<p>{{ post.content }}</p>
|
<p>{{ post.content }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<a href="./posts/entry">+ Tambah Pengumuman</a>
|
{% if status %}
|
||||||
|
<a href="/posts/entry">+ Tambah Pengumuman</a>
|
||||||
|
<a href="/logout">Logout</a>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user