lepisi-pengumuman/App/Models/Post.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 int(3)',
'content varchar(255) NOT NULL',
'status tinyint(1) 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(1) NOT NULL DEFAULT 1',
'PRIMARY KEY (id)'
]
);
}
public function showCategories()
{
try {
$db = static::connectDB();
$sql = "SELECT * FROM kategori";
$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);
}
}
}