• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/landingsource/dataloader.php
  • Класс: BitrixIblockLandingSourceDataLoader
  • Вызов: DataLoader::getElementsInternal
private function getElementsInternal(array $settings)
	{
		$result = [];

		$iterator = CIBlockElement::GetList(
			$settings['order'],
			$settings['filter'],
			false,
			($settings['limit'] > 0 ? ['nTopCount' => $settings['limit']] : false),
			$settings['element']
		);
		if (!empty($settings['templates']['detailPageUrl']))
			$iterator->SetUrlTemplates($settings['templates']['detailPageUrl']);

		$needPreview = in_array('PREVIEW_PICTURE', $settings['element']);
		$needDetailPicture = in_array('DETAIL_PICTURE', $settings['element']);

		$loadSeo = ($needPreview || $needDetailPicture || $settings['loadSeo']);

		if (!empty($settings['element_properties']))
		{
			$settings['element_properties'] = $this->getAllowedPropertyId(
				$settings['filter']['IBLOCK_ID'],
				$settings['element_properties'],
				($settings['mode'] == 'list'
					? IblockModelPropertyFeature::FEATURE_ID_LIST_PAGE_SHOW
					: IblockModelPropertyFeature::FEATURE_ID_DETAIL_PAGE_SHOW
				)
			);
		}

		while ($row = $iterator->GetNext())
		{
			$id = (int)$row['ID'];
			if ($loadSeo)
			{
				IblockInheritedPropertyElementValues::queue($row['IBLOCK_ID'], $row['ID']);
			}

			$row['PROPERTIES'] = [];

			$result[$id] = $row;
		}
		unset($row, $iterator);

		if (!empty($result))
		{
			$needDiscountCache = false;
			if ($this->catalogIncluded && $settings['prices'])
			{
				$needDiscountCache = CIBlockPriceTools::SetCatalogDiscountCache(
					$this->getPriceTypes(),
					$this->getUserGroups()
				);
			}
			$loadProperties = (!empty($settings['element_properties']) || $needDiscountCache);
			if ($loadProperties)
			{
				$propertyFilter = [];
				if (!$needDiscountCache)
				{
					$propertyFilter = ['ID' => $settings['element_properties']];
				}

				CIBlockElement::GetPropertyValuesArray(
					$result,
					$settings['filter']['IBLOCK_ID'],
					['ID' => array_keys($result)],
					$propertyFilter,
					['USE_PROPERTY_ID' => 'Y']
				);
				unset($propertyFilter);
			}
			if ($needDiscountCache)
			{
				$elementIds = array_keys($result);
				foreach ($elementIds as $itemId)
				{
					CCatalogDiscount::SetProductPropertiesCache($itemId, $result[$itemId]['PROPERTIES']);
				}
				CatalogDiscountDiscountManager::preloadPriceData($elementIds, $this->getPriceTypes());
				CatalogDiscountDiscountManager::preloadProductDataToExtendOrder($elementIds, $this->getUserGroups());
				CCatalogDiscount::SetProductSectionsCache($elementIds);
			}

			foreach ($result as &$row)
			{
				if ($loadSeo)
				{
					$ipropValues = new IblockInheritedPropertyElementValues($row['IBLOCK_ID'], $row['ID']);
					$row['IPROPERTY_VALUES'] = $ipropValues->getValues();
				}
				if ($needPreview || $needDetailPicture)
				{
					IblockComponentTools::getFieldImageData(
						$row,
						['PREVIEW_PICTURE', 'DETAIL_PICTURE'],
						IblockComponentTools::IPROPERTY_ENTITY_ELEMENT,
						'IPROPERTY_VALUES'
					);
					if ($needPreview)
					{
						if (!empty($row['PREVIEW_PICTURE']))
						{
							$row['PREVIEW_PICTURE'] = [
								'src' => $row['PREVIEW_PICTURE']['SRC'],
								'alt' => $row['PREVIEW_PICTURE']['ALT'],
							];
						}
					}
					if ($needDetailPicture)
					{
						if (!empty($row['DETAIL_PICTURE']))
						{
							$row['DETAIL_PICTURE'] = [
								'src' => $row['DETAIL_PICTURE']['SRC'],
								'alt' => $row['DETAIL_PICTURE']['ALT'],
							];
						}
					}
				}

				if (!empty($settings['element_properties']))
				{
					foreach ($settings['element_properties'] as $propertyId)
					{
						$row['PROPERTY_'.$propertyId] = null;
						if (isset($row['PROPERTIES'][$propertyId]))
						{
							$row['PROPERTY_'.$propertyId] = self::getPropertyValue($row['PROPERTIES'][$propertyId]);
						}
					}
					unset($propertyId);
				}
				unset($row['PROPERTIES']);

				if ($settings['prices'])
				{
					$row['PRICE'] = null;
					$row['SORT_ORDER'] = null;
				}

				if ($settings['loadSeo'])
				{
					$this->fillElementSeo($row);
				}

				if ($loadSeo)
				{
					unset($row['IPROPERTY_VALUES']);
					unset($ipropValues);
				}
			}
			unset($row);

			if ($this->catalogIncluded)
			{
				if (!empty($settings['product']))
				{
					self::loadProduct($result, $settings['product']);
				}

				if ($settings['prices'])
				{
					$this->loadPrices($result);
					if (!empty($settings['sortByPrice']))
					{
						$sortPrice = mb_strtoupper($settings['sortByPrice']);
						$sortPrice = ($sortPrice === 'ASC' ? SORT_ASC : SORT_DESC);
						MainTypeCollection::sortByColumn($result, ['SORT_ORDER' => $sortPrice]);
					}
					foreach ($result as &$item)
					{
						unset($item['SORT_ORDER']);
					}
				}
				if ($needDiscountCache)
				{
					CCatalogDiscount::ClearDiscountCache(array(
						'PRODUCT' => true,
						'SECTIONS' => true,
						'PROPERTIES' => true
					));
				}
			}
		}

		return $result;
	}