ModuleGeo_MapperGeo
Package | modules.geo |
---|---|
Inheritance | class ModuleGeo_MapperGeo » Mapper » LsObject |
Since | 1.0 |
Source Code | /classes/modules/geo/mapper/Geo.mapper.class.php |
Объект маппера для работы с БД
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
oDb | DbSimple_Generic_Database | Объект подключения к базе данных | Mapper |
Public Methods
Method | Description | Defined By |
---|---|---|
AddTarget() | Добавляет связь объекта с гео-объектом в БД | ModuleGeo_MapperGeo |
DeleteTargets() | Удаляет связи по фильтру | ModuleGeo_MapperGeo |
GetCities() | Возвращает список стран по фильтру | ModuleGeo_MapperGeo |
GetCountries() | Возвращает список стран по фильтру | ModuleGeo_MapperGeo |
GetGroupCitiesByTargetType() | Возвращает список городов сгруппированных по количеству использований в данном типе объектов | ModuleGeo_MapperGeo |
GetGroupCountriesByTargetType() | Возвращает список стран сгруппированных по количеству использований в данном типе объектов | ModuleGeo_MapperGeo |
GetRegions() | Возвращает список стран по фильтру | ModuleGeo_MapperGeo |
GetTargets() | Возвращает список связей по фильтру | ModuleGeo_MapperGeo |
__construct() | Передаем коннект к БД | Mapper |
Method Details
AddTarget()
method
public ModuleGeo_EntityTarget|bool AddTarget(ModuleGeo_EntityTarget $oTarget)
| ||
$oTarget | ModuleGeo_EntityTarget | Объект связи с владельцем |
{return} | ModuleGeo_EntityTarget|bool |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#31 (show)
public function AddTarget($oTarget) {
$sql = "INSERT INTO ".Config::Get('db.table.geo_target')." SET ?a ";
if ($this->oDb->query($sql,$oTarget->_getData())) {
return true;
}
return false;
}
Добавляет связь объекта с гео-объектом в БД
DeleteTargets()
method
public bool|int DeleteTargets(array $aFilter)
| ||
$aFilter | array | Фильтр |
{return} | bool|int |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#156 (show)
public function DeleteTargets($aFilter) {
if (!$aFilter) {
return false;
}
$sql = "DELETE
FROM
".Config::Get('db.table.geo_target')."
WHERE
1 = 1
{ AND geo_type = ? }
{ AND geo_id = ?d }
{ AND target_type = ? }
{ AND target_id = ?d }
{ AND country_id = ?d }
{ AND region_id = ?d }
{ AND city_id = ?d }
";
return $this->oDb->query($sql,
isset($aFilter['geo_type']) ? $aFilter['geo_type'] : DBSIMPLE_SKIP,
isset($aFilter['geo_id']) ? $aFilter['geo_id'] : DBSIMPLE_SKIP,
isset($aFilter['target_type']) ? $aFilter['target_type'] : DBSIMPLE_SKIP,
isset($aFilter['target_id']) ? $aFilter['target_id'] : DBSIMPLE_SKIP,
isset($aFilter['country_id']) ? $aFilter['country_id'] : DBSIMPLE_SKIP,
isset($aFilter['region_id']) ? $aFilter['region_id'] : DBSIMPLE_SKIP,
isset($aFilter['city_id']) ? $aFilter['city_id'] : DBSIMPLE_SKIP
);
}
Удаляет связи по фильтру
GetCities()
method
public array GetCities(array $aFilter, array $aOrder, int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$aFilter | array | Фильтр |
$aOrder | array | Сортировка |
$iCount | int | Возвращает количество элементов |
$iCurrPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
{return} | array |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#311 (show)
public function GetCities($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
$aOrderAllow=array('id','name_ru','name_en','sort','country_id','region_id');
$sOrder='';
foreach ($aOrder as $key=>$value) {
if (!in_array($key,$aOrderAllow)) {
unset($aOrder[$key]);
} elseif (in_array($value,array('asc','desc'))) {
$sOrder.=" {$key} {$value},";
}
}
$sOrder=trim($sOrder,',');
if ($sOrder=='') {
$sOrder=' id desc ';
}
if (isset($aFilter['country_id']) and !is_array($aFilter['country_id'])) {
$aFilter['country_id']=array($aFilter['country_id']);
}
if (isset($aFilter['region_id']) and !is_array($aFilter['region_id'])) {
$aFilter['region_id']=array($aFilter['region_id']);
}
$sql = "SELECT
*
FROM
".Config::Get('db.table.geo_city')."
WHERE
1 = 1
{ AND id = ?d }
{ AND name_ru = ? }
{ AND name_ru LIKE ? }
{ AND name_en = ? }
{ AND name_en LIKE ? }
{ AND country_id IN ( ?a ) }
{ AND region_id IN ( ?a ) }
ORDER by {$sOrder}
LIMIT ?d, ?d ;
";
$aResult=array();
if ($aRows=$this->oDb->selectPage($iCount,$sql,
isset($aFilter['id']) ? $aFilter['id'] : DBSIMPLE_SKIP,
isset($aFilter['name_ru']) ? $aFilter['name_ru'] : DBSIMPLE_SKIP,
isset($aFilter['name_ru_like']) ? $aFilter['name_ru_like'] : DBSIMPLE_SKIP,
isset($aFilter['name_en']) ? $aFilter['name_en'] : DBSIMPLE_SKIP,
isset($aFilter['name_en_like']) ? $aFilter['name_en_like'] : DBSIMPLE_SKIP,
(isset($aFilter['country_id']) && count($aFilter['country_id'])) ? $aFilter['country_id'] : DBSIMPLE_SKIP,
(isset($aFilter['region_id']) && count($aFilter['region_id'])) ? $aFilter['region_id'] : DBSIMPLE_SKIP,
($iCurrPage-1)*$iPerPage, $iPerPage
)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('ModuleGeo_EntityCity',$aRow);
}
}
return $aResult;
}
Возвращает список стран по фильтру
GetCountries()
method
public array GetCountries(array $aFilter, array $aOrder, int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$aFilter | array | Фильтр |
$aOrder | array | Сортировка |
$iCount | int | Возвращает количество элементов |
$iCurrPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
{return} | array |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#193 (show)
public function GetCountries($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
$aOrderAllow=array('id','name_ru','name_en','sort');
$sOrder='';
foreach ($aOrder as $key=>$value) {
if (!in_array($key,$aOrderAllow)) {
unset($aOrder[$key]);
} elseif (in_array($value,array('asc','desc'))) {
$sOrder.=" {$key} {$value},";
}
}
$sOrder=trim($sOrder,',');
if ($sOrder=='') {
$sOrder=' id desc ';
}
$sql = "SELECT
*
FROM
".Config::Get('db.table.geo_country')."
WHERE
1 = 1
{ AND id = ?d }
{ AND name_ru = ? }
{ AND name_ru LIKE ? }
{ AND name_en = ? }
{ AND name_en LIKE ? }
{ AND code = ? }
ORDER by {$sOrder}
LIMIT ?d, ?d ;
";
$aResult=array();
if ($aRows=$this->oDb->selectPage($iCount,$sql,
isset($aFilter['id']) ? $aFilter['id'] : DBSIMPLE_SKIP,
isset($aFilter['name_ru']) ? $aFilter['name_ru'] : DBSIMPLE_SKIP,
isset($aFilter['name_ru_like']) ? $aFilter['name_ru_like'] : DBSIMPLE_SKIP,
isset($aFilter['name_en']) ? $aFilter['name_en'] : DBSIMPLE_SKIP,
isset($aFilter['name_en_like']) ? $aFilter['name_en_like'] : DBSIMPLE_SKIP,
isset($aFilter['code']) ? $aFilter['code'] : DBSIMPLE_SKIP,
($iCurrPage-1)*$iPerPage, $iPerPage
)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('ModuleGeo_EntityCountry',$aRow);
}
}
return $aResult;
}
Возвращает список стран по фильтру
GetGroupCitiesByTargetType()
method
public array GetGroupCitiesByTargetType(string $sTargetType, int $iLimit)
| ||
$sTargetType | string | Тип владельца |
$iLimit | int | Количество элементов |
{return} | array |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#125 (show)
public function GetGroupCitiesByTargetType($sTargetType,$iLimit) {
$sql = "
SELECT
t.count,
g.*
FROM (
SELECT
count(*) as count,
city_id
FROM
".Config::Get('db.table.geo_target')."
WHERE target_type = ? and city_id IS NOT NULL
GROUP BY city_id ORDER BY count DESC LIMIT 0, ?d
) as t
JOIN ".Config::Get('db.table.geo_city')." as g on t.city_id=g.id
ORDER BY g.name_ru
";
$aResult=array();
if ($aRows=$this->oDb->select($sql,$sTargetType,$iLimit)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('ModuleGeo_EntityCity',$aRow);
}
}
return $aResult;
}
Возвращает список городов сгруппированных по количеству использований в данном типе объектов
GetGroupCountriesByTargetType()
method
public array GetGroupCountriesByTargetType(string $sTargetType, int $iLimit)
| ||
$sTargetType | string | Тип владельца |
$iLimit | int | Количество элементов |
{return} | array |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#93 (show)
public function GetGroupCountriesByTargetType($sTargetType,$iLimit) {
$sql = "
SELECT
t.count,
g.*
FROM (
SELECT
count(*) as count,
country_id
FROM
".Config::Get('db.table.geo_target')."
WHERE target_type = ? and country_id IS NOT NULL
GROUP BY country_id ORDER BY count DESC LIMIT 0, ?d
) as t
JOIN ".Config::Get('db.table.geo_country')." as g on t.country_id=g.id
ORDER BY g.name_ru
";
$aResult=array();
if ($aRows=$this->oDb->select($sql,$sTargetType,$iLimit)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('ModuleGeo_EntityCountry',$aRow);
}
}
return $aResult;
}
Возвращает список стран сгруппированных по количеству использований в данном типе объектов
GetRegions()
method
public array GetRegions(array $aFilter, array $aOrder, int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$aFilter | array | Фильтр |
$aOrder | array | Сортировка |
$iCount | int | Возвращает количество элементов |
$iCurrPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
{return} | array |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#250 (show)
public function GetRegions($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
$aOrderAllow=array('id','name_ru','name_en','sort','country_id');
$sOrder='';
foreach ($aOrder as $key=>$value) {
if (!in_array($key,$aOrderAllow)) {
unset($aOrder[$key]);
} elseif (in_array($value,array('asc','desc'))) {
$sOrder.=" {$key} {$value},";
}
}
$sOrder=trim($sOrder,',');
if ($sOrder=='') {
$sOrder=' id desc ';
}
if (isset($aFilter['country_id']) and !is_array($aFilter['country_id'])) {
$aFilter['country_id']=array($aFilter['country_id']);
}
$sql = "SELECT
*
FROM
".Config::Get('db.table.geo_region')."
WHERE
1 = 1
{ AND id = ?d }
{ AND name_ru = ? }
{ AND name_ru LIKE ? }
{ AND name_en = ? }
{ AND name_en LIKE ? }
{ AND country_id IN ( ?a ) }
ORDER by {$sOrder}
LIMIT ?d, ?d ;
";
$aResult=array();
if ($aRows=$this->oDb->selectPage($iCount,$sql,
isset($aFilter['id']) ? $aFilter['id'] : DBSIMPLE_SKIP,
isset($aFilter['name_ru']) ? $aFilter['name_ru'] : DBSIMPLE_SKIP,
isset($aFilter['name_ru_like']) ? $aFilter['name_ru_like'] : DBSIMPLE_SKIP,
isset($aFilter['name_en']) ? $aFilter['name_en'] : DBSIMPLE_SKIP,
isset($aFilter['name_en_like']) ? $aFilter['name_en_like'] : DBSIMPLE_SKIP,
(isset($aFilter['country_id']) && count($aFilter['country_id'])) ? $aFilter['country_id'] : DBSIMPLE_SKIP,
($iCurrPage-1)*$iPerPage, $iPerPage
)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('ModuleGeo_EntityRegion',$aRow);
}
}
return $aResult;
}
Возвращает список стран по фильтру
GetTargets()
method
public array GetTargets(array $aFilter, int &$iCount, int $iCurrPage, int $iPerPage)
| ||
$aFilter | array | Фильтр |
$iCount | int | Возвращает количество элементов |
$iCurrPage | int | Номер страницы |
$iPerPage | int | Количество элементов на страницу |
{return} | array |
Source Code: /classes/modules/geo/mapper/Geo.mapper.class.php#47 (show)
public function GetTargets($aFilter,&$iCount,$iCurrPage,$iPerPage) {
if (isset($aFilter['target_id']) and !is_array($aFilter['target_id'])) {
$aFilter['target_id']=array($aFilter['target_id']);
}
$sql = "SELECT
*
FROM
".Config::Get('db.table.geo_target')."
WHERE
1 = 1
{ AND geo_type = ? }
{ AND geo_id = ?d }
{ AND target_type = ? }
{ AND target_id IN ( ?a ) }
{ AND country_id = ?d }
{ AND region_id = ?d }
{ AND city_id = ?d }
ORDER BY target_id DESC
LIMIT ?d, ?d ;
";
$aResult=array();
if ($aRows=$this->oDb->selectPage($iCount,$sql,
isset($aFilter['geo_type']) ? $aFilter['geo_type'] : DBSIMPLE_SKIP,
isset($aFilter['geo_id']) ? $aFilter['geo_id'] : DBSIMPLE_SKIP,
isset($aFilter['target_type']) ? $aFilter['target_type'] : DBSIMPLE_SKIP,
(isset($aFilter['target_id']) and count($aFilter['target_id'])) ? $aFilter['target_id'] : DBSIMPLE_SKIP,
isset($aFilter['country_id']) ? $aFilter['country_id'] : DBSIMPLE_SKIP,
isset($aFilter['region_id']) ? $aFilter['region_id'] : DBSIMPLE_SKIP,
isset($aFilter['city_id']) ? $aFilter['city_id'] : DBSIMPLE_SKIP,
($iCurrPage-1)*$iPerPage, $iPerPage
)) {
foreach ($aRows as $aRow) {
$aResult[]=Engine::GetEntity('ModuleGeo_EntityTarget',$aRow);
}
}
return $aResult;
}
Возвращает список связей по фильтру