From b5ceeeb6c28fb52e4d1a8e8b721d73ef02e1e302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Thu, 30 Jun 2022 23:09:18 +0200 Subject: [PATCH] GH-224 Move fleet mission colors form to a component --- modules/settings/_includes.php | 1 + .../FleetMissionColorsForm.component.php | 57 +++++++++++++++++++ .../FleetMissionColorsForm/index.php | 5 ++ .../FleetMissionColorsForm/missionRow.tpl | 0 settings.php | 27 +++------ 5 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 modules/settings/components/FleetMissionColorsForm/FleetMissionColorsForm.component.php create mode 100644 modules/settings/components/FleetMissionColorsForm/index.php rename templates/default_template/settings_fleetcolors_row.tpl => modules/settings/components/FleetMissionColorsForm/missionRow.tpl (100%) diff --git a/modules/settings/_includes.php b/modules/settings/_includes.php index 07c1101f2..cc50c91f9 100644 --- a/modules/settings/_includes.php +++ b/modules/settings/_includes.php @@ -6,6 +6,7 @@ $includePath = $_EnginePath . 'modules/settings/'; + include($includePath . './components/FleetMissionColorsForm/FleetMissionColorsForm.component.php'); include($includePath . './components/IgnoredUsersList/IgnoredUsersList.component.php'); include($includePath . './components/LanguageSelectorList/LanguageSelectorList.component.php'); include($includePath . './components/LoginHistory/LoginHistory.component.php'); diff --git a/modules/settings/components/FleetMissionColorsForm/FleetMissionColorsForm.component.php b/modules/settings/components/FleetMissionColorsForm/FleetMissionColorsForm.component.php new file mode 100644 index 000000000..679b221d4 --- /dev/null +++ b/modules/settings/components/FleetMissionColorsForm/FleetMissionColorsForm.component.php @@ -0,0 +1,57 @@ + $localTemplateLoader('missionRow'), + ]; + + $getMissionColor = function ($missionId, $flightType) use ($missionsColorSettings) { + return ( + isset($missionsColorSettings[$flightType][$missionId]) ? + $missionsColorSettings[$flightType][$missionId] : + null + ); + }; + + $missionRows = array_map_withkeys( + $_Vars_FleetMissions['all'], + function ($missionId) use (&$tplBodyCache, &$_Lang, $getMissionColor) { + $tplParams = [ + 'MissionName' => $_Lang['type_mission'][$missionId], + 'MissionID' => $missionId, + 'Value_OwnFly' => $getMissionColor($missionId, 'ownfly'), + 'Value_OwnComeback' => $getMissionColor($missionId, 'owncb'), + 'Value_NonOwn' => $getMissionColor($missionId, 'nonown'), + ]; + + return parsetemplate($tplBodyCache['missionRow'], $tplParams); + } + ); + + $componentHTML = implode('', $missionRows); + + return [ + 'componentHTML' => $componentHTML + ]; +} + +?> diff --git a/modules/settings/components/FleetMissionColorsForm/index.php b/modules/settings/components/FleetMissionColorsForm/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/settings/components/FleetMissionColorsForm/index.php @@ -0,0 +1,5 @@ + diff --git a/templates/default_template/settings_fleetcolors_row.tpl b/modules/settings/components/FleetMissionColorsForm/missionRow.tpl similarity index 100% rename from templates/default_template/settings_fleetcolors_row.tpl rename to modules/settings/components/FleetMissionColorsForm/missionRow.tpl diff --git a/settings.php b/settings.php index 2707c33fa..5ad893122 100644 --- a/settings.php +++ b/settings.php @@ -1065,26 +1065,13 @@ function isInputKeyChecked($input, $key) { ])['componentHTML']; // FleetColors - Pickers - $TPL_FleetColors_Row = gettemplate('settings_fleetcolors_row'); - if(!empty($_User['settings_FleetColors'])) - { - if(isset($FleetColors_NeedChange) && $FleetColors_NeedChange === true) - { - $_User['settings_FleetColors'] = stripslashes($_User['settings_FleetColors']); - } - $FleetColors = json_decode($_User['settings_FleetColors'], true); - } - foreach($_Vars_FleetMissions['all'] as $MissionID) - { - $_Lang['Insert_FleetColors_Pickers'][] = parsetemplate($TPL_FleetColors_Row, [ - 'MissionName' => $_Lang['type_mission'][$MissionID], - 'MissionID' => $MissionID, - 'Value_OwnFly' => (isset($FleetColors['ownfly'][$MissionID]) ? $FleetColors['ownfly'][$MissionID] : null), - 'Value_OwnComeback' => (isset($FleetColors['owncb'][$MissionID]) ? $FleetColors['owncb'][$MissionID] : null), - 'Value_NonOwn' => (isset($FleetColors['nonown'][$MissionID]) ? $FleetColors['nonown'][$MissionID] : null), - ]); - } - $_Lang['Insert_FleetColors_Pickers'] = implode('', $_Lang['Insert_FleetColors_Pickers']); + $_Lang['Insert_FleetColors_Pickers'] = Settings\Components\FleetMissionColorsForm\render([ + 'missionsColorSettings' => ( + (isset($FleetColors_NeedChange) && $FleetColors_NeedChange) ? + stripslashes($_User['settings_FleetColors']) : + $_User['settings_FleetColors'] + ), + ])['componentHTML']; $BodyTPL = gettemplate('settings_body'); $Page = parsetemplate($BodyTPL, $_Lang);