Your IP : 18.118.0.175


Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/local/components/ballu.b2c/geo.map.yandex/
Upload File :
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/local/components/ballu.b2c/geo.map.yandex/class.php

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

use \Bitrix\Main\Data\Cache;
use \Bitrix\Main\Context;
use Rusklimat\B2b\Helpers\Main\Geo;
use Rusklimat\B2b\Helpers\Main\GeoOffices;

class ComponentB2bGeoMapYandex extends CBitrixComponent
{
	static $loadJs = false;

	public function executeComponent()
	{
		$this->InitComponentTemplate();

		if (!$this->extractDataFromCache())
		{
			$this->prepareData();

			$this->includeComponentTemplate();
			$this->setResultCacheKeys([]);
		}
	}

	public function onPrepareComponentParams($arParams)
	{
		$arParams['CACHE_TYPE'] = 'N';
		
		return parent::onPrepareComponentParams($arParams);
	}

	public function extractDataFromCache()
	{
		if($this->arParams['CACHE_TYPE'] == 'N')
			return false;

		return !($this->StartResultCache(false));
	}

	public function prepareData()
	{
		$this->arResult = [];

		if($this->arParams['PLACEMARKS'])
		{
			$this->arResult['PLACEMARKS'] = $this->arParams['PLACEMARKS'];
		}
		elseif($this->arParams['PLACE'])
		{
			$this->arResult['PLACE'] = $this->arParams['PLACE'];
		}
		else
		{
			$this->getPoint();
		}
	}

	private function getPoint()
	{
		$arResult['geo'] =  Rusklimat\B2b\Helpers\Main\Geo::getInstance()->getByID($this->arParams['CUR_CITY_ID']);

		$arGeoPoints = GeoOffices::getByGeo($arResult['geo']);

		// Доставка
		if(!empty($arResult['geo']['ID']))
		{
			$arResult['geo']['DELIVERY'] = \CIBlockElement::GetList(
				[],
				[
					'IBLOCK_ID' => \Rusklimat\B2b\Config\Catalog::IBLOCK_GLOBUS,
					'ID' => $arResult['geo']['ID'],
					'ACTIVE' => 'Y',
				],
				false,
				false,
				[
					'ID', 'PROPERTY_deliveryTariffs_st', 'PROPERTY_deliveryTariffs_kr'
				]
			)->Fetch();
		}

		if(!empty($arGeoPoints))
		{
			foreach($arGeoPoints as $point)
			{
				$arResult['PLACEMARKS'][$point['PROPERTY_PLACE_VALUE']] = [
					'hintContent' => $point['PROPERTY_PICKUPPOINT_ADRESS_VALUE'],
					'balloonContent' => $point['PROPERTY_PICKUPPOINT_ADRESS_VALUE'],
					'balloonContentPhone' => $point['PROPERTY_PHONE_VALUE'],
					'id' => $point['ID'],
				];
			}
		}

		$this->arResult = $arResult;
	}

	public static function getGeoCenterPlacemark($data = [])
	{
		$result = '';

		if($data)
		{
			$points = [
				'min' => [
					0 => null,
					1 => null,
				],
				'max' => [
					0 => null,
					1 => null,
				],
			];

			foreach($data as $geo => $prop)
			{
				$g = explode(',', $geo);

				if($g[0] <= $points['min'][0] || $points['min'][0] === null)
					$points['min'][0] = $g[0];

				if($g[1] <= $points['min'][1] || $points['min'][1] === null)
					$points['min'][1] = $g[1];

				if($g[0] >= $points['max'][0] || $points['max'][0] === null)
					$points['max'][0] = $g[0];

				if($g[1] >= $points['max'][1] || $points['max'][1] === null)
					$points['max'][1] = $g[1];
			}

			$result = '['.implode(',', $points['min']).'], ['.implode(',', $points['max']).']';
		}

		return $result;
	}
}