From 7ec348b9d705f7f7c5978dc382b9d8d3dd100135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Tue, 12 Jul 2022 23:17:08 +0200 Subject: [PATCH 01/10] GH-230 Move morale rendering code to own component --- modules/overview/_includes.php | 2 + .../components/Morale/Morale.component.php | 66 +++++++++++++++ .../components/Morale/Morale.utils.php | 80 +++++++++++++++++++ .../Overview/components/Morale/body.tpl | 18 +++++ .../Overview/components/Morale/index.php | 5 ++ overview.php | 71 +++------------- .../default_template/overview_body_morale.tpl | 12 --- 7 files changed, 180 insertions(+), 74 deletions(-) create mode 100644 modules/overview/screens/Overview/components/Morale/Morale.component.php create mode 100644 modules/overview/screens/Overview/components/Morale/Morale.utils.php create mode 100644 modules/overview/screens/Overview/components/Morale/body.tpl create mode 100644 modules/overview/screens/Overview/components/Morale/index.php delete mode 100644 templates/default_template/overview_body_morale.tpl diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index fde288bd6..20316d7c9 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -26,6 +26,8 @@ include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php'); + include($includePath . './screens/Overview/components/Morale/Morale.component.php'); + include($includePath . './screens/Overview/components/Morale/Morale.utils.php'); include($includePath . './screens/Overview/components/NewMessagesInfo/NewMessagesInfo.component.php'); include($includePath . './screens/Overview/components/NewSurveysInfo/NewSurveysInfo.component.php'); include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php'); diff --git a/modules/overview/screens/Overview/components/Morale/Morale.component.php b/modules/overview/screens/Overview/components/Morale/Morale.component.php new file mode 100644 index 000000000..735d14e42 --- /dev/null +++ b/modules/overview/screens/Overview/components/Morale/Morale.component.php @@ -0,0 +1,66 @@ + '', + 'globalJS' => '', + ]; + } + + $user = &$props['user']; + $currentTimestamp = $props['currentTimestamp']; + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + + $moraleLevelColor = null; + + if ($user['morale_level'] > 0) { + $moraleLevelColor = 'lime'; + } else if ($user['morale_level'] == 0) { + $moraleLevelColor = ''; + } else if ($user['morale_level'] > -50) { + $moraleLevelColor = 'orange'; + } else { + $moraleLevelColor = 'red'; + } + + $moraleStatusData = Morale\Utils\getMoraleStatusData([ + 'user' => &$user, + 'currentTimestamp' => $currentTimestamp, + ]); + + $tplBodyParams = [ + 'Insert_Morale_Level' => $user['morale_level'], + 'Insert_Morale_Color' => $moraleLevelColor, + 'Insert_Morale_Status' => $moraleStatusData['text'], + 'Insert_Morale_Points' => sprintf( + $_Lang['Box_Morale_Points'], + prettyNumber($user['morale_points']) + ), + ]; + $tplBodyParams = array_merge($_Lang, $tplBodyParams); + + $componentHTML = parsetemplate( + $localTemplateLoader('body'), + $tplBodyParams + ); + + return [ + 'componentHTML' => $componentHTML, + 'globalJS' => $moraleStatusData['globalJS'], + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/Morale/Morale.utils.php b/modules/overview/screens/Overview/components/Morale/Morale.utils.php new file mode 100644 index 000000000..c35a31a22 --- /dev/null +++ b/modules/overview/screens/Overview/components/Morale/Morale.utils.php @@ -0,0 +1,80 @@ + $_Lang['Box_Morale_NoChanges'], + 'globalJS' => null, + ]; + } + + $moraleSentiment = ( + $userMoraleLevel > 0 ? + 'Pos' : + 'Neg' + ); + $moraleDroptimeRemaining = $user['morale_droptime'] - $currentTimestamp; + + if ($moraleDroptimeRemaining > 0) { + return [ + 'text' => sprintf( + $_Lang["Box_Morale_DropStartIn_{$moraleSentiment}"], + pretty_time( + $moraleDroptimeRemaining, + true, + 'D' + ) + ), + 'globalJS' => InsertJavaScriptChronoApplet( + 'morale', + '', + $user['morale_droptime'], + true + ), + ]; + } + + $moraleDropInterval = ( + $userMoraleLevel > 0 ? + MORALE_DROPINTERVAL_POSITIVE : + MORALE_DROPINTERVAL_NEGATIVE + ); + $moraleDropNextTimepoint = ( + ($user['morale_lastupdate'] == 0) ? + ($user['morale_droptime'] + $moraleDropInterval) : + ($user['morale_lastupdate'] + $moraleDropInterval) + ); + + return [ + 'text' => sprintf( + $_Lang["Box_Morale_Dropping_{$moraleSentiment}"], + pretty_time( + $moraleDropNextTimepoint - $currentTimestamp, + true, + 'D' + ) + ), + 'globalJS' => InsertJavaScriptChronoApplet( + 'morale', + '', + $moraleDropNextTimepoint, + true + ), + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/Morale/body.tpl b/modules/overview/screens/Overview/components/Morale/body.tpl new file mode 100644 index 000000000..214173922 --- /dev/null +++ b/modules/overview/screens/Overview/components/Morale/body.tpl @@ -0,0 +1,18 @@ + + + + + + + + + + +
+ {Box_Morale_Header} + (?) +
+ {Insert_Morale_Level}%
+ {Insert_Morale_Status} +
{Insert_Morale_Points}
+
diff --git a/modules/overview/screens/Overview/components/Morale/index.php b/modules/overview/screens/Overview/components/Morale/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/Morale/index.php @@ -0,0 +1,5 @@ + diff --git a/overview.php b/overview.php index f7f3382b0..f212c3285 100644 --- a/overview.php +++ b/overview.php @@ -171,72 +171,19 @@ $parse['LastStatsRecount'] = date('d.m.Y H:i:s', $_GameConfig['last_update']); // --- MoraleSystem Box --- - if(MORALE_ENABLED) - { + if (MORALE_ENABLED) { Morale_ReCalculate($_User); - $UserMoraleLevel = $_User['morale_level']; - $parse['Insert_Morale_Level'] = $UserMoraleLevel; - if($UserMoraleLevel > 0) - { - $parse['Insert_Morale_Color'] = 'lime'; - } - else if($UserMoraleLevel < 0) - { - if($UserMoraleLevel <= -50) - { - $parse['Insert_Morale_Color'] = 'red'; - } - else - { - $parse['Insert_Morale_Color'] = 'orange'; - } - } + $moraleComponent = Overview\Screens\Overview\Components\Morale\render([ + 'user' => &$_User, + 'currentTimestamp' => $Now, + ]); - if($UserMoraleLevel == 0) - { - $parse['Insert_Morale_Status'] = $_Lang['Box_Morale_NoChanges']; - } - else - { - if($UserMoraleLevel > 0) - { - $Temp_MoraleStatus = 'Pos'; - } - else - { - $Temp_MoraleStatus = 'Neg'; - } - if($_User['morale_droptime'] > $Now) - { - GlobalTemplate_AppendToAfterBody(InsertJavaScriptChronoApplet('morale', '', $_User['morale_droptime'], true)); - $parse['Insert_Morale_Status'] = sprintf($_Lang['Box_Morale_DropStartIn_'.$Temp_MoraleStatus], pretty_time($_User['morale_droptime'] - $Now, true, 'D')); - } - else - { - if($UserMoraleLevel > 0) - { - $Temp_MoraleDropInterval = MORALE_DROPINTERVAL_POSITIVE; - } - else - { - $Temp_MoraleDropInterval = MORALE_DROPINTERVAL_NEGATIVE; - } - if($_User['morale_lastupdate'] == 0) - { - $Temp_MoraleNextDrop = $_User['morale_droptime'] + $Temp_MoraleDropInterval; - } - else - { - $Temp_MoraleNextDrop = $_User['morale_lastupdate'] + $Temp_MoraleDropInterval; - } - GlobalTemplate_AppendToAfterBody(InsertJavaScriptChronoApplet('morale', '', $Temp_MoraleNextDrop, true)); - $parse['Insert_Morale_Status'] = sprintf($_Lang['Box_Morale_Dropping_'.$Temp_MoraleStatus], pretty_time($Temp_MoraleNextDrop - $Now, true, 'D')); - } - } - $_Lang['Box_Morale_Points'] = sprintf($_Lang['Box_Morale_Points'], prettyNumber($_User['morale_points'])); + $parse['Insert_MoraleBox'] = $moraleComponent['componentHTML']; - $parse['Insert_MoraleBox'] = parsetemplate(gettemplate('overview_body_morale'), $parse); + if (!empty($moraleComponent['globalJS'])) { + GlobalTemplate_AppendToAfterBody($moraleComponent['globalJS']); + } } // --- Get Register Date - diff --git a/templates/default_template/overview_body_morale.tpl b/templates/default_template/overview_body_morale.tpl deleted file mode 100644 index b0180f6be..000000000 --- a/templates/default_template/overview_body_morale.tpl +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - -
{Box_Morale_Header}(?)
{Insert_Morale_Level}%
{Insert_Morale_Status}
{Box_Morale_Points}
-
From ef2c93905ceb75f2d48886fa5b0d6117ff2e2300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Wed, 13 Jul 2022 00:17:02 +0200 Subject: [PATCH 02/10] GH-230 Move vacation box to its own component --- modules/overview/_includes.php | 1 + .../VacationInfoBox.component.php | 30 +++++++++++++++++++ .../components/VacationInfoBox/body.tpl | 8 +++++ .../components/VacationInfoBox/index.php | 5 ++++ overview.php | 8 ++--- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 modules/overview/screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php create mode 100644 modules/overview/screens/Overview/components/VacationInfoBox/body.tpl create mode 100644 modules/overview/screens/Overview/components/VacationInfoBox/index.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index 20316d7c9..4cc40c5f0 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -33,6 +33,7 @@ include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php'); include($includePath . './screens/Overview/components/ResourcesTransport/ResourcesTransport.component.php'); include($includePath . './screens/Overview/components/StatsList/StatsList.component.php'); + include($includePath . './screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php'); include($includePath . './screens/PlanetNameChange/PlanetNameChange.screen.php'); include($includePath . './screens/PlanetNameChange/PlanetNameChange.utils.php'); diff --git a/modules/overview/screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php b/modules/overview/screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php new file mode 100644 index 000000000..fbf51b7f2 --- /dev/null +++ b/modules/overview/screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php @@ -0,0 +1,30 @@ + '', + ]; + } + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + + $componentHTML = parsetemplate( + $localTemplateLoader('body'), + $_Lang + ); + + return [ + 'componentHTML' => $componentHTML, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/VacationInfoBox/body.tpl b/modules/overview/screens/Overview/components/VacationInfoBox/body.tpl new file mode 100644 index 000000000..6fd92b51e --- /dev/null +++ b/modules/overview/screens/Overview/components/VacationInfoBox/body.tpl @@ -0,0 +1,8 @@ + + + {VacationModeBox_Text} + + + +   + diff --git a/modules/overview/screens/Overview/components/VacationInfoBox/index.php b/modules/overview/screens/Overview/components/VacationInfoBox/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/VacationInfoBox/index.php @@ -0,0 +1,5 @@ + diff --git a/overview.php b/overview.php index f212c3285..5a329e012 100644 --- a/overview.php +++ b/overview.php @@ -59,11 +59,9 @@ InsertJavaScriptChronoApplet(false, false, false); $InsertJSChronoApplet_GlobalIncluded = true; - // --- Vacation Mode Box - if(isOnVacation()) - { - $parse['VacationModeBox'] = ''.$_Lang['VacationModeBox_Text'].' '; - } + $parse['VacationModeBox'] = Overview\Screens\Overview\Components\VacationInfoBox\render([ + 'user' => &$_User, + ])['componentHTML']; // --- Activation Box if (!isUserAccountActivated($_User)) { From de2ef2fd9c60bf85a641d927ae07258ff78749cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Wed, 13 Jul 2022 00:24:18 +0200 Subject: [PATCH 03/10] GH-230 Move account activation info box to own component --- modules/overview/_includes.php | 1 + .../AccountActivationInfoBox.component.php | 30 +++++++++++++++++++ .../AccountActivationInfoBox/body.tpl | 8 +++++ .../AccountActivationInfoBox/index.php | 5 ++++ overview.php | 8 ++--- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 modules/overview/screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php create mode 100644 modules/overview/screens/Overview/components/AccountActivationInfoBox/body.tpl create mode 100644 modules/overview/screens/Overview/components/AccountActivationInfoBox/index.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index 4cc40c5f0..decf6aa6d 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -24,6 +24,7 @@ include($includePath . './screens/FirstLogin/utils/effects/updateUserOnFirstLogin.effect.php'); include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php'); + include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php'); include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php'); include($includePath . './screens/Overview/components/Morale/Morale.component.php'); diff --git a/modules/overview/screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php b/modules/overview/screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php new file mode 100644 index 000000000..5ab45d716 --- /dev/null +++ b/modules/overview/screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php @@ -0,0 +1,30 @@ + '', + ]; + } + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + + $componentHTML = parsetemplate( + $localTemplateLoader('body'), + $_Lang + ); + + return [ + 'componentHTML' => $componentHTML, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/AccountActivationInfoBox/body.tpl b/modules/overview/screens/Overview/components/AccountActivationInfoBox/body.tpl new file mode 100644 index 000000000..66f7937e4 --- /dev/null +++ b/modules/overview/screens/Overview/components/AccountActivationInfoBox/body.tpl @@ -0,0 +1,8 @@ + + + {ActivationInfo_Text} + + + +   + diff --git a/modules/overview/screens/Overview/components/AccountActivationInfoBox/index.php b/modules/overview/screens/Overview/components/AccountActivationInfoBox/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/AccountActivationInfoBox/index.php @@ -0,0 +1,5 @@ + diff --git a/overview.php b/overview.php index 5a329e012..f17d32d7f 100644 --- a/overview.php +++ b/overview.php @@ -62,11 +62,9 @@ $parse['VacationModeBox'] = Overview\Screens\Overview\Components\VacationInfoBox\render([ 'user' => &$_User, ])['componentHTML']; - - // --- Activation Box - if (!isUserAccountActivated($_User)) { - $parse['ActivationInfoBox'] = ''.$_Lang['ActivationInfo_Text'].' '; - } + $parse['ActivationInfoBox'] = Overview\Screens\Overview\Components\AccountActivationInfoBox\render([ + 'user' => &$_User, + ])['componentHTML']; // --- New User Protection Box if($_User['NoobProtection_EndTime'] > $Now) From c050b3c9cd7bac203dd4ca90c3721f3216d03791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Thu, 14 Jul 2022 21:37:09 +0200 Subject: [PATCH 04/10] GH-230 Move noob protection infobox & effects into own component --- modules/overview/_includes.php | 4 + .../NoobProtectionInfoBox.component.php | 75 +++++++++++++++++++ .../NoobProtectionInfoBox.utils.php | 50 +++++++++++++ .../components/NoobProtectionInfoBox/body.tpl | 8 ++ .../NoobProtectionInfoBox/index.php | 5 ++ .../NoobProtectionInfoBox/turnOffMessage.tpl | 8 ++ .../effects/turnOffProtection.effect.php | 31 ++++++++ .../utils/helpers.utils.php | 14 ++++ .../NoobProtectionInfoBox/utils/index.php | 5 ++ overview.php | 24 +++--- 10 files changed, 209 insertions(+), 15 deletions(-) create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/body.tpl create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/index.php create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/turnOffMessage.tpl create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.php create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php create mode 100644 modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/index.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index decf6aa6d..f0f15b3e5 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -31,6 +31,10 @@ include($includePath . './screens/Overview/components/Morale/Morale.utils.php'); include($includePath . './screens/Overview/components/NewMessagesInfo/NewMessagesInfo.component.php'); include($includePath . './screens/Overview/components/NewSurveysInfo/NewSurveysInfo.component.php'); + include($includePath . './screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php'); + include($includePath . './screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php'); + include($includePath . './screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php'); + include($includePath . './screens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.php'); include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php'); include($includePath . './screens/Overview/components/ResourcesTransport/ResourcesTransport.component.php'); include($includePath . './screens/Overview/components/StatsList/StatsList.component.php'); diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php new file mode 100644 index 000000000..bb0b1a846 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.component.php @@ -0,0 +1,75 @@ + &$user, + 'currentTimestamp' => $currentTimestamp, + ]); + + if (!$isProtectedByNoobProtection) { + return [ + 'componentHTML' => '', + 'globalJS' => '', + ]; + } + + $effectsResult = NoobProtectionInfoBox\runEffects([ + 'input' => &$input, + 'user' => &$user, + 'currentTimestamp' => $currentTimestamp, + ]); + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + + if ( + $effectsResult['isSuccess'] && + $effectsResult['payload']['protectionTurnedOff'] + ) { + $componentHTML = parsetemplate( + $localTemplateLoader('turnOffMessage'), + $_Lang + ); + + return [ + 'componentHTML' => $componentHTML, + 'globalJS' => '', + ]; + } + + $protectionTimeLeft = $user['NoobProtection_EndTime'] - $currentTimestamp; + + $componentHTML = parsetemplate( + $localTemplateLoader('body'), + [ + 'data_ProtectionCounterMessage' => sprintf( + $_Lang['NewUserProtection_Text'], + pretty_time($protectionTimeLeft, true, 'dhms') + ) + ] + ); + + $protectionCountdownJS = InsertJavaScriptChronoApplet('newprotect', '', $protectionTimeLeft); + + return [ + 'componentHTML' => $componentHTML, + 'globalJS' => $protectionCountdownJS, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php new file mode 100644 index 000000000..db0409e93 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/NoobProtectionInfoBox.utils.php @@ -0,0 +1,50 @@ + &$user, + 'currentTimestamp' => $currentTimestamp, + ]); + + if (!$isProtectedByNoobProtection) { + return [ + 'isSuccess' => null, + ]; + } + if ( + !isset($input['cancelprotection']) || + $input['cancelprotection'] != '1' + ) { + return [ + 'isSuccess' => null, + ]; + } + + NoobProtectionInfoBox\Utils\Effects\turnOffProtection([ + 'user' => &$user, + 'currentTimestamp' => $currentTimestamp, + ]); + + return [ + 'isSuccess' => true, + 'payload' => [ + 'protectionTurnedOff' => true, + ], + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/body.tpl b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/body.tpl new file mode 100644 index 000000000..3ec8d4634 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/body.tpl @@ -0,0 +1,8 @@ + + + {data_ProtectionCounterMessage} + + + +   + diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/index.php b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/turnOffMessage.tpl b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/turnOffMessage.tpl new file mode 100644 index 000000000..d6f30e75b --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/turnOffMessage.tpl @@ -0,0 +1,8 @@ + + + {NewUserProtection_Canceled} + + + +   + diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.php b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.php new file mode 100644 index 000000000..bc3e33b52 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/effects/turnOffProtection.effect.php @@ -0,0 +1,31 @@ + diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php new file mode 100644 index 000000000..4638fbf77 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/helpers.utils.php @@ -0,0 +1,14 @@ + $props['currentTimestamp']); +} + +?> diff --git a/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/index.php b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/NoobProtectionInfoBox/utils/index.php @@ -0,0 +1,5 @@ + diff --git a/overview.php b/overview.php index f17d32d7f..88b79eb43 100644 --- a/overview.php +++ b/overview.php @@ -66,22 +66,16 @@ 'user' => &$_User, ])['componentHTML']; - // --- New User Protection Box - if($_User['NoobProtection_EndTime'] > $Now) - { - if(isset($_GET['cancelprotection']) && $_GET['cancelprotection'] == '1') - { - $_User['NoobProtection_EndTime'] = $Now; - $Query_UpdateUser = "UPDATE {{table}} SET `NoobProtection_EndTime` = {$Now} WHERE `id` = {$_User['id']} LIMIT 1;"; - doquery($Query_UpdateUser, 'users'); + $noobProtectionInfoBoxComponent = Overview\Screens\Overview\Components\NoobProtectionInfoBox\render([ + 'input' => &$_GET, + 'user' => &$_User, + 'currentTimestamp' => $Now, + ]); - $parse['NewUserBox'] = ''.$_Lang['NewUserProtection_Canceled'].' '; - } - else - { - $ProtectTimeLeft = $_User['NoobProtection_EndTime'] - $Now; - $parse['NewUserBox'] = InsertJavaScriptChronoApplet('newprotect', '', $ProtectTimeLeft).''.sprintf($_Lang['NewUserProtection_Text'], pretty_time($ProtectTimeLeft, true, 'dhms')).' '; - } + $parse['NewUserBox'] = $noobProtectionInfoBoxComponent['componentHTML']; + + if (!empty($noobProtectionInfoBoxComponent['globalJS'])) { + GlobalTemplate_AppendToAfterBody($noobProtectionInfoBoxComponent['globalJS']); } // --- Admin Info Box ------------------------------------------------------------------------------------ From f46dee608fba2da76aa6b2a39ec1dd38d125afe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Fri, 15 Jul 2022 23:32:11 +0200 Subject: [PATCH 05/10] GH-230 Move gift items infobox to its own component --- modules/overview/_includes.php | 1 + .../GiftItemsInfoBox.component.php | 50 +++++++++++++++++++ .../components/GiftItemsInfoBox/body.tpl | 7 +++ .../components/GiftItemsInfoBox/index.php | 5 ++ overview.php | 8 ++- 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 modules/overview/screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php create mode 100644 modules/overview/screens/Overview/components/GiftItemsInfoBox/body.tpl create mode 100644 modules/overview/screens/Overview/components/GiftItemsInfoBox/index.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index f0f15b3e5..388fd86cc 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -27,6 +27,7 @@ include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php'); include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php'); + include($includePath . './screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php'); include($includePath . './screens/Overview/components/Morale/Morale.component.php'); include($includePath . './screens/Overview/components/Morale/Morale.utils.php'); include($includePath . './screens/Overview/components/NewMessagesInfo/NewMessagesInfo.component.php'); diff --git a/modules/overview/screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php b/modules/overview/screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php new file mode 100644 index 000000000..21f7c3a7e --- /dev/null +++ b/modules/overview/screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php @@ -0,0 +1,50 @@ + '', + ]; + } + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + + $content = sprintf( + $_Lang['FreePremItem_Text'], + $giftItemsData['Count'] + ); + + $componentHTML = parsetemplate( + $localTemplateLoader('body'), + [ + 'content' => $content, + ] + ); + + return [ + 'componentHTML' => $componentHTML, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/GiftItemsInfoBox/body.tpl b/modules/overview/screens/Overview/components/GiftItemsInfoBox/body.tpl new file mode 100644 index 000000000..243d88314 --- /dev/null +++ b/modules/overview/screens/Overview/components/GiftItemsInfoBox/body.tpl @@ -0,0 +1,7 @@ + + + + {content} + + + diff --git a/modules/overview/screens/Overview/components/GiftItemsInfoBox/index.php b/modules/overview/screens/Overview/components/GiftItemsInfoBox/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/GiftItemsInfoBox/index.php @@ -0,0 +1,5 @@ + diff --git a/overview.php b/overview.php index 88b79eb43..a44a21eed 100644 --- a/overview.php +++ b/overview.php @@ -93,11 +93,9 @@ $parse['P_SFBInfobox'] = FlightControl\Components\SmartFleetBlockadeInfoBox\render()['componentHTML']; // --- Free Premium Items Info Box ----------------------------------------------------------------------- - $GetFreeItems = doquery("SELECT COUNT(`ID`) as `Count` FROM {{table}} WHERE `UserID` = {$_User['id']} AND `Used` = false;", 'premium_free', true); - if($GetFreeItems['Count'] > 0) - { - $parse['FreePremiumItemsBox'] = ''.sprintf($_Lang['FreePremItem_Text'], $GetFreeItems['Count']).''; - } + $parse['FreePremiumItemsBox'] = Overview\Screens\Overview\Components\GiftItemsInfoBox\render([ + 'userId' => $_User['id'], + ])['componentHTML']; // --- System Messages Box ------------------------------------------------------------------------------- if(!empty($_GET['showmsg'])) From 036f7de6f286d5c5b1fff5ec5d255376478a89cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Fri, 15 Jul 2022 23:41:08 +0200 Subject: [PATCH 06/10] GH-230 Minor translation fixes for gifted items --- language/en/overview.lang | 2 +- language/fr/overview.lang | 2 +- language/pl/overview.lang | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/language/en/overview.lang b/language/en/overview.lang index 44c978aad..49cd42fc5 100644 --- a/language/en/overview.lang +++ b/language/en/overview.lang @@ -88,7 +88,7 @@ $_Lang['BuildJS_Complete'] = 'Completed'; $_Lang['BuildJS_Continue'] = 'Continue'; // Free PremiumItems Box -$_Lang['FreePremItem_Text'] = 'You\'ve received free Premium Items [%s] as a reward from the Game or Administration!
Go to the Ship to check your items list!'; +$_Lang['FreePremItem_Text'] = 'You\'ve received free Premium Items (%s) as a reward from the Game or Administration!
Go to the Ship to check your items list!'; // Vacation Mode Box $_Lang['VacationModeBox_Text'] = 'Your account is currently in Vacation Mode'; diff --git a/language/fr/overview.lang b/language/fr/overview.lang index db1752ee8..aec48f2bf 100644 --- a/language/fr/overview.lang +++ b/language/fr/overview.lang @@ -88,7 +88,7 @@ $_Lang['BuildJS_Complete'] = 'Terminé'; $_Lang['BuildJS_Continue'] = 'Continuer'; // Free PremiumItems Box -$_Lang['FreePremItem_Text'] = 'Tu as reçu un cadeau Premium [%s] de la part du jeu ou des administrateurs !
Regarde dans la Boutique ce que tu as reçu !'; +$_Lang['FreePremItem_Text'] = 'Tu as reçu un cadeau Premium (%s) de la part du jeu ou des administrateurs !
Regarde dans la Boutique ce que tu as reçu !'; // Vacation Mode Box $_Lang['VacationModeBox_Text'] = 'Ton compte est actuellement en mode vacances.'; diff --git a/language/pl/overview.lang b/language/pl/overview.lang index 86e3b444b..5025ee10c 100644 --- a/language/pl/overview.lang +++ b/language/pl/overview.lang @@ -87,7 +87,7 @@ $_Lang['BuildJS_Complete'] = 'Zakończono'; $_Lang['BuildJS_Continue'] = 'Kontynuuj'; // Free PremiumItems Box -$_Lang['FreePremItem_Text'] = 'Otrzymałeś Darmowe Towary Premium [%s] (Konto Pro, Oficerowie itp.) od Systemu lub Administracji!
Przejdź do Sklepu aby przejrzeć listę!'; +$_Lang['FreePremItem_Text'] = 'Otrzymałeś Darmowe przedmioty Premium (%s) od Systemu lub Administracji!
Przejdź do Sklepu aby przejrzeć listę!'; // Vacation Mode Box $_Lang['VacationModeBox_Text'] = 'Twoje konto jest obecnie w Trybie Urlopu'; From d46de52aa2cce329f2ca96db331c210ca99ec638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Sat, 16 Jul 2022 00:15:17 +0200 Subject: [PATCH 07/10] GH-230 Move feedback messages to their own component --- modules/overview/_includes.php | 2 + .../FeedbackMessagesDisplay.component.php | 39 +++++++++++++++++++ .../FeedbackMessagesDisplay.utils.php | 29 ++++++++++++++ .../FeedbackMessagesDisplay/index.php | 5 +++ .../FeedbackMessagesDisplay/messageRow.tpl | 5 +++ overview.php | 22 ++--------- 6 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php create mode 100644 modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php create mode 100644 modules/overview/screens/Overview/components/FeedbackMessagesDisplay/index.php create mode 100644 modules/overview/screens/Overview/components/FeedbackMessagesDisplay/messageRow.tpl diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index 388fd86cc..91a1dd803 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -27,6 +27,8 @@ include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php'); include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php'); + include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php'); + include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php'); include($includePath . './screens/Overview/components/GiftItemsInfoBox/GiftItemsInfoBox.component.php'); include($includePath . './screens/Overview/components/Morale/Morale.component.php'); include($includePath . './screens/Overview/components/Morale/Morale.utils.php'); diff --git a/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php new file mode 100644 index 000000000..833408b1d --- /dev/null +++ b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php @@ -0,0 +1,39 @@ + '', + ]; + } + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + $tplBodyCache = [ + 'messageRow' => $localTemplateLoader('messageRow'), + ]; + + $parsedMessages = array_map_withkeys($messages, function ($message) use (&$tplBodyCache) { + return parsetemplate( + $tplBodyCache['messageRow'], + $message + ); + }); + + $componentHTML = implode('', $parsedMessages); + + return [ + 'componentHTML' => $componentHTML, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php new file mode 100644 index 000000000..a264a31af --- /dev/null +++ b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php @@ -0,0 +1,29 @@ + $_Lang['Abandon_ColonyAbandoned'], + 'colorClass' => 'lime', + ]; + } + + return $messages; +} + +?> diff --git a/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/index.php b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/messageRow.tpl b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/messageRow.tpl new file mode 100644 index 000000000..374b38298 --- /dev/null +++ b/modules/overview/screens/Overview/components/FeedbackMessagesDisplay/messageRow.tpl @@ -0,0 +1,5 @@ + + + {messageContent} + + diff --git a/overview.php b/overview.php index a44a21eed..0d188cc46 100644 --- a/overview.php +++ b/overview.php @@ -98,25 +98,9 @@ ])['componentHTML']; // --- System Messages Box ------------------------------------------------------------------------------- - if(!empty($_GET['showmsg'])) - { - $SysMsgLoop = 0; - if($_GET['showmsg'] == 'abandon') - { - $ShowSystemMsg[$SysMsgLoop]['txt'] = $_Lang['Abandon_ColonyAbandoned']; - $ShowSystemMsg[$SysMsgLoop]['col'] = 'lime'; - $SysMsgLoop += 1; - } - } - - if(!empty($ShowSystemMsg)) - { - $parse['SystemMsgBox'] = ''; - foreach($ShowSystemMsg as $SystemMsg) - { - $parse['SystemMsgBox'] .= ''.$SystemMsg['txt'].''; - } - } + $parse['SystemMsgBox'] = Overview\Screens\Overview\Components\FeedbackMessagesDisplay\render([ + 'input' => &$_GET, + ])['componentHTML']; // --- New Messages Information Box ---------------------------------------------------------------------- $parse['NewMsgBox'] = Overview\Screens\Overview\Components\NewMessagesInfo\render([ From ce3c8f3b1a9dc2f4dba2331784b62cff4d5f3190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Sun, 17 Jul 2022 18:52:38 +0200 Subject: [PATCH 08/10] GH-230 Move combat stats to own component --- modules/overview/_includes.php | 1 + .../CombatStatsList.component.php | 114 ++++++++++++++++++ .../components/CombatStatsList/body.tpl | 18 +++ .../components/CombatStatsList/index.php | 5 + .../CombatStatsList/statCategoryRow.tpl | 4 + overview.php | 17 +-- templates/default_template/overview_body.tpl | 40 +----- 7 files changed, 149 insertions(+), 50 deletions(-) create mode 100644 modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php create mode 100644 modules/overview/screens/Overview/components/CombatStatsList/body.tpl create mode 100644 modules/overview/screens/Overview/components/CombatStatsList/index.php create mode 100644 modules/overview/screens/Overview/components/CombatStatsList/statCategoryRow.tpl diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index 91a1dd803..983accc5a 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -26,6 +26,7 @@ include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php'); include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); + include($includePath . './screens/Overview/components/CombatStatsList/CombatStatsList.component.php'); include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php'); include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php'); include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php'); diff --git a/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php b/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php new file mode 100644 index 000000000..a3e119997 --- /dev/null +++ b/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php @@ -0,0 +1,114 @@ + $localTemplateLoader('body'), + 'statCategoryRow' => $localTemplateLoader('statCategoryRow'), + ]; + + $categories = [ + 'allBattles' => [ + 'label' => $_Lang['Box_battlesAll'], + 'statsTableKeys' => [ + 'ustat_raids_won', + 'ustat_raids_draw', + 'ustat_raids_lost', + 'ustat_raids_inAlly', + ], + ], + 'battlesWon' => [ + 'label' => $_Lang['Box_battlesWon'], + 'statsTableKeys' => [ + 'ustat_raids_won', + ], + ], + 'battlesWonUnited' => [ + 'label' => $_Lang['Box_battlesACSWon'], + 'statsTableKeys' => [ + 'ustat_raids_acs_won', + ], + 'colorClass' => 'orange', + ], + 'battlesDrawn' => [ + 'label' => $_Lang['Box_battlesDraw'], + 'statsTableKeys' => [ + 'ustat_raids_draw', + ], + ], + 'battlesLost' => [ + 'label' => $_Lang['Box_battlesLost'], + 'statsTableKeys' => [ + 'ustat_raids_lost', + ], + ], + 'battlesInAlly' => [ + 'label' => $_Lang['Box_battlesInAlly'], + 'statsTableKeys' => [ + 'ustat_raids_inAlly', + ], + ], + 'missileStrikes' => [ + 'label' => $_Lang['Box_missileAttacks'], + 'statsTableKeys' => [ + 'ustat_raids_missileAttack', + ], + ], + ]; + + $categoriesHTML = []; + + foreach ($categories as $categoryKey => $category) { + $categorySubValues = array_map_withkeys($category['statsTableKeys'], function ($key) use ($stats) { + return $stats[$key]; + }); + $categoryTotalValue = array_sum($categorySubValues); + + $categoryTplBodyParams = [ + 'statCategoryColorClass' => ( + !empty($category['colorClass']) ? + $category['colorClass'] : + '' + ), + 'statCategoryLabel' => $category['label'], + 'statCategoryValue' => prettyNumber($categoryTotalValue), + ]; + + $categoriesHTML[$categoryKey] = parsetemplate( + $tplBodyCache['statCategoryRow'], + $categoryTplBodyParams + ); + } + + $tplBodyParams = [ + 'categoryRow_allBattles' => $categoriesHTML['allBattles'], + 'categoryRow_battlesWon' => $categoriesHTML['battlesWon'], + 'categoryRow_battlesWonUnited' => $categoriesHTML['battlesWonUnited'], + 'categoryRow_battlesDrawn' => $categoriesHTML['battlesDrawn'], + 'categoryRow_battlesLost' => $categoriesHTML['battlesLost'], + 'categoryRow_battlesInAlly' => $categoriesHTML['battlesInAlly'], + 'categoryRow_missileStrikes' => $categoriesHTML['missileStrikes'], + ]; + $tplBodyParams = array_merge($_Lang, $tplBodyParams); + + $componentHTML = parsetemplate( + $tplBodyCache['body'], + $tplBodyParams + ); + + return [ + 'componentHTML' => $componentHTML, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/CombatStatsList/body.tpl b/modules/overview/screens/Overview/components/CombatStatsList/body.tpl new file mode 100644 index 000000000..004cbd211 --- /dev/null +++ b/modules/overview/screens/Overview/components/CombatStatsList/body.tpl @@ -0,0 +1,18 @@ + + + + + {categoryRow_allBattles} + + + + {categoryRow_battlesWon} + {categoryRow_battlesWonUnited} + {categoryRow_battlesDrawn} + {categoryRow_battlesLost} + {categoryRow_battlesInAlly} + + + + {categoryRow_missileStrikes} +
{YourBattles}
 
 
diff --git a/modules/overview/screens/Overview/components/CombatStatsList/index.php b/modules/overview/screens/Overview/components/CombatStatsList/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/CombatStatsList/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/overview/screens/Overview/components/CombatStatsList/statCategoryRow.tpl b/modules/overview/screens/Overview/components/CombatStatsList/statCategoryRow.tpl new file mode 100644 index 000000000..375b57f33 --- /dev/null +++ b/modules/overview/screens/Overview/components/CombatStatsList/statCategoryRow.tpl @@ -0,0 +1,4 @@ + + {statCategoryLabel} + {statCategoryValue} + diff --git a/overview.php b/overview.php index 0d188cc46..6d322fa5b 100644 --- a/overview.php +++ b/overview.php @@ -180,22 +180,17 @@ $parse['RefferedCounter'] = prettyNumber((($Referred['count'] > 0) ? $Referred['count'] : '0')); // --- Render UserStats --- + $GetStats_Fields = '`ustat_raids_won`, `ustat_raids_draw`, `ustat_raids_lost`, `ustat_raids_acs_won`, `ustat_raids_inAlly`, `ustat_raids_missileAttack`'; + $StatRecord = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = {$_User['id']} LIMIT 1;", 'statpoints', true); + $GetStats = doquery("SELECT {$GetStats_Fields} FROM {{table}} WHERE `A_UserID` = {$_User['id']} LIMIT 1;", 'achievements_stats', true); $parse['Component_StatsList'] = Overview\Screens\Overview\Components\StatsList\render([ 'stats' => $StatRecord, ])['componentHTML']; - - // Get User Achievements - $GetStats_Fields = '`ustat_raids_won`, `ustat_raids_draw`, `ustat_raids_lost`, `ustat_raids_acs_won`, `ustat_raids_inAlly`, `ustat_raids_missileAttack`'; - $GetStats = doquery("SELECT {$GetStats_Fields} FROM {{table}} WHERE `A_UserID` = {$_User['id']} LIMIT 1;", 'achievements_stats', true); - $parse['raids'] = prettyNumber($GetStats['ustat_raids_won'] + $GetStats['ustat_raids_draw'] + $GetStats['ustat_raids_lost'] + $GetStats['ustat_raids_inAlly']); - $parse['raidswin'] = prettyNumber($GetStats['ustat_raids_won']); - $parse['raidsdraw'] = prettyNumber($GetStats['ustat_raids_draw']); - $parse['raidsloose'] = prettyNumber($GetStats['ustat_raids_lost']); - $parse['raidacswin'] = prettyNumber($GetStats['ustat_raids_acs_won']); - $parse['raidsinally'] = prettyNumber($GetStats['ustat_raids_inAlly']); - $parse['raidsmissileattacks'] = prettyNumber($GetStats['ustat_raids_missileAttack']); + $parse['Component_CombatStatsList'] = Overview\Screens\Overview\Components\CombatStatsList\render([ + 'stats' => $GetStats, + ])['componentHTML']; // --- Planet Data --------- if($_Planet['planet_type'] == 1) diff --git a/templates/default_template/overview_body.tpl b/templates/default_template/overview_body.tpl index 798589d39..a90d0b25c 100644 --- a/templates/default_template/overview_body.tpl +++ b/templates/default_template/overview_body.tpl @@ -158,45 +158,7 @@ $(document).ready(function() {Component_StatsList}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{YourBattles}
{Box_battlesAll}{raids}
 
{Box_battlesWon}{raidswin}
{Box_battlesACSWon}{raidacswin}
{Box_battlesDraw}{raidsdraw}
{Box_battlesLost}{raidsloose}
{Box_battlesInAlly}{raidsinally}
 
{Box_missileAttacks}{raidsmissileattacks}
+ {Component_CombatStatsList} From 169d22d289c08dbbbf9a80a3988cdb5c815e40f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Sun, 17 Jul 2022 18:56:22 +0200 Subject: [PATCH 09/10] GH-230 Move combat stats data fetcher to utils --- modules/overview/_includes.php | 1 + .../CombatStatsList.component.php | 14 +++++---- .../CombatStatsList/CombatStatsList.utils.php | 30 +++++++++++++++++++ overview.php | 5 +--- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.utils.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index 983accc5a..d96f151c7 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -27,6 +27,7 @@ include($includePath . './screens/Overview/components/AccountActivationInfoBox/AccountActivationInfoBox.component.php'); include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); include($includePath . './screens/Overview/components/CombatStatsList/CombatStatsList.component.php'); + include($includePath . './screens/Overview/components/CombatStatsList/CombatStatsList.utils.php'); include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php'); include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.component.php'); include($includePath . './screens/Overview/components/FeedbackMessagesDisplay/FeedbackMessagesDisplay.utils.php'); diff --git a/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php b/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php index a3e119997..d007e42cc 100644 --- a/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php +++ b/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.component.php @@ -2,21 +2,25 @@ namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\CombatStatsList; +use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\CombatStatsList; + /** * @param array $props - * @param array $props['stats'] + * @param number $props['userId'] */ function render($props) { global $_Lang; - $stats = $props['stats']; - $localTemplateLoader = createLocalTemplateLoader(__DIR__); $tplBodyCache = [ 'body' => $localTemplateLoader('body'), 'statCategoryRow' => $localTemplateLoader('statCategoryRow'), ]; + $statsData = CombatStatsList\Utils\getUserCombatStats([ + 'userId' => $props['userId'], + ]); + $categories = [ 'allBattles' => [ 'label' => $_Lang['Box_battlesAll'], @@ -69,8 +73,8 @@ function render($props) { $categoriesHTML = []; foreach ($categories as $categoryKey => $category) { - $categorySubValues = array_map_withkeys($category['statsTableKeys'], function ($key) use ($stats) { - return $stats[$key]; + $categorySubValues = array_map_withkeys($category['statsTableKeys'], function ($key) use ($statsData) { + return $statsData[$key]; }); $categoryTotalValue = array_sum($categorySubValues); diff --git a/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.utils.php b/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.utils.php new file mode 100644 index 000000000..47cd43c95 --- /dev/null +++ b/modules/overview/screens/Overview/components/CombatStatsList/CombatStatsList.utils.php @@ -0,0 +1,30 @@ + diff --git a/overview.php b/overview.php index 6d322fa5b..49da37909 100644 --- a/overview.php +++ b/overview.php @@ -180,16 +180,13 @@ $parse['RefferedCounter'] = prettyNumber((($Referred['count'] > 0) ? $Referred['count'] : '0')); // --- Render UserStats --- - $GetStats_Fields = '`ustat_raids_won`, `ustat_raids_draw`, `ustat_raids_lost`, `ustat_raids_acs_won`, `ustat_raids_inAlly`, `ustat_raids_missileAttack`'; - $StatRecord = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = {$_User['id']} LIMIT 1;", 'statpoints', true); - $GetStats = doquery("SELECT {$GetStats_Fields} FROM {{table}} WHERE `A_UserID` = {$_User['id']} LIMIT 1;", 'achievements_stats', true); $parse['Component_StatsList'] = Overview\Screens\Overview\Components\StatsList\render([ 'stats' => $StatRecord, ])['componentHTML']; $parse['Component_CombatStatsList'] = Overview\Screens\Overview\Components\CombatStatsList\render([ - 'stats' => $GetStats, + 'userId' => $_User['id'], ])['componentHTML']; // --- Planet Data --------- From 8bd6ce3e901af5a882b0d6002116f41cf881c5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Sun, 17 Jul 2022 18:59:05 +0200 Subject: [PATCH 10/10] GH-230 Move game stats data fetcher to utils as well --- modules/overview/_includes.php | 1 + .../StatsList/StatsList.component.php | 20 +++++++++------ .../components/StatsList/StatsList.utils.php | 25 +++++++++++++++++++ overview.php | 4 +-- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 modules/overview/screens/Overview/components/StatsList/StatsList.utils.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index d96f151c7..7c41e6ef1 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -43,6 +43,7 @@ include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php'); include($includePath . './screens/Overview/components/ResourcesTransport/ResourcesTransport.component.php'); include($includePath . './screens/Overview/components/StatsList/StatsList.component.php'); + include($includePath . './screens/Overview/components/StatsList/StatsList.utils.php'); include($includePath . './screens/Overview/components/VacationInfoBox/VacationInfoBox.component.php'); include($includePath . './screens/PlanetNameChange/PlanetNameChange.screen.php'); diff --git a/modules/overview/screens/Overview/components/StatsList/StatsList.component.php b/modules/overview/screens/Overview/components/StatsList/StatsList.component.php index 1bc5e2210..adcf0364e 100644 --- a/modules/overview/screens/Overview/components/StatsList/StatsList.component.php +++ b/modules/overview/screens/Overview/components/StatsList/StatsList.component.php @@ -2,21 +2,25 @@ namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\StatsList; +use UniEngine\Engine\Modules\Overview\Screens\Overview\Components\StatsList; + /** * @param array $props - * @param array $props['stats'] + * @param number $props['userId'] */ function render($props) { global $_Lang; - $stats = $props['stats']; - $localTemplateLoader = createLocalTemplateLoader(__DIR__); $tplBodyCache = [ 'body' => $localTemplateLoader('body'), 'statCategoryRow' => $localTemplateLoader('statCategoryRow'), ]; + $statsData = StatsList\Utils\getUserGameStats([ + 'userId' => $props['userId'], + ]); + $categories = [ 'general' => [ 'categoryName' => $_Lang['Box_statGeneral'], @@ -63,7 +67,7 @@ function render($props) { 'statCategoryType' => $category['categoryType'], 'userCategoryRankLabel' => '0', 'userCategoryRankPosition' => '0', - 'userCategoryPoints' => prettyNumber($stats[$category['pointsKey']]), + 'userCategoryPoints' => prettyNumber($statsData[$category['pointsKey']]), 'statsUnit' => $_Lang['_statUnit'], ]; @@ -71,16 +75,16 @@ function render($props) { $recordsOldKey = $category['recordsOldKey']; if ( - !isset($stats[$recordsCurrentKey]) || - $stats[$recordsCurrentKey] <= 0 + !isset($statsData[$recordsCurrentKey]) || + $statsData[$recordsCurrentKey] <= 0 ) { $categoriesHTML[] = parsetemplate($tplBodyCache['statCategoryRow'], $categoryTplBodyParams); continue; } - $oldPosition = $stats[$recordsOldKey]; - $currentPosition = $stats[$recordsCurrentKey]; + $oldPosition = $statsData[$recordsOldKey]; + $currentPosition = $statsData[$recordsCurrentKey]; $positionDifference = $oldPosition - $currentPosition; $positionDifferenceLabel = null; diff --git a/modules/overview/screens/Overview/components/StatsList/StatsList.utils.php b/modules/overview/screens/Overview/components/StatsList/StatsList.utils.php new file mode 100644 index 000000000..e7d36a258 --- /dev/null +++ b/modules/overview/screens/Overview/components/StatsList/StatsList.utils.php @@ -0,0 +1,25 @@ + diff --git a/overview.php b/overview.php index 49da37909..50363bafe 100644 --- a/overview.php +++ b/overview.php @@ -180,10 +180,8 @@ $parse['RefferedCounter'] = prettyNumber((($Referred['count'] > 0) ? $Referred['count'] : '0')); // --- Render UserStats --- - $StatRecord = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `id_owner` = {$_User['id']} LIMIT 1;", 'statpoints', true); - $parse['Component_StatsList'] = Overview\Screens\Overview\Components\StatsList\render([ - 'stats' => $StatRecord, + 'userId' => $_User['id'], ])['componentHTML']; $parse['Component_CombatStatsList'] = Overview\Screens\Overview\Components\CombatStatsList\render([ 'userId' => $_User['id'],