diff --git a/classes/actions/ActionAdmin.class.php b/classes/actions/ActionAdmin.class.php index 85506d5c..1c49fa38 100644 --- a/classes/actions/ActionAdmin.class.php +++ b/classes/actions/ActionAdmin.class.php @@ -42,6 +42,7 @@ class ActionAdmin extends Action { $this->AddEvent('plugins','EventPlugins'); $this->AddEvent('restorecomment','EventRestoreComment'); $this->AddEvent('userfields','EventUserfields'); + $this->AddEvent('recalcfavourite','EventRecalculateFavourite'); } @@ -67,6 +68,20 @@ class ActionAdmin extends Action { $this->SetTemplateAction('index'); } + /** + * Перестроение дерева комментариев, актуально при $config['module']['comment']['use_nested'] = true; + * + */ + protected function EventRecalculateFavourite() { + set_time_limit(0); + $this->Comment_RecalculateFavourite(); + $this->Topic_RecalculateFavourite(); + $this->Cache_Clean(); + + $this->Message_AddNotice($this->Lang_Get('admin_favourites_recalculated'),$this->Lang_Get('attention')); + $this->SetTemplateAction('index'); + } + /** * Страница со списком плагинов * diff --git a/classes/actions/ActionAjax.class.php b/classes/actions/ActionAjax.class.php index 11b23d84..f6fcb748 100644 --- a/classes/actions/ActionAjax.class.php +++ b/classes/actions/ActionAjax.class.php @@ -428,9 +428,11 @@ class ActionAjax extends Action { 'target_publish' => $oTopic->getPublish() ) ); - if ($this->Topic_AddFavouriteTopic($oFavouriteTopicNew)) { + $oTopic->setCountFavourite($oTopic->getCountFavourite()+1); + if ($this->Topic_AddFavouriteTopic($oFavouriteTopicNew) and $this->Topic_UpdateTopic($oTopic)) { $this->Message_AddNoticeSingle($this->Lang_Get('topic_favourite_add_ok'),$this->Lang_Get('attention')); $this->Viewer_AssignAjax('bState',true); + $this->Viewer_AssignAjax('iCount', $oTopic->getCountFavourite()); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error')); return; @@ -445,9 +447,11 @@ class ActionAjax extends Action { return; } if ($oFavouriteTopic and !$iType) { - if ($this->Topic_DeleteFavouriteTopic($oFavouriteTopic)) { + $oTopic->setCountFavourite($oTopic->getCountFavourite()-1); + if ($this->Topic_DeleteFavouriteTopic($oFavouriteTopic) and $this->Topic_UpdateTopic($oTopic)) { $this->Message_AddNoticeSingle($this->Lang_Get('topic_favourite_del_ok'),$this->Lang_Get('attention')); $this->Viewer_AssignAjax('bState',false); + $this->Viewer_AssignAjax('iCount', $oTopic->getCountFavourite()); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error')); return; @@ -488,9 +492,11 @@ class ActionAjax extends Action { 'target_publish' => $oComment->getPublish() ) ); - if ($this->Comment_AddFavouriteComment($oFavouriteCommentNew)) { + $oComment->setCountFavourite($oComment->getCountFavourite()+1); + if ($this->Comment_AddFavouriteComment($oFavouriteCommentNew) and $this->Comment_UpdateComment($oComment)) { $this->Message_AddNoticeSingle($this->Lang_Get('comment_favourite_add_ok'),$this->Lang_Get('attention')); $this->Viewer_AssignAjax('bState',true); + $this->Viewer_AssignAjax('iCount', $oComment->getCountFavourite()); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error')); return; @@ -505,9 +511,11 @@ class ActionAjax extends Action { return; } if ($oFavouriteComment and !$iType) { - if ($this->Comment_DeleteFavouriteComment($oFavouriteComment)) { + $oComment->setCountFavourite($oComment->getCountFavourite()-1); + if ($this->Comment_DeleteFavouriteComment($oFavouriteComment) and $this->Comment_UpdateComment($oComment)) { $this->Message_AddNoticeSingle($this->Lang_Get('comment_favourite_del_ok'),$this->Lang_Get('attention')); $this->Viewer_AssignAjax('bState',false); + $this->Viewer_AssignAjax('iCount', $oComment->getCountFavourite()); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error')); return; diff --git a/classes/modules/comment/Comment.class.php b/classes/modules/comment/Comment.class.php index 9b962976..4a3c25be 100644 --- a/classes/modules/comment/Comment.class.php +++ b/classes/modules/comment/Comment.class.php @@ -886,5 +886,15 @@ class ModuleComment extends Module { } } } + + /** + * Пересчитывает счетчик избранных комментариев + * + * @return type + */ + public function RecalculateFavourite(){ + return $this->oMapper->RecalculateFavourite(); + } + } ?> \ No newline at end of file diff --git a/classes/modules/comment/entity/Comment.entity.class.php b/classes/modules/comment/entity/Comment.entity.class.php index 783a3c5c..e91769c4 100644 --- a/classes/modules/comment/entity/Comment.entity.class.php +++ b/classes/modules/comment/entity/Comment.entity.class.php @@ -87,7 +87,11 @@ class ModuleComment_EntityComment extends Entity } public function getIsFavourite() { return $this->_aData['comment_is_favourite']; - } + } + + public function getCountFavourite() { + return $this->_aData['comment_count_favourite']; + } @@ -155,6 +159,9 @@ class ModuleComment_EntityComment extends Entity } public function setIsFavourite($data) { $this->_aData['comment_is_favourite']=$data; - } + } + public function setCountFavourite($data) { + $this->_aData['comment_count_favourite']=$data; + } } ?> \ No newline at end of file diff --git a/classes/modules/comment/mapper/Comment.mapper.class.php b/classes/modules/comment/mapper/Comment.mapper.class.php index 8c72124c..e9c619a9 100644 --- a/classes/modules/comment/mapper/Comment.mapper.class.php +++ b/classes/modules/comment/mapper/Comment.mapper.class.php @@ -489,13 +489,14 @@ class ModuleComment_MapperComment extends Mapper { comment_text= ?, comment_rating= ?f, comment_count_vote= ?d, + comment_count_favourite= ?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())) { + if ($this->oDb->query($sql,$oComment->getText(),$oComment->getRating(),$oComment->getCountVote(),$oComment->getCountFavourite(),$oComment->getDelete(),$oComment->getPublish(),$oComment->getTextHash(),$oComment->getId())) { return true; } return false; @@ -649,5 +650,25 @@ class ModuleComment_MapperComment extends Mapper { } return array(); } + + public function RecalculateFavourite() { + $sql = " + UPDATE ".Config::Get('db.table.comment')." c + SET c.comment_count_favourite = ( + SELECT count(f.user_id) + FROM ".Config::Get('db.table.favourite')." f + WHERE + f.target_id = c.comment_id + AND + f.target_publish = 1 + AND + f.target_type = 'comment' + ) + "; + if ($this->oDb->query($sql)) { + return true; + } + return false; + } } ?> \ No newline at end of file diff --git a/classes/modules/topic/Topic.class.php b/classes/modules/topic/Topic.class.php index b1348125..0381f22f 100644 --- a/classes/modules/topic/Topic.class.php +++ b/classes/modules/topic/Topic.class.php @@ -1635,6 +1635,15 @@ class ModuleTopic extends Module { return $this->Image_GetWebPath($sFile); } + + /** + * Пересчитывает счетчик избранных топиков + * + * @return type + */ + public function RecalculateFavourite(){ + return $this->oMapperTopic->RecalculateFavourite(); + } } ?> \ No newline at end of file diff --git a/classes/modules/topic/entity/Topic.entity.class.php b/classes/modules/topic/entity/Topic.entity.class.php index 102457b4..57ffe8d5 100644 --- a/classes/modules/topic/entity/Topic.entity.class.php +++ b/classes/modules/topic/entity/Topic.entity.class.php @@ -130,6 +130,9 @@ class ModuleTopic_EntityTopic extends Entity public function getIsFavourite() { return $this->_aData['topic_is_favourite']; } + public function getCountFavourite() { + return $this->_aData['topic_count_favourite']; + } /*************************************************************************************************************************************************** * методы расширения типов топика @@ -394,6 +397,8 @@ class ModuleTopic_EntityTopic extends Entity public function setIsFavourite($data) { $this->_aData['topic_is_favourite']=$data; } - + public function setCountFavourite($data) { + $this->_aData['topic_count_favourite']=$data; + } } ?> \ No newline at end of file diff --git a/classes/modules/topic/mapper/Topic.mapper.class.php b/classes/modules/topic/mapper/Topic.mapper.class.php index f39203ea..540ae4ff 100644 --- a/classes/modules/topic/mapper/Topic.mapper.class.php +++ b/classes/modules/topic/mapper/Topic.mapper.class.php @@ -383,13 +383,14 @@ class ModuleTopic_MapperTopic extends Mapper { topic_count_vote= ?d, topic_count_read= ?d, topic_count_comment= ?d, + topic_count_favourite= ?d, topic_cut_text = ? , topic_forbid_comment = ? , topic_text_hash = ? WHERE topic_id = ?d "; - if ($this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getTitle(),$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getDateEdit(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getRating(),$oTopic->getCountVote(),$oTopic->getCountRead(),$oTopic->getCountComment(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash(),$oTopic->getId())) { + if ($this->oDb->query($sql,$oTopic->getBlogId(),$oTopic->getTitle(),$oTopic->getTags(),$oTopic->getDateAdd(),$oTopic->getDateEdit(),$oTopic->getUserIp(),$oTopic->getPublish(),$oTopic->getPublishDraft(),$oTopic->getPublishIndex(),$oTopic->getRating(),$oTopic->getCountVote(),$oTopic->getCountRead(),$oTopic->getCountComment(),$oTopic->getCountFavourite(),$oTopic->getCutText(),$oTopic->getForbidComment(),$oTopic->getTextHash(),$oTopic->getId())) { $this->UpdateTopicContent($oTopic); return true; } @@ -798,5 +799,25 @@ class ModuleTopic_MapperTopic extends Mapper { id= ?d'; $this->oDb->query($sql, $iPhotoId); } + + public function RecalculateFavourite() { + $sql = " + UPDATE ".Config::Get('db.table.topic')." t + SET t.topic_count_favourite = ( + SELECT count(f.user_id) + FROM ".Config::Get('db.table.favourite')." f + WHERE + f.target_id = t.topic_id + AND + f.target_publish = 1 + AND + f.target_type = 'topic' + ) + "; + if ($this->oDb->query($sql)) { + return true; + } + return false; + } } ?> \ No newline at end of file diff --git a/install/convert_0.5.1_to_0.5.2.sql b/install/convert_0.5.1_to_0.5.2.sql new file mode 100644 index 00000000..14667967 --- /dev/null +++ b/install/convert_0.5.1_to_0.5.2.sql @@ -0,0 +1,2 @@ +ALTER TABLE `prefix_topic` ADD `topic_count_favourite` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `topic_count_comment`; +ALTER TABLE `prefix_comment` ADD `comment_count_favourite` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `comment_count_vote`; diff --git a/templates/language/english.php b/templates/language/english.php index 11ea40dd..f41bfccd 100644 --- a/templates/language/english.php +++ b/templates/language/english.php @@ -835,6 +835,7 @@ return array( 'admin_list_plugins' => 'Manage plugins', 'admin_list_userfields' => 'Configuring custom fields', 'admin_list_restorecomment' => 'Rebuilding a tree comments', + 'admin_list_recalcfavourite' => 'Recalculate counters of favorites', /** @@ -900,6 +901,7 @@ return array( */ 'admin_title' => 'Admin', 'admin_comment_restore_tree' => 'Tree comments restore successful', + 'admin_favourites_recalculated' => 'Favourites counters has been recalculated', /** * Plugin administration page diff --git a/templates/language/russian.php b/templates/language/russian.php index 14620910..bb2eee64 100644 --- a/templates/language/russian.php +++ b/templates/language/russian.php @@ -834,6 +834,7 @@ return array( 'admin_list_plugins' => 'Управление плагинами', 'admin_list_userfields' => 'Настройка пользовательских полей', 'admin_list_restorecomment' => 'Перестроение дерева комментариев', + 'admin_list_recalcfavourite' => 'Пересчитать счетчики избранных', /** * Рейтинг TOP @@ -898,6 +899,7 @@ return array( */ 'admin_title' => 'Админка', 'admin_comment_restore_tree' => 'Дерево комментариев перестроенно', + 'admin_favourites_recalculated' => 'Счетчики избранных пересчитаны', /** * Страница администрирования плагинов diff --git a/templates/skin/developer-jquery/actions/ActionAdmin/index.tpl b/templates/skin/developer-jquery/actions/ActionAdmin/index.tpl index 2553e51f..46b3714e 100644 --- a/templates/skin/developer-jquery/actions/ActionAdmin/index.tpl +++ b/templates/skin/developer-jquery/actions/ActionAdmin/index.tpl @@ -4,6 +4,7 @@