lepisi-pengumuman/App/Controllers/Api.php

48 lines
1.1 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 = [];
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 = [];
}
header('Content-Type: application/json');
echo json_encode($get);
}
}