58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
class Post extends \Core\Model
|
|
{
|
|
public function __construct()
|
|
{
|
|
// Create table for posts
|
|
$this->createTable(
|
|
'pengumuman',
|
|
[
|
|
'id int(3) NOT NULL AUTO_INCREMENT',
|
|
'category int(3) 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 date',
|
|
'editor date',
|
|
'content varchar(255) NOT NULL',
|
|
'status tinyint NOT NULL DEFAULT 1',
|
|
'PRIMARY KEY (id)'
|
|
]
|
|
);
|
|
|
|
// Create table for categories
|
|
$this->createTable(
|
|
'kategori',
|
|
[
|
|
'id int(3) NOT NULL AUTO_INCREMENT',
|
|
'category varchar(20) NOT NULL',
|
|
'status tinyint NOT NULL DEFAULT 1',
|
|
'PRIMARY KEY (id)'
|
|
]
|
|
);
|
|
}
|
|
|
|
public function showCategories()
|
|
{
|
|
try {
|
|
$db = static::connectDB();
|
|
|
|
$sql = "SELECT * FROM kategori WHERE status = 1";
|
|
|
|
$query = $db->prepare($sql);
|
|
|
|
if ($query->execute()) {
|
|
if ($query->rowCount() > 1) {
|
|
$results = $query->fetchAll(\PDO::FETCH_ASSOC);
|
|
return $results;
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
throw new \Exception($e->getMessage(), 444);
|
|
}
|
|
}
|
|
}
|