From 4bbcb6c3d6aa329f0047b15745811ecc1ea598e2 Mon Sep 17 00:00:00 2001 From: aB0t Date: Wed, 17 Apr 2024 10:40:24 +0200 Subject: [PATCH] update 2024-04-17 10:40:23 --- .../README.md | 10 ++++ .../code.php | 48 ++++++++++++++++++- .../code.power | 48 ++++++++++++++++++- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/55278140-80d5-4168-8241-d64515c4b35e/README.md b/src/55278140-80d5-4168-8241-d64515c4b35e/README.md index 751766b..d2ccff8 100644 --- a/src/55278140-80d5-4168-8241-d64515c4b35e/README.md +++ b/src/55278140-80d5-4168-8241-d64515c4b35e/README.md @@ -61,6 +61,7 @@ class Builders << (F,LightGreen) >> #RoyalBlue { # CMSApplication $app + __construct(Config $config, Power $power, ...) + set(string $langLabel, string $langView, ...) : void + - normalizeDatabaseValues(string $nameSingleCode, string $name) : ?array } note right of Builders::__construct @@ -138,6 +139,15 @@ note right of Builders::set ?array $custom = null ?array $options = null end note + +note right of Builders::normalizeDatabaseValues + Normalizes database values by adjusting the 'length' and 'default' fields based on specific conditions. +This function modifies the database values by replacing placeholder texts and appending specifications +to types based on the 'length' field. It removes unnecessary fields from the result array. + + since: 3.2.1 + return: ?array +end note @enduml ``` diff --git a/src/55278140-80d5-4168-8241-d64515c4b35e/code.php b/src/55278140-80d5-4168-8241-d64515c4b35e/code.php index ee79b9a..5b7ed32 100644 --- a/src/55278140-80d5-4168-8241-d64515c4b35e/code.php +++ b/src/55278140-80d5-4168-8241-d64515c4b35e/code.php @@ -1300,10 +1300,56 @@ final class Builders 'title' => (is_string($title_) && $name === $title_) ? true : false, 'list' => $nameListCode, 'store' => (isset($field['store'])) ? $field['store'] : null, - 'tab_name' => $tabName + 'tab_name' => $tabName, + 'db' => $this->normalizeDatabaseValues($nameSingleCode, $name) ] ); } + } + + /** + * Normalizes database values by adjusting the 'length' and 'default' fields based on specific conditions. + * This function modifies the database values by replacing placeholder texts and appending specifications + * to types based on the 'length' field. It removes unnecessary fields from the result array. + * + * @param string $nameSingleCode The code for naming single entries. + * @param string $name The name of the database entry. + * + * @return array|null Returns the modified database values array or null if no values are found. + * @since 3.2.1 + */ + private function normalizeDatabaseValues($nameSingleCode, $name): ?array + { + $db_values = $this->databasetables->get($nameSingleCode . '.' . $name, null); + if ($db_values === null) + { + return null; + } + + if (isset($db_values['lenght'])) + { + if ($db_values['lenght'] === 'Other' && isset($db_values['lenght_other'])) + { + $db_values['lenght'] = $db_values['lenght_other']; + } + $db_values['lenght'] = trim($db_values['lenght']); + if (strlen($db_values['lenght'])) + { + $db_values['type'] .= '(' . $db_values['lenght'] . ')'; + } + } + + if (isset($db_values['default'])) + { + if ($db_values['default'] === 'Other' && isset($db_values['other'])) + { + $db_values['default'] = $db_values['other']; + } + } + + unset($db_values['ID'], $db_values['lenght'], $db_values['lenght_other'], $db_values['other']); + + return $db_values; } } diff --git a/src/55278140-80d5-4168-8241-d64515c4b35e/code.power b/src/55278140-80d5-4168-8241-d64515c4b35e/code.power index b224cca..55d343c 100644 --- a/src/55278140-80d5-4168-8241-d64515c4b35e/code.power +++ b/src/55278140-80d5-4168-8241-d64515c4b35e/code.power @@ -1223,8 +1223,54 @@ 'title' => (is_string($title_) && $name === $title_) ? true : false, 'list' => $nameListCode, 'store' => (isset($field['store'])) ? $field['store'] : null, - 'tab_name' => $tabName + 'tab_name' => $tabName, + 'db' => $this->normalizeDatabaseValues($nameSingleCode, $name) ] ); } + } + + /** + * Normalizes database values by adjusting the 'length' and 'default' fields based on specific conditions. + * This function modifies the database values by replacing placeholder texts and appending specifications + * to types based on the 'length' field. It removes unnecessary fields from the result array. + * + * @param string $nameSingleCode The code for naming single entries. + * @param string $name The name of the database entry. + * + * @return array|null Returns the modified database values array or null if no values are found. + * @since 3.2.1 + */ + private function normalizeDatabaseValues($nameSingleCode, $name): ?array + { + $db_values = $this->databasetables->get($nameSingleCode . '.' . $name, null); + if ($db_values === null) + { + return null; + } + + if (isset($db_values['lenght'])) + { + if ($db_values['lenght'] === 'Other' && isset($db_values['lenght_other'])) + { + $db_values['lenght'] = $db_values['lenght_other']; + } + $db_values['lenght'] = trim($db_values['lenght']); + if (strlen($db_values['lenght'])) + { + $db_values['type'] .= '(' . $db_values['lenght'] . ')'; + } + } + + if (isset($db_values['default'])) + { + if ($db_values['default'] === 'Other' && isset($db_values['other'])) + { + $db_values['default'] = $db_values['other']; + } + } + + unset($db_values['ID'], $db_values['lenght'], $db_values['lenght_other'], $db_values['other']); + + return $db_values; } \ No newline at end of file