Пример #1
0
	public static function getTreePropertyValues(&$propList, &$propNeedValues)
	{
		$result = array();
		if (!empty($propList) && is_array($propList))
		{
			foreach ($propList as $oneProperty)
			{
				$values = array();
				$valuesExist = false;
				$pictMode = ('PICT' == $oneProperty['SHOW_MODE']);
				$needValuesExist = isset($propNeedValues[$oneProperty['ID']]) && !empty($propNeedValues[$oneProperty['ID']]);
				$filterValuesExist = ($needValuesExist && count($propNeedValues[$oneProperty['ID']]) <= 100);
				if ('L' == $oneProperty['PROPERTY_TYPE'])
				{
					$propEnums = CIBlockProperty::GetPropertyEnum(
						$oneProperty['ID'],
						array('SORT' => 'ASC', 'VALUE' => 'ASC')
					);
					while ($oneEnum = $propEnums->Fetch())
					{
						$oneEnum['ID'] = intval($oneEnum['ID']);
						if ($needValuesExist && !isset($propNeedValues[$oneProperty['ID']][$oneEnum['ID']]))
							continue;
						$values[$oneEnum['ID']] = array(
							'ID' => $oneEnum['ID'],
							'NAME' => $oneEnum['VALUE'],
							'SORT' => intval($oneEnum['SORT']),
							'PICT' => false
						);
						$valuesExist = true;
					}
					$values[0] = array(
						'ID' => 0,
						'SORT' => PHP_INT_MAX,
						'NA' => true,
						'NAME' => $oneProperty['DEFAULT_VALUES']['NAME'],
						'PICT' => $oneProperty['DEFAULT_VALUES']['PICT']
					);
				}
				elseif ('E' == $oneProperty['PROPERTY_TYPE'])
				{
					$selectFields = array('ID', 'NAME');
					if ($pictMode)
						$selectFields[] = 'PREVIEW_PICTURE';
					$filterValues = (
						$filterValuesExist
						? array('ID' => $propNeedValues[$oneProperty['ID']], 'IBLOCK_ID' => $oneProperty['LINK_IBLOCK_ID'], 'ACTIVE' => 'Y')
						: array('IBLOCK_ID' => $oneProperty['LINK_IBLOCK_ID'], 'ACTIVE' => 'Y')
					);
					$propEnums = CIBlockElement::GetList(
						array('SORT' => 'ASC', 'NAME' => 'ASC'),
						$filterValues,
						false,
						false,
						$selectFields
					);
					while ($oneEnum = $propEnums->Fetch())
					{
						if ($needValuesExist && !$filterValuesExist)
						{
							if (!isset($propNeedValues[$oneProperty['ID']][$oneEnum['ID']]))
								continue;
						}
						if ($pictMode)
						{
							$oneEnum['PICT'] = false;
							if (!empty($oneEnum['PREVIEW_PICTURE']))
							{
								$previewPict = CFile::GetFileArray($oneEnum['PREVIEW_PICTURE']);
								if (!empty($previewPict))
								{
									$oneEnum['PICT'] = array(
										'SRC' => $previewPict['SRC'],
										'WIDTH' => intval($previewPict['WIDTH']),
										'HEIGHT' => intval($previewPict['HEIGHT'])
									);
								}
							}
							if (empty($oneEnum['PICT']))
							{
								$oneEnum['PICT'] = $oneProperty['DEFAULT_VALUES']['PICT'];
							}
						}
						$oneEnum['ID'] = intval($oneEnum['ID']);
						$values[$oneEnum['ID']] = array(
							'ID' => $oneEnum['ID'],
							'NAME' => $oneEnum['NAME'],
							'SORT' => intval($oneEnum['SORT']),
							'PICT' => ($pictMode ? $oneEnum['PICT'] : false)
						);
						$valuesExist = true;
					}
					$values[0] = array(
						'ID' => 0,
						'SORT' => PHP_INT_MAX,
						'NA' => true,
						'NAME' => $oneProperty['DEFAULT_VALUES']['NAME'],
						'PICT' => ($pictMode ? $oneProperty['DEFAULT_VALUES']['PICT'] : false)
					);
				}
				else
				{
					if (null === self::$highLoadInclude)
						self::$highLoadInclude = \Freetrix\Main\Loader::includeModule('highloadblock');
					if (!self::$highLoadInclude)
						continue;
					$xmlMap = array();
					$sortExist = isset($oneProperty['USER_TYPE_SETTINGS']['FIELDS_MAP']['UF_SORT']);

					$directorySelect = array('ID', 'UF_NAME', 'UF_XML_ID');
					$directoryOrder = array();
					if ($pictMode)
					{
						$directorySelect[] = 'UF_FILE';
					}
					if ($sortExist)
					{
						$directorySelect[] = 'UF_SORT';
						$directoryOrder['UF_SORT'] = 'ASC';
					}
					$directoryOrder['UF_NAME'] = 'ASC';
					$sortValue = 100;

					$entityDataClass = $oneProperty['USER_TYPE_SETTINGS']['ENTITY']->getDataClass();
					$entityGetList = array(
						'select' => $directorySelect,
						'order' => $directoryOrder
					);
					if ($filterValuesExist)
						$entityGetList['filter'] = array('=UF_XML_ID' => $propNeedValues[$oneProperty['ID']]);
					$propEnums = $entityDataClass::getList($entityGetList);
					while ($oneEnum = $propEnums->fetch())
					{
						$oneEnum['ID'] = intval($oneEnum['ID']);
						$oneEnum['UF_SORT'] = ($sortExist ? intval($oneEnum['UF_SORT']) : $sortValue);
						$sortValue += 100;

						if ($pictMode)
						{
							if (!empty($oneEnum['UF_FILE']))
							{
								$arFile = CFile::GetFileArray($oneEnum['UF_FILE']);
								if (!empty($arFile))
								{
									$oneEnum['PICT'] = array(
										'SRC' => $arFile['SRC'],
										'WIDTH' => intval($arFile['WIDTH']),
										'HEIGHT' => intval($arFile['HEIGHT'])
									);
								}
							}
							if (empty($oneEnum['PICT']))
								$oneEnum['PICT'] = $oneProperty['DEFAULT_VALUES']['PICT'];
						}
						$values[$oneEnum['ID']] = array(
							'ID' => $oneEnum['ID'],
							'NAME' => $oneEnum['UF_NAME'],
							'SORT' => intval($oneEnum['UF_SORT']),
							'XML_ID' => $oneEnum['UF_XML_ID'],
							'PICT' => ($pictMode ? $oneEnum['PICT'] : false)
						);
						$valuesExist = true;
						$xmlMap[$oneEnum['UF_XML_ID']] = $oneEnum['ID'];
					}
					$values[0] = array(
						'ID' => 0,
						'SORT' => PHP_INT_MAX,
						'NA' => true,
						'NAME' => $oneProperty['DEFAULT_VALUES']['NAME'],
						'XML_ID' => '',
						'PICT' => ($pictMode ? $oneProperty['DEFAULT_VALUES']['PICT'] : false)
					);
					if ($valuesExist)
						$oneProperty['XML_MAP'] = $xmlMap;
				}
				if (!$valuesExist)
					continue;
				$oneProperty['VALUES'] = $values;
				$oneProperty['VALUES_COUNT'] = count($values);

				$result[$oneProperty['CODE']] = $oneProperty;
			}
		}
		$propList = $result;
		unset($arFilterProp);
	}