Bitrix-D7  20.0.0
Класс BusinessValue

Открытые статические члены

static getValueFromProvider (IBusinessValueProvider $provider=null, $codeKey, $consumerKey)
 
static redefineProviderField (array $fields)
 
static get ($codeKey, $consumerKey=null, $personTypeId=null, $providerInstance=null)
 Get business value. Подробнее...
 
static isSetMapping ($codeKey, $consumerKey=null, $personTypeId=null)
 Check if mapping has been set. Подробнее...
 
static getMapping ($codeKey, $consumerKey=null, $personTypeId=null, array $options=array())
 Get mapping. Подробнее...
 
static setMapping ($codeKey, $consumerKey, $personTypeId, array $mapping, $withCommon=false)
 Set mapping. Подробнее...
 
static delete ($consumerKey, $personTypeId=null)
 
static getConsumerCodePersonMapping ()
 
static getProviders ()
 Get all registered providers. Подробнее...
 
static getConsumers ()
 Get all registered consumers. Подробнее...
 
static addConsumer ($consumerKey, array $consumer)
 
static changeConsumer ($consumerKey, array $consumer)
 
static changeConsumerKey ($fromConsumerKey, $toConsumerKey)
 
static getGroups ()
 
static getPersonTypes ($all=false, array $resetAllPersonTypes=null)
 
static install ($parentName, $translationSource, $data)
 

Поля данных

const ENTITY_DOMAIN = 'E'
 
const INDIVIDUAL_DOMAIN = 'I'
 
const MATCH_ALL = -1
 
const MATCH_EXACT = 1
 
const MATCH_COMMON = 2
 
const MATCH_DEFAULT = 4
 
const COMMON_PERSON_ID = 0
 
const COMMON_DOMAIN = 'C'
 

Подробное описание

См. определение в файле businessvalue.php строка 13

Методы

◆ addConsumer()

static addConsumer (   $consumerKey,
array  $consumer 
)
static

См. определение в файле businessvalue.php строка 496

497  {
498  if (! $consumerKey)
499  throw new SystemException('Empty consumer key!');
500 
501  if (! is_array($consumer))
502  throw new SystemException('Invalid consumer!');
503 
504  self::getConsumers(); // preload consumers
505  self::addConsumerByRef($consumerKey, $consumer);
506  }

◆ changeConsumer()

static changeConsumer (   $consumerKey,
array  $consumer 
)
static

См. определение в файле businessvalue.php строка 508

509  {
510  if (! $consumerKey)
511  throw new SystemException('Empty consumer key!');
512 
513  self::getConsumers(); // preload consumers
514 
515  if (! isset(self::$consumers[$consumerKey]))
516  throw new SystemException('There is no consumer "'.$consumerKey.'" to change!');
517 
518  self::$consumers[$consumerKey] = $consumer;
519  }

◆ changeConsumerKey()

static changeConsumerKey (   $fromConsumerKey,
  $toConsumerKey 
)
static

См. определение в файле businessvalue.php строка 521

522  {
523  if (! ($fromConsumerKey && $toConsumerKey))
524  throw new SystemException('Empty consumer key!');
525 
526  if ($fromConsumerKey == $toConsumerKey)
527  return;
528 
529  self::getConsumers(); // preload consumers
530 
531  if (! isset(self::$consumers[$fromConsumerKey]))
532  throw new SystemException('There is no consumer "'.$fromConsumerKey.'" to change key!');
533 
534  if (isset(self::$consumers[$toConsumerKey]))
535  throw new SystemException('Cannot change to consumer key "'.$toConsumerKey.'", as it already exists!');
536 
537  // TODO change common consumer code['CONSUMERS']
538  self::$consumers[$toConsumerKey] = & self::$consumers[$fromConsumerKey]; // by ref!
539  unset(self::$consumers[$fromConsumerKey]);
540  }

◆ delete()

static delete (   $consumerKey,
  $personTypeId = null 
)
static
Аргументы
$consumerKey
null$personTypeId
Исключения
SystemException

См. определение в файле businessvalue.php строка 267

268  {
269  $consumerCodePersonMapping = self::getConsumerCodePersonMapping();
270  if (!isset($consumerCodePersonMapping[$consumerKey]))
271  {
272  return;
273  }
274 
275  foreach ($consumerCodePersonMapping[$consumerKey] as $code => $personTypes)
276  {
277  if ($personTypeId === null)
278  {
279  foreach ($personTypes as $id => $mapping)
280  {
281  self::deleteInternal($consumerKey, $code, $id, $mapping);
282  }
283  }
284  else
285  {
286  $mapping = $personTypes[$personTypeId];
287  self::deleteInternal($consumerKey, $code, $personTypeId, $mapping);
288  }
289  }
290  }

◆ get()

static get (   $codeKey,
  $consumerKey = null,
  $personTypeId = null,
  $providerInstance = null 
)
static

Get business value.

Аргументы
string$codeKey
string | null$consumerKey
IBusinessValueProvider | string | integer | null$personTypeId
mixed$providerInstance
Возвращает
mixed

См. определение в файле businessvalue.php строка 43

44  {
45  $value = null;
46 
47  if ($personTypeId instanceof IBusinessValueProvider)
48  {
49  $provider = $personTypeId;
50  $personTypeId = $provider->getPersonTypeId();
51  $mapping = self::getMapping(
52  $codeKey,
53  $consumerKey,
54  $personTypeId,
55  array('GET_VALUE' => array('PROPERTY' => 'BY_ID', 'PROVIDER' => $provider))
56  );
57 
58  $providerInstance = $provider->getBusinessValueProviderInstance($mapping);
59  }
60  else
61  {
62  if ($personTypeId <= 0)
63  $personTypeId = null;
64  $mapping = self::getMapping($codeKey, $consumerKey, $personTypeId, array('GET_VALUE' => array('PROPERTY' => 'BY_ID')));
65  }
66 
67  if (isset(self::$redefinedFields[$mapping['PROVIDER_KEY']][$mapping['PROVIDER_VALUE']]))
68  {
69  return self::$redefinedFields[$mapping['PROVIDER_KEY']][$mapping['PROVIDER_VALUE']];
70  }
71 
72  if ($mapping['PROVIDER_KEY'] && $mapping['PROVIDER_VALUE'])
73  {
74  switch ($mapping['PROVIDER_KEY'])
75  {
76  case 'VALUE':
77  case 'INPUT':
78  $value = $mapping['PROVIDER_VALUE'];
79  break;
80 
81  default:
82  if (($providers = self::getProviders())
83  && ($provider = $providers[$mapping['PROVIDER_KEY']])
84  && is_array($provider)
85  && is_callable($provider['GET_INSTANCE_VALUE'])
86  && ($v = call_user_func($provider['GET_INSTANCE_VALUE'], $providerInstance, $mapping['PROVIDER_VALUE'], $personTypeId)))
87  {
88  $value = $v;
89  }
90  }
91  }
92 
93  return $value;
94  }

◆ getConsumerCodePersonMapping()

static getConsumerCodePersonMapping ( )
static

См. определение в файле businessvalue.php строка 318

319  {
320  if (! self::$consumerCodePersonMapping)
321  {
322  $result = BusinessValueTable::getList(array(
323  'select' => array('CODE_KEY', 'CONSUMER_KEY', 'PERSON_TYPE_ID', 'PROVIDER_KEY', 'PROVIDER_VALUE'),
324  // !!! if filter is set, than setMapping must evaluate personTypeId's for codes, otherwise it will throw duplicate error!!!
325  //'filter' => array('=PERSON_TYPE_ID' => array_merge(array(BusinessValueTable::COMMON_PERSON_TYPE_ID), array_keys(self::getPersonTypes())),
326  ));
327 
328  while ($row = $result->fetch())
329  {
330  $row['CODE_KEY'] = ToUpper($row['CODE_KEY']);
331  // TODO delete mappings for non existent code:consumer:person from db
332  // TODO optimize memory usage $consumerCodePersonMapping >> $personConsumerCodeMapping
333  self::$consumerCodePersonMapping[$row['CONSUMER_KEY']][$row['CODE_KEY']][$row['PERSON_TYPE_ID']] = array(
334  'PROVIDER_KEY' => $row['PROVIDER_KEY'],
335  'PROVIDER_VALUE' => $row['PROVIDER_VALUE'],
336  );
337  }
338  }
339 
340  return self::$consumerCodePersonMapping;
341  }

◆ getConsumers()

static getConsumers ( )
static

Get all registered consumers.

Возвращает
array
Исключения
SystemException

См. определение в файле businessvalue.php строка 381

382  {
383  if (! self::$consumers)
384  {
385  self::$commonConsumer = array(
386  'NAME' => Loc::getMessage('BIZVAL_CONSUMER_COMMON'),
387  'SORT' => 0,
388  'CODES' => array(),
389  );
390 
391  self::$consumers[''] =& self::$commonConsumer;
392 
393  foreach (EventManager::getInstance()->findEventHandlers('sale', 'OnGetBusinessValueConsumers') as $handler)
394  {
395 // // TODO remove
396 // if (! ($handler['TO_NAME'] == 'Bitrix\Sale\BusinessValueHandlers::getConsumers'
397 //// || $handler['TO_NAME'] == 'Bitrix\Sale\BusinessValueConsumer1C::getConsumers'
398 // ))
399 // continue;
400 
401  $result = &ExecuteModuleEventEx($handler); // by ref! // TODO modern api
402 
403  if (is_array($result))
404  {
405  foreach ($result as $consumerKey => &$consumer) // by ref!
406  {
407  if ($consumerKey && is_array($consumer))
408  {
409  self::addConsumerByRef($consumerKey, $consumer);
410  }
411  }
412  }
413  }
414  self::sortArray(self::$commonConsumer['CODES']);
415 
416  self::sortArray(self::$consumers);
417 
418 // if (self::$commonConsumer['CODES'] &&
419 // (self::$commonConsumer['CODES'] = array_filter(
420 // self::$commonConsumer['CODES'],
421 // function ($i) {return count($i['CONSUMERS']) > 1 && (! is_array($i['DOMAINS']) || $i['DOMAINS']);}
422 // )))
423 // {}
424  }
425 
426  return self::$consumers;
427  }

◆ getGroups()

static getGroups ( )
static

См. определение в файле businessvalue.php строка 542

543  {
544  static $groups = array();
545 
546  if (! $groups)
547  {
548  foreach (EventManager::getInstance()->findEventHandlers('sale', 'OnGetBusinessValueGroups') as $handler)
549  {
550  $result = ExecuteModuleEventEx($handler); // TODO modern api
551 
552  if (is_array($result))
553  {
554  foreach ($result as $groupKey => $group)
555  {
556  if ($groupKey && is_array($group) && ! $groups[$groupKey])
557  {
558  $groups[$groupKey] = $group;
559  }
560  }
561  }
562  }
563 
564  self::sortArray($groups);
565  }
566 
567  return $groups;
568  }

◆ getMapping()

static getMapping (   $codeKey,
  $consumerKey = null,
  $personTypeId = null,
array  $options = array() 
)
static

Get mapping.

Аргументы
string$codeKey
string | null$consumerKey
string | integer | null$personTypeId
array$options
Возвращает
array with PROVIDER_KEY and PROVIDER_VALUE if mapping was found, or empty array

См. определение в файле businessvalue.php строка 120

121  {
122  $mapping = array();
123  $codeKeyUp = ToUpper($codeKey);
124 
125  if ((int)$personTypeId === 0)
126  {
127  $personTypeId = null;
128  }
129 
130  $match = is_int($options['MATCH']) ? $options['MATCH'] : self::MATCH_ALL;
131 
132  $consumerCodePersonMapping = is_array($options['consumerCodePersonMapping']) // internal, do not use!
133  ? $options['consumerCodePersonMapping']
135 
136  if ($match & self::MATCH_EXACT && isset($consumerCodePersonMapping[$consumerKey][$codeKeyUp][$personTypeId]))
137  {
138  $mapping = $consumerCodePersonMapping[$consumerKey][$codeKeyUp][$personTypeId];
139  }
140  else
141  {
142  if ($match & self::MATCH_COMMON)
143  {
144  if ($personTypeId && isset($consumerCodePersonMapping[$consumerKey][$codeKeyUp]['']))
145  $mapping = $consumerCodePersonMapping[$consumerKey][$codeKeyUp][''];
146  elseif ($consumerKey && isset($consumerCodePersonMapping[''][$codeKeyUp][$personTypeId]))
147  $mapping = $consumerCodePersonMapping[''][$codeKeyUp][$personTypeId];
148  elseif ($consumerKey && $personTypeId && isset($consumerCodePersonMapping[''][$codeKeyUp]['']))
149  $mapping = $consumerCodePersonMapping[''][$codeKeyUp][''];
150  }
151 
152  if (! $mapping && $match & self::MATCH_DEFAULT && ($consumers = self::getConsumers()))
153  {
154  if (is_array($consumers[$consumerKey]['CODES'][$codeKey]['DEFAULT']))
155  {
156  $mapping = $consumers[$consumerKey]['CODES'][$codeKey]['DEFAULT'];
157  }
158 // elseif ($consumerKey && is_array($consumers['']['CODES'][$codeKey]['DEFAULT']))
159 // {
160 // $mapping = $consumers['']['CODES'][$codeKey]['DEFAULT'];
161 // }
162  }
163  }
164 
165  // TODO universal approach maybe later
166  if ($mapping
167  && $mapping['PROVIDER_KEY'] == 'PROPERTY'
168  && $mapping['PROVIDER_VALUE']
169  && ($providers = BusinessValue::getProviders())
170  && is_callable($providers['PROPERTY']['GET_VALUE']))
171  {
172  $mapping['PROVIDER_VALUE'] = call_user_func($providers['PROPERTY']['GET_VALUE'],
173  $mapping['PROVIDER_VALUE'],
174  $personTypeId,
175  isset($options['GET_VALUE']['PROPERTY']) ? $options['GET_VALUE']['PROPERTY'] : null,
176  isset($options['GET_VALUE']['PROVIDER']) ? $options['GET_VALUE']['PROVIDER'] : null
177  );
178  }
179 
180  return $mapping;
181  }

◆ getPersonTypes()

static getPersonTypes (   $all = false,
array  $resetAllPersonTypes = null 
)
static

См. определение в файле businessvalue.php строка 585

586  {
587  static $allPersonTypes = array(), $personTypes = array();
588 
589  if ($resetAllPersonTypes !== null)
590  {
591  $allPersonTypes = $resetAllPersonTypes;
592  $personTypes = array_filter($allPersonTypes, function ($i) {return $i['DOMAIN'];});
593  }
594  elseif (! $allPersonTypes)
595  {
596  $dbRes = Internals\PersonTypeTable::getList([
597  'select' => [
598  'ID', 'NAME', 'LID', 'ACTIVE', 'ENTITY_REGISTRY_TYPE',
599  'DOMAIN' => 'BIZVAL.DOMAIN',
600  'PT_SITE' => 'PERSON_TYPE_SITE.SITE_ID'
601  ],
602  'order' => ['SORT', 'NAME'],
603  'runtime' => [
604  new \Bitrix\Main\Entity\ReferenceField(
605  'BIZVAL',
606  'Bitrix\Sale\Internals\BusinessValuePersonDomainTable',
607  ['=this.ID' => 'ref.PERSON_TYPE_ID'],
608  ['join_type' => 'LEFT']
609  ),
610  ],
611  ]);
612 
613  $result = array();
614  while ($row = $dbRes->fetch())
615  {
616  if (!isset($result[$row['ID']]))
617  {
618  $row['PT_SITE'] = array($row['PT_SITE']);
619  $result[$row['ID']] = $row;
620  }
621  else
622  {
623  $result[$row['ID']]['PT_SITE'][] = $row['PT_SITE'];
624  }
625  }
626 
627  foreach ($result as $item)
628  {
629  $item['TITLE'] = $item['NAME'].' ('.implode(', ' , $item['PT_SITE']).')';
630 
631  $allPersonTypes[$item['ID']] = $item;
632 
633  if ($item['DOMAIN'])
634  $personTypes[$item['ID']] = $item;
635  }
636  }
637 
638  return $all ? $allPersonTypes : $personTypes;
639  }

◆ getProviders()

static getProviders ( )
static

Get all registered providers.

Возвращает
array
Исключения
SystemException

См. определение в файле businessvalue.php строка 348

349  {
351 
352  foreach (EventManager::getInstance()->findEventHandlers('sale', 'OnGetBusinessValueProviders') as $handler)
353  {
354  $result = ExecuteModuleEventEx($handler);
355 
356  if (is_array($result))
357  {
358  foreach ($result as $providerKey => $provider)
359  {
360  if ($providerKey && is_array($provider))
361  {
362  if (isset($providers[$providerKey]))
363  throw new SystemException('duplicate provider key '.$providerKey);
364 
365  $providers[$providerKey] = $provider;
366  }
367  }
368  }
369  }
370 
371  self::sortArray($providers);
372  return $providers;
373  }

◆ getValueFromProvider()

static getValueFromProvider ( IBusinessValueProvider  $provider = null,
  $codeKey,
  $consumerKey 
)
static
Уст.:

См. определение в файле businessvalue.php строка 23

24  {
25  return self::get($codeKey, $consumerKey, $provider);
26  }

◆ install()

static install (   $parentName,
  $translationSource,
  $data 
)
static
Уст.:

См. определение в файле businessvalue.php строка 644

645  {
646  }

◆ isSetMapping()

static isSetMapping (   $codeKey,
  $consumerKey = null,
  $personTypeId = null 
)
static

Check if mapping has been set.

Аргументы
string$codeKey
string | null$consumerKey
string | integer | null$personTypeId
Возвращает
bool

См. определение в файле businessvalue.php строка 102

103  {
104  $codeKey = ToUpper($codeKey);
105  return isset(self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]);
106  }

◆ redefineProviderField()

static redefineProviderField ( array  $fields)
static
Аргументы
array$fields

См. определение в файле businessvalue.php строка 31

32  {
33  self::$redefinedFields = array_replace_recursive(self::$redefinedFields, $fields);
34  }

◆ setMapping()

static setMapping (   $codeKey,
  $consumerKey,
  $personTypeId,
array  $mapping,
  $withCommon = false 
)
static

Set mapping.

Аргументы
string$codeKey
string | null$consumerKey
string | integer | null$personTypeId
array$mapping
bool$withCommoninternal, do not use!
Возвращает
\Bitrix\Main\Entity\Result
Исключения

См. определение в файле businessvalue.php строка 192

193  {
194  $codeKey = ToUpper($codeKey);
195  if (! $consumerKey || $consumerKey === BusinessValueTable::COMMON_CONSUMER_KEY)
196  $consumerKey = null;
197 
198  if (! $personTypeId || $personTypeId === BusinessValueTable::COMMON_PERSON_TYPE_ID)
199  $personTypeId = null;
200 
201  if (!array_key_exists('PROVIDER_KEY', $mapping) || !array_key_exists('PROVIDER_VALUE', $mapping))
202  $mapping = array();
203 
204  $primary = array(
205  'CODE_KEY' => $codeKey,
206  // TODO remove save_data_modification hack
207  'CONSUMER_KEY' => $consumerKey ?: BusinessValueTable::COMMON_CONSUMER_KEY,
208  'PERSON_TYPE_ID' => $personTypeId ?: BusinessValueTable::COMMON_PERSON_TYPE_ID,
209  );
210 
211  $consumerCodePersonMapping = self::getConsumerCodePersonMapping();
212 
213  if (isset($consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]))
214  {
215  if ($mapping)
216  {
217  $savedMapping = $consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId];
218 
219  if (! ($mapping['PROVIDER_KEY'] == $savedMapping['PROVIDER_KEY']
220  && $mapping['PROVIDER_VALUE'] == $savedMapping['PROVIDER_VALUE']))
221  $result = BusinessValueTable::update($primary, $mapping);
222  }
223  else
224  {
225  $result = BusinessValueTable::delete($primary);
226  }
227  }
228  elseif ($mapping)
229  {
230  if ($withCommon
231  && $consumerKey
232  && !isset($consumerCodePersonMapping[''][$codeKey][''])
233  )
234  {
235  $consumerKey = null;
236  $personTypeId = null;
237  $primary['CONSUMER_KEY'] = BusinessValueTable::COMMON_CONSUMER_KEY;
238  $primary['PERSON_TYPE_ID'] = BusinessValueTable::COMMON_PERSON_TYPE_ID;
239  }
240 
241  $result = BusinessValueTable::add($primary + $mapping);
242  }
243 
244  if (isset($result))
245  {
246  if ($result->isSuccess())
247  {
248  if ($mapping)
249  self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId] = $mapping;
250  else
251  unset(self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]);
252  }
253  }
254  else
255  {
256  $result = new \Bitrix\Main\Entity\Result;
257  }
258 
259  return $result;
260  }

Поля

◆ COMMON_DOMAIN

const COMMON_DOMAIN = 'C'
Уст.:

См. определение в файле businessvalue.php строка 651

◆ COMMON_PERSON_ID

const COMMON_PERSON_ID = 0
Уст.:

См. определение в файле businessvalue.php строка 649

◆ ENTITY_DOMAIN

const ENTITY_DOMAIN = 'E'

См. определение в файле businessvalue.php строка 15

◆ INDIVIDUAL_DOMAIN

const INDIVIDUAL_DOMAIN = 'I'

См. определение в файле businessvalue.php строка 16

◆ MATCH_ALL

const MATCH_ALL = -1

См. определение в файле businessvalue.php строка 108

◆ MATCH_COMMON

const MATCH_COMMON = 2

См. определение в файле businessvalue.php строка 110

◆ MATCH_DEFAULT

const MATCH_DEFAULT = 4

См. определение в файле businessvalue.php строка 111

◆ MATCH_EXACT

const MATCH_EXACT = 1

См. определение в файле businessvalue.php строка 109


Объявления и описания членов класса находятся в файле:
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
Bitrix\Sale\BusinessValue\getConsumerCodePersonMapping
static getConsumerCodePersonMapping()
Definition: businessvalue.php:318
Bitrix\Sale\Internals\BusinessValueTable\COMMON_PERSON_TYPE_ID
const COMMON_PERSON_TYPE_ID
Definition: internals/businessvalue.php:19
Bitrix\Sale\BusinessValue\getConsumers
static getConsumers()
Get all registered consumers.
Definition: businessvalue.php:381
Bitrix\Sale\Internals\BusinessValueTable\COMMON_CONSUMER_KEY
const COMMON_CONSUMER_KEY
Definition: internals/businessvalue.php:20
Bitrix\Main\EventManager\getInstance
static getInstance()
Definition: main/lib/eventmanager.php:34
Bitrix\Sale\BusinessValue\getProviders
static getProviders()
Get all registered providers.
Definition: businessvalue.php:348
Bitrix\Sale\BusinessValue\MATCH_ALL
const MATCH_ALL
Definition: businessvalue.php:108
Bitrix\Sale\BusinessValue\get
static get($codeKey, $consumerKey=null, $personTypeId=null, $providerInstance=null)
Get business value.
Definition: businessvalue.php:43
Bitrix\Sale\BusinessValue\getMapping
static getMapping($codeKey, $consumerKey=null, $personTypeId=null, array $options=array())
Get mapping.
Definition: businessvalue.php:120
Bitrix
Class Button.
Bitrix\Sale\BusinessValueHandlers\getProviders
static getProviders()
Definition: businessvalue.php:657