• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/component/selector/element.php
  • Класс: BitrixIblockComponentSelectorElement
  • Вызов: Element::getData
protected function getData()
{
	Loader::includeModule('fileman');

	$this->rows = [];

	$listImageSize = MainConfigOption::get('iblock', 'list_image_size');
	$minImageSize = ['W' => 1, 'H' => 1];
	$maxImageSize = ['W' => $listImageSize, 'H' => $listImageSize];
	unset($listImageSize);

	$binaryStates = $this->getBinaryDictionary();

	$allowedSets = CatalogConfigFeature::isProductSetsEnabled();

	$this->loadElementPropertiesDescription();

	$viewedColumns = $this->getDataFields();
	$selectedFields = [];
	$selectedProperties = [];
	foreach ($viewedColumns as $columnId)
	{
		if (strncmp($columnId, 'PROPERTY_', 9) == 0)
		{
			if (isset($this->elementProperties[$columnId]))
			{
				$selectedProperties[] = $this->elementProperties[$columnId]['ID'];
			}
		}
		else
		{
			$selectedFields[] = $columnId;
			if ($columnId == 'TYPE')
				$selectedFields[] = 'BUNDLE';
		}
	}
	unset($columnId);
	if (!in_array('ID', $selectedFields))
		$selectedFields[] = 'ID';

	$viewedColumns = array_fill_keys($viewedColumns, true);

	$iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID');
	$needProperties = $iblockId > 0 && !empty($selectedProperties);

	$productTypeList = [];
	if ($this->catalogIncluded)
		$productTypeList = CatalogProductTable::getProductTypes(true);

	$listIds = [];

	$iterator = CIBlockElement::GetList(
		$this->getDataOrder(),
		$this->getDataFilter(),
		false,
		$this->getGridNavigationParams(),
		$selectedFields
	);
	$iterator->bShowAll = false;
	while ($row = $iterator->Fetch())
	{
		$row['ID'] = (int)$row['ID'];

		if (isset($viewedColumns['ACTIVE']))
			$row['ACTIVE'] = ($row['ACTIVE'] == 'Y' ? $binaryStates['Y'] : $binaryStates['N']);
		if (isset($viewedColumns['NAME']))
			$row['NAME'] = htmlspecialcharsEx((string)$row['NAME']);
		if (isset($viewedColumns['SORT']))
			$row['SORT'] = (int)$row['SORT'];
		if (isset($viewedColumns['CODE']))
			$row['CODE'] = htmlspecialcharsbx((string)$row['CODE']);
		if (isset($viewedColumns['XML_ID']))
			$row['XML_ID'] = htmlspecialcharsbx((string)$row['XML_ID']);
		if (isset($viewedColumns['ACTIVE_FROM']))
			$row['ACTIVE_FROM'] = htmlspecialcharsbx((string)$row['ACTIVE_FROM']);
		if (isset($viewedColumns['ACTIVE_TO']))
			$row['ACTIVE_TO'] = htmlspecialcharsbx((string)$row['ACTIVE_TO']);

		if (isset($viewedColumns['TYPE']))
		{
			if ($row['TYPE'] === null)
			{
				$row['TYPE'] = Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_MESS_IS_NOT_PRODUCT');
			}
			else
			{
				$productType = (int)$row['TYPE'];
				if (isset($productTypeList[$productType]))
				{
					$row['TYPE'] = $productTypeList[$productType];
				}
				else
				{
					$row['TYPE'] = Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_MESS_BAD_PRODUCT_TYPE');
				}
				if ($allowedSets && $row['BUNDLE'] == 'Y')
				{
					$row['TYPE'] = Loc::getMessage(
						'IBLOCK_SELECTOR_ELEMENT_MESS_TYPE_DESCRIPTION',
						['#TYPE#' => $row['TYPE']]
					);
				}
			}
			unset($row['BUNDLE']);
		}
		if (isset($viewedColumns['AVAILABLE']))
			$row['AVAILABLE'] = ($row['AVAILABLE'] == 'Y' ? $binaryStates['Y'] : $binaryStates['N']);

		if ($needProperties)
			$row['PROPERTIES'] = [];
		$this->rows[$row['ID']] = $row;
		$listIds[] = $row['ID'];
	}
	unset($row);

	if (!empty($this->rows) && $needProperties)
	{
		CIBlockElement::GetPropertyValuesArray(
			$this->rows,
			$iblockId,
			['ID' => $listIds],
			['ID' => $selectedProperties],
			[
				'USE_PROPERTY_ID' => 'Y',
				'PROPERTY_FIELDS' => ['ID'],
				'GET_RAW_DATA' => 'Y'
			]
		);

		$elementCache = [];
		$sectionCache = [];

		foreach ($listIds as $id)
		{
			foreach ($selectedProperties as $propertyId)
			{
				$viewedValue = '';
				$index = 'PROPERTY_'.$propertyId;
				if (isset($this->rows[$id]['PROPERTIES'][$propertyId]))
				{
					$property = $this->elementProperties[$index];
					$value = $this->rows[$id]['PROPERTIES'][$propertyId];
					$complexValue = is_array($value['VALUE']);
					if (
						($complexValue && !empty($value['VALUE']))
						|| (!$complexValue && (string)$value['VALUE'] !== '')
					)
					{
						$direct = false;
						$assembly = [];
						$userType = $property['PROPERTY_USER_TYPE'];
						if (isset($userType['GetAdminListViewHTML']))
						{
							$rawValue = $value['VALUE'];
							if ($property['MULTIPLE'] == 'N' || !$complexValue)
								$rawValue = [$rawValue];
							foreach ($rawValue as $item)
							{
								$itemValue = (string)call_user_func_array(
									$userType['GetAdminListViewHTML'],
									[
										$property,
										[
											'VALUE' => $item,
											'DESCRIPTION' => ''
										],
										[
											'MODE' => 'iblock_element_admin',
											'FORM_NAME' => ''
										]
									]
								);
								if ($itemValue !== '')
									$assembly[] = $itemValue;
							}
						}
						else
						{
							$rawValue = $value['VALUE'];
							if (!$complexValue)
								$rawValue = [$rawValue];

							switch ($this->elementProperties[$index]['PROPERTY_TYPE'])
							{
								case IblockPropertyTable::TYPE_STRING:
								case IblockPropertyTable::TYPE_NUMBER:
								case IblockPropertyTable::TYPE_LIST:
									$assembly = $rawValue;
									break;
								case IblockPropertyTable::TYPE_ELEMENT:
									foreach ($rawValue as $item)
									{
										if (!isset($elementCache[$item]))
										{
											$elementCache[$item] = '';
											$valueIterator = IblockElementTable::getList([
												'select' => ['ID', 'NAME'],
												'filter' => ['=ID' => $item]
											]);
											$valueRow = $valueIterator->fetch();
											if (!empty($valueRow))
												$elementCache[$item] = '['.$valueRow['ID'].'] '.$valueRow['NAME'];
											unset($valueRow, $valueIterator);
										}
										if ($elementCache[$item] !== '')
											$assembly[] = $elementCache[$item];
									}
									break;
								case IblockPropertyTable::TYPE_SECTION:
									foreach ($rawValue as $item)
									{
										if (!isset($sectionCache[$item]))
										{
											$sectionCache[$item] = '';
											$valueIterator = IblockSectionTable::getList([
												'select' => ['ID', 'NAME'],
												'filter' => ['=ID' => $item]
											]);
											$valueRow = $valueIterator->fetch();
											if (!empty($valueRow))
												$sectionCache[$item] = '['.$valueRow['ID'].'] '.$valueRow['NAME'];
											unset($valueRow, $valueIterator);
										}
										if ($sectionCache[$item] !== '')
											$assembly[] = $sectionCache[$item];
									}
									break;
								case IblockPropertyTable::TYPE_FILE:
									$direct = true;
									/*										$fileInputParams = [
																				'edit' => false,
																				'description' => true,
																				'upload' => false,
																				'medialib' => false,
																				'fileDialog' => false,
																				'cloud' => false,
																				'delete' => false,
																			];
																			if ($property['MULTIPLE'] == 'Y')
																			{
																				$fileInputParams['name'] = $index.'[#IND#]';
																			}
																			else
																			{
																				$fileInputParams['name'] = $index;
																				$fileInputParams['maxCount'] = 1;
																				$rawValue = reset($rawValue);
																			}
																			$assembly = UIFileInput::createInstance($fileInputParams)->show(
																				$rawValue,
																				false
																			);
																			unset($fileInputParams); */
									$fileInputParams = [
										'upload' => false,
										'medialib' => false,
										'file_dialog' => false,
										'cloud' => false,
										'del' => false,
										'description' => false
									];
									$fileOptions = [
										'IMAGE' => 'Y',
										'PATH' => 'N',
										'FILE_SIZE' => 'N',
										'DIMENSIONS' => 'N',
										'IMAGE_POPUP' => 'Y',
										'MAX_SIZE' => $maxImageSize,
										'MIN_SIZE' => $minImageSize,
									];
									if ($property['MULTIPLE'] == 'Y')
									{
										$assembly = CFileInput::ShowMultiple(
											$rawValue,
											$index.'[#IND#]',
											$fileOptions,
											false,
											$fileInputParams
										);
									}
									else
									{
										$rawValue = reset($rawValue);
										$assembly = CFileInput::Show(
											$index,
											$rawValue,
											$fileOptions,
											$fileInputParams
										);
									}
									break;
							}
						}
						if (!empty($assembly))
						{
							$viewedValue = ($direct ? $assembly : htmlspecialcharsbx(implode(' / ', $assembly)));
						}
						unset($direct, $assembly);
					}
				}
				$this->rows[$id][$index] = $viewedValue;
				unset($viewedValue);
			}
			unset($this->rows[$id]['PROPERTIES']);
		}

		unset($sectionCache, $elementCache);
	}
	if (!empty($this->rows))
		$this->rows = array_values($this->rows);

	$this->setImplicitNavigationData($iterator);
	unset($iterator);
}