Fix posts status issues
This commit is contained in:
parent
05f213045e
commit
6f65c067df
@ -19,27 +19,37 @@ class Posts
|
||||
$this->access = new Access();
|
||||
}
|
||||
|
||||
public function checkExpired()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$now = $date->format("Y-m-d");
|
||||
|
||||
if ($expired = $this->post->showAll('expired_at', '<', $now)) {
|
||||
foreach ($expired as $value) {
|
||||
$this->post->update('pengumuman', ['status' => 0], $value['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkValid()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$date = $date->setTime(0,0);
|
||||
$now = $date->format("Y-m-d");
|
||||
|
||||
if ($not_valid = $this->post->showAll('valid_at', '>', $now)) {
|
||||
foreach ($not_valid as $value) {
|
||||
$this->post->update('pengumuman', ['status' => 2], $value['id']);
|
||||
$table = 'pengumuman';
|
||||
|
||||
$valid = $this->post->showAll('valid_at', '<=', $now);
|
||||
if ($valid !== false) {
|
||||
foreach ($valid as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($table, ['status' => 1], $id);
|
||||
}
|
||||
}
|
||||
|
||||
$not_valid = $this->post->showAll('valid_at', '>', $now);
|
||||
if ($not_valid !== false) {
|
||||
foreach ($not_valid as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($table, ['status' => 2], $id);
|
||||
}
|
||||
}
|
||||
|
||||
$expired = $this->post->showAll('expired_at', '<', $now);
|
||||
if ($expired !== false) {
|
||||
foreach ($expired as $fields) {
|
||||
$id = $fields['id'];
|
||||
|
||||
$this->post->update($table, ['status' => 0], $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,7 +57,6 @@ class Posts
|
||||
public function index()
|
||||
{
|
||||
$this->checkValid();
|
||||
$this->checkExpired();
|
||||
|
||||
$posts = $this->post->showAll('status', '=', 1);
|
||||
|
||||
@ -162,9 +171,9 @@ class Posts
|
||||
if ($this->post->entry($table, $args)) {
|
||||
Session::flash('info', 'Data successfuly uploaded');
|
||||
|
||||
if ($table = 'kategori') {
|
||||
if ($table == 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
} elseif ($table = 'pengumuman') {
|
||||
} elseif ($table == 'pengumuman') {
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ abstract class Model
|
||||
try {
|
||||
$db = static::connectDB();
|
||||
|
||||
$result = $this->showAll();
|
||||
$result = $this->showAll('id', '=', $id);
|
||||
|
||||
foreach ($result as $post) {
|
||||
foreach ($post as $key => $val) {
|
||||
|
Loading…
Reference in New Issue
Block a user