1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Template.php
См. документацию.
1<?php
2
3namespace Bitrix\BizprocDesigner\Controller;
4
5use Bitrix\Main;
6use Bitrix\Bizproc\Api;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\Component\ParameterSigner;
9
10class Template extends Base
11{
12 protected function init()
13 {
14 if (!Main\Loader::includeModule('bizproc'))
15 {
16 throw new Main\SystemException(Loc::getMessage('BIZPROC_MODULE_NOT_INSTALLED'));
17 }
18
19 parent::init();
20 }
21
22 public function configureActions()
23 {
24 return [
25 'export' => [
26 '+prefilters' => [
28 ],
29 ],
30 'import' => [
31 '+prefilters' => [
33 ],
34 ],
35 ];
36 }
37
39 {
40 $templateService = new Api\Service\WorkflowTemplateService();
41 $parameters = (array) $this->getUnsignedParameters();
42 $user = new \CBPWorkflowTemplateUser(\CBPWorkflowTemplateUser::CurrentUser);
43
46 $parameters,
47 $user,
48 );
49
50 $result = $templateService->exportTemplate($request);
52
53 if (!$result->isSuccess())
54 {
55 $error = $result->getError();
56 if ($error && $error->getCode() === 404)
57 {
58 return $response->setStatus(404);
59 }
60
61 return false;
62 }
63
64 $response->setStatus('200 OK');
65 $response->addHeader('Content-Type', 'application/force-download; name="bp-' . $templateId . '.bpt"');
66 $response->addHeader('Content-Transfer-Encoding', 'binary');
67 $response->addHeader('Content-Length', strlen($result->getTemplateData()));
68 $response->addHeader('Content-Disposition', "attachment; filename=\"bp-" . $templateId . ".bpt\"");
69 $response->addHeader('Cache-Control', "must-revalidate, post-check=0, pre-check=0");
70 $response->addHeader('Expires', "0");
71 $response->addHeader('Pragma', "public");
72
73 $response->setContent($result->getTemplateData());
74
75 return $response;
76 }
77
78 public function importAction(int $templateId): ?int
79 {
80 $user = new \CBPWorkflowTemplateUser(\CBPWorkflowTemplateUser::CurrentUser);
81
82 $templateService = new Api\Service\WorkflowTemplateService();
83
84 $isAutomation =
85 (int)$this->request->getPost('workflowTemplateAutostart') === \CBPDocumentEventType::Automation;
86
87 if ($templateId > 0 && $isAutomation)
88 {
89 $workflowTemplateAutostart = \CBPDocumentEventType::Automation;
90 }
91 else
92 {
93 $workflowTemplateAutostart = (int) $this->request->getPost('import_template_autostart');
94 }
95
96 $parameters = $this->getUnsignedParameters();
99 (array) $parameters,
100 (string) $this->request->getPost('import_template_name'),
101 (string) $this->request->getPost('import_template_description'),
102 $workflowTemplateAutostart,
103 (array) $this->request->getFile('import_template_file'),
104 $user,
105 );
106
107 $response = $templateService->importTemplate($request);
108
109 if (!$response->isSuccess())
110 {
111 $this->addErrors($response->getErrors());
112
113 return null;
114 }
115
116 return $response->getTemplateId();
117 }
118
119 public function saveAction(): array|int
120 {
121 $json = $this->getRequest()->getJsonList();
122 $templateId = (int)$json->get('templateId');
123 $fields = (array)$json->get('fields');
124 $componentName = (string)$json->get('c');
125 $signedParameters = (string)$json->get('signedParameters');
126 $user = new \CBPWorkflowTemplateUser(\CBPWorkflowTemplateUser::CurrentUser);
127
128 $templateService = new Api\Service\WorkflowTemplateService();
129
130 $parameters = ParameterSigner::unsignParameters($componentName, $signedParameters);
132
133 $response = $templateService->saveTemplate($request);
134
135 if ($response->isSuccess())
136 {
137 return $response->getTemplateId();
138 }
139
140 $this->addErrors($response->getErrors());
141
142 return ['activityErrors' => $response->getActivityErrors()];
143 }
144
145 public function saveDraftAction(): ?int
146 {
147 $json = $this->getRequest()->getJsonList();
148 $templateId = (int)$json->get('templateId');
149 $fields = (array)$json->get('fields');
150 $componentName = (string)$json->get('c');
151 $signedParameters = (string)$json->get('signedParameters');
152 $user = new \CBPWorkflowTemplateUser(\CBPWorkflowTemplateUser::CurrentUser);
153
154 $templateService = new Api\Service\WorkflowTemplateService();
155
156 $parameters = ParameterSigner::unsignParameters($componentName, $signedParameters);
159 $parameters,
160 $fields,
161 $user
162 );
163
164 $response = $templateService->saveTemplateDraft($request);
165 if ($response->isSuccess())
166 {
167 return $response->getTemplateDraftId();
168 }
169
170 $this->addErrors($response->getErrors());
171
172 return null;
173 }
174
175 public function loadDraftAction(int $draftId): ?array
176 {
177 $templateService = new Api\Service\WorkflowTemplateService();
179 $response = $templateService->loadTemplateDraft($request);
180 if ($response->isSuccess())
181 {
182 return $response->getData();
183 }
184
185 $this->addErrors($response->getErrors());
186
187 return null;
188 }
189}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
importAction(int $templateId)
Определения Template.php:78
exportAction(int $templateId)
Определения Template.php:38
loadDraftAction(int $draftId)
Определения Template.php:175
static includeModule($moduleName)
Определения loader.php:67
const Automation
Определения constants.php:156
$templateId
Определения component_props2.php:51
$componentName
Определения component_props2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$user
Определения mysql_to_pgsql.php:33
return false
Определения prolog_main_admin.php:185
$response
Определения result.php:21
$error
Определения subscription_card_product.php:20
$fields
Определения yandex_run.php:501