component.php 2.35 KB
<?
use \Cpeople\Classes\Block;

$arParams['CODE'] = !empty($_REQUEST['CODE']) ? $_REQUEST['CODE'] : false;
$arParams['TEMPLATE'] = $arParams['CODE']
    ? 'detail'
    : false;

try {
    if ($this->StartResultCache(COMPONENTS_CACHE_TTL))
    {
        if ($arParams['TEMPLATE'] == 'detail') {
            $arResult['ITEM'] = Block\Getter::instance()
                ->setFilter(array('IBLOCK_ID' => IBLOCK_LUMBER, 'ACTIVE' => 'Y'))
                ->setClassName('\SH\Entities\Lumber')
                ->setNavStartParams(array('nTopCount' => 1))
                ->getByCode($arParams['CODE']);

            if (!$arResult['ITEM']) throw new Exception('detail not found');

            $arResult['NAME'] = $arResult['ITEM']->NAME;

            $ipropValues = new \Bitrix\Iblock\InheritedProperty\ElementValues(IBLOCK_LUMBER, $arResult['ITEM']->ID);
            $arResult['IPROPERTY_VALUES'] = $ipropValues->getValues();

            $arResult['TITLE'] = $arResult['IPROPERTY_VALUES']['ELEMENT_META_TITLE'];
            $arResult['KEYWORDS'] = $arResult['IPROPERTY_VALUES']['ELEMENT_META_KEYWORDS'];
            $arResult['DESCRIPTION'] = $arResult['IPROPERTY_VALUES']['ELEMENT_META_DESCRIPTION'];
        } else {
            $getter = Block\Getter::instance()
                ->setFilter(array('IBLOCK_ID' => IBLOCK_LUMBER, 'ACTIVE' => 'Y'))
                ->setOrder(array('SORT' => 'ASC', 'NAME' => 'ASC'))
                ->setClassName('\SH\Entities\Lumber');

            $arResult['ITEMS'] = $getter->get();

            $arResult['COUNT'] = $getter->getFoundRows();
            $arResult['REMAIN'] = $arResult['COUNT'] - $arParams['PAGE_SIZE'] * $arParams['PAGE_NUM'];
        }

        $this->SetResultCacheKeys(array('NAME', 'TITLE', 'KEYWORDS', 'DESCRIPTION'));
        $this->IncludeComponentTemplate($arParams['TEMPLATE']);
    }
} catch(Exception $e) {
    define('ERROR_404', true);
    $this->AbortResultCache();
    return;
}

if($arResult['NAME']) $APPLICATION->AddChainItem($arResult['NAME']);
if($arResult['NAME']) $APPLICATION->SetTitle($arResult['NAME']);
if($arResult['TITLE']) $APPLICATION->SetPageProperty('title', $arResult['TITLE']);
if($arResult['KEYWORDS']) $APPLICATION->SetPageProperty("keywords", $arResult['KEYWORDS']);
if($arResult['DESCRIPTION']) $APPLICATION->SetPageProperty("description", $arResult['DESCRIPTION']);