53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\Post;
|
|
use Core\Session;
|
|
|
|
class Api
|
|
{
|
|
private $model;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->model = new Post();
|
|
}
|
|
|
|
public function posts($args = ['id' => '1'])
|
|
{
|
|
$get = [];
|
|
$get['count'] = 0;
|
|
|
|
if ($args['id'] == 3) {
|
|
$get['data'] = $this->model->showJoin();
|
|
} else {
|
|
$get['data'] = $this->model->showJoin([
|
|
['pengumuman.status', '=', $args['id']]
|
|
]);
|
|
}
|
|
|
|
if ($get['data'] == false) {
|
|
$get['data']['content'] = 'Tidak ada pengumuman';
|
|
$get['data']['valid_at'] = '';
|
|
$get['data']['expired_at'] = '';
|
|
$get['data']['status'] = 0;
|
|
$get['data']['background'] = '#333';
|
|
$get['data']['foreground'] = '#888';
|
|
}
|
|
|
|
if (array_key_exists(0, $get['data']) == false) {
|
|
$temp_data = $get['data'];
|
|
unset($get['data']);
|
|
$get['data'][] = $temp_data;
|
|
$temp_data = [];
|
|
}
|
|
|
|
if ($get['data'] != false) {
|
|
$get['count'] = count($get['data']);
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode($get);
|
|
}
|
|
}
|