Added function to entry remove categories
This commit is contained in:
parent
01ce24fd39
commit
1ee4ca3730
@ -76,6 +76,7 @@ class Posts
|
||||
|
||||
public function entry()
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
$categories = $this->post->showCategories();
|
||||
|
||||
$user = Session::get('userid');
|
||||
@ -87,10 +88,14 @@ class Posts
|
||||
]);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
if ($id) {
|
||||
if (is_array($id)) {
|
||||
$id = implode('', $id);
|
||||
@ -123,18 +128,44 @@ class Posts
|
||||
]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
$categories = $this->post->showCategories();
|
||||
|
||||
View::render('Data/kategori.html', [
|
||||
'categories' => $categories,
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
// Methods
|
||||
public function post($args = [])
|
||||
{
|
||||
$table = 'pengumuman';
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
}
|
||||
|
||||
if ($this->post->entry($table, $args)) {
|
||||
Session::flash('info', 'Data successfuly uploaded');
|
||||
|
||||
if ($table = 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
} elseif ($table = 'pengumuman') {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function put($args = [])
|
||||
{
|
||||
@ -154,12 +185,21 @@ class Posts
|
||||
public function delete($args = [])
|
||||
{
|
||||
$table = 'pengumuman';
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
}
|
||||
|
||||
$id = $args['id'];
|
||||
|
||||
if ($this->post->delete($table, $id)) {
|
||||
Session::flash('info', 'Data successfuly removed');
|
||||
|
||||
if ($table = 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
} elseif ($table = 'pengumuman') {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ class Post extends \Core\Model
|
||||
[
|
||||
'id int(3) NOT NULL AUTO_INCREMENT',
|
||||
'category varchar(20) NOT NULL',
|
||||
'status tinyint NOT NULL DEFAULT 1',
|
||||
'PRIMARY KEY (id)'
|
||||
]
|
||||
);
|
||||
@ -88,7 +89,7 @@ class Post extends \Core\Model
|
||||
try {
|
||||
$db = static::connectDB();
|
||||
|
||||
$sql = "SELECT * FROM kategori";
|
||||
$sql = "SELECT * FROM kategori WHERE status = 1";
|
||||
|
||||
$query = $db->prepare($sql);
|
||||
|
||||
|
36
App/Views/Data/kategori.html
Normal file
36
App/Views/Data/kategori.html
Normal file
@ -0,0 +1,36 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Kategori{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<p>List Kategori:</p>
|
||||
<ul>
|
||||
{% for cat in categories %}
|
||||
<li>{{ cat.category }}
|
||||
<form method="post">
|
||||
<input type="hidden" name="id" value="{{ cat.id }}">
|
||||
<input type="hidden" name="_method" value="delete">
|
||||
<input type="hidden" name="_addon" value="kategori">
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<button type="submit">Remove</button>
|
||||
</form>
|
||||
</li><br>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<form method="post">
|
||||
<label for="category">Tambah</label>
|
||||
<input type="text" name="category" value="" placeholder="Kategori">
|
||||
|
||||
<input type="hidden" name="_method" value="post">
|
||||
|
||||
<input type="hidden" name="_addon" value="kategori">
|
||||
|
||||
<input type="hidden" name="_token" value="{{ token }}">
|
||||
|
||||
<button type="submit">Entry</button>
|
||||
</form>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
@ -24,6 +24,7 @@
|
||||
|
||||
{% if status %}
|
||||
<a href="/posts/entry">+ Tambah Pengumuman</a>
|
||||
<a href="/posts/category">+ Tambah Kategori</a>
|
||||
<a href="/logout">Logout</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user