-
Notifications
You must be signed in to change notification settings - Fork 2
/
lists.php
177 lines (161 loc) · 4.87 KB
/
lists.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* Class definition update migrations scenario actions
**/
class ws_m_1550063367_dobavleniya_infobloka_personal extends \WS\ReduceMigrations\Scenario\ScriptScenario
{
/**
* Name of scenario
**/
static public function name()
{
return "Добавления инфоблока - TEST";
}
/**
* Priority of scenario
**/
static public function priority()
{
return self::PRIORITY_HIGH;
}
/**
* @return string hash
*/
static public function hash()
{
return "b9aaf1ae154df97fa5e3049af2307dcfef575d7d";
}
/**
* @return int approximately time in seconds
*/
static public function approximatelyTime()
{
return 20;
}
/**
* Write action by apply scenario. Use method `setData` for save need rollback data
**/
public function commit()
{
$this->createIblock();
$this->createProps();
}
/**
* Write action by rollback scenario. Use method `getData` for getting commit saved data
**/
public function rollback()
{
$this->deleteIblock();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
///
public function createIblock()
{
\Bitrix\Main\Loader::includeModule('main');
\Bitrix\Main\Loader::includeModule('iblock');
$site = \CSite::GetList($by, $order, ['DEFAULT'=>'Y'])->fetch();
$ib = new \CIBlock;
$arFields = Array(
"ACTIVE" => "Y",
'NAME' => 'TEST',
"CODE" => 'TEST',
"XML_ID" => 'TEST',
"LIST_PAGE_URL" => "",
"DETAIL_PAGE_URL" => "",
"IBLOCK_TYPE_ID" => "lists",
"SITE_ID" => [$site['LID']],
"GROUP_ID"=>["2" => "R"],
"SORT" => 100,
"PICTURE" => "",
"DESCRIPTION" => "",
"DESCRIPTION_TYPE" => "",
'BIZPROC'=>'Y',
'WORKFLOW'=>'N',
'INDEX_ELEMENT'=>'Y',
"ELEMENT_NAME" => 'TEST',
"ELEMENTS_NAME" => 'TEST',
"ELEMENT_ADD" => 'TEST',
"ELEMENT_EDIT" => 'TEST',
"ELEMENT_DELETE" => 'TEST',
"SECTION_NAME" => 'Раздел',
"SECTIONS_NAME" => 'Разделы',
"SECTION_ADD" => 'Раздел',
"SECTION_EDIT" => 'Раздел',
"SECTION_DELETE" => 'Раздел',
);
return $ib->Add($arFields);
}
public function createProps()
{
\Bitrix\Main\Loader::includeModule('lists');
$res = \Bitrix\Iblock\IblockTable::getList([
'filter'=>['CODE'=>"TEST"],
'select'=>['ID']
])->fetch();
$iblockId = $res['ID'];
$obList = new \CList( $iblockId );
$allListsFields = [
[
"SORT" => 100,
"NAME" => 'Название',
"IS_REQUIRED" => "Y",
"MULTIPLE" => "N",
"CODE" => "TEST_NAME",
"TYPE" => "S",
"DEFAULT_VALUE" => "",
"USER_TYPE_SETTINGS" => "",
"SETTINGS" => [
"SHOW_ADD_FORM" => "Y",
"SHOW_EDIT_FORM" => "Y",
"ADD_READ_ONLY_FIELD" => "N",
"EDIT_READ_ONLY_FIELD" => "N",
"SHOW_FIELD_PREVIEW" => "N",
],
"LIST" =>[],
],
[
"SORT" => 200,
"NAME" => 'Стоимость',
"IS_REQUIRED" => "Y",
"MULTIPLE" => "N",
"CODE" => "TEST_PRICE",
"TYPE" => "N",
"DEFAULT_VALUE" => "",
"USER_TYPE_SETTINGS" => "",
"SETTINGS" => [
"SHOW_ADD_FORM" => "Y",
"SHOW_EDIT_FORM" => "Y",
"ADD_READ_ONLY_FIELD" => "N",
"EDIT_READ_ONLY_FIELD" => "N",
"SHOW_FIELD_PREVIEW" => "N",
],
"LIST" =>[],
],
];
foreach ($allListsFields as $allListsField)
{
$obList->AddField($allListsField);
}
$obList->Save();
global $CACHE_MANAGER;
$CACHE_MANAGER->ClearByTag("lists_list_".$iblockId);
}
public function deleteIblock()
{
global $DB;
\Bitrix\Main\Loader::includeModule('main');
\Bitrix\Main\Loader::includeModule('iblock');
$res = \Bitrix\Iblock\IblockTable::getList([
'filter'=>['CODE'=>"TEST"],
'select'=>['ID']
])->fetch();
$DB->StartTransaction();
if(!\CIBlock::Delete($res['ID']))
{
echo 'Delete Iblock error!';
$DB->Rollback();
}
else
$DB->Commit();
}
}