Centralize domain stats retrieval in LayoutHelper

Moved domain statistics logic into a new LayoutHelper::getDomainStats() method. Updated base layout and dashboard view to use this helper, reducing code duplication and improving maintainability.
This commit is contained in:
Hosteroid
2025-10-20 18:44:03 +03:00
parent 7ad01a7da0
commit e448855687
3 changed files with 24 additions and 10 deletions

View File

@@ -35,6 +35,23 @@ class LayoutHelper
} }
/**
* Get domain statistics (centralized function for views)
*/
public static function getDomainStats(): array
{
$domainModel = new \App\Models\Domain();
$userId = \Core\Auth::id();
$settingModel = new \App\Models\Setting();
$isolationMode = $settingModel->getValue('user_isolation_mode', 'shared');
if ($isolationMode === 'isolated') {
return $domainModel->getStatistics($userId);
} else {
return $domainModel->getStatistics();
}
}
/** /**
* Convert timestamp to "time ago" format * Convert timestamp to "time ago" format
*/ */

View File

@@ -3,6 +3,12 @@ $title = 'Dashboard';
$pageTitle = 'Dashboard Overview'; $pageTitle = 'Dashboard Overview';
$pageDescription = 'Monitor your domains and expiration dates'; $pageDescription = 'Monitor your domains and expiration dates';
$pageIcon = 'fas fa-chart-line'; $pageIcon = 'fas fa-chart-line';
// Get stats for dashboard (if not already set by base.php)
if (!isset($stats)) {
$stats = \App\Helpers\LayoutHelper::getDomainStats();
}
ob_start(); ob_start();
?> ?>
@@ -262,7 +268,6 @@ ob_start();
</div> </div>
</div> </div>
<?php <?php
$content = ob_get_clean(); $content = ob_get_clean();
include __DIR__ . '/../layout/base.php'; include __DIR__ . '/../layout/base.php';

View File

@@ -19,15 +19,7 @@ if ($userId) {
// Get stats for sidebar (available on all pages) // Get stats for sidebar (available on all pages)
if (!isset($stats)) { if (!isset($stats)) {
$domainModel = new \App\Models\Domain(); $stats = \App\Helpers\LayoutHelper::getDomainStats();
$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 // Get application settings from database