Простой компонент - amel-post/bitrix.help GitHub Wiki

<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

class SimpleComponent extends CBitrixComponent
{
    public function onPrepareComponentParams($arParams)
    {
        return $arParams;
    }

    public function executeComponent()
    {
        $obCache = new CPHPCache();
        $cachePath = '/'.SITE_ID.'/'.self::class;
        if( $obCache->InitCache($this->arParams['CACHE_TIME'], serialize($this->arParams), $cachePath) ) {
            $vars = $obCache->GetVars();
            $this->arResult = $vars['data'];
        } else {
            global $CACHE_MANAGER;
            $CACHE_MANAGER->StartTagCache($cachePath);
            $obCache->StartDataCache();
            $CACHE_MANAGER->RegisterTag("iblock_id_".$this->arParams["IBLOCK_ID"]);
            $this->getResult();
            $CACHE_MANAGER->EndTagCache();
            $obCache->EndDataCache(['data' => $this->arResult]);
        }

        $this->includeComponentTemplate();
    }

    protected function getResult()
    {
        $this->arResult = [];
    }
}