10 private const EMPTY_FIELD_NAME =
null;
20 $this->mapper = $mapper;
33 "name" => $form[
"NAME"],
34 "description" => !$form[
'CONTEXT_CARD'][
'content']
36 : implode(PHP_EOL, $form[
'CONTEXT_CARD'][
'content']),
37 "title" => $form[
'CONTEXT_CARD'][
'title'],
38 "fields" => $this->buildQuestions($form[
'QUESTIONS'] ?? []),
39 "message" => $form[
'THANK_YOU_PAGE'][
'title'],
40 "link" => $form[
'FOLLOW_UP_ACTION_URL'],
41 "active" => $form[
'STATUS'] ===
'ACTIVE'
51 private function buildQuestions(array $questions): array
53 $questionsResult = [];
54 foreach ($questions as $field)
56 if ($this->mapper->getCrmName($field[
'type']))
60 self::EMPTY_FIELD_NAME,
65 elseif ($field[
'type'] ===
"CUSTOM")
69 is_array($field[
'dependent_conditional_questions'])
70 && is_array($field[
'conditional_questions_choices'])
75 self::EMPTY_FIELD_NAME,
78 $this->getOptions($field[
'conditional_questions_choices'], 0)
80 foreach ($field[
'dependent_conditional_questions'] as $key => $question)
84 self::EMPTY_FIELD_NAME,
86 $question[
'field_key'],
87 $this->getOptions($field[
'conditional_questions_choices'], $key + 1)
91 elseif (is_array($field[
'options']))
95 self::EMPTY_FIELD_NAME,
99 static function ($option): array {
101 "key" => $option[
"key"],
102 "label" => $option[
'value'],
111 $questionsResult[] =
new LeadAds\Field(
113 self::EMPTY_FIELD_NAME,
121 return $questionsResult;
130 private function getOptions(array $options,
int $depth): array
133 foreach ($options as $value)
137 $result[$value[
'customized_token']] = [
'key' => $value[
'customized_token'],
'label' => $value[
'value']];
139 elseif ($depth > 0 && $value[
'next_question_choices'])
141 foreach ($this->getOptions($value[
'next_question_choices'], $depth - 1) as $option)
143 if (array_key_exists($option[
"key"], $result))
148 $result[$option[
"key"]] = $option;