1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-28 20:45:00 +03:00

Доработка поиска пользователей по geo-объектам

This commit is contained in:
Mzhelskiy Maxim 2014-11-28 14:30:15 +07:00
parent 1f8e100ca8
commit 42abb39b41
6 changed files with 133 additions and 25 deletions

View file

@ -1030,10 +1030,19 @@ class ActionAjax extends Action
/**
* Получаем список регионов
*/
$aResult = $this->Geo_GetRegions(array('country_id' => $oCountry->getId()), array('sort' => 'asc'), 1, $iLimit);
$aRegions = array();
foreach ($aResult['collection'] as $oObject) {
$aRegions[] = array(
if ($sTargetType = getRequestStr('target_type') and $this->Geo_IsAllowTargetType($sTargetType)) {
$aRegions = $this->Geo_GetRegionsUsedByTargetType($oCountry->getId(), $sTargetType);
} else {
$aRegions = $this->Geo_GetRegions(array('country_id' => $oCountry->getId()), array('sort' => 'asc'), 1,
$iLimit);
$aRegions = $aRegions['collection'];
}
/**
* Формируем ответ
*/
$aReturn = array();
foreach ($aRegions as $oObject) {
$aReturn[] = array(
'id' => $oObject->getId(),
'name' => $oObject->getName(),
);
@ -1041,7 +1050,7 @@ class ActionAjax extends Action
/**
* Устанавливаем переменные для ajax ответа
*/
$this->Viewer_AssignAjax('aRegions', $aRegions);
$this->Viewer_AssignAjax('aRegions', $aReturn);
}
/**
@ -1063,10 +1072,19 @@ class ActionAjax extends Action
/**
* Получаем города
*/
$aResult = $this->Geo_GetCities(array('region_id' => $oRegion->getId()), array('sort' => 'asc'), 1, $iLimit);
$aCities = array();
foreach ($aResult['collection'] as $oObject) {
$aCities[] = array(
if ($sTargetType = getRequestStr('target_type') and $this->Geo_IsAllowTargetType($sTargetType)) {
$aCities = $this->Geo_GetCitiesUsedByTargetType($oRegion->getId(), $sTargetType);
} else {
$aCities = $this->Geo_GetCities(array('region_id' => $oRegion->getId()), array('sort' => 'asc'), 1,
$iLimit);
$aCities = $aCities['collection'];
}
/**
* Формируем ответ
*/
$aReturn = array();
foreach ($aCities as $oObject) {
$aReturn[] = array(
'id' => $oObject->getId(),
'name' => $oObject->getName(),
);
@ -1074,7 +1092,7 @@ class ActionAjax extends Action
/**
* Устанавливаем переменные для ajax ответа
*/
$this->Viewer_AssignAjax('aCities', $aCities);
$this->Viewer_AssignAjax('aCities', $aReturn);
}
/**

View file

@ -132,6 +132,16 @@ class ActionPeople extends Action
if (getRequest('is_online')) {
$aFilter['date_last_more'] = date('Y-m-d H:i:s', time() - Config::Get('module.user.time_onlive'));
}
/**
* Geo привязка
*/
if (getRequestStr('city')) {
$aFilter['geo_city'] = getRequestStr('city');
} elseif (getRequestStr('region')) {
$aFilter['geo_region'] = getRequestStr('region');
} elseif (getRequestStr('country')) {
$aFilter['geo_country'] = getRequestStr('country');
}
/**
* Ищем пользователей
*/

View file

@ -480,7 +480,7 @@ class ModuleGeo extends Module
/**
* Возвращает список использованых стран для типа
*
* @param $sTargetType Тип владельца
* @param string $sTargetType Тип владельца
* @return array
*/
public function GetCountriesUsedByTargetType($sTargetType)
@ -488,6 +488,30 @@ class ModuleGeo extends Module
return $this->oMapper->GetCountriesUsedByTargetType($sTargetType);
}
/**
* Возвращает список использованых регионов для типа
*
* @param int $iCountryId
* @param string $sTargetType Тип владельца
* @return array
*/
public function GetRegionsUsedByTargetType($iCountryId, $sTargetType)
{
return $this->oMapper->GetRegionsUsedByTargetType($iCountryId, $sTargetType);
}
/**
* Возвращает список использованых городов для типа
*
* @param int $iRegionId
* @param string $sTargetType Тип владельца
* @return array
*/
public function GetCitiesUsedByTargetType($iRegionId, $sTargetType)
{
return $this->oMapper->GetCitiesUsedByTargetType($iRegionId, $sTargetType);
}
/**
* Проверка объекта с типом "user"
* Название метода формируется автоматически

View file

@ -414,4 +414,54 @@ class ModuleGeo_MapperGeo extends Mapper
}
return $aResult;
}
public function GetRegionsUsedByTargetType($iCountryId,$sTargetType)
{
$sql = "
SELECT
c.*
FROM (
SELECT
DISTINCT region_id
FROM
" . Config::Get('db.table.geo_target') . "
WHERE target_type = ? and region_id IS NOT NULL
) as t
JOIN " . Config::Get('db.table.geo_region') . " as c on ( t.region_id=c.id and c.country_id = ? )
ORDER BY c.name_ru
";
$aResult = array();
if ($aRows = $this->oDb->select($sql, $sTargetType, $iCountryId)) {
foreach ($aRows as $aRow) {
$aResult[] = Engine::GetEntity('ModuleGeo_EntityRegion', $aRow);
}
}
return $aResult;
}
public function GetCitiesUsedByTargetType($iRegionId,$sTargetType)
{
$sql = "
SELECT
c.*
FROM (
SELECT
DISTINCT city_id
FROM
" . Config::Get('db.table.geo_target') . "
WHERE target_type = ? and city_id IS NOT NULL
) as t
JOIN " . Config::Get('db.table.geo_city') . " as c on ( t.city_id=c.id and c.region_id = ? )
ORDER BY c.name_ru
";
$aResult = array();
if ($aRows = $this->oDb->select($sql, $sTargetType, $iRegionId)) {
foreach ($aRows as $aRow) {
$aResult[] = Engine::GetEntity('ModuleGeo_EntityCity', $aRow);
}
}
return $aResult;
}
}

View file

@ -1359,6 +1359,9 @@ class ModuleUser_MapperUser extends Mapper
u.user_id
FROM
" . Config::Get('db.table.user') . " as u
{ JOIN " . Config::Get('db.table.geo_target') . " as g ON ( u.user_id=g.target_id and g.country_id = ? ) }
{ JOIN " . Config::Get('db.table.geo_target') . " as g ON ( u.user_id=g.target_id and g.region_id = ? ) }
{ JOIN " . Config::Get('db.table.geo_target') . " as g ON ( u.user_id=g.target_id and g.city_id = ? ) }
LEFT JOIN " . Config::Get('db.table.session') . " as s ON u.user_id=s.user_id
WHERE
1 = 1
@ -1377,6 +1380,9 @@ class ModuleUser_MapperUser extends Mapper
";
$aResult = array();
if ($aRows = $this->oDb->selectPage($iCount, $sql,
isset($aFilter['geo_country']) ? $aFilter['geo_country'] : DBSIMPLE_SKIP,
isset($aFilter['geo_region']) ? $aFilter['geo_region'] : DBSIMPLE_SKIP,
isset($aFilter['geo_city']) ? $aFilter['geo_city'] : DBSIMPLE_SKIP,
isset($aFilter['date_last_more']) ? $aFilter['date_last_more'] : DBSIMPLE_SKIP,
isset($aFilter['id']) ? $aFilter['id'] : DBSIMPLE_SKIP,
isset($aFilter['mail']) ? $aFilter['mail'] : DBSIMPLE_SKIP,

View file

@ -247,17 +247,17 @@ jQuery(document).ready(function($){
{
type: 'select',
name: 'country',
selector: '.js-search-ajax-user-geo .js-field-geo-country'
selector: '.js-field-geo-country'
},
{
type: 'select',
name: 'region',
selector: '.js-search-ajax-user-geo .js-field-geo-region'
selector: '.js-field-geo-region'
},
{
type: 'select',
name: 'city',
selector: '.js-search-ajax-user-geo .js-field-geo-city'
selector: '.js-field-geo-city'
}
]
});