. */ namespace App\Services\LabelSystem\PlaceholderProviders; use App\Entity\Parts\PartLot; use App\Services\AmountFormatter; use App\Services\LabelSystem\LabelTextReplacer; use IntlDateFormatter; use Locale; class PartLotProvider implements PlaceholderProviderInterface { protected $labelTextReplacer; protected $amountFormatter; public function __construct(LabelTextReplacer $labelTextReplacer, AmountFormatter $amountFormatter) { $this->labelTextReplacer = $labelTextReplacer; $this->amountFormatter = $amountFormatter; } public function replace(string $placeholder, object $label_target, array $options = []): ?string { if ($label_target instanceof PartLot) { if ($placeholder === '[[LOT_ID]]') { return $label_target->getID() ?? 'unknown'; } if ($placeholder === '[[LOT_NAME]]') { return $label_target->getName(); } if ($placeholder === '[[LOT_COMMENT]]') { return $label_target->getComment(); } if ($placeholder === '[[EXPIRATION_DATE]]') { if ($label_target->getExpirationDate() === null) { return ''; } $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::NONE //$label_target->getExpirationDate()->getTimezone() ); return $formatter->format($label_target->getExpirationDate()); } if ($placeholder === '[[AMOUNT]]') { if ($label_target->isInstockUnknown()) { return '?'; } return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit()); } if ($placeholder === '[[LOCATION]]') { return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : ''; } if ($placeholder === '[[LOCATION_FULL]]') { return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : ''; } return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart()); } return null; } }