Added function to entry remove categories
This commit is contained in:
parent
01ce24fd39
commit
1ee4ca3730
@ -76,6 +76,7 @@ class Posts
|
|||||||
|
|
||||||
public function entry()
|
public function entry()
|
||||||
{
|
{
|
||||||
|
if (Session::exists('userid')) {
|
||||||
$categories = $this->post->showCategories();
|
$categories = $this->post->showCategories();
|
||||||
|
|
||||||
$user = Session::get('userid');
|
$user = Session::get('userid');
|
||||||
@ -87,10 +88,14 @@ class Posts
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
Redirect::to('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
|
if (Session::exists('userid')) {
|
||||||
if ($id) {
|
if ($id) {
|
||||||
if (is_array($id)) {
|
if (is_array($id)) {
|
||||||
$id = implode('', $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
|
// Methods
|
||||||
public function post($args = [])
|
public function post($args = [])
|
||||||
{
|
{
|
||||||
$table = 'pengumuman';
|
$table = 'pengumuman';
|
||||||
|
if (isset($args['_addon'])) {
|
||||||
|
$table = $args['_addon'];
|
||||||
|
unset($args['_addon']);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->post->entry($table, $args)) {
|
if ($this->post->entry($table, $args)) {
|
||||||
Session::flash('info', 'Data successfuly uploaded');
|
Session::flash('info', 'Data successfuly uploaded');
|
||||||
|
|
||||||
|
if ($table = 'kategori') {
|
||||||
|
Redirect::to('/posts/category');
|
||||||
|
} elseif ($table = 'pengumuman') {
|
||||||
Redirect::to('/');
|
Redirect::to('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function put($args = [])
|
public function put($args = [])
|
||||||
{
|
{
|
||||||
@ -154,12 +185,21 @@ class Posts
|
|||||||
public function delete($args = [])
|
public function delete($args = [])
|
||||||
{
|
{
|
||||||
$table = 'pengumuman';
|
$table = 'pengumuman';
|
||||||
|
if (isset($args['_addon'])) {
|
||||||
|
$table = $args['_addon'];
|
||||||
|
unset($args['_addon']);
|
||||||
|
}
|
||||||
|
|
||||||
$id = $args['id'];
|
$id = $args['id'];
|
||||||
|
|
||||||
if ($this->post->delete($table, $id)) {
|
if ($this->post->delete($table, $id)) {
|
||||||
Session::flash('info', 'Data successfuly removed');
|
Session::flash('info', 'Data successfuly removed');
|
||||||
|
|
||||||
|
if ($table = 'kategori') {
|
||||||
|
Redirect::to('/posts/category');
|
||||||
|
} elseif ($table = 'pengumuman') {
|
||||||
Redirect::to('/');
|
Redirect::to('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ class Post extends \Core\Model
|
|||||||
[
|
[
|
||||||
'id int(3) NOT NULL AUTO_INCREMENT',
|
'id int(3) NOT NULL AUTO_INCREMENT',
|
||||||
'category varchar(20) NOT NULL',
|
'category varchar(20) NOT NULL',
|
||||||
|
'status tinyint NOT NULL DEFAULT 1',
|
||||||
'PRIMARY KEY (id)'
|
'PRIMARY KEY (id)'
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -88,7 +89,7 @@ class Post extends \Core\Model
|
|||||||
try {
|
try {
|
||||||
$db = static::connectDB();
|
$db = static::connectDB();
|
||||||
|
|
||||||
$sql = "SELECT * FROM kategori";
|
$sql = "SELECT * FROM kategori WHERE status = 1";
|
||||||
|
|
||||||
$query = $db->prepare($sql);
|
$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 %}
|
{% 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="/logout">Logout</a>
|
<a href="/logout">Logout</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user