Initial commit - CMS Gov Bapenda Garut dengan EditorJS
This commit is contained in:
71
app/Controllers/Admin/Dashboard.php
Normal file
71
app/Controllers/Admin/Dashboard.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\NewsModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Models\AuditLogModel;
|
||||
|
||||
class Dashboard extends BaseController
|
||||
{
|
||||
protected $newsModel;
|
||||
protected $userModel;
|
||||
protected $auditLogModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->newsModel = new NewsModel();
|
||||
$this->userModel = new UserModel();
|
||||
$this->auditLogModel = new AuditLogModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Get news statistics
|
||||
$totalNews = $this->newsModel->countByStatus();
|
||||
$publishedNews = $this->newsModel->countByStatus('published');
|
||||
$draftNews = $this->newsModel->countByStatus('draft');
|
||||
|
||||
// Get pages statistics (query directly since no PageModel)
|
||||
$db = \Config\Database::connect();
|
||||
$totalPages = $db->table('pages')->countAllResults();
|
||||
$publishedPages = $db->table('pages')->where('status', 'published')->countAllResults();
|
||||
$draftPages = $db->table('pages')->where('status', 'draft')->countAllResults();
|
||||
|
||||
// Get users statistics
|
||||
$totalUsers = $this->userModel->countAllResults();
|
||||
$activeUsers = $this->userModel->where('is_active', 1)->countAllResults();
|
||||
|
||||
// Get recent audit logs (limit 10)
|
||||
$recentAuditLogs = $this->auditLogModel->select('audit_logs.*, users.username')
|
||||
->join('users', 'users.id = audit_logs.user_id', 'left')
|
||||
->orderBy('audit_logs.created_at', 'DESC')
|
||||
->limit(10)
|
||||
->findAll();
|
||||
|
||||
$data = [
|
||||
'title' => 'Dashboard',
|
||||
'stats' => [
|
||||
'news' => [
|
||||
'total' => $totalNews,
|
||||
'published' => $publishedNews,
|
||||
'draft' => $draftNews,
|
||||
],
|
||||
'pages' => [
|
||||
'total' => $totalPages,
|
||||
'published' => $publishedPages,
|
||||
'draft' => $draftPages,
|
||||
],
|
||||
'users' => [
|
||||
'total' => $totalUsers,
|
||||
'active' => $activeUsers,
|
||||
],
|
||||
],
|
||||
'recentAuditLogs' => $recentAuditLogs,
|
||||
];
|
||||
|
||||
return view('admin/dashboard', $data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user