1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-04 23:44:25 +03:00

Merge pull request #29 from fluxuator/master

Счетчик ибранных топиков и комментариев
This commit is contained in:
Mzhelskiy Maxim 2011-10-09 13:42:12 -07:00
commit d1079481e6
28 changed files with 134 additions and 23 deletions

View file

@ -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');
}
/**
* Страница со списком плагинов
*

View file

@ -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;

View file

@ -886,5 +886,15 @@ class ModuleComment extends Module {
}
}
}
/**
* Пересчитывает счетчик избранных комментариев
*
* @return type
*/
public function RecalculateFavourite(){
return $this->oMapper->RecalculateFavourite();
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -1635,6 +1635,15 @@ class ModuleTopic extends Module {
return $this->Image_GetWebPath($sFile);
}
/**
* Пересчитывает счетчик избранных топиков
*
* @return type
*/
public function RecalculateFavourite(){
return $this->oMapperTopic->RecalculateFavourite();
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -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;
}
}
?>

View file

@ -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`;

View file

@ -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

View file

@ -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' => 'Счетчики избранных пересчитаны',
/**
* Страница администрирования плагинов

View file

@ -4,6 +4,7 @@
<li><a href="{router page="admin"}plugins">{$aLang.admin_list_plugins}</a></li>
<li><a href="{router page="admin"}userfields">{$aLang.admin_list_userfields}</a></li>
<li><a href="{router page="admin"}restorecomment">{$aLang.admin_list_restorecomment}</a></li>
<li><a href="{router page="admin"}recalcfavourite">{$aLang.admin_list_recalcfavourite}</a></li>
{hook run='admin_action_item'}
</ul>

View file

@ -16,7 +16,7 @@
{/if}
<li class="goto-comment-child"><a href="#" title="{$aLang.comment_goto_child}">↓</a></li>
{if $oUserCurrent and !$bNoCommentFavourites}
<li><a href="#" onclick="return ls.favourite.toggle({$oComment->getId()},this,'comment');" class="favourite {if $oComment->getIsFavourite()}active{/if}"></a></li>
<li><a href="#" onclick="return ls.favourite.toggle({$oComment->getId()},this,'comment');" class="favourite {if $oComment->getIsFavourite()}active{/if}"></a><span class="favourite-count" id="fav_count_comment_{$oComment->getId()}">{if $oComment->getCountFavourite()>0}{$oComment->getCountFavourite()}{else}&nbsp;{/if}</span></li>
{/if}
{if !$oComment->getDelete() and $oUserCurrent and $oUserCurrent->isAdministrator()}
<li><a href="#" class="delete" onclick="ls.comments.toggle(this,{$oComment->getId()}); return false;">{$aLang.comment_delete}</a></li>

View file

@ -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 */

View file

@ -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;

View file

@ -60,7 +60,7 @@
</li>
<li class="username"><a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a></li>
<li class="date">{date_format date=$oTopic->getDateAdd()}</li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a></li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></li>
<li><a href="{router page='link'}go/{$oTopic->getId()}/" title="{$aLang.topic_link_count_jump}: {$oTopic->getLinkCountJump()}">{$oTopic->getLinkUrl(true)}</a></li>
{if $bTopicList}
<li class="comments-link">

View file

@ -112,7 +112,7 @@ jQuery(window).load(function($) {
</li>
<li class="username"><a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a></li>
<li class="date">{date_format date=$oTopic->getDateAdd()}</li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a></li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></li>
{if $bTopicList}
<li class="comments-link">
{if $oTopic->getCountComment()>0}

View file

@ -91,7 +91,7 @@
</li>
<li class="username"><a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a></li>
<li class="date">{date_format date=$oTopic->getDateAdd()}</li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a></li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></li>
{if $bTopicList}
<li class="comments-link">
{if $oTopic->getCountComment()>0}

View file

@ -59,7 +59,7 @@
</li>
<li class="username"><a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a></li>
<li class="date">{date_format date=$oTopic->getDateAdd()}</li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a></li>
<li><a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></li>
{if $bTopicList}
<li class="comments-link">
{if $oTopic->getCountComment()>0}

View file

@ -4,6 +4,7 @@
<li><a href="{router page="admin"}plugins">{$aLang.admin_list_plugins}</a></li>
<li><a href="{router page="admin"}userfields">{$aLang.admin_list_userfields}</a></li>
<li><a href="{router page="admin"}restorecomment">{$aLang.admin_list_restorecomment}</a></li>
<li><a href="{router page="admin"}recalcfavourite">{$aLang.admin_list_recalcfavourite}</a></li>
{hook run='admin_action_item'}
</ul>

View file

@ -43,7 +43,7 @@
{/if}
<li class="goto-comment-child"><a href="#" title="{$aLang.comment_goto_child}">↓</a></li>
{if $oUserCurrent and !$bNoCommentFavourites}
<li><a href="#" onclick="return ls.favourite.toggle({$oComment->getId()},this,'comment');" class="favourite {if $oComment->getIsFavourite()}active{/if}"></a></li>
<li><a href="#" onclick="return ls.favourite.toggle({$oComment->getId()},this,'comment');" class="favourite {if $oComment->getIsFavourite()}active{/if}"><span class="favourite-count" id="fav_count_comment_{$oComment->getId()}">{if $oComment->getCountFavourite()>0}{$oComment->getCountFavourite()}{else}&nbsp;{/if}</span></a></li>
{/if}
{if !$oComment->getDelete() and $oUserCurrent and $oUserCurrent->isAdministrator()}
<li><a href="#" class="delete" onclick="ls.comments.toggle(this,{$oComment->getId()}); return false;">{$aLang.comment_delete}</a></li>

View file

@ -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 */

View file

@ -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; }

View file

@ -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;

View file

@ -11,7 +11,7 @@
<img src="{cfg name='path.static.skin'}/images/topic_link_big.gif" title="{$aLang.topic_link}" alt="{$aLang.topic_link}" />
</h1>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></a>
<div class="info-top">

View file

@ -20,7 +20,7 @@ jQuery(window).load(function($) {
{/if}
</h1>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></a>

View file

@ -15,7 +15,7 @@
{/if}
</h1>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></a>

View file

@ -14,7 +14,7 @@
{/if}
</h1>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"></a>
<a href="#" onclick="return ls.favourite.toggle({$oTopic->getId()},this,'topic');" class="favourite {if $oUserCurrent && $oTopic->getIsFavourite()}active{/if}"><span class="favourite-count" id="fav_count_topic_{$oTopic->getId()}">{if $oTopic->getCountFavourite()>0}{$oTopic->getCountFavourite()}{else}&nbsp;{/if}</span></a>