• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/photoresizer.php
  • Класс: BitrixSaleTradingPlatformVkPhotoResizer
  • Вызов: PhotoResizer::sortPhotoArray
static function sortPhotoArray($photos, $type)
{
	$sortedPhotos = array();
	
	switch ($type)
	{
		case 'PRODUCT':
			$count = Vk::MAX_PHOTOS_IN_PRODUCT;
//				todo: for photos we must ALWAYS set VK-field in first places
			break;
		
		case 'ALBUM':
			$count = Vk::MAX_PHOTOS_IN_ALBUM;
			break;
		
		default:
			return $photos;
	}
	
//		match sizes of photos. Key of array - sum of width and height
	$photosSizes = array();
	foreach($photos as $photo)
	{
//			photo may be not set
		if($photo)
		{
			$sizes = CFile::GetFileArray($photo);
			$photosSizes[$sizes['HEIGHT'] + $sizes['WIDTH']] = array(
				'PHOTO_ID' => $photo,
				'SIZES_SUM' => $sizes['HEIGHT'] + $sizes['WIDTH']
			);
		}
	}
	krsort($photosSizes);
	
//		get elements from sorted sizes until not catch count
	while(count($sortedPhotos) < $count)
	{
		$biggestPhoto = current($photosSizes);
		$sortedPhotos[$biggestPhoto['PHOTO_ID']] = $biggestPhoto['PHOTO_ID'];
		unset($photosSizes[$biggestPhoto['SIZES_SUM']]);
	}
	
	return $sortedPhotos;
}