72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?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);
|
|
}
|
|
}
|
|
|