<?php
namespace App\Form\Flow;
// src/MyCompany/MyBundle/Form/CreateVehicleFlow.php
use App\Form\InstallSensorForm;
use Craue\FormFlowBundle\Event\GetStepsEvent;
use Craue\FormFlowBundle\Event\PostBindFlowEvent;
use Craue\FormFlowBundle\Event\PostBindRequestEvent;
use Craue\FormFlowBundle\Event\PostBindSavedDataEvent;
use Craue\FormFlowBundle\Event\PostValidateEvent;
use Craue\FormFlowBundle\Event\PreBindEvent;
use Craue\FormFlowBundle\Form\FormFlow;
use Craue\FormFlowBundle\Form\FormFlowEvents;
use Craue\FormFlowBundle\Form\FormFlowInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class InstallFlow extends FormFlow implements EventSubscriberInterface
{
protected $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public static function getSubscribedEvents(): array {
return [
FormFlowEvents::PRE_BIND => 'onPreBind',
FormFlowEvents::GET_STEPS => 'onGetSteps',
FormFlowEvents::POST_BIND_SAVED_DATA => 'onPostBindSavedData',
FormFlowEvents::POST_BIND_FLOW => 'onPostBindFlow',
FormFlowEvents::POST_BIND_REQUEST => 'onPostBindRequest',
FormFlowEvents::POST_VALIDATE => 'onPostValidate',
];
}
public function onPreBind(PreBindEvent $event)
{
// ...
}
public function onGetSteps(GetStepsEvent $event)
{
// ...
}
public function onPostBindSavedData(PostBindSavedDataEvent $event)
{
// ...
}
public function onPostBindFlow(PostBindFlowEvent $event)
{
// ...
}
public function onPostBindRequest(PostBindRequestEvent $event)
{
// ...
}
public function onPostValidate(PostValidateEvent $event)
{
/*if($this->determineCurrentStepNumber() && $this->determineCurrentStepNumber() == 3) {
$manualInspection = $event->getFormData();
for($i = 1; $i < 16; $i++) {
$methodName = 'getQ'.$i;
$options = parent::getFormOptions(1);
if($manualInspection->{$methodName}() == false) {
$manualInspection->setHasAnswersWithNo(true);
break;
}
}
}*/
}
protected function loadStepsConfig(): array {
$this->logger->debug('AcoDebug: InstallFlow: loadStepsConfig');
return [
// Step 1: Info
[
'label' => 'Adresse',
'form_type' => InstallSensorForm::class,
],
// Step 2: Info
[
'label' => 'Info',
'form_type' => InstallSensorForm::class,
],
// Step 3: Fahrt separate Messspunkte
[
'label' => 'Fahrt seaparate Messpunkte',
'form_type' => InstallSensorForm::class,
'skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) {
$this->logger->debug('AcoDebug: InstallFlow: Step 3: $estimatedCurrentStepNumber: '.$estimatedCurrentStepNumber);
$this->logger->debug('AcoDebug: InstallFlow: Step 3: secondCond: '.(!$flow->getFormData()->hasMultipleDriveMeasuringPoint()));
return $estimatedCurrentStepNumber >= 2 && !$flow->getFormData()->hasMultipleDriveMeasuringPoint();
},
],
// Step 4: Fahrt ein Messspunkt
[
'label' => 'Fahrt ein Messpunkt',
'form_type' => InstallSensorForm::class,
'skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) {
$this->logger->debug('AcoDebug: InstallFlow: Step 4: $estimatedCurrentStepNumber: '.$estimatedCurrentStepNumber);
$this->logger->debug('AcoDebug: InstallFlow: Step 4: secondCond: '.$flow->getFormData()->hasMultipleDriveMeasuringPoint());
return $estimatedCurrentStepNumber >= 3 && $flow->getFormData()->hasMultipleDriveMeasuringPoint();
},
],
// Step 5: Sicherheitskreis vor den Türen
[
'label' => 'Sicherheitskreis vor den Türen',
'form_type' => InstallSensorForm::class,
],
// Step 6: Sicherheitskreis nach den Türen
[
'label' => 'Sicherheitskreis nach den Türen',
'form_type' => InstallSensorForm::class,
],
// Step 7: Sicherheitskreis Schachttüren
[
'label' => 'Sicherheitskreis Schachttüren',
'form_type' => InstallSensorForm::class,
'skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) {
$this->logger->debug('AcoDebug: InstallFlow: Step 9: $estimatedCurrentStepNumber: '.$estimatedCurrentStepNumber);
if ($estimatedCurrentStepNumber >= 6) {
if (!$flow->getFormData()->getHasHoistwayDoor()) {
$this->logger->debug('AcoDebug: InstallFlow: Step 9: getHasHoistwayDoor: '.(!$flow->getFormData()->getHasHoistwayDoor()));
return true;
}
} else {
$this->logger->debug('AcoDebug: InstallFlow: Step 9: else: '.true);
return true;
}
$this->logger->debug('AcoDebug: InstallFlow: Step 9: end: '.false);
return false;
},
],
// Step 8: Sammelstörung
[
'label' => 'Sammelstörung',
'form_type' => InstallSensorForm::class,
'skip' => function ($estimatedCurrentStepNumber, FormFlowInterface $flow) {
if ($estimatedCurrentStepNumber >= 7) {
if (!$flow->getFormData()->getHasCollectiveDisorder()) {
return true;
}
}
return false;
},
],
// Step 9: Kabinenlicht
[
'label' => 'Kabinenlicht',
'form_type' => InstallSensorForm::class,
],
// Step 10: Netz
[
'label' => 'Netz',
'form_type' => InstallSensorForm::class,
],
// Step 11: Invertierung
[
'label' => 'Invertierung',
'form_type' => InstallSensorForm::class,
],
// Step 12: Dokumentation
[
'label' => 'Dokumentation',
'form_type' => InstallSensorForm::class,
],
];
}
}