vendor/bluue/recurring-invoices-bundle/src/EventSubscriber/ConfigQuotationButtonsSubscriber.php line 65

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\RecurringInvoicesBundle\EventSubscriber;
  9. use Bluue\RecurringInvoicesBundle\Repository\RecurringInvoiceRepository;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Bluue\SalesBundle\Event\ConfigQuotationButtonsEvent;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ConfigQuotationButtonsSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var ContainerInterface
  18.      */
  19.     private ContainerInterface $container;
  20.     /**
  21.      * @var TranslatorInterface
  22.      */
  23.     private TranslatorInterface $tr;
  24.     /**
  25.      * @var RecurringInvoiceRepository
  26.      */
  27.     private RecurringInvoiceRepository $recurringInvoiceRepo;
  28.     /**
  29.      * @param ContainerInterface $container
  30.      * @param TranslatorInterface $tr
  31.      * @param RecurringInvoiceRepository $recurringInvoiceRepo
  32.      */
  33.     public function __construct(
  34.         ContainerInterface $container,
  35.         TranslatorInterface $tr,
  36.         RecurringInvoiceRepository $recurringInvoiceRepo
  37.     ) {
  38.         $this->container $container;
  39.         $this->tr $tr;
  40.         $this->recurringInvoiceRepo $recurringInvoiceRepo;
  41.     }
  42.     /**
  43.      * @return array
  44.      */
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             ConfigQuotationButtonsEvent::NAME => 'onLoad'
  49.         ];
  50.     }
  51.     /**
  52.      * @param ConfigQuotationButtonsEvent $event
  53.      * @return void
  54.      */
  55.     public function onLoad(ConfigQuotationButtonsEvent $event): void
  56.     {
  57.         $id $event->getQuotationId();
  58.         $recurringInvoiceExist $this->recurringInvoiceRepo->findOneBy(['quotation' => $id]);
  59.         if (!$recurringInvoiceExist) {
  60.             $router $this->container->get('router');
  61.             $buttons $event->getButtons();
  62.             $path $router->generate('recurring_invoices_bundle__quotation_to_recurring_invoice', ['id' => $id]);
  63.             $trView $this->tr->trans('Convert to recurring invoice', [], 'RecurringInvoicesBundle');
  64.             $buttons[] = '<div class="btn-group mr-1 align-self-start">
  65.                 <a href="' $path '" class="btn btn-primary">
  66.                     <i class="fas fa-file-invoice"></i>
  67.                     ' $trView '
  68.                 </a>
  69.             </div>';
  70.             $event->setButtons($buttons);
  71.         }
  72.     }
  73. }