1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
facebookformbuilder.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Seo\LeadAds\Response\Builder
;
4
5
use
Bitrix\Seo\LeadAds
;
6
use
Bitrix\Seo\LeadAds\LeadAdsForm
;
7
8
class
FacebookFormBuilder
implements
FormBuilderInterface
9
{
10
private
const
EMPTY_FIELD_NAME =
null
;
11
13
private
$mapper;
14
18
public
function
__construct
(
LeadAds
\
Mapper
$mapper)
19
{
20
$this->mapper = $mapper;
21
}
22
28
public
function
buildForm
(
array
$form):
LeadAdsForm
29
{
30
return
new
LeadAdsForm
(
31
[
32
"id"
=> $form[
"ID"
],
33
"name"
=> $form[
"NAME"
],
34
"description"
=> !$form[
'CONTEXT_CARD'
][
'content'
]
35
?
null
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'
42
]
43
);
44
}
45
51
private
function
buildQuestions(
array
$questions):
array
52
{
53
$questionsResult = [];
54
foreach
($questions as $field)
55
{
56
if
($this->mapper->getCrmName($field[
'type'
]))
57
{
58
$questionsResult[] =
new
LeadAds\Field
(
59
$field[
'type'
],
60
self::EMPTY_FIELD_NAME,
61
$field[
'label'
],
62
$field[
'key'
]
63
);
64
}
65
elseif
($field[
'type'
] ===
"CUSTOM"
)
66
{
67
//if question is custom condition
68
if
(
69
is_array($field[
'dependent_conditional_questions'
])
70
&& is_array($field[
'conditional_questions_choices'
])
71
)
72
{
73
$questionsResult[] =
new
LeadAds\Field
(
74
LeadAds
\
Field::TYPE_RADIO
,
75
self::EMPTY_FIELD_NAME,
76
$field[
'label'
],
77
$field[
'key'
],
78
$this->getOptions($field[
'conditional_questions_choices'
], 0)
79
);
80
foreach
($field[
'dependent_conditional_questions'
] as
$key
=> $question)
81
{
82
$questionsResult[] =
new
LeadAds\Field
(
83
LeadAds
\
Field::TYPE_RADIO
,
84
self::EMPTY_FIELD_NAME,
85
$question[
'name'
],
86
$question[
'field_key'
],
87
$this->getOptions($field[
'conditional_questions_choices'
],
$key
+ 1)
88
);
89
}
90
}
91
elseif
(is_array($field[
'options'
]))
92
{
93
$questionsResult[] =
new
LeadAds\Field
(
94
LeadAds
\
Field::TYPE_RADIO
,
95
self::EMPTY_FIELD_NAME,
96
$field[
'label'
],
97
$field[
'key'
],
98
array_map(
99
static
function
(
$option
):
array
{
100
return
[
101
"key"
=>
$option
[
"key"
],
102
"label"
=>
$option
[
'value'
],
103
];
104
},
105
$field[
'options'
]
106
)
107
);
108
}
109
else
110
{
111
$questionsResult[] =
new
LeadAds\Field(
112
LeadAds\
Field::TYPE_INPUT
,
113
self::EMPTY_FIELD_NAME,
114
$field[
'label'
],
115
$field[
'key'
]
116
);
117
}
118
}
119
}
120
121
return
$questionsResult;
122
}
123
130
private
function
getOptions(
array
$options
,
int
$depth):
array
131
{
132
$result
= [];
133
foreach
(
$options
as $value)
134
{
135
if
($depth === 0)
136
{
137
$result
[
$value
[
'customized_token'
]] = [
'key'
=>
$value
[
'customized_token'
],
'label'
=>
$value
[
'value'
]];
138
}
139
elseif
($depth > 0 && $value[
'next_question_choices'
])
140
{
141
foreach
($this->getOptions($value[
'next_question_choices'
], $depth - 1) as
$option
)
142
{
143
if
(array_key_exists(
$option
[
"key"
],
$result
))
144
{
145
continue
;
146
}
147
148
$result
[
$option
[
"key"
]] =
$option
;
149
}
150
}
151
}
152
153
return
$result
;
154
}
155
}
Bitrix\Main\ORM\Fields\Field
Определения
field.php:25
Bitrix\Seo\LeadAds\Field\TYPE_INPUT
const TYPE_INPUT
Определения
field.php:13
Bitrix\Seo\LeadAds\Field\TYPE_RADIO
const TYPE_RADIO
Определения
field.php:15
Bitrix\Seo\LeadAds\LeadAdsForm
Определения
leadadsform.php:9
Bitrix\Seo\LeadAds\Mapper
Определения
mapper.php:14
Bitrix\Seo\LeadAds\Response\Builder\FacebookFormBuilder
Определения
facebookformbuilder.php:9
Bitrix\Seo\LeadAds\Response\Builder\FacebookFormBuilder\buildForm
buildForm(array $form)
Определения
facebookformbuilder.php:28
Bitrix\Seo\LeadAds\Response\Builder\FacebookFormBuilder\__construct
__construct(LeadAds\Mapper $mapper)
Определения
facebookformbuilder.php:18
$options
$options
Определения
commerceml2.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Seo\LeadAds\Response\Builder\FormBuilderInterface
Определения
formbuilderinterface.php:8
Bitrix\Im\V2\Chat\Param\$value
$value
Определения
Param.php:39
Bitrix\Seo\LeadAds\Response\Builder
Определения
facebookformbuilder.php:3
Bitrix\Seo\LeadAds
Определения
account.php:3
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$option
$option
Определения
options.php:1711
bitrix
modules
seo
lib
leadads
response
builder
facebookformbuilder.php
Создано системой
1.14.0