diff --git a/app/Export/CSV/PaymentExport.php b/app/Export/CSV/PaymentExport.php index 425375295821..86ee229bfd5f 100644 --- a/app/Export/CSV/PaymentExport.php +++ b/app/Export/CSV/PaymentExport.php @@ -117,6 +117,8 @@ class PaymentExport extends BaseExport } elseif (array_key_exists($key, $transformed_entity)) { $entity[$key] = $transformed_entity[$key]; } else { + + // $entity[$key] = $this->decorator->transform($key, $payment); $entity[$key] = $this->resolveKey($key, $payment, $this->entity_transformer); } diff --git a/app/Export/Decorators/Decorator.php b/app/Export/Decorators/Decorator.php index 970151dae739..fd8918fe7cd0 100644 --- a/app/Export/Decorators/Decorator.php +++ b/app/Export/Decorators/Decorator.php @@ -34,7 +34,7 @@ class Decorator implements DecoratorInterface{ { } - public function transform(): string + public function transform(string $key, mixed $entity): string { return 'Decorator'; } @@ -110,4 +110,11 @@ class Decorator implements DecoratorInterface{ { return $this->entity; } + + public function getKeyPart(int $index, string $key): string + { + $parts = explode('.', $key ?? ''); + + return $parts[$index]; + } } diff --git a/app/Export/Decorators/DecoratorInterface.php b/app/Export/Decorators/DecoratorInterface.php index a19b231f8fda..60225d257c8d 100644 --- a/app/Export/Decorators/DecoratorInterface.php +++ b/app/Export/Decorators/DecoratorInterface.php @@ -12,5 +12,5 @@ namespace App\Export\Decorators; interface DecoratorInterface { - public function transform(): string; + public function transform(string $key, mixed $entity): string; } diff --git a/app/Export/Decorators/PaymentDecorator.php b/app/Export/Decorators/PaymentDecorator.php index ae0fea96c4e5..82f619fdd0f4 100644 --- a/app/Export/Decorators/PaymentDecorator.php +++ b/app/Export/Decorators/PaymentDecorator.php @@ -15,9 +15,16 @@ use App\Models\Payment; class PaymentDecorator extends Decorator implements DecoratorInterface{ - public function transform(): string + private $key = 'payment'; + + public function transform(string $key, $payment): string { + $index = $this->getKeyPart(0,$key); + + // match($index) return 'Payment Decorator'; } + + } \ No newline at end of file