7 public function deleteAction($fieldId, $mode, $documentType): array
9 $documentType = \CBPDocument::unSignDocumentType($documentType);
10 $fieldId = htmlspecialcharsback($fieldId);
14 return $this->deleteVariable($fieldId, $documentType);
16 return $this->deleteConstant($fieldId, $documentType);
19 'error' => \Bitrix\Main\Localization\Loc::getMessage(
20 'BIZPROC_CONTROLLER_GLOBALFIELD_MODE_NOT_DEFINED'
26 private function deleteVariable($variableId, $documentType): array
28 $userId = (int)($this->getCurrentUser()->getId());
29 $canDelete = \Bitrix\Bizproc\Workflow\Type\GlobalVar::canUserDelete($documentType, $userId);
33 'error' => \Bitrix\Main\Localization\Loc::getMessage(
34 'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_DELETE_VARIABLE_RIGHT'
39 $field = \Bitrix\Bizproc\Workflow\Type\GlobalVar::getById($variableId);
43 'error' => \Bitrix\Main\Localization\Loc::getMessage(
44 'BIZPROC_CONTROLLER_GLOBALFIELD_NOT_EXISTS_VARIABLE'
49 $result = \Bitrix\Bizproc\Workflow\Type\GlobalVar::delete($variableId);
53 'error' => \Bitrix\Main\Localization\Loc::getMessage(
54 'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_DELETE_VARIABLE'
59 return [
'status' =>
'success'];
62 private function deleteConstant($constantId, $documentType): array
64 $userId = (int)($this->getCurrentUser()->getId());
65 $canDelete = \Bitrix\Bizproc\Workflow\Type\GlobalConst::canUserDelete($documentType, $userId);
69 'error' => \Bitrix\Main\Localization\Loc::getMessage(
70 'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_DELETE_CONSTANT_RIGHT'
75 $field = \Bitrix\Bizproc\Workflow\Type\GlobalConst::getById($constantId);
79 'error' => \Bitrix\Main\Localization\Loc::getMessage(
80 'BIZPROC_CONTROLLER_GLOBALFIELD_NOT_EXISTS_CONSTANT'
85 $result = \Bitrix\Bizproc\Workflow\Type\GlobalConst::delete($constantId);
89 'error' => \Bitrix\Main\Localization\Loc::getMessage(
90 'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_DELETE_CONSTANT'
95 return [
'status' =>
'success'];
98 public function upsertAction($fieldId, $property, $documentType, $mode): array
100 $documentType = \CBPDocument::unSignDocumentType($documentType);
104 return $this->upsertVariable($fieldId, $property, $documentType);
106 return $this->upsertConstant($fieldId, $property, $documentType);
109 'error' => \Bitrix\Main\Localization\Loc::getMessage(
110 'BIZPROC_CONTROLLER_GLOBALFIELD_MODE_NOT_DEFINED'
116 private function upsertVariable($variableId, $property, $documentType): array
118 $userId = (int)($this->getCurrentUser()->getId());
119 $canUpsert = \Bitrix\Bizproc\Workflow\Type\GlobalVar::canUserUpsert($documentType, $userId);
123 'error' => \Bitrix\Main\Localization\Loc::getMessage(
124 'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_UPSERT_VARIABLE_RIGHT'
130 $value = $this->getDefaultValue($documentType, $property, $error);
133 return [
'error' => $error[0][
'message']];
135 $property[
'Default'] = $value ??
'';
136 $property[
'Name'] = trim($property[
'Name']);
138 $userId = (int)($this->getCurrentUser()->getId());
139 $result = \Bitrix\Bizproc\Workflow\Type\GlobalVar::upsertByProperty($variableId, $property, $userId);
140 if (!$result->isSuccess())
143 'error' => $result->getErrorMessages()[0],
147 return [
'status' =>
'success'];
150 private function upsertConstant($constantId, $property, $documentType): array
152 $userId = (int)($this->getCurrentUser()->getId());
153 $canUpsert = \Bitrix\Bizproc\Workflow\Type\GlobalConst::canUserUpsert($documentType, $userId);
157 'error' => \Bitrix\Main\Localization\Loc::getMessage(
158 'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_UPSERT_CONSTANT_RIGHT'
164 $value = $this->getDefaultValue($documentType, $property, $error);
167 return [
'error' => $error[0][
'message']];
169 $property[
'Default'] = $value ??
'';
170 $property[
'Name'] = trim($property[
'Name']);
172 $userId = (int)($this->getCurrentUser()->getId());
173 $result = \Bitrix\Bizproc\Workflow\Type\GlobalConst::upsertByProperty($constantId, $property, $userId);
174 if (!$result->isSuccess())
177 'error' => $result->getErrorMessages()[0],
181 return [
'status' =>
'success'];
184 private function getDefaultValue($documentType, $property, &$error)
187 $runtime = \CBPRuntime::GetRuntime();
188 $runtime->StartRuntime();
189 $documentService = $runtime->GetService(
"DocumentService");
190 $value = $documentService->GetFieldInputValue(
203 $documentType = \CBPDocument::unSignDocumentType($documentTypeSigned);
208 return [
'list' => \Bitrix\Bizproc\Workflow\Type\GlobalVar::getAll($documentType)];
210 return [
'list' => \Bitrix\Bizproc\Workflow\Type\GlobalConst::getAll($documentType)];
213 'error' => \Bitrix\Main\Localization\Loc::getMessage(
214 'BIZPROC_CONTROLLER_GLOBALFIELD_MODE_NOT_DEFINED'