Refactor global stats handling and user ID access
Moved global stats logic from LayoutHelper to Domain model and updated views/controllers to use the new stats structure. Replaced direct $_SESSION['user_id'] access with Core\Auth::id() for consistency. Cleaned up redundant code and improved isolation mode handling for statistics.
This commit is contained in:
@@ -4,9 +4,12 @@
|
||||
* Contains: HTML structure, meta tags, CSS/JS includes, global stats
|
||||
*/
|
||||
|
||||
// Get current user ID (used for both notifications and stats)
|
||||
$userId = \Core\Auth::id();
|
||||
|
||||
// Fetch notifications for top nav (available on all pages)
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
$notificationData = \App\Helpers\LayoutHelper::getNotifications($_SESSION['user_id']);
|
||||
if ($userId) {
|
||||
$notificationData = \App\Helpers\LayoutHelper::getNotifications($userId);
|
||||
$recentNotifications = $notificationData['items'];
|
||||
$unreadNotifications = $notificationData['unread_count'];
|
||||
} else {
|
||||
@@ -14,10 +17,17 @@ if (isset($_SESSION['user_id'])) {
|
||||
$unreadNotifications = 0;
|
||||
}
|
||||
|
||||
// Fetch global stats for sidebar (available on all pages)
|
||||
if (!isset($globalStats)) {
|
||||
$userId = \Core\Auth::id();
|
||||
$globalStats = \App\Helpers\LayoutHelper::getGlobalStats($userId);
|
||||
// Get stats for sidebar (available on all pages)
|
||||
if (!isset($stats)) {
|
||||
$domainModel = new \App\Models\Domain();
|
||||
$settingModel = new \App\Models\Setting();
|
||||
$isolationMode = $settingModel->getValue('user_isolation_mode', 'shared');
|
||||
|
||||
if ($isolationMode === 'isolated') {
|
||||
$stats = $domainModel->getStatistics($userId);
|
||||
} else {
|
||||
$stats = $domainModel->getStatistics();
|
||||
}
|
||||
}
|
||||
|
||||
// Get application settings from database
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
</div>
|
||||
<span class="text-gray-400 text-xs">Total</span>
|
||||
</div>
|
||||
<span class="text-white font-semibold text-sm"><?= $globalStats['total'] ?? 0 ?></span>
|
||||
<span class="text-white font-semibold text-sm"><?= $stats['total'] ?? 0 ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -94,9 +94,9 @@
|
||||
<div class="w-7 h-7 bg-orange-500/20 rounded flex items-center justify-center mr-2.5">
|
||||
<i class="fas fa-exclamation-triangle text-orange-400 text-xs"></i>
|
||||
</div>
|
||||
<span class="text-gray-400 text-xs" title="Within <?= $globalStats['expiring_threshold'] ?? 30 ?> days">Expiring</span>
|
||||
<span class="text-gray-400 text-xs" title="Within <?= $stats['expiring_threshold'] ?? 30 ?> days">Expiring</span>
|
||||
</div>
|
||||
<span class="text-orange-400 font-semibold text-sm"><?= $globalStats['expiring_soon'] ?? 0 ?></span>
|
||||
<span class="text-orange-400 font-semibold text-sm"><?= $stats['expiring_soon'] ?? 0 ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
</div>
|
||||
<span class="text-gray-400 text-xs">Active</span>
|
||||
</div>
|
||||
<span class="text-green-400 font-semibold text-sm"><?= $globalStats['active'] ?? 0 ?></span>
|
||||
<span class="text-green-400 font-semibold text-sm"><?= $stats['active'] ?? 0 ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user