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

Выборка комментариев идет с учетом закрытых блогов, а не топиков в закрытых блогах.

This commit is contained in:
Alexey Kachayev 2009-11-18 18:46:16 +00:00
parent c7deead1b8
commit f0d703f5b0
8 changed files with 99 additions and 67 deletions

View file

@ -755,7 +755,7 @@ class ActionBlog extends Action {
/**
* Обработка добавление комментария к топику
*
* @return unknown
* @return bool
*/
protected function SubmitComment() {
/**
@ -763,7 +763,7 @@ class ActionBlog extends Action {
*/
if (!$this->User_IsAuthorization()) {
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
return;
return;
}
/**
* Проверяем топик
@ -779,6 +779,7 @@ class ActionBlog extends Action {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем разрешено ли постить комменты
*/
@ -851,6 +852,7 @@ class ActionBlog extends Action {
$oCommentNew=Engine::GetEntity('Comment');
$oCommentNew->setTargetId($oTopic->getId());
$oCommentNew->setTargetType('topic');
$oCommentNew->setTargetParentId($oTopic->getBlog()->getId());
$oCommentNew->setUserId($this->oUserCurrent->getId());
$oCommentNew->setText($sText);
$oCommentNew->setDate(date("Y-m-d H:i:s"));
@ -870,7 +872,9 @@ class ActionBlog extends Action {
$oCommentOnline=Engine::GetEntity('Comment_CommentOnline');
$oCommentOnline->setTargetId($oCommentNew->getTargetId());
$oCommentOnline->setTargetType($oCommentNew->getTargetType());
$oCommentOnline->setTargetParentId($oCommentNew->getTargetParentId());
$oCommentOnline->setCommentId($oCommentNew->getId());
$this->Comment_AddCommentOnline($oCommentOnline);
}
/**

View file

@ -22,7 +22,7 @@ require_once('mapper/Comment.mapper.class.php');
* Модуль для работы с комментариями
*
*/
class LsComment extends Module {
class LsComment extends Module {
protected $oMapper;
protected $oUserCurrent=null;
@ -46,7 +46,7 @@ class LsComment extends Module {
return $aComments[$sId];
}
return null;
}
}
/**
* Получает уникальный коммент, это помогает спастись от дублей комментов
*
@ -239,18 +239,16 @@ class LsComment extends Module {
*/
public function GetCommentsOnline($sTargetType,$iLimit) {
/**
* Если получаем комментарии не текущего пользователя,
* то получаем exlude массив идентификаторов топиков,
* которые нужно исключить из выдачи
* Исключаем из выборки идентификаторы закрытых блогов (target_parent_id)
*/
$aCloseTopics = ($this->oUserCurrent)
? $this->Topic_GetTopicsCloseByUser($this->oUserCurrent->getId())
: $this->Topic_GetTopicsCloseByUser();
$aCloseBlogs = ($this->oUserCurrent)
? $this->Blog_GetInaccessibleBlogsByUser($this->oUserCurrent)
: $this->Blog_GetInaccessibleBlogsByUser();
$s=serialize($aCloseTopics);
$s=serialize($aCloseBlogs);
if (false === ($data = $this->Cache_Get("comment_online_{$sTargetType}_{$s}_{$iLimit}"))) {
$data = $this->oMapper->GetCommentsOnline($sTargetType,$aCloseTopics,$iLimit);
$data = $this->oMapper->GetCommentsOnline($sTargetType,$aCloseBlogs,$iLimit);
$this->Cache_Set($data, "comment_online_{$sTargetType}_{$s}_{$iLimit}", array("comment_online_update_{$sTargetType}"), 60*60*24*1);
}
$data=$this->GetCommentsAdditionalData($data);
@ -267,60 +265,62 @@ class LsComment extends Module {
*/
public function GetCommentsByUserId($sId,$sTargetType,$iPage,$iPerPage) {
/**
* Если получаем комментарии не текущего пользователя,
* то получаем exlude массив идентификаторов топиков,
* которые нужно исключить из выдачи
* Исключаем из выборки идентификаторы закрытых блогов
*/
$aCloseTopics = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
? array()
: $this->Topic_GetTopicsCloseByUser();
$s=serialize($aCloseTopics);
: $this->Blog_GetInaccessibleBlogsByUser();
$s=serialize($aCloseBlogs);
if (false === ($data = $this->Cache_Get("comment_user_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
$data = array('collection'=>$this->oMapper->GetCommentsByUserId($sId,$sTargetType,$iCount,$iPage,$iPerPage,$aCloseTopics),'count'=>$iCount);
$data = array('collection'=>$this->oMapper->GetCommentsByUserId($sId,$sTargetType,$iCount,$iPage,$iPerPage,array(),$aCloseBlogs),'count'=>$iCount);
$this->Cache_Set($data, "comment_user_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}", array("comment_new_user_{$sId}_{$sTargetType}","comment_update_status_{$sTargetType}"), 60*60*24*2);
}
$data['collection']=$this->GetCommentsAdditionalData($data['collection']);
return $data;
return $data;
}
/**
* Получает количество комментариев одного пользователя
*
* @param string $sId
* @param string $sTargetType
* @return int
*/
public function GetCountCommentsByUserId($sId,$sTargetType) {
/**
* Если получаем комментарии не текущего пользователя,
* то получаем exlude массив идентификаторов топиков,
* которые нужно исключить из выдачи
* Исключаем из выборки идентификаторы закрытых блогов
*/
$aCloseTopics = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
? array()
: $this->Topic_GetTopicsCloseByUser();
$s=serialize($aCloseTopics);
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
? array()
: $this->Blog_GetInaccessibleBlogsByUser();
$s=serialize($aCloseBlogs);
if (false === ($data = $this->Cache_Get("comment_count_user_{$sId}_{$sTargetType}_{$s}"))) {
$data = $this->oMapper->GetCountCommentsByUserId($sId,$sTargetType,$aCloseTopics);
$data = $this->oMapper->GetCountCommentsByUserId($sId,$sTargetType,array(),$aCloseBlogs);
$this->Cache_Set($data, "comment_count_user_{$sId}_{$sTargetType}", array("comment_new_user_{$sId}_{$sTargetType}","comment_update_status_{$sTargetType}"), 60*60*24*2);
}
return $data;
return $data;
}
/**
* Получить комменты по рейтингу и дате
*
* @param unknown_type $sDate
* @param unknown_type $sTargetType
* @param unknown_type $iLimit
* @return unknown
* @param string $sDate
* @param string $sTargetType
* @param int $iLimit
* @return array
*/
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit=20) {
/**
* Выбираем топики, комметарии к которым являются недоступными для пользователя
*/
$aCloseTopics = ($this->oUserCurrent)
? $this->Topic_GetTopicsCloseByUser($this->oUserCurrent->getId())
: $this->Topic_GetTopicsCloseByUser();
$s=serialize($aCloseTopics);
$aCloseBlogs = ($this->oUserCurrent)
? $this->Blog_GetInaccessibleBlogsByUser($this->oUserCurrent)
: $this->Blog_GetInaccessibleBlogsByUser();
$s=serialize($aCloseBlogs);
//т.к. время передаётся с точностью 1 час то можно по нему замутить кеширование
if (false === ($data = $this->Cache_Get("comment_rating_{$sDate}_{$sTargetType}_{$iLimit}_{$s}"))) {
$data = $this->oMapper->GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,$aCloseTopics);
$data = $this->oMapper->GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,array(),$aCloseBlogs);
$this->Cache_Set($data, "comment_rating_{$sDate}_{$sTargetType}_{$iLimit}_{$s}", array("comment_new_{$sTargetType}","comment_update_status_{$sTargetType}","comment_update_rating_{$sTargetType}"), 60*60*24*2);
}
$data=$this->GetCommentsAdditionalData($data);
@ -329,9 +329,9 @@ class LsComment extends Module {
/**
* Получить комменты для топика
*
* @param unknown_type $sId
* @param unknown_type $sTargetType
* @return unknown
* @param string $sId
* @param string $sTargetType
* @return object
*/
public function GetCommentsByTargetId($sId,$sTargetType) {
if (false === ($aCommentsRec = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}"))) {
@ -354,8 +354,8 @@ class LsComment extends Module {
/**
* Добавляет коммент
*
* @param CommentEntity_Comment $oComment
* @return unknown
* @param CommentEntity_Comment $oComment
* @return bool
*/
public function AddComment(CommentEntity_Comment $oComment) {
if ($sId=$this->oMapper->AddComment($oComment)) {
@ -368,12 +368,12 @@ class LsComment extends Module {
return $oComment;
}
return false;
}
}
/**
* Обновляет коммент
*
* @param CommentEntity_Comment $oComment
* @return unknown
* @param CommentEntity_Comment $oComment
* @return bool
*/
public function UpdateComment(CommentEntity_Comment $oComment) {
if ($this->oMapper->UpdateComment($oComment)) {
@ -387,8 +387,8 @@ class LsComment extends Module {
/**
* Обновляет рейтинг у коммента
*
* @param CommentEntity_Comment $oComment
* @return unknown
* @param CommentEntity_Comment $oComment
* @return bool
*/
public function UpdateCommentRating(CommentEntity_Comment $oComment) {
if ($this->oMapper->UpdateComment($oComment)) {

View file

@ -29,6 +29,9 @@ class CommentEntity_Comment extends Entity
public function getTargetType() {
return $this->_aData['target_type'];
}
public function getTargetParentId() {
return (array_key_exists('target_parent_id',$this->_aData)) ? $this->_aData['target_parent_id'] : 0;
}
public function getUserId() {
return $this->_aData['user_id'];
}
@ -94,6 +97,9 @@ class CommentEntity_Comment extends Entity
public function setTargetType($data) {
$this->_aData['target_type']=$data;
}
public function setTargetParentId($data) {
$this->_aData['target_parent_id']=$data;
}
public function setUserId($data) {
$this->_aData['user_id']=$data;
}

View file

@ -26,7 +26,9 @@ class CommentEntity_CommentOnline extends Entity
public function getCommentId() {
return $this->_aData['comment_id'];
}
public function getTargetParentId() {
return (array_key_exists('target_parent_id',$this->_aData)) ? $this->_aData['target_parent_id'] : 0;
}
public function setTargetId($data) {
$this->_aData['target_id']=$data;
@ -37,5 +39,8 @@ class CommentEntity_CommentOnline extends Entity
public function setCommentId($data) {
$this->_aData['comment_id']=$data;
}
public function setTargetParentId($data) {
$this->_aData['target_parent_id']=$data;
}
}
?>

View file

@ -68,7 +68,7 @@ class Mapper_Comment extends Mapper {
return null;
}
public function GetCommentsAll($sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
public function GetCommentsAll($sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
$sql = "SELECT
comment_id
FROM
@ -80,12 +80,14 @@ class Mapper_Comment extends Mapper {
AND
comment_publish = 1
{ AND target_id NOT IN(?a) }
{ AND target_parent_id NOT IN(?a) }
ORDER by comment_id desc
LIMIT ?d, ?d ";
$aComments=array();
if ($aRows=$this->oDb->selectPage(
$iCount,$sql,$sTargetType,
(count($aExcludeTarget)?$aExcludeTarget:DBSIMPLE_SKIP),
(count($aExcludeParentTarget)?$aExcludeParentTarget:DBSIMPLE_SKIP),
($iCurrPage-1)*$iPerPage, $iPerPage
)
) {
@ -119,20 +121,20 @@ class Mapper_Comment extends Mapper {
}
public function GetCommentsOnline($sTargetType,$aExcludeTopics,$iLimit) {
public function GetCommentsOnline($sTargetType,$aExcludeTargets,$iLimit) {
$sql = "SELECT
comment_id
FROM
".Config::Get('db.table.comment_online')."
WHERE
target_type = ?
{ AND target_id NOT IN(?a) }
{ AND target_parent_id NOT IN(?a) }
ORDER by comment_online_id desc limit 0, ?d ; ";
$aComments=array();
if ($aRows=$this->oDb->select(
$sql,$sTargetType,
(count($aExcludeTopics)?$aExcludeTopics:DBSIMPLE_SKIP),
(count($aExcludeTargets)?$aExcludeTargets:DBSIMPLE_SKIP),
$iLimit
)
) {
@ -149,11 +151,11 @@ class Mapper_Comment extends Mapper {
comment_id as ARRAY_KEY,
comment_pid as PARENT_KEY
FROM
".Config::Get('db.table.comment')."
".Config::Get('db.table.comment')."
WHERE
target_id = ?d
AND
target_type = ?
target_type = ?
ORDER by comment_id asc;
";
if ($aRows=$this->oDb->select($sql,$sId,$sTargetType)) {
@ -184,7 +186,7 @@ class Mapper_Comment extends Mapper {
return $aComments;
}
public function GetCommentsByUserId($sId,$sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
public function GetCommentsByUserId($sId,$sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
$sql = "SELECT
comment_id
FROM
@ -198,6 +200,7 @@ class Mapper_Comment extends Mapper {
AND
comment_publish = 1
{ AND target_id NOT IN (?a) }
{ AND target_parent_id NOT IN (?a) }
ORDER by comment_id desc
LIMIT ?d, ?d ";
$aComments=array();
@ -205,6 +208,7 @@ class Mapper_Comment extends Mapper {
$iCount,$sql,$sId,
$sTargetType,
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
($iCurrPage-1)*$iPerPage, $iPerPage
)
) {
@ -215,7 +219,7 @@ class Mapper_Comment extends Mapper {
return $aComments;
}
public function GetCountCommentsByUserId($sId,$sTargetType,$aExcludeTarget=array()) {
public function GetCountCommentsByUserId($sId,$sTargetType,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
$sql = "SELECT
count(comment_id) as count
FROM
@ -229,10 +233,12 @@ class Mapper_Comment extends Mapper {
AND
comment_publish = 1
{ AND target_id NOT IN (?a) }
{ AND target_parent_id NOT IN (?a) }
";
if ($aRow=$this->oDb->selectRow(
$sql,$sId,$sTargetType,
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP)
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP)
)
) {
return $aRow['count'];
@ -245,18 +251,19 @@ class Mapper_Comment extends Mapper {
(comment_pid,
target_id,
target_type,
target_parent_id,
user_id,
comment_text,
comment_date,
comment_user_ip,
comment_text_hash
)
VALUES(?, ?d, ?, ?d, ?, ?, ?, ?)
VALUES(?, ?d, ?, ?d, ?d, ?, ?, ?, ?)
";
if ($iId=$this->oDb->query($sql,$oComment->getPid(),$oComment->getTargetId(),$oComment->getTargetType(),$oComment->getUserId(),$oComment->getText(),$oComment->getDate(),$oComment->getUserIp(),$oComment->getTextHash()))
if ($iId=$this->oDb->query($sql,$oComment->getPid(),$oComment->getTargetId(),$oComment->getTargetType(),$oComment->getTargetParentId(),$oComment->getUserId(),$oComment->getText(),$oComment->getDate(),$oComment->getUserIp(),$oComment->getTextHash()))
{
return $iId;
}
}
return false;
}
@ -266,10 +273,11 @@ class Mapper_Comment extends Mapper {
$sql = "REPLACE INTO ".Config::Get('db.table.comment_online')."
SET
target_id= ?d ,
target_type= ? ,
target_type= ? ,
target_parent_id = ?d,
comment_id= ?d
";
if ($iId=$this->oDb->query($sql,$oCommentOnline->getTargetId(),$oCommentOnline->getTargetType(),$oCommentOnline->getCommentId()))
if ($iId=$this->oDb->query($sql,$oCommentOnline->getTargetId(),$oCommentOnline->getTargetType(),$oCommentOnline->getTargetParentId(),$oCommentOnline->getCommentId()))
{
return $iId;
}

View file

@ -132,4 +132,7 @@ ALTER TABLE `prefix_blog` CHANGE `blog_avatar` `blog_avatar` VARCHAR( 250 );
ALTER TABLE `prefix_blog` DROP `blog_avatar_type`;
ALTER TABLE `prefix_user` ADD `user_date_topic_last` DATETIME AFTER `user_date_comment_last` ;
ALTER TABLE `prefix_user` DROP `user_date_topic_last`
ALTER TABLE `prefix_user` DROP `user_date_topic_last`;
ALTER TABLE `prefix_comment` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;

View file

@ -952,4 +952,7 @@ ALTER TABLE `prefix_blog` CHANGE `blog_avatar` `blog_avatar` VARCHAR( 250 );
ALTER TABLE `prefix_blog` DROP `blog_avatar_type`;
ALTER TABLE `prefix_user` ADD `user_date_topic_last` DATETIME AFTER `user_date_comment_last` ;
ALTER TABLE `prefix_user` DROP `user_date_topic_last`;
ALTER TABLE `prefix_user` DROP `user_date_topic_last`;
ALTER TABLE `prefix_comment` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;

View file

@ -132,4 +132,7 @@ ALTER TABLE `prefix_blog` CHANGE `blog_avatar` `blog_avatar` VARCHAR( 250 );
ALTER TABLE `prefix_blog` DROP `blog_avatar_type`;
ALTER TABLE `prefix_user` ADD `user_date_topic_last` DATETIME AFTER `user_date_comment_last` ;
ALTER TABLE `prefix_user` DROP `user_date_topic_last`
ALTER TABLE `prefix_user` DROP `user_date_topic_last`
ALTER TABLE `prefix_comment` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;
ALTER TABLE `prefix_comment_online` ADD `target_parent_id` INT DEFAULT '0' NOT NULL AFTER `target_type` ;