Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
persontype.php
1<?php
2
3namespace Bitrix\Sale;
4
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}
static loadMessages($file)
Definition loc.php:64
static getPersonTypes($all=false, array $resetAllPersonTypes=null)
setPersonTypeId($personTypeId)
static doCalculate(OrderBase $order)
static load($siteId=null, $id=null)
static isIndividual($personTypeId)
static isEntity($personTypeId)
static getList(array $parameters=[])
static getInstance($type)
Definition registry.php:183