2009-05-10 10:50:39 +03:00
< ? php
2008-09-21 09:36:57 +03:00
/*-------------------------------------------------------
*
* 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 Mapper_User extends Mapper {
protected $oUserCurrent = null ;
public function SetUserCurrent ( $oUserCurrent ) {
$this -> oUserCurrent = $oUserCurrent ;
}
public function Add ( UserEntity_User $oUser ) {
2009-08-20 10:43:06 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.user' ) . "
2008-09-21 09:36:57 +03:00
( user_login ,
user_password ,
user_mail ,
user_date_register ,
user_ip_register ,
user_activate ,
user_activate_key
)
VALUES ( ? , ? , ? , ? , ? , ? , ? )
" ;
if ( $iId = $this -> oDb -> query ( $sql , $oUser -> getLogin (), $oUser -> getPassword (), $oUser -> getMail (), $oUser -> getDateRegister (), $oUser -> getIpRegister (), $oUser -> getActivate (), $oUser -> getActivateKey ())) {
return $iId ;
}
return false ;
}
public function Update ( UserEntity_User $oUser ) {
2009-08-20 10:43:06 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.user' ) . "
2008-09-21 09:36:57 +03:00
SET
user_password = ? ,
2009-06-13 00:54:04 +03:00
user_mail = ? ,
user_skill = ? ,
2008-09-21 09:36:57 +03:00
user_date_activate = ? ,
2009-06-13 00:54:04 +03:00
user_date_comment_last = ? ,
2008-09-21 09:36:57 +03:00
user_rating = ? ,
user_count_vote = ? ,
user_activate = ? ,
user_profile_name = ? ,
user_profile_sex = ? ,
user_profile_country = ? ,
user_profile_region = ? ,
user_profile_city = ? ,
user_profile_birthday = ? ,
user_profile_site = ? ,
user_profile_site_name = ? ,
user_profile_icq = ? ,
user_profile_about = ? ,
user_profile_date = ? ,
user_profile_avatar = ? ,
2008-10-14 21:36:36 +03:00
user_profile_avatar_type = ? ,
2009-01-14 23:12:35 +02:00
user_profile_foto = ? ,
2008-10-14 21:36:36 +03:00
user_settings_notice_new_topic = ? ,
user_settings_notice_new_comment = ? ,
user_settings_notice_new_talk = ? ,
2008-10-28 21:24:35 +02:00
user_settings_notice_reply_comment = ? ,
user_settings_notice_new_friend = ?
2008-09-21 09:36:57 +03:00
WHERE user_id = ?
" ;
if ( $this -> oDb -> query ( $sql , $oUser -> getPassword (),
2009-06-13 00:54:04 +03:00
$oUser -> getMail (),
$oUser -> getSkill (),
2008-09-21 09:36:57 +03:00
$oUser -> getDateActivate (),
2009-06-13 00:54:04 +03:00
$oUser -> getDateCommentLast (),
2008-09-21 09:36:57 +03:00
$oUser -> getRating (),
$oUser -> getCountVote (),
$oUser -> getActivate (),
$oUser -> getProfileName (),
$oUser -> getProfileSex (),
$oUser -> getProfileCountry (),
$oUser -> getProfileRegion (),
$oUser -> getProfileCity (),
$oUser -> getProfileBirthday (),
$oUser -> getProfileSite (),
$oUser -> getProfileSiteName (),
$oUser -> getProfileIcq (),
$oUser -> getProfileAbout (),
$oUser -> getProfileDate (),
$oUser -> getProfileAvatar (),
2008-10-14 21:36:36 +03:00
$oUser -> getProfileAvatarType (),
2009-01-14 23:12:35 +02:00
$oUser -> getProfileFoto (),
2008-10-14 21:36:36 +03:00
$oUser -> getSettingsNoticeNewTopic (),
$oUser -> getSettingsNoticeNewComment (),
$oUser -> getSettingsNoticeNewTalk (),
2008-10-28 21:24:35 +02:00
$oUser -> getSettingsNoticeReplyComment (),
$oUser -> getSettingsNoticeNewFriend (),
2008-09-21 09:36:57 +03:00
$oUser -> getId ())) {
return true ;
}
return false ;
}
2009-06-13 00:54:04 +03:00
public function GetUserBySessionKey ( $sKey ) {
$sql = " SELECT
s . user_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.session'). " as s
2009-06-13 00:54:04 +03:00
WHERE
s . session_key = ?
" ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sKey )) {
return $aRow [ 'user_id' ];
}
return null ;
}
public function CreateSession ( UserEntity_Session $oSession ) {
2009-08-20 15:50:14 +03:00
$sql = " REPLACE INTO " . Config :: Get ( 'db.table.session' ) . "
2009-06-13 00:54:04 +03:00
SET
session_key = ? ,
user_id = ? ,
session_ip_create = ? ,
session_ip_last = ? ,
session_date_create = ? ,
session_date_last = ?
" ;
return $this -> oDb -> query ( $sql , $oSession -> getKey (), $oSession -> getUserId (), $oSession -> getIpCreate (), $oSession -> getIpLast (), $oSession -> getDateCreate (), $oSession -> getDateLast ());
}
public function UpdateSession ( UserEntity_Session $oSession ) {
2009-08-20 15:50:14 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.session' ) . "
2009-06-13 00:54:04 +03:00
SET
session_ip_last = ? ,
session_date_last = ?
WHERE user_id = ?
" ;
return $this -> oDb -> query ( $sql , $oSession -> getIpLast (), $oSession -> getDateLast (), $oSession -> getUserId ());
}
public function GetSessionsByArrayId ( $aArrayId ) {
if ( ! is_array ( $aArrayId ) or count ( $aArrayId ) == 0 ) {
return array ();
}
$sql = " SELECT
s .*
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.session'). " as s
2009-06-13 00:54:04 +03:00
WHERE
s . user_id IN ( ? a ) " ;
$aRes = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $aArrayId )) {
foreach ( $aRows as $aRow ) {
$aRes [] = new UserEntity_Session ( $aRow );
}
}
return $aRes ;
}
2009-05-29 18:32:37 +03:00
public function GetUsersByArrayId ( $aArrayId ) {
if ( ! is_array ( $aArrayId ) or count ( $aArrayId ) == 0 ) {
return array ();
}
$sql = " SELECT
u .* ,
IF ( ua . user_id IS NULL , 0 , 1 ) as user_is_administrator
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). " as u
2009-08-20 15:50:14 +03:00
LEFT JOIN " .Config::Get('db.table.user_administrator'). " AS ua ON u . user_id = ua . user_id
2009-05-29 18:32:37 +03:00
WHERE
u . user_id IN ( ? a )
ORDER BY FIELD ( u . user_id , ? a ) " ;
$aUsers = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $aArrayId , $aArrayId )) {
foreach ( $aRows as $aUser ) {
$aUsers [] = new UserEntity_User ( $aUser );
}
}
return $aUsers ;
}
2008-09-21 09:36:57 +03:00
2009-02-07 15:04:44 +02:00
public function GetUserByActivateKey ( $sKey ) {
$sql = " SELECT
2009-05-29 18:32:37 +03:00
u . user_id
2009-02-07 15:04:44 +02:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). " as u
2009-02-07 15:04:44 +02:00
WHERE u . user_activate_key = ? " ;
2008-09-21 09:36:57 +03:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sKey )) {
2009-05-29 18:32:37 +03:00
return $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
return null ;
}
2009-06-13 00:54:04 +03:00
2009-02-07 15:04:44 +02:00
public function GetUserByMail ( $sMail ) {
$sql = " SELECT
2009-05-29 18:32:37 +03:00
u . user_id
2009-02-07 15:04:44 +02:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). " as u
2009-02-07 15:04:44 +02:00
WHERE u . user_mail = ? " ;
2009-05-29 18:32:37 +03:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sMail )) {
return $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
return null ;
}
2009-05-29 18:32:37 +03:00
public function GetUserByLogin ( $sLogin ) {
2008-09-21 09:36:57 +03:00
$sql = " SELECT
2009-05-29 18:32:37 +03:00
u . user_id
2008-09-21 09:36:57 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). " as u
2008-09-21 09:36:57 +03:00
WHERE
2008-10-26 17:51:03 +02:00
u . user_login = ? " ;
2009-05-29 18:32:37 +03:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sLogin )) {
return $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
return null ;
}
public function GetUsersByDateLast ( $iLimit ) {
$sql = " SELECT
2009-06-13 00:54:04 +03:00
user_id
2008-09-21 09:36:57 +03:00
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.session'). "
2008-09-21 09:36:57 +03:00
ORDER BY
2009-06-13 00:54:04 +03:00
session_date_last DESC
2008-09-21 09:36:57 +03:00
LIMIT 0 , ? d
" ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $iLimit )) {
foreach ( $aRows as $aRow ) {
2009-06-13 00:54:04 +03:00
$aReturn [] = $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
}
return $aReturn ;
}
public function GetUsersByDateRegister ( $iLimit ) {
$sql = " SELECT
2009-06-13 00:54:04 +03:00
user_id
2008-09-21 09:36:57 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). "
2008-09-21 09:36:57 +03:00
WHERE
user_activate = 1
ORDER BY
2009-06-13 00:54:04 +03:00
user_id DESC
2008-09-21 09:36:57 +03:00
LIMIT 0 , ? d
" ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $iLimit )) {
foreach ( $aRows as $aRow ) {
2009-06-13 00:54:04 +03:00
$aReturn [] = $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
}
return $aReturn ;
}
public function GetUsersRating ( $sType , & $iCount , $iCurrPage , $iPerPage ) {
$sql = " SELECT
2009-06-13 00:54:04 +03:00
user_id
2008-09-21 09:36:57 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). "
2008-09-21 09:36:57 +03:00
WHERE
user_rating " .( $sType =='good' ? '>=0' : '<0'). " and user_activate = 1
ORDER BY
user_rating " .( $sType =='good' ? 'DESC' : 'ASC'). " , user_skill desc
LIMIT ? d , ? d
" ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> selectPage ( $iCount , $sql ,( $iCurrPage - 1 ) * $iPerPage , $iPerPage )) {
foreach ( $aRows as $aRow ) {
2009-06-13 00:54:04 +03:00
$aReturn [] = $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
}
return $aReturn ;
}
public function GetCountUsers () {
2009-08-20 10:43:06 +03:00
$sql = " SELECT count(user_id) as count FROM " . Config :: Get ( 'db.table.user' ) . " WHERE user_activate = 1 " ;
2008-09-21 09:36:57 +03:00
$result = $this -> oDb -> selectRow ( $sql );
return $result [ 'count' ];
}
public function GetCountUsersActive ( $sDateActive ) {
2009-08-20 15:50:14 +03:00
$sql = " SELECT count(user_id) as count FROM " . Config :: Get ( 'db.table.session' ) . " WHERE session_date_last >= ? " ;
2008-09-21 09:36:57 +03:00
$result = $this -> oDb -> selectRow ( $sql , $sDateActive );
return $result [ 'count' ];
}
public function GetCountUsersSex () {
2009-08-20 10:43:06 +03:00
$sql = " SELECT user_profile_sex AS ARRAY_KEY, count(user_id) as count FROM " . Config :: Get ( 'db.table.user' ) . " WHERE user_activate = 1 GROUP BY user_profile_sex " ;
2008-09-21 09:36:57 +03:00
$result = $this -> oDb -> select ( $sql );
return $result ;
}
2008-11-01 08:16:18 +02:00
public function GetCountUsersCountry ( $sLimit ) {
$sql = "
SELECT
cu . count ,
c . country_name as name
FROM (
SELECT
count ( user_id ) as count ,
country_id
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.country_user'). "
2009-01-18 22:38:45 +02:00
GROUP BY country_id LIMIT 0 , ? d
2008-11-01 08:16:18 +02:00
) as cu
2009-08-20 15:50:14 +03:00
JOIN " .Config::Get('db.table.country'). " as c on cu . country_id = c . country_id
2009-01-18 22:38:45 +02:00
ORDER BY c . country_name
2008-11-01 08:16:18 +02:00
" ;
$result = $this -> oDb -> select ( $sql , $sLimit );
2008-09-21 09:36:57 +03:00
return $result ;
}
2008-11-01 08:16:18 +02:00
public function GetCountUsersCity ( $sLimit ) {
$sql = "
SELECT
cu . count ,
c . city_name as name
FROM (
SELECT
count ( user_id ) as count ,
city_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.city_user'). "
2009-01-18 22:38:45 +02:00
GROUP BY city_id LIMIT 0 , ? d
2008-11-01 08:16:18 +02:00
) as cu
2009-08-20 15:50:14 +03:00
JOIN " .Config::Get('db.table.city'). " as c on cu . city_id = c . city_id
2009-01-18 22:38:45 +02:00
ORDER BY c . city_name
2008-11-01 08:16:18 +02:00
" ;
$result = $this -> oDb -> select ( $sql , $sLimit );
2008-09-21 09:36:57 +03:00
return $result ;
}
2008-10-26 17:51:03 +02:00
public function GetUsersByLoginLike ( $sUserLogin , $iLimit ) {
2008-09-21 09:36:57 +03:00
$sql = " SELECT
2009-06-13 00:54:04 +03:00
user_id
2008-09-21 09:36:57 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). "
2008-09-21 09:36:57 +03:00
WHERE
2009-06-13 00:54:04 +03:00
user_activate = 1
and
user_login LIKE ?
2008-09-21 09:36:57 +03:00
LIMIT 0 , ? d
" ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sUserLogin . '%' , $iLimit )) {
foreach ( $aRows as $aRow ) {
2009-06-13 00:54:04 +03:00
$aReturn [] = $aRow [ 'user_id' ];
2008-09-21 09:36:57 +03:00
}
}
return $aReturn ;
}
2009-06-13 14:32:06 +03:00
public function AddFriend ( UserEntity_Friend $oFriend ) {
2009-08-20 10:43:06 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.friend' ) . "
2008-09-21 09:36:57 +03:00
( user_id ,
2009-06-13 14:32:06 +03:00
user_friend_id
2008-09-21 09:36:57 +03:00
)
VALUES ( ? d , ? d )
" ;
2009-06-13 14:32:06 +03:00
if ( $this -> oDb -> query ( $sql , $oFriend -> getUserId (), $oFriend -> getFriendId ()) === 0 )
2008-09-21 09:36:57 +03:00
{
return true ;
}
return false ;
}
2009-06-13 14:32:06 +03:00
public function DeleteFriend ( UserEntity_Friend $oFriend ) {
2009-08-20 10:43:06 +03:00
$sql = " DELETE FROM " . Config :: Get ( 'db.table.friend' ) . "
2008-09-21 09:36:57 +03:00
WHERE
user_id = ? d
AND
2009-06-13 14:32:06 +03:00
user_friend_id = ? d
2008-09-21 09:36:57 +03:00
" ;
2009-06-13 14:32:06 +03:00
if ( $this -> oDb -> query ( $sql , $oFriend -> getUserId (), $oFriend -> getFriendId ()))
2008-09-21 09:36:57 +03:00
{
return true ;
}
return false ;
}
2009-06-13 14:32:06 +03:00
public function GetFriendsByArrayId ( $aArrayId , $sUserId ) {
if ( ! is_array ( $aArrayId ) or count ( $aArrayId ) == 0 ) {
return array ();
2008-09-21 09:36:57 +03:00
}
2009-06-13 14:32:06 +03:00
$sql = " SELECT
*
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.friend'). "
2009-06-13 14:32:06 +03:00
WHERE
user_id = ?
AND
user_friend_id IN ( ? a ) " ;
$aRes = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sUserId , $aArrayId )) {
foreach ( $aRows as $aRow ) {
$aRes [] = new UserEntity_Friend ( $aRow );
}
}
return $aRes ;
2008-09-21 09:36:57 +03:00
}
2009-06-13 14:32:06 +03:00
public function GetUsersFriend ( $sUserId ) {
2008-09-21 09:36:57 +03:00
$sql = " SELECT
2009-06-13 14:32:06 +03:00
uf . user_friend_id
2008-09-21 09:36:57 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.friend'). " as uf
2008-09-21 09:36:57 +03:00
WHERE
2009-06-13 14:32:06 +03:00
uf . user_id = ? d ;
2008-09-21 09:36:57 +03:00
" ;
$aUsers = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sUserId )) {
foreach ( $aRows as $aUser ) {
2009-06-13 14:32:06 +03:00
$aUsers [] = $aUser [ 'user_friend_id' ];
2008-09-21 09:36:57 +03:00
}
}
return $aUsers ;
}
2008-09-28 23:07:57 +03:00
2009-06-13 14:32:06 +03:00
public function GetUsersSelfFriend ( $sUserId ) {
2008-09-28 23:07:57 +03:00
$sql = " SELECT
2009-06-27 18:05:17 +03:00
user_id
2008-09-28 23:07:57 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.friend'). "
2008-09-28 23:07:57 +03:00
WHERE
2009-06-27 18:05:17 +03:00
user_friend_id = ? d " ;
2008-09-28 23:07:57 +03:00
$aUsers = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sUserId )) {
foreach ( $aRows as $aUser ) {
2009-06-27 18:05:17 +03:00
$aUsers [] = $aUser [ 'user_id' ];
2008-09-28 23:07:57 +03:00
}
}
return $aUsers ;
}
2008-10-11 17:51:38 +03:00
public function GetInviteByCode ( $sCode , $iUsed = 0 ) {
2009-08-20 10:43:06 +03:00
$sql = " SELECT * FROM " . Config :: Get ( 'db.table.invite' ) . " WHERE invite_code = ? and invite_used = ?d " ;
2008-10-11 17:51:38 +03:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sCode , $iUsed )) {
return new UserEntity_Invite ( $aRow );
}
return null ;
}
public function AddInvite ( UserEntity_Invite $oInvite ) {
2009-08-20 10:43:06 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.invite' ) . "
2008-10-11 17:51:38 +03:00
( invite_code ,
user_from_id ,
invite_date_add
)
VALUES ( ? , ? , ? )
" ;
if ( $iId = $this -> oDb -> query ( $sql , $oInvite -> getCode (), $oInvite -> getUserFromId (), $oInvite -> getDateAdd ())) {
return $iId ;
}
return false ;
}
public function UpdateInvite ( UserEntity_Invite $oInvite ) {
2009-08-20 10:43:06 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.invite' ) . "
2008-10-11 17:51:38 +03:00
SET
user_to_id = ? ,
invite_date_used = ? ,
invite_used = ?
WHERE invite_id = ?
" ;
if ( $this -> oDb -> query ( $sql , $oInvite -> getUserToId (), $oInvite -> getDateUsed (), $oInvite -> getUsed (), $oInvite -> getId ())) {
return true ;
}
return false ;
}
2008-10-16 07:29:15 +03:00
public function GetCountInviteUsedByDate ( $sUserIdFrom , $sDate ) {
2009-08-20 10:43:06 +03:00
$sql = " SELECT count(invite_id) as count FROM " . Config :: Get ( 'db.table.invite' ) . " WHERE user_from_id = ?d and invite_date_add >= ? " ;
2008-10-16 07:29:15 +03:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sUserIdFrom , $sDate )) {
return $aRow [ 'count' ];
}
return 0 ;
}
public function GetCountInviteUsed ( $sUserIdFrom ) {
2009-08-20 10:43:06 +03:00
$sql = " SELECT count(invite_id) as count FROM " . Config :: Get ( 'db.table.invite' ) . " WHERE user_from_id = ?d " ;
2008-10-16 07:29:15 +03:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sUserIdFrom )) {
return $aRow [ 'count' ];
}
return 0 ;
}
public function GetUsersInvite ( $sUserId ) {
$sql = " SELECT
2009-06-13 14:32:06 +03:00
i . user_to_id
2008-10-16 07:29:15 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.invite'). " as i
2008-10-16 07:29:15 +03:00
WHERE
2009-06-13 14:32:06 +03:00
i . user_from_id = ? d " ;
2008-10-16 07:29:15 +03:00
$aUsers = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sUserId )) {
foreach ( $aRows as $aUser ) {
2009-06-13 14:32:06 +03:00
$aUsers [] = $aUser [ 'user_to_id' ];
2008-10-16 07:29:15 +03:00
}
}
return $aUsers ;
}
public function GetUserInviteFrom ( $sUserIdTo ) {
$sql = " SELECT
2009-06-13 14:32:06 +03:00
i . user_from_id
2008-10-16 07:29:15 +03:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.invite'). " as i
2008-10-16 07:29:15 +03:00
WHERE
2009-06-13 14:32:06 +03:00
i . user_to_id = ? d
2008-10-16 07:29:15 +03:00
LIMIT 0 , 1 ;
" ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sUserIdTo )) {
2009-06-13 14:32:06 +03:00
return $aRow [ 'user_from_id' ];
2008-10-16 07:29:15 +03:00
}
return null ;
}
2008-11-01 08:16:18 +02:00
public function SetCountryUser ( $sCountryId , $sUserId ) {
2009-08-20 10:43:06 +03:00
$sql = " REPLACE " . Config :: Get ( 'db.table.country_user' ) . "
2008-11-01 08:16:18 +02:00
SET
country_id = ? ,
user_id = ?
" ;
return $this -> oDb -> query ( $sql , $sCountryId , $sUserId );
}
public function GetCountryByName ( $sName ) {
2009-08-20 10:43:06 +03:00
$sql = " SELECT * FROM " . Config :: Get ( 'db.table.country' ) . " WHERE country_name = ? " ;
2008-11-01 08:16:18 +02:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sName )) {
return new UserEntity_Country ( $aRow );
}
return null ;
}
2009-01-24 00:46:27 +02:00
public function GetUsersByCountry ( $sCountry , & $iCount , $iCurrPage , $iPerPage ) {
$sql = "
2009-06-13 00:54:04 +03:00
SELECT cu . user_id
2009-01-24 00:46:27 +02:00
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.country'). " as c ,
" .Config::Get('db.table.country_user'). " as cu
2009-01-24 00:46:27 +02:00
WHERE
c . country_name = ?
AND
2009-06-13 00:54:04 +03:00
c . country_id = cu . country_id
ORDER BY cu . user_id DESC
2009-01-24 00:46:27 +02:00
LIMIT ? d , ? d " ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> selectPage ( $iCount , $sql , $sCountry ,( $iCurrPage - 1 ) * $iPerPage , $iPerPage )) {
foreach ( $aRows as $aRow ) {
2009-06-13 00:54:04 +03:00
$aReturn [] = $aRow [ 'user_id' ];
2009-01-24 00:46:27 +02:00
}
}
return $aReturn ;
}
public function GetUsersByCity ( $sCity , & $iCount , $iCurrPage , $iPerPage ) {
$sql = "
2009-06-13 00:54:04 +03:00
SELECT cu . user_id
2009-01-24 00:46:27 +02:00
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.city'). " as c ,
" .Config::Get('db.table.city_user'). " as cu
2009-01-24 00:46:27 +02:00
WHERE
c . city_name = ?
AND
2009-06-13 00:54:04 +03:00
c . city_id = cu . city_id
ORDER BY cu . user_id DESC
2009-01-24 00:46:27 +02:00
LIMIT ? d , ? d " ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> selectPage ( $iCount , $sql , $sCity ,( $iCurrPage - 1 ) * $iPerPage , $iPerPage )) {
foreach ( $aRows as $aRow ) {
2009-06-13 00:54:04 +03:00
$aReturn [] = $aRow [ 'user_id' ];
2009-01-24 00:46:27 +02:00
}
}
return $aReturn ;
}
2008-11-01 08:16:18 +02:00
public function AddCountry ( UserEntity_Country $oCountry ) {
2009-08-20 10:43:06 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.country' ) . "
2008-11-01 08:16:18 +02:00
( country_name )
VALUES ( ? )
" ;
if ( $iId = $this -> oDb -> query ( $sql , $oCountry -> getName ())) {
return $iId ;
}
return false ;
}
public function SetCityUser ( $sCityId , $sUserId ) {
2009-08-20 15:50:14 +03:00
$sql = " REPLACE " . Config :: Get ( 'db.table.city_user' ) . "
2008-11-01 08:16:18 +02:00
SET
city_id = ? ,
user_id = ?
" ;
return $this -> oDb -> query ( $sql , $sCityId , $sUserId );
}
public function GetCityByName ( $sName ) {
2009-08-20 15:50:14 +03:00
$sql = " SELECT * FROM " . Config :: Get ( 'db.table.city' ) . " WHERE city_name = ? " ;
2008-11-01 08:16:18 +02:00
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sName )) {
return new UserEntity_City ( $aRow );
}
return null ;
}
public function AddCity ( UserEntity_City $oCity ) {
2009-08-20 15:50:14 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.city' ) . "
2008-11-01 08:16:18 +02:00
( city_name )
VALUES ( ? )
" ;
if ( $iId = $this -> oDb -> query ( $sql , $oCity -> getName ())) {
return $iId ;
}
return false ;
}
public function GetCityByNameLike ( $sName , $iLimit ) {
$sql = " SELECT
*
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.city'). "
2008-11-01 08:16:18 +02:00
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
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.country'). "
2008-11-01 08:16:18 +02:00
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 ;
}
2008-11-29 12:50:49 +02:00
public function AddReminder ( UserEntity_Reminder $oReminder ) {
2009-08-20 10:43:06 +03:00
$sql = " REPLACE " . Config :: Get ( 'db.table.reminder' ) . "
2008-11-29 12:50:49 +02:00
SET
reminder_code = ? ,
user_id = ? ,
reminder_date_add = ? ,
reminder_date_used = ? ,
reminder_date_expire = ? ,
reminde_is_used = ?
" ;
return $this -> oDb -> query ( $sql , $oReminder -> getCode (), $oReminder -> getUserId (), $oReminder -> getDateAdd (), $oReminder -> getDateUsed (), $oReminder -> getDateExpire (), $oReminder -> getIsUsed ());
}
public function UpdateReminder ( UserEntity_Reminder $oReminder ) {
return $this -> AddReminder ( $oReminder );
}
public function GetReminderByCode ( $sCode ) {
$sql = " SELECT
*
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.reminder'). "
2008-11-29 12:50:49 +02:00
WHERE
reminder_code = ? " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sCode )) {
return new UserEntity_Reminder ( $aRow );
}
return null ;
}
2008-09-21 09:36:57 +03:00
}
?>