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