Files

88 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
use Bitrix\Iblock\ElementTable;
use Bitrix\Main\Application;
use Bitrix\Main\Data\Cache;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\DI\ServiceLocator;
use Jinove\Vinoteca\Catalog\MegaMenu;
use Jinove\Vinoteca\Config;
use Jinove\Vinoteca\PageSchema;
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
die();
}
Loc::loadMessages(__FILE__);
class JinoveAboutComponent extends CBitrixComponent
{
private const CACHE_TTL = 86400;
private const CACHE_DIR = "/jinove.vinoteca/about";
private const MAP_ADDRESS = "Краснодар, улица Красная, 251";
private const MAP_LAT = 45.0508;
private const MAP_LON = 38.9803;
private const MAP_ZOOM = 15;
public function executeComponent(): array
{
global $APPLICATION;
$title = (string)Loc::getMessage("VINO_ABOUT_TITLE");
$APPLICATION->SetTitle($title);
$APPLICATION->SetPageProperty("title", (string)Loc::getMessage("VINO_ABOUT_BROWSER_TITLE"));
$APPLICATION->SetPageProperty("description", (string)Loc::getMessage("VINO_ABOUT_DESCRIPTION"));
$contacts = Config::contacts();
$counts = $this->counts();
$this->arResult = [
"TITLE" => $title,
"WINES" => $counts["wines"],
"BRANDS" => $counts["brands"],
"TYPES" => $counts["types"],
"PHONE" => (string)($contacts["phone"] ?? ""),
"PHONE_LABEL" => (string)($contacts["phoneLabel"] ?? ""),
"EMAIL" => (string)($contacts["email"] ?? ""),
"MAP_URL" => "https://yandex.ru/maps/?text=" . rawurlencode(self::MAP_ADDRESS),
"CATALOG_URL" => SITE_DIR . "catalog/",
"BRANDS_URL" => SITE_DIR . "brands/",
"DESCRIPTION" => (string)Loc::getMessage("VINO_ABOUT_DESCRIPTION"),
"SCHEMA" => PageSchema::aboutPage(SITE_DIR . "about/", $title, (string)Loc::getMessage("VINO_ABOUT_DESCRIPTION"), PageSchema::image(Config::host() . SITE_DIR . "about/#image", Config::host() . SITE_TEMPLATE_PATH . "/assets/media/about-intro-1400.webp", 1400, 933)),
"MAP" => ["LAT" => self::MAP_LAT, "LON" => self::MAP_LON, "ZOOM" => self::MAP_ZOOM, "STYLE" => SITE_TEMPLATE_PATH . "/assets/map/vinoteca-dark.json"],
];
$this->includeComponentTemplate();
return $this->arResult;
}
private function counts(): array
{
$cache = Cache::createInstance();
if ($cache->initCache(self::CACHE_TTL, "counts-" . LANGUAGE_ID, self::CACHE_DIR)) {
return (array)$cache->getVars();
}
$cache->startDataCache();
$taggedCache = Application::getInstance()->getTaggedCache();
$taggedCache->startTagCache(self::CACHE_DIR);
try {
$brandsId = Config::iblockId("brands");
$taggedCache->registerTag("iblock_id_" . Config::iblockId("catalog"));
$taggedCache->registerTag("iblock_id_" . $brandsId);
$counts = [
"wines" => ServiceLocator::getInstance()->get("jinove.vinoteca.wineStats")->getActiveCount(),
"brands" => Loader::includeModule("iblock") ? ElementTable::getCount(["=IBLOCK_ID" => $brandsId, "=ACTIVE" => "Y"]) : 0,
"types" => MegaMenu::types(Config::iblockId("catalog")),
];
} catch (\Throwable $e) {
$taggedCache->abortTagCache();
$cache->abortDataCache();
return ["wines" => 0, "brands" => 0, "types" => []];
}
$taggedCache->endTagCache();
$cache->endDataCache($counts);
return $counts;
}
}