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_Talk extends Mapper {
|
|
|
|
public function AddTalk(TalkEntity_Talk $oTalk) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.talk')."
|
2008-09-21 09:36:57 +03:00
|
|
|
(user_id,
|
|
|
|
talk_title,
|
|
|
|
talk_text,
|
|
|
|
talk_date,
|
2009-02-01 20:08:29 +02:00
|
|
|
talk_date_last,
|
2008-09-21 09:36:57 +03:00
|
|
|
talk_user_ip
|
|
|
|
)
|
2009-02-01 23:13:00 +02:00
|
|
|
VALUES(?d, ?, ?, ?, ?, ?)
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-02-01 20:08:29 +02:00
|
|
|
if ($iId=$this->oDb->query($sql,$oTalk->getUserId(),$oTalk->getTitle(),$oTalk->getText(),$oTalk->getDate(),$oTalk->getDateLast(),$oTalk->getUserIp()))
|
2008-09-21 09:36:57 +03:00
|
|
|
{
|
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
2009-02-01 20:08:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function UpdateTalk(TalkEntity_Talk $oTalk) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.talk')." SET
|
2009-07-05 00:41:42 +03:00
|
|
|
talk_date_last = ? ,
|
|
|
|
talk_count_comment = ?
|
2009-02-01 20:08:29 +02:00
|
|
|
WHERE
|
|
|
|
talk_id = ?d
|
|
|
|
";
|
2009-07-05 00:41:42 +03:00
|
|
|
return $this->oDb->query($sql,$oTalk->getDateLast(),$oTalk->getCountComment(),$oTalk->getId());
|
2009-02-01 20:08:29 +02:00
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
2009-07-05 00:41:42 +03:00
|
|
|
public function GetTalksByArrayId($aArrayId) {
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
t.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.talk')." as t
|
2009-07-05 00:41:42 +03:00
|
|
|
WHERE
|
|
|
|
t.talk_id IN(?a)
|
|
|
|
ORDER BY FIELD(t.talk_id,?a) ";
|
|
|
|
$aTalks=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$aArrayId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aTalks[]=new TalkEntity_Talk($aRow);
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
2009-07-05 00:41:42 +03:00
|
|
|
return $aTalks;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetTalkUserByArray($aArrayId,$sUserId) {
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
t.*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.talk_user')." as t
|
2009-07-05 00:41:42 +03:00
|
|
|
WHERE
|
|
|
|
t.user_id = ?d
|
|
|
|
AND
|
2009-08-27 22:54:31 +03:00
|
|
|
t.talk_id IN(?a)
|
2009-07-05 00:41:42 +03:00
|
|
|
";
|
|
|
|
$aTalkUsers=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aTalkUsers[]=new TalkEntity_TalkUser($aRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aTalkUsers;
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function GetTalkById($sId) {
|
2009-08-25 21:05:59 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
t.*,
|
|
|
|
u.user_login as user_login
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.talk')." as t,
|
2009-08-20 10:43:06 +03:00
|
|
|
".Config::Get('db.table.user')." as u
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
t.talk_id = ?d
|
|
|
|
AND
|
|
|
|
t.user_id=u.user_id
|
|
|
|
";
|
2009-08-25 21:05:59 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sId)) {
|
|
|
|
return new TalkEntity_Talk($aRow);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-07-05 00:41:42 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
public function AddTalkUser(TalkEntity_TalkUser $oTalkUser) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.talk_user')."
|
2008-09-21 09:36:57 +03:00
|
|
|
(talk_id,
|
|
|
|
user_id,
|
2009-08-27 22:54:31 +03:00
|
|
|
date_last,
|
|
|
|
talk_user_active
|
2008-09-21 09:36:57 +03:00
|
|
|
)
|
2009-08-27 22:54:31 +03:00
|
|
|
VALUES(?d, ?d, ?, ?d)
|
|
|
|
ON DUPLICATE KEY
|
|
|
|
UPDATE talk_user_active = ?d
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-08-27 22:54:31 +03:00
|
|
|
if ($this->oDb->query($sql,
|
|
|
|
$oTalkUser->getTalkId(),
|
|
|
|
$oTalkUser->getUserId(),
|
|
|
|
$oTalkUser->getDateLast(),
|
|
|
|
$oTalkUser->getUserActive(),
|
|
|
|
$oTalkUser->getUserActive()
|
|
|
|
)===0) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-26 15:46:44 +03:00
|
|
|
public function UpdateTalkUser(TalkEntity_TalkUser $oTalkUser) {
|
2009-08-25 21:05:59 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.talk_user')."
|
|
|
|
SET
|
|
|
|
date_last = ?,
|
|
|
|
comment_id_last = ?d,
|
|
|
|
comment_count_new = ?d,
|
|
|
|
talk_user_active = ?d
|
|
|
|
WHERE
|
|
|
|
talk_id = ?d
|
|
|
|
AND
|
|
|
|
user_id = ?d
|
|
|
|
";
|
|
|
|
|
|
|
|
if (
|
|
|
|
$this->oDb->query(
|
|
|
|
$sql,
|
|
|
|
$oTalkUser->getDateLast(),
|
|
|
|
$oTalkUser->getCommentIdLast(),
|
|
|
|
$oTalkUser->getCommentCountNew(),
|
2009-08-27 22:54:31 +03:00
|
|
|
$oTalkUser->getUserActive(),
|
2009-08-25 21:05:59 +03:00
|
|
|
$oTalkUser->getTalkId(),
|
|
|
|
$oTalkUser->getUserId()
|
|
|
|
)
|
|
|
|
) {
|
2009-07-05 00:41:42 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 22:54:31 +03:00
|
|
|
public function DeleteTalkUserByArray($aTalkId,$sUserId,$iActive) {
|
2009-07-05 14:30:55 +03:00
|
|
|
if (!is_array($aTalkId)) {
|
|
|
|
$aTalkId=array($aTalkId);
|
2009-08-26 15:46:44 +03:00
|
|
|
}
|
2009-08-25 21:05:59 +03:00
|
|
|
$sql = "
|
|
|
|
UPDATE ".Config::Get('db.table.talk_user')."
|
|
|
|
SET
|
2009-08-27 22:54:31 +03:00
|
|
|
talk_user_active = ?d
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
2009-07-05 14:30:55 +03:00
|
|
|
talk_id IN (?a)
|
2008-09-21 09:36:57 +03:00
|
|
|
AND
|
|
|
|
user_id = ?d
|
2009-08-25 21:05:59 +03:00
|
|
|
";
|
2009-08-27 22:54:31 +03:00
|
|
|
if ($this->oDb->query($sql,$iActive,$aTalkId,$sUserId))
|
2008-09-21 09:36:57 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-05 00:41:42 +03:00
|
|
|
|
2009-07-05 14:30:55 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
public function GetCountCommentNew($sUserId) {
|
|
|
|
$sql = "
|
|
|
|
SELECT
|
2009-07-05 14:30:55 +03:00
|
|
|
SUM(tu.comment_count_new) as count_new
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.talk_user')." as tu
|
2009-07-05 14:30:55 +03:00
|
|
|
WHERE
|
2009-08-25 21:05:59 +03:00
|
|
|
tu.user_id = ?d
|
|
|
|
AND
|
2009-08-27 22:54:31 +03:00
|
|
|
tu.talk_user_active=?d
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-08-27 22:54:31 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sUserId, LsTalk::TALK_USER_ACTIVE)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return $aRow['count_new'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetCountTalkNew($sUserId) {
|
|
|
|
$sql = "
|
|
|
|
SELECT
|
|
|
|
COUNT(tu.talk_id) as count_new
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.talk_user')." as tu
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
|
|
|
tu.date_last IS NULL
|
|
|
|
AND
|
2009-08-25 21:05:59 +03:00
|
|
|
tu.user_id = ?d
|
|
|
|
AND
|
2009-08-27 22:54:31 +03:00
|
|
|
tu.talk_user_active=?d
|
2008-09-21 09:36:57 +03:00
|
|
|
";
|
2009-08-27 22:54:31 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sUserId,LsTalk::TALK_USER_ACTIVE)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
return $aRow['count_new'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-25 21:05:59 +03:00
|
|
|
public function GetTalksByUserId($sUserId,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
$sql = "SELECT
|
|
|
|
tu.talk_id
|
|
|
|
FROM
|
|
|
|
".Config::Get('db.table.talk_user')." as tu,
|
|
|
|
".Config::Get('db.table.talk')." as t
|
|
|
|
WHERE
|
|
|
|
tu.user_id = ?d
|
|
|
|
AND
|
|
|
|
tu.talk_id=t.talk_id
|
|
|
|
AND
|
2009-08-27 22:54:31 +03:00
|
|
|
tu.talk_user_active = ?d
|
2009-08-25 21:05:59 +03:00
|
|
|
ORDER BY t.talk_date_last desc, t.talk_date desc
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
";
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
$aTalks=array();
|
2009-08-27 22:54:31 +03:00
|
|
|
if ($aRows=$this->oDb->selectPage($iCount,$sql,$sUserId,LsTalk::TALK_USER_ACTIVE,($iCurrPage-1)*$iPerPage, $iPerPage)) {
|
2009-07-05 00:41:42 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aTalks[]=$aRow['talk_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aTalks;
|
|
|
|
}
|
|
|
|
|
2009-07-05 00:41:42 +03:00
|
|
|
|
|
|
|
public function GetUsersTalk($sTalkId) {
|
2009-08-24 12:30:25 +03:00
|
|
|
$sql = "
|
|
|
|
SELECT
|
2009-08-25 21:05:59 +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.talk_user')."
|
2008-09-21 09:36:57 +03:00
|
|
|
WHERE
|
2009-08-24 12:30:25 +03:00
|
|
|
talk_id = ?
|
|
|
|
|
|
|
|
";
|
2008-09-21 09:36:57 +03:00
|
|
|
$aReturn=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sTalkId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-07-05 00:41:42 +03:00
|
|
|
$aReturn[]=$aRow['user_id'];
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
}
|
2009-08-25 21:05:59 +03:00
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
return $aReturn;
|
|
|
|
}
|
2009-07-05 00:41:42 +03:00
|
|
|
|
|
|
|
public function increaseCountCommentNew($sTalkId,$aExcludeId) {
|
|
|
|
if (!is_null($aExcludeId) and !is_array($aExcludeId)) {
|
|
|
|
$aExcludeId=array($aExcludeId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "UPDATE
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.talk_user')."
|
2009-07-05 00:41:42 +03:00
|
|
|
SET comment_count_new=comment_count_new+1
|
|
|
|
WHERE
|
|
|
|
talk_id = ?
|
|
|
|
{ AND user_id NOT IN (?a) }";
|
|
|
|
return $this->oDb->select($sql,$sTalkId,!is_null($aExcludeId) ? $aExcludeId : DBSIMPLE_SKIP);
|
|
|
|
}
|
2009-08-25 21:05:59 +03:00
|
|
|
|
|
|
|
public function GetTalkUsers($sTalkId) {
|
|
|
|
$sql = "
|
|
|
|
SELECT
|
|
|
|
t.*
|
|
|
|
FROM
|
|
|
|
".Config::Get('db.table.talk_user')." as t
|
|
|
|
WHERE
|
|
|
|
talk_id = ?
|
|
|
|
|
|
|
|
";
|
|
|
|
$aReturn=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sTalkId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aReturn[]=new TalkEntity_TalkUser($aRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $aReturn;
|
|
|
|
}
|
2009-08-26 01:15:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Возвращает список идентификаторов писем, удовлетворяющих условию фильтра
|
|
|
|
*
|
|
|
|
* @param array $aFilter
|
|
|
|
* @param int $iCount
|
|
|
|
* @param int $iCurrPage
|
|
|
|
* @param int $iPerPage
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function GetTalksByFilter($aFilter,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
$sql = "SELECT
|
|
|
|
tu.talk_id
|
|
|
|
FROM
|
|
|
|
".Config::Get('db.table.talk_user')." as tu,
|
|
|
|
".Config::Get('db.table.talk')." as t,
|
|
|
|
".Config::Get('db.table.user')." as u
|
|
|
|
WHERE
|
|
|
|
tu.talk_id=t.talk_id
|
2009-08-27 22:54:31 +03:00
|
|
|
AND tu.talk_user_active = ?d
|
2009-08-26 01:15:58 +03:00
|
|
|
AND u.user_id=t.user_id
|
|
|
|
{ AND tu.user_id = ?d }
|
|
|
|
{ AND t.talk_date < ? }
|
|
|
|
{ AND t.talk_date > ? }
|
|
|
|
{ AND t.talk_title LIKE ? }
|
|
|
|
{ AND u.user_login = ? }
|
|
|
|
ORDER BY t.talk_date_last desc, t.talk_date desc
|
|
|
|
LIMIT ?d, ?d
|
|
|
|
";
|
|
|
|
|
|
|
|
$aTalks=array();
|
|
|
|
if (
|
|
|
|
$aRows=$this->oDb->selectPage(
|
|
|
|
$iCount,
|
|
|
|
$sql,
|
2009-08-27 22:54:31 +03:00
|
|
|
LsTalk::TALK_USER_ACTIVE,
|
2009-08-26 01:15:58 +03:00
|
|
|
(!empty($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP),
|
|
|
|
(!empty($aFilter['date_max']) ? $aFilter['date_max'] : DBSIMPLE_SKIP),
|
|
|
|
(!empty($aFilter['date_min']) ? $aFilter['date_min'] : DBSIMPLE_SKIP),
|
|
|
|
(!empty($aFilter['keyword']) ? $aFilter['keyword'] : DBSIMPLE_SKIP),
|
|
|
|
(!empty($aFilter['user_login']) ? $aFilter['user_login'] : DBSIMPLE_SKIP),
|
|
|
|
($iCurrPage-1)*$iPerPage,
|
|
|
|
$iPerPage
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aTalks[]=$aRow['talk_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aTalks;
|
|
|
|
}
|
2009-08-27 04:05:34 +03:00
|
|
|
|
|
|
|
public function GetBlacklistByUserId($sUserId) {
|
|
|
|
$sql = "SELECT
|
|
|
|
tb.user_target_id
|
|
|
|
FROM
|
|
|
|
".Config::Get('db.table.talk_blacklist')." as tb
|
|
|
|
WHERE
|
|
|
|
tb.user_id = ?d";
|
|
|
|
$aTargetId=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aTargetId[]=$aRow['user_target_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aTargetId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetBlacklistByTargetId($sUserId) {
|
|
|
|
$sql = "SELECT
|
|
|
|
tb.user_id
|
|
|
|
FROM
|
|
|
|
".Config::Get('db.table.talk_blacklist')." as tb
|
|
|
|
WHERE
|
|
|
|
tb.user_target_id = ?d";
|
|
|
|
$aUserId=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sUserId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aUserId[]=$aRow['user_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aUserId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AddUserToBlacklist($sTargetId, $sUserId) {
|
|
|
|
$sql = "
|
|
|
|
INSERT INTO ".Config::Get('db.table.talk_blacklist')."
|
|
|
|
( user_id, user_target_id )
|
|
|
|
VALUES
|
|
|
|
(?d, ?d)
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$sUserId,$sTargetId)===0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function DeleteUserFromBlacklist($sTargetId, $sUserId) {
|
|
|
|
$sql = "
|
|
|
|
DELETE FROM ".Config::Get('db.table.talk_blacklist')."
|
|
|
|
WHERE
|
|
|
|
user_id = ?d
|
|
|
|
AND
|
|
|
|
user_target_id = ?d
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$sUserId,$sTargetId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AddUserArrayToBlacklist($aTargetId, $sUserId) {
|
|
|
|
$sql = "
|
|
|
|
INSERT INTO ".Config::Get('db.table.talk_blacklist')."
|
|
|
|
( user_id, user_target_id )
|
|
|
|
VALUES
|
|
|
|
(?d, ?d)
|
|
|
|
";
|
|
|
|
$bOk=true;
|
|
|
|
foreach ($aTargetId as $sTarget) {
|
|
|
|
$bOk = $bOk && $this->oDb->query($sql, $sUserId, $sTarget);
|
|
|
|
}
|
|
|
|
return $bOk;
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
}
|
|
|
|
?>
|