Initial survey bundle import
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user