2024-04-20 00:04:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Editor;
|
|
|
|
|
|
|
|
use App\Form\Models\Participant;
|
2024-07-12 00:16:50 +02:00
|
|
|
use App\Lib\Editor\Condition;
|
2024-04-20 00:04:20 +02:00
|
|
|
use App\Lib\Editor\ConditionResolver;
|
|
|
|
|
|
|
|
class FormConditionResolver extends ConditionResolver
|
|
|
|
{
|
|
|
|
|
|
|
|
private Participant $participant;
|
|
|
|
|
|
|
|
public function forParticipant(Participant $participant): self
|
|
|
|
{
|
|
|
|
$this->participant = $participant;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-07-12 00:16:50 +02:00
|
|
|
public function filterCondition(Condition $condition): bool
|
2024-04-20 00:04:20 +02:00
|
|
|
{
|
2024-07-12 00:16:50 +02:00
|
|
|
if (!$condition->hasStatements()) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
foreach ($condition->ifs as $if) {
|
|
|
|
$field = $this->participant->getFields()->findByKey($if->field);
|
|
|
|
$matches = $field->matches($if->comparator, $if->value);
|
|
|
|
if ($matches && $condition->isAny()) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
2024-07-12 00:16:50 +02:00
|
|
|
if (!$matches && $condition->isAll()) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
if ($condition->isAny()) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-24 15:39:07 +02:00
|
|
|
return true;
|
2024-04-20 00:04:20 +02:00
|
|
|
}
|
|
|
|
}
|