Changed model structure
This commit is contained in:
@@ -11,13 +11,11 @@ use \Core\Redirect;
|
||||
class Posts
|
||||
{
|
||||
private $post,
|
||||
$access,
|
||||
$table;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->post = new Post();
|
||||
$this->access = new Access();
|
||||
$this->model = new Post();
|
||||
$this->table = 'pengumuman';
|
||||
}
|
||||
|
||||
@@ -26,7 +24,7 @@ class Posts
|
||||
$date = new \DateTime();
|
||||
$now = $date->format("Y-m-d");
|
||||
|
||||
$valid = $this->post->showAll($this->table, [
|
||||
$valid = $this->model->showAll($this->table, [
|
||||
['valid_at', '<=', $now],
|
||||
['status', '!=', 3]
|
||||
]);
|
||||
@@ -34,11 +32,11 @@ class Posts
|
||||
foreach ($valid as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($this->table, ['status' => 1], $id);
|
||||
$this->model->update($this->table, ['status' => 1], $id);
|
||||
}
|
||||
}
|
||||
|
||||
$not_valid = $this->post->showAll($this->table, [
|
||||
$not_valid = $this->model->showAll($this->table, [
|
||||
['valid_at', '>', $now],
|
||||
['status', '!=', 3]
|
||||
]);
|
||||
@@ -46,11 +44,11 @@ class Posts
|
||||
foreach ($not_valid as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($this->table, ['status' => 2], $id);
|
||||
$this->model->update($this->table, ['status' => 2], $id);
|
||||
}
|
||||
}
|
||||
|
||||
$expired = $this->post->showAll($this->table, [
|
||||
$expired = $this->model->showAll($this->table, [
|
||||
['expired_at', '<', $now],
|
||||
['status', '!=', 3]
|
||||
]);
|
||||
@@ -58,7 +56,7 @@ class Posts
|
||||
foreach ($expired as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($this->table, ['status' => 0], $id);
|
||||
$this->model->update($this->table, ['status' => 0], $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +66,7 @@ class Posts
|
||||
{
|
||||
$this->checkValid();
|
||||
|
||||
$posts = $this->post->showAll($this->table, [
|
||||
$posts = $this->model->showAll($this->table, [
|
||||
['status', '=', 1]
|
||||
]);
|
||||
|
||||
@@ -77,7 +75,7 @@ class Posts
|
||||
$status = '';
|
||||
|
||||
if (Session::exists('userid')) {
|
||||
$posts = $this->post->showAll($this->table);
|
||||
$posts = $this->model->showAll($this->table);
|
||||
$status = 'admin';
|
||||
}
|
||||
|
||||
@@ -98,7 +96,9 @@ class Posts
|
||||
$date = new \DateTime();
|
||||
$now = $date->format("Y-m-d");
|
||||
|
||||
$categories = $this->post->showCategories();
|
||||
$this->table = 'kategori';
|
||||
|
||||
$categories = $this->model->showAll($this->table);
|
||||
|
||||
$user = Session::get('userid');
|
||||
|
||||
@@ -111,6 +111,7 @@ class Posts
|
||||
} else {
|
||||
throw new \Exception("Page not found", 404);
|
||||
}
|
||||
$this->table = 'pengumuman';
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
@@ -121,21 +122,25 @@ class Posts
|
||||
$id = implode('', $id);
|
||||
}
|
||||
|
||||
$categories = $this->post->showCategories();
|
||||
$categories = $this->model->showCategories();
|
||||
|
||||
$post = $this->post->showAll($this->table, [
|
||||
$post = $this->model->showAll($this->table, [
|
||||
['id', '=', $id]
|
||||
]);
|
||||
$creator = $post['creator'];
|
||||
$editor = $post['editor'];
|
||||
|
||||
$creator = $this->access->showAll($this->table, [
|
||||
$this->table = 'user';
|
||||
|
||||
$creator = $this->model->showAll($this->table, [
|
||||
['id', '=', $creator]
|
||||
]);
|
||||
$editor = $this->access->showAll($this->table, [
|
||||
$editor = $this->model->showAll($this->table, [
|
||||
['id', '=', $editor]
|
||||
]);
|
||||
|
||||
$this->table = 'pengumuman';
|
||||
|
||||
$editor_now = Session::get('userid');
|
||||
|
||||
$date = new \DateTime();
|
||||
@@ -162,7 +167,8 @@ class Posts
|
||||
public function category()
|
||||
{
|
||||
if (Session::exists('userid')) {
|
||||
$categories = $this->post->showCategories();
|
||||
$this->table = 'kategori';
|
||||
$categories = $this->model->showAll($this->table);
|
||||
|
||||
View::render('Data/kategori.html', [
|
||||
'categories' => $categories,
|
||||
@@ -171,6 +177,8 @@ class Posts
|
||||
} else {
|
||||
throw new \Exception("Bad request", 400);
|
||||
}
|
||||
|
||||
$this->table = 'pengumuman';
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
@@ -193,7 +201,7 @@ class Posts
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->post->entry($this->table, $args)) {
|
||||
if ($this->model->entry($this->table, $args)) {
|
||||
Session::flash('info', 'Data berhasil diunggah.');
|
||||
|
||||
if ($this->table == 'kategori') {
|
||||
@@ -212,7 +220,7 @@ class Posts
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
|
||||
$this->post->update($table, ['status' => 1], $args['id']);
|
||||
$this->model->update($table, ['status' => 1], $args['id']);
|
||||
|
||||
Session::flash('info', 'Data berhasil diaktifkan.');
|
||||
Redirect::to('/posts/category');
|
||||
@@ -249,7 +257,7 @@ class Posts
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->post->update($this->table, $args, $id)) {
|
||||
if ($this->model->update($this->table, $args, $id)) {
|
||||
Session::flash('info', 'Data berhasil diperbarui.');
|
||||
Redirect::to('/');
|
||||
} else {
|
||||
@@ -268,9 +276,9 @@ class Posts
|
||||
$id = $args['id'];
|
||||
|
||||
if ($this->table == 'kategori') {
|
||||
$delete = $this->post->delete($this->table, $id, 0);
|
||||
$delete = $this->model->delete($this->table, $id, 0);
|
||||
} else {
|
||||
$delete = $this->post->delete($this->table, $id);
|
||||
$delete = $this->model->delete($this->table, $id);
|
||||
}
|
||||
|
||||
if ($delete == true) {
|
||||
|
||||
Reference in New Issue
Block a user