From e448855687f593a12cfdb93b503ecd43c9e6d7fe Mon Sep 17 00:00:00 2001 From: Hosteroid Date: Mon, 20 Oct 2025 18:44:03 +0300 Subject: [PATCH] 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. --- app/Helpers/LayoutHelper.php | 17 +++++++++++++++++ app/Views/dashboard/index.php | 7 ++++++- app/Views/layout/base.php | 10 +--------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/Helpers/LayoutHelper.php b/app/Helpers/LayoutHelper.php index 12e67b5..6f77203 100644 --- a/app/Helpers/LayoutHelper.php +++ b/app/Helpers/LayoutHelper.php @@ -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 */ diff --git a/app/Views/dashboard/index.php b/app/Views/dashboard/index.php index a1f5ed5..8f1871f 100644 --- a/app/Views/dashboard/index.php +++ b/app/Views/dashboard/index.php @@ -3,6 +3,12 @@ $title = 'Dashboard'; $pageTitle = 'Dashboard Overview'; $pageDescription = 'Monitor your domains and expiration dates'; $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(); ?> @@ -262,7 +268,6 @@ ob_start(); - getValue('user_isolation_mode', 'shared'); - - if ($isolationMode === 'isolated') { - $stats = $domainModel->getStatistics($userId); - } else { - $stats = $domainModel->getStatistics(); - } + $stats = \App\Helpers\LayoutHelper::getDomainStats(); } // Get application settings from database