Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
form.php
1<?php
3
4use Bitrix\Crm\WebForm\EntityFieldProvider;
5use Bitrix\Crm\WebForm\Options;
9use \Bitrix\Crm\Category\DealCategory;
10
11class Form
12{
13 public static function getAgreements()
14 {
15 $result = [];
16
17 $agreementsIds = array_keys(
18 Agreement::getActiveList()
19 );
20
21 foreach ($agreementsIds as $agreementId)
22 {
23 $agreement = new Agreement($agreementId);
24 $agreementData = $agreement->getData();
25
26 $result[] = [
27 'id' => (int)$agreementData['ID'],
28 'name' => (string)$agreementData['NAME'],
29 'labelText' => (string)$agreement->getLabelText(),
30 ];
31 }
32
33 $publicActionResult = new PublicActionResult();
34 $publicActionResult->setResult($result);
35
36 return $publicActionResult;
37 }
38
39 public static function getCrmFields(?array $options = null)
40 {
41 if (
42 Loader::includeModule('crm')
43 && static::checkFormPermission()
44 )
45 {
46 $hiddenTypes = [];
47 if ((int)($options['hideVirtual'] ?? 0))
48 {
49 $hiddenTypes[] = EntityFieldProvider::TYPE_VIRTUAL;
50 }
51 if ((int)($options['hideRequisites'] ?? 1))
52 {
53 $hiddenTypes[] = \CCrmOwnerType::Requisite;
54 }
55 if ((int)($options['hideSmartDocument'] ?? 0))
56 {
57 $hiddenTypes[] = \CCrmOwnerType::SmartDocument;
58 }
59
60 if (isset($options['presetId']) && is_numeric($options['presetId']))
61 {
62 $presetId = (int)$options['presetId'];
63 }
64 else
65 {
66 $presetId = null;
67 }
68
69 $fields = EntityFieldProvider::getFieldsTree($hiddenTypes, $presetId);
70 foreach ($fields as $key => $item)
71 {
72 if (strpos($key, 'DYNAMIC_') === 0)
73 {
74 $dynamicId = str_replace('DYNAMIC_', '', $key);
75 $fields[$key]["DYNAMIC_ID"] = \CCrmOwnerType::ResolveUserFieldEntityID($dynamicId);
76 }
77 }
78 }
79 else
80 {
81 $fields = [];
82 }
83
84 $publicActionResult = new PublicActionResult();
85 $publicActionResult->setResult($fields);
86
87 return $publicActionResult;
88 }
89
90 public static function getCrmCompanies()
91 {
92 $companies = [];
93
94 if (
95 Loader::includeModule('crm')
96 && static::checkFormPermission()
97 )
98 {
99 $res = \CCrmCompany::GetListEx(
100 [],
101 [
102 '=IS_MY_COMPANY' => 'Y',
103 'CHECK_PERMISSIONS' => 'N',
104 ],
105 false,
106 false,
107 [
108 'ID',
109 'TITLE',
110 ]
111 );
112 if ($res)
113 {
114 while ($company = $res->fetch())
115 {
116 $companies[] = $company;
117 }
118 }
119 }
120
121 $publicActionResult = new PublicActionResult();
122 $publicActionResult->setResult($companies);
123
124 return $publicActionResult;
125 }
126
127 public static function getCrmCategories()
128 {
129 $categories = [];
130
131 if (
132 Loader::includeModule('crm')
133 && static::checkFormPermission()
134 )
135 {
136 $userPermissions = \CCrmPerms::GetCurrentUserPermissions();
137 $map = array_fill_keys(\CCrmDeal::GetPermittedToReadCategoryIDs($userPermissions), true);
138 $allCategories = DealCategory::getAll(true);
139
140 foreach ($allCategories as $key => $category)
141 {
142 $ID = (int)$category['ID'];
143 if(!isset($map[$ID]))
144 {
145 continue;
146 }
147
148 $stages = \CCrmViewHelper::getDealStageInfos($category['ID']);
149 \CCrmViewHelper::prepareDealStageExtraParams($stages, $category['ID']);
150
151 $category['STAGES'] = array_values($stages);
152 $categories[] = $category;
153 }
154 }
155
156 $publicActionResult = new PublicActionResult();
157 $publicActionResult->setResult($categories);
158
159 return $publicActionResult;
160 }
161
162 public static function checkFormPermission(): bool
163 {
164 global $USER;
165 $CrmPerms = new \CCrmPerms($USER->GetID());
166
167 if($CrmPerms->HavePerm('WEBFORM', BX_CRM_PERM_NONE))
168 {
169 return false;
170 }
171
172 return true;
173 }
174
179 public static function getList(): PublicActionResult
180 {
181 $publicActionResult = new PublicActionResult();
182 $publicActionResult->setResult(
183 array_values(\Bitrix\Landing\Subtype\Form::getForms())
184 );
185
186 return $publicActionResult;
187 }
188
193 public static function getById($formId): PublicActionResult
194 {
195 $publicActionResult = new PublicActionResult();
196 $publicActionResult->setResult(
197 \Bitrix\Landing\Subtype\Form::getFormById((int)$formId)
198 );
199
200 return $publicActionResult;
201 }
202
203 public static function getEditorData($formId)
204 {
205 $publicActionResult = new PublicActionResult();
206 $publicActionResult->setResult([]);
207
208 if (static::checkFormPermission())
209 {
210 $formController = new \Bitrix\Crm\Controller\Form();
211 $publicActionResult->setResult([
212 'crmFields' => static::getCrmFields()->getResult(),
213 'crmCompanies' => static::getCrmCompanies()->getResult(),
214 'crmCategories' => static::getCrmCategories()->getResult(),
215 'agreements' => static::getAgreements()->getResult(),
216 'formOptions' => Options::create($formId)->getArray(),
217 'dictionary' => $formController->getDictAction(),
218 ]);
219 }
220
221 return $publicActionResult;
222 }
223}
static getCrmFields(?array $options=null)
Definition form.php:39
static getEditorData($formId)
Definition form.php:203