Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
bb7d8af290
469 files changed
+26426
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jinove\Vinoteca\Personal;
|
||||
|
||||
use Bitrix\Iblock\Iblock;
|
||||
use Bitrix\Main\Loader;
|
||||
use Jinove\Vinoteca\Catalog\Related;
|
||||
use Jinove\Vinoteca\Catalog\ReviewStats;
|
||||
|
||||
class Reviews
|
||||
{
|
||||
private const LIMIT = 100;
|
||||
|
||||
public static function forUser(int $userId): array
|
||||
{
|
||||
$reviewsId = ReviewStats::iblockId(ReviewStats::REVIEWS_CODE);
|
||||
if ($userId <= 0 || $reviewsId <= 0 || !Loader::includeModule("iblock")) {
|
||||
return [];
|
||||
}
|
||||
$table = Iblock::wakeUp($reviewsId)->getEntityDataClass();
|
||||
if ($table === null) {
|
||||
return [];
|
||||
}
|
||||
$rows = $table::getList([
|
||||
"select" => ["ID", "ACTIVE", "PREVIEW_TEXT", "ACTIVE_FROM", "DATE_CREATE", "PRODUCT_" => "PRODUCT", "RATING_" => "RATING"],
|
||||
"filter" => ["=USER_ID.VALUE" => $userId],
|
||||
"order" => ["ACTIVE_FROM" => "DESC", "ID" => "DESC"],
|
||||
"limit" => self::LIMIT,
|
||||
])->fetchAll();
|
||||
$items = [];
|
||||
foreach ($rows as $row) {
|
||||
$date = $row["ACTIVE_FROM"] ?: $row["DATE_CREATE"];
|
||||
$items[] = [
|
||||
"product" => (int)$row["PRODUCT_VALUE"],
|
||||
"rating" => max(0, min(5, (int)$row["RATING_VALUE"])),
|
||||
"text" => trim((string)preg_replace('/\s+/u', " ", strip_tags((string)$row["PREVIEW_TEXT"]))),
|
||||
"date" => $date instanceof \Bitrix\Main\Type\DateTime ? $date->getTimestamp() : 0,
|
||||
"published" => $row["ACTIVE"] === "Y",
|
||||
];
|
||||
}
|
||||
$products = Related::summariesById(array_column($items, "product"));
|
||||
foreach ($items as $key => $item) {
|
||||
$items[$key]["name"] = $products[$item["product"]]["name"] ?? "";
|
||||
$items[$key]["url"] = $products[$item["product"]]["url"] ?? "";
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user