Created
June 5, 2024 11:47
-
-
Save EscApp2/2efc1660b1a69e782236ff33d84002a0 to your computer and use it in GitHub Desktop.
twofingers.location search by name
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
<?$LOC_ID = false; | |
if (\Bitrix\Main\Loader::includeModule('twofingers.location') | |
&& $location = \TwoFingers\Location\Factory\LocationFactory::buildByStorage()) | |
{ | |
$LOC_ID = $location->getId(); // ID местоположения | |
} | |
?> | |
<?$APPLICATION->IncludeComponent( | |
"bitrix:news", | |
"contacts", | |
Array( | |
"LOC_ID"=> $LOC_ID, | |
"ADD_ELEMENT_CHAIN" => "N", ............. |
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
<?php | |
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) | |
die(); | |
/** @var array $arParams */ | |
/** @var array $arResult */ | |
/** @global CMain $APPLICATION */ | |
/** @global CUser $USER */ | |
/** @global CDatabase $DB */ | |
/** @var CBitrixComponentTemplate $this */ | |
/** @var string $templateName */ | |
/** @var string $templateFile */ | |
/** @var string $templateFolder */ | |
/** @var string $componentPath */ | |
/** @var CBitrixComponent $component */ | |
$this->setFrameMode(true); | |
?> | |
<?php | |
use Bitrix\Main\Composite\BufferArea; | |
use Bitrix\Main\Loader; | |
use TwoFingers\Location\Entity\Location; | |
use TwoFingers\Location\Factory\LocationFactory; | |
$arLocation=array(); | |
$arLocationParent=array(); | |
if (Loader::includeModule('twofingers.location') | |
&& $location = LocationFactory::buildByStorage()) | |
{ | |
$arLocation["ID"] = $location->getId(); // ID местоположения | |
$arLocation["CODE"] = $location->getCode(); // Код местоположения | |
$arLocation["NAME"] = $location->getName(); // название местоположения | |
if ($location->hasParent()) | |
{ | |
$parents = LocationFactory::buildParentsCollection($location); | |
/** @var Location $parent */ | |
foreach ($parents as $parent) | |
{ | |
// выводим только регион и страну | |
if (in_array($parent->getType(), [Location::TYPE_REGION, Location::TYPE_COUNTRY])) | |
{ | |
$arLocationParent["ID"] = $parent->getId(); // ID родительского местоположения | |
$arLocationParent["CODE"] = $parent->getCode(); // Код родительского местоположения | |
$arLocationParent["NAME"] = $parent->getName(); // название родительского местоположения | |
} | |
} | |
} | |
} | |
$arItemsBySect = []; | |
$sectIds = []; | |
foreach ($arResult['ITEMS'] as $one) { | |
if (!empty($one['IBLOCK_SECTION_ID'])) { | |
$arItemsBySect[$one['IBLOCK_SECTION_ID']][] = $one; | |
$sectIds[$one['IBLOCK_SECTION_ID']] = $one['IBLOCK_SECTION_ID']; | |
} | |
} | |
$emptCity=true; | |
if (!empty($sectIds)) { | |
$dbSects = \CIBlockSection::GetList( | |
['sort' => 'asc', 'name' => 'asc'], | |
['IBLOCK_ID' => $arParams['IBLOCK_ID']], | |
false, | |
['ID', 'IBLOCK_ID', 'NAME', 'SECTION_PAGE_URL'] | |
); | |
$arSects = []; | |
while ($one = $dbSects->getNext()) { | |
$arSects[$one['ID']] = $one; | |
if($one["NAME"]=="Москва и МО"){ | |
$arSects[$one['ID']]["CITY"]="Москва"; | |
}else{ | |
$arSects[$one['ID']]["CITY"]=$one["NAME"]; | |
} | |
if($arSects[$one['ID']]["CITY"]==$arLocation["NAME"]){ | |
$arSects[$one['ID']]["ACTIVE"]="Y"; | |
$emptCity=false; | |
} | |
} | |
} | |
if($emptCity){ | |
$arSects[484]["ACTIVE"]="Y"; | |
} | |
$arResult["SECT"]=$arSects; | |
$arResult["SECT_ITEMS"]=$arItemsBySect; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment