Changed login/logout process
This commit is contained in:
@@ -11,12 +11,14 @@ use \Core\Redirect;
|
||||
class Posts
|
||||
{
|
||||
private $post,
|
||||
$access;
|
||||
$access,
|
||||
$table;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->post = new Post();
|
||||
$this->access = new Access();
|
||||
$this->table = 'pengumuman';
|
||||
}
|
||||
|
||||
public function checkValid()
|
||||
@@ -24,9 +26,7 @@ class Posts
|
||||
$date = new \DateTime();
|
||||
$now = $date->format("Y-m-d");
|
||||
|
||||
$table = 'pengumuman';
|
||||
|
||||
$valid = $this->post->showAll([
|
||||
$valid = $this->post->showAll($this->table, [
|
||||
['valid_at', '<=', $now],
|
||||
['status', '!=', 3]
|
||||
]);
|
||||
@@ -34,11 +34,11 @@ class Posts
|
||||
foreach ($valid as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($table, ['status' => 1], $id);
|
||||
$this->post->update($this->table, ['status' => 1], $id);
|
||||
}
|
||||
}
|
||||
|
||||
$not_valid = $this->post->showAll([
|
||||
$not_valid = $this->post->showAll($this->table, [
|
||||
['valid_at', '>', $now],
|
||||
['status', '!=', 3]
|
||||
]);
|
||||
@@ -46,11 +46,11 @@ class Posts
|
||||
foreach ($not_valid as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($table, ['status' => 2], $id);
|
||||
$this->post->update($this->table, ['status' => 2], $id);
|
||||
}
|
||||
}
|
||||
|
||||
$expired = $this->post->showAll([
|
||||
$expired = $this->post->showAll($this->table, [
|
||||
['expired_at', '<', $now],
|
||||
['status', '!=', 3]
|
||||
]);
|
||||
@@ -58,16 +58,17 @@ class Posts
|
||||
foreach ($expired as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($table, ['status' => 0], $id);
|
||||
$this->post->update($this->table, ['status' => 0], $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Routes */
|
||||
public function index()
|
||||
{
|
||||
$this->checkValid();
|
||||
|
||||
$posts = $this->post->showAll([
|
||||
$posts = $this->post->showAll($this->table, [
|
||||
['status', '=', 1]
|
||||
]);
|
||||
|
||||
@@ -76,7 +77,7 @@ class Posts
|
||||
$status = '';
|
||||
|
||||
if (Session::exists('userid')) {
|
||||
$posts = $this->post->showAll();
|
||||
$posts = $this->post->showAll($this->table);
|
||||
$status = 'admin';
|
||||
}
|
||||
|
||||
@@ -122,12 +123,18 @@ class Posts
|
||||
|
||||
$categories = $this->post->showCategories();
|
||||
|
||||
$post = $this->post->showSingle($id);
|
||||
$post = $this->post->showAll($this->table, [
|
||||
['id', '=', $id]
|
||||
]);
|
||||
$creator = $post['creator'];
|
||||
$editor = $post['editor'];
|
||||
|
||||
$creator = $this->access->showSingle($creator);
|
||||
$editor = $this->access->showSingle($editor);
|
||||
$creator = $this->access->showAll($this->table, [
|
||||
['id', '=', $creator]
|
||||
]);
|
||||
$editor = $this->access->showAll($this->table, [
|
||||
['id', '=', $editor]
|
||||
]);
|
||||
|
||||
$editor_now = Session::get('userid');
|
||||
|
||||
@@ -166,42 +173,42 @@ class Posts
|
||||
}
|
||||
}
|
||||
|
||||
// Methods
|
||||
/* Methods */
|
||||
public function post($args = [])
|
||||
{
|
||||
$table = 'pengumuman';
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
$this->table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
}
|
||||
|
||||
foreach ($args as $value) {
|
||||
if ($value == '') {
|
||||
Session::flash('info', 'All data must not be empty');
|
||||
if ($table == 'pengumuman') {
|
||||
if ($this->table == 'pengumuman') {
|
||||
Redirect::to('/posts/entry');
|
||||
} elseif ($table == 'kategori') {
|
||||
} elseif ($this->table == 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
}
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->post->entry($table, $args)) {
|
||||
if ($this->post->entry($this->table, $args)) {
|
||||
Session::flash('info', 'Data successfuly uploaded');
|
||||
|
||||
if ($table == 'kategori') {
|
||||
if ($this->table == 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
} elseif ($table == 'pengumuman') {
|
||||
} elseif ($this->table == 'pengumuman') {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
// Return the $table back to default
|
||||
$this->table = 'pengumuman';
|
||||
}
|
||||
|
||||
public function put($args = [])
|
||||
{
|
||||
$table = 'pengumuman';
|
||||
|
||||
$args['content'] = htmlspecialchars($args['content']);
|
||||
|
||||
$id = $args['id'];
|
||||
@@ -234,7 +241,7 @@ class Posts
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->post->update($table, $args, $id)) {
|
||||
if ($this->post->update($this->table, $args, $id)) {
|
||||
Session::flash('info', 'Data successfuly updated');
|
||||
Redirect::to('/');
|
||||
} else {
|
||||
@@ -245,22 +252,24 @@ class Posts
|
||||
|
||||
public function delete($args = [])
|
||||
{
|
||||
$table = 'pengumuman';
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
$this->table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
}
|
||||
|
||||
$id = $args['id'];
|
||||
|
||||
if ($this->post->delete($table, $id)) {
|
||||
if ($this->post->delete($this->table, $id)) {
|
||||
Session::flash('info', 'Data successfuly removed');
|
||||
|
||||
if ($table = 'kategori') {
|
||||
if ($this->table = 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
} elseif ($table = 'pengumuman') {
|
||||
} elseif ($this->table = 'pengumuman') {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
// Return the $table back to default
|
||||
$this->table = 'pengumuman';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user