1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-05-17 00:08:17 +03:00

переработана структура хранения стран и городов, добавлена их автоподстановка

This commit is contained in:
Mzhelskiy Maxim 2008-11-01 06:16:18 +00:00
parent 7b119a4142
commit 3edfdf1b86
12 changed files with 505 additions and 16 deletions

View file

@ -191,12 +191,15 @@ class ActionSettings extends Action {
}
/**
* Проверяем регион
* пока отключим регион, т.к. не понятно нужен ли он вообще =)
*/
/*
if (func_check(getRequest('profile_region'),'text',1,30)) {
$this->oUserCurrent->setProfileRegion(getRequest('profile_region'));
} else {
$this->oUserCurrent->setProfileRegion(null);
}
*/
/**
* Проверяем город
*/
@ -296,6 +299,29 @@ class ActionSettings extends Action {
*/
if (!$bError) {
if ($this->User_Update($this->oUserCurrent)) {
/**
* Добавляем страну
*/
if ($this->oUserCurrent->getProfileCountry()) {
if (!($oCountry=$this->User_GetCountryByName($this->oUserCurrent->getProfileCountry()))) {
$oCountry=new UserEntity_Country();
$oCountry->setName($this->oUserCurrent->getProfileCountry());
$this->User_AddCountry($oCountry);
}
$this->User_SetCountryUser($oCountry->getId(),$this->oUserCurrent->getId());
}
/**
* Добавляем город
*/
if ($this->oUserCurrent->getProfileCity()) {
if (!($oCity=$this->User_GetCityByName($this->oUserCurrent->getProfileCity()))) {
$oCity=new UserEntity_City();
$oCity->setName($this->oUserCurrent->getProfileCity());
$this->User_AddCity($oCity);
}
$this->User_SetCityUser($oCity->getId(),$this->oUserCurrent->getId());
}
$this->Message_AddNoticeSingle('Профиль успешно сохранён','Ура');
} else {
$this->Message_AddErrorSingle('Возникли технические неполадки, пожалуйста повторите позже.','Внутреняя ошибка');

View file

@ -322,8 +322,8 @@ class User extends Module {
$aStat['count_sex_man']=(isset($aSex['man']) ? $aSex['man']['count'] : 0);
$aStat['count_sex_woman']=(isset($aSex['woman']) ? $aSex['woman']['count'] : 0);
$aStat['count_sex_other']=(isset($aSex['other']) ? $aSex['other']['count'] : 0);
$aStat['count_country']=$this->oMapper->GetCountUsersCountry();
$aStat['count_city']=$this->oMapper->GetCountUsersCity();
$aStat['count_country']=$this->oMapper->GetCountUsersCountry(15);
$aStat['count_city']=$this->oMapper->GetCountUsersCity(15);
$this->Cache_Set($aStat, "user_stats", array("user_update","user_new"), 60*5);
}
@ -508,5 +508,101 @@ class User extends Module {
}
return $data;
}
/**
* Привязывает страну к пользователю
*
* @param unknown_type $sCountryId
* @param unknown_type $sUserId
* @return unknown
*/
public function SetCountryUser($sCountryId,$sUserId) {
return $this->oMapper->SetCountryUser($sCountryId,$sUserId);
}
/**
* Получает страну по имени
*
* @param unknown_type $sName
* @return unknown
*/
public function GetCountryByName($sName) {
return $this->oMapper->GetCountryByName($sName);
}
/**
* Добавляет страну
*
* @param UserEntity_Country $oCountry
* @return unknown
*/
public function AddCountry(UserEntity_Country $oCountry) {
if ($sId=$this->oMapper->AddCountry($oCountry)) {
$oCountry->setId($sId);
//чистим зависимые кеши
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("country_new"));
return $oCountry;
}
return false;
}
/**
* Привязывает город к пользователю
*
* @param unknown_type $sCityId
* @param unknown_type $sUserId
* @return unknown
*/
public function SetCityUser($sCityId,$sUserId) {
return $this->oMapper->SetCityUser($sCityId,$sUserId);
}
/**
* Получает город по имени
*
* @param unknown_type $sName
* @return unknown
*/
public function GetCityByName($sName) {
return $this->oMapper->GetCityByName($sName);
}
/**
* Добавляет город
*
* @param UserEntity_City $oCity
* @return unknown
*/
public function AddCity(UserEntity_City $oCity) {
if ($sId=$this->oMapper->AddCity($oCity)) {
$oCity->setId($sId);
//чистим зависимые кеши
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("city_new"));
return $oCity;
}
return false;
}
/**
* Получает список похожих городов
*
* @param unknown_type $sName
* @param unknown_type $iLimit
* @return unknown
*/
public function GetCityByNameLike($sName,$iLimit) {
if (false === ($data = $this->Cache_Get("city_like_{$sName}_{$iLimit}"))) {
$data = $this->oMapper->GetCityByNameLike($sName,$iLimit);
$this->Cache_Set($data, "city_like_{$sName}_{$iLimit}", array("city_new"), 60*15);
}
return $data;
}
/**
* Получает список похожих стран
*
* @param unknown_type $sName
* @param unknown_type $iLimit
* @return unknown
*/
public function GetCountryByNameLike($sName,$iLimit) {
if (false === ($data = $this->Cache_Get("country_like_{$sName}_{$iLimit}"))) {
$data = $this->oMapper->GetCountryByNameLike($sName,$iLimit);
$this->Cache_Set($data, "country_like_{$sName}_{$iLimit}", array("country_new"), 60*15);
}
return $data;
}
}
?>

View file

@ -0,0 +1,36 @@
<?
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
class UserEntity_City extends Entity
{
public function getId() {
return $this->_aData['city_id'];
}
public function getName() {
return $this->_aData['city_name'];
}
public function setId($data) {
$this->_aData['city_id']=$data;
}
public function setName($data) {
$this->_aData['city_name']=$data;
}
}
?>

View file

@ -0,0 +1,36 @@
<?
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
class UserEntity_Country extends Entity
{
public function getId() {
return $this->_aData['country_id'];
}
public function getName() {
return $this->_aData['country_name'];
}
public function setId($data) {
$this->_aData['country_id']=$data;
}
public function setName($data) {
$this->_aData['country_name']=$data;
}
}
?>

View file

@ -294,15 +294,41 @@ class Mapper_User extends Mapper {
return $result;
}
public function GetCountUsersCountry() {
$sql = "SELECT user_profile_country AS ARRAY_KEY, count(user_id) as count FROM ".DB_TABLE_USER." WHERE NOT user_profile_country IS NULL and user_profile_country<>'' GROUP BY user_profile_country ";
$result=$this->oDb->select($sql);
public function GetCountUsersCountry($sLimit) {
$sql = "
SELECT
cu.count,
c.country_name as name
FROM (
SELECT
count(user_id) as count,
country_id
FROM
".DB_TABLE_COUNTRY_USER."
GROUP BY country_id ORDER BY count LIMIT 0, ?d
) as cu
JOIN ".DB_TABLE_COUNTRY." as c on cu.country_id=c.country_id
";
$result=$this->oDb->select($sql,$sLimit);
return $result;
}
public function GetCountUsersCity() {
$sql = "SELECT user_profile_city AS ARRAY_KEY, count(user_id) as count FROM ".DB_TABLE_USER." WHERE NOT user_profile_city IS NULL and user_profile_city<>'' GROUP BY user_profile_city ";
$result=$this->oDb->select($sql);
public function GetCountUsersCity($sLimit) {
$sql = "
SELECT
cu.count,
c.city_name as name
FROM (
SELECT
count(user_id) as count,
city_id
FROM
".DB_TABLE_CITY_USER."
GROUP BY city_id ORDER BY count LIMIT 0, ?d
) as cu
JOIN ".DB_TABLE_CITY." as c on cu.city_id=c.city_id
";
$result=$this->oDb->select($sql,$sLimit);
return $result;
}
@ -503,5 +529,98 @@ class Mapper_User extends Mapper {
}
return null;
}
public function SetCountryUser($sCountryId,$sUserId) {
$sql = "REPLACE ".DB_TABLE_COUNTRY_USER."
SET
country_id = ? ,
user_id = ?
";
return $this->oDb->query($sql,$sCountryId,$sUserId);
}
public function GetCountryByName($sName) {
$sql = "SELECT * FROM ".DB_TABLE_COUNTRY." WHERE country_name = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sName)) {
return new UserEntity_Country($aRow);
}
return null;
}
public function AddCountry(UserEntity_Country $oCountry) {
$sql = "INSERT INTO ".DB_TABLE_COUNTRY."
(country_name)
VALUES(?)
";
if ($iId=$this->oDb->query($sql,$oCountry->getName())) {
return $iId;
}
return false;
}
public function SetCityUser($sCityId,$sUserId) {
$sql = "REPLACE ".DB_TABLE_CITY_USER."
SET
city_id = ? ,
user_id = ?
";
return $this->oDb->query($sql,$sCityId,$sUserId);
}
public function GetCityByName($sName) {
$sql = "SELECT * FROM ".DB_TABLE_CITY." WHERE city_name = ? ";
if ($aRow=$this->oDb->selectRow($sql,$sName)) {
return new UserEntity_City($aRow);
}
return null;
}
public function AddCity(UserEntity_City $oCity) {
$sql = "INSERT INTO ".DB_TABLE_CITY."
(city_name)
VALUES(?)
";
if ($iId=$this->oDb->query($sql,$oCity->getName())) {
return $iId;
}
return false;
}
public function GetCityByNameLike($sName,$iLimit) {
$sql = "SELECT
*
FROM
".DB_TABLE_CITY."
WHERE
city_name LIKE ?
LIMIT 0, ?d
";
$aReturn=array();
if ($aRows=$this->oDb->select($sql,$sName.'%',$iLimit)) {
foreach ($aRows as $aRow) {
$aReturn[]=new UserEntity_City($aRow);
}
}
return $aReturn;
}
public function GetCountryByNameLike($sName,$iLimit) {
$sql = "SELECT
*
FROM
".DB_TABLE_COUNTRY."
WHERE
country_name LIKE ?
LIMIT 0, ?d
";
$aReturn=array();
if ($aRows=$this->oDb->select($sql,$sName.'%',$iLimit)) {
foreach ($aRows as $aRow) {
$aReturn[]=new UserEntity_Country($aRow);
}
}
return $aReturn;
}
}
?>

View file

@ -44,4 +44,8 @@ define('DB_TABLE_TOPIC_COMMENT_ONLINE',DB_PREFIX_TABLE.'topic_comment_online');
define('DB_TABLE_INVITE',DB_PREFIX_TABLE.'invite');
define('DB_TABLE_PAGE',DB_PREFIX_TABLE.'page');
define('DB_TABLE_TOPIC_COMMENT_LAST',DB_PREFIX_TABLE.'topic_comment_last');
define('DB_TABLE_CITY',DB_PREFIX_TABLE.'city');
define('DB_TABLE_CITY_USER',DB_PREFIX_TABLE.'city_user');
define('DB_TABLE_COUNTRY',DB_PREFIX_TABLE.'country');
define('DB_TABLE_COUNTRY_USER',DB_PREFIX_TABLE.'country_user');
?>

View file

@ -0,0 +1,39 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Автоподстановка города
*/
set_include_path(get_include_path().PATH_SEPARATOR.dirname(dirname(dirname(__FILE__))));
chdir(dirname(dirname(dirname(__FILE__))));
require_once("./config/config.ajax.php");
header('Content-Type: text/html; charset=utf-8');
if (!isset($_POST['value'])) {
exit();
}
$sCity = trim($_POST['value']);
if ($sCity!='') {
$aCity=$oEngine->User_GetCityByNameLike($sCity,10);
foreach ($aCity as $oCity) {
echo('<li>'.$oCity->getName().'</li>');
}
}
?>

View file

@ -0,0 +1,39 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Автоподстановка города
*/
set_include_path(get_include_path().PATH_SEPARATOR.dirname(dirname(dirname(__FILE__))));
chdir(dirname(dirname(dirname(__FILE__))));
require_once("./config/config.ajax.php");
header('Content-Type: text/html; charset=utf-8');
if (!isset($_POST['value'])) {
exit();
}
$sCountry = trim($_POST['value']);
if ($sCountry!='') {
$aCountry=$oEngine->User_GetCountryByNameLike($sCountry,10);
foreach ($aCountry as $oCountry) {
echo('<li>'.$oCountry->getName().'</li>');
}
}
?>

View file

@ -244,6 +244,75 @@ RENAME TABLE `social`.`prefix_frend` TO `social`.`prefix_friend` ;
ADD UNIQUE `topic_id` ( `topic_id` ) ;
--
-- Структура таблицы `prefix_city`
--
CREATE TABLE IF NOT EXISTS `prefix_city` (
`city_id` int(11) unsigned NOT NULL auto_increment,
`city_name` varchar(30) NOT NULL,
PRIMARY KEY (`city_id`),
KEY `city_name` (`city_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Структура таблицы `prefix_city_user`
--
CREATE TABLE IF NOT EXISTS `prefix_city_user` (
`city_id` int(11) unsigned NOT NULL,
`user_id` int(11) unsigned NOT NULL,
UNIQUE KEY `user_id` (`user_id`),
KEY `city_id` (`city_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Структура таблицы `prefix_country`
--
CREATE TABLE IF NOT EXISTS `prefix_country` (
`country_id` int(11) unsigned NOT NULL auto_increment,
`country_name` varchar(30) NOT NULL,
PRIMARY KEY (`country_id`),
KEY `country_name` (`country_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Структура таблицы `prefix_country_user`
--
CREATE TABLE IF NOT EXISTS `prefix_country_user` (
`country_id` int(11) unsigned NOT NULL,
`user_id` int(11) unsigned NOT NULL,
UNIQUE KEY `user_id` (`user_id`),
KEY `country_id` (`country_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Ограничения внешнего ключа сохраненных таблиц
--
--
-- Ограничения внешнего ключа таблицы `prefix_city_user`
--
ALTER TABLE `prefix_city_user`
ADD CONSTRAINT `prefix_city_user_fk` FOREIGN KEY (`city_id`) REFERENCES `prefix_city` (`city_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `prefix_city_user_fk1` FOREIGN KEY (`user_id`) REFERENCES `prefix_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Ограничения внешнего ключа таблицы `prefix_country_user`
--
ALTER TABLE `prefix_country_user`
ADD CONSTRAINT `prefix_country_user_fk` FOREIGN KEY (`country_id`) REFERENCES `prefix_country` (`country_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `prefix_country_user_fk1` FOREIGN KEY (`user_id`) REFERENCES `prefix_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- ВНИМАНИЕ!!! То что ниже нужно выполнить только после запуска скрипта convert.php !!!! иначе УДАЛЯТСЯ ВСЕ ТОПИКИ!!!!!
--

View file

@ -91,8 +91,8 @@
<div class="statsblock">
<h4 class="people_stat_header"><img src="{$DIR_STATIC_SKIN}/img/people_arrow_2.gif">Откуда мы?</h4>
<ul>
{foreach from=$aStat.count_country item=aValue key=sCountry}
<li>{$sCountry|escape:'html'}: {$aValue.count}</li>
{foreach from=$aStat.count_country item=aValue}
<li>{$aValue.name|escape:'html'}: {$aValue.count}</li>
{/foreach}
</ul>
</div>
@ -100,8 +100,8 @@
<div class="statsblock">
<h4 class="people_stat_header"><img src="{$DIR_STATIC_SKIN}/img/people_arrow_2.gif">Где мы?</h4>
<ul>
{foreach from=$aStat.count_city item=aValue key=sCity}
<li>{$sCity|escape:'html'}: {$aValue.count}</li>
{foreach from=$aStat.count_city item=aValue}
<li>{$aValue.name|escape:'html'}: {$aValue.count}</li>
{/foreach}
</ul>
</div>

View file

@ -4,6 +4,32 @@
{include file='system_message.tpl'}
{literal}
<script>
document.addEvent('domready', function() {
var inputCity = $('profile_city');
new Autocompleter.Request.HTML(inputCity, DIR_WEB_ROOT+'/include/ajax/cityAutocompleter.php', {
'indicatorClass': 'autocompleter-loading', // class added to the input during request
'minLength': 2, // We need at least 1 character
'selectMode': 'pick', // Instant completion
'multiple': false // Tag support, by default comma separated
});
var inputCountry = $('profile_country');
new Autocompleter.Request.HTML(inputCountry, DIR_WEB_ROOT+'/include/ajax/countryAutocompleter.php', {
'indicatorClass': 'autocompleter-loading', // class added to the input during request
'minLength': 2, // We need at least 1 character
'selectMode': 'pick', // Instant completion
'multiple': false // Tag support, by default comma separated
});
});
</script>
{/literal}
<BR>
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
@ -67,9 +93,8 @@
<br><br>
<span class="form">Страна: </span><br /><input style="width: 60%;" type="text" name="profile_country" value="{$oUserCurrent->getProfileCountry()|escape:'html'}"><br>
<span class="form">Регион: </span><br /><input style="width: 60%;" type="text" name="profile_region" value="{$oUserCurrent->getProfileRegion()|escape:'html'}"><br>
<span class="form">Город: </span><br /><input style="width: 60%;" type="text" name="profile_city" value="{$oUserCurrent->getProfileCity()|escape:'html'}"><br>
<span class="form">Страна: </span><br /><input style="width: 60%;" type="text" id="profile_country" name="profile_country" value="{$oUserCurrent->getProfileCountry()|escape:'html'}"><br>
<span class="form">Город: </span><br /><input style="width: 60%;" type="text" id="profile_city" name="profile_city" value="{$oUserCurrent->getProfileCity()|escape:'html'}"><br>
<br>

View file

@ -12,7 +12,7 @@ document.addEvent('domready', function() {
new Autocompleter.Request.HTML(inputUsers, DIR_WEB_ROOT+'/include/ajax/userAutocompleter.php', {
'indicatorClass': 'autocompleter-loading', // class added to the input during request
'minLength': 1, // We need at least 1 character
'selectMode': 'type-ahead', // Instant completion
'selectMode': 'pick', // Instant completion
'multiple': true // Tag support, by default comma separated
});
});