src/Invoice/Form/Dto/Factory/InvoiceEmailDraftCreateFormDtoFactory.php line 49
<?phpdeclare(strict_types=1);/*** Copyright (c) 2020 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2020 TECLA Consulting Group oü*/namespace App\Invoice\Form\Dto\Factory;use App\Contact\Security\ContactContextInterface;use App\Invoice\Form\Dto\InvoiceEmailDraftCreateFormDto;use App\Invoice\Model\InvoiceInterface;use App\Invoice\Query\InvoiceEmail\FindLatestByInvoiceQueryInterface;use App\Invoice\Util\DefaultInvoiceEmailMessageGeneratorInterface;final class InvoiceEmailDraftCreateFormDtoFactory implements InvoiceEmailDraftCreateFormDtoFactoryInterface{private ContactContextInterface $contactContext;private DefaultInvoiceEmailMessageGeneratorInterface $defaultMessageGenerator;private EmailRecipientFormDtoFactoryInterface $recipientDtoFactory;private FindLatestByInvoiceQueryInterface $latestByInvoiceQuery;public function __construct(ContactContextInterface $contactContext,DefaultInvoiceEmailMessageGeneratorInterface $defaultMessageGenerator,EmailRecipientFormDtoFactoryInterface $recipientDtoFactory,FindLatestByInvoiceQueryInterface $latestByInvoiceQuery) {$this->contactContext = $contactContext;$this->defaultMessageGenerator = $defaultMessageGenerator;$this->recipientDtoFactory = $recipientDtoFactory;$this->latestByInvoiceQuery = $latestByInvoiceQuery;}public function create(array $recipients = [], array $recipientsCc = [], array $recipientsBcc = [], string $message = null): InvoiceEmailDraftCreateFormDto{return new InvoiceEmailDraftCreateFormDto($recipients,$recipientsCc,$recipientsBcc,$message);}public function createDefault(InvoiceInterface $invoice): InvoiceEmailDraftCreateFormDto{if (null !== ($latestSentInvoice = $this->latestByInvoiceQuery->execute($invoice))) {$recipients = $this->recipientDtoFactory->createFromCollection($latestSentInvoice->getRecipients());$recipientsCc = $this->recipientDtoFactory->createFromCollection($latestSentInvoice->getRecipientsCc());} elseif (false === empty($invoice->getRecipients())) {$recipients = $this->recipientDtoFactory->createFromCollection($invoice->getRecipients());$recipientsCc = $this->recipientDtoFactory->createFromCollection($invoice->getRecipientsCc());} else {$recipients = [$this->recipientDtoFactory->create($invoice->getCustomer()->getContactEmail()?->getEmail())];$recipientsCc = [$this->recipientDtoFactory->create($this->contactContext->getBase()?->getContactEmail()?->getEmail() ??$invoice->getSupplier()->getContactEmail()?->getEmail())];}return $this->create($recipients,$recipientsCc,[],$this->defaultMessageGenerator->generate($invoice));}}