Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
codetranslator.php
1<?php
2
4
6use CIBlock;
7
8trait CodeTranslator
9{
14 private array $iblockFields;
15
21 abstract protected function getIblockId(): int;
22
27 private function getIblockFields(): array
28 {
29 if (!isset($this->iblockFields))
30 {
31 $result = CIBlock::GetArrayByID($this->getIblockId());
32 if (!is_array($result))
33 {
34 throw new SystemException('Iblock not found');
35 }
36
37 $this->iblockFields = $result;
38 }
39
40 return $this->iblockFields;
41 }
42
48 protected function getElementTranslitSettings(): ?array
49 {
50 $iblock = $this->getIblockFields();
51
52 $elementTranslit = $iblock['FIELDS']['CODE']['DEFAULT_VALUE'] ?? null;
53 if (empty($elementTranslit))
54 {
55 return null;
56 }
57
58 $useElementTranslit =
59 isset($elementTranslit['TRANSLITERATION'], $elementTranslit['USE_GOOGLE'])
60 && $elementTranslit['TRANSLITERATION'] === 'Y'
61 && $elementTranslit['USE_GOOGLE'] !== 'Y'
62 ;
63 if ($useElementTranslit)
64 {
65 return [
66 'max_len' => $elementTranslit['TRANS_LEN'],
67 'change_case' => $elementTranslit['TRANS_CASE'],
68 'replace_space' => $elementTranslit['TRANS_SPACE'],
69 'replace_other' => $elementTranslit['TRANS_OTHER'],
70 'delete_repeat_replace' => ($elementTranslit['TRANS_EAT'] === 'Y')
71 ];
72 }
73
74 return null;
75 }
76
82 protected function getSectionTranslitSettings(): ?array
83 {
84 $iblock = $this->getIblockFields();
85
86 $sectionTranslit = $iblock['FIELDS']['SECTION_CODE']['DEFAULT_VALUE'] ?? null;
87 if (empty($sectionTranslit))
88 {
89 return null;
90 }
91
92 $useSectionTranslit =
93 isset($sectionTranslit['TRANSLITERATION'], $sectionTranslit['USE_GOOGLE'])
94 && $sectionTranslit['TRANSLITERATION'] === 'Y'
95 && $sectionTranslit['USE_GOOGLE'] !== 'Y'
96 ;
97 if ($useSectionTranslit)
98 {
99 return [
100 'max_len' => $sectionTranslit['TRANS_LEN'],
101 'change_case' => $sectionTranslit['TRANS_CASE'],
102 'replace_space' => $sectionTranslit['TRANS_SPACE'],
103 'replace_other' => $sectionTranslit['TRANS_OTHER'],
104 'delete_repeat_replace' => ($sectionTranslit['TRANS_EAT'] === 'Y')
105 ];
106 }
107
108 return null;
109 }
110}