Last active
March 29, 2023 09:40
-
-
Save freekir/025f9e87e516b62c9477a34723a104ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/iblock/lib/template/functions/fabric.php'); | |
use Bitrix\Main; | |
$eventManager = Main\EventManager::getInstance(); | |
$eventManager->addEventHandler("iblock", "OnTemplateGetFunctionClass", "myOnTemplateGetFunctionClass"); | |
function myOnTemplateGetFunctionClass(Bitrix\Main\Event $event) { | |
$arParam = $event->getParameters(); | |
$functionClass = $arParam[0]; | |
if (is_string($functionClass) && class_exists($functionClass) && $functionClass=='count_section'){ | |
$result = new Bitrix\Main\EventResult(1,$functionClass); | |
return $result; | |
} | |
} | |
class count_section extends Bitrix\Iblock\Template\Functions\FunctionBase | |
{ | |
public function onPrepareParameters(\Bitrix\Iblock\Template\Entity\Base $entity, $parameters) | |
{ | |
$arguments = array(); | |
/** @var \Bitrix\Iblock\Template\NodeBase $parameter */ | |
foreach ($parameters as $parameter) | |
{ | |
$arguments[] = $parameter->process($entity); | |
} | |
return $arguments; | |
} | |
public function calculate(array $parameters) | |
{ | |
$arFilter = Array( | |
"IBLOCK_ID"=>IntVal($parameters[0]), | |
"SECTION_CODE" => $parameters[1], | |
"ACTIVE"=>"Y", | |
"INCLUDE_SUBSECTIONS" => 'Y' | |
); | |
$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, Array("ID")); | |
if($count = $res->SelectedRowsCount()){ | |
$activeElements = $count; | |
} | |
return $activeElements; | |
} | |
} | |
//пример вызова в сео модуле {=count_section 4 this.Code} где 4 id инфоблока, а this.Code символьный код раздела |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment