From db8f2d184c8b636ded2fb112f818842fee306054 Mon Sep 17 00:00:00 2001 From: Steffen Persch Date: Mon, 30 Oct 2023 14:09:40 +0100 Subject: [PATCH] [ENH] add option to currencyColumn to sepcify currency path --- src/ColumnType/CurrencyColumn.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ColumnType/CurrencyColumn.php b/src/ColumnType/CurrencyColumn.php index 965b050..d592ee1 100644 --- a/src/ColumnType/CurrencyColumn.php +++ b/src/ColumnType/CurrencyColumn.php @@ -15,9 +15,34 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults([ 'currency' => 'EUR', + 'currency_path' => null, + 'divider' => 0, ]); - $resolver->setAllowedTypes('currency', ['string']); + $resolver->setAllowedTypes('currency', ['string', 'null']); + $resolver->setAllowedTypes('currency_path', ['string', 'null']); + $resolver->setAllowedValues('currency', Currencies::getCurrencyCodes()); } + + public function getValue(string $field, object $object, array $options = []) + { + $value = parent::getValue($field, $object, $options); + + if ($options['divider'] > 0) { + $value /= $options['divider']; + } + + return $value; + } + + public function getCurrency(object $object, array $options) + { + if ($options['currency_path']) { + return $this->propertyAccessor->getValue($object, $options['currency_path']); + } + + return $options['currency']; + } + }