38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mummert\SurveyBundle\Service;
|
|
|
|
use Mummert\SurveyBundle\Model\SurveyContentModel;
|
|
use Mummert\SurveyBundle\Model\SurveyModel;
|
|
use Mummert\SurveyBundle\Repository\SurveyConditionRepository;
|
|
use Mummert\SurveyBundle\Repository\SurveyQuestionRepository;
|
|
|
|
final class SurveyEngine
|
|
{
|
|
public function __construct(
|
|
private readonly SurveyConditionRepository $surveyConditionRepository,
|
|
private readonly SurveyQuestionRepository $surveyQuestionRepository,
|
|
) {
|
|
}
|
|
|
|
public function resolveConditionalTarget(SurveyModel $survey, SurveyContentModel $sourceQuestion, string $normalizedAnswer): ?SurveyContentModel
|
|
{
|
|
$condition = $this->surveyConditionRepository->findMatchingCondition(
|
|
(int) $survey->id,
|
|
(int) $sourceQuestion->id,
|
|
mb_strtolower(trim($normalizedAnswer)),
|
|
);
|
|
|
|
if (null === $condition) {
|
|
return null;
|
|
}
|
|
|
|
return $this->surveyQuestionRepository->findByIdForSurvey(
|
|
(int) $survey->id,
|
|
(int) $condition->targetQuestion,
|
|
false,
|
|
);
|
|
}
|
|
} |