- Added database validation
- Added valid date for posts - Fix passing data to htmls conflicts
This commit is contained in:
@@ -11,12 +11,14 @@ class Post extends \Core\Model
|
||||
[
|
||||
'id int(3) NOT NULL AUTO_INCREMENT',
|
||||
'category int(3) NOT NULL',
|
||||
'created_at timestamp DEFAULT CURRENT_TIMESTAMP',
|
||||
'expired_at timestamp NOT NULL',
|
||||
'created_at date NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||
'valid_at date NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||
'expired_at date NOT NULL',
|
||||
'creator int(3) NOT NULL',
|
||||
'edited_at timestamp',
|
||||
'editor timestamp',
|
||||
'edited_at date',
|
||||
'editor date',
|
||||
'content varchar(255) NOT NULL',
|
||||
'status tinyint NOT NULL DEFAULT 1',
|
||||
'PRIMARY KEY (id)'
|
||||
]
|
||||
);
|
||||
@@ -32,22 +34,21 @@ class Post extends \Core\Model
|
||||
);
|
||||
}
|
||||
|
||||
public function showAll($conds = [])
|
||||
public function showAll($key = '', $operator = '', $cond = '')
|
||||
{
|
||||
try {
|
||||
$db = static::connectDB();
|
||||
|
||||
$sql = "SELECT * FROM pengumuman";
|
||||
|
||||
if ($conds) {
|
||||
$key = implode('', array_keys($conds));
|
||||
$sql .= " WHERE {$key} = ?";
|
||||
if ($key && $operator && $cond) {
|
||||
$sql .= " WHERE {$key} {$operator} ?";
|
||||
}
|
||||
|
||||
$query = $db->prepare($sql);
|
||||
|
||||
if ($conds) {
|
||||
$query->bindValue(1, implode('', array_values($conds)));
|
||||
if ($key && $operator && $cond) {
|
||||
$query->bindValue(1, $cond);
|
||||
}
|
||||
|
||||
if ($query->execute()) {
|
||||
@@ -56,6 +57,7 @@ class Post extends \Core\Model
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user