src/Modules/Contract/Event/Subscriber/ChangeWarrantyContractStatus.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Modules\Contract\Event\Subscriber;
  3. use App\Modules\Contract\Entity\Contract;
  4. use App\Modules\Contract\Event\WarrantyFormUpdated;
  5. use App\Modules\Contract\Service\ContractService;
  6. use App\Modules\Contract\StateMachine\WarrantyFormState;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ChangeWarrantyContractStatus implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var ContractService
  12.      */
  13.     private $contractService;
  14.     public function __construct(ContractService $contractService)
  15.     {
  16.         $this->contractService $contractService;
  17.     }
  18.     /**
  19.      * Returns an array of event names this subscriber wants to listen to.
  20.      *
  21.      * The array keys are event names and the value can be:
  22.      *
  23.      *  * The method name to call (priority defaults to 0)
  24.      *  * An array composed of the method name to call and the priority
  25.      *  * An array of arrays composed of the method names to call and respective
  26.      *    priorities, or 0 if unset
  27.      *
  28.      * For instance:
  29.      *
  30.      *  * ['eventName' => 'methodName']
  31.      *  * ['eventName' => ['methodName', $priority]]
  32.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  33.      *
  34.      * @return array The event names to listen to
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             WarrantyFormUpdated::class => 'onWarrantyFormUpdated',
  40.         ];
  41.     }
  42.     public function onWarrantyFormUpdated(WarrantyFormUpdated $event)
  43.     {
  44.         $form $event->getForm();
  45.         $contract $form->getContract();
  46.         if (is_null($contract)) {
  47.             return;
  48.         }
  49.         $formProgress $form->getState();
  50.         if (in_array($formProgressWarrantyFormState::$inProgressStatuses)) {
  51.             $this->contractService->updateStatus($contractContract::STATUS_IN_PROGRESS);
  52.         } elseif (in_array($formProgressWarrantyFormState::$claimedStatuses)) {
  53.             $this->contractService->updateStatus($contractContract::STATUS_CLAIMED);
  54.         } elseif (in_array($formProgressWarrantyFormState::$disputedStatuses)) {
  55.             $this->contractService->updateStatus($contractContract::STATUS_DISPUTED);
  56.         } elseif (in_array($formProgressWarrantyFormState::$cancelledStatus)) {
  57.             $this->contractService->updateStatus($contractContract::STATUS_CANCELLED);
  58.         } elseif (in_array($formProgressWarrantyFormState::$acceptedButNeverCompletedStatus)) {
  59.             $this->contractService->updateStatus($contractContract::STATUS_ACCEPTED_BUT_NEVER_COMPLETED);
  60.         } elseif (in_array($formProgressWarrantyFormState::$rejectedStatuses)) {
  61.             $this->contractService->updateStatus($contractContract::STATUS_REJECTED);
  62.         } elseif (in_array($formProgressWarrantyFormState::$completedStatuses)) {
  63.             $this->contractService->updateStatus($contractContract::STATUS_COMPLETED);
  64.         }
  65.     }
  66. }