2009-05-10 10:50:39 +03:00
|
|
|
|
<?php
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/*-------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Модуль для работы с комментариями
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @package modules.comment
|
|
|
|
|
* @since 1.0
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2010-05-27 17:02:43 +03:00
|
|
|
|
class ModuleComment extends Module {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
/**
|
|
|
|
|
* Объект маппера
|
|
|
|
|
*
|
|
|
|
|
* @var ModuleComment_MapperComment
|
|
|
|
|
*/
|
|
|
|
|
protected $oMapper;
|
|
|
|
|
/**
|
|
|
|
|
* Объект текущего пользователя
|
|
|
|
|
*
|
|
|
|
|
* @var ModuleUser_EntityUser|null
|
|
|
|
|
*/
|
2009-06-28 17:04:44 +03:00
|
|
|
|
protected $oUserCurrent=null;
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function Init() {
|
2010-05-27 23:40:30 +03:00
|
|
|
|
$this->oMapper=Engine::GetMapper(__CLASS__);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$this->oUserCurrent=$this->User_GetUserCurrent();
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получить коммент по айдишнику
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sId ID комментария
|
|
|
|
|
* @return ModuleComment_EntityComment|null
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
|
|
|
|
public function GetCommentById($sId) {
|
2012-07-08 11:50:36 +03:00
|
|
|
|
if (!is_numeric($sId)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aComments=$this->GetCommentsAdditionalData($sId);
|
2009-06-23 20:06:19 +03:00
|
|
|
|
if (isset($aComments[$sId])) {
|
|
|
|
|
return $aComments[$sId];
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
return null;
|
2009-11-18 20:46:16 +02:00
|
|
|
|
}
|
2008-10-25 23:31:29 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает уникальный коммент, это помогает спастись от дублей комментов
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sTargetId ID владельца комментария
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $sUserId ID пользователя
|
|
|
|
|
* @param int $sCommentPid ID родительского комментария
|
|
|
|
|
* @param string $sHash Хеш строка текста комментария
|
|
|
|
|
* @return ModuleComment_EntityComment|null
|
2008-10-25 23:31:29 +03:00
|
|
|
|
*/
|
2009-06-23 20:06:19 +03:00
|
|
|
|
public function GetCommentUnique($sTargetId,$sTargetType,$sUserId,$sCommentPid,$sHash) {
|
|
|
|
|
$sId=$this->oMapper->GetCommentUnique($sTargetId,$sTargetType,$sUserId,$sCommentPid,$sHash);
|
|
|
|
|
return $this->GetCommentById($sId);
|
2008-10-25 23:31:29 +03:00
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получить все комменты
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iPage Номер страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на страницу
|
|
|
|
|
* @param array $aExcludeTarget Список ID владельцев, которые необходимо исключить из выдачи
|
|
|
|
|
* @param array $aExcludeParentTarget Список ID родителей владельцев, которые необходимо исключить из выдачи, например, исключить комментарии топиков к определенным блогам(закрытым)
|
|
|
|
|
* @return array('collection'=>array,'count'=>int)
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function GetCommentsAll($sTargetType,$iPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
2010-02-06 18:56:01 +02:00
|
|
|
|
$s=serialize($aExcludeTarget).serialize($aExcludeParentTarget);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if (false === ($data = $this->Cache_Get("comment_all_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
|
2010-02-06 18:56:01 +02:00
|
|
|
|
$data = array('collection'=>$this->oMapper->GetCommentsAll($sTargetType,$iCount,$iPage,$iPerPage,$aExcludeTarget,$aExcludeParentTarget),'count'=>$iCount);
|
2009-10-15 18:52:53 +03:00
|
|
|
|
$this->Cache_Set($data, "comment_all_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}", array("comment_new_{$sTargetType}","comment_update_status_{$sTargetType}"), 60*60*24*1);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2010-02-06 18:56:01 +02:00
|
|
|
|
$data['collection']=$this->GetCommentsAdditionalData($data['collection'],array('target','favourite','user'=>array()));
|
2012-06-24 10:20:49 +03:00
|
|
|
|
return $data;
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-06-23 20:06:19 +03:00
|
|
|
|
* Получает дополнительные данные(объекты) для комментов по их ID
|
2008-11-12 22:04:21 +02:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array $aCommentId Список ID комментов
|
|
|
|
|
* @param array|null $aAllowData Список типов дополнительных данных, которые нужно получить для комментариев
|
|
|
|
|
* @return array
|
2008-11-12 22:04:21 +02:00
|
|
|
|
*/
|
2012-04-09 12:39:40 +03:00
|
|
|
|
public function GetCommentsAdditionalData($aCommentId,$aAllowData=null) {
|
|
|
|
|
if (is_null($aAllowData)) {
|
|
|
|
|
$aAllowData=array('vote','target','favourite','user'=>array());
|
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
func_array_simpleflip($aAllowData);
|
|
|
|
|
if (!is_array($aCommentId)) {
|
|
|
|
|
$aCommentId=array($aCommentId);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получаем комменты
|
|
|
|
|
*/
|
|
|
|
|
$aComments=$this->GetCommentsByArrayId($aCommentId);
|
|
|
|
|
/**
|
|
|
|
|
* Формируем ID дополнительных данных, которые нужно получить
|
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aUserId=array();
|
|
|
|
|
$aTargetId=array('topic'=>array(),'talk'=>array());
|
2009-06-23 20:06:19 +03:00
|
|
|
|
foreach ($aComments as $oComment) {
|
|
|
|
|
if (isset($aAllowData['user'])) {
|
|
|
|
|
$aUserId[]=$oComment->getUserId();
|
|
|
|
|
}
|
|
|
|
|
if (isset($aAllowData['target'])) {
|
|
|
|
|
$aTargetId[$oComment->getTargetType()][]=$oComment->getTargetId();
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получаем дополнительные данные
|
|
|
|
|
*/
|
|
|
|
|
$aUsers=isset($aAllowData['user']) && is_array($aAllowData['user']) ? $this->User_GetUsersAdditionalData($aUserId,$aAllowData['user']) : $this->User_GetUsersAdditionalData($aUserId);
|
|
|
|
|
/**
|
|
|
|
|
* В зависимости от типа target_type достаем данные
|
|
|
|
|
*/
|
|
|
|
|
$aTargets=array();
|
2009-07-26 16:43:16 +03:00
|
|
|
|
//$aTargets['topic']=isset($aAllowData['target']) && is_array($aAllowData['target']) ? $this->Topic_GetTopicsAdditionalData($aTargetId['topic'],$aAllowData['target']) : $this->Topic_GetTopicsAdditionalData($aTargetId['topic']);
|
2012-08-05 14:54:48 +03:00
|
|
|
|
$aTargets['topic']=$this->Topic_GetTopicsAdditionalData($aTargetId['topic'],array('blog'=>array('owner'=>array()),'user'=>array()));
|
2009-06-28 17:04:44 +03:00
|
|
|
|
$aVote=array();
|
|
|
|
|
if (isset($aAllowData['vote']) and $this->oUserCurrent) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aVote=$this->Vote_GetVoteByArray($aCommentId,'comment',$this->oUserCurrent->getId());
|
2009-06-28 17:04:44 +03:00
|
|
|
|
}
|
2010-01-05 19:27:21 +02:00
|
|
|
|
if (isset($aAllowData['favourite']) and $this->oUserCurrent) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aFavouriteComments=$this->Favourite_GetFavouritesByArray($aCommentId,'comment',$this->oUserCurrent->getId());
|
2010-01-05 19:27:21 +02:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Добавляем данные к результату
|
|
|
|
|
*/
|
|
|
|
|
foreach ($aComments as $oComment) {
|
|
|
|
|
if (isset($aUsers[$oComment->getUserId()])) {
|
|
|
|
|
$oComment->setUser($aUsers[$oComment->getUserId()]);
|
|
|
|
|
} else {
|
2010-05-27 18:16:20 +03:00
|
|
|
|
$oComment->setUser(null); // или $oComment->setUser(new ModuleUser_EntityUser());
|
2009-06-23 20:06:19 +03:00
|
|
|
|
}
|
|
|
|
|
if (isset($aTargets[$oComment->getTargetType()][$oComment->getTargetId()])) {
|
|
|
|
|
$oComment->setTarget($aTargets[$oComment->getTargetType()][$oComment->getTargetId()]);
|
|
|
|
|
} else {
|
|
|
|
|
$oComment->setTarget(null);
|
|
|
|
|
}
|
2009-06-28 17:04:44 +03:00
|
|
|
|
if (isset($aVote[$oComment->getId()])) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$oComment->setVote($aVote[$oComment->getId()]);
|
2009-06-28 17:04:44 +03:00
|
|
|
|
} else {
|
|
|
|
|
$oComment->setVote(null);
|
|
|
|
|
}
|
2009-08-22 00:01:09 +03:00
|
|
|
|
if (isset($aFavouriteComments[$oComment->getId()])) {
|
|
|
|
|
$oComment->setIsFavourite(true);
|
|
|
|
|
} else {
|
|
|
|
|
$oComment->setIsFavourite(false);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2008-11-12 22:04:21 +02:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
return $aComments;
|
2008-11-12 22:04:21 +02:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Список комментов по ID
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array $aCommentId Список ID комментариев
|
|
|
|
|
* @return array
|
2009-06-23 20:06:19 +03:00
|
|
|
|
*/
|
|
|
|
|
public function GetCommentsByArrayId($aCommentId) {
|
2009-08-08 12:33:32 +03:00
|
|
|
|
if (!$aCommentId) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2009-10-10 22:13:14 +03:00
|
|
|
|
if (Config::Get('sys.cache.solid')) {
|
2009-08-08 12:33:32 +03:00
|
|
|
|
return $this->GetCommentsByArrayIdSolid($aCommentId);
|
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
if (!is_array($aCommentId)) {
|
|
|
|
|
$aCommentId=array($aCommentId);
|
|
|
|
|
}
|
|
|
|
|
$aCommentId=array_unique($aCommentId);
|
|
|
|
|
$aComments=array();
|
|
|
|
|
$aCommentIdNotNeedQuery=array();
|
|
|
|
|
/**
|
|
|
|
|
* Делаем мульти-запрос к кешу
|
|
|
|
|
*/
|
|
|
|
|
$aCacheKeys=func_build_cache_keys($aCommentId,'comment_');
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if (false !== ($data = $this->Cache_Get($aCacheKeys))) {
|
2009-06-23 20:06:19 +03:00
|
|
|
|
/**
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* Проверяем что досталось из кеша
|
2009-06-23 20:06:19 +03:00
|
|
|
|
*/
|
|
|
|
|
foreach ($aCacheKeys as $sValue => $sKey ) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if (array_key_exists($sKey,$data)) {
|
2009-06-23 20:06:19 +03:00
|
|
|
|
if ($data[$sKey]) {
|
|
|
|
|
$aComments[$data[$sKey]->getId()]=$data[$sKey];
|
|
|
|
|
} else {
|
|
|
|
|
$aCommentIdNotNeedQuery[]=$sValue;
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Смотрим каких комментов не было в кеше и делаем запрос в БД
|
2012-06-24 10:20:49 +03:00
|
|
|
|
*/
|
|
|
|
|
$aCommentIdNeedQuery=array_diff($aCommentId,array_keys($aComments));
|
|
|
|
|
$aCommentIdNeedQuery=array_diff($aCommentIdNeedQuery,$aCommentIdNotNeedQuery);
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$aCommentIdNeedStore=$aCommentIdNeedQuery;
|
|
|
|
|
if ($data = $this->oMapper->GetCommentsByArrayId($aCommentIdNeedQuery)) {
|
|
|
|
|
foreach ($data as $oComment) {
|
|
|
|
|
/**
|
|
|
|
|
* Добавляем к результату и сохраняем в кеш
|
|
|
|
|
*/
|
|
|
|
|
$aComments[$oComment->getId()]=$oComment;
|
2009-08-08 12:33:32 +03:00
|
|
|
|
$this->Cache_Set($oComment, "comment_{$oComment->getId()}", array(), 60*60*24*4);
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$aCommentIdNeedStore=array_diff($aCommentIdNeedStore,array($oComment->getId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Сохраняем в кеш запросы не вернувшие результата
|
|
|
|
|
*/
|
|
|
|
|
foreach ($aCommentIdNeedStore as $sId) {
|
2009-07-26 16:43:16 +03:00
|
|
|
|
$this->Cache_Set(null, "comment_{$sId}", array(), 60*60*24*4);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Сортируем результат согласно входящему массиву
|
|
|
|
|
*/
|
|
|
|
|
$aComments=func_array_sort_by_keys($aComments,$aCommentId);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
return $aComments;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получает список комментариев по ID используя единый кеш
|
|
|
|
|
*
|
|
|
|
|
* @param array $aCommentId Список ID комментариев
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2009-08-08 12:33:32 +03:00
|
|
|
|
public function GetCommentsByArrayIdSolid($aCommentId) {
|
|
|
|
|
if (!is_array($aCommentId)) {
|
|
|
|
|
$aCommentId=array($aCommentId);
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aCommentId=array_unique($aCommentId);
|
|
|
|
|
$aComments=array();
|
2009-08-08 12:33:32 +03:00
|
|
|
|
$s=join(',',$aCommentId);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if (false === ($data = $this->Cache_Get("comment_id_{$s}"))) {
|
2009-08-08 12:33:32 +03:00
|
|
|
|
$data = $this->oMapper->GetCommentsByArrayId($aCommentId);
|
|
|
|
|
foreach ($data as $oComment) {
|
|
|
|
|
$aComments[$oComment->getId()]=$oComment;
|
|
|
|
|
}
|
|
|
|
|
$this->Cache_Set($aComments, "comment_id_{$s}", array("comment_update"), 60*60*24*1);
|
|
|
|
|
return $aComments;
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-08-08 12:33:32 +03:00
|
|
|
|
return $data;
|
|
|
|
|
}
|
2008-11-12 22:04:21 +02:00
|
|
|
|
/**
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* Получить все комменты сгрупированные по типу(для вывода прямого эфира)
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iLimit Количество элементов
|
|
|
|
|
* @return array
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2009-06-23 20:06:19 +03:00
|
|
|
|
public function GetCommentsOnline($sTargetType,$iLimit) {
|
2009-09-19 03:43:00 +03:00
|
|
|
|
/**
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* Исключаем из выборки идентификаторы закрытых блогов (target_parent_id)
|
2009-09-19 03:43:00 +03:00
|
|
|
|
*/
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$aCloseBlogs = ($this->oUserCurrent)
|
|
|
|
|
? $this->Blog_GetInaccessibleBlogsByUser($this->oUserCurrent)
|
|
|
|
|
: $this->Blog_GetInaccessibleBlogsByUser();
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$s=serialize($aCloseBlogs);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
|
|
|
|
if (false === ($data = $this->Cache_Get("comment_online_{$sTargetType}_{$s}_{$iLimit}"))) {
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$data = $this->oMapper->GetCommentsOnline($sTargetType,$aCloseBlogs,$iLimit);
|
2009-09-19 03:43:00 +03:00
|
|
|
|
$this->Cache_Set($data, "comment_online_{$sTargetType}_{$s}_{$iLimit}", array("comment_online_update_{$sTargetType}"), 60*60*24*1);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$data=$this->GetCommentsAdditionalData($data);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
return $data;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получить комменты по юзеру
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sId ID пользователя
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iPage Номер страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на страницу
|
2009-11-04 20:24:21 +02:00
|
|
|
|
* @return array
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function GetCommentsByUserId($sId,$sTargetType,$iPage,$iPerPage) {
|
2009-09-18 23:36:07 +03:00
|
|
|
|
/**
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* Исключаем из выборки идентификаторы закрытых блогов
|
2009-09-18 23:36:07 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
|
|
|
|
|
? array()
|
2009-11-18 20:46:16 +02:00
|
|
|
|
: $this->Blog_GetInaccessibleBlogsByUser();
|
|
|
|
|
$s=serialize($aCloseBlogs);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
|
|
|
|
if (false === ($data = $this->Cache_Get("comment_user_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$data = array('collection'=>$this->oMapper->GetCommentsByUserId($sId,$sTargetType,$iCount,$iPage,$iPerPage,array(),$aCloseBlogs),'count'=>$iCount);
|
2009-09-20 21:43:20 +03:00
|
|
|
|
$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);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$data['collection']=$this->GetCommentsAdditionalData($data['collection']);
|
2009-11-18 20:46:16 +02:00
|
|
|
|
return $data;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2009-11-18 20:46:16 +02:00
|
|
|
|
/**
|
|
|
|
|
* Получает количество комментариев одного пользователя
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param id $sId ID пользователя
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2009-06-23 20:06:19 +03:00
|
|
|
|
public function GetCountCommentsByUserId($sId,$sTargetType) {
|
2009-09-18 23:36:07 +03:00
|
|
|
|
/**
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* Исключаем из выборки идентификаторы закрытых блогов
|
2009-09-18 23:36:07 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
|
|
|
|
|
? array()
|
2009-11-18 20:46:16 +02:00
|
|
|
|
: $this->Blog_GetInaccessibleBlogsByUser();
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$s=serialize($aCloseBlogs);
|
|
|
|
|
|
|
|
|
|
if (false === ($data = $this->Cache_Get("comment_count_user_{$sId}_{$sTargetType}_{$s}"))) {
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$data = $this->oMapper->GetCountCommentsByUserId($sId,$sTargetType,array(),$aCloseBlogs);
|
2009-09-20 16:26:09 +03:00
|
|
|
|
$this->Cache_Set($data, "comment_count_user_{$sId}_{$sTargetType}", array("comment_new_user_{$sId}_{$sTargetType}","comment_update_status_{$sTargetType}"), 60*60*24*2);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2009-11-18 20:46:16 +02:00
|
|
|
|
return $data;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получить комменты по рейтингу и дате
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param string $sDate Дата за которую выводить рейтинг, т.к. кеширование происходит по дате, то дату лучше передавать с точностью до часа (минуты и секунды как 00:00)
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iLimit Количество элементов
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* @return array
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2009-06-23 20:06:19 +03:00
|
|
|
|
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit=20) {
|
2009-09-19 17:48:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* Выбираем топики, комметарии к которым являются недоступными для пользователя
|
|
|
|
|
*/
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$aCloseBlogs = ($this->oUserCurrent)
|
|
|
|
|
? $this->Blog_GetInaccessibleBlogsByUser($this->oUserCurrent)
|
|
|
|
|
: $this->Blog_GetInaccessibleBlogsByUser();
|
|
|
|
|
$s=serialize($aCloseBlogs);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
/**
|
|
|
|
|
* Т.к. время передаётся с точностью 1 час то можно по нему замутить кеширование
|
|
|
|
|
*/
|
|
|
|
|
if (false === ($data = $this->Cache_Get("comment_rating_{$sDate}_{$sTargetType}_{$iLimit}_{$s}"))) {
|
2009-11-18 20:46:16 +02:00
|
|
|
|
$data = $this->oMapper->GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,array(),$aCloseBlogs);
|
2009-09-19 17:48:28 +03:00
|
|
|
|
$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);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$data=$this->GetCommentsAdditionalData($data);
|
2009-11-04 12:36:08 +02:00
|
|
|
|
return $data;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* Получить комменты по владельцу
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iPage Номер страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на страницу
|
|
|
|
|
* @return array('comments'=>array,'iMaxIdComment'=>int)
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function GetCommentsByTargetId($sId,$sTargetType,$iPage=1,$iPerPage=0) {
|
2010-09-19 00:58:52 +03:00
|
|
|
|
if (Config::Get('module.comment.use_nested')) {
|
|
|
|
|
return $this->GetCommentsTreeByTargetId($sId,$sTargetType,$iPage,$iPerPage);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2010-09-19 00:58:52 +03:00
|
|
|
|
|
|
|
|
|
if (false === ($aCommentsRec = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}"))) {
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$aCommentsRow=$this->oMapper->GetCommentsByTargetId($sId,$sTargetType);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
if (count($aCommentsRow)) {
|
2010-09-19 00:58:52 +03:00
|
|
|
|
$aCommentsRec=$this->BuildCommentsRecursive($aCommentsRow);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$this->Cache_Set($aCommentsRec, "comment_target_{$sId}_{$sTargetType}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*2);
|
2009-10-25 22:01:05 +02:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
if (!isset($aCommentsRec['comments'])) {
|
2009-01-10 21:23:36 +02:00
|
|
|
|
return array('comments'=>array(),'iMaxIdComment'=>0);
|
2009-11-10 20:49:53 +02:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$aComments=$aCommentsRec;
|
2010-09-19 00:58:52 +03:00
|
|
|
|
$aComments['comments']=$this->GetCommentsAdditionalData(array_keys($aCommentsRec['comments']));
|
2009-06-23 20:06:19 +03:00
|
|
|
|
foreach ($aComments['comments'] as $oComment) {
|
2010-09-19 00:58:52 +03:00
|
|
|
|
$oComment->setLevel($aCommentsRec['comments'][$oComment->getId()]);
|
2009-01-10 21:23:36 +02:00
|
|
|
|
}
|
2009-10-15 18:52:53 +03:00
|
|
|
|
return $aComments;
|
2010-09-19 00:58:52 +03:00
|
|
|
|
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2010-09-19 00:58:52 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает комменты используя nested set
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iPage Номер страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на страницу
|
|
|
|
|
* @return array('comments'=>array,'iMaxIdComment'=>int,'count'=>int)
|
2010-09-19 00:58:52 +03:00
|
|
|
|
*/
|
2010-09-21 12:29:54 +03:00
|
|
|
|
public function GetCommentsTreeByTargetId($sId,$sTargetType,$iPage=1,$iPerPage=0) {
|
|
|
|
|
if (!Config::Get('module.comment.nested_page_reverse') and $iPerPage and $iCountPage=ceil($this->GetCountCommentsRootByTargetId($sId,$sTargetType)/$iPerPage)) {
|
|
|
|
|
$iPage=$iCountPage-$iPage+1;
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$iPage=$iPage<1 ? 1 : $iPage;
|
2010-09-19 00:58:52 +03:00
|
|
|
|
if (false === ($aReturn = $this->Cache_Get("comment_tree_target_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}"))) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
2010-09-19 00:58:52 +03:00
|
|
|
|
/**
|
|
|
|
|
* Нужно или нет использовать постраничное разбиение комментариев
|
|
|
|
|
*/
|
|
|
|
|
if ($iPerPage) {
|
|
|
|
|
$aComments=$this->oMapper->GetCommentsTreePageByTargetId($sId,$sTargetType,$iCount,$iPage,$iPerPage);
|
|
|
|
|
} else {
|
|
|
|
|
$aComments=$this->oMapper->GetCommentsTreeByTargetId($sId,$sTargetType);
|
|
|
|
|
$iCount=count($aComments);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2010-09-19 13:09:31 +03:00
|
|
|
|
$iMaxIdComment=count($aComments) ? max($aComments) : 0;
|
2010-09-19 00:58:52 +03:00
|
|
|
|
$aReturn=array('comments'=>$aComments,'iMaxIdComment'=>$iMaxIdComment,'count'=>$iCount);
|
|
|
|
|
$this->Cache_Set($aReturn, "comment_tree_target_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*2);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2010-09-19 00:58:52 +03:00
|
|
|
|
$aReturn['comments']=$this->GetCommentsAdditionalData($aReturn['comments']);
|
|
|
|
|
return $aReturn;
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает количество дочерних комментариев у корневого коммента
|
|
|
|
|
*
|
|
|
|
|
* @param int $sId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2010-09-19 00:58:52 +03:00
|
|
|
|
public function GetCountCommentsRootByTargetId($sId,$sTargetType) {
|
|
|
|
|
return $this->oMapper->GetCountCommentsRootByTargetId($sId,$sTargetType);
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает номер страницы, на которой расположен комментарий
|
|
|
|
|
*
|
|
|
|
|
* @param int $sId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param ModuleComment_EntityComment $oComment Объект комментария
|
|
|
|
|
* @return bool|int
|
|
|
|
|
*/
|
2010-09-19 12:27:13 +03:00
|
|
|
|
public function GetPageCommentByTargetId($sId,$sTargetType,$oComment) {
|
|
|
|
|
if (!Config::Get('module.comment.nested_per_page')) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (is_numeric($oComment)) {
|
|
|
|
|
if (!($oComment=$this->GetCommentById($oComment))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ($oComment->getTargetId()!=$sId or $oComment->getTargetType()!=$sTargetType) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получаем корневого родителя
|
|
|
|
|
*/
|
|
|
|
|
if ($oComment->getPid()) {
|
|
|
|
|
if (!($oCommentRoot=$this->oMapper->GetCommentRootByTargetIdAndChildren($sId,$sTargetType,$oComment->getLeft()))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$oCommentRoot=$oComment;
|
|
|
|
|
}
|
|
|
|
|
$iCount=ceil($this->oMapper->GetCountCommentsAfterByTargetId($sId,$sTargetType,$oCommentRoot->getLeft())/Config::Get('module.comment.nested_per_page'));
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
2010-09-21 12:29:54 +03:00
|
|
|
|
if (!Config::Get('module.comment.nested_page_reverse') and $iCountPage=ceil($this->GetCountCommentsRootByTargetId($sId,$sTargetType)/Config::Get('module.comment.nested_per_page'))) {
|
|
|
|
|
$iCount=$iCountPage-$iCount+1;
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2010-09-19 12:27:13 +03:00
|
|
|
|
return $iCount ? $iCount : 1;
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-06-23 20:06:19 +03:00
|
|
|
|
* Добавляет коммент
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleComment_EntityComment $oComment Объект комментария
|
|
|
|
|
* @return bool|ModuleComment_EntityComment
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2010-05-27 18:16:20 +03:00
|
|
|
|
public function AddComment(ModuleComment_EntityComment $oComment) {
|
2010-09-19 00:58:52 +03:00
|
|
|
|
if (Config::Get('module.comment.use_nested')) {
|
|
|
|
|
$sId=$this->oMapper->AddCommentTree($oComment);
|
2012-06-10 13:51:56 +03:00
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update"));
|
2010-09-19 00:58:52 +03:00
|
|
|
|
} else {
|
|
|
|
|
$sId=$this->oMapper->AddComment($oComment);
|
|
|
|
|
}
|
|
|
|
|
if ($sId) {
|
2009-06-23 20:06:19 +03:00
|
|
|
|
if ($oComment->getTargetType()=='topic') {
|
|
|
|
|
$this->Topic_increaseTopicCountComment($oComment->getTargetId());
|
|
|
|
|
}
|
|
|
|
|
//чистим зависимые кеши
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_new_{$oComment->getTargetType()}","comment_new_user_{$oComment->getUserId()}_{$oComment->getTargetType()}","comment_new_{$oComment->getTargetType()}_{$oComment->getTargetId()}"));
|
|
|
|
|
$oComment->setId($sId);
|
|
|
|
|
return $oComment;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-11-18 20:46:16 +02:00
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-06-23 20:06:19 +03:00
|
|
|
|
* Обновляет коммент
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleComment_EntityComment $oComment Объект комментария
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* @return bool
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function UpdateComment(ModuleComment_EntityComment $oComment) {
|
|
|
|
|
if ($this->oMapper->UpdateComment($oComment)) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
//чистим зависимые кеши
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update","comment_update_{$oComment->getTargetType()}_{$oComment->getTargetId()}"));
|
2009-07-26 16:43:16 +03:00
|
|
|
|
$this->Cache_Delete("comment_{$oComment->getId()}");
|
2009-06-23 20:06:19 +03:00
|
|
|
|
return true;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-06-23 20:06:19 +03:00
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-06-23 20:06:19 +03:00
|
|
|
|
* Обновляет рейтинг у коммента
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleComment_EntityComment $oComment Объект комментария
|
2009-11-18 20:46:16 +02:00
|
|
|
|
* @return bool
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function UpdateCommentRating(ModuleComment_EntityComment $oComment) {
|
|
|
|
|
if ($this->oMapper->UpdateComment($oComment)) {
|
2009-06-23 20:06:19 +03:00
|
|
|
|
//чистим зависимые кеши
|
2009-11-10 20:49:53 +02:00
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_rating_{$oComment->getTargetType()}"));
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$this->Cache_Delete("comment_{$oComment->getId()}");
|
2008-09-21 09:36:57 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-06-23 20:06:19 +03:00
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-06-23 20:06:19 +03:00
|
|
|
|
* Обновляет статус у коммента - delete или publish
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleComment_EntityComment $oComment Объект комментария
|
2009-10-25 22:01:05 +02:00
|
|
|
|
* @return bool
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function UpdateCommentStatus(ModuleComment_EntityComment $oComment) {
|
|
|
|
|
if ($this->oMapper->UpdateComment($oComment)) {
|
2009-10-25 22:01:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Если комментарий удаляется, удаляем его из прямого эфира
|
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if($oComment->getDelete()) $this->DeleteCommentOnlineByArrayId($oComment->getId(),$oComment->getTargetType());
|
2010-06-05 01:05:15 +03:00
|
|
|
|
/**
|
|
|
|
|
* Обновляем избранное
|
|
|
|
|
*/
|
|
|
|
|
$this->Favourite_SetFavouriteTargetPublish($oComment->getId(),'comment',!$oComment->getDelete());
|
2009-10-25 22:01:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Чистим зависимые кеши
|
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if(Config::Get('sys.cache.solid')){
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update"));
|
2009-11-10 20:49:53 +02:00
|
|
|
|
}
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$oComment->getTargetType()}"));
|
|
|
|
|
$this->Cache_Delete("comment_{$oComment->getId()}");
|
2008-09-21 09:36:57 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливает publish у коммента
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sTargetId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $iPublish Статус отображать комментарии или нет
|
2009-08-22 00:01:09 +03:00
|
|
|
|
* @return bool
|
2009-06-23 20:06:19 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function SetCommentsPublish($sTargetId,$sTargetType,$iPublish) {
|
2009-11-20 02:59:01 +02:00
|
|
|
|
if(!$aComments = $this->GetCommentsByTargetId($sTargetId,$sTargetType)) {
|
2009-08-22 00:01:09 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-11-20 02:59:01 +02:00
|
|
|
|
if(!isset($aComments['comments']) or count($aComments)==0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$sTargetType}"));
|
2009-10-25 22:01:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Если статус публикации успешно изменен, то меняем статус в отметке "избранное".
|
|
|
|
|
* Если комментарии снимаются с публикации, удаляем их из прямого эфира.
|
|
|
|
|
*/
|
|
|
|
|
if($this->oMapper->SetCommentsPublish($sTargetId,$sTargetType,$iPublish)){
|
2009-11-20 02:59:01 +02:00
|
|
|
|
$this->Favourite_SetFavouriteTargetPublish(array_keys($aComments['comments']),'comment',$iPublish);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if($iPublish!=1) $this->DeleteCommentOnlineByTargetId($sTargetId,$sTargetType);
|
2009-10-25 22:01:05 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-06-23 20:06:19 +03:00
|
|
|
|
}
|
2008-10-10 20:23:00 +03:00
|
|
|
|
/**
|
|
|
|
|
* Удаляет коммент из прямого эфира
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sTargetId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @return bool
|
2008-10-10 20:23:00 +03:00
|
|
|
|
*/
|
2009-06-23 20:06:19 +03:00
|
|
|
|
public function DeleteCommentOnlineByTargetId($sTargetId,$sTargetType) {
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}"));
|
|
|
|
|
return $this->oMapper->DeleteCommentOnlineByTargetId($sTargetId,$sTargetType);
|
2008-10-28 20:54:36 +02:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Добавляет новый коммент в прямой эфир
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleComment_EntityCommentOnline $oCommentOnline Объект онлайн комментария
|
|
|
|
|
* @return bool|int
|
2008-10-28 20:54:36 +02:00
|
|
|
|
*/
|
2010-05-27 18:16:20 +03:00
|
|
|
|
public function AddCommentOnline(ModuleComment_EntityCommentOnline $oCommentOnline) {
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$oCommentOnline->getTargetType()}"));
|
|
|
|
|
return $this->oMapper->AddCommentOnline($oCommentOnline);
|
2008-10-10 20:23:00 +03:00
|
|
|
|
}
|
2009-01-10 21:23:36 +02:00
|
|
|
|
/**
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* Получить новые комменты для владельца
|
2009-01-10 21:23:36 +02:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sId ID владельца коммента
|
|
|
|
|
* @param string $sTargetType Тип владельца комментария
|
|
|
|
|
* @param int $sIdCommentLast ID последнего прочитанного комментария
|
|
|
|
|
* @return array('comments'=>array,'iMaxIdComment'=>int)
|
2009-01-10 21:23:36 +02:00
|
|
|
|
*/
|
2009-06-23 20:06:19 +03:00
|
|
|
|
public function GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if (false === ($aComments = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}_{$sIdCommentLast}"))) {
|
|
|
|
|
$aComments=$this->oMapper->GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast);
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$this->Cache_Set($aComments, "comment_target_{$sId}_{$sTargetType}_{$sIdCommentLast}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*1);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-06-23 20:06:19 +03:00
|
|
|
|
if (count($aComments)==0) {
|
2009-01-10 21:23:36 +02:00
|
|
|
|
return array('comments'=>array(),'iMaxIdComment'=>0);
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
|
|
|
|
$iMaxIdComment=max($aComments);
|
2012-04-29 20:28:37 +03:00
|
|
|
|
$aCmts=$this->GetCommentsAdditionalData($aComments);
|
2009-12-14 22:25:30 +02:00
|
|
|
|
$oViewerLocal=$this->Viewer_GetLocalViewer();
|
2009-06-27 12:10:11 +03:00
|
|
|
|
$oViewerLocal->Assign('oUserCurrent',$this->User_GetUserCurrent());
|
|
|
|
|
$oViewerLocal->Assign('bOneComment',true);
|
2009-08-28 10:22:54 +03:00
|
|
|
|
if($sTargetType!='topic') {
|
|
|
|
|
$oViewerLocal->Assign('bNoCommentFavourites',true);
|
|
|
|
|
}
|
2009-01-10 21:23:36 +02:00
|
|
|
|
$aCmt=array();
|
2012-06-24 10:20:49 +03:00
|
|
|
|
foreach ($aCmts as $oComment) {
|
|
|
|
|
$oViewerLocal->Assign('oComment',$oComment);
|
2012-04-29 20:28:37 +03:00
|
|
|
|
$sText=$oViewerLocal->Fetch($this->GetTemplateCommentByTarget($sId,$sTargetType));
|
2009-01-10 21:23:36 +02:00
|
|
|
|
$aCmt[]=array(
|
|
|
|
|
'html' => $sText,
|
|
|
|
|
'obj' => $oComment,
|
2012-06-24 10:20:49 +03:00
|
|
|
|
);
|
2009-01-10 21:23:36 +02:00
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
return array('comments'=>$aCmt,'iMaxIdComment'=>$iMaxIdComment);
|
2009-01-10 21:23:36 +02:00
|
|
|
|
}
|
2012-04-29 20:28:37 +03:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает шаблон комментария для рендеринга
|
|
|
|
|
* Плагин может переопределить данный метод и вернуть свой шаблон в зависимости от типа
|
|
|
|
|
*
|
|
|
|
|
* @param int $iTargetId ID объекта комментирования
|
|
|
|
|
* @param string $sTargetType Типа объекта комментирования
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function GetTemplateCommentByTarget($iTargetId,$sTargetType) {
|
|
|
|
|
return "comment.tpl";
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Строит дерево комментариев
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array $aComments Список комментариев
|
|
|
|
|
* @param bool $bBegin Флаг начала построения дерева, для инициализации параметров внутри метода
|
|
|
|
|
* @return array('comments'=>array,'iMaxIdComment'=>int)
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
|
|
|
|
protected function BuildCommentsRecursive($aComments,$bBegin=true) {
|
|
|
|
|
static $aResultCommnets;
|
|
|
|
|
static $iLevel;
|
2009-01-10 21:23:36 +02:00
|
|
|
|
static $iMaxIdComment;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
if ($bBegin) {
|
|
|
|
|
$aResultCommnets=array();
|
|
|
|
|
$iLevel=0;
|
2009-01-10 21:23:36 +02:00
|
|
|
|
$iMaxIdComment=0;
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
foreach ($aComments as $aComment) {
|
|
|
|
|
$aTemp=$aComment;
|
2009-01-10 21:23:36 +02:00
|
|
|
|
if ($aComment['comment_id']>$iMaxIdComment) {
|
|
|
|
|
$iMaxIdComment=$aComment['comment_id'];
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$aTemp['level']=$iLevel;
|
|
|
|
|
unset($aTemp['childNodes']);
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$aResultCommnets[$aTemp['comment_id']]=$aTemp['level'];
|
2008-09-21 09:36:57 +03:00
|
|
|
|
if (isset($aComment['childNodes']) and count($aComment['childNodes'])>0) {
|
|
|
|
|
$iLevel++;
|
|
|
|
|
$this->BuildCommentsRecursive($aComment['childNodes'],false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$iLevel--;
|
2009-01-10 21:23:36 +02:00
|
|
|
|
return array('comments'=>$aResultCommnets,'iMaxIdComment'=>$iMaxIdComment);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
2009-08-22 00:01:09 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает привязку комментария к ибранному(добавлен ли коммент в избранное у юзера)
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sCommentId ID комментария
|
|
|
|
|
* @param int $sUserId ID пользователя
|
2010-05-27 18:16:20 +03:00
|
|
|
|
* @return ModuleFavourite_EntityFavourite|null
|
2009-08-22 00:01:09 +03:00
|
|
|
|
*/
|
|
|
|
|
public function GetFavouriteComment($sCommentId,$sUserId) {
|
|
|
|
|
return $this->Favourite_GetFavourite($sCommentId,'comment',$sUserId);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получить список избранного по списку айдишников
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array $aCommentId Список ID комментов
|
|
|
|
|
* @param int $sUserId ID пользователя
|
|
|
|
|
* @return array
|
2009-08-22 00:01:09 +03:00
|
|
|
|
*/
|
|
|
|
|
public function GetFavouriteCommentsByArray($aCommentId,$sUserId) {
|
|
|
|
|
return $this->Favourite_GetFavouritesByArray($aCommentId,'comment',$sUserId);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получить список избранного по списку айдишников, но используя единый кеш
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array $aCommentId Список ID комментов
|
|
|
|
|
* @param int $sUserId ID пользователя
|
2009-08-22 00:01:09 +03:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function GetFavouriteCommentsByArraySolid($aCommentId,$sUserId) {
|
|
|
|
|
return $this->Favourite_GetFavouritesByArraySolid($aCommentId,'comment',$sUserId);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получает список комментариев из избранного пользователя
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sUserId ID пользователя
|
|
|
|
|
* @param int $iCurrPage Номер страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на страницу
|
2009-08-22 00:01:09 +03:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function GetCommentsFavouriteByUserId($sUserId,$iCurrPage,$iPerPage) {
|
2009-09-19 13:53:33 +03:00
|
|
|
|
$aCloseTopics = array();
|
2009-09-19 03:43:00 +03:00
|
|
|
|
/**
|
2009-09-19 13:53:33 +03:00
|
|
|
|
* Получаем список идентификаторов избранных комментов
|
2009-09-19 03:43:00 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$data = ($this->oUserCurrent && $sUserId==$this->oUserCurrent->getId())
|
2009-10-15 02:34:03 +03:00
|
|
|
|
? $this->Favourite_GetFavouritesByUserId($sUserId,'comment',$iCurrPage,$iPerPage,$aCloseTopics)
|
2009-09-19 13:53:33 +03:00
|
|
|
|
: $this->Favourite_GetFavouriteOpenCommentsByUserId($sUserId,$iCurrPage,$iPerPage);
|
|
|
|
|
/**
|
|
|
|
|
* Получаем комменты по переданому массиву айдишников
|
2012-06-24 10:20:49 +03:00
|
|
|
|
*/
|
|
|
|
|
$data['collection']=$this->GetCommentsAdditionalData($data['collection']);
|
|
|
|
|
return $data;
|
2009-08-22 00:01:09 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает число комментариев в избранном
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sUserId ID пользователя
|
2009-08-22 00:01:09 +03:00
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function GetCountCommentsFavouriteByUserId($sUserId) {
|
2009-09-19 13:53:33 +03:00
|
|
|
|
return ($this->oUserCurrent && $sUserId==$this->oUserCurrent->getId())
|
|
|
|
|
? $this->Favourite_GetCountFavouritesByUserId($sUserId,'comment')
|
|
|
|
|
: $this->Favourite_GetCountFavouriteOpenCommentsByUserId($sUserId);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
}
|
2009-08-22 00:01:09 +03:00
|
|
|
|
/**
|
|
|
|
|
* Добавляет комментарий в избранное
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
|
|
|
|
* @return bool|ModuleFavourite_EntityFavourite
|
2009-08-22 00:01:09 +03:00
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
public function AddFavouriteComment(ModuleFavourite_EntityFavourite $oFavourite) {
|
|
|
|
|
if( ($oFavourite->getTargetType()=='comment')
|
|
|
|
|
&& ($oComment=$this->Comment_GetCommentById($oFavourite->getTargetId()))
|
|
|
|
|
&& in_array($oComment->getTargetType(),Config::get('module.comment.favourite_target_allow'))) {
|
|
|
|
|
return $this->Favourite_AddFavourite($oFavourite);
|
|
|
|
|
}
|
2009-08-28 10:22:54 +03:00
|
|
|
|
return false;
|
2009-08-22 00:01:09 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Удаляет комментарий из избранного
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
2009-08-22 00:01:09 +03:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2010-05-27 18:16:20 +03:00
|
|
|
|
public function DeleteFavouriteComment(ModuleFavourite_EntityFavourite $oFavourite) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if( ($oFavourite->getTargetType()=='comment')
|
|
|
|
|
&& ($oComment=$this->Comment_GetCommentById($oFavourite->getTargetId()))
|
|
|
|
|
&& in_array($oComment->getTargetType(),Config::get('module.comment.favourite_target_allow'))) {
|
|
|
|
|
return $this->Favourite_DeleteFavourite($oFavourite);
|
2009-08-28 10:22:54 +03:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-10-25 22:01:05 +02:00
|
|
|
|
}
|
|
|
|
|
/**
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* Удаляет комментарии из избранного по списку
|
2009-10-25 22:01:05 +02:00
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array $aCommentId Список ID комментариев
|
2009-10-25 22:01:05 +02:00
|
|
|
|
* @return bool
|
2012-06-24 10:20:49 +03:00
|
|
|
|
*/
|
2009-10-25 22:01:05 +02:00
|
|
|
|
public function DeleteFavouriteCommentsByArrayId($aCommentId) {
|
2012-06-24 10:20:49 +03:00
|
|
|
|
return $this->Favourite_DeleteFavouriteByTargetId($aCommentId, 'comment');
|
2009-10-25 22:01:05 +02:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Удаляет комментарии из базы данных
|
2012-06-24 10:20:49 +03:00
|
|
|
|
*
|
|
|
|
|
* @param array|int $aTargetId Список ID владельцев
|
|
|
|
|
* @param string $sTargetType Тип владельцев
|
2009-10-25 22:01:05 +02:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function DeleteCommentByTargetId($aTargetId,$sTargetType) {
|
|
|
|
|
if(!is_array($aTargetId)) $aTargetId = array($aTargetId);
|
|
|
|
|
/**
|
|
|
|
|
* Получаем список идентификаторов удаляемых комментариев
|
|
|
|
|
*/
|
|
|
|
|
$aCommentsId = array();
|
|
|
|
|
foreach ($aTargetId as $sTargetId) {
|
|
|
|
|
$aComments=$this->GetCommentsByTargetId($sTargetId,$sTargetType);
|
|
|
|
|
$aCommentsId = array_merge($aCommentsId, array_keys($aComments['comments']));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Если ни одного комментария не найдено, выходим
|
|
|
|
|
*/
|
|
|
|
|
if(!count($aCommentsId)) return true;
|
|
|
|
|
/**
|
|
|
|
|
* Чистим зависимые кеши
|
|
|
|
|
*/
|
2009-11-10 20:49:53 +02:00
|
|
|
|
if(Config::Get('sys.cache.solid')) {
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("comment_update","comment_target_{$sTargetId}_{$sTargetType}"));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("comment_target_{$sTargetId}_{$sTargetType}"));
|
|
|
|
|
/**
|
|
|
|
|
* Удаляем кеш для каждого комментария
|
|
|
|
|
*/
|
|
|
|
|
foreach($aCommentsId as $iCommentId) $this->Cache_Delete("comment_{$iCommentId}");
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
if($this->oMapper->DeleteCommentByTargetId($aTargetId,$sTargetType)){
|
2009-10-25 22:01:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Удаляем комментарии из избранного
|
|
|
|
|
*/
|
|
|
|
|
$this->DeleteFavouriteCommentsByArrayId($aCommentsId);
|
|
|
|
|
/**
|
|
|
|
|
* Удаляем комментарии к топику из прямого эфира
|
|
|
|
|
*/
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$this->DeleteCommentOnlineByArrayId($aCommentsId,$sTargetType);
|
2009-10-25 22:01:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Удаляем голосование за комментарии
|
|
|
|
|
*/
|
|
|
|
|
$this->Vote_DeleteVoteByTarget($aCommentsId,'comment');
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Удаляет коммент из прямого эфира по массиву переданных идентификаторов
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param array|int $aCommentId
|
|
|
|
|
* @param string $sTargetType Тип владельцев
|
2009-10-25 22:01:05 +02:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function DeleteCommentOnlineByArrayId($aCommentId,$sTargetType) {
|
|
|
|
|
if(!is_array($aCommentId)) $aCommentId = array($aCommentId);
|
|
|
|
|
/**
|
|
|
|
|
* Чистим кеш
|
|
|
|
|
*/
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}"));
|
|
|
|
|
return $this->oMapper->DeleteCommentOnlineByArrayId($aCommentId,$sTargetType);
|
|
|
|
|
}
|
2009-11-18 21:46:21 +02:00
|
|
|
|
/**
|
|
|
|
|
* Меняем target parent по массиву идентификаторов
|
2012-06-24 10:20:49 +03:00
|
|
|
|
*
|
|
|
|
|
* @param int $sParentId Новый ID родителя владельца
|
|
|
|
|
* @param string $sTargetType Тип владельца
|
|
|
|
|
* @param array|int $aTargetId Список ID владельцев
|
2009-11-18 21:46:21 +02:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function UpdateTargetParentByTargetId($sParentId, $sTargetType, $aTargetId) {
|
|
|
|
|
if(!is_array($aTargetId)) $aTargetId = array($aTargetId);
|
|
|
|
|
// чистим зависимые кеши
|
2010-04-17 20:55:22 +03:00
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_new_{$sTargetType}"));
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
2009-11-18 21:46:21 +02:00
|
|
|
|
return $this->oMapper->UpdateTargetParentByTargetId($sParentId, $sTargetType, $aTargetId);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Меняем target parent по массиву идентификаторов в таблице комментариев online
|
2012-06-24 10:20:49 +03:00
|
|
|
|
*
|
|
|
|
|
* @param int $sParentId Новый ID родителя владельца
|
|
|
|
|
* @param string $sTargetType Тип владельца
|
|
|
|
|
* @param array|int $aTargetId Список ID владельцев
|
2009-11-18 21:46:21 +02:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function UpdateTargetParentByTargetIdOnline($sParentId, $sTargetType, $aTargetId) {
|
|
|
|
|
if(!is_array($aTargetId)) $aTargetId = array($aTargetId);
|
|
|
|
|
// чистим зависимые кеши
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}"));
|
2012-06-24 10:20:49 +03:00
|
|
|
|
|
2009-11-18 21:46:21 +02:00
|
|
|
|
return $this->oMapper->UpdateTargetParentByTargetIdOnline($sParentId, $sTargetType, $aTargetId);
|
|
|
|
|
}
|
2010-04-17 20:55:22 +03:00
|
|
|
|
/**
|
|
|
|
|
* Меняет target parent на новый
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sParentId Прежний ID родителя владельца
|
|
|
|
|
* @param string $sTargetType Тип владельца
|
|
|
|
|
* @param int $sParentIdNew Новый ID родителя владельца
|
2010-04-17 20:55:22 +03:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function MoveTargetParent($sParentId, $sTargetType, $sParentIdNew) {
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_new_{$sTargetType}"));
|
|
|
|
|
return $this->oMapper->MoveTargetParent($sParentId, $sTargetType, $sParentIdNew);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Меняет target parent на новый в прямом эфире
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $sParentId Прежний ID родителя владельца
|
|
|
|
|
* @param string $sTargetType Тип владельца
|
|
|
|
|
* @param int $sParentIdNew Новый ID родителя владельца
|
2010-04-17 20:55:22 +03:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function MoveTargetParentOnline($sParentId, $sTargetType, $sParentIdNew) {
|
|
|
|
|
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}"));
|
|
|
|
|
return $this->oMapper->MoveTargetParentOnline($sParentId, $sTargetType, $sParentIdNew);
|
|
|
|
|
}
|
2010-09-19 00:58:52 +03:00
|
|
|
|
/**
|
|
|
|
|
* Перестраивает дерево комментариев
|
|
|
|
|
* Восстанавливает значения left, right и level
|
|
|
|
|
*
|
2012-06-24 10:20:49 +03:00
|
|
|
|
* @param int $aTargetId Список ID владельцев
|
|
|
|
|
* @param string $sTargetType Тип владельца
|
2010-09-19 00:58:52 +03:00
|
|
|
|
*/
|
2010-09-19 13:09:31 +03:00
|
|
|
|
public function RestoreTree($aTargetId=null,$sTargetType=null) {
|
|
|
|
|
// обработать конкретную сущность
|
|
|
|
|
if (!is_null($aTargetId) and !is_null($sTargetType)) {
|
|
|
|
|
$this->oMapper->RestoreTree(null,0,-1,$aTargetId,$sTargetType);
|
2012-06-24 10:20:49 +03:00
|
|
|
|
return ;
|
2010-09-19 13:09:31 +03:00
|
|
|
|
}
|
|
|
|
|
$aType=array();
|
|
|
|
|
// обработать все сущности конкретного типа
|
|
|
|
|
if (!is_null($sTargetType)) {
|
|
|
|
|
$aType[]=$sTargetType;
|
|
|
|
|
} else {
|
|
|
|
|
// обработать все сущности всех типов
|
|
|
|
|
$aType=$this->oMapper->GetCommentTypes();
|
|
|
|
|
}
|
|
|
|
|
foreach ($aType as $sTargetType) {
|
|
|
|
|
// для каждого типа получаем порциями ID сущностей
|
|
|
|
|
$iPage=1;
|
|
|
|
|
$iPerPage=50;
|
|
|
|
|
while ($aResult=$this->oMapper->GetTargetIdByType($sTargetType,$iPage,$iPerPage)) {
|
|
|
|
|
foreach ($aResult as $Row) {
|
|
|
|
|
$this->oMapper->RestoreTree(null,0,-1,$Row['target_id'],$sTargetType);
|
|
|
|
|
}
|
2012-06-24 10:20:49 +03:00
|
|
|
|
$iPage++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Пересчитывает счетчик избранных комментариев
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function RecalculateFavourite() {
|
|
|
|
|
return $this->oMapper->RecalculateFavourite();
|
|
|
|
|
}
|
2012-07-10 09:58:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает список комментариев по фильтру
|
|
|
|
|
*
|
|
|
|
|
* @param array $aFilter Фильтр выборки
|
|
|
|
|
* @param array $aOrder Сортировка
|
|
|
|
|
* @param int $iCurrPage Номер текущей страницы
|
|
|
|
|
* @param int $iPerPage Количество элементов на одну страницу
|
|
|
|
|
* @param array $aAllowData Список типов данных, которые нужно подтянуть к списку комментов
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function GetCommentsByFilter($aFilter,$aOrder,$iCurrPage,$iPerPage,$aAllowData=null) {
|
|
|
|
|
if (is_null($aAllowData)) {
|
|
|
|
|
$aAllowData=array('target','user'=>array());
|
|
|
|
|
}
|
|
|
|
|
$aCollection=$this->oMapper->GetCommentsByFilter($aFilter,$aOrder,$iCount,$iCurrPage,$iPerPage);
|
|
|
|
|
return array('collection'=>$this->GetCommentsAdditionalData($aCollection,$aAllowData),'count'=>$iCount);
|
|
|
|
|
}
|
2012-08-05 12:47:09 +03:00
|
|
|
|
/**
|
|
|
|
|
* Алиас для корректной работы ORM
|
|
|
|
|
*
|
|
|
|
|
* @param array $aCommentId Список ID комментариев
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function GetCommentItemsByArrayId($aCommentId) {
|
|
|
|
|
return $this->GetCommentsByArrayId($aCommentId);
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
?>
|