Added function to entry remove categories
This commit is contained in:
parent
01ce24fd39
commit
1ee4ca3730
@ -76,52 +76,74 @@ class Posts
|
||||
|
||||
public function entry()
|
||||
{
|
||||
$categories = $this->post->showCategories();
|
||||
if (Session::exists('userid')) {
|
||||
$categories = $this->post->showCategories();
|
||||
|
||||
$user = Session::get('userid');
|
||||
$user = Session::get('userid');
|
||||
|
||||
View::render('Data/entry_pengumuman.html', [
|
||||
'categories' => $categories,
|
||||
'user' => $user,
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
View::render('Data/entry_pengumuman.html', [
|
||||
'categories' => $categories,
|
||||
'user' => $user,
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if ($id) {
|
||||
if (is_array($id)) {
|
||||
$id = implode('', $id);
|
||||
}
|
||||
if (Session::exists('userid')) {
|
||||
if ($id) {
|
||||
if (is_array($id)) {
|
||||
$id = implode('', $id);
|
||||
}
|
||||
|
||||
$categories = $this->post->showCategories();
|
||||
|
||||
$post = $this->post->showSingle($id);
|
||||
$creator = $post['creator'];
|
||||
$editor = $post['editor'];
|
||||
|
||||
$creator = $this->access->showSingle($creator);
|
||||
$editor = $this->access->showSingle($editor);
|
||||
|
||||
$editor_now = Session::get('userid');
|
||||
|
||||
$date = new \DateTime();
|
||||
$timestamp = $date->format("Y-m-d");
|
||||
|
||||
View::render(
|
||||
'Data/edit_pengumuman.html',
|
||||
[
|
||||
'post' => $post,
|
||||
'categories' => $categories,
|
||||
'creator' => $creator,
|
||||
'editor' => $editor,
|
||||
'editor_now' => $editor_now,
|
||||
'timestamp' => $timestamp,
|
||||
'token' => Token::generate()
|
||||
]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
$categories = $this->post->showCategories();
|
||||
|
||||
$post = $this->post->showSingle($id);
|
||||
$creator = $post['creator'];
|
||||
$editor = $post['editor'];
|
||||
|
||||
$creator = $this->access->showSingle($creator);
|
||||
$editor = $this->access->showSingle($editor);
|
||||
|
||||
$editor_now = Session::get('userid');
|
||||
|
||||
$date = new \DateTime();
|
||||
$timestamp = $date->format("Y-m-d");
|
||||
|
||||
View::render(
|
||||
'Data/edit_pengumuman.html',
|
||||
[
|
||||
'post' => $post,
|
||||
'categories' => $categories,
|
||||
'creator' => $creator,
|
||||
'editor' => $editor,
|
||||
'editor_now' => $editor_now,
|
||||
'timestamp' => $timestamp,
|
||||
'token' => Token::generate()
|
||||
]
|
||||
);
|
||||
View::render('Data/kategori.html', [
|
||||
'categories' => $categories,
|
||||
'token' => Token::generate()
|
||||
]);
|
||||
} else {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,10 +151,19 @@ class Posts
|
||||
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');
|
||||
Redirect::to('/');
|
||||
|
||||
if ($table = 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
} elseif ($table = 'pengumuman') {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
Redirect::to('/');
|
||||
|
||||
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