Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
controller.php
1<?php
2
4
8
10{
11 const ON_REST_APP_CONFIGURATION_CLEAR = 'OnRestApplicationConfigurationClear';
12 const ON_REST_APP_CONFIGURATION_ENTITY = 'OnRestApplicationConfigurationEntity';
13 const ON_REST_APP_CONFIGURATION_EXPORT = 'OnRestApplicationConfigurationExport';
14 const ON_REST_APP_CONFIGURATION_IMPORT = 'OnRestApplicationConfigurationImport';
15 const ON_REST_APP_CONFIGURATION_FINISH = 'OnRestApplicationConfigurationFinish';
16
20 public static function getEntityCodeList()
21 {
22 $result = [];
23
24 $event = new Event('rest', static::ON_REST_APP_CONFIGURATION_ENTITY);
25 EventManager::getInstance()->send($event);
26 foreach ($event->getResults() as $eventResult)
27 {
28 $codeList = $eventResult->getParameters();
29 if (is_array($codeList))
30 {
31 $result = array_merge($result, $codeList);
32 }
33 }
34 asort($result);
35
36 return array_keys($result);
37 }
38
39 public static function callEventExport($manifestCode, $code, $step = 0, $next = '', $itemCode = '', $contextUser = false)
40 {
41 $result = [];
42 if ($manifestCode == '')
43 {
44 return $result;
45 }
46
47 $manifest = Manifest::get($manifestCode);
48 if (!is_null($manifest))
49 {
50 $setting = new Setting($contextUser);
51
52 $event = new Event(
53 'rest',
54 static::ON_REST_APP_CONFIGURATION_EXPORT,
55 [
56 'CODE' => $code,
57 'STEP' => $step,
58 'NEXT' => $next,
59 'MANIFEST' => $manifest,
60 'ITEM_CODE' => $itemCode,
61 'SETTING' => $setting->get(Setting::SETTING_MANIFEST),
62 'USER_ID' => $setting->get(Setting::SETTING_USER_ID) ?? 0,
63 ]
64 );
65 EventManager::getInstance()->send($event);
66 foreach ($event->getResults() as $eventResult)
67 {
68 $parameters = $eventResult->getParameters();
69 $result[] = [
70 'FILE_NAME' => $parameters['FILE_NAME'],
71 'CONTENT' => $parameters['CONTENT'],
72 'FILES' => $parameters['FILES'],
73 'NEXT' => $parameters['NEXT'],
74 'ERROR_MESSAGES' => $parameters['ERROR_MESSAGES'],
75 'ERROR_ACTION' => $parameters['ERROR_ACTION'],
76 'ERROR_EXCEPTION' => $parameters['ERROR_EXCEPTION'],
77 ];
78 }
79 }
80
81 return $result;
82 }
83
84 public static function callEventClear($data)
85 {
86 $result = [
87 'NEXT' => false
88 ];
89
90 $data['SETTING'] = null;
91 if (isset($data['CONTEXT_USER']))
92 {
93 $setting = new Setting($data['CONTEXT_USER']);
94 $data['SETTING'] = $setting->get(Setting::SETTING_MANIFEST);
95 $data['USER_ID'] = $setting->get(Setting::SETTING_USER_ID) ?? 0;
96 }
97
98 $event = new Event(
99 'rest',
100 static::ON_REST_APP_CONFIGURATION_CLEAR,
101 $data
102 );
103 EventManager::getInstance()->send($event);
104 foreach ($event->getResults() as $eventResult)
105 {
106 $parameters = $eventResult->getParameters();
107 $result = [
108 'NEXT' => $parameters['NEXT'] ?? null,
109 'ERROR_MESSAGES' => $parameters['ERROR_MESSAGES'] ?? null,
110 'ERROR_ACTION' => $parameters['ERROR_ACTION'] ?? null,
111 'ERROR_EXCEPTION' => $parameters['ERROR_EXCEPTION'] ?? null
112 ];
113
114 if (!empty($parameters['OWNER_DELETE']) && is_array($parameters['OWNER_DELETE']))
115 {
116 OwnerEntityTable::deleteMulti($parameters['OWNER_DELETE']);
117 }
118 }
119
120 return $result;
121 }
122
123 public static function callEventImport($params)
124 {
125 $result = [];
126 $params['CONTEXT_USER'] = $params['CONTEXT_USER'] ?: false;
127 $setting = new Setting($params['CONTEXT_USER']);
128
129 $app = $setting->get(Setting::SETTING_APP_INFO);
130 if ($app['ID'] > 0)
131 {
132 $owner = $app['ID'];
134 }
135 else
136 {
139 }
140
141 $event = new Event(
142 'rest',
143 static::ON_REST_APP_CONFIGURATION_IMPORT,
144 [
145 'CODE' => $params['CODE'],
146 'CONTENT' => $params['CONTENT'],
147 'RATIO' => $params['RATIO'],
148 'CONTEXT' => $params['CONTEXT'],
149 'CONTEXT_USER' => $params['CONTEXT_USER'],
150 'SETTING' => $setting->get(Setting::SETTING_MANIFEST),
151 'USER_ID' => $setting->get(Setting::SETTING_USER_ID) ?? 0,
152 'MANIFEST_CODE' => $params['MANIFEST_CODE'],
153 'IMPORT_MANIFEST' => $params['IMPORT_MANIFEST'],
154 'ADDITIONAL_OPTION' => is_array($params['ADDITIONAL_OPTION']) ? $params['ADDITIONAL_OPTION'] : [],
155 'APP_ID' => intVal($owner),
156 ]
157 );
158
159 EventManager::getInstance()->send($event);
160 foreach ($event->getResults() as $eventResult)
161 {
162 $parameters = $eventResult->getParameters();
163 $result[] = [
164 'RATIO' => $parameters['RATIO'],
165 'ERROR_MESSAGES' => $parameters['ERROR_MESSAGES'] ?? null,
166 'ERROR_ACTION' => $parameters['ERROR_ACTION'] ?? null,
167 'ERROR_EXCEPTION' => $parameters['ERROR_EXCEPTION']
168 ];
169
170 if (isset($parameters['OWNER_DELETE']) && is_array($parameters['OWNER_DELETE']))
171 {
172 OwnerEntityTable::deleteMulti($parameters['OWNER_DELETE']);
173 }
174
175 if (!empty($parameters['OWNER']))
176 {
177 OwnerEntityTable::saveMulti($owner, $ownerType, $parameters['OWNER']);
178 }
179 }
180
181 return $result;
182 }
183
184 public static function callEventFinish($params)
185 {
186 $result = [];
187 $event = new Event(
188 'rest',
189 static::ON_REST_APP_CONFIGURATION_FINISH,
190 $params
191 );
192 EventManager::getInstance()->send($event);
193 foreach ($event->getResults() as $eventResult)
194 {
195 $parameters = $eventResult->getParameters();
196 $result[] = [
197 'CREATE_DOM_LIST' => $parameters['CREATE_DOM_LIST'],
198 'ADDITIONAL' => $parameters['ADDITIONAL'],
199 ];
200 }
201
202 return $result;
203 }
204}
send($sender=null)
Definition event.php:139
static callEventExport($manifestCode, $code, $step=0, $next='', $itemCode='', $contextUser=false)
static saveMulti($owner, $ownerType, $itemList)