2009-06-23 20:06:19 +03:00
|
|
|
<?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
|
|
|
|
*
|
|
|
|
---------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Mapper_Comment extends Mapper {
|
|
|
|
|
2009-09-19 17:48:28 +03:00
|
|
|
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,$aExcludeTarget=array()) {
|
2009-06-23 20:06:19 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
comment_id
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
target_type = ?
|
|
|
|
AND
|
|
|
|
comment_delete = 0
|
|
|
|
AND
|
|
|
|
comment_publish = 1
|
|
|
|
AND
|
|
|
|
comment_date >= ?
|
|
|
|
AND
|
|
|
|
comment_rating >= 0
|
2009-09-19 17:48:28 +03:00
|
|
|
{ AND target_id NOT IN(?a) }
|
2009-06-23 20:06:19 +03:00
|
|
|
ORDER by comment_rating desc, comment_id desc
|
|
|
|
LIMIT 0, ?d ";
|
2009-09-19 17:48:28 +03:00
|
|
|
$aComments=array();
|
|
|
|
if ($aRows=$this->oDb->select(
|
|
|
|
$sql,$sTargetType, $sDate,
|
|
|
|
(is_array($aExcludeTarget)&&count($aExcludeTarget)) ? $aExcludeTarget : DBSIMPLE_SKIP,
|
|
|
|
$iLimit
|
|
|
|
)
|
|
|
|
) {
|
2009-06-23 20:06:19 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aComments[]=$aRow['comment_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aComments;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetCommentUnique($sTargetId,$sTargetType,$sUserId,$sCommentPid,$sHash) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "SELECT comment_id FROM ".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
target_id = ?d
|
|
|
|
AND
|
|
|
|
target_type = ?
|
|
|
|
AND
|
|
|
|
user_id = ?d
|
|
|
|
AND
|
|
|
|
((comment_pid = ?) or (? is NULL and comment_pid is NULL))
|
|
|
|
AND
|
|
|
|
comment_text_hash =?
|
|
|
|
";
|
|
|
|
if ($aRow=$this->oDb->selectRow($sql,$sTargetId,$sTargetType,$sUserId,$sCommentPid,$sCommentPid,$sHash)) {
|
|
|
|
return $aRow['comment_id'];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetCommentsAll($sTargetType,&$iCount,$iCurrPage,$iPerPage) {
|
|
|
|
$sql = "SELECT
|
|
|
|
comment_id
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
target_type = ?
|
|
|
|
AND
|
|
|
|
comment_delete = 0
|
|
|
|
AND
|
|
|
|
comment_publish = 1
|
|
|
|
ORDER by comment_id desc
|
|
|
|
LIMIT ?d, ?d ";
|
|
|
|
$aComments=array();
|
|
|
|
if ($aRows=$this->oDb->selectPage($iCount,$sql,$sTargetType,($iCurrPage-1)*$iPerPage, $iPerPage)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aComments[]=$aRow['comment_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aComments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function GetCommentsByArrayId($aArrayId) {
|
|
|
|
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT
|
|
|
|
*
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
comment_id IN(?a)
|
|
|
|
ORDER by FIELD(comment_id,?a)";
|
|
|
|
$aComments=array();
|
|
|
|
if ($aRows=$this->oDb->select($sql,$aArrayId,$aArrayId)) {
|
|
|
|
foreach ($aRows as $aRow) {
|
2009-09-08 15:02:51 +03:00
|
|
|
$aComments[]=Engine::GetEntity('Comment',$aRow);
|
2009-06-23 20:06:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aComments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-19 03:43:00 +03:00
|
|
|
public function GetCommentsOnline($sTargetType,$aExcludeTopics,$iLimit) {
|
2009-06-23 20:06:19 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
comment_id
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment_online')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
2009-09-19 03:43:00 +03:00
|
|
|
target_type = ?
|
|
|
|
{ AND target_id NOT IN(?a) }
|
|
|
|
ORDER by comment_online_id desc limit 0, ?d ; ";
|
|
|
|
|
2009-06-23 20:06:19 +03:00
|
|
|
$aComments=array();
|
2009-09-19 03:43:00 +03:00
|
|
|
if ($aRows=$this->oDb->select(
|
|
|
|
$sql,$sTargetType,
|
|
|
|
(count($aExcludeTopics)?$aExcludeTopics:DBSIMPLE_SKIP),
|
|
|
|
$iLimit
|
|
|
|
)
|
|
|
|
) {
|
2009-06-23 20:06:19 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aComments[]=$aRow['comment_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aComments;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetCommentsByTargetId($sId,$sTargetType) {
|
|
|
|
$sql = "SELECT
|
|
|
|
comment_id,
|
|
|
|
comment_id as ARRAY_KEY,
|
|
|
|
comment_pid as PARENT_KEY
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
target_id = ?d
|
|
|
|
AND
|
|
|
|
target_type = ?
|
|
|
|
ORDER by comment_id asc;
|
|
|
|
";
|
|
|
|
if ($aRows=$this->oDb->select($sql,$sId,$sTargetType)) {
|
|
|
|
return $aRows;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast) {
|
|
|
|
$sql = "SELECT
|
|
|
|
comment_id
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
target_id = ?d
|
|
|
|
AND
|
|
|
|
target_type = ?
|
|
|
|
AND
|
|
|
|
comment_id > ?d
|
2009-06-24 00:35:20 +03:00
|
|
|
ORDER by comment_id asc;
|
2009-06-23 20:06:19 +03:00
|
|
|
";
|
2009-06-24 00:35:20 +03:00
|
|
|
$aComments=array();
|
2009-06-23 20:06:19 +03:00
|
|
|
if ($aRows=$this->oDb->select($sql,$sId,$sTargetType,$sIdCommentLast)) {
|
2009-06-24 00:35:20 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aComments[]=$aRow['comment_id'];
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
}
|
2009-06-24 00:35:20 +03:00
|
|
|
return $aComments;
|
2009-06-23 20:06:19 +03:00
|
|
|
}
|
|
|
|
|
2009-09-20 21:43:20 +03:00
|
|
|
public function GetCommentsByUserId($sId,$sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
|
2009-06-23 20:06:19 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
comment_id
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
user_id = ?d
|
|
|
|
AND
|
|
|
|
target_type= ?
|
|
|
|
AND
|
|
|
|
comment_delete = 0
|
|
|
|
AND
|
2009-09-18 23:36:07 +03:00
|
|
|
comment_publish = 1
|
|
|
|
{ AND target_id NOT IN (?a) }
|
2009-06-23 20:06:19 +03:00
|
|
|
ORDER by comment_id desc
|
|
|
|
LIMIT ?d, ?d ";
|
|
|
|
$aComments=array();
|
2009-09-18 23:36:07 +03:00
|
|
|
if ($aRows=$this->oDb->selectPage(
|
|
|
|
$iCount,$sql,$sId,
|
|
|
|
$sTargetType,
|
|
|
|
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
|
|
|
($iCurrPage-1)*$iPerPage, $iPerPage
|
|
|
|
)
|
|
|
|
) {
|
2009-06-23 20:06:19 +03:00
|
|
|
foreach ($aRows as $aRow) {
|
|
|
|
$aComments[]=$aRow['comment_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $aComments;
|
|
|
|
}
|
|
|
|
|
2009-09-20 21:43:20 +03:00
|
|
|
public function GetCountCommentsByUserId($sId,$sTargetType,$aExcludeTarget=array()) {
|
2009-06-23 20:06:19 +03:00
|
|
|
$sql = "SELECT
|
|
|
|
count(comment_id) as count
|
|
|
|
FROM
|
2009-08-20 15:50:14 +03:00
|
|
|
".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
WHERE
|
|
|
|
user_id = ?d
|
|
|
|
AND
|
|
|
|
target_type= ?
|
|
|
|
AND
|
|
|
|
comment_delete = 0
|
|
|
|
AND
|
|
|
|
comment_publish = 1
|
2009-09-18 23:36:07 +03:00
|
|
|
{ AND target_id NOT IN (?a) }
|
2009-06-23 20:06:19 +03:00
|
|
|
";
|
2009-09-18 23:36:07 +03:00
|
|
|
if ($aRow=$this->oDb->selectRow(
|
|
|
|
$sql,$sId,$sTargetType,
|
|
|
|
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP)
|
|
|
|
)
|
|
|
|
) {
|
2009-06-23 20:06:19 +03:00
|
|
|
return $aRow['count'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AddComment(CommentEntity_Comment $oComment) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "INSERT INTO ".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
(comment_pid,
|
|
|
|
target_id,
|
|
|
|
target_type,
|
|
|
|
user_id,
|
|
|
|
comment_text,
|
|
|
|
comment_date,
|
|
|
|
comment_user_ip,
|
|
|
|
comment_text_hash
|
|
|
|
)
|
|
|
|
VALUES(?, ?d, ?, ?d, ?, ?, ?, ?)
|
|
|
|
";
|
|
|
|
if ($iId=$this->oDb->query($sql,$oComment->getPid(),$oComment->getTargetId(),$oComment->getTargetType(),$oComment->getUserId(),$oComment->getText(),$oComment->getDate(),$oComment->getUserIp(),$oComment->getTextHash()))
|
|
|
|
{
|
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function AddCommentOnline(CommentEntity_CommentOnline $oCommentOnline) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "REPLACE INTO ".Config::Get('db.table.comment_online')."
|
2009-06-23 20:06:19 +03:00
|
|
|
SET
|
|
|
|
target_id= ?d ,
|
|
|
|
target_type= ? ,
|
|
|
|
comment_id= ?d
|
|
|
|
";
|
|
|
|
if ($iId=$this->oDb->query($sql,$oCommentOnline->getTargetId(),$oCommentOnline->getTargetType(),$oCommentOnline->getCommentId()))
|
|
|
|
{
|
|
|
|
return $iId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function DeleteCommentOnlineByTargetId($sTargetId,$sTargetType) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "DELETE FROM ".Config::Get('db.table.comment_online')." WHERE target_id = ?d and target_type = ? ";
|
2009-06-23 20:06:19 +03:00
|
|
|
if ($this->oDb->query($sql,$sTargetId,$sTargetType))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function UpdateComment(CommentEntity_Comment $oComment) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
SET
|
|
|
|
comment_text= ?,
|
|
|
|
comment_rating= ?f,
|
|
|
|
comment_count_vote= ?d,
|
|
|
|
comment_delete = ?d ,
|
|
|
|
comment_publish = ?d ,
|
|
|
|
comment_text_hash = ?
|
|
|
|
WHERE
|
|
|
|
comment_id = ?d
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$oComment->getText(),$oComment->getRating(),$oComment->getCountVote(),$oComment->getDelete(),$oComment->getPublish(),$oComment->getTextHash(),$oComment->getId())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function SetCommentsPublish($sTargetId,$sTargetType,$iPublish) {
|
2009-08-20 15:50:14 +03:00
|
|
|
$sql = "UPDATE ".Config::Get('db.table.comment')."
|
2009-06-23 20:06:19 +03:00
|
|
|
SET
|
|
|
|
comment_publish= ?
|
|
|
|
WHERE
|
|
|
|
target_id = ?d AND target_type = ?
|
|
|
|
";
|
|
|
|
if ($this->oDb->query($sql,$iPublish,$sTargetId,$sTargetType)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|