|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Arrilot\BitrixMigrations\Constructors; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Arrilot\BitrixMigrations\Logger; |
|
8
|
|
|
use Bitrix\Main\Application; |
|
9
|
|
|
|
|
10
|
|
|
class IBlockType |
|
11
|
|
|
{ |
|
12
|
|
|
use FieldConstructor; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Добавить тип инфоблока |
|
16
|
|
|
* @throws \Exception |
|
17
|
|
|
*/ |
|
18
|
|
View Code Duplication |
public function add() |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
$obj = new \CIBlockType(); |
|
21
|
|
|
if (!$obj->Add($this->getFieldsWithDefault())) { |
|
22
|
|
|
throw new \Exception($obj->LAST_ERROR); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
Logger::log("Добавлен тип инфоблока {$this->fields['ID']}", Logger::COLOR_GREEN); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Обновить тип инфоблока |
|
30
|
|
|
* @param $id |
|
31
|
|
|
* @throws \Exception |
|
32
|
|
|
*/ |
|
33
|
|
View Code Duplication |
public function update($id) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$obj = new \CIBlockType(); |
|
36
|
|
|
if (!$obj->Update($id, $this->fields)) { |
|
37
|
|
|
throw new \Exception($obj->LAST_ERROR); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
Logger::log("Обновлен тип инфоблока {$id}", Logger::COLOR_GREEN); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Удалить тип инфоблока |
|
45
|
|
|
* @param $id |
|
46
|
|
|
* @throws \Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function delete($id) |
|
49
|
|
|
{ |
|
50
|
|
|
if (!\CIBlockType::Delete($id)) { |
|
51
|
|
|
throw new \Exception('Ошибка при удалении типа инфоблока'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
Logger::log("Удален тип инфоблока {$id}", Logger::COLOR_GREEN); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* ID типа информационных блоков. Уникален. |
|
59
|
|
|
* @param string $id |
|
60
|
|
|
* @return $this |
|
61
|
|
|
*/ |
|
62
|
|
|
public function setId($id) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->fields['ID'] = $id; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Разделяются ли элементы блока этого типа по разделам. |
|
71
|
|
|
* @param bool $has |
|
72
|
|
|
* @return $this |
|
73
|
|
|
*/ |
|
74
|
|
|
public function setSections($has = true) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->fields['SECTIONS'] = $has ? 'Y' : 'N'; |
|
77
|
|
|
|
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Полный путь к файлу-обработчику массива полей элемента перед сохранением на странице редактирования элемента. |
|
83
|
|
|
* @param string $editFileBefore |
|
84
|
|
|
* @return $this |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setEditFileBefore($editFileBefore) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->fields['EDIT_FILE_BEFORE'] = $editFileBefore; |
|
89
|
|
|
|
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Полный путь к файлу-обработчику вывода интерфейса редактирования элемента. |
|
95
|
|
|
* @param string $editFileAfter |
|
96
|
|
|
* @return $this |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setEditFileAfter($editFileAfter) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->fields['EDIT_FILE_AFTER'] = $editFileAfter; |
|
101
|
|
|
|
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Блоки данного типа экспортировать в RSS |
|
107
|
|
|
* @param bool $inRss |
|
108
|
|
|
* @return $this |
|
109
|
|
|
*/ |
|
110
|
|
|
public function setInRss($inRss = false) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->fields['IN_RSS'] = $inRss ? 'Y' : 'N'; |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Порядок сортировки типа |
|
119
|
|
|
* @param int $sort |
|
120
|
|
|
* @return $this |
|
121
|
|
|
*/ |
|
122
|
|
|
public function setSort($sort = 500) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->fields['SORT'] = $sort; |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Указать языковые фразы |
|
131
|
|
|
* @param string $lang ключ языка (ru) |
|
132
|
|
|
* @param string $name |
|
133
|
|
|
* @param string $sectionName |
|
134
|
|
|
* @param string $elementName |
|
135
|
|
|
* @return $this |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setLang($lang, $name, $sectionName = null, $elementName = null) |
|
138
|
|
|
{ |
|
139
|
|
|
$setting = ['NAME' => $name]; |
|
140
|
|
|
|
|
141
|
|
|
if ($sectionName) { |
|
|
|
|
|
|
142
|
|
|
$setting['SECTION_NAME'] = $sectionName; |
|
143
|
|
|
} |
|
144
|
|
|
if ($elementName) { |
|
|
|
|
|
|
145
|
|
|
$setting['ELEMENT_NAME'] = $elementName; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$this->fields['LANG'][$lang] = $setting; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.