Vinoteca: wine shop on 1C-Bitrix (module, template, components, pages)
This commit is contained in:
commit
52795535ae
586 files changed
+27619
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jinove\Vinoteca\Catalog;
|
||||
|
||||
use Bitrix\Iblock\ElementTable;
|
||||
use Bitrix\Main\Loader;
|
||||
|
||||
final class Media
|
||||
{
|
||||
public static function thumbs(array $productIds, int $width, int $height): array
|
||||
{
|
||||
$productIds = array_values(array_unique(array_filter(array_map("intval", $productIds))));
|
||||
if (!$productIds || !Loader::includeModule("iblock")) {
|
||||
return [];
|
||||
}
|
||||
$images = [];
|
||||
$rows = ElementTable::getList(["select" => ["ID", "PREVIEW_PICTURE", "DETAIL_PICTURE"], "filter" => ["=ID" => $productIds]]);
|
||||
while ($row = $rows->fetch()) {
|
||||
$fileId = (int)($row["DETAIL_PICTURE"] ?: $row["PREVIEW_PICTURE"]);
|
||||
if ($fileId > 0) {
|
||||
$resized = \CFile::ResizeImageGet($fileId, ["width" => $width, "height" => $height], BX_RESIZE_IMAGE_PROPORTIONAL, false);
|
||||
if (!empty($resized["src"])) {
|
||||
$images[(int)$row["ID"]] = (string)$resized["src"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user