14final class BusinessValueControl
17 private $consumerCodePersonMapping = array();
18 private $errors = array();
22 $this->name = $name.
'BizVal';
25 public function setMapFromPost()
27 if ($this->consumerCodePersonMapping)
28 throw new SystemException(
'Map is already set from post!');
30 if (isset($_POST[$this->name][
'MAP']) && is_array($_POST[$this->name][
'MAP']))
32 $_POST = Input\File::getPostWithFiles($_POST, $_FILES);
33 $consumerCodePersonMapping = $_POST[$this->name][
'MAP'];
34 unset($_POST[$this->name][
'MAP']);
38 $consumers = BusinessValue::getConsumers();
40 foreach ($consumerCodePersonMapping as $consumerKey => &$codePersonMapping)
42 if ($consumerKey === BusinessValueTable::COMMON_CONSUMER_KEY)
45 $consumerCodePersonMapping[
null] = &$codePersonMapping;
46 unset($consumerCodePersonMapping[BusinessValueTable::COMMON_CONSUMER_KEY]);
49 if (! (($consumer = $consumers[$consumerKey]) && is_array($consumer) && is_array($codePersonMapping)))
51 unset($consumerCodePersonMapping[$consumerKey]);
55 if (! (($codes = $consumer[
'CODES']) && is_array($codes)))
58 $skipNewCodeSanitation = $consumer[
'SKIP_NEW_CODE_SANITATION'] ??
false;
60 $sanitizeMapping = $consumer[
'SANITIZE_MAPPING'] ??
null;
61 if (!is_callable($sanitizeMapping))
63 $sanitizeMapping =
null;
66 $renderColumns = $consumer[
'RENDER_COLUMNS'] ??
null;
68 (! $codes && ! $skipNewCodeSanitation)
69 || ($skipNewCodeSanitation && ! $sanitizeMapping)
70 || (is_callable($renderColumns) && ! $sanitizeMapping)
73 unset($consumerCodePersonMapping[$consumerKey]);
77 foreach ($codePersonMapping as $codeKey => &$personMapping)
79 $code = $codes[$codeKey];
81 if (! (is_array($personMapping) && (is_array($code) || $skipNewCodeSanitation)))
83 unset($codePersonMapping[$codeKey]);
87 foreach ($personMapping as $personTypeId => &$mapping)
89 if ($personTypeId === BusinessValueTable::COMMON_PERSON_TYPE_ID)
92 $personMapping[
null] = &$mapping;
93 unset($personMapping[BusinessValueTable::COMMON_PERSON_TYPE_ID]);
96 $codeDomains = $code[
'DOMAINS'] ??
null;
97 $personType = self::$personTypes[$personTypeId] ??
null;
99 if (! is_array($code) && $skipNewCodeSanitation)
103 elseif (! (is_array($code)
104 && (! isset($code[
'PERSON_TYPE_ID']) || $code[
'PERSON_TYPE_ID'] == $personTypeId)
105 && (! is_array($codeDomains) || in_array($personType[
'DOMAIN'], $codeDomains,
true))
106 && is_array($mapping)))
108 unset($personMapping[$personTypeId]);
114 !empty($mapping[
'DELETE'])
115 || empty($mapping[
'PROVIDER_KEY'])
116 || empty($mapping[
'PROVIDER_VALUE'])
122 if ($sanitizeMapping)
124 if ($e = call_user_func_array($sanitizeMapping, array($codeKey, $personTypeId, &$mapping)))
125 $errors[$consumerKey][$codeKey][$personTypeId] = $e;
127 elseif (isset($code[
'INPUT']) && is_array($code[
'INPUT']))
129 $mapping[
'PROVIDER_KEY'] =
'INPUT';
131 if ($e = Input\Manager::getError($code[
'INPUT'], $mapping[
'PROVIDER_VALUE'] ?? []))
132 $errors[$consumerKey][$codeKey][$personTypeId][
'PROVIDER_VALUE'] = $e;
136 if ($e = self::sanitizeMapping($personTypeId, $mapping, $code[
'PROVIDERS'] ?? $consumer[
'PROVIDERS'] ?? []))
137 $errors[$consumerKey][$codeKey][$personTypeId] = $e;
142 unset($personMapping[$personTypeId]);
148 $this->consumerCodePersonMapping = $consumerCodePersonMapping;
149 $this->errors = $errors;
152 return ! $this->errors;
156 public static function sanitizeMapping($personTypeId, array &$mapping, array $providerKeys =
null)
160 if (($providerInput = self::getProviderInput($personTypeId, $providerKeys))
161 && ($providerValueInput = self::$personProviderValueInput[$personTypeId])
162 && ($valueInput = $providerValueInput[$mapping[
'PROVIDER_KEY']]))
164 if ($e = Input\Manager::getError($providerInput, $mapping[
'PROVIDER_KEY']))
165 $error[
'PROVIDER_KEY'] = $e;
167 $mapping[
'PROVIDER_KEY'] = Input\Manager::getValue($providerInput, $mapping[
'PROVIDER_KEY']);
169 if ($e = Input\Manager::getError($valueInput, $mapping[
'PROVIDER_VALUE'] ?? []))
170 $error[
'PROVIDER_VALUE'] = $e;
172 $mapping[
'PROVIDER_VALUE'] = Input\Manager::getValue($valueInput, $mapping[
'PROVIDER_VALUE'] ?? []);
182 public function changeConsumerKey($fromConsumerKey, $toConsumerKey)
184 BusinessValue::changeConsumerKey($fromConsumerKey, $toConsumerKey);
186 if (isset($this->consumerCodePersonMapping[$fromConsumerKey]))
188 $this->consumerCodePersonMapping[$toConsumerKey] = $this->consumerCodePersonMapping[$fromConsumerKey];
189 unset($this->consumerCodePersonMapping[$fromConsumerKey]);
193 public function saveMap()
196 throw new SystemException(
'There are errors in map!');
198 $consumers = BusinessValue::getConsumers();
200 foreach ($this->consumerCodePersonMapping as $consumerKey => $codePersonMapping)
202 $consumer = $consumers[$consumerKey] ?? [];
204 isset($consumer[
'SET_MAPPING']) && is_callable($consumer[
'SET_MAPPING'])
205 ? $consumer[
'SET_MAPPING']
208 $codes = $consumer[
'CODES'] ?? [];
210 foreach ($codePersonMapping as $codeKey => $personMapping)
212 $code = $codes[$codeKey] ?? [];
213 $fileInput = $code[
'INPUT'] ?? [];
214 $fileType = $fileInput[
'TYPE'] ??
'';
215 if (!(is_array($fileInput) && ($fileType ==
'FILE' || $fileType ==
'DATABASE_FILE')))
220 foreach ($personMapping as $personTypeId => $mapping)
224 $result = call_user_func($setMapping, $codeKey, $personTypeId, $mapping);
228 $consumerCodePersonMapping = \Bitrix\Sale\BusinessValue::getConsumerCodePersonMapping();
229 if ($fileInput && ($file =& $mapping[
'PROVIDER_VALUE']))
231 if (Input\File::isDeletedSingle($file))
233 if ($fileInput[
'TYPE'] ==
'FILE')
235 if (is_numeric($file[
'ID']) && isset($consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]))
237 \CFile::Delete($file[
'ID']);
243 elseif (Input\File::isUploadedSingle($file))
245 if ($fileInput[
'TYPE'] ==
'FILE')
247 if (($file = \CFile::SaveFile(array(
'MODULE_ID' =>
'sale') + $file,
'sale/bizval')) && is_numeric($file))
249 if (($oldFile = BusinessValue::getMapping($codeKey, $consumerKey, $personTypeId, array(
'MATCH' => BusinessValue::MATCH_EXACT))) && is_numeric($oldFile[
'PROVIDER_VALUE']))
250 \CFile::Delete($oldFile[
'PROVIDER_VALUE']);
254 $this->errors[$consumerKey][$codeKey][$personTypeId][
'DATABASE'] =
'unable to save file';
258 $file = Input\Manager::getValue($fileInput, $file);
260 elseif($fileInput[
'TYPE'] ==
'DATABASE_FILE')
264 $content = $APPLICATION->GetFileContent($file[
'tmp_name']);
278 elseif (isset($fileInput[
'TYPE']) && is_array($fileInput) && $fileInput[
'TYPE'] ===
'FILE')
280 if (isset($consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]))
282 \CFile::Delete($consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId][
'PROVIDER_VALUE']);
286 $common = IsModuleInstalled(
'bitrix24') ? false :
true;
287 $result = BusinessValue::setMapping($codeKey, $consumerKey, $personTypeId, $mapping, $common);
290 if (! $result->isSuccess())
291 $this->errors[$consumerKey][$codeKey][$personTypeId][
'DATABASE'] = $result->getErrorMessages();
296 return ! $this->errors;
299 private static function getTabControl($name, $personGroupCodes)
303 BusinessValue::INDIVIDUAL_DOMAIN =>
Loc::getMessage(
'BIZVAL_DOMAIN_INDIVIDUAL'),
304 BusinessValue::ENTITY_DOMAIN =>
Loc::getMessage(
'BIZVAL_DOMAIN_ENTITY' ),
309 foreach ($personGroupCodes as $personTypeId => $groupCodes)
311 $personType = self::$personTypes[$personTypeId];
312 if (isset($personType[
'ENTITY_REGISTRY_TYPE'])
313 && $personType[
'ENTITY_REGISTRY_TYPE'] !== Registry::REGISTRY_TYPE_ORDER
320 'DIV' =>
'map'.$personTypeId,
321 'TAB' => htmlspecialcharsbx($personType[
'TITLE']),
322 'TITLE' => $domains[$personType[
'DOMAIN']],
326 return new \CAdminViewTabControl($name.
'TabControl', $tabs);
329 private static function getPersonGroupCodes(array $consumers, array $filter)
331 $personGroupCodes = [];
333 $consumerCodePersonMapping = BusinessValue::getConsumerCodePersonMapping();
335 $consumer = $consumers[$filter[
'CONSUMER_KEY']];
338 (empty($filter[
'PROVIDER_KEY']) && empty($filter[
'CODE_KEY']))
339 || !empty($filter[
'CONSUMER_KEY'])
343 $filter[
'CONSUMER_KEY'] => $consumer,
347 foreach (self::$personTypes as $personTypeId => $personType)
349 foreach ($consumers as $consumerKey => $consumer)
351 if (is_array($consumer) && isset($consumer[
'CODES']) && is_array($consumer[
'CODES']))
353 $consumerCodes = $consumer[
'CODES'];
354 foreach ($consumerCodes as $codeKey => $code)
356 $needCodeKey = !isset($filter[
'CODE_KEY']) || (string)$filter[
'CODE_KEY'] === (
string)$codeKey;
357 $needPersonTypeId = !isset($code[
'PERSON_TYPE_ID']) || (int)$code[
'PERSON_TYPE_ID'] === (
int)$personTypeId;
359 !isset($code[
'DOMAINS'])
360 || !is_array($code[
'DOMAINS'])
361 || in_array($personType[
'DOMAIN'], $code[
'DOMAINS'],
true)
371 $code[
'CONSUMER_KEY'] = $consumerKey;
373 if (!empty($filter[
'PROVIDER_KEY']))
375 if (isset($consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]))
377 $mapping = $consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId];
379 if ($mapping[
'PROVIDER_KEY' ] == $filter[
'PROVIDER_KEY' ] &&
380 $mapping[
'PROVIDER_VALUE'] == $filter[
'PROVIDER_VALUE'])
382 $personGroupCodes[$personTypeId][$consumer[
'NAME'] ?? $consumerKey][$codeKey] = $code;
386 elseif (!empty($filter[
'CODE_KEY']))
388 $personGroupCodes[$personTypeId][$consumer[
'NAME'] ?? $consumerKey][$codeKey] = $code;
392 $codeGroup = $code[
'GROUP'] ??
'';
393 $personGroupCodes[$personTypeId][$codeGroup][$codeKey] = $code;
400 if (isset($personGroupCodes[$personTypeId]) && empty($filter[
'PROVIDER_KEY']) && empty($filter[
'CODE_KEY']))
402 self::sortRenameGroups($personGroupCodes[$personTypeId], self::$groups);
406 return $personGroupCodes;
409 public function renderMap(array $options = array())
412 isset($options[
'HIDE_FILLED_CODES']) && $options[
'HIDE_FILLED_CODES'] ===
false
417 $consumers = BusinessValue::getConsumers();
418 $personGroupCodes = self::getPersonGroupCodes($consumers, $options);
419 $tabControl = self::getTabControl($this->name, $personGroupCodes);
421 $consumerCodePersonMapping = BusinessValue::getConsumerCodePersonMapping();
425 foreach ($this->consumerCodePersonMapping as $consumerKey => $codePersonMapping)
426 foreach ($codePersonMapping as $codeKey => $personMapping)
427 foreach ($personMapping as $personTypeId => $mapping)
428 if ($mapping[
'PROVIDER_KEY'])
429 $consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId] = $mapping;
432 $tabControl->Begin();
434 foreach ($personGroupCodes as $personTypeId => $groupCodes)
436 $personType = self::$personTypes[$personTypeId];
437 if (isset($personType[
'ENTITY_REGISTRY_TYPE'])
438 && $personType[
'ENTITY_REGISTRY_TYPE'] !== Registry::REGISTRY_TYPE_ORDER
444 $tabControl->BeginNextTab();
447 <table border=
"0" cellspacing=
"0" cellpadding=
"0" width=
"100%" class=
"adm-detail-content-table edit-table">
449 <col
class=
"adm-detail-content-cell-l" width=
"40%">
450 <col
class=
"adm-detail-content-cell-r" width=
"60%">
454 $personHasHiddenRows = 0;
456 foreach ($groupCodes as $groupName => $codes)
458 $groupHasVisibleRows =
false;
466 foreach ($codes as $codeKey => $code)
468 if ($codeKey ===
'USER_COLUMNS')
471 $consumerKey = $code[
'CONSUMER_KEY'];
472 $consumer = $consumers[$consumerKey];
474 if (isset($this->errors[$consumerKey][$codeKey][$personTypeId]) &&
475 ($error = $this->errors[$consumerKey][$codeKey][$personTypeId]))
477 if (! is_array($error))
478 $error = array($error);
483 <td style=
"color:#ff1118; padding: 1em 0 0 13em;">
486 foreach ($error as $k => $e)
487 echo htmlspecialcharsbx(is_array($e) ? implode(
', ', $e) : $e).
'<br>';
496 'consumerCodePersonMapping' => $consumerCodePersonMapping,
497 'GET_VALUE' => array(
'PROPERTY' =>
'BY_ID'),
501 'EXACT' => BusinessValue::getMapping($codeKey, $consumerKey, $personTypeId, array(
'MATCH' => BusinessValue::MATCH_EXACT ) + $o),
502 'COMMON' => BusinessValue::getMapping($codeKey, $consumerKey, $personTypeId, array(
'MATCH' => BusinessValue::MATCH_COMMON ) + $o),
503 'DEFAULT' => BusinessValue::getMapping($codeKey, $consumerKey, $personTypeId, array(
'MATCH' => BusinessValue::MATCH_DEFAULT) + $o),
506 $inputNamePrefix = $this->name.
'[MAP]['
507 .($consumerKey ?: BusinessValueTable::COMMON_CONSUMER_KEY).
']['
509 .($personTypeId ?: BusinessValueTable::COMMON_PERSON_TYPE_ID).
']';
513 if (isset($consumer[
'RENDER_COLUMNS']) && is_callable($consumer[
'RENDER_COLUMNS']))
515 $hideCode = call_user_func($consumer[
'RENDER_COLUMNS'], $codeKey, $personTypeId, $mappings, $inputNamePrefix);
523 if (isset($code[
'CONSUMERS']) && is_array($code[
'CONSUMERS']) && count($code[
'CONSUMERS']) > 1)
525 echo implode(
', ', array_map(
function ($i) {
return htmlspecialcharsbx($i);}, array_flip($code[
'NAMES'])));
528 <img src=
"/bitrix/js/main/core/images/hint.gif" style=
"cursor: help;"
529 title=
"<?=htmlspecialcharsbx(implode(', ', $code['CONSUMERS']))?>">
534 echo htmlspecialcharsbx($code[
'NAME'] ?? $codeKey);
537 if (isset($code[
'DESCRIPTION']) && is_string($code[
'DESCRIPTION']))
540 <div style=
"font-size:10px;"><?=htmlspecialcharsbx($code[
'DESCRIPTION'])?></div>
549 $commonProviderInput = $commonProviderValueInput =
null;
551 if (isset($code[
'INPUT']) && is_array($code[
'INPUT']))
553 $providerInput = array(
'TYPE' =>
'ENUM',
'HIDDEN' =>
true,
'OPTIONS' => array(
'INPUT' =>
''));
554 $providerValueInput = array(
557 'ONCHANGE' =>
"bizvalChangeValue(this)",
564 $providersValues = $code[
'PROVIDERS'] ?? $consumer[
'PROVIDERS'] ?? [];
566 $providerInput = self::getProviderInput($personTypeId, $providersValues);
567 $providerValueInput = self::getValueInput($personTypeId);
571 $commonProviderInput = self::getProviderInput(
'', $providersValues);
572 $commonProviderValueInput = self::getValueInput(
'');
578 $hideCode = self::renderMapping($mappings, $inputNamePrefix, $providerInput, $providerValueInput, $commonProviderInput, $commonProviderValueInput);
580 catch (SystemException $exception)
590 $columnsHTML = ob_get_clean();
595 if ($hideFilledCodes && $hideCode)
597 ?>
class=
"<?=$this->name.$personTypeId?>row-with-value" style=
"display:none;"<?
598 $personHasHiddenRows =
true;
602 $groupHasVisibleRows =
true;
611 $rowsHTML = ob_get_clean();
618 if ($hideFilledCodes && ! $groupHasVisibleRows)
619 echo
' class="'.$this->name.$personTypeId.
'row-with-value" style="display:none;"';
622 <td colspan=
"2" style=
"
623 padding: 15px 15px 3px;
624 text-align: center; color: #4B6267;
625 font-weight: bold; border-bottom: 5px solid #E0E8EA;">
626 <?=htmlspecialcharsbx($groupName)?>
643 if ($hideFilledCodes && $personHasHiddenRows)
647 <a href=
"#" onclick=
"bizvalToggleRowsVisibility(this, '<?=$this->name.$personTypeId.'row-with-value'?>'); return false;">
657 self::renderScript();
661 public static function renderMapping(array $mappings, $inputNamePrefix, array $providerInput, array $providerValueInput, array $commonProviderInput =
null, array $commonProviderValueInput =
null)
663 foreach ($mappings as &$m)
664 $m = self::correctMapping($providerInput, $providerValueInput, $m);
667 $mappings[
'EXACT'] ??= [];
668 $mappings[
'COMMON'] ??= [];
669 $mappings[
'DEFAULT'] ??= [];
671 if ($m = ($mappings[
'EXACT'] ?: $mappings[
'COMMON'] ?: $mappings[
'DEFAULT']))
673 $providerKey = $m[
'PROVIDER_KEY' ];
674 $providerValue = $m[
'PROVIDER_VALUE'];
675 $valueInput = $providerValueInput[$providerKey];
679 $providerKey = is_array($providerInput[
'OPTIONS']) ? key($providerInput[
'OPTIONS']) : null;
680 $providerValue =
null;
681 $valueInput = $providerValueInput[$providerKey] ?? array(
'TYPE' =>
'STRING',
'HIDDEN' =>
true);
684 if ($providerKey ==
'INPUT')
686 switch ($valueInput[
'TYPE'])
690 $valueInput[
'OPTIONS'] = is_array($valueInput[
'OPTIONS'])
691 ? array(
'' =>
'') + $valueInput[
'OPTIONS']
699 $providerValue = Input\File::loadInfoSingle($providerValue);
701 $valueInput[
'CLASS'] =
'adm-designed-file';
705 case 'DATABASE_FILE':
706 $valueInput[
'CLASS'] =
'adm-designed-file';
713 if ($commonProviderInput
714 && $commonProviderValueInput
715 && ! $mappings[
'EXACT']
716 && ! $mappings[
'COMMON']
717 && $mappings[
'DEFAULT']
718 && $mappings[
'DEFAULT'] == self::correctMapping($commonProviderInput, $commonProviderValueInput, $mappings[
'DEFAULT']))
720 $mappings[
'COMMON'] = $mappings[
'DEFAULT'];
732 if (! $mappings[
'EXACT'] && $mappings[
'COMMON'])
733 $providerInput[
'DISABLED'] = $valueInput[
'DISABLED'] =
true;
738 Input\Manager::getEditHtml($inputNamePrefix.
'[PROVIDER_KEY]', $providerInput, $providerKey)
742 Input\Manager::getEditHtml($inputNamePrefix.
'[PROVIDER_VALUE]', $valueInput, $providerValue)
744 ?> </span><label <?=$mappings[
'COMMON'] ?
'' :
' style="display:none"'?>>
748 name=
"<?=$inputNamePrefix?>[DELETE]"'
749 <?if (! $mappings['EXACT
'] && $mappings['COMMON
']):?>
752 <?if ($m = $mappings['EXACT
']):?>
753 data-initial-key="<?=htmlspecialcharsbx($m['PROVIDER_KEY
'])?>"
754 data-initial-value="<?=htmlspecialcharsbx($m['PROVIDER_VALUE
'])?>"
756 <?if ($m = $mappings['COMMON
']):?>
757 data-default-key="<?=htmlspecialcharsbx($m['PROVIDER_KEY
'])?>"
758 data-default-value="<?=htmlspecialcharsbx($m['PROVIDER_VALUE
'])?>"
760 onclick="bizvalToggleDelete(this)">
763 return $providerValue; // $hideCode TODO
766 private static function correctMapping(array $providerInput, array $providerValueInput, array $mapping)
768 $key = $mapping['PROVIDER_KEY
'] ?? null;
769 $value = $mapping['PROVIDER_VALUE
'] ?? null;
772 !Input\Manager::getError($providerInput, $key)
773 && isset($providerValueInput[$key])
774 && !Input\Manager::getError($providerValueInput[$key], $value)
785 private static function renderScript()
795 function bizvalChangeProvider(keyElement, personTypeId, filterMode)
799 var providerKey = keyElement.options[keyElement.selectedIndex].value,
800 wrapElement = keyElement.parentNode.nextSibling,
801 name = wrapElement.firstChild.name,
802 personProviderValueInput = <?
804 $personProviderValueInput = self::$personProviderValueInput;
806 echo \CUtil::PhpToJSObject(
808 function () use ($personProviderValueInput)
810 foreach ($personProviderValueInput as &$providerFieldInput)
811 foreach ($providerFieldInput as &$fieldInput)
812 $fieldInput = Input\Manager::getEditHtml('', $fieldInput);
814 return $personProviderValueInput;
821 wrapElement.innerHTML = personProviderValueInput[personTypeId][providerKey];
822 wrapElement.firstChild.name = name;
827 bizvalChangeValue(wrapElement.firstChild);
830 return wrapElement.firstChild;
833 function bizvalToggleDelete(deleteElement)
837 var path = deleteElement.name.split('[
');
839 if (! (path.length == 6
841 && path[5] == 'DELETE]
'
844 // [ 0 ][ 1 ][ 2 ][ 3 ][4][ 5 ]
845 // mBizVal[MAP][1CC][ZIP][2][PROVIDER_VALUE]
847 var elements = deleteElement.parentNode.parentNode.parentNode.querySelectorAll('input, select, textarea
'), // TODO
848 i = 0, length = elements.length,
849 personTypeId = path[4].slice(0, -1);
851 if (personTypeId == '<?=BusinessValueTable::COMMON_PERSON_TYPE_ID?>
')
854 for (; i < length; ++i)
856 var keyElement = elements[i],
857 p = keyElement.name.split('[
');
860 && p[0] == path[0] && p[1] == path[1] && p[2] == path[2] && p[3] == path[3] && p[4] == path[4]
861 && p[5] == 'PROVIDER_KEY]
')
863 // note that, data-default.., must be set since checkbox only visible with default mapping!
865 var valueElement, key, val;
867 if (deleteElement.checked)
869 key = deleteElement.getAttribute('data-
default-key
');
870 val = deleteElement.getAttribute('data-
default-value
');
874 key = deleteElement.hasAttribute('data-initial-key
')
875 ? deleteElement.getAttribute('data-initial-key
')
876 : deleteElement.getAttribute('data-
default-key
');
877 val = deleteElement.hasAttribute('data-initial-value
')
878 ? deleteElement.getAttribute('data-initial-value
')
879 : deleteElement.getAttribute('data-
default-value
');
882 if (keyElement.value == 'INPUT
')
884 valueElement = keyElement.parentNode.nextSibling.firstChild;
886 if (valueElement.type == 'hidden
') // checkbox
888 valueElement = valueElement.nextSibling;
889 valueElement.checked = val;
893 valueElement.value = val;
898 keyElement.value = key;
899 valueElement = bizvalChangeProvider(keyElement, personTypeId, true);
900 valueElement.value = val;
903 keyElement.disabled = deleteElement.checked;
905 var parentElement = valueElement.parentNode;
906 var tagList = ['input
', 'select
', 'textarea
'];
907 for (var tagIndex in tagList)
909 if (tagList.hasOwnProperty(tagIndex))
911 var inputs = BX.findChildren(parentElement, {tag : tagList[tagIndex]}, true);
912 for (var k in inputs)
914 if (inputs.hasOwnProperty(k))
916 if (inputs[k].type != 'button
')
917 inputs[k].disabled = deleteElement.checked;
924 bizvalChangeValue(valueElement);
931 function bizvalChangeValue(valueElement)
935 var path = valueElement.name.split('[
');
937 if (! (path.length == 6
939 && path[5] == 'PROVIDER_VALUE]
'
940 && path[4] == '<?=BusinessValueTable::COMMON_PERSON_TYPE_ID?>]
'
943 // [ 0 ][ 1 ][ 2 ][ 3 ][4][ 5 ]
944 // mBizVal[MAP][1CC][ZIP][2][PROVIDER_VALUE]
946 var keyElement = valueElement.parentNode.previousSibling.firstChild, value,
947 elements = document.querySelectorAll('input, select, textarea
'), // TODO
948 i = 0, length = elements.length;
950 switch (valueElement.type)
952 case 'checkbox
': value = valueElement.checked ? 'true' : ''; break;
953 default: value = valueElement.value;
956 for (; i < length; ++i)
958 var de = elements[i],
959 p = de.name.split('[
');
962 && p[0] == path[0] && p[1] == path[1] && p[2] == path[2] && p[3] == path[3]
963 && p[4] != path[4] // self exclude
964 && p[5] == 'DELETE]
')
966 de.setAttribute('data-
default-key
', keyElement.value);
967 de.setAttribute('data-
default-value
', value);
969 var we = de.parentNode,
970 v = valueElement.type == 'checkbox
' ? we.previousSibling.firstChild.nextSibling.checked : we.previousSibling.firstChild.value;
974 if (de.checked || ! v)
977 bizvalToggleDelete(de);
980 we.style.display = 'inline';
987 bizvalToggleDelete(de);
990 we.style.display = 'none
';
996 function bizvalToggleRowsVisibility(anchor, className)
1002 if (anchor.rowsAreVisible)
1004 anchor.rowsAreVisible = false;
1010 anchor.rowsAreVisible = true;
1012 display = 'table-row
';
1015 var nodes = document.querySelectorAll('.
'+className), i, l = nodes.length;
1017 for (i = 0; i < l; i++)
1018 nodes[i].style.display = display;
1023 foreach (BusinessValue::getConsumers() as $consumerKey => $consumer)
1025 if (isset($consumer['GET_JAVASCRIPT
']) && is_callable($consumer['GET_JAVASCRIPT
']))
1027 echo call_user_func($consumer['GET_JAVASCRIPT
']);
1037 public static function getFilter($filter)
1041 ? array_intersect_key($filter, array('CODE_KEY
'=>1,'CONSUMER_KEY
'=>1,'PROVIDER_KEY
'=>1,'PROVIDER_VALUE
'=>1))
1045 if (self::$consumerInput['OPTIONS
'])
1047 $value = $filter['CONSUMER_KEY
'] ?? null;
1048 $filter['CONSUMER_KEY
'] =
1049 ! Input\Manager::getError(self::$consumerInput, $value)
1050 ? Input\Manager::getValue(self::$consumerInput, $value)
1051 : key(self::$consumerInput['OPTIONS
']) // REQUIRED
1055 if (is_array(self::$consumerCodeInput[$filter['CONSUMER_KEY
']]))
1057 $value = $filter['CODE_KEY
'] ?? null;
1058 $filter['CODE_KEY
'] =
1059 ! Input\Manager::getError(self::$consumerCodeInput[$filter['CONSUMER_KEY
']], $value)
1060 ? Input\Manager::getValue(self::$consumerCodeInput[$filter['CONSUMER_KEY
']], $value)
1066 // TODO null - personTypeId
1067 $value = $filter['PROVIDER_KEY
'] ?? null;
1068 $filter['PROVIDER_KEY
'] =
1069 ! Input\Manager::getError(self::$personProviderInput[null], $value)
1070 ? Input\Manager::getValue(self::$personProviderInput[null], $value)
1073 // TODO null - personTypeId
1074 $value = $filter['PROVIDER_VALUE
'] ?? null;
1075 $filter['PROVIDER_VALUE
'] = $filter['PROVIDER_KEY
']
1076 && ! Input\Manager::getError(self::$personProviderValueInput[null][$filter['PROVIDER_KEY
']], $value)
1077 ? Input\Manager::getValue(self::$personProviderValueInput[null][$filter['PROVIDER_KEY
']], $value)
1085 private static $personTypes;
1086 private static $personProviderInput, $personProviderValueInput;
1087 private static $groups, $consumerInput, $consumerCodeInput;
1090 public static function initialize()
1092 self::$personTypes = array('
' => array('DOMAIN
' => '', 'TITLE
' => Loc::getMessage('BIZVAL_DOMAIN_COMMON
'))) + BusinessValue::getPersonTypes();
1094 list (self::$personProviderInput, self::$personProviderValueInput) = self::getProviderInputs(BusinessValue::getProviders(), self::$personTypes);
1096 self::$groups = array('' => array()) + BusinessValue::getGroups();
1098 list (self::$consumerInput, self::$consumerCodeInput) = self::getConsumerInputs(BusinessValue::getConsumers(), self::$groups);
1102 public static function getProviderInput($personTypeId, array $providerKeys = null)
1104 $providerInput = self::$personProviderInput[$personTypeId];
1106 if ($providerKeys && is_array($providerInput['OPTIONS
']))
1107 $providerInput['OPTIONS
'] = array_intersect_key($providerInput['OPTIONS
'], array_flip($providerKeys));
1109 return $providerInput;
1113 public static function getValueInput($personTypeId, $providerKey = null)
1116 ? self::$personProviderValueInput[$personTypeId][$providerKey]
1117 : self::$personProviderValueInput[$personTypeId];
1121 public static function getConsumerInput()
1123 return self::$consumerInput;
1127 public static function getConsumerCodeInput()
1129 return self::$consumerCodeInput;
1132 private static function getProviderInputs(array $providers, array $personTypes)
1134 $personProviderInput = $personProviderValueInput = array();
1136 $onChange = "bizvalChangeValue(this)";
1138 foreach ($personTypes as $personTypeId => $personType)
1140 $providerOptions = array();
1142 foreach ($providers as $providerKey => $provider)
1144 if (isset($provider['INPUT
']) && is_array($provider['INPUT
']))
1146 $provider['INPUT
']['REQUIRED
'] = true;
1147 $provider['INPUT
']['ONCHANGE
'] = $onChange;
1149 $providerOptions[$providerKey] = $provider['NAME
'] ?? $providerKey;
1150 $personProviderValueInput[$personTypeId][$providerKey] = $provider['INPUT
'];
1152 elseif (isset($provider['FIELDS
']) && is_array($provider['FIELDS
']))
1154 $fields = $provider['FIELDS
'];
1155 $fieldOptions = array();
1158 foreach ($fields as $fieldKey => $field)
1162 && (empty($field['PERSON_TYPE_ID
']) || $field['PERSON_TYPE_ID
'] == $personTypeId)
1165 $group = $field['GROUP
'] ?? null; // null is GENERAL
1166 $fieldOptions[$group][$fieldKey] = $field['NAME
'] ?? $fieldKey;
1170 if (count($fieldOptions) == 1)
1172 $fieldOptions = reset($fieldOptions);
1174 elseif (is_array($provider['FIELDS_GROUPS
']))
1176 self::sortRenameGroups($fieldOptions, $provider['FIELDS_GROUPS
']);
1179 if (! empty($fieldOptions))
1181 $providerOptions[$providerKey] = $provider['NAME
'] ?? $providerKey;
1182 $personProviderValueInput[$personTypeId][$providerKey] = array('TYPE
' => 'ENUM
', 'OPTIONS
' => $fieldOptions, 'ONCHANGE
' => $onChange);
1187 $providerOptions[$providerKey] = $provider['NAME
'] ?? $providerKey;
1188 $personProviderValueInput[$personTypeId][$providerKey] = array('TYPE
' => 'STRING
', 'SIZE
' => 30, 'ONCHANGE
' => $onChange);
1192 $personProviderValueInput[$personTypeId][''] = array('TYPE
' => 'STRING
', 'SIZE
' => 30); // for filter only
1194 if ($providerOptions)
1196 $personProviderInput[$personTypeId] = array(
1198 'OPTIONS
' => $providerOptions,
1200 'ONCHANGE
' => "bizvalChangeProvider(this, '".$personTypeId."')",
1205 return array($personProviderInput, $personProviderValueInput);
1208 private static function getConsumerInputs(array $consumers, array $groups)
1210 $consumerInput = array(
1215 $consumerCodeInput = array();
1217 $consumerOptions = array();
1219 foreach ($consumers as $consumerKey => $consumer)
1221 if (is_array($consumer) && isset($consumer['CODES
']) && is_array($consumer['CODES
']))
1223 $consumerCodes = $consumer['CODES
'];
1224 $consumerGroup = $consumer['GROUP
'] ?? null; // null is GENERAL
1226 $consumerOptions[$consumerGroup][$consumerKey] = $consumer['NAME
'] ?? $consumerKey;
1228 $codeOptions = array();
1230 foreach ($consumerCodes as $codeKey => $code)
1232 if (is_array($code) && isset($code['GROUP
']))
1234 $codeOptions[$code['GROUP
']][$codeKey] = $code['NAME
'] ?? $codeKey;
1238 if (count($codeOptions) == 1)
1240 $codeOptions = reset($codeOptions);
1244 self::sortRenameGroups($codeOptions, $groups, true);
1247 $consumerCodeInput[$consumerKey] = array(
1249 'OPTIONS
' => array('' => Loc::getMessage('BIZVAL_PAGE_ALL
')) + $codeOptions,
1254 if ($consumerOptions)
1256 self::sortRenameGroups($consumerOptions, $groups, true);
1257 $consumerInput['OPTIONS
'] = $consumerOptions;
1260 return array($consumerInput, $consumerCodeInput);
1263 private static function sortRenameGroups(array &$groupedItems, array $groups, $flattenEmptyGroup = false)
1265 $sortedItems = array();
1267 if ($flattenEmptyGroup && isset($groupedItems['']))
1269 $sortedItems = $groupedItems[''];
1270 unset($groupedItems['']);
1273 foreach ($groups as $groupKey => $group)
1275 if (is_array($group) && isset($groupedItems[$groupKey]))
1277 $sortedItems[$group['NAME
'] ?? $groupKey] = $groupedItems[$groupKey];
1278 unset($groupedItems[$groupKey]);
1282 $groupedItems = $sortedItems + $groupedItems;
1286BusinessValueControl::initialize();
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)