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