GeoIP/src/Application/Controller/Admin/d3_cfg_geoipset_main.php

98 regels
3.1 KiB
PHP

<?php
2013-04-22 11:40:11 +02:00
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2020-06-10 10:28:16 +02:00
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
2013-04-22 11:40:11 +02:00
* @link http://www.oxidmodule.com
*/
2020-06-10 10:28:16 +02:00
namespace D3\GeoIp\Application\Controller\Admin;
use D3\GeoIp\Application\Model\d3geoip;
use D3\ModCfg\Application\Controller\Admin\d3_cfg_mod_main;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Model\CountryList;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
class d3_cfg_geoipset_main extends d3_cfg_mod_main
{
protected $_sModId = 'd3_geoip';
protected $_sThisTemplate = "d3_cfg_geoipset_main.tpl";
2015-06-23 11:29:07 +02:00
protected $_blHasDebugSwitch = true;
2013-04-22 11:40:11 +02:00
protected $_sDebugHelpTextIdent = 'D3_GEOIP_SET_DEBUG_DESC';
2016-11-21 16:34:21 +01:00
protected $_sMenuItemTitle = 'd3mxgeoip';
protected $_sMenuSubItemTitle = 'd3mxgeoip_settings';
public $oCountryList;
2013-04-22 11:25:27 +02:00
2013-04-22 11:40:11 +02:00
/**
* @param $sIP
* @return string
2020-06-10 10:28:16 +02:00
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
2013-04-22 11:40:11 +02:00
*/
public function getIpCountry($sIP)
{
2013-04-22 11:40:11 +02:00
startProfile(__METHOD__);
/** @var $oD3GeoIP d3geoip */
2020-04-17 09:29:09 +02:00
$oD3GeoIP = oxNew(d3geoip::class);
$oCountry = $oD3GeoIP->getUserLocationCountryObject($sIP);
2015-06-23 11:29:07 +02:00
if ($oCountry->getId()) {
$sTitle = $oCountry->getFieldData('oxtitle');
2015-06-23 11:29:07 +02:00
} else {
2020-04-17 09:29:09 +02:00
$sTitle = Registry::getLang()->translateString('D3_GEOIP_SET_IP_CHECKIP_NOTSET');
2013-04-22 11:40:11 +02:00
}
stopProfile(__METHOD__);
return $sTitle;
}
2013-04-22 11:25:27 +02:00
2013-04-22 11:40:11 +02:00
/**
2020-04-17 09:29:09 +02:00
* @return CountryList
2013-04-22 11:40:11 +02:00
*/
2013-04-22 11:25:27 +02:00
public function getIPCountryList()
{
2016-11-21 16:34:21 +01:00
if ($this->oCountryList) {
return $this->oCountryList;
}
2013-04-22 11:40:11 +02:00
2016-11-21 16:34:21 +01:00
startProfile(__METHOD__);
2020-04-17 09:29:09 +02:00
/** @var $oGeoIp d3geoip */
$oGeoIp = oxNew(d3geoip::class);
/** @var $oCountryList CountryList */
$this->oCountryList = oxNew(CountryList::class);
2016-11-21 16:34:21 +01:00
$oListObject = $this->oCountryList->getBaseObject();
2013-04-22 11:25:27 +02:00
$sFieldList = $oListObject->getSelectFields();
2015-06-23 11:29:07 +02:00
$sQ = "select (SELECT d3startip FROM ".$oGeoIp->getViewName().
" WHERE D3ISO = " .$oListObject->getViewName(). ".
oxisoalpha2 LIMIT 1) as IP, $sFieldList from " . $oListObject->getViewName();
$sQ.= " ORDER BY oxactive DESC, oxtitle";
2013-04-22 11:25:27 +02:00
2016-11-21 16:34:21 +01:00
$this->oCountryList->selectString($sQ);
2013-04-22 11:25:27 +02:00
2013-04-22 11:40:11 +02:00
stopProfile(__METHOD__);
2016-11-21 16:34:21 +01:00
return $this->oCountryList;
2013-04-22 11:25:27 +02:00
}
2015-06-23 11:29:07 +02:00
}