Fix #478 - Add Currency Mapper

This commit is contained in:
Jack Anderson 2024-07-11 14:16:41 +01:00 committed by y.yerli
parent 7c96218746
commit d7880e064a
2 changed files with 86 additions and 0 deletions

View file

@ -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()] = [];

View file

@ -0,0 +1,84 @@
<?php
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2024 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/
require_once __DIR__ .'/TypeMapperInterface.php';
class CurrencyMapper implements TypeMapperInterface
{
/**
* @inheritDoc
*/
public static function getType(): string
{
return 'currency';
}
/**
* @inheritDoc
*/
public function toApi(SugarBean $bean, array &$container, string $name, string $alternativeName = ''): void
{
$newName = $name;
if (!empty($alternativeName)) {
$newName = $alternativeName;
}
if (empty($bean->$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";
}
}