src/Form/Flow/InstallFlow.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Form\Flow;
  3. // src/MyCompany/MyBundle/Form/CreateVehicleFlow.php
  4. use App\Form\InstallSensorForm;
  5. use Craue\FormFlowBundle\Event\GetStepsEvent;
  6. use Craue\FormFlowBundle\Event\PostBindFlowEvent;
  7. use Craue\FormFlowBundle\Event\PostBindRequestEvent;
  8. use Craue\FormFlowBundle\Event\PostBindSavedDataEvent;
  9. use Craue\FormFlowBundle\Event\PostValidateEvent;
  10. use Craue\FormFlowBundle\Event\PreBindEvent;
  11. use Craue\FormFlowBundle\Form\FormFlow;
  12. use Craue\FormFlowBundle\Form\FormFlowEvents;
  13. use Craue\FormFlowBundle\Form\FormFlowInterface;
  14. use Psr\Log\LoggerInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class InstallFlow extends FormFlow implements EventSubscriberInterface
  17. {
  18.     protected $logger;
  19.     public function __construct(LoggerInterface $logger)
  20.     {
  21.         $this->logger $logger;
  22.     }
  23.     public static function getSubscribedEvents(): array {
  24.         return [
  25.             FormFlowEvents::PRE_BIND => 'onPreBind',
  26.             FormFlowEvents::GET_STEPS => 'onGetSteps',
  27.             FormFlowEvents::POST_BIND_SAVED_DATA => 'onPostBindSavedData',
  28.             FormFlowEvents::POST_BIND_FLOW => 'onPostBindFlow',
  29.             FormFlowEvents::POST_BIND_REQUEST => 'onPostBindRequest',
  30.             FormFlowEvents::POST_VALIDATE => 'onPostValidate',
  31.         ];
  32.     }
  33.     public function onPreBind(PreBindEvent $event)
  34.     {
  35.         // ...
  36.     }
  37.     public function onGetSteps(GetStepsEvent $event)
  38.     {
  39.         // ...
  40.     }
  41.     public function onPostBindSavedData(PostBindSavedDataEvent $event)
  42.     {
  43.         // ...
  44.     }
  45.     public function onPostBindFlow(PostBindFlowEvent $event)
  46.     {
  47.         // ...
  48.     }
  49.     public function onPostBindRequest(PostBindRequestEvent $event)
  50.     {
  51.         // ...
  52.     }
  53.     public function onPostValidate(PostValidateEvent $event)
  54.     {
  55.         /*if($this->determineCurrentStepNumber() && $this->determineCurrentStepNumber() == 3) {
  56.             $manualInspection = $event->getFormData();
  57.             for($i = 1; $i < 16; $i++) {
  58.                 $methodName = 'getQ'.$i;
  59.                 $options = parent::getFormOptions(1);
  60.                 if($manualInspection->{$methodName}() == false) {
  61.                     $manualInspection->setHasAnswersWithNo(true);
  62.                     break;
  63.                 }
  64.             }
  65.         }*/
  66.     }
  67.     protected function loadStepsConfig(): array {
  68.         $this->logger->debug('AcoDebug: InstallFlow: loadStepsConfig');
  69.         return [
  70.             // Step 1: Info
  71.             [
  72.                 'label' => 'Adresse',
  73.                 'form_type' => InstallSensorForm::class,
  74.             ],
  75.             // Step 2: Info
  76.             [
  77.                 'label' => 'Info',
  78.                 'form_type' => InstallSensorForm::class,
  79.             ],
  80.             // Step 3: Fahrt separate Messspunkte
  81.             [
  82.                 'label' => 'Fahrt seaparate Messpunkte',
  83.                 'form_type' => InstallSensorForm::class,
  84.                 'skip' => function ($estimatedCurrentStepNumberFormFlowInterface $flow) {
  85.                     $this->logger->debug('AcoDebug: InstallFlow: Step 3: $estimatedCurrentStepNumber: '.$estimatedCurrentStepNumber);
  86.                     $this->logger->debug('AcoDebug: InstallFlow: Step 3: secondCond: '.(!$flow->getFormData()->hasMultipleDriveMeasuringPoint()));
  87.                     return $estimatedCurrentStepNumber >= && !$flow->getFormData()->hasMultipleDriveMeasuringPoint();
  88.                 },
  89.             ],
  90.             // Step 4: Fahrt ein Messspunkt
  91.             [
  92.                 'label' => 'Fahrt ein Messpunkt',
  93.                 'form_type' => InstallSensorForm::class,
  94.                 'skip' => function ($estimatedCurrentStepNumberFormFlowInterface $flow) {
  95.                     $this->logger->debug('AcoDebug: InstallFlow: Step 4: $estimatedCurrentStepNumber: '.$estimatedCurrentStepNumber);
  96.                     $this->logger->debug('AcoDebug: InstallFlow: Step 4: secondCond: '.$flow->getFormData()->hasMultipleDriveMeasuringPoint());
  97.                     return $estimatedCurrentStepNumber >= && $flow->getFormData()->hasMultipleDriveMeasuringPoint();
  98.                 },
  99.             ],
  100.             // Step 5: Sicherheitskreis vor den Türen
  101.             [
  102.                 'label' => 'Sicherheitskreis vor den Türen',
  103.                 'form_type' => InstallSensorForm::class,
  104.             ],
  105.             // Step 6: Sicherheitskreis nach den Türen
  106.             [
  107.                 'label' => 'Sicherheitskreis nach den Türen',
  108.                 'form_type' => InstallSensorForm::class,
  109.             ],
  110.             // Step 7: Sicherheitskreis Schachttüren
  111.             [
  112.                 'label' => 'Sicherheitskreis Schachttüren',
  113.                 'form_type' => InstallSensorForm::class,
  114.                 'skip' => function ($estimatedCurrentStepNumberFormFlowInterface $flow) {
  115.                     $this->logger->debug('AcoDebug: InstallFlow: Step 9: $estimatedCurrentStepNumber: '.$estimatedCurrentStepNumber);
  116.                     if ($estimatedCurrentStepNumber >= 6) {
  117.                         if (!$flow->getFormData()->getHasHoistwayDoor()) {
  118.                             $this->logger->debug('AcoDebug: InstallFlow: Step 9: getHasHoistwayDoor: '.(!$flow->getFormData()->getHasHoistwayDoor()));
  119.                             return true;
  120.                         }
  121.                     } else {
  122.                         $this->logger->debug('AcoDebug: InstallFlow: Step 9: else: '.true);
  123.                         return true;
  124.                     }
  125.                     $this->logger->debug('AcoDebug: InstallFlow: Step 9: end: '.false);
  126.                     return false;
  127.                 },
  128.             ],
  129.             // Step 8: Sammelstörung
  130.             [
  131.                 'label' => 'Sammelstörung',
  132.                 'form_type' => InstallSensorForm::class,
  133.                 'skip' => function ($estimatedCurrentStepNumberFormFlowInterface $flow) {
  134.                     if ($estimatedCurrentStepNumber >= 7) {
  135.                         if (!$flow->getFormData()->getHasCollectiveDisorder()) {
  136.                             return true;
  137.                         }
  138.                     }
  139.                     return false;
  140.                 },
  141.             ],
  142.             // Step 9: Kabinenlicht
  143.             [
  144.                 'label' => 'Kabinenlicht',
  145.                 'form_type' => InstallSensorForm::class,
  146.             ],
  147.             // Step 10: Netz
  148.             [
  149.                 'label' => 'Netz',
  150.                 'form_type' => InstallSensorForm::class,
  151.             ],
  152.             // Step 11: Invertierung
  153.             [
  154.                 'label' => 'Invertierung',
  155.                 'form_type' => InstallSensorForm::class,
  156.             ],
  157.             // Step 12: Dokumentation
  158.             [
  159.                 'label' => 'Dokumentation',
  160.                 'form_type' => InstallSensorForm::class,
  161.             ],
  162.         ];
  163.     }
  164. }