From d7880e064a4c165e22d38ca930a95c17b89e8348 Mon Sep 17 00:00:00 2001 From: Jack Anderson Date: Thu, 11 Jul 2024 14:16:41 +0100 Subject: [PATCH] Fix #478 - Add Currency Mapper --- .../ApiBeanMapper/ApiBeanMapper.php | 2 + .../TypeMappers/CurrencyMapper.php | 84 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 public/legacy/include/portability/ApiBeanMapper/TypeMappers/CurrencyMapper.php diff --git a/public/legacy/include/portability/ApiBeanMapper/ApiBeanMapper.php b/public/legacy/include/portability/ApiBeanMapper/ApiBeanMapper.php index ed0683b0e..485c4f856 100644 --- a/public/legacy/include/portability/ApiBeanMapper/ApiBeanMapper.php +++ b/public/legacy/include/portability/ApiBeanMapper/ApiBeanMapper.php @@ -39,6 +39,7 @@ require_once __DIR__ . '/TypeMappers/MultiEnumMapper.php'; require_once __DIR__ . '/TypeMappers/BooleanMapper.php'; require_once __DIR__ . '/TypeMappers/HtmlMapper.php'; require_once __DIR__ . '/TypeMappers/TextMapper.php'; +require_once __DIR__ . '/TypeMappers/CurrencyMapper.php'; require_once __DIR__ . '/ApiBeanModuleMappers.php'; require_once __DIR__ . '/ModuleMappers/SavedSearch/SavedSearchMappers.php'; require_once __DIR__ . '/ModuleMappers/AOP_Case_Updates/CaseUpdatesMappers.php'; @@ -86,6 +87,7 @@ class ApiBeanMapper $this->typeMappers['boolean'] = $this->typeMappers[BooleanMapper::getType()]; $this->typeMappers[HtmlMapper::getType()] = new HtmlMapper(); $this->typeMappers[TextMapper::getType()] = new TextMapper(); + $this->typeMappers[CurrencyMapper::getType()] = new CurrencyMapper(); $this->moduleMappers[SavedSearchMappers::getModule()] = new SavedSearchMappers(); $this->typeMappers[DateTimeComboMapper::getType()] = new DateTimeMapper(); $this->linkMappers[EmailAddressLinkMapper::getRelateModule()] = []; diff --git a/public/legacy/include/portability/ApiBeanMapper/TypeMappers/CurrencyMapper.php b/public/legacy/include/portability/ApiBeanMapper/TypeMappers/CurrencyMapper.php new file mode 100644 index 000000000..117fcf454 --- /dev/null +++ b/public/legacy/include/portability/ApiBeanMapper/TypeMappers/CurrencyMapper.php @@ -0,0 +1,84 @@ +$name)) { + $container[$newName] = ''; + + return; + } + + $value = $bean->$name; + + $value = format_number($value); + $container[$newName] = "$value"; + } + + /** + * @inheritDoc + */ + public function toBean(SugarBean $bean, array &$container, string $name, string $alternativeName = ''): void + { + $newName = $name; + + if (!empty($alternativeName)) { + $newName = $alternativeName; + } + + $value = $container[$newName] ?? ''; + + if (empty($value)) { + return; + } + + $value = format_number($value); + + $container[$newName] = "$value"; + } +}