vendor/bluue/sales-bundle/src/EventSubscriber/AccessEditDocumentValidatedSubscriber.php line 77

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\SalesBundle\EventSubscriber;
  9. use App\Services\Configuration;
  10. use Bluue\SalesBundle\Event\ConfigurationAccessQuotationEditEvent;
  11. use Bluue\SalesBundle\Security\SalesVoter;
  12. use Symfony\Component\Security\Core\Security;
  13. use Bluue\SalesBundle\Event\ConfigurationAccessOrderEditEvent;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class AccessEditDocumentValidatedSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var Configuration
  19.      */
  20.     protected Configuration $configuration;
  21.     /**
  22.      * @var Security
  23.      */
  24.     protected Security $security;
  25.     /**
  26.      * @param Configuration $configuration
  27.      * @param Security $security
  28.      */
  29.     public function __construct(Configuration $configurationSecurity $security)
  30.     {
  31.         $this->configuration $configuration;
  32.         $this->security $security;
  33.     }
  34.     /**
  35.      * @return array
  36.      */
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [
  40.             ConfigurationAccessOrderEditEvent::NAME => 'orderEdit',
  41.             ConfigurationAccessQuotationEditEvent::NAME => 'quotationEdit'
  42.         ];
  43.     }
  44.     /**
  45.      * @param ConfigurationAccessOrderEditEvent $event
  46.      * @return void
  47.      */
  48.     public function orderEdit(ConfigurationAccessOrderEditEvent $event): void
  49.     {
  50.         $order $event->getOrder();
  51.         if (
  52.             !$this->configuration->get('sales_bundle__modify_quotations_and_orders_validated')
  53.             || !$this->security->isGranted(SalesVoter::ACCESS$order)
  54.             || !$order->getInvoices()->isEmpty()
  55.             || !$order->getFilterDeliveryNotes(falsefalsefalsetrue)->isEmpty()
  56.         ) {
  57.             return;
  58.         }
  59.         $event->setIsAccess(true);
  60.     }
  61.     /**
  62.      * @param ConfigurationAccessQuotationEditEvent $event
  63.      * @return void
  64.      */
  65.     public function quotationEdit(ConfigurationAccessQuotationEditEvent $event): void
  66.     {
  67.         $quotation $event->getQuotation();
  68.         if (
  69.             !$this->configuration->get('sales_bundle__modify_quotations_and_orders_validated')
  70.             || !$this->security->isGranted(SalesVoter::ACCESS$quotation)
  71.             || $quotation->getOrder()
  72.             || !$quotation->getInvoices()->isEmpty()
  73.         ) {
  74.             return;
  75.         }
  76.         $event->setAccess(true);
  77.     }
  78. }