adrema/app/Form/Editor/FormConditionResolver.php

48 lines
1.0 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Form\Editor;
use App\Form\Models\Participant;
2024-07-12 00:16:50 +02:00
use App\Lib\Editor\Condition;
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-07-12 00:16:50 +02:00
if (!$condition->hasStatements()) {
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()) {
return true;
}
2024-07-12 00:16:50 +02:00
if (!$matches && $condition->isAll()) {
return false;
}
}
2024-07-12 00:16:50 +02:00
if ($condition->isAny()) {
return false;
}
2024-04-24 15:39:07 +02:00
return true;
}
}