Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
catalogsectiontabhandler.php
1<?php
2
4
9
10Loc::loadMessages(__FILE__);
11
12
19{
20 protected static $vkCategoriesVariations = array();
21 protected static $vkRequiredVariations = array();
22 protected $section = array();
23
27 public function __construct()
28 {
29 $this->name = Loc::getMessage("SALE_VK_NAME");
30 $this->description = Loc::getMessage("SALE_VK_DESCRIPTION");
31 }
32
39 public function action($arArgs)
40 {
41 $sectionId = $arArgs["ID"];
42 $vk = Vk::getInstance();
43 $exportProfiles = $vk->getExportProfilesList();
44
45 foreach ($exportProfiles as $export)
46 {
47 $dataToMapping = array();
48 $dataToDelete = array();
49
50 $sectionsList = new SectionsList($export["ID"]);
51// in moment of changes setting we must drop cached sections and mapped sections
52 $sectionsList->clearCaches();
53 $sectionsList->setCurrSectionSettings($_POST['VK_EXPORT'][$export["ID"]]);
54
55// formatted or remove current section
56 $preparedSection = $sectionsList->prepareSectionToSave($sectionId);
57 $dataToMapping += $preparedSection['TO_SAVE'] ? $preparedSection['TO_SAVE'] : array();
58 $dataToDelete += $preparedSection['TO_DELETE'] ? $preparedSection['TO_DELETE'] : array();
59
60// save or remove childs
61 $preparedChilds = $sectionsList->prepareChildsToSave($sectionId);
62 $dataToMapping += $preparedChilds['TO_SAVE'] ? $preparedChilds['TO_SAVE'] : array();
63 $dataToDelete += $preparedChilds['TO_DELETE'] ? $preparedChilds['TO_DELETE'] : array();
64
65 if (!empty($dataToMapping))
66 {
67 Map::updateSectionsMapping($dataToMapping, $export["ID"], 'ONLY_INTERNAL');
68 }
69
70 if (!empty($dataToDelete))
71 {
72 Map::removeSectionsMapping($dataToDelete, $export["ID"], 'ONLY_INTERNAL');
73 }
74 }
75
76 return true;
77 }
78
79
87 public function check($arArgs)
88 {
89 $vk = Vk::getInstance();
90 $exports = $vk->getExportProfilesList();
91 $errors = array();
92
93 foreach ($exports as $export)
94 {
95 $currErrors = array();
96// all VK-errors can be only if export ENABLE
97 if (isset($_POST['VK_EXPORT'][$export["ID"]]["ENABLE"]) && $_POST['VK_EXPORT'][$export["ID"]]["ENABLE"])
98 {
99// wrong section
100 if (isset($_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM"]) && $_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM"] < 0)
101 {
102 $currErrors[] = Loc::getMessage("SALE_VK_EXPORT_SETTINGS__ERROR_WRONG_ALBUM");
103 unset($_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM"]);
104 }
105
106// section is selected, but alias is empty
107 if (
108 isset($_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM"]) && $_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM"] > 0 &&
109 $_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM"] == $_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM_CURRENT"] &&
110 mb_strlen($_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM_ALIAS"]) < 2
111 )
112 {
113 $currErrors[] = Loc::getMessage("SALE_VK_EXPORT_SETTINGS__ERROR_EMPTY_ALIAS");
114 unset($_POST['VK_EXPORT'][$export["ID"]]["TO_ALBUM_ALIAS"]);
115 }
116
117 if (isset($_POST['VK_EXPORT'][$export["ID"]]["VK_CATEGORY"]) && $_POST['VK_EXPORT'][$export["ID"]]["VK_CATEGORY"] == 0)
118 {
119 $currErrors[] = Loc::getMessage("SALE_VK_EXPORT_SETTINGS__ERROR_WRONG_VK_CATEGORY");
120 unset($_POST['VK_EXPORT'][$export["ID"]]["VK_CATEGORY"]);
121 }
122 }
123
124 if (!empty($currErrors))
125 $errors[] =
126 Loc::getMessage("SALE_VK_EXPORT_PROFILE") .
127 '"' . HtmlFilter::encode($export['DESC']) . '": <br>' .
128 implode('<br>', $currErrors);
129 }
130
131 if (!empty($errors))
132 throw new SystemException(implode('<br><br>', $errors));
133
134 return true;
135 }
136
137
146 public function showTabSection($divName, $arArgs, $bVarsFromForm)
147 {
148// ONLY RUSSIAN!!!
149// todo: translate to other language
150 if (defined('LANG') && LANG != 'ru')
151 {
152 $resultHtml = '<tr><td colspan="2">';
153 $resultHtml .= BeginNote();
154 $resultHtml .= '<p>' . Loc::getMessage("SALE_VK_ONLY_RUSSIAN") . '</p>';
155 $resultHtml .= '<p>' . Loc::getMessage("SALE_VK_ONLY_RUSSIAN_2") . '</p>';
156 $resultHtml .= '<img src="/bitrix/images/sale/vk/vk_only_russian.png" alt="">';
157 $resultHtml .= EndNote();
158 $resultHtml .= '</td></tr>';
159
160 return $resultHtml;
161 }
162
163 $resultHtml = "";
164
165 $iblockId = $arArgs["IBLOCK"]["ID"];
166 $sectionId = $arArgs["ID"];
167
168// test current section activity (if new - we have not ID and cant set settings)
169 if ($sectionId <= 0)
170 return '<tr><td colspan="2">' . Loc::getMessage("SALE_VK_NEED_SAVE_SECTION") . '</td></tr>';
171
172// if we not have exports profiles - we cant sdave settings
173 $vk = Vk::getInstance();
174 $exports = $vk->getExportProfilesList();
175 if (empty($exports))
176 {
177 return
178 '<tr><td colspan="2">' .
179 Loc::getMessage("SALE_VK_NEED_EXPORT_PROFILE", array('#A1' => '/bitrix/admin/sale_vk_export_list.php')) .
180 '</td></tr>';
181 }
182
183
184// ----------- PRINT ------------
185// ------------------------------
186 $resultHtml .= '<tr><td colspan="2">';
187 $resultHtml .= '
188 <table class="internal" id="table_EXPORT_PROFILES"
189 style="border-left: none !important; border-right: none !important; width: 100%;">';
190
191 $resultHtml .= '
192 <tr
193 id="tr_HEADING"
194 class="heading"
195 mode="flat"
196 prop_sort="-1"
197 prop_id="0"
198 left_margin="-1"
199 >
200 <td align="left" class="internal-left">' . Loc::getMessage("SALE_VK_EXPORT_SETTINGS__EXPORT_ID") . '</td>
201 <td style="width: 220px">' . Loc::getMessage("SALE_VK_EXPORT_SETTINGS__INHERIT") . '</td>
202 <td style="width: 100px">' . Loc::getMessage("SALE_VK_EXPORT_SETTINGS__ENABLE") . '</td>
203 <td align="left">' .
204 Loc::getMessage("SALE_VK_EXPORT_SETTINGS__TO_ALBUM") .
205 ShowJSHint(Loc::getMessage("SALE_VK_EXPORT_SETTINGS__TO_ALBUM_HELP"), array('return'=>true)) . '
206 </td>' .
207 '<td style="width: 220px">' .
208 Loc::getMessage("SALE_VK_EXPORT_SETTINGS__INCLUDE_CHILDS") .
209 ShowJSHint(Loc::getMessage("SALE_VK_EXPORT_SETTINGS__INCLUDE_CHILDS_HELP"), array('return'=>true)) . '
210 </td>
211 <td align="left" class="internal-right">' .
212 Loc::getMessage("SALE_VK_CATEGORY_SELECTOR") .
213 ShowJSHint(Loc::getMessage("SALE_VK_CATEGORY_SELECTOR_HELP"), array('return'=>true)) . '
214 </td>
215 </tr>';
216
217 foreach ($exports as $export)
218 {
219 try
220 {
221 $sectionsList = new SectionsList($export['ID']);
222 $currSettings = $sectionsList->prepareSectionToShow($sectionId);
223// load values from post, if page will be reload (e.g. if error)
224 $currSettings = $this->compareSettingsWithPost($currSettings, $export["ID"]);
225 $currSettings = $sectionsList->prepareSettingsVisibility($currSettings, $sectionId);
226
227 $categoriesVk = new VkCategories((int)$export["ID"]);
228 $vkCategorySelector = $categoriesVk->getVkCategorySelector(
229 $currSettings["VK_CATEGORY"],
230 Loc::getMessage('SALE_VK_CATEGORY_SELECTOR_DEFAULT')
231 );
232 }
233 catch (ExecuteException $e)
234 {
235// export is wrong
236 self::setUnactiveExport($export['ID']);
237 continue;
238 }
239
240 $resultHtml .= '<tr id="tr_EXPORT__' . $export["ID"] . ' class="vk_export_row" mode="both" left_margin="124" >';
241
242// EXPORT settings - profile
243 $resultHtml .= '
244 <td class="internal-left">
245 <span>' . HtmlFilter::encode($export["DESC"]) . '</span>
246 <input
247 class="vk_export__profile_id"
248 type="hidden"
249 name="VK_EXPORT[' . $export["ID"] . '][ID]"
250 value ="' . $export["ID"] . '" />
251 </td>';
252
253// INHERIT from parent
254 $resultHtml .= '
255 <td align="center">
256 <input ' . $currSettings["INHERIT"] . ' ' . $currSettings['INHERIT__DISPLAY'] . '
257 id="vk_export_inherit_' . $export["ID"] . '"
258 type="checkbox"
259 name="VK_EXPORT[' . $export["ID"] . '][INHERIT]"
260 value="1">
261 </td>';
262
263// ENDABLE export
264 $resultHtml .= '
265 <td align="center">
266 <input ' . $currSettings["ENABLE"] . ' ' . $currSettings["ENABLE__DISPLAY"] . '
267 id="vk_export_enable_' . $export["ID"] . '"
268 type="checkbox"
269 name="VK_EXPORT[' . $export["ID"] . '][ENABLE]"
270 value="1">
271 <input type="hidden" name="VK_EXPORT[' . $export["ID"] . '][IBLOCK]" value="' . $iblockId . '">
272 <input
273 type="hidden"
274 id="vk_export_enable_parent_' . $export["ID"] . '"
275 value="' . $currSettings["ENABLE__PARENT"] . '">
276 </td>';
277
278// TO ALBUM
279 $sectionsSelector = $sectionsList->getSectionsSelector($currSettings["TO_ALBUM"], false);
280 $resultHtml .= '
281 <td>
282 <input
283 type="hidden"
284 id="vk_export_to_album_current_' . $export["ID"] . '"
285 name="VK_EXPORT[' . $export["ID"] . '][TO_ALBUM_CURRENT]"
286 value="' . $sectionId . '">
287 <input
288 type="hidden"
289 id="vk_export_to_album_parent_' . $export["ID"] . '"
290 value="' . $currSettings["TO_ALBUM__PARENT"] . '">
291
292 <select ' . $currSettings["TO_ALBUM__DISPLAY"] . '
293 style="width: 100%"
294 id="vk_export_to_album_' . $export["ID"] . '"
295 class="vk_sale_export_category_to_album"
296 name="VK_EXPORT[' . $export["ID"] . '][TO_ALBUM]">' .
297 $sectionsSelector . '
298 </select>' .
299
300// alias
301 '<div id="vk_export_to_album_alias_container_'. $export["ID"] .'"
302 style="margin-top: 6px; '. $currSettings["TO_ALBUM_ALIAS__DISPLAY"] .'">' .
303 '<i>'.Loc::getMessage("SALE_VK_EXPORT_SETTINGS__TO_ALBUM_ALIAS").': </i>'.
304 '<input ' .
305 'id="vk_export_to_album_alias_' . $export["ID"] . '"' .
306 'type="text"' .
307 'name="VK_EXPORT[' . $export["ID"] . '][TO_ALBUM_ALIAS]"'.
308 'size="25" maxlength="255"' .
309 'value="' . $currSettings["TO_ALBUM_ALIAS"] . '"'.
310 '>' .
311 '<input '.
312 'type="hidden"'.
313 'id="vk_export_to_album_alias_parent_' . $export["ID"] . '"'.
314 'value="' . $currSettings["TO_ALBUM_ALIAS__PARENT"] . '"'.
315 '>'.
316 '</div>' .
317 '</td>';
318
319// include CHILDS
320 $resultHtml .= '
321 <td align="center">
322 <input ' . $currSettings["INCLUDE_CHILDS__DISPLAY"] . ' ' . $currSettings["INCLUDE_CHILDS"] . '
323 id="vk_export_include_childs_' . $export["ID"] . '"
324 type="checkbox"
325 name="VK_EXPORT[' . $export["ID"] . '][INCLUDE_CHILDS]"
326 value="1"
327 >
328 <input
329 type="hidden"
330 id="vk_export_include_childs_parent_' . $export["ID"] . '"
331 value="' . $currSettings["INCLUDE_CHILDS__PARENT"] . '">
332
333 </td>';
334
335// categories SELECTOR
336 $resultHtml .= '
337 <td class="internal - right">
338 <select ' . $currSettings["VK_CATEGORY__DISPLAY"] . '
339 id="vk_export_vk_category_' . $export["ID"] . '"
340 name="VK_EXPORT[' . $export["ID"] . '][VK_CATEGORY]">' .
341 $vkCategorySelector . '
342 </select>
343 <input
344 type="hidden"
345 id="vk_export_vk_category_parent_' . $export["ID"] . '"
346 value="' . $currSettings["VK_CATEGORY__PARENT"] . '">
347 </td>';
348
349 $resultHtml .= '</tr>';
350 } //end foreach
351
352 $resultHtml .= '</table>';
353 $resultHtml .= BeginNote() . Loc::getMessage("SALE_VK_CATEGORY_INTRO") . EndNote();
354 $resultHtml .= '</td></tr>';
355
356
357// SCRIPT for beauty
358 \Bitrix\Main\Page\Asset::getInstance()->addJs("/bitrix/js/sale/vk_section_edit.js", true);
359
360 return $resultHtml;
361 }
362
363
371 private function compareSettingsWithPost($settings, $exportId)
372 {
373// not need check INHERIT and ENABLE. Patamushta not need
374 if ($_POST['VK_EXPORT'][$exportId]["TO_ALBUM"])
375 $settings["TO_ALBUM"] = $_POST['VK_EXPORT'][$exportId]["TO_ALBUM"];
376
377 if ($_POST['VK_EXPORT'][$exportId]["TO_ALBUM_ALIAS"])
378 $settings["TO_ALBUM_ALIAS"] = $_POST['VK_EXPORT'][$exportId]["TO_ALBUM_ALIAS"];
379
380 if ($_POST['VK_EXPORT'][$exportId]["VK_CATEGORY"])
381 $settings["VK_CATEGORY"] = $_POST['VK_EXPORT'][$exportId]["VK_CATEGORY"];
382
383 $settings["INCLUDE_CHILDS"] = $_POST['VK_EXPORT'][$exportId]["INCLUDE_CHILDS"] ? true : $settings["INCLUDE_CHILDS"];
384
385 return $settings;
386 }
387
388 private static function setUnactiveExport($exportId)
389 {
390 $vk = Vk::getInstance();
391 $vk->unsetActiveById($exportId);
392 }
393}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)
static updateSectionsMapping($values, $exportId, $flagKeys='')
Definition map.php:166
static removeSectionsMapping($values, $exportId, $flagKeys='')
Definition map.php:158