Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
senderconnector.php
1<?php
9namespace Bitrix\Form;
10
13
14Loc::loadMessages(__FILE__);
15
17{
22 public static function onConnectorListForm($data)
23 {
24 $data['CONNECTOR'] = 'Bitrix\Form\SenderConnectorForm';
25
26 return $data;
27 }
28}
29
30if (Loader::includeModule('sender'))
31{
32 class SenderConnectorForm extends \Bitrix\Sender\Connector
33 {
37 public function getName()
38 {
39 return Loc::getMessage('sender_connector_form_name');
40 }
41
45 public function getCode()
46 {
47 return "form";
48 }
49
53 public function requireConfigure()
54 {
55 return true;
56 }
57
59 public function getData()
60 {
61 $formId = $this->getFieldValue('FORM', null);
62 $propertyNameId = $this->getFieldValue('PROPERTY_NAME', null);
63 $propertyEmailId = $this->getFieldValue('PROPERTY_EMAIL', null);
64
65 $formResultsDb = new \CDBResult();
66 $dataResult = array();
67
68 if($formId && $propertyEmailId)
69 {
70 $filter = array();
71 $formResultDb = \CFormResult::GetList($formId, "s_timestamp", $order="asc", $filter, null, "N");
72 while ($formResult = $formResultDb->Fetch())
73 {
74 $answerList = \CFormResult::GetDataByID(
75 $formResult['ID'],
76 array(),
77 $formResult,
78 $answerList2
79 );
80
81 $data = array();
82 foreach($answerList as $fieldCode => $fieldsAnswer)
83 {
84 if($fieldsAnswer[0]['TITLE_TYPE'] == 'text')
85 {
86 if($fieldsAnswer[0]['FIELD_ID'] == $propertyNameId)
87 $data['NAME'] = $fieldsAnswer[0]['USER_TEXT'];
88
89 if($fieldsAnswer[0]['FIELD_ID'] == $propertyEmailId)
90 $data['EMAIL'] = $fieldsAnswer[0]['USER_TEXT'];
91 }
92
93 }
94
95 if(!empty($data['EMAIL']))
96 {
97 if(intval($formResult['USER_ID']) > 0)
98 $data['USER_ID'] = intval($formResult['USER_ID']);
99
100 $dataResult[] = $data;
101 }
102 }
103 }
104
105 $formResultsDb->InitFromArray($dataResult);
106 return $formResultsDb;
107 }
108
112 public function getForm()
113 {
114 /*
115 * select form list
116 */
117 $formList = array();
118 $formDb = \CForm::GetList();
119 while($form = $formDb->Fetch())
120 {
121 $formList[] = array('ID' => $form['ID'], 'NAME' => $form['NAME']);
122 }
123 if(!empty($formList))
124 $formList = array_merge(
125 array(array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_select'))),
126 $formList
127 );
128 else
129 $formList = array_merge(
130 array(array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_empty'))),
131 $formList
132 );
133
134 /*
135 * select properties from all forms
136 */
137 $propertyToForm = array();
138 $propertyList = array();
139 $propertyList[''][] = array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_select'));
140 $propertyList['EMPTY'][] = array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_prop_empty'));
141 foreach($formList as $form)
142 {
143 if(empty($form['ID'])) continue;
144
145 $formFieldsDb = \CFormField::GetList($form['ID'], 'N');
146 while ($formFields = $formFieldsDb->Fetch())
147 {
148 if($formFields['TITLE_TYPE'] != 'text') continue;
149 // add default value
150 if (!array_key_exists($formFields['FORM_ID'], $propertyList))
151 {
152 $propertyList[$formFields['FORM_ID']][] = array(
153 'ID' => '',
154 'NAME' => Loc::getMessage('sender_connector_form_field_select')
155 );
156 }
157
158 // add property
159 $propertyList[$formFields['FORM_ID']][] = array(
160 'ID' => $formFields['ID'],
161 'NAME' => $formFields['TITLE']
162 );
163
164 // add property link to iblock
165 $propertyToForm[$formFields['ID']] = $formFields['FORM_ID'];
166 }
167 }
168
169
170 /*
171 * create html-control of form list
172 */
173 $formInput = '<select name="'.$this->getFieldName('FORM').'" id="'.$this->getFieldId('FORM').'" onChange="FormSelect'.$this->getFieldId('FORM').'()">';
174 foreach($formList as $form)
175 {
176 $inputSelected = ($form['ID'] == $this->getFieldValue('FORM') ? 'selected' : '');
177 $formInput .= '<option value="'.$form['ID'].'" '.$inputSelected.'>';
178 $formInput .= htmlspecialcharsbx($form['NAME']);
179 $formInput .= '</option>';
180 }
181 $formInput .= '</select>';
182
183
184 /*
185 * create html-control of properties list for name
186 */
187 $formPropertyNameInput = '<select name="'.$this->getFieldName('PROPERTY_NAME').'" id="'.$this->getFieldId('PROPERTY_NAME').'">';
188 if(array_key_exists($this->getFieldValue('PROPERTY_NAME', 0), $propertyToForm))
189 {
190 $propertyCollcetion = $propertyList[$propertyToForm[$this->getFieldValue('PROPERTY_NAME', 0)]];
191 }
192 else
193 {
194 $propertyCollcetion = $propertyList[''];
195 }
196 foreach($propertyCollcetion as $property)
197 {
198 $inputSelected = ($property['ID'] == $this->getFieldValue('PROPERTY_NAME') ? 'selected' : '');
199 $formPropertyNameInput .= '<option value="'.$property['ID'].'" '.$inputSelected.'>';
200 $formPropertyNameInput .= htmlspecialcharsbx($property['NAME']);
201 $formPropertyNameInput .= '</option>';
202 }
203 $formPropertyNameInput .= '</select>';
204
205
206 /*
207 * create html-control of properties list for email
208 */
209 $formPropertyEmailInput = '<select name="'.$this->getFieldName('PROPERTY_EMAIL').'" id="'.$this->getFieldId('PROPERTY_EMAIL').'">';
210 if(array_key_exists($this->getFieldValue('PROPERTY_EMAIL', 0), $propertyToForm))
211 {
212 $propertyCollcetion = $propertyList[$propertyToForm[$this->getFieldValue('PROPERTY_EMAIL', 0)]];
213 }
214 else
215 {
216 $propertyCollcetion = $propertyList[''];
217 }
218 foreach($propertyCollcetion as $property)
219 {
220 $inputSelected = ($property['ID'] == $this->getFieldValue('PROPERTY_EMAIL') ? 'selected' : '');
221 $formPropertyEmailInput .= '<option value="'.$property['ID'].'" '.$inputSelected.'>';
222 $formPropertyEmailInput .= htmlspecialcharsbx($property['NAME']);
223 $formPropertyEmailInput .= '</option>';
224 }
225 $formPropertyEmailInput .= '</select>';
226
227
228 $jsScript = "
229 <script>
230 function FormSelect".$this->getFieldId('FORM')."()
231 {
232 var iblock = BX('".$this->getFieldId('FORM')."');
233 FormPropertyAdd(iblock, BX('".$this->getFieldId('PROPERTY_NAME')."'));
234 FormPropertyAdd(iblock, BX('".$this->getFieldId('PROPERTY_EMAIL')."'));
235 }
236 function FormPropertyAdd(iblock, iblockProperty)
237 {
238 if(iblockProperty.length>0)
239 {
240 for (var j in iblockProperty.options)
241 {
242 iblockProperty.options.remove(j);
243 }
244 }
245 var propList = {};
246 if(formProperties[iblock.value] && formProperties[iblock.value].length>0)
247 propList = formProperties[iblock.value];
248 else
249 propList = formProperties['EMPTY'];
250 for(var i in propList)
251 {
252 var optionName = propList[i]['NAME'];
253 var optionValue = propList[i]['ID'];
254 iblockProperty.options.add(new Option(optionName, optionValue));
255 }
256
257 }
258
259 var formProperties = ".\CUtil::PhpToJSObject($propertyList).";
260 </script>
261 ";
262
263
264
265 return '
266 '.Loc::getMessage('sender_connector_form_required_settings').'
267 <br/><br/>
268 <table>
269 <tr>
270 <td>'.Loc::getMessage('sender_connector_form_field_form').'</td>
271 <td>'.$formInput.'</td>
272 </tr>
273 <tr>
274 <td>'.Loc::getMessage('sender_connector_form_field_name').'</td>
275 <td>'.$formPropertyNameInput.'</td>
276 </tr>
277 <tr>
278 <td>'.Loc::getMessage('sender_connector_form_field_email').'</td>
279 <td>'.$formPropertyEmailInput.'</td>
280 </tr>
281 </table>
282 '.$jsScript.'
283 ';
284 }
285 }
286}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29