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

изменена структура хранения комментариев "Прямого эфира"

This commit is contained in:
Mzhelskiy Maxim 2008-10-10 17:23:00 +00:00
parent b9268bd1c3
commit 3035f54d28
7 changed files with 150 additions and 2 deletions

View file

@ -149,6 +149,14 @@ class Comment extends Module {
public function AddComment(CommentEntity_TopicComment $oComment) {
if ($sId=$this->oMapperTopicComment->AddComment($oComment)) {
$this->Topic_increaseTopicCountComment($oComment->getTopicId());
/**
* Добавляем коммент в прямой эфир
*/
$this->oMapperTopicComment->deleteTopicCommentOnline($oComment->getTopicId());
$oTopicCommentOnline=new CommentEntity_TopicCommentOnline();
$oTopicCommentOnline->setTopicId($oComment->getTopicId());
$oTopicCommentOnline->setCommentId($sId);
$this->oMapperTopicComment->AddTopicCommentOnline($oTopicCommentOnline);
//чистим зависимые кеши
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('comment_new',"comment_new_user_{$oComment->getUserId()}","comment_new_topic_{$oComment->getTopicId()}"));
$oComment->setId($sId);
@ -182,6 +190,15 @@ class Comment extends Module {
}
return false;
}
/**
* Удаляет коммент из прямого эфира
*
* @param unknown_type $sTopicId
* @return unknown
*/
public function deleteTopicCommentOnline($sTopicId) {
return $this->oMapperTopicComment->deleteTopicCommentOnline($sTopicId);
}
/**
* Строит дерево комментариев
*

View file

@ -0,0 +1,41 @@
<?
/*-------------------------------------------------------
*
* 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 CommentEntity_TopicCommentOnline extends Entity
{
public function getCommentOnlineId() {
return $this->_aData['comment_online_id'];
}
public function getTopicId() {
return $this->_aData['topic_id'];
}
public function getCommentId() {
return $this->_aData['comment_id'];
}
public function setCommentOnlineId($data) {
$this->_aData['comment_online_id']=$data;
}
public function setTopicId($data) {
$this->_aData['topic_id']=$data;
}
public function setCommentId($data) {
$this->_aData['comment_id']=$data;
}
}
?>

View file

@ -242,6 +242,30 @@ class Mapper_TopicComment extends Mapper {
*/
ORDER by c.comment_date desc limit 0, ?d ;
";
/**
* оптимизирован
*/
$sql = "SELECT
c.*,
t.topic_title as topic_title,
t.topic_count_comment as topic_count_comment,
u.user_profile_avatar as user_profile_avatar,
u.user_profile_avatar_type as user_profile_avatar_type,
u.user_login as user_login,
b.blog_title as blog_title,
b.blog_type as blog_type,
b.blog_url as blog_url,
u_owner.user_login as blog_owner_login
FROM
".DB_TABLE_TOPIC_COMMENT_ONLINE." as co
JOIN ".DB_TABLE_TOPIC_COMMENT." AS c ON co.comment_id=c.comment_id
JOIN ".DB_TABLE_TOPIC." AS t ON co.topic_id=t.topic_id
JOIN ".DB_TABLE_USER." AS u ON c.user_id=u.user_id
JOIN ".DB_TABLE_BLOG." AS b ON t.blog_id=b.blog_id
JOIN ".DB_TABLE_USER." AS u_owner ON b.user_owner_id=u_owner.user_id
ORDER by co.comment_online_id desc limit 0, ?d ;
";
$aComments=array();
if ($aRows=$this->oDb->select($sql,$iLimit)) {
foreach ($aRows as $aTopicComment) {
@ -388,6 +412,29 @@ class Mapper_TopicComment extends Mapper {
return false;
}
public function AddTopicCommentOnline(CommentEntity_TopicCommentOnline $oTopicCommentOnline) {
$sql = "INSERT INTO ".DB_TABLE_TOPIC_COMMENT_ONLINE."
(topic_id,
comment_id
)
VALUES(?d, ?d)
";
if ($iId=$this->oDb->query($sql,$oTopicCommentOnline->getTopicId(),$oTopicCommentOnline->getCommentId()))
{
return $iId;
}
return false;
}
public function deleteTopicCommentOnline($sTopicId) {
$sql = "DELETE FROM ".DB_TABLE_TOPIC_COMMENT_ONLINE." WHERE topic_id = ?d ";
if ($this->oDb->query($sql,$sTopicId))
{
return true;
}
return false;
}
public function GetTopicCommentVote($sCommentId,$sUserId) {
$sql = "SELECT * FROM ".DB_TABLE_TOPIC_COMMENT_VOTE." WHERE comment_id = ?d and user_voter_id = ?d ";
if ($aRow=$this->oDb->selectRow($sql,$sCommentId,$sUserId)) {

View file

@ -101,6 +101,12 @@ class Topic extends Module {
$this->oMapperTopic->AddTopicTag($oTag);
}
}
/**
* Удаляем комментарий топика из прямого эфира
*/
if ($oTopic->getPublish()==0) {
$this->Comment_deleteTopicCommentOnline($oTopic->getId());
}
//чистим зависимые кеши
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('topic_update',"topic_update_{$oTopic->getId()}","topic_update_user_{$oTopic->getUserId()}","topic_update_blog_{$oTopic->getBlogId()}"));
return true;

View file

@ -40,4 +40,5 @@ define('DB_TABLE_FREND',DB_PREFIX_TABLE.'frend');
define('DB_TABLE_TOPIC_CONTENT',DB_PREFIX_TABLE.'topic_content');
define('DB_TABLE_TOPIC_QUESTION_VOTE',DB_PREFIX_TABLE.'topic_question_vote');
define('DB_TABLE_USER_ADMINISTRATOR',DB_PREFIX_TABLE.'user_administrator');
define('DB_TABLE_TOPIC_COMMENT_ONLINE',DB_PREFIX_TABLE.'topic_comment_online');
?>

View file

@ -17,6 +17,11 @@ mysql_select_db($aConfig['dbname'],$link);
mysql_query("set character_set_client='utf8'",$link);
mysql_query("set character_set_results='utf8'",$link);
mysql_query("set collation_connection='utf8_bin'",$link);
/**
* Конвертирует топики из старой структуры в новую
*/
$sql = "SELECT
*
FROM
@ -32,6 +37,4 @@ while ($row=mysql_fetch_assoc($res)) {
";
mysql_query($sql2,$link);
}
?>

View file

@ -57,6 +57,39 @@ ALTER TABLE `prefix_topic_comment` ADD `comment_delete` TINYINT NOT NULL DEFAULT
ALTER TABLE `prefix_topic_comment` ADD INDEX ( `comment_delete` ) ;
--
-- Структура таблицы `prefix_topic_comment_online`
--
CREATE TABLE IF NOT EXISTS `prefix_topic_comment_online` (
`comment_online_id` int(11) unsigned NOT NULL auto_increment,
`topic_id` int(11) unsigned NOT NULL,
`comment_id` int(11) unsigned NOT NULL,
PRIMARY KEY (`comment_online_id`),
KEY `topic_id` (`topic_id`),
KEY `comment_id` (`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
--
-- Ограничения внешнего ключа сохраненных таблиц
--
--
-- Ограничения внешнего ключа таблицы `prefix_topic_comment_online`
--
ALTER TABLE `prefix_topic_comment_online`
ADD CONSTRAINT `prefix_topic_comment_online_fk1` FOREIGN KEY (`comment_id`) REFERENCES `prefix_topic_comment` (`comment_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `prefix_topic_comment_online_fk` FOREIGN KEY (`topic_id`) REFERENCES `prefix_topic` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- ВНИМАНИЕ!!! То что ниже нужно выполнить только после запуска скрипта convert.php !!!! иначе УДАЛЯТСЯ ВСЕ ТОПИКИ!!!!!