Update: 2026-05-06 17:10:14
This commit is contained in:
42
app/modules_app/dashboard/recent_activity.php
Normal file
42
app/modules_app/dashboard/recent_activity.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Dashboard Recent Activity Endpoint
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
|
||||
$decoded = AuthMiddleware::check();
|
||||
$db = Database::getInstance();
|
||||
|
||||
$tenantId = $decoded['tenant_id'] ?? null;
|
||||
$role = $decoded['role'];
|
||||
|
||||
try {
|
||||
if ($role === 'super_admin') {
|
||||
$where = "WHERE 1=1";
|
||||
$params = [];
|
||||
} else {
|
||||
$where = "WHERE tenant_id = ?";
|
||||
$params = [$tenantId];
|
||||
}
|
||||
|
||||
// Join with users table to get the name of the person who did the action
|
||||
$stmt = $db->prepare("
|
||||
SELECT a.id, a.action, a.entity_type, a.created_at, u.name as user_name
|
||||
FROM audit_logs a
|
||||
LEFT JOIN users u ON a.user_id = u.id
|
||||
$where
|
||||
ORDER BY a.created_at DESC
|
||||
LIMIT 20
|
||||
");
|
||||
$stmt->execute($params);
|
||||
$activities = $stmt->fetchAll();
|
||||
|
||||
json_success($activities);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
json_error('Failed to fetch recent activity', 500);
|
||||
}
|
||||
Reference in New Issue
Block a user