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
*
---------------------------------------------------------
*/
2010-05-27 23:40:30 +03:00
class ModuleUser_MapperUser extends Mapper {
2008-09-21 09:36:57 +03:00
protected $oUserCurrent = null ;
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function SetUserCurrent ( $oUserCurrent ) {
$this -> oUserCurrent = $oUserCurrent ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function Add ( ModuleUser_EntityUser $oUser ) {
2011-06-22 12:11:05 +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 ( ? , ? , ? , ? , ? , ? , ? )
2011-06-22 12:11:05 +03:00
" ;
2008-09-21 09:36:57 +03:00
if ( $iId = $this -> oDb -> query ( $sql , $oUser -> getLogin (), $oUser -> getPassword (), $oUser -> getMail (), $oUser -> getDateRegister (), $oUser -> getIpRegister (), $oUser -> getActivate (), $oUser -> getActivateKey ())) {
return $iId ;
2011-06-22 12:11:05 +03:00
}
2008-09-21 09:36:57 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function Update ( ModuleUser_EntityUser $oUser ) {
2011-06-22 12:11:05 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.user' ) . "
SET
2008-09-21 09:36:57 +03:00
user_password = ? ,
2011-06-22 12:11:05 +03:00
user_mail = ? ,
user_skill = ? ,
2008-09-21 09:36:57 +03:00
user_date_activate = ? ,
2011-06-22 12:11:05 +03:00
user_date_comment_last = ? ,
2008-09-21 09:36:57 +03:00
user_rating = ? ,
user_count_vote = ? ,
2011-06-22 12:11:05 +03:00
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 = ? ,
2008-09-21 09:36:57 +03:00
user_profile_about = ? ,
user_profile_date = ? ,
user_profile_avatar = ? ,
2011-06-22 12:11:05 +03: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 = ? ,
2011-06-22 12:11:05 +03:00
user_settings_notice_new_friend = ?
2008-09-21 09:36:57 +03:00
WHERE user_id = ?
2011-06-22 12:11:05 +03:00
" ;
2008-09-21 09:36:57 +03:00
if ( $this -> oDb -> query ( $sql , $oUser -> getPassword (),
2011-06-22 12:11:05 +03:00
$oUser -> getMail (),
$oUser -> getSkill (),
2008-09-21 09:36:57 +03:00
$oUser -> getDateActivate (),
2011-06-22 12:11:05 +03:00
$oUser -> getDateCommentLast (),
2008-09-21 09:36:57 +03:00
$oUser -> getRating (),
$oUser -> getCountVote (),
2011-06-22 12:11:05 +03:00
$oUser -> getActivate (),
2008-09-21 09:36:57 +03:00
$oUser -> getProfileName (),
$oUser -> getProfileSex (),
$oUser -> getProfileCountry (),
$oUser -> getProfileRegion (),
$oUser -> getProfileCity (),
$oUser -> getProfileBirthday (),
$oUser -> getProfileSite (),
$oUser -> getProfileSiteName (),
$oUser -> getProfileIcq (),
2011-06-22 12:11:05 +03:00
$oUser -> getProfileAbout (),
$oUser -> getProfileDate (),
2009-10-13 11:39:30 +03:00
$oUser -> getProfileAvatar (),
2009-01-14 23:12:35 +02:00
$oUser -> getProfileFoto (),
2008-10-14 21:36:36 +03:00
$oUser -> getSettingsNoticeNewTopic (),
$oUser -> getSettingsNoticeNewComment (),
$oUser -> getSettingsNoticeNewTalk (),
2011-06-22 12:11:05 +03:00
$oUser -> getSettingsNoticeReplyComment (),
$oUser -> getSettingsNoticeNewFriend (),
2008-09-21 09:36:57 +03:00
$oUser -> getId ())) {
return true ;
2011-06-22 12:11:05 +03:00
}
2008-09-21 09:36:57 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
2009-06-13 00:54:04 +03:00
public function GetUserBySessionKey ( $sKey ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
s . user_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.session'). " as s
2011-06-22 12:11:05 +03:00
WHERE
s . session_key = ?
2009-06-13 00:54:04 +03:00
" ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sKey )) {
return $aRow [ 'user_id' ];
}
return null ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function CreateSession ( ModuleUser_EntitySession $oSession ) {
2011-06-22 12:11:05 +03:00
$sql = " REPLACE INTO " . Config :: Get ( 'db.table.session' ) . "
SET
2009-06-13 00:54:04 +03:00
session_key = ? ,
user_id = ? ,
session_ip_create = ? ,
session_ip_last = ? ,
2011-06-22 12:11:05 +03:00
session_date_create = ? ,
session_date_last = ?
" ;
2009-06-13 00:54:04 +03:00
return $this -> oDb -> query ( $sql , $oSession -> getKey (), $oSession -> getUserId (), $oSession -> getIpCreate (), $oSession -> getIpLast (), $oSession -> getDateCreate (), $oSession -> getDateLast ());
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function UpdateSession ( ModuleUser_EntitySession $oSession ) {
2011-06-22 12:11:05 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.session' ) . "
SET
session_ip_last = ? ,
session_date_last = ?
2009-06-13 00:54:04 +03:00
WHERE user_id = ?
2011-06-22 12:11:05 +03:00
" ;
2009-06-13 00:54:04 +03:00
return $this -> oDb -> query ( $sql , $oSession -> getIpLast (), $oSession -> getDateLast (), $oSession -> getUserId ());
}
2011-06-22 12:11:05 +03:00
2009-06-13 00:54:04 +03:00
public function GetSessionsByArrayId ( $aArrayId ) {
if ( ! is_array ( $aArrayId ) or count ( $aArrayId ) == 0 ) {
return array ();
}
2011-06-22 12:11:05 +03:00
$sql = " SELECT
s .*
FROM
" .Config::Get('db.table.session'). " as s
WHERE
2009-06-13 00:54:04 +03:00
s . user_id IN ( ? a ) " ;
$aRes = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $aArrayId )) {
foreach ( $aRows as $aRow ) {
2009-09-08 15:02:51 +03:00
$aRes [] = Engine :: GetEntity ( 'User_Session' , $aRow );
2009-06-13 00:54:04 +03:00
}
2011-06-22 12:11:05 +03:00
}
2009-06-13 00:54:04 +03:00
return $aRes ;
}
2011-06-22 12:11:05 +03:00
2009-05-29 18:32:37 +03:00
public function GetUsersByArrayId ( $aArrayId ) {
if ( ! is_array ( $aArrayId ) or count ( $aArrayId ) == 0 ) {
return array ();
}
2011-06-22 12:11:05 +03:00
$sql = " SELECT
2009-05-29 18:32:37 +03:00
u .* ,
2011-06-22 12:11:05 +03:00
IF ( ua . user_id IS NULL , 0 , 1 ) as user_is_administrator
FROM
" .Config::Get('db.table.user'). " as u
LEFT JOIN " .Config::Get('db.table.user_administrator'). " AS ua ON u . user_id = ua . user_id
WHERE
u . user_id IN ( ? a )
2009-05-29 18:32:37 +03:00
ORDER BY FIELD ( u . user_id , ? a ) " ;
$aUsers = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $aArrayId , $aArrayId )) {
foreach ( $aRows as $aUser ) {
2009-09-08 15:02:51 +03:00
$aUsers [] = Engine :: GetEntity ( 'User' , $aUser );
2009-05-29 18:32:37 +03:00
}
2011-06-22 12:11:05 +03:00
}
2009-05-29 18:32:37 +03:00
return $aUsers ;
}
2011-06-22 12:11:05 +03:00
public function GetUserByActivateKey ( $sKey ) {
$sql = " SELECT
2009-05-29 18:32:37 +03:00
u . user_id
2011-06-22 12:11:05 +03:00
FROM
" .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 ;
}
2011-06-22 12:11:05 +03:00
public function GetUserByMail ( $sMail ) {
$sql = " SELECT
2009-05-29 18:32:37 +03:00
u . user_id
2011-06-22 12:11:05 +03:00
FROM
" .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 ;
}
2011-06-22 12:11:05 +03:00
public function GetUserByLogin ( $sLogin ) {
$sql = " SELECT
u . user_id
FROM
" .Config::Get('db.table.user'). " as u
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 ;
}
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function GetUsersByDateLast ( $iLimit ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
user_id
FROM
" .Config::Get('db.table.session'). "
ORDER BY
session_date_last DESC
LIMIT 0 , ? d
" ;
2008-09-21 09:36:57 +03:00
$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 ;
}
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function GetUsersByDateRegister ( $iLimit ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
user_id
FROM
" .Config::Get('db.table.user'). "
2008-09-21 09:36:57 +03:00
WHERE
2011-06-22 12:11:05 +03:00
user_activate = 1
ORDER BY
user_id DESC
LIMIT 0 , ? d
" ;
2008-09-21 09:36:57 +03:00
$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 ;
}
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function GetUsersRating ( $sType , & $iCount , $iCurrPage , $iPerPage ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
user_id
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.user'). "
2011-06-22 12:11:05 +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
" ;
2008-09-21 09:36:57 +03:00
$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 ;
}
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function GetCountUsers () {
2012-02-16 18:07:43 +02:00
$sql = " SELECT count(*) 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' ];
}
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function GetCountUsersActive ( $sDateActive ) {
2012-02-16 18:07:43 +02:00
$sql = " SELECT count(*) 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' ];
}
2011-06-22 12:11:05 +03:00
2008-09-21 09:36:57 +03:00
public function GetCountUsersSex () {
2012-02-16 18:07:43 +02:00
$sql = " SELECT user_profile_sex AS ARRAY_KEY, count(*) 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 ;
}
2011-06-22 12:11:05 +03:00
2008-11-01 08:16:18 +02:00
public function GetCountUsersCountry ( $sLimit ) {
$sql = "
2011-06-22 12:11:05 +03:00
SELECT
2008-11-01 08:16:18 +02:00
cu . count ,
c . country_name as name
2011-06-22 12:11:05 +03:00
FROM (
SELECT
2012-02-16 18:07:43 +02:00
count ( * ) as count ,
2011-06-22 12:11:05 +03:00
country_id
FROM
2009-08-20 10:43:06 +03:00
" .Config::Get('db.table.country_user'). "
2011-06-22 12:11:05 +03:00
GROUP BY country_id ORDER BY count DESC LIMIT 0 , ? d
2008-11-01 08:16:18 +02:00
) as cu
2011-06-22 12:11:05 +03:00
JOIN " .Config::Get('db.table.country'). " as c on cu . country_id = c . country_id
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 ;
}
2011-06-22 12:11:05 +03:00
2008-11-01 08:16:18 +02:00
public function GetCountUsersCity ( $sLimit ) {
$sql = "
2011-06-22 12:11:05 +03:00
SELECT
2008-11-01 08:16:18 +02:00
cu . count ,
c . city_name as name
2011-06-22 12:11:05 +03:00
FROM (
SELECT
2012-02-16 18:07:43 +02:00
count ( * ) as count ,
2011-06-22 12:11:05 +03:00
city_id
FROM
2009-08-20 15:50:14 +03:00
" .Config::Get('db.table.city_user'). "
2010-03-28 23:02:57 +03:00
GROUP BY city_id ORDER BY count DESC LIMIT 0 , ? d
2008-11-01 08:16:18 +02:00
) as cu
2011-06-22 12:11:05 +03:00
JOIN " .Config::Get('db.table.city'). " as c on cu . city_id = c . city_id
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 ;
}
2011-06-22 12:11:05 +03:00
public function GetUsersByLoginLike ( $sUserLogin , $iLimit ) {
$sql = " SELECT
user_id
FROM
" .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
2011-06-22 12:11:05 +03:00
user_login LIKE ?
LIMIT 0 , ? d
" ;
2008-09-21 09:36:57 +03:00
$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 ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function AddFriend ( ModuleUser_EntityFriend $oFriend ) {
2011-06-22 12:11:05 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.friend' ) . "
2009-09-02 23:36:44 +03:00
( user_from ,
user_to ,
status_from ,
2011-06-22 12:11:05 +03:00
status_to
2008-09-21 09:36:57 +03:00
)
2009-09-02 23:36:44 +03:00
VALUES ( ? d , ? d , ? d , ? d )
2011-06-22 12:11:05 +03:00
" ;
2009-09-02 23:36:44 +03:00
if (
$this -> oDb -> query (
$sql ,
$oFriend -> getUserFrom (),
$oFriend -> getUserTo (),
$oFriend -> getStatusFrom (),
$oFriend -> getStatusTo ()
) === 0
) {
2008-09-21 09:36:57 +03:00
return true ;
2011-06-22 12:11:05 +03:00
}
2008-09-21 09:36:57 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function EraseFriend ( ModuleUser_EntityFriend $oFriend ) {
2011-06-22 12:11:05 +03:00
$sql = " DELETE FROM " . Config :: Get ( 'db.table.friend' ) . "
2008-09-21 09:36:57 +03:00
WHERE
2009-09-04 02:40:56 +03:00
user_from = ? d
2008-09-21 09:36:57 +03:00
AND
2011-06-22 12:11:05 +03:00
user_to = ? d
" ;
if ( $this -> oDb -> query ( $sql , $oFriend -> getUserFrom (), $oFriend -> getUserTo ()))
2008-09-21 09:36:57 +03:00
{
return true ;
2011-06-22 12:11:05 +03:00
}
2008-09-21 09:36:57 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function UpdateFriend ( ModuleUser_EntityFriend $oFriend ) {
2009-09-02 23:36:44 +03:00
$sql = "
UPDATE " .Config::Get('db.table.friend'). "
2011-06-22 12:11:05 +03:00
SET
2009-09-02 23:36:44 +03:00
status_from = ? d ,
2011-06-22 12:11:05 +03:00
status_to = ? d
2009-09-02 23:36:44 +03:00
WHERE
user_from = ? d
AND
2011-06-22 12:11:05 +03:00
user_to = ? d
" ;
2009-09-02 23:36:44 +03:00
if (
$this -> oDb -> query (
$sql ,
$oFriend -> getStatusFrom (),
$oFriend -> getStatusTo (),
$oFriend -> getUserFrom (),
$oFriend -> getUserTo ()
)
) {
return true ;
2011-06-22 12:11:05 +03:00
}
2009-09-02 23:36:44 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
2009-09-02 23:36:44 +03:00
/**
* Получить отношей дружбы по массиву идентификаторов
*
* @ param array $aArrayId
* @ param string $sUserId
* @ param int $iStatus
* @ return array
*/
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-09-02 23:36:44 +03:00
2011-06-22 12:11:05 +03:00
$sql = " SELECT
*
FROM
" .Config::Get('db.table.friend'). "
WHERE
2009-09-02 23:36:44 +03:00
( `user_from` = ? d AND `user_to` IN ( ? a ) )
OR
( `user_from` IN ( ? a ) AND `user_to` = ? d )
2011-06-22 12:11:05 +03:00
" ;
2009-09-02 23:36:44 +03:00
$aRows = $this -> oDb -> select (
$sql ,
$sUserId , $aArrayId ,
$aArrayId , $sUserId
2011-06-22 12:11:05 +03:00
);
2009-06-13 14:32:06 +03:00
$aRes = array ();
2009-09-02 23:36:44 +03:00
if ( $aRows ) {
2009-06-13 14:32:06 +03:00
foreach ( $aRows as $aRow ) {
2009-09-02 23:36:44 +03:00
$aRow [ 'user' ] = $sUserId ;
2009-09-08 15:02:51 +03:00
$aRes [] = Engine :: GetEntity ( 'User_Friend' , $aRow );
2009-06-13 14:32:06 +03:00
}
2011-06-22 12:11:05 +03:00
}
2009-06-13 14:32:06 +03:00
return $aRes ;
2008-09-21 09:36:57 +03:00
}
2011-06-22 12:11:05 +03:00
2009-09-02 23:36:44 +03:00
/**
* Получить список друзей указанного пользователя
*
* @ param string $sUserId
* @ param int $iStatus
* @ return array
*/
2010-03-06 23:17:40 +02:00
public function GetUsersFriend ( $sUserId ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
2009-09-02 23:36:44 +03:00
uf . user_from ,
2011-06-22 12:11:05 +03:00
uf . user_to
FROM
" .Config::Get('db.table.friend'). " as uf
WHERE
2009-09-02 23:36:44 +03:00
( uf . user_from = ? d
OR
uf . user_to = ? d )
2011-06-22 12:11:05 +03:00
AND
( uf . status_from + uf . status_to = ? d
2010-03-06 23:17:40 +02:00
OR
( uf . status_from = ? d AND uf . status_to = ? d )
)
2009-09-02 23:36:44 +03:00
; " ;
$aUsers = array ();
if ( $aRows = $this -> oDb -> select (
$sql ,
$sUserId ,
$sUserId ,
2010-05-27 17:02:43 +03:00
ModuleUser :: USER_FRIEND_ACCEPT + ModuleUser :: USER_FRIEND_OFFER ,
ModuleUser :: USER_FRIEND_ACCEPT ,
2011-06-22 12:11:05 +03:00
ModuleUser :: USER_FRIEND_ACCEPT
2009-09-02 23:36:44 +03:00
)
) {
foreach ( $aRows as $aUser ) {
$aUsers [] = ( $aUser [ 'user_from' ] == $sUserId )
? $aUser [ 'user_to' ]
: $aUser [ 'user_from' ];
}
}
return array_unique ( $aUsers );
}
2011-06-22 12:11:05 +03:00
2009-09-02 23:36:44 +03:00
/**
* Получить список заявок на добавление в друзья от указанного пользователя
*
* @ param string $sUserId
* @ param int $iStatus Статус запроса с о стороны добавляемого
* @ return array
*/
2010-05-27 17:02:43 +03:00
public function GetUsersFriendOffer ( $sUserId , $iStatus = ModuleUser :: USER_FRIEND_NULL ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
uf . user_to
FROM
" .Config::Get('db.table.friend'). " as uf
WHERE
2009-09-02 23:36:44 +03:00
uf . user_from = ? d
2011-06-22 12:11:05 +03:00
AND
2009-09-02 23:36:44 +03:00
uf . status_from = ? d
AND
uf . status_to = ? d
; " ;
2008-09-21 09:36:57 +03:00
$aUsers = array ();
2009-09-02 23:36:44 +03:00
if ( $aRows = $this -> oDb -> select (
$sql ,
$sUserId ,
2010-05-27 17:02:43 +03:00
ModuleUser :: USER_FRIEND_OFFER ,
2011-06-22 12:11:05 +03:00
$iStatus
2009-09-02 23:36:44 +03:00
)
) {
2008-09-21 09:36:57 +03:00
foreach ( $aRows as $aUser ) {
2009-09-02 23:36:44 +03:00
$aUsers [] = $aUser [ 'user_to' ];
2008-09-21 09:36:57 +03:00
}
}
return $aUsers ;
}
2011-06-22 12:11:05 +03:00
2009-09-02 23:36:44 +03:00
/**
* Получить список заявок на добавление в друзья от указанного пользователя
*
* @ param string $sUserId
* @ param int $iStatus Статус запроса с о стороны самого пользователя
* @ return array
*/
2010-05-27 17:02:43 +03:00
public function GetUserSelfFriendOffer ( $sUserId , $iStatus = ModuleUser :: USER_FRIEND_NULL ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
2009-09-02 23:36:44 +03:00
uf . user_from
2011-06-22 12:11:05 +03:00
FROM
" .Config::Get('db.table.friend'). " as uf
WHERE
2009-09-02 23:36:44 +03:00
uf . user_to = ? d
2011-06-22 12:11:05 +03:00
AND
2009-09-02 23:36:44 +03:00
uf . status_from = ? d
AND
uf . status_to = ? d
; " ;
2008-09-28 23:07:57 +03:00
$aUsers = array ();
2009-09-02 23:36:44 +03:00
if ( $aRows = $this -> oDb -> select (
$sql ,
$sUserId ,
2010-05-27 17:02:43 +03:00
ModuleUser :: USER_FRIEND_OFFER ,
2011-06-22 12:11:05 +03:00
$iStatus
2009-09-02 23:36:44 +03:00
)
) {
2008-09-28 23:07:57 +03:00
foreach ( $aRows as $aUser ) {
2009-09-02 23:36:44 +03:00
$aUsers [] = $aUser [ 'user_from' ];
2008-09-28 23:07:57 +03:00
}
}
return $aUsers ;
}
2011-06-22 12:11:05 +03:00
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 )) {
2009-09-08 15:02:51 +03:00
return Engine :: GetEntity ( 'User_Invite' , $aRow );
2008-10-11 17:51:38 +03:00
}
return null ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function AddInvite ( ModuleUser_EntityInvite $oInvite ) {
2011-06-22 12:11:05 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.invite' ) . "
2008-10-11 17:51:38 +03:00
( invite_code ,
user_from_id ,
2011-06-22 12:11:05 +03:00
invite_date_add
2008-10-11 17:51:38 +03:00
)
VALUES ( ? , ? , ? )
2011-06-22 12:11:05 +03:00
" ;
2008-10-11 17:51:38 +03:00
if ( $iId = $this -> oDb -> query ( $sql , $oInvite -> getCode (), $oInvite -> getUserFromId (), $oInvite -> getDateAdd ())) {
return $iId ;
2011-06-22 12:11:05 +03:00
}
2008-10-11 17:51:38 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function UpdateInvite ( ModuleUser_EntityInvite $oInvite ) {
2011-06-22 12:11:05 +03:00
$sql = " UPDATE " . Config :: Get ( 'db.table.invite' ) . "
SET
2008-10-11 17:51:38 +03:00
user_to_id = ? ,
2011-06-22 12:11:05 +03:00
invite_date_used = ? ,
invite_used = ?
2008-10-11 17:51:38 +03:00
WHERE invite_id = ?
2011-06-22 12:11:05 +03:00
" ;
2008-10-11 17:51:38 +03:00
if ( $this -> oDb -> query ( $sql , $oInvite -> getUserToId (), $oInvite -> getDateUsed (), $oInvite -> getUsed (), $oInvite -> getId ())) {
return true ;
2011-06-22 12:11:05 +03:00
}
2008-10-11 17:51:38 +03:00
return false ;
}
2011-06-22 12:11:05 +03:00
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 ;
}
2011-06-22 12:11:05 +03:00
2008-10-16 07:29:15 +03:00
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 ;
}
2011-06-22 12:11:05 +03:00
public function GetUsersInvite ( $sUserId ) {
$sql = " SELECT
i . user_to_id
FROM
" .Config::Get('db.table.invite'). " as i
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 ;
}
2011-06-22 12:11:05 +03:00
2008-10-16 07:29:15 +03:00
public function GetUserInviteFrom ( $sUserIdTo ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
i . user_from_id
FROM
" .Config::Get('db.table.invite'). " as i
WHERE
i . user_to_id = ? d
LIMIT 0 , 1 ;
2008-10-16 07:29:15 +03:00
" ;
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 ;
}
2011-06-22 12:11:05 +03:00
public function SetCountryUser ( $sCountryId , $sUserId ) {
$sql = " REPLACE " . Config :: Get ( 'db.table.country_user' ) . "
SET
2008-11-01 08:16:18 +02:00
country_id = ? ,
2011-06-22 12:11:05 +03:00
user_id = ?
" ;
2008-11-01 08:16:18 +02:00
return $this -> oDb -> query ( $sql , $sCountryId , $sUserId );
}
2011-06-22 12:11:05 +03:00
2008-11-01 08:16:18 +02:00
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 )) {
2009-09-08 15:02:51 +03:00
return Engine :: GetEntity ( 'User_Country' , $aRow );
2008-11-01 08:16:18 +02:00
}
return null ;
}
2011-06-22 12:11:05 +03:00
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 ,
2011-06-22 12:11:05 +03:00
" .Config::Get('db.table.country_user'). " as cu
2009-01-24 00:46:27 +02:00
WHERE
c . country_name = ?
AND
2011-06-22 12:11:05 +03:00
c . country_id = cu . country_id
2009-06-13 00:54:04 +03:00
ORDER BY cu . user_id DESC
2011-06-22 12:11:05 +03:00
LIMIT ? d , ? d " ;
2009-01-24 00:46:27 +02:00
$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 ;
}
2011-06-22 12:11:05 +03:00
2009-01-24 00:46:27 +02:00
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
2011-06-22 12:11:05 +03:00
c . city_id = cu . city_id
2009-06-13 00:54:04 +03:00
ORDER BY cu . user_id DESC
2011-06-22 12:11:05 +03:00
LIMIT ? d , ? d " ;
2009-01-24 00:46:27 +02:00
$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 ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function AddCountry ( ModuleUser_EntityCountry $oCountry ) {
2011-06-22 12:11:05 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.country' ) . "
2008-11-01 08:16:18 +02:00
( country_name )
VALUES ( ? )
2011-06-22 12:11:05 +03:00
" ;
2008-11-01 08:16:18 +02:00
if ( $iId = $this -> oDb -> query ( $sql , $oCountry -> getName ())) {
return $iId ;
2011-06-22 12:11:05 +03:00
}
2008-11-01 08:16:18 +02:00
return false ;
}
2011-06-22 12:11:05 +03:00
public function SetCityUser ( $sCityId , $sUserId ) {
$sql = " REPLACE " . Config :: Get ( 'db.table.city_user' ) . "
SET
2008-11-01 08:16:18 +02:00
city_id = ? ,
2011-06-22 12:11:05 +03:00
user_id = ?
" ;
2008-11-01 08:16:18 +02:00
return $this -> oDb -> query ( $sql , $sCityId , $sUserId );
}
2011-06-22 12:11:05 +03:00
2008-11-01 08:16:18 +02:00
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 )) {
2009-09-08 15:02:51 +03:00
return Engine :: GetEntity ( 'User_City' , $aRow );
2008-11-01 08:16:18 +02:00
}
return null ;
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function AddCity ( ModuleUser_EntityCity $oCity ) {
2011-06-22 12:11:05 +03:00
$sql = " INSERT INTO " . Config :: Get ( 'db.table.city' ) . "
2008-11-01 08:16:18 +02:00
( city_name )
VALUES ( ? )
2011-06-22 12:11:05 +03:00
" ;
2008-11-01 08:16:18 +02:00
if ( $iId = $this -> oDb -> query ( $sql , $oCity -> getName ())) {
return $iId ;
2011-06-22 12:11:05 +03:00
}
2008-11-01 08:16:18 +02:00
return false ;
}
2011-06-22 12:11:05 +03:00
public function GetCityByNameLike ( $sName , $iLimit ) {
$sql = " SELECT
*
FROM
" .Config::Get('db.table.city'). "
2008-11-01 08:16:18 +02:00
WHERE
2011-06-22 12:11:05 +03:00
city_name LIKE ?
LIMIT 0 , ? d
" ;
2008-11-01 08:16:18 +02:00
$aReturn = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sName . '%' , $iLimit )) {
foreach ( $aRows as $aRow ) {
2009-09-08 15:02:51 +03:00
$aReturn [] = Engine :: GetEntity ( 'User_City' , $aRow );
2008-11-01 08:16:18 +02:00
}
}
return $aReturn ;
}
2011-06-22 12:11:05 +03:00
public function GetCountryByNameLike ( $sName , $iLimit ) {
$sql = " SELECT
*
FROM
" .Config::Get('db.table.country'). "
2008-11-01 08:16:18 +02:00
WHERE
2011-06-22 12:11:05 +03:00
country_name LIKE ?
LIMIT 0 , ? d
" ;
2008-11-01 08:16:18 +02:00
$aReturn = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $sName . '%' , $iLimit )) {
foreach ( $aRows as $aRow ) {
2009-09-08 15:02:51 +03:00
$aReturn [] = Engine :: GetEntity ( 'User_Country' , $aRow );
2008-11-01 08:16:18 +02:00
}
}
return $aReturn ;
}
2011-06-22 12:11:05 +03:00
public function AddReminder ( ModuleUser_EntityReminder $oReminder ) {
$sql = " REPLACE " . Config :: Get ( 'db.table.reminder' ) . "
SET
2008-11-29 12:50:49 +02:00
reminder_code = ? ,
user_id = ? ,
reminder_date_add = ? ,
reminder_date_used = ? ,
reminder_date_expire = ? ,
2011-06-22 12:11:05 +03:00
reminde_is_used = ?
" ;
2008-11-29 12:50:49 +02:00
return $this -> oDb -> query ( $sql , $oReminder -> getCode (), $oReminder -> getUserId (), $oReminder -> getDateAdd (), $oReminder -> getDateUsed (), $oReminder -> getDateExpire (), $oReminder -> getIsUsed ());
}
2011-06-22 12:11:05 +03:00
2010-05-27 18:16:20 +03:00
public function UpdateReminder ( ModuleUser_EntityReminder $oReminder ) {
2008-11-29 12:50:49 +02:00
return $this -> AddReminder ( $oReminder );
}
2011-06-22 12:11:05 +03:00
2008-11-29 12:50:49 +02:00
public function GetReminderByCode ( $sCode ) {
2011-06-22 12:11:05 +03:00
$sql = " SELECT
*
FROM
" .Config::Get('db.table.reminder'). "
WHERE
2008-11-29 12:50:49 +02:00
reminder_code = ? " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $sCode )) {
2009-09-08 15:02:51 +03:00
return Engine :: GetEntity ( 'User_Reminder' , $aRow );
2008-11-29 12:50:49 +02:00
}
return null ;
}
2011-06-22 12:11:05 +03:00
2012-03-15 11:05:27 +02:00
public function getUserFields ( $aType ) {
if ( ! is_null ( $aType ) and ! is_array ( $aType )) {
$aType = array ( $aType );
}
$sql = 'SELECT * FROM ' . Config :: Get ( 'db.table.user_field' ) . ' WHERE 1=1 { and type IN (?a) }' ;
$aFields = $this -> oDb -> select ( $sql ,( is_null ( $aType ) or ! count ( $aType )) ? DBSIMPLE_SKIP : $aType );
if ( ! count ( $aFields )) {
return array ();
}
$aResult = array ();
foreach ( $aFields as $aField ) {
$aResult [ $aField [ 'id' ]] = Engine :: GetEntity ( 'User_Field' , $aField );
}
return $aResult ;
}
public function getUserFieldValueByName ( $iUserId , $sName ) {
$sql = 'SELECT value FROM ' . Config :: Get ( 'db.table.user_field_value' ) . ' WHERE
2011-07-05 10:18:54 +03:00
user_id = ? d
AND
field_id = ( SELECT id FROM '.Config::Get(' db . table . user_field ').' WHERE name = ? ) ' ;
2012-03-15 11:05:27 +02:00
$ret = $this -> oDb -> selectCol ( $sql , $iUserId , $sName );
return $ret [ 0 ];
}
public function getUserFieldsValues ( $iUserId , $bOnlyNoEmpty , $aType ) {
if ( ! is_null ( $aType ) and ! is_array ( $aType )) {
$aType = array ( $aType );
}
/**
* Если запрашиваем без типа , то необходимо вернуть В С Е возможные поля с этим типом в не звависимости указал ли их пользователь у себя в профили или нет
* Выглядит костыльно
*/
if ( is_array ( $aType ) and count ( $aType ) == 1 and $aType [ 0 ] == '' ) {
$sql = 'SELECT f.*, v.value FROM ' . Config :: Get ( 'db.table.user_field' ) . ' as f LEFT JOIN ' . Config :: Get ( 'db.table.user_field_value' ) . ' as v ON f.id = v.field_id WHERE v.user_id = ?d and f.type IN (?a)' ;
} else {
$sql = 'SELECT v.value, f.* FROM ' . Config :: Get ( 'db.table.user_field_value' ) . ' as v, ' . Config :: Get ( 'db.table.user_field' ) . ' as f
WHERE v . user_id = ? d AND v . field_id = f . id { and f . type IN ( ? a ) } ' ;
}
$aResult = array ();
if ( $aRows = $this -> oDb -> select ( $sql , $iUserId ,( is_null ( $aType ) or ! count ( $aType )) ? DBSIMPLE_SKIP : $aType )) {
foreach ( $aRows as $aRow ) {
if ( $bOnlyNoEmpty and ! $aRow [ 'value' ]) {
continue ;
}
$aResult [] = Engine :: GetEntity ( 'User_Field' , $aRow );
}
}
return $aResult ;
}
public function setUserFieldsValues ( $iUserId , $aFields , $bSingle ) {
if ( ! count ( $aFields )) return ;
foreach ( $aFields as $iId => $sValue ) {
$sql = 'SELECT * FROM ' . Config :: Get ( 'db.table.user_field_value' ) . ' WHERE user_id = ?d AND field_id = ?' ;
if ( $bSingle and $this -> oDb -> select ( $sql , $iUserId , $iId )) {
$sql = 'UPDATE ' . Config :: Get ( 'db.table.user_field_value' ) . ' SET value = ? WHERE user_id = ?d AND field_id = ?' ;
} else {
$sql = 'INSERT INTO ' . Config :: Get ( 'db.table.user_field_value' ) . ' SET value = ?, user_id = ?d, field_id = ?' ;
}
$this -> oDb -> query ( $sql , $sValue , $iUserId , $iId );
}
}
public function addUserField ( $oField ) {
$sql = 'INSERT INTO ' . Config :: Get ( 'db.table.user_field' ) . ' SET
name = ? , title = ? , pattern = ? , type = ? ' ;
return $this -> oDb -> query ( $sql , $oField -> getName (), $oField -> getTitle (), $oField -> getPattern (), $oField -> getType ());
}
public function deleteUserField ( $iId ) {
$sql = 'DELETE FROM ' . Config :: Get ( 'db.table.user_field_value' ) . ' WHERE field_id = ?d' ;
$this -> oDb -> query ( $sql , $iId );
$sql = 'DELETE FROM ' . Config :: Get ( 'db.table.user_field' ) . ' WHERE
2011-07-05 10:18:54 +03:00
id = ? d ' ;
2012-03-15 11:05:27 +02:00
$this -> oDb -> query ( $sql , $iId );
}
public function updateUserField ( $oField ) {
$sql = 'UPDATE ' . Config :: Get ( 'db.table.user_field' ) . ' SET
name = ? , title = ? , pattern = ? , type = ?
2011-07-05 10:18:54 +03:00
WHERE id = ? d ' ;
2012-03-15 11:05:27 +02:00
$this -> oDb -> query ( $sql , $oField -> getName (), $oField -> getTitle (), $oField -> getPattern (), $oField -> getType (), $oField -> getId ());
}
public function userFieldExistsByName ( $sName , $iId ) {
$sql = 'SELECT id FROM ' . Config :: Get ( 'db.table.user_field' ) . ' WHERE name = ? {AND id != ?d}' ;
return $this -> oDb -> select ( $sql , $sName , $iId ? $iId : DBSIMPLE_SKIP );
}
public function userFieldExistsById ( $iId ) {
$sql = 'SELECT id FROM ' . Config :: Get ( 'db.table.user_field' ) . ' WHERE id = ?d' ;
return $this -> oDb -> select ( $sql , $iId );
}
public function DeleteUserFieldValues ( $iUserId , $aType ) {
if ( ! is_null ( $aType ) and ! is_array ( $aType )) {
$aType = array ( $aType );
}
$sql = 'DELETE FROM ' . Config :: Get ( 'db.table.user_field_value' ) . '
WHERE user_id = ? d AND field_id IN (
SELECT id FROM '.Config::Get(' db . table . user_field ').' WHERE 1 = 1 { and type IN ( ? a ) }
) ' ;
return $this -> oDb -> query ( $sql , $iUserId ,( is_null ( $aType ) or ! count ( $aType )) ? DBSIMPLE_SKIP : $aType );
}
2012-03-16 13:14:35 +02:00
public function GetUserNotesByUserId ( $iUserId , & $iCount , $iCurrPage , $iPerPage ) {
$sql = "
SELECT *
FROM
" .Config::Get('db.table.user_note'). "
WHERE
user_id = ? d
ORDER BY id DESC
LIMIT ? d , ? d " ;
$aReturn = array ();
if ( $aRows = $this -> oDb -> selectPage ( $iCount , $sql , $iUserId ,( $iCurrPage - 1 ) * $iPerPage , $iPerPage )) {
foreach ( $aRows as $aRow ) {
$aReturn [] = Engine :: GetEntity ( 'ModuleUser_EntityNote' , $aRow );
}
}
return $aReturn ;
}
public function GetUserNote ( $iTargetUserId , $iUserId ) {
$sql = " SELECT * FROM " . Config :: Get ( 'db.table.user_note' ) . " WHERE target_user_id = ?d and user_id = ?d " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $iTargetUserId , $iUserId )) {
return Engine :: GetEntity ( 'ModuleUser_EntityNote' , $aRow );
}
return null ;
}
public function GetUserNoteById ( $iId ) {
$sql = " SELECT * FROM " . Config :: Get ( 'db.table.user_note' ) . " WHERE id = ?d " ;
if ( $aRow = $this -> oDb -> selectRow ( $sql , $iId )) {
return Engine :: GetEntity ( 'ModuleUser_EntityNote' , $aRow );
}
return null ;
}
public function DeleteUserNoteById ( $iId ) {
$sql = " DELETE FROM " . Config :: Get ( 'db.table.user_note' ) . " WHERE id = ?d " ;
return $this -> oDb -> query ( $sql , $iId );
}
public function AddUserNote ( $oNote ) {
$sql = " INSERT INTO " . Config :: Get ( 'db.table.user_note' ) . " SET ?a " ;
if ( $iId = $this -> oDb -> query ( $sql , $oNote -> _getData ())) {
return $iId ;
}
return false ;
}
public function UpdateUserNote ( $oNote ) {
$sql = " UPDATE " . Config :: Get ( 'db.table.user_note' ) . "
SET
text = ?
WHERE id = ? d
" ;
return $this -> oDb -> query ( $sql , $oNote -> getText (),
$oNote -> getId ());
}
2008-09-21 09:36:57 +03:00
}
?>