src/Listing/Builder/ResultEntry/ResultEntryForQuoteFormatter.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Listing\Builder\ResultEntry;
  3. use App\Export\Builder\ExportBuilderInterface;
  4. use App\Export\Builder\ExporterInterface;
  5. use App\V4\Exporter\QuoteInvoicesExporter;
  6. use App\V4\Model\Quote\Quote;
  7. use App\V4\Model\Response\Listing\ListingResult;
  8. class ResultEntryForQuoteFormatter implements ResultEntryFormatterInterface
  9. {
  10.     /**
  11.      * @var ExportBuilderInterface
  12.      */
  13.     private $exportBuilder;
  14.     public function __construct(ExportBuilderInterface $exportBuilder)
  15.     {
  16.         $this->exportBuilder $exportBuilder;
  17.     }
  18.     /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function supports($entity): bool
  22.     {
  23.         return Quote::class === get_class($entity);
  24.     }
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function build($entity): ListingResult
  29.     {
  30.         /** @var Quote $entity */
  31.         $quoteMetadata = [
  32.             'id' => $entity->getId(),
  33.             'name' => $entity->getName(),
  34.             'prospectId' => $entity->getProspectId(),
  35.             'isLate' => $entity->isLate(),
  36.             'isWon' => $entity->isWon(),
  37.             'isSplit' => $entity->isSplit(),
  38.             'splitType' => $entity->getSplitType(),
  39.         ];
  40.         $quoteMetadata[QuoteInvoicesExporter::QUOTE_INVOICES] = $this->exportBuilder
  41.             ->getExporter($entityQuoteInvoicesExporter::QUOTE_INVOICESExporterInterface::EXPORT_TYPE_LISTING)
  42.             ->convert($entityQuoteInvoicesExporter::QUOTE_INVOICES)
  43.         ;
  44.         return (new ListingResult())
  45.             ->setMetadata($quoteMetadata)
  46.         ;
  47.     }
  48. }