Changed the way same data checker works
This commit is contained in:
@@ -166,20 +166,24 @@ class Posts
|
||||
// Methods
|
||||
public function post($args = [])
|
||||
{
|
||||
foreach ($args as $value) {
|
||||
if ($value == '') {
|
||||
Session::flash('info', 'All data must not be empty');
|
||||
Redirect::to('/');
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$table = 'pengumuman';
|
||||
if (isset($args['_addon'])) {
|
||||
$table = $args['_addon'];
|
||||
unset($args['_addon']);
|
||||
}
|
||||
|
||||
foreach ($args as $value) {
|
||||
if ($value == '') {
|
||||
Session::flash('info', 'All data must not be empty');
|
||||
if ($table == 'pengumuman') {
|
||||
Redirect::to('/posts/entry');
|
||||
} elseif ($table == 'kategori') {
|
||||
Redirect::to('/posts/category');
|
||||
}
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->post->entry($table, $args)) {
|
||||
Session::flash('info', 'Data successfuly uploaded');
|
||||
|
||||
@@ -200,11 +204,38 @@ class Posts
|
||||
$id = $args['id'];
|
||||
unset($args['id']);
|
||||
|
||||
// Check if data same with old data
|
||||
$old_data = [
|
||||
$args['old_category'],
|
||||
$args['old_content'],
|
||||
$args['old_valid_at'],
|
||||
$args['old_expired_at']
|
||||
];
|
||||
$new_data = [
|
||||
$args['category'],
|
||||
$args['content'],
|
||||
$args['valid_at'],
|
||||
$args['expired_at']
|
||||
];
|
||||
|
||||
if ($old_data == $new_data) {
|
||||
Session::flash('info', 'Data must not be same');
|
||||
Redirect::to("./$id");
|
||||
die();
|
||||
}
|
||||
|
||||
$keys = array_keys($args);
|
||||
if ($matches = preg_grep('/^old_/', $keys)) {
|
||||
foreach ($matches as $match) {
|
||||
unset($args[$match]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->post->update($table, $args, $id)) {
|
||||
Session::flash('info', 'Data successfuly updated');
|
||||
Redirect::to('/');
|
||||
} else {
|
||||
Session::flash('info', 'Error');
|
||||
Session::flash('info', 'Data cannot be uploaded');
|
||||
Redirect::to("./$id");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user