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 @@
  • {$aLang.admin_list_plugins}
  • {$aLang.admin_list_userfields}
  • {$aLang.admin_list_restorecomment}
  • +
  • {$aLang.admin_list_recalcfavourite}
  • {hook run='admin_action_item'} diff --git a/templates/skin/developer-jquery/comment.tpl b/templates/skin/developer-jquery/comment.tpl index d1fc15c6..1b103a4a 100644 --- a/templates/skin/developer-jquery/comment.tpl +++ b/templates/skin/developer-jquery/comment.tpl @@ -16,7 +16,7 @@ {/if}
  • {if $oUserCurrent and !$bNoCommentFavourites} -
  • +
  • {if $oComment->getCountFavourite()>0}{$oComment->getCountFavourite()}{else} {/if}
  • {/if} {if !$oComment->getDelete() and $oUserCurrent and $oUserCurrent->isAdministrator()}
  • {$aLang.comment_delete}
  • diff --git a/templates/skin/developer-jquery/css/common.css b/templates/skin/developer-jquery/css/common.css index c2c265a9..cce28285 100644 --- a/templates/skin/developer-jquery/css/common.css +++ b/templates/skin/developer-jquery/css/common.css @@ -24,9 +24,10 @@ /* Favorite */ -.favourite { background: url(../images/favorite.png) no-repeat; display: block; height: 16px; width: 16px; position: relative; top: 1px; } +.favourite { background: url(../images/favorite.png) no-repeat; display: block; height: 16px; width: 16px; position: relative; top: 1px; float: left;} .favourite:hover { background-position: 0 -16px !important; } .favourite.active { background-position: 0 -16px; } +.favourite-count { color: #333; font-weight: bold; float: left; margin-left: 2px; } /* Pagination */ diff --git a/templates/skin/developer-jquery/js/favourite.js b/templates/skin/developer-jquery/js/favourite.js index e5853587..a4eb914b 100644 --- a/templates/skin/developer-jquery/js/favourite.js +++ b/templates/skin/developer-jquery/js/favourite.js @@ -47,6 +47,8 @@ ls.favourite = (function ($) { if (result.bState) { this.objFavourite.addClass(this.options.active); } + + $('#fav_count_'+type+'_'+idTarget).text((result.iCount>0) ? result.iCount : ''); } }.bind(this)); return false; diff --git a/templates/skin/developer-jquery/topic_link.tpl b/templates/skin/developer-jquery/topic_link.tpl index 7311539b..a1ad5ac4 100644 --- a/templates/skin/developer-jquery/topic_link.tpl +++ b/templates/skin/developer-jquery/topic_link.tpl @@ -60,7 +60,7 @@
  • {$oUser->getLogin()}
  • {date_format date=$oTopic->getDateAdd()}
  • -
  • +
  • {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if}
  • {$oTopic->getLinkUrl(true)}
  • {if $bTopicList}
  • {$oUser->getLogin()}
  • {date_format date=$oTopic->getDateAdd()}
  • -
  • +
  • {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if}
  • {if $bTopicList}
  • {$oUser->getLogin()}
  • {date_format date=$oTopic->getDateAdd()}
  • -
  • +
  • {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if}
  • {if $bTopicList}
  • {$oUser->getLogin()}
  • {date_format date=$oTopic->getDateAdd()}
  • -
  • +
  • {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if}
  • {if $bTopicList}
  • {$aLang.admin_list_plugins}
  • {$aLang.admin_list_userfields}
  • {$aLang.admin_list_restorecomment}
  • +
  • {$aLang.admin_list_recalcfavourite}
  • {hook run='admin_action_item'} diff --git a/templates/skin/new-jquery/comment.tpl b/templates/skin/new-jquery/comment.tpl index 35e6808e..10474607 100644 --- a/templates/skin/new-jquery/comment.tpl +++ b/templates/skin/new-jquery/comment.tpl @@ -43,7 +43,7 @@ {/if}
  • {if $oUserCurrent and !$bNoCommentFavourites} -
  • +
  • {if $oComment->getCountFavourite()>0}{$oComment->getCountFavourite()}{else} {/if}
  • {/if} {if !$oComment->getDelete() and $oUserCurrent and $oUserCurrent->isAdministrator()}
  • {$aLang.comment_delete}
  • diff --git a/templates/skin/new-jquery/css/comments.css b/templates/skin/new-jquery/css/comments.css index 2bfc095e..698ff65c 100644 --- a/templates/skin/new-jquery/css/comments.css +++ b/templates/skin/new-jquery/css/comments.css @@ -62,6 +62,7 @@ .comment .info li a.favourite { float: left; width: 10px; height: 8px; background: url(../images/icons.gif) -40px -40px no-repeat; position: relative; top: 4px; } .comment .info li a.favourite.active { background-position: -50px -40px; } .comment .info li a.favourite:hover { background-position: -50px -40px; } +.comment .info li span.favourite-count { color: #390; margin-left: 2px; position: relative; top: 1px; } .comment .info li a { } /* Content */ diff --git a/templates/skin/new-jquery/css/topic.css b/templates/skin/new-jquery/css/topic.css index 4e9184ee..a55a5df5 100644 --- a/templates/skin/new-jquery/css/topic.css +++ b/templates/skin/new-jquery/css/topic.css @@ -42,9 +42,10 @@ .topic .info li.comments-link a:hover span { background: #390; color: #fff; } .topic .info li.url a { padding-left: 16px; background: url(../images/topic_link.gif) 0 1px no-repeat; font-size: 11px; } -.topic .favourite { position: absolute; top: 8px; left: -8px; height: 16px; width: 20px; background: url(../images/icons.gif) no-repeat 0 -40px; } -.topic .favourite:hover { background: url(../images/icons.gif) no-repeat -20px -40px; } -.topic .favourite.active { background: url(../images/icons.gif) no-repeat -20px -40px; } +.topic .favourite { position: absolute; top: 8px; left: -8px; height: 16px; width: 20px; background: url(../images/icons.gif) no-repeat 0 -40px; text-align: center; font-weight: bold; text-decoration: none; } +.topic .favourite:hover { background: url(../images/icons.gif) no-repeat -20px -40px; color: #fff; } +.topic .favourite.active { background: url(../images/icons.gif) no-repeat -20px -40px; color: #fff; } +.topic .favourite-count { color: #390; position: absolute;top: 15px; left: -7px; width: 32px; } /* Poll */ .topic .poll { margin-bottom: 15px; font-size: 14px; } diff --git a/templates/skin/new-jquery/js/favourite.js b/templates/skin/new-jquery/js/favourite.js index e5853587..04561d0f 100644 --- a/templates/skin/new-jquery/js/favourite.js +++ b/templates/skin/new-jquery/js/favourite.js @@ -47,6 +47,8 @@ ls.favourite = (function ($) { if (result.bState) { this.objFavourite.addClass(this.options.active); } + + $('#fav_count_'+type+'_'+idTarget).text((result.iCount>0) ? result.iCount : ''); } }.bind(this)); return false; diff --git a/templates/skin/new-jquery/topic_link.tpl b/templates/skin/new-jquery/topic_link.tpl index eb1db350..a5633faf 100644 --- a/templates/skin/new-jquery/topic_link.tpl +++ b/templates/skin/new-jquery/topic_link.tpl @@ -11,7 +11,7 @@ {$aLang.topic_link} - + {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if}
    diff --git a/templates/skin/new-jquery/topic_photoset.tpl b/templates/skin/new-jquery/topic_photoset.tpl index f132b1d3..1dfe7447 100644 --- a/templates/skin/new-jquery/topic_photoset.tpl +++ b/templates/skin/new-jquery/topic_photoset.tpl @@ -20,7 +20,7 @@ jQuery(window).load(function($) { {/if} - + {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if} diff --git a/templates/skin/new-jquery/topic_question.tpl b/templates/skin/new-jquery/topic_question.tpl index 365b446f..f146ae8f 100644 --- a/templates/skin/new-jquery/topic_question.tpl +++ b/templates/skin/new-jquery/topic_question.tpl @@ -15,7 +15,7 @@ {/if} - + {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if} diff --git a/templates/skin/new-jquery/topic_topic.tpl b/templates/skin/new-jquery/topic_topic.tpl index a451612c..a63d694f 100644 --- a/templates/skin/new-jquery/topic_topic.tpl +++ b/templates/skin/new-jquery/topic_topic.tpl @@ -14,7 +14,7 @@ {/if} - + {if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else} {/if}