1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
persontype.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale;
4
5use Bitrix\Main\ArgumentException;
6use Bitrix\Sale\Internals;
7use Bitrix\Main\Entity;
8use Bitrix\Main\Localization\Loc;
9
10Loc::loadMessages(__FILE__);
11
17{
19 protected $siteId;
20
22 private $personTypeList = array();
23
27 protected function __construct() {}
28
32 public static function getRegistryType()
33 {
35 }
36
41 private static function createPersonTypeObject()
42 {
43 $registry = Registry::getInstance(static::getRegistryType());
44 $personTypeClassName = $registry->getPersonTypeClassName();
45
46 return new $personTypeClassName();
47 }
48
57 public static function load($siteId = null, $id = null)
58 {
59 if (strval($siteId) == "" && intval($id) <= 0)
60 {
61 throw new ArgumentException();
62 }
63
64 $personType = static::createPersonTypeObject();
65 $personType->siteId = $siteId;
66
67 $filter = array("=ACTIVE" => "Y");
68
69 if (strval($siteId) != "")
70 {
71 $filter['=PERSON_TYPE_SITE.SITE_ID'] = $siteId;
72 }
73
74 if ($id > 0)
75 {
76 $filter['ID'] = $id;
77 }
78
79 $personTypeList = static::getList(['order'=>["SORT" => "ASC", "ID"=>"ASC"], 'filter' => $filter])
80 ->fetchAll();
81
82 if ($personTypeList)
83 {
84 foreach($personTypeList as $personTypeData)
85 {
86 $personType->personTypeList[$personTypeData['ID']] = $personTypeData;
87 }
88 }
89
90 return $personType->personTypeList;
91 }
92
100 public static function getList(array $parameters = [])
101 {
102 if (!isset($parameters['filter']))
103 {
104 $parameters['filter'] = [];
105 }
106
107 $parameters['filter']['=ENTITY_REGISTRY_TYPE'] = static::getRegistryType();
108
109 return Internals\PersonTypeTable::getList($parameters);
110 }
111
119 public static function doCalculate(OrderBase $order)
120 {
121 $result = new Result();
122
123 if ($order->getPersonTypeId() !== null)
124 {
125 if (!($personTypeList = static::load($order->getSiteId(), $order->getPersonTypeId())))
126 {
127 $result->addError(new Entity\EntityError(GetMessage('SKGP_PERSON_TYPE_NOT_FOUND'), 'PERSON_TYPE_ID'));
128 }
129
130 return $result;
131 }
132
133 if (($personTypeList = static::load($order->getSiteId())) && !empty($personTypeList) && is_array($personTypeList))
134 {
135 $firstPersonType = reset($personTypeList);
136 $order->setPersonTypeId($firstPersonType["ID"]);
137 }
138 else
139 {
140 $result->addError(new Entity\EntityError(GetMessage('SKGP_PERSON_TYPE_EMPTY'), 'PERSON_TYPE_ID'));
141 }
142
143 return $result;
144 }
145
149 public static function generateXmlId()
150 {
151 return uniqid('bx_');
152 }
153
160 public static function isIndividual($personTypeId)
161 {
162 $row = BusinessValue::getPersonTypes()[$personTypeId] ?? null;
163 if ($row)
164 {
165 return $row['DOMAIN'] === BusinessValue::INDIVIDUAL_DOMAIN;
166 }
167 return false;
168 }
169
176 public static function isEntity($personTypeId)
177 {
178 $row = BusinessValue::getPersonTypes()[$personTypeId] ?? null;
179 if ($row)
180 {
181 return $row['DOMAIN'] === BusinessValue::ENTITY_DOMAIN;
182 }
183 return false;
184 }
185
186 public static function delete($id)
187 {
188 $result = Internals\PersonTypeTable::delete($id);
189 if (!$result->isSuccess())
190 {
191 return false;
192 }
193
195
197
198 return true;
199 }
200
207 public static function getIdsByDomain(string $domain): array
208 {
209 if (
212 )
213 {
214 return [];
215 }
216
217 $result = [];
219 'filter' => [
220 '=BIZVAL.DOMAIN' => $domain,
221 ],
222 'select' => [
223 'ID',
224 ],
225 'runtime' => [
227 'BIZVAL',
228 'Bitrix\Sale\Internals\BusinessValuePersonDomainTable',
229 [
230 '=this.ID' => 'ref.PERSON_TYPE_ID',
231 ],
232 [
233 'join_type' => 'INNER',
234 ]
235 ),
236 ],
237 ]);
238 while ($row = $iterator->fetch())
239 {
240 $result[] = (int)$row['ID'];
241 }
242
243 return $result;
244 }
245}
const INDIVIDUAL_DOMAIN
Определения businessvalue.php:17
static getPersonTypes($all=false, array $resetAllPersonTypes=null)
Определения businessvalue.php:627
const ENTITY_DOMAIN
Определения businessvalue.php:16
static deleteByPersonTypeId($personTypeId)
Определения persontypesite.php:64
__construct()
Определения persontype.php:27
static doCalculate(OrderBase $order)
Определения persontype.php:119
static load($siteId=null, $id=null)
Определения persontype.php:57
static isIndividual($personTypeId)
Определения persontype.php:160
static getIdsByDomain(string $domain)
Определения persontype.php:207
static isEntity($personTypeId)
Определения persontype.php:176
static generateXmlId()
Определения persontype.php:149
static getRegistryType()
Определения persontype.php:32
static getList(array $parameters=[])
Определения persontype.php:100
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
</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
$filter
Определения iblock_catalog_list.php:54
GetMessage($name, $aReplace=null)
Определения tools.php:3397
Определения ufield.php:9
$order
Определения payment.php:8
$iterator
Определения yandex_run.php:610