mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-05-19 09:18:18 +03:00
Документация классов
This commit is contained in:
parent
168a1443d1
commit
acf74de8ec
|
@ -18,40 +18,53 @@
|
|||
/**
|
||||
* Модуль для работы с комментариями
|
||||
*
|
||||
* @package modules.comment
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleComment extends Module {
|
||||
protected $oMapper;
|
||||
/**
|
||||
* Объект маппера
|
||||
*
|
||||
* @var ModuleComment_MapperComment
|
||||
*/
|
||||
protected $oMapper;
|
||||
/**
|
||||
* Объект текущего пользователя
|
||||
*
|
||||
* @var ModuleUser_EntityUser|null
|
||||
*/
|
||||
protected $oUserCurrent=null;
|
||||
|
||||
|
||||
/**
|
||||
* Инициализация
|
||||
*
|
||||
*/
|
||||
public function Init() {
|
||||
public function Init() {
|
||||
$this->oMapper=Engine::GetMapper(__CLASS__);
|
||||
$this->oUserCurrent=$this->User_GetUserCurrent();
|
||||
$this->oUserCurrent=$this->User_GetUserCurrent();
|
||||
}
|
||||
/**
|
||||
* Получить коммент по айдишнику
|
||||
*
|
||||
* @param unknown_type $sId
|
||||
* @return unknown
|
||||
* @param int $sId ID комментария
|
||||
* @return ModuleComment_EntityComment|null
|
||||
*/
|
||||
public function GetCommentById($sId) {
|
||||
$aComments=$this->GetCommentsAdditionalData($sId);
|
||||
$aComments=$this->GetCommentsAdditionalData($sId);
|
||||
if (isset($aComments[$sId])) {
|
||||
return $aComments[$sId];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Получает уникальный коммент, это помогает спастись от дублей комментов
|
||||
*
|
||||
* @param unknown_type $sTargetId
|
||||
* @param unknown_type $sTargetType
|
||||
* @param unknown_type $sUserId
|
||||
* @param unknown_type $sCommentPid
|
||||
* @param unknown_type $sHash
|
||||
* @param int $sTargetId ID владельца комментария
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $sCommentPid ID родительского комментария
|
||||
* @param string $sHash Хеш строка текста комментария
|
||||
* @return ModuleComment_EntityComment|null
|
||||
*/
|
||||
public function GetCommentUnique($sTargetId,$sTargetType,$sUserId,$sCommentPid,$sHash) {
|
||||
$sId=$this->oMapper->GetCommentUnique($sTargetId,$sTargetType,$sUserId,$sCommentPid,$sHash);
|
||||
|
@ -60,23 +73,28 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Получить все комменты
|
||||
*
|
||||
* @param unknown_type $sTargetType
|
||||
* @param unknown_type $iPage
|
||||
* @param unknown_type $iPerPage
|
||||
* @return unknown
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @param array $aExcludeTarget Список ID владельцев, которые необходимо исключить из выдачи
|
||||
* @param array $aExcludeParentTarget Список ID родителей владельцев, которые необходимо исключить из выдачи, например, исключить комментарии топиков к определенным блогам(закрытым)
|
||||
* @return array('collection'=>array,'count'=>int)
|
||||
*/
|
||||
public function GetCommentsAll($sTargetType,$iPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
public function GetCommentsAll($sTargetType,$iPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
$s=serialize($aExcludeTarget).serialize($aExcludeParentTarget);
|
||||
if (false === ($data = $this->Cache_Get("comment_all_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
|
||||
if (false === ($data = $this->Cache_Get("comment_all_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
|
||||
$data = array('collection'=>$this->oMapper->GetCommentsAll($sTargetType,$iCount,$iPage,$iPerPage,$aExcludeTarget,$aExcludeParentTarget),'count'=>$iCount);
|
||||
$this->Cache_Set($data, "comment_all_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}", array("comment_new_{$sTargetType}","comment_update_status_{$sTargetType}"), 60*60*24*1);
|
||||
}
|
||||
$data['collection']=$this->GetCommentsAdditionalData($data['collection'],array('target','favourite','user'=>array()));
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Получает дополнительные данные(объекты) для комментов по их ID
|
||||
*
|
||||
* @param array $aCommentId Список ID комментов
|
||||
* @param array|null $aAllowData Список типов дополнительных данных, которые нужно получить для комментариев
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsAdditionalData($aCommentId,$aAllowData=null) {
|
||||
if (is_null($aAllowData)) {
|
||||
|
@ -93,17 +111,16 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Формируем ID дополнительных данных, которые нужно получить
|
||||
*/
|
||||
$aUserId=array();
|
||||
$aTargetId=array('topic'=>array(),'talk'=>array());
|
||||
$aUserId=array();
|
||||
$aTargetId=array('topic'=>array(),'talk'=>array());
|
||||
foreach ($aComments as $oComment) {
|
||||
if (isset($aAllowData['user'])) {
|
||||
$aUserId[]=$oComment->getUserId();
|
||||
}
|
||||
if (isset($aAllowData['target'])) {
|
||||
$aTargetId[$oComment->getTargetType()][]=$oComment->getTargetId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получаем дополнительные данные
|
||||
*/
|
||||
|
@ -116,10 +133,10 @@ class ModuleComment extends Module {
|
|||
$aTargets['topic']=$this->Topic_GetTopicsAdditionalData($aTargetId['topic'],array('blog'=>array('owner'=>array())));
|
||||
$aVote=array();
|
||||
if (isset($aAllowData['vote']) and $this->oUserCurrent) {
|
||||
$aVote=$this->Vote_GetVoteByArray($aCommentId,'comment',$this->oUserCurrent->getId());
|
||||
$aVote=$this->Vote_GetVoteByArray($aCommentId,'comment',$this->oUserCurrent->getId());
|
||||
}
|
||||
if (isset($aAllowData['favourite']) and $this->oUserCurrent) {
|
||||
$aFavouriteComments=$this->Favourite_GetFavouritesByArray($aCommentId,'comment',$this->oUserCurrent->getId());
|
||||
$aFavouriteComments=$this->Favourite_GetFavouritesByArray($aCommentId,'comment',$this->oUserCurrent->getId());
|
||||
}
|
||||
/**
|
||||
* Добавляем данные к результату
|
||||
|
@ -136,7 +153,7 @@ class ModuleComment extends Module {
|
|||
$oComment->setTarget(null);
|
||||
}
|
||||
if (isset($aVote[$oComment->getId()])) {
|
||||
$oComment->setVote($aVote[$oComment->getId()]);
|
||||
$oComment->setVote($aVote[$oComment->getId()]);
|
||||
} else {
|
||||
$oComment->setVote(null);
|
||||
}
|
||||
|
@ -144,15 +161,15 @@ class ModuleComment extends Module {
|
|||
$oComment->setIsFavourite(true);
|
||||
} else {
|
||||
$oComment->setIsFavourite(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aComments;
|
||||
}
|
||||
/**
|
||||
* Список комментов по ID
|
||||
*
|
||||
* @param array $aUserId
|
||||
* @param array $aCommentId Список ID комментариев
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsByArrayId($aCommentId) {
|
||||
if (!$aCommentId) {
|
||||
|
@ -171,25 +188,25 @@ class ModuleComment extends Module {
|
|||
* Делаем мульти-запрос к кешу
|
||||
*/
|
||||
$aCacheKeys=func_build_cache_keys($aCommentId,'comment_');
|
||||
if (false !== ($data = $this->Cache_Get($aCacheKeys))) {
|
||||
if (false !== ($data = $this->Cache_Get($aCacheKeys))) {
|
||||
/**
|
||||
* проверяем что досталось из кеша
|
||||
* Проверяем что досталось из кеша
|
||||
*/
|
||||
foreach ($aCacheKeys as $sValue => $sKey ) {
|
||||
if (array_key_exists($sKey,$data)) {
|
||||
if (array_key_exists($sKey,$data)) {
|
||||
if ($data[$sKey]) {
|
||||
$aComments[$data[$sKey]->getId()]=$data[$sKey];
|
||||
} else {
|
||||
$aCommentIdNotNeedQuery[]=$sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Смотрим каких комментов не было в кеше и делаем запрос в БД
|
||||
*/
|
||||
$aCommentIdNeedQuery=array_diff($aCommentId,array_keys($aComments));
|
||||
$aCommentIdNeedQuery=array_diff($aCommentIdNeedQuery,$aCommentIdNotNeedQuery);
|
||||
*/
|
||||
$aCommentIdNeedQuery=array_diff($aCommentId,array_keys($aComments));
|
||||
$aCommentIdNeedQuery=array_diff($aCommentIdNeedQuery,$aCommentIdNotNeedQuery);
|
||||
$aCommentIdNeedStore=$aCommentIdNeedQuery;
|
||||
if ($data = $this->oMapper->GetCommentsByArrayId($aCommentIdNeedQuery)) {
|
||||
foreach ($data as $oComment) {
|
||||
|
@ -206,36 +223,42 @@ class ModuleComment extends Module {
|
|||
*/
|
||||
foreach ($aCommentIdNeedStore as $sId) {
|
||||
$this->Cache_Set(null, "comment_{$sId}", array(), 60*60*24*4);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Сортируем результат согласно входящему массиву
|
||||
*/
|
||||
$aComments=func_array_sort_by_keys($aComments,$aCommentId);
|
||||
return $aComments;
|
||||
}
|
||||
return $aComments;
|
||||
}
|
||||
/**
|
||||
* Получает список комментариев по ID используя единый кеш
|
||||
*
|
||||
* @param array $aCommentId Список ID комментариев
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsByArrayIdSolid($aCommentId) {
|
||||
if (!is_array($aCommentId)) {
|
||||
$aCommentId=array($aCommentId);
|
||||
}
|
||||
$aCommentId=array_unique($aCommentId);
|
||||
$aComments=array();
|
||||
$aCommentId=array_unique($aCommentId);
|
||||
$aComments=array();
|
||||
$s=join(',',$aCommentId);
|
||||
if (false === ($data = $this->Cache_Get("comment_id_{$s}"))) {
|
||||
if (false === ($data = $this->Cache_Get("comment_id_{$s}"))) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Получть все комменты сгрупированные по топику(для вывода прямого эфира)
|
||||
* Получить все комменты сгрупированные по типу(для вывода прямого эфира)
|
||||
*
|
||||
* @param unknown_type $sTargetType
|
||||
* @param unknown_type $iLimit
|
||||
* @return unknown
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsOnline($sTargetType,$iLimit) {
|
||||
/**
|
||||
|
@ -244,35 +267,35 @@ class ModuleComment extends Module {
|
|||
$aCloseBlogs = ($this->oUserCurrent)
|
||||
? $this->Blog_GetInaccessibleBlogsByUser($this->oUserCurrent)
|
||||
: $this->Blog_GetInaccessibleBlogsByUser();
|
||||
|
||||
|
||||
$s=serialize($aCloseBlogs);
|
||||
|
||||
if (false === ($data = $this->Cache_Get("comment_online_{$sTargetType}_{$s}_{$iLimit}"))) {
|
||||
|
||||
if (false === ($data = $this->Cache_Get("comment_online_{$sTargetType}_{$s}_{$iLimit}"))) {
|
||||
$data = $this->oMapper->GetCommentsOnline($sTargetType,$aCloseBlogs,$iLimit);
|
||||
$this->Cache_Set($data, "comment_online_{$sTargetType}_{$s}_{$iLimit}", array("comment_online_update_{$sTargetType}"), 60*60*24*1);
|
||||
}
|
||||
$data=$this->GetCommentsAdditionalData($data);
|
||||
return $data;
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Получить комменты по юзеру
|
||||
*
|
||||
* @param string $sId
|
||||
* @param string $sTargetType
|
||||
* @param int $iPage
|
||||
* @param int $iPerPage
|
||||
* @param int $sId ID пользователя
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsByUserId($sId,$sTargetType,$iPage,$iPerPage) {
|
||||
public function GetCommentsByUserId($sId,$sTargetType,$iPage,$iPerPage) {
|
||||
/**
|
||||
* Исключаем из выборки идентификаторы закрытых блогов
|
||||
*/
|
||||
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
|
||||
? array()
|
||||
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
|
||||
? array()
|
||||
: $this->Blog_GetInaccessibleBlogsByUser();
|
||||
$s=serialize($aCloseBlogs);
|
||||
|
||||
if (false === ($data = $this->Cache_Get("comment_user_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
|
||||
|
||||
if (false === ($data = $this->Cache_Get("comment_user_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}_{$s}"))) {
|
||||
$data = array('collection'=>$this->oMapper->GetCommentsByUserId($sId,$sTargetType,$iCount,$iPage,$iPerPage,array(),$aCloseBlogs),'count'=>$iCount);
|
||||
$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);
|
||||
}
|
||||
|
@ -282,20 +305,20 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Получает количество комментариев одного пользователя
|
||||
*
|
||||
* @param string $sId
|
||||
* @param string $sTargetType
|
||||
* @param id $sId ID пользователя
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return int
|
||||
*/
|
||||
public function GetCountCommentsByUserId($sId,$sTargetType) {
|
||||
/**
|
||||
* Исключаем из выборки идентификаторы закрытых блогов
|
||||
*/
|
||||
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
|
||||
? array()
|
||||
$aCloseBlogs = ($this->oUserCurrent && $sId==$this->oUserCurrent->getId())
|
||||
? array()
|
||||
: $this->Blog_GetInaccessibleBlogsByUser();
|
||||
$s=serialize($aCloseBlogs);
|
||||
|
||||
if (false === ($data = $this->Cache_Get("comment_count_user_{$sId}_{$sTargetType}_{$s}"))) {
|
||||
$s=serialize($aCloseBlogs);
|
||||
|
||||
if (false === ($data = $this->Cache_Get("comment_count_user_{$sId}_{$sTargetType}_{$s}"))) {
|
||||
$data = $this->oMapper->GetCountCommentsByUserId($sId,$sTargetType,array(),$aCloseBlogs);
|
||||
$this->Cache_Set($data, "comment_count_user_{$sId}_{$sTargetType}", array("comment_new_user_{$sId}_{$sTargetType}","comment_update_status_{$sTargetType}"), 60*60*24*2);
|
||||
}
|
||||
|
@ -304,9 +327,9 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Получить комменты по рейтингу и дате
|
||||
*
|
||||
* @param string $sDate
|
||||
* @param string $sTargetType
|
||||
* @param int $iLimit
|
||||
* @param string $sDate Дата за которую выводить рейтинг, т.к. кеширование происходит по дате, то дату лучше передавать с точностью до часа (минуты и секунды как 00:00)
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit=20) {
|
||||
|
@ -317,27 +340,29 @@ class ModuleComment extends Module {
|
|||
? $this->Blog_GetInaccessibleBlogsByUser($this->oUserCurrent)
|
||||
: $this->Blog_GetInaccessibleBlogsByUser();
|
||||
$s=serialize($aCloseBlogs);
|
||||
|
||||
//т.к. время передаётся с точностью 1 час то можно по нему замутить кеширование
|
||||
if (false === ($data = $this->Cache_Get("comment_rating_{$sDate}_{$sTargetType}_{$iLimit}_{$s}"))) {
|
||||
/**
|
||||
* Т.к. время передаётся с точностью 1 час то можно по нему замутить кеширование
|
||||
*/
|
||||
if (false === ($data = $this->Cache_Get("comment_rating_{$sDate}_{$sTargetType}_{$iLimit}_{$s}"))) {
|
||||
$data = $this->oMapper->GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,array(),$aCloseBlogs);
|
||||
$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);
|
||||
}
|
||||
$data=$this->GetCommentsAdditionalData($data);
|
||||
$data=$this->GetCommentsAdditionalData($data);
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Получить комменты для топика
|
||||
* Получить комменты по владельцу
|
||||
*
|
||||
* @param string $sId
|
||||
* @param string $sTargetType
|
||||
* @return object
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('comments'=>array,'iMaxIdComment'=>int)
|
||||
*/
|
||||
public function GetCommentsByTargetId($sId,$sTargetType,$iPage=1,$iPerPage=0) {
|
||||
|
||||
public function GetCommentsByTargetId($sId,$sTargetType,$iPage=1,$iPerPage=0) {
|
||||
if (Config::Get('module.comment.use_nested')) {
|
||||
return $this->GetCommentsTreeByTargetId($sId,$sTargetType,$iPage,$iPerPage);
|
||||
}
|
||||
}
|
||||
|
||||
if (false === ($aCommentsRec = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}"))) {
|
||||
$aCommentsRow=$this->oMapper->GetCommentsByTargetId($sId,$sTargetType);
|
||||
|
@ -356,22 +381,23 @@ class ModuleComment extends Module {
|
|||
}
|
||||
return $aComments;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Получает комменты используя nested set
|
||||
*
|
||||
* @param unknown_type $sId
|
||||
* @param unknown_type $sTargetType
|
||||
* @return unknown
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('comments'=>array,'iMaxIdComment'=>int,'count'=>int)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
$iPage=$iPage<1 ? 1 : $iPage;
|
||||
$iPage=$iPage<1 ? 1 : $iPage;
|
||||
if (false === ($aReturn = $this->Cache_Get("comment_tree_target_{$sId}_{$sTargetType}_{$iPage}_{$iPerPage}"))) {
|
||||
|
||||
|
||||
/**
|
||||
* Нужно или нет использовать постраничное разбиение комментариев
|
||||
*/
|
||||
|
@ -380,19 +406,32 @@ class ModuleComment extends Module {
|
|||
} else {
|
||||
$aComments=$this->oMapper->GetCommentsTreeByTargetId($sId,$sTargetType);
|
||||
$iCount=count($aComments);
|
||||
}
|
||||
}
|
||||
$iMaxIdComment=count($aComments) ? max($aComments) : 0;
|
||||
$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);
|
||||
}
|
||||
}
|
||||
$aReturn['comments']=$this->GetCommentsAdditionalData($aReturn['comments']);
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает количество дочерних комментариев у корневого коммента
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return int
|
||||
*/
|
||||
public function GetCountCommentsRootByTargetId($sId,$sTargetType) {
|
||||
return $this->oMapper->GetCountCommentsRootByTargetId($sId,$sTargetType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает номер страницы, на которой расположен комментарий
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool|int
|
||||
*/
|
||||
public function GetPageCommentByTargetId($sId,$sTargetType,$oComment) {
|
||||
if (!Config::Get('module.comment.nested_per_page')) {
|
||||
return 1;
|
||||
|
@ -416,18 +455,17 @@ class ModuleComment extends Module {
|
|||
$oCommentRoot=$oComment;
|
||||
}
|
||||
$iCount=ceil($this->oMapper->GetCountCommentsAfterByTargetId($sId,$sTargetType,$oCommentRoot->getLeft())/Config::Get('module.comment.nested_per_page'));
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return $iCount ? $iCount : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет коммент
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment
|
||||
* @return bool
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool|ModuleComment_EntityComment
|
||||
*/
|
||||
public function AddComment(ModuleComment_EntityComment $oComment) {
|
||||
if (Config::Get('module.comment.use_nested')) {
|
||||
|
@ -450,13 +488,13 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Обновляет коммент
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateComment(ModuleComment_EntityComment $oComment) {
|
||||
if ($this->oMapper->UpdateComment($oComment)) {
|
||||
public function UpdateComment(ModuleComment_EntityComment $oComment) {
|
||||
if ($this->oMapper->UpdateComment($oComment)) {
|
||||
//чистим зависимые кеши
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update","comment_update_{$oComment->getTargetType()}_{$oComment->getTargetId()}"));
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update","comment_update_{$oComment->getTargetType()}_{$oComment->getTargetId()}"));
|
||||
$this->Cache_Delete("comment_{$oComment->getId()}");
|
||||
return true;
|
||||
}
|
||||
|
@ -465,14 +503,14 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Обновляет рейтинг у коммента
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateCommentRating(ModuleComment_EntityComment $oComment) {
|
||||
if ($this->oMapper->UpdateComment($oComment)) {
|
||||
public function UpdateCommentRating(ModuleComment_EntityComment $oComment) {
|
||||
if ($this->oMapper->UpdateComment($oComment)) {
|
||||
//чистим зависимые кеши
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_rating_{$oComment->getTargetType()}"));
|
||||
$this->Cache_Delete("comment_{$oComment->getId()}");
|
||||
$this->Cache_Delete("comment_{$oComment->getId()}");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -480,15 +518,15 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Обновляет статус у коммента - delete или publish
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateCommentStatus(ModuleComment_EntityComment $oComment) {
|
||||
if ($this->oMapper->UpdateComment($oComment)) {
|
||||
public function UpdateCommentStatus(ModuleComment_EntityComment $oComment) {
|
||||
if ($this->oMapper->UpdateComment($oComment)) {
|
||||
/**
|
||||
* Если комментарий удаляется, удаляем его из прямого эфира
|
||||
*/
|
||||
if($oComment->getDelete()) $this->DeleteCommentOnlineByArrayId($oComment->getId(),$oComment->getTargetType());
|
||||
if($oComment->getDelete()) $this->DeleteCommentOnlineByArrayId($oComment->getId(),$oComment->getTargetType());
|
||||
/**
|
||||
* Обновляем избранное
|
||||
*/
|
||||
|
@ -496,8 +534,8 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Чистим зависимые кеши
|
||||
*/
|
||||
if(Config::Get('sys.cache.solid')){
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update"));
|
||||
if(Config::Get('sys.cache.solid')){
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update"));
|
||||
}
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$oComment->getTargetType()}"));
|
||||
$this->Cache_Delete("comment_{$oComment->getId()}");
|
||||
|
@ -508,27 +546,27 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Устанавливает publish у коммента
|
||||
*
|
||||
* @param string $sTargetId
|
||||
* @param string $sTargetType
|
||||
* @param int $iPublish
|
||||
* @param int $sTargetId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iPublish Статус отображать комментарии или нет
|
||||
* @return bool
|
||||
*/
|
||||
public function SetCommentsPublish($sTargetId,$sTargetType,$iPublish) {
|
||||
public function SetCommentsPublish($sTargetId,$sTargetType,$iPublish) {
|
||||
if(!$aComments = $this->GetCommentsByTargetId($sTargetId,$sTargetType)) {
|
||||
return false;
|
||||
}
|
||||
if(!isset($aComments['comments']) or count($aComments)==0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$sTargetType}"));
|
||||
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update_status_{$sTargetType}"));
|
||||
/**
|
||||
* Если статус публикации успешно изменен, то меняем статус в отметке "избранное".
|
||||
* Если комментарии снимаются с публикации, удаляем их из прямого эфира.
|
||||
*/
|
||||
if($this->oMapper->SetCommentsPublish($sTargetId,$sTargetType,$iPublish)){
|
||||
$this->Favourite_SetFavouriteTargetPublish(array_keys($aComments['comments']),'comment',$iPublish);
|
||||
if($iPublish!=1) $this->DeleteCommentOnlineByTargetId($sTargetId,$sTargetType);
|
||||
if($iPublish!=1) $this->DeleteCommentOnlineByTargetId($sTargetId,$sTargetType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -536,9 +574,9 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Удаляет коммент из прямого эфира
|
||||
*
|
||||
* @param unknown_type $sTargetId
|
||||
* @param unknown_type $sTargetType
|
||||
* @return unknown
|
||||
* @param int $sTargetId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteCommentOnlineByTargetId($sTargetId,$sTargetType) {
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}"));
|
||||
|
@ -547,31 +585,31 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Добавляет новый коммент в прямой эфир
|
||||
*
|
||||
* @param ModuleComment_EntityCommentOnline $oCommentOnline
|
||||
* @param ModuleComment_EntityCommentOnline $oCommentOnline Объект онлайн комментария
|
||||
* @return bool|int
|
||||
*/
|
||||
public function AddCommentOnline(ModuleComment_EntityCommentOnline $oCommentOnline) {
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$oCommentOnline->getTargetType()}"));
|
||||
return $this->oMapper->AddCommentOnline($oCommentOnline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить новые комменты для топика
|
||||
* Получить новые комменты для владельца
|
||||
*
|
||||
* @param unknown_type $sId
|
||||
* @param unknown_type $sTargetType
|
||||
* @param unknown_type $sIdCommentLast - last read comment
|
||||
* @return unknown
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $sIdCommentLast ID последнего прочитанного комментария
|
||||
* @return array('comments'=>array,'iMaxIdComment'=>int)
|
||||
*/
|
||||
public function GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast) {
|
||||
if (false === ($aComments = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}_{$sIdCommentLast}"))) {
|
||||
$aComments=$this->oMapper->GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast);
|
||||
if (false === ($aComments = $this->Cache_Get("comment_target_{$sId}_{$sTargetType}_{$sIdCommentLast}"))) {
|
||||
$aComments=$this->oMapper->GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast);
|
||||
$this->Cache_Set($aComments, "comment_target_{$sId}_{$sTargetType}_{$sIdCommentLast}", array("comment_new_{$sTargetType}_{$sId}"), 60*60*24*1);
|
||||
}
|
||||
}
|
||||
if (count($aComments)==0) {
|
||||
return array('comments'=>array(),'iMaxIdComment'=>0);
|
||||
}
|
||||
|
||||
$iMaxIdComment=max($aComments);
|
||||
|
||||
$iMaxIdComment=max($aComments);
|
||||
$aCmts=$this->GetCommentsAdditionalData($aComments);
|
||||
$oViewerLocal=$this->Viewer_GetLocalViewer();
|
||||
$oViewerLocal->Assign('oUserCurrent',$this->User_GetUserCurrent());
|
||||
|
@ -580,16 +618,15 @@ class ModuleComment extends Module {
|
|||
$oViewerLocal->Assign('bNoCommentFavourites',true);
|
||||
}
|
||||
$aCmt=array();
|
||||
foreach ($aCmts as $oComment) {
|
||||
$oViewerLocal->Assign('oComment',$oComment);
|
||||
foreach ($aCmts as $oComment) {
|
||||
$oViewerLocal->Assign('oComment',$oComment);
|
||||
$sText=$oViewerLocal->Fetch($this->GetTemplateCommentByTarget($sId,$sTargetType));
|
||||
$aCmt[]=array(
|
||||
'html' => $sText,
|
||||
'obj' => $oComment,
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
return array('comments'=>$aCmt,'iMaxIdComment'=>$iMaxIdComment);
|
||||
return array('comments'=>$aCmt,'iMaxIdComment'=>$iMaxIdComment);
|
||||
}
|
||||
/**
|
||||
* Возвращает шаблон комментария для рендеринга
|
||||
|
@ -602,13 +639,12 @@ class ModuleComment extends Module {
|
|||
public function GetTemplateCommentByTarget($iTargetId,$sTargetType) {
|
||||
return "comment.tpl";
|
||||
}
|
||||
|
||||
/**
|
||||
* Строит дерево комментариев
|
||||
*
|
||||
* @param unknown_type $aComments
|
||||
* @param unknown_type $bBegin
|
||||
* @return unknown
|
||||
* @param array $aComments Список комментариев
|
||||
* @param bool $bBegin Флаг начала построения дерева, для инициализации параметров внутри метода
|
||||
* @return array('comments'=>array,'iMaxIdComment'=>int)
|
||||
*/
|
||||
protected function BuildCommentsRecursive($aComments,$bBegin=true) {
|
||||
static $aResultCommnets;
|
||||
|
@ -618,7 +654,7 @@ class ModuleComment extends Module {
|
|||
$aResultCommnets=array();
|
||||
$iLevel=0;
|
||||
$iMaxIdComment=0;
|
||||
}
|
||||
}
|
||||
foreach ($aComments as $aComment) {
|
||||
$aTemp=$aComment;
|
||||
if ($aComment['comment_id']>$iMaxIdComment) {
|
||||
|
@ -632,117 +668,114 @@ class ModuleComment extends Module {
|
|||
$this->BuildCommentsRecursive($aComment['childNodes'],false);
|
||||
}
|
||||
}
|
||||
$iLevel--;
|
||||
$iLevel--;
|
||||
return array('comments'=>$aResultCommnets,'iMaxIdComment'=>$iMaxIdComment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает привязку комментария к ибранному(добавлен ли коммент в избранное у юзера)
|
||||
*
|
||||
* @param string $sCommentId
|
||||
* @param string $sUserId
|
||||
* @param int $sCommentId ID комментария
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return ModuleFavourite_EntityFavourite|null
|
||||
*/
|
||||
public function GetFavouriteComment($sCommentId,$sUserId) {
|
||||
return $this->Favourite_GetFavourite($sCommentId,'comment',$sUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить список избранного по списку айдишников
|
||||
*
|
||||
* @param array $aCommentId
|
||||
* @param array $aCommentId Список ID комментов
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteCommentsByArray($aCommentId,$sUserId) {
|
||||
return $this->Favourite_GetFavouritesByArray($aCommentId,'comment',$sUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить список избранного по списку айдишников, но используя единый кеш
|
||||
*
|
||||
* @param array $aCommentId
|
||||
* @param int $sUserId
|
||||
* @param array $aCommentId Список ID комментов
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteCommentsByArraySolid($aCommentId,$sUserId) {
|
||||
return $this->Favourite_GetFavouritesByArraySolid($aCommentId,'comment',$sUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает список комментариев из избранного пользователя
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @param int $iCount
|
||||
* @param int $iCurrPage
|
||||
* @param int $iPerPage
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsFavouriteByUserId($sUserId,$iCurrPage,$iPerPage) {
|
||||
public function GetCommentsFavouriteByUserId($sUserId,$iCurrPage,$iPerPage) {
|
||||
$aCloseTopics = array();
|
||||
/**
|
||||
* Получаем список идентификаторов избранных комментов
|
||||
*/
|
||||
$data = ($this->oUserCurrent && $sUserId==$this->oUserCurrent->getId())
|
||||
$data = ($this->oUserCurrent && $sUserId==$this->oUserCurrent->getId())
|
||||
? $this->Favourite_GetFavouritesByUserId($sUserId,'comment',$iCurrPage,$iPerPage,$aCloseTopics)
|
||||
: $this->Favourite_GetFavouriteOpenCommentsByUserId($sUserId,$iCurrPage,$iPerPage);
|
||||
/**
|
||||
* Получаем комменты по переданому массиву айдишников
|
||||
*/
|
||||
$data['collection']=$this->GetCommentsAdditionalData($data['collection']);
|
||||
return $data;
|
||||
*/
|
||||
$data['collection']=$this->GetCommentsAdditionalData($data['collection']);
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Возвращает число комментариев в избранном
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return int
|
||||
*/
|
||||
public function GetCountCommentsFavouriteByUserId($sUserId) {
|
||||
return ($this->oUserCurrent && $sUserId==$this->oUserCurrent->getId())
|
||||
? $this->Favourite_GetCountFavouritesByUserId($sUserId,'comment')
|
||||
: $this->Favourite_GetCountFavouriteOpenCommentsByUserId($sUserId);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Добавляет комментарий в избранное
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite
|
||||
* @return bool
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool|ModuleFavourite_EntityFavourite
|
||||
*/
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Удаляет комментарий из избранного
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteFavouriteComment(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_DeleteFavourite($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_DeleteFavourite($oFavourite);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Удаляет комментарии из избранного по списку
|
||||
* Удаляет комментарии из избранного по списку
|
||||
*
|
||||
* @param array $aCommentId
|
||||
* @param array $aCommentId Список ID комментариев
|
||||
* @return bool
|
||||
*/
|
||||
*/
|
||||
public function DeleteFavouriteCommentsByArrayId($aCommentId) {
|
||||
return $this->Favourite_DeleteFavouriteByTargetId($aCommentId, 'comment');
|
||||
return $this->Favourite_DeleteFavouriteByTargetId($aCommentId, 'comment');
|
||||
}
|
||||
/**
|
||||
* Удаляет комментарии из базы данных
|
||||
*
|
||||
* @param array|int $aTargetId
|
||||
* @param string $sTargetType
|
||||
*
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteCommentByTargetId($aTargetId,$sTargetType) {
|
||||
|
@ -771,7 +804,7 @@ class ModuleComment extends Module {
|
|||
*/
|
||||
foreach($aCommentsId as $iCommentId) $this->Cache_Delete("comment_{$iCommentId}");
|
||||
}
|
||||
if($this->oMapper->DeleteCommentByTargetId($aTargetId,$sTargetType)){
|
||||
if($this->oMapper->DeleteCommentByTargetId($aTargetId,$sTargetType)){
|
||||
/**
|
||||
* Удаляем комментарии из избранного
|
||||
*/
|
||||
|
@ -779,7 +812,7 @@ class ModuleComment extends Module {
|
|||
/**
|
||||
* Удаляем комментарии к топику из прямого эфира
|
||||
*/
|
||||
$this->DeleteCommentOnlineByArrayId($aCommentsId,$sTargetType);
|
||||
$this->DeleteCommentOnlineByArrayId($aCommentsId,$sTargetType);
|
||||
/**
|
||||
* Удаляем голосование за комментарии
|
||||
*/
|
||||
|
@ -788,12 +821,11 @@ class ModuleComment extends Module {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет коммент из прямого эфира по массиву переданных идентификаторов
|
||||
*
|
||||
* @param (array|int) $aCommentId
|
||||
* @param string $sTargetType
|
||||
* @param array|int $aCommentId
|
||||
* @param string $sTargetType Тип владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteCommentOnlineByArrayId($aCommentId,$sTargetType) {
|
||||
|
@ -804,77 +836,72 @@ class ModuleComment extends Module {
|
|||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_online_update_{$sTargetType}"));
|
||||
return $this->oMapper->DeleteCommentOnlineByArrayId($aCommentId,$sTargetType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняем target parent по массиву идентификаторов
|
||||
*
|
||||
* @param string $sParentId
|
||||
* @param string $sTargetType
|
||||
* @param array|string $aTargetId
|
||||
*
|
||||
* @param int $sParentId Новый ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateTargetParentByTargetId($sParentId, $sTargetType, $aTargetId) {
|
||||
if(!is_array($aTargetId)) $aTargetId = array($aTargetId);
|
||||
// чистим зависимые кеши
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_new_{$sTargetType}"));
|
||||
|
||||
|
||||
return $this->oMapper->UpdateTargetParentByTargetId($sParentId, $sTargetType, $aTargetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняем target parent по массиву идентификаторов в таблице комментариев online
|
||||
*
|
||||
* @param string $sParentId
|
||||
* @param string $sTargetType
|
||||
* @param array|string $aTargetId
|
||||
*
|
||||
* @param int $sParentId Новый ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @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}"));
|
||||
|
||||
|
||||
return $this->oMapper->UpdateTargetParentByTargetIdOnline($sParentId, $sTargetType, $aTargetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняет target parent на новый
|
||||
*
|
||||
* @param string $sParentId
|
||||
* @param string $sTargetType
|
||||
* @param string $sParentIdNew
|
||||
* @param int $sParentId Прежний ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sParentIdNew Новый ID родителя владельца
|
||||
* @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 на новый в прямом эфире
|
||||
*
|
||||
* @param string $sParentId
|
||||
* @param string $sTargetType
|
||||
* @param string $sParentIdNew
|
||||
* @param int $sParentId Прежний ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sParentIdNew Новый ID родителя владельца
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Перестраивает дерево комментариев
|
||||
* Восстанавливает значения left, right и level
|
||||
*
|
||||
* @param unknown_type $aTargetId
|
||||
* @param unknown_type $sTargetType
|
||||
* @param int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
*/
|
||||
public function RestoreTree($aTargetId=null,$sTargetType=null) {
|
||||
// обработать конкретную сущность
|
||||
if (!is_null($aTargetId) and !is_null($sTargetType)) {
|
||||
$this->oMapper->RestoreTree(null,0,-1,$aTargetId,$sTargetType);
|
||||
return ;
|
||||
return ;
|
||||
}
|
||||
$aType=array();
|
||||
// обработать все сущности конкретного типа
|
||||
|
@ -892,19 +919,17 @@ class ModuleComment extends Module {
|
|||
foreach ($aResult as $Row) {
|
||||
$this->oMapper->RestoreTree(null,0,-1,$Row['target_id'],$sTargetType);
|
||||
}
|
||||
$iPage++;
|
||||
}
|
||||
}
|
||||
$iPage++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Пересчитывает счетчик избранных комментариев
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function RecalculateFavourite() {
|
||||
return $this->oMapper->RecalculateFavourite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Пересчитывает счетчик избранных комментариев
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function RecalculateFavourite(){
|
||||
return $this->oMapper->RecalculateFavourite();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -15,153 +15,380 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ModuleComment_EntityComment extends Entity
|
||||
{
|
||||
public function getId() {
|
||||
return $this->_getDataOne('comment_id');
|
||||
}
|
||||
public function getPid() {
|
||||
return $this->_getDataOne('comment_pid');
|
||||
}
|
||||
public function getLeft() {
|
||||
return $this->_getDataOne('comment_left');
|
||||
}
|
||||
public function getRight() {
|
||||
return $this->_getDataOne('comment_right');
|
||||
}
|
||||
public function getTargetId() {
|
||||
return $this->_getDataOne('target_id');
|
||||
}
|
||||
public function getTargetType() {
|
||||
return $this->_getDataOne('target_type');
|
||||
}
|
||||
public function getTargetParentId() {
|
||||
return $this->_getDataOne('target_parent_id') ? $this->_getDataOne('target_parent_id') : 0;
|
||||
}
|
||||
public function getUserId() {
|
||||
return $this->_getDataOne('user_id');
|
||||
}
|
||||
public function getText() {
|
||||
return $this->_getDataOne('comment_text');
|
||||
}
|
||||
public function getDate() {
|
||||
return $this->_getDataOne('comment_date');
|
||||
}
|
||||
public function getUserIp() {
|
||||
return $this->_getDataOne('comment_user_ip');
|
||||
}
|
||||
public function getRating() {
|
||||
return number_format(round($this->_getDataOne('comment_rating'),2), 0, '.', '');
|
||||
}
|
||||
public function getCountVote() {
|
||||
return $this->_getDataOne('comment_count_vote');
|
||||
}
|
||||
public function getDelete() {
|
||||
return $this->_getDataOne('comment_delete');
|
||||
}
|
||||
public function getPublish() {
|
||||
return $this->_getDataOne('comment_publish') ? 1 : 0;
|
||||
}
|
||||
public function getTextHash() {
|
||||
return $this->_getDataOne('comment_text_hash');
|
||||
}
|
||||
|
||||
|
||||
public function getLevel() {
|
||||
return $this->_getDataOne('comment_level');
|
||||
}
|
||||
public function isBad() {
|
||||
if ($this->getRating()<=Config::Get('module.comment.bad')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getUser() {
|
||||
return $this->_getDataOne('user');
|
||||
}
|
||||
public function getTarget() {
|
||||
return $this->_getDataOne('target');
|
||||
}
|
||||
public function getVote() {
|
||||
return $this->_getDataOne('vote');
|
||||
}
|
||||
public function getIsFavourite() {
|
||||
return $this->_getDataOne('comment_is_favourite');
|
||||
}
|
||||
/**
|
||||
* Объект сущности комментариев
|
||||
*
|
||||
* @package modules.comment
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleComment_EntityComment extends Entity {
|
||||
/**
|
||||
* Возвращает ID коммента
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->_getDataOne('comment_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает ID родительского коммента
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getPid() {
|
||||
return $this->_getDataOne('comment_pid');
|
||||
}
|
||||
/**
|
||||
* Возвращает значение left для дерева nested set
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getLeft() {
|
||||
return $this->_getDataOne('comment_left');
|
||||
}
|
||||
/**
|
||||
* Возвращает значение right для дерева nested set
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getRight() {
|
||||
return $this->_getDataOne('comment_right');
|
||||
}
|
||||
/**
|
||||
* Возвращает ID владельца
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTargetId() {
|
||||
return $this->_getDataOne('target_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает тип владельца
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTargetType() {
|
||||
return $this->_getDataOne('target_type');
|
||||
}
|
||||
/**
|
||||
* Возвращет ID родителя владельца
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTargetParentId() {
|
||||
return $this->_getDataOne('target_parent_id') ? $this->_getDataOne('target_parent_id') : 0;
|
||||
}
|
||||
/**
|
||||
* Возвращает ID пользователя, автора комментария
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->_getDataOne('user_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает текст комментария
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getText() {
|
||||
return $this->_getDataOne('comment_text');
|
||||
}
|
||||
/**
|
||||
* Возвращает дату комментария
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDate() {
|
||||
return $this->_getDataOne('comment_date');
|
||||
}
|
||||
/**
|
||||
* Возвращает IP пользователя
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUserIp() {
|
||||
return $this->_getDataOne('comment_user_ip');
|
||||
}
|
||||
/**
|
||||
* Возвращает рейтинг комментария
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRating() {
|
||||
return number_format(round($this->_getDataOne('comment_rating'),2), 0, '.', '');
|
||||
}
|
||||
/**
|
||||
* Возвращает количество проголосовавших
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCountVote() {
|
||||
return $this->_getDataOne('comment_count_vote');
|
||||
}
|
||||
/**
|
||||
* Возвращает флаг удаленного комментария
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getDelete() {
|
||||
return $this->_getDataOne('comment_delete');
|
||||
}
|
||||
/**
|
||||
* Возвращает флаг опубликованного комментария
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPublish() {
|
||||
return $this->_getDataOne('comment_publish') ? 1 : 0;
|
||||
}
|
||||
/**
|
||||
* Возвращает хеш комментария
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTextHash() {
|
||||
return $this->_getDataOne('comment_text_hash');
|
||||
}
|
||||
|
||||
public function getCountFavourite() {
|
||||
return $this->_getDataOne('comment_count_favourite');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает уровень вложенности комментария
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getLevel() {
|
||||
return $this->_getDataOne('comment_level');
|
||||
}
|
||||
/**
|
||||
* Проверяет является ли комментарий плохим
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isBad() {
|
||||
if ($this->getRating()<=Config::Get('module.comment.bad')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Возвращает объект пользователя
|
||||
*
|
||||
* @return ModuleUser_EntityUser|null
|
||||
*/
|
||||
public function getUser() {
|
||||
return $this->_getDataOne('user');
|
||||
}
|
||||
/**
|
||||
* Возвращает объект владельца
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getTarget() {
|
||||
return $this->_getDataOne('target');
|
||||
}
|
||||
/**
|
||||
* Возвращает объект голосования
|
||||
*
|
||||
* @return ModuleVote_EntityVote|null
|
||||
*/
|
||||
public function getVote() {
|
||||
return $this->_getDataOne('vote');
|
||||
}
|
||||
/**
|
||||
* Проверяет является ли комментарий избранным у текущего пользователя
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function getIsFavourite() {
|
||||
return $this->_getDataOne('comment_is_favourite');
|
||||
}
|
||||
/**
|
||||
* Возвращает количество избранного
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCountFavourite() {
|
||||
return $this->_getDataOne('comment_count_favourite');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Устанавливает ID комментария
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setId($data) {
|
||||
$this->_aData['comment_id']=$data;
|
||||
}
|
||||
public function setPid($data) {
|
||||
$this->_aData['comment_pid']=$data;
|
||||
}
|
||||
public function setLeft($data) {
|
||||
$this->_aData['comment_left']=$data;
|
||||
}
|
||||
public function setRight($data) {
|
||||
$this->_aData['comment_right']=$data;
|
||||
}
|
||||
public function setTargetId($data) {
|
||||
$this->_aData['target_id']=$data;
|
||||
}
|
||||
public function setTargetType($data) {
|
||||
$this->_aData['target_type']=$data;
|
||||
}
|
||||
public function setTargetParentId($data) {
|
||||
$this->_aData['target_parent_id']=$data;
|
||||
}
|
||||
public function setUserId($data) {
|
||||
$this->_aData['user_id']=$data;
|
||||
}
|
||||
public function setText($data) {
|
||||
$this->_aData['comment_text']=$data;
|
||||
}
|
||||
public function setDate($data) {
|
||||
$this->_aData['comment_date']=$data;
|
||||
}
|
||||
public function setUserIp($data) {
|
||||
$this->_aData['comment_user_ip']=$data;
|
||||
}
|
||||
public function setRating($data) {
|
||||
$this->_aData['comment_rating']=$data;
|
||||
}
|
||||
public function setCountVote($data) {
|
||||
$this->_aData['comment_count_vote']=$data;
|
||||
}
|
||||
public function setDelete($data) {
|
||||
$this->_aData['comment_delete']=$data;
|
||||
}
|
||||
public function setPublish($data) {
|
||||
$this->_aData['comment_publish']=$data;
|
||||
}
|
||||
$this->_aData['comment_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID родительского комментария
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setPid($data) {
|
||||
$this->_aData['comment_pid']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает значени left для дерева nested set
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setLeft($data) {
|
||||
$this->_aData['comment_left']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает значени right для дерева nested set
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setRight($data) {
|
||||
$this->_aData['comment_right']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID владельца
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setTargetId($data) {
|
||||
$this->_aData['target_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает тип владельца
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function setTargetType($data) {
|
||||
$this->_aData['target_type']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID родителя владельца
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setTargetParentId($data) {
|
||||
$this->_aData['target_parent_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID пользователя
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setUserId($data) {
|
||||
$this->_aData['user_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает текст комментария
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function setText($data) {
|
||||
$this->_aData['comment_text']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает дату комментария
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function setDate($data) {
|
||||
$this->_aData['comment_date']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанвливает IP пользователя
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function setUserIp($data) {
|
||||
$this->_aData['comment_user_ip']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает рейтинг комментария
|
||||
*
|
||||
* @param float $data
|
||||
*/
|
||||
public function setRating($data) {
|
||||
$this->_aData['comment_rating']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает количество проголосавших
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setCountVote($data) {
|
||||
$this->_aData['comment_count_vote']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает флаг удаленности комментария
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setDelete($data) {
|
||||
$this->_aData['comment_delete']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает флаг публикации
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setPublish($data) {
|
||||
$this->_aData['comment_publish']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает хеш комментария
|
||||
*
|
||||
* @param strign $data
|
||||
*/
|
||||
public function setTextHash($data) {
|
||||
$this->_aData['comment_text_hash']=$data;
|
||||
}
|
||||
|
||||
|
||||
public function setLevel($data) {
|
||||
$this->_aData['comment_level']=$data;
|
||||
}
|
||||
public function setUser($data) {
|
||||
$this->_aData['user']=$data;
|
||||
}
|
||||
public function setTarget($data) {
|
||||
$this->_aData['target']=$data;
|
||||
}
|
||||
public function setVote($data) {
|
||||
$this->_aData['vote']=$data;
|
||||
}
|
||||
public function setIsFavourite($data) {
|
||||
$this->_aData['comment_is_favourite']=$data;
|
||||
}
|
||||
public function setCountFavourite($data) {
|
||||
$this->_aData['comment_count_favourite']=$data;
|
||||
}
|
||||
$this->_aData['comment_text_hash']=$data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает уровень вложенности комментария
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setLevel($data) {
|
||||
$this->_aData['comment_level']=$data;
|
||||
}
|
||||
/**
|
||||
* Устаналвает объект пользователя
|
||||
*
|
||||
* @param ModuleUser_EntityUser $data
|
||||
*/
|
||||
public function setUser($data) {
|
||||
$this->_aData['user']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает объект владельца
|
||||
*
|
||||
* @param mixed $data
|
||||
*/
|
||||
public function setTarget($data) {
|
||||
$this->_aData['target']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает объект голосования
|
||||
*
|
||||
* @param ModuleVote_EntityVote $data
|
||||
*/
|
||||
public function setVote($data) {
|
||||
$this->_aData['vote']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает факт нахождения комментария в избранном у текущего пользователя
|
||||
*
|
||||
* @param bool $data
|
||||
*/
|
||||
public function setIsFavourite($data) {
|
||||
$this->_aData['comment_is_favourite']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает количество избранного
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setCountFavourite($data) {
|
||||
$this->_aData['comment_count_favourite']=$data;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -15,32 +15,77 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ModuleComment_EntityCommentOnline extends Entity
|
||||
{
|
||||
public function getTargetId() {
|
||||
return $this->_getDataOne('target_id');
|
||||
}
|
||||
public function getTargetType() {
|
||||
return $this->_getDataOne('target_type');
|
||||
}
|
||||
/**
|
||||
* Объект сущности прямого эфира
|
||||
*
|
||||
* @package modules.comment
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleComment_EntityCommentOnline extends Entity {
|
||||
/**
|
||||
* Возвращает ID владельца
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTargetId() {
|
||||
return $this->_getDataOne('target_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает тип владельца
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTargetType() {
|
||||
return $this->_getDataOne('target_type');
|
||||
}
|
||||
/**
|
||||
* Возвращает ID комментария
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCommentId() {
|
||||
return $this->_getDataOne('comment_id');
|
||||
}
|
||||
public function getTargetParentId() {
|
||||
return $this->_getDataOne('target_parent_id') ? $this->_getDataOne('target_parent_id') : 0;
|
||||
}
|
||||
|
||||
public function setTargetId($data) {
|
||||
$this->_aData['target_id']=$data;
|
||||
}
|
||||
public function setTargetType($data) {
|
||||
$this->_aData['target_type']=$data;
|
||||
}
|
||||
public function setCommentId($data) {
|
||||
$this->_aData['comment_id']=$data;
|
||||
}
|
||||
public function setTargetParentId($data) {
|
||||
$this->_aData['target_parent_id']=$data;
|
||||
}
|
||||
return $this->_getDataOne('comment_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает ID родителя владельца
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTargetParentId() {
|
||||
return $this->_getDataOne('target_parent_id') ? $this->_getDataOne('target_parent_id') : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает ID владельца
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setTargetId($data) {
|
||||
$this->_aData['target_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает тип владельца
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function setTargetType($data) {
|
||||
$this->_aData['target_type']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID комментария
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setCommentId($data) {
|
||||
$this->_aData['comment_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID родителя владельца
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setTargetParentId($data) {
|
||||
$this->_aData['target_parent_id']=$data;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -15,10 +15,26 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ModuleComment_MapperComment extends Mapper {
|
||||
|
||||
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
$sql = "SELECT
|
||||
/**
|
||||
* Маппер комментариев, работа с базой данных
|
||||
*
|
||||
* @package modules.comment
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleComment_MapperComment extends Mapper {
|
||||
|
||||
/**
|
||||
* Получить комменты по рейтингу и дате
|
||||
*
|
||||
* @param string $sDate Дата за которую выводить рейтинг
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iLimit Количество элементов
|
||||
* @param array $aExcludeTarget Список ID владельцев, которые необходимо исключить из выдачи
|
||||
* @param array $aExcludeParentTarget Список ID родителей владельцев, которые необходимо исключить из выдачи
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsRatingByDate($sDate,$sTargetType,$iLimit,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
$sql = "SELECT
|
||||
comment_id
|
||||
FROM
|
||||
".Config::Get('db.table.comment')."
|
||||
|
@ -35,14 +51,14 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
{ AND target_id NOT IN(?a) }
|
||||
{ AND target_parent_id NOT IN (?a) }
|
||||
ORDER by comment_rating desc, comment_id desc
|
||||
LIMIT 0, ?d ";
|
||||
$aComments=array();
|
||||
LIMIT 0, ?d ";
|
||||
$aComments=array();
|
||||
if ($aRows=$this->oDb->select(
|
||||
$sql,$sTargetType, $sDate,
|
||||
(is_array($aExcludeTarget)&&count($aExcludeTarget)) ? $aExcludeTarget : DBSIMPLE_SKIP,
|
||||
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
|
||||
$iLimit
|
||||
)
|
||||
$sql,$sTargetType, $sDate,
|
||||
(is_array($aExcludeTarget)&&count($aExcludeTarget)) ? $aExcludeTarget : DBSIMPLE_SKIP,
|
||||
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
|
||||
$iLimit
|
||||
)
|
||||
) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$aComments[]=$aRow['comment_id'];
|
||||
|
@ -50,7 +66,16 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает уникальный коммент, это помогает спастись от дублей комментов
|
||||
*
|
||||
* @param int $sTargetId ID владельца комментария
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $sCommentPid ID родительского комментария
|
||||
* @param string $sHash Хеш строка текста комментария
|
||||
* @return int|null
|
||||
*/
|
||||
public function GetCommentUnique($sTargetId,$sTargetType,$sUserId,$sCommentPid,$sHash) {
|
||||
$sql = "SELECT comment_id FROM ".Config::Get('db.table.comment')."
|
||||
WHERE
|
||||
|
@ -69,7 +94,17 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить все комменты
|
||||
*
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iCount Возвращает общее количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @param array $aExcludeTarget Список ID владельцев, которые необходимо исключить из выдачи
|
||||
* @param array $aExcludeParentTarget Список ID родителей владельцев, которые необходимо исключить из выдачи, например, исключить комментарии топиков к определенным блогам(закрытым)
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsAll($sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
$sql = "SELECT
|
||||
comment_id
|
||||
|
@ -84,28 +119,32 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
{ AND target_id NOT IN(?a) }
|
||||
{ AND target_parent_id NOT IN(?a) }
|
||||
ORDER by comment_id desc
|
||||
LIMIT ?d, ?d ";
|
||||
LIMIT ?d, ?d ";
|
||||
$aComments=array();
|
||||
if ($aRows=$this->oDb->selectPage(
|
||||
$iCount,$sql,$sTargetType,
|
||||
(count($aExcludeTarget)?$aExcludeTarget:DBSIMPLE_SKIP),
|
||||
(count($aExcludeParentTarget)?$aExcludeParentTarget:DBSIMPLE_SKIP),
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
)
|
||||
$iCount,$sql,$sTargetType,
|
||||
(count($aExcludeTarget)?$aExcludeTarget:DBSIMPLE_SKIP),
|
||||
(count($aExcludeParentTarget)?$aExcludeParentTarget:DBSIMPLE_SKIP),
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
)
|
||||
) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$aComments[]=$aRow['comment_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Список комментов по ID
|
||||
*
|
||||
* @param array $aArrayId Список ID комментариев
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsByArrayId($aArrayId) {
|
||||
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
*
|
||||
FROM
|
||||
|
@ -117,13 +156,19 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
if ($aRows=$this->oDb->select($sql,$aArrayId,$aArrayId)) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$aComments[]=Engine::GetEntity('Comment',$aRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
|
||||
public function GetCommentsOnline($sTargetType,$aExcludeTargets,$iLimit) {
|
||||
/**
|
||||
* Получить все комменты сгрупированные по типу(для вывода прямого эфира)
|
||||
*
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param array $aExcludeTargets Список ID владельцев для исключения
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsOnline($sTargetType,$aExcludeTargets,$iLimit) {
|
||||
$sql = "SELECT
|
||||
comment_id
|
||||
FROM
|
||||
|
@ -132,13 +177,13 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_type = ?
|
||||
{ AND target_parent_id NOT IN(?a) }
|
||||
ORDER by comment_online_id desc limit 0, ?d ; ";
|
||||
|
||||
|
||||
$aComments=array();
|
||||
if ($aRows=$this->oDb->select(
|
||||
$sql,$sTargetType,
|
||||
(count($aExcludeTargets)?$aExcludeTargets:DBSIMPLE_SKIP),
|
||||
$iLimit
|
||||
)
|
||||
$sql,$sTargetType,
|
||||
(count($aExcludeTargets)?$aExcludeTargets:DBSIMPLE_SKIP),
|
||||
$iLimit
|
||||
)
|
||||
) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$aComments[]=$aRow['comment_id'];
|
||||
|
@ -146,8 +191,14 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
public function GetCommentsByTargetId($sId,$sTargetType) {
|
||||
/**
|
||||
* Получить комменты по владельцу
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsByTargetId($sId,$sTargetType) {
|
||||
$sql = "SELECT
|
||||
comment_id,
|
||||
comment_id as ARRAY_KEY,
|
||||
|
@ -165,8 +216,14 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetCommentsTreeByTargetId($sId,$sTargetType) {
|
||||
/**
|
||||
* Получает комменты используя nested set
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsTreeByTargetId($sId,$sTargetType) {
|
||||
$sql = "SELECT
|
||||
comment_id
|
||||
FROM
|
||||
|
@ -185,10 +242,18 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получает комменты используя nested set
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iCount Возвращает общее количество элементов
|
||||
* @param int $iPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsTreePageByTargetId($sId,$sTargetType,&$iCount,$iPage,$iPerPage) {
|
||||
|
||||
|
||||
/**
|
||||
* Сначала получаем корни и определяем границы выборки веток
|
||||
*/
|
||||
|
@ -210,13 +275,13 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
$aCmt=array_pop($aRows);
|
||||
$iLeft=$aCmt['comment_left'];
|
||||
if ($aRows) {
|
||||
$aCmt=array_shift($aRows);
|
||||
$aCmt=array_shift($aRows);
|
||||
}
|
||||
$iRight=$aCmt['comment_right'];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Теперь получаем полный список комментов
|
||||
*/
|
||||
|
@ -240,10 +305,16 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
$aComments[]=$aRow['comment_id'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает количество дочерних комментариев у корневого коммента
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return int
|
||||
*/
|
||||
public function GetCountCommentsRootByTargetId($sId,$sTargetType) {
|
||||
$sql = "SELECT
|
||||
count(comment_id) as c
|
||||
|
@ -255,12 +326,19 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_type = ?
|
||||
AND
|
||||
comment_pid IS NULL ;";
|
||||
|
||||
|
||||
if ($aRow=$this->oDb->selectRow($sql,$sId,$sTargetType)) {
|
||||
return $aRow['c'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает количество комментариев
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iLeft Значение left для дерева nested set
|
||||
* @return int
|
||||
*/
|
||||
public function GetCountCommentsAfterByTargetId($sId,$sTargetType,$iLeft) {
|
||||
$sql = "SELECT
|
||||
count(comment_id) as c
|
||||
|
@ -274,12 +352,19 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
comment_pid IS NULL
|
||||
AND
|
||||
comment_left >= ?d ;";
|
||||
|
||||
|
||||
if ($aRow=$this->oDb->selectRow($sql,$sId,$sTargetType,$iLeft)) {
|
||||
return $aRow['c'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает корневой комментарий
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iLeft Значение left для дерева nested set
|
||||
* @return ModuleComment_EntityComment|null
|
||||
*/
|
||||
public function GetCommentRootByTargetIdAndChildren($sId,$sTargetType,$iLeft) {
|
||||
$sql = "SELECT
|
||||
*
|
||||
|
@ -296,14 +381,21 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
AND
|
||||
comment_right > ?d
|
||||
LIMIT 0,1 ;";
|
||||
|
||||
|
||||
if ($aRow=$this->oDb->selectRow($sql,$sId,$sTargetType,$iLeft,$iLeft)) {
|
||||
return Engine::GetEntity('Comment',$aRow);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast) {
|
||||
/**
|
||||
* Получить новые комменты для владельца
|
||||
*
|
||||
* @param int $sId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $sIdCommentLast ID последнего прочитанного комментария
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsNewByTargetId($sId,$sTargetType,$sIdCommentLast) {
|
||||
$sql = "SELECT
|
||||
comment_id
|
||||
FROM
|
||||
|
@ -324,7 +416,18 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить комменты по юзеру
|
||||
*
|
||||
* @param int $sId ID пользователя
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iCount Возращает общее количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @param array $aExcludeTarget Список ID владельцев, которые необходимо исключить из выдачи
|
||||
* @param array $aExcludeParentTarget Список ID родителей владельцев, которые необходимо исключить из выдачи
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentsByUserId($sId,$sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
$sql = "SELECT
|
||||
comment_id
|
||||
|
@ -341,15 +444,15 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
{ AND target_id NOT IN (?a) }
|
||||
{ AND target_parent_id NOT IN (?a) }
|
||||
ORDER by comment_id desc
|
||||
LIMIT ?d, ?d ";
|
||||
LIMIT ?d, ?d ";
|
||||
$aComments=array();
|
||||
if ($aRows=$this->oDb->selectPage(
|
||||
$iCount,$sql,$sId,
|
||||
$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
||||
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
)
|
||||
$iCount,$sql,$sId,
|
||||
$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
||||
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP),
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
)
|
||||
) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$aComments[]=$aRow['comment_id'];
|
||||
|
@ -357,7 +460,15 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return $aComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает количество комментариев одного пользователя
|
||||
*
|
||||
* @param id $sId ID пользователя
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param array $aExcludeTarget Список ID владельцев, которые необходимо исключить из выдачи
|
||||
* @param array $aExcludeParentTarget Список ID родителей владельцев, которые необходимо исключить из выдачи
|
||||
* @return int
|
||||
*/
|
||||
public function GetCountCommentsByUserId($sId,$sTargetType,$aExcludeTarget=array(),$aExcludeParentTarget=array()) {
|
||||
$sql = "SELECT
|
||||
count(comment_id) as count
|
||||
|
@ -373,18 +484,23 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
comment_publish = 1
|
||||
{ AND target_id NOT IN (?a) }
|
||||
{ AND target_parent_id NOT IN (?a) }
|
||||
";
|
||||
";
|
||||
if ($aRow=$this->oDb->selectRow(
|
||||
$sql,$sId,$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
||||
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP)
|
||||
)
|
||||
$sql,$sId,$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
||||
(count($aExcludeParentTarget) ? $aExcludeParentTarget : DBSIMPLE_SKIP)
|
||||
)
|
||||
) {
|
||||
return $aRow['count'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет коммент
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool|int
|
||||
*/
|
||||
public function AddComment(ModuleComment_EntityComment $oComment) {
|
||||
$sql = "INSERT INTO ".Config::Get('db.table.comment')."
|
||||
(comment_pid,
|
||||
|
@ -399,22 +515,27 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
comment_text_hash
|
||||
)
|
||||
VALUES(?, ?d, ?, ?d, ?d, ?, ?, ?, ?d, ?)
|
||||
";
|
||||
if ($iId=$this->oDb->query($sql,$oComment->getPid(),$oComment->getTargetId(),$oComment->getTargetType(),$oComment->getTargetParentId(),$oComment->getUserId(),$oComment->getText(),$oComment->getDate(),$oComment->getUserIp(),$oComment->getPublish(),$oComment->getTextHash()))
|
||||
";
|
||||
if ($iId=$this->oDb->query($sql,$oComment->getPid(),$oComment->getTargetId(),$oComment->getTargetType(),$oComment->getTargetParentId(),$oComment->getUserId(),$oComment->getText(),$oComment->getDate(),$oComment->getUserIp(),$oComment->getPublish(),$oComment->getTextHash()))
|
||||
{
|
||||
return $iId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет коммент в дерево nested set
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool|int
|
||||
*/
|
||||
public function AddCommentTree(ModuleComment_EntityComment $oComment) {
|
||||
$this->oDb->transaction();
|
||||
|
||||
|
||||
if ($oComment->getPid() and $oCommentParent=$this->GetCommentsByArrayId(array($oComment->getPid()))) {
|
||||
$oCommentParent=$oCommentParent[0];
|
||||
$iLeft=$oCommentParent->getRight();
|
||||
$iLevel=$oCommentParent->getLevel()+1;
|
||||
|
||||
|
||||
$sql= "UPDATE ".Config::Get('db.table.comment')." SET comment_left=comment_left+2 WHERE target_id=?d and target_type=? and comment_left>? ;";
|
||||
$this->oDb->query($sql, $oComment->getTargetId(),$oComment->getTargetType(),$iLeft-1);
|
||||
$sql = "UPDATE ".Config::Get('db.table.comment')." SET comment_right=comment_right+2 WHERE target_id=?d and target_type=? and comment_right>? ;";
|
||||
|
@ -427,21 +548,27 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
$iLevel=0;
|
||||
}
|
||||
|
||||
|
||||
if ($iId=$this->AddComment($oComment)) {
|
||||
$sql = "UPDATE ".Config::Get('db.table.comment')." SET comment_left = ?d, comment_right = ?d, comment_level = ?d WHERE comment_id = ? ;";
|
||||
$this->oDb->query($sql, $iLeft,$iLeft+1,$iLevel,$iId);
|
||||
$this->oDb->commit();
|
||||
return $iId;
|
||||
}
|
||||
|
||||
|
||||
if (strtolower(Config::Get('db.tables.engine'))=='innodb') {
|
||||
$this->oDb->rollback();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает последний комментарий
|
||||
*
|
||||
* @param int $sTargetId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return ModuleComment_EntityComment|null
|
||||
*/
|
||||
public function GetCommentLast($sTargetId,$sTargetType) {
|
||||
$sql = "SELECT * FROM ".Config::Get('db.table.comment')."
|
||||
WHERE
|
||||
|
@ -456,7 +583,12 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет новый коммент в прямой эфир
|
||||
*
|
||||
* @param ModuleComment_EntityCommentOnline $oCommentOnline Объект онлайн комментария
|
||||
* @return bool|int
|
||||
*/
|
||||
public function AddCommentOnline(ModuleComment_EntityCommentOnline $oCommentOnline) {
|
||||
$sql = "REPLACE INTO ".Config::Get('db.table.comment_online')."
|
||||
SET
|
||||
|
@ -464,26 +596,33 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_type= ? ,
|
||||
target_parent_id = ?d,
|
||||
comment_id= ?d
|
||||
";
|
||||
if ($iId=$this->oDb->query($sql,$oCommentOnline->getTargetId(),$oCommentOnline->getTargetType(),$oCommentOnline->getTargetParentId(),$oCommentOnline->getCommentId()))
|
||||
{
|
||||
";
|
||||
if ($iId=$this->oDb->query($sql,$oCommentOnline->getTargetId(),$oCommentOnline->getTargetType(),$oCommentOnline->getTargetParentId(),$oCommentOnline->getCommentId())) {
|
||||
return $iId;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет коммент из прямого эфира
|
||||
*
|
||||
* @param int $sTargetId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteCommentOnlineByTargetId($sTargetId,$sTargetType) {
|
||||
$sql = "DELETE FROM ".Config::Get('db.table.comment_online')." WHERE target_id = ?d and target_type = ? ";
|
||||
if ($this->oDb->query($sql,$sTargetId,$sTargetType))
|
||||
{
|
||||
$sql = "DELETE FROM ".Config::Get('db.table.comment_online')." WHERE target_id = ?d and target_type = ? ";
|
||||
if ($this->oDb->query($sql,$sTargetId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function UpdateComment(ModuleComment_EntityComment $oComment) {
|
||||
/**
|
||||
* Обновляет коммент
|
||||
*
|
||||
* @param ModuleComment_EntityComment $oComment Объект комментария
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateComment(ModuleComment_EntityComment $oComment) {
|
||||
$sql = "UPDATE ".Config::Get('db.table.comment')."
|
||||
SET
|
||||
comment_text= ?,
|
||||
|
@ -495,26 +634,39 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
comment_text_hash = ?
|
||||
WHERE
|
||||
comment_id = ?d
|
||||
";
|
||||
";
|
||||
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;
|
||||
}
|
||||
|
||||
public function SetCommentsPublish($sTargetId,$sTargetType,$iPublish) {
|
||||
/**
|
||||
* Устанавливает publish у коммента
|
||||
*
|
||||
* @param int $sTargetId ID владельца коммента
|
||||
* @param string $sTargetType Тип владельца комментария
|
||||
* @param int $iPublish Статус отображать комментарии или нет
|
||||
* @return bool
|
||||
*/
|
||||
public function SetCommentsPublish($sTargetId,$sTargetType,$iPublish) {
|
||||
$sql = "UPDATE ".Config::Get('db.table.comment')."
|
||||
SET
|
||||
comment_publish= ?
|
||||
WHERE
|
||||
target_id = ?d AND target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$iPublish,$sTargetId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет комментарии из базы данных
|
||||
*
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteCommentByTargetId($aTargetId,$sTargetType) {
|
||||
$sql = "
|
||||
DELETE FROM ".Config::Get('db.table.comment')."
|
||||
|
@ -522,13 +674,19 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_id IN (?a)
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$aTargetId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет коммент из прямого эфира по массиву переданных идентификаторов
|
||||
*
|
||||
* @param array|int $aCommentId
|
||||
* @param string $sTargetType Тип владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteCommentOnlineByArrayId($aCommentId,$sTargetType) {
|
||||
$sql = "
|
||||
DELETE FROM ".Config::Get('db.table.comment_online')."
|
||||
|
@ -536,13 +694,20 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
comment_id IN (?a)
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$aCommentId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняем target parent по массиву идентификаторов
|
||||
*
|
||||
* @param int $sParentId Новый ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateTargetParentByTargetId($sParentId, $sTargetType, $aTargetId) {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.comment')."
|
||||
|
@ -552,13 +717,20 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_id IN (?a)
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$sParentId,$aTargetId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняем target parent по массиву идентификаторов в таблице комментариев online
|
||||
*
|
||||
* @param int $sParentId Новый ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateTargetParentByTargetIdOnline($sParentId, $sTargetType, $aTargetId) {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.comment_online')."
|
||||
|
@ -568,13 +740,20 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_id IN (?a)
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$sParentId,$aTargetId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Меняет target parent на новый
|
||||
*
|
||||
* @param int $sParentId Прежний ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sParentIdNew Новый ID родителя владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function MoveTargetParent($sParentId, $sTargetType, $sParentIdNew) {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.comment')."
|
||||
|
@ -584,13 +763,20 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_parent_id = ?d
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$sParentIdNew,$sParentId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняет target parent на новый в прямом эфире
|
||||
*
|
||||
* @param int $sParentId Прежний ID родителя владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sParentIdNew Новый ID родителя владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function MoveTargetParentOnline($sParentId, $sTargetType, $sParentIdNew) {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.comment_online')."
|
||||
|
@ -600,20 +786,29 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
target_parent_id = ?d
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql,$sParentIdNew,$sParentId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function RestoreTree($iPid,$iLft,$iLevel,$aTargetId,$sTargetType) {
|
||||
/**
|
||||
* Перестраивает дерево комментариев
|
||||
* Восстанавливает значения left, right и level
|
||||
*
|
||||
* @param int $iPid ID родителя
|
||||
* @param int $iLft Значение left для дерева nested set
|
||||
* @param int $iLevel Уровень
|
||||
* @param int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return int
|
||||
*/
|
||||
public function RestoreTree($iPid,$iLft,$iLevel,$aTargetId,$sTargetType) {
|
||||
$iRgt = $iLft+1;
|
||||
$iLevel++;
|
||||
$sql = "SELECT comment_id FROM ".Config::Get('db.table.comment')." WHERE target_id = ? and target_type = ? { and comment_pid = ? } { and comment_pid IS NULL and 1=?d}
|
||||
ORDER BY comment_id ASC";
|
||||
|
||||
|
||||
if ($aRows=$this->oDb->select($sql,$aTargetId,$sTargetType,!is_null($iPid) ? $iPid:DBSIMPLE_SKIP, is_null($iPid) ? 1:DBSIMPLE_SKIP)) {
|
||||
foreach ($aRows as $aRow) {
|
||||
$iRgt = $this->RestoreTree($aRow['comment_id'], $iRgt,$iLevel,$aTargetId,$sTargetType);
|
||||
|
@ -624,12 +819,16 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
$sql = "UPDATE ".Config::Get('db.table.comment')."
|
||||
SET comment_left=?d, comment_right=?d , comment_level =?d
|
||||
WHERE comment_id = ? ";
|
||||
$this->oDb->query($sql,$iLft,$iRgt,$iLevel,$iPid);
|
||||
$this->oDb->query($sql,$iLft,$iRgt,$iLevel,$iPid);
|
||||
}
|
||||
|
||||
|
||||
return $iRgt+1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список всех используемых типов владельца
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetCommentTypes() {
|
||||
$sql = "SELECT target_type FROM ".Config::Get('db.table.comment')."
|
||||
GROUP BY target_type ";
|
||||
|
@ -641,17 +840,28 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
}
|
||||
return $aTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список ID владельцев
|
||||
*
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на одну старницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetTargetIdByType($sTargetType,$iPage,$iPerPage) {
|
||||
$sql = "SELECT target_id FROM ".Config::Get('db.table.comment')."
|
||||
WHERE target_type = ? GROUP BY target_id ORDER BY target_id LIMIT ?d, ?d ";
|
||||
WHERE target_type = ? GROUP BY target_id ORDER BY target_id LIMIT ?d, ?d ";
|
||||
if ($aRows=$this->oDb->select($sql,$sTargetType,($iPage-1)*$iPerPage, $iPerPage)) {
|
||||
return $aRows;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function RecalculateFavourite() {
|
||||
/**
|
||||
* Пересчитывает счетчик избранных комментариев
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function RecalculateFavourite() {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.comment')." c
|
||||
SET c.comment_count_favourite = (
|
||||
|
@ -664,11 +874,11 @@ class ModuleComment_MapperComment extends Mapper {
|
|||
AND
|
||||
f.target_type = 'comment'
|
||||
)
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query($sql)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -16,26 +16,32 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Модуль для работы с голосованиями
|
||||
* Модуль для работы с избранным
|
||||
*
|
||||
* @package modules.favourite
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleFavourite extends Module {
|
||||
protected $oMapper;
|
||||
|
||||
class ModuleFavourite extends Module {
|
||||
/**
|
||||
* Объект маппера
|
||||
*
|
||||
* @var ModuleFavourite_MapperFavourite
|
||||
*/
|
||||
protected $oMapper;
|
||||
|
||||
/**
|
||||
* Инициализация
|
||||
*
|
||||
*/
|
||||
public function Init() {
|
||||
public function Init() {
|
||||
$this->oMapper=Engine::GetMapper(__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает информацию о том, найден ли таргет в избранном или нет
|
||||
*
|
||||
* @param string $sTargetId
|
||||
* @param string $sTargetType
|
||||
* @param string $sUserId
|
||||
* @param int $sTargetId ID владельца
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return ModuleFavourite_EntityFavourite|null
|
||||
*/
|
||||
public function GetFavourite($sTargetId,$sTargetType,$sUserId) {
|
||||
|
@ -44,19 +50,18 @@ class ModuleFavourite extends Module {
|
|||
? $data[$sTargetId]
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить список избранного по списку айдишников
|
||||
*
|
||||
* @param array $aTargetId
|
||||
* @param string $sTargetType
|
||||
* @param string $sUserId
|
||||
* @param array $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouritesByArray($aTargetId,$sTargetType,$sUserId) {
|
||||
if (!$aTargetId) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
if (Config::Get('sys.cache.solid')) {
|
||||
return $this->GetFavouritesByArraySolid($aTargetId,$sTargetType,$sUserId);
|
||||
}
|
||||
|
@ -70,25 +75,25 @@ class ModuleFavourite extends Module {
|
|||
* Делаем мульти-запрос к кешу
|
||||
*/
|
||||
$aCacheKeys=func_build_cache_keys($aTargetId,"favourite_{$sTargetType}_",'_'.$sUserId);
|
||||
if (false !== ($data = $this->Cache_Get($aCacheKeys))) {
|
||||
if (false !== ($data = $this->Cache_Get($aCacheKeys))) {
|
||||
/**
|
||||
* проверяем что досталось из кеша
|
||||
*/
|
||||
foreach ($aCacheKeys as $sValue => $sKey ) {
|
||||
if (array_key_exists($sKey,$data)) {
|
||||
if (array_key_exists($sKey,$data)) {
|
||||
if ($data[$sKey]) {
|
||||
$aFavourite[$data[$sKey]->getTargetId()]=$data[$sKey];
|
||||
} else {
|
||||
$aIdNotNeedQuery[]=$sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Смотрим чего не было в кеше и делаем запрос в БД
|
||||
*/
|
||||
$aIdNeedQuery=array_diff($aTargetId,array_keys($aFavourite));
|
||||
$aIdNeedQuery=array_diff($aIdNeedQuery,$aIdNotNeedQuery);
|
||||
*/
|
||||
$aIdNeedQuery=array_diff($aTargetId,array_keys($aFavourite));
|
||||
$aIdNeedQuery=array_diff($aIdNeedQuery,$aIdNotNeedQuery);
|
||||
$aIdNeedStore=$aIdNeedQuery;
|
||||
if ($data = $this->oMapper->GetFavouritesByArray($aIdNeedQuery,$sTargetType,$sUserId)) {
|
||||
foreach ($data as $oFavourite) {
|
||||
|
@ -105,193 +110,191 @@ class ModuleFavourite extends Module {
|
|||
*/
|
||||
foreach ($aIdNeedStore as $sId) {
|
||||
$this->Cache_Set(null, "favourite_{$sTargetType}_{$sId}_{$sUserId}", array(), 60*60*24*7);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Сортируем результат согласно входящему массиву
|
||||
*/
|
||||
$aFavourite=func_array_sort_by_keys($aFavourite,$aTargetId);
|
||||
return $aFavourite;
|
||||
return $aFavourite;
|
||||
}
|
||||
/**
|
||||
* Получить список избранного по списку айдишников, но используя единый кеш
|
||||
*
|
||||
* @param array $aTargetId
|
||||
* @param string $sTargetType
|
||||
* @param string $sUserId
|
||||
* @param array $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouritesByArraySolid($aTargetId,$sTargetType,$sUserId) {
|
||||
if (!is_array($aTargetId)) {
|
||||
$aTargetId=array($aTargetId);
|
||||
}
|
||||
$aTargetId=array_unique($aTargetId);
|
||||
$aFavourites=array();
|
||||
$s=join(',',$aTargetId);
|
||||
if (false === ($data = $this->Cache_Get("favourite_{$sTargetType}_{$sUserId}_id_{$s}"))) {
|
||||
$aTargetId=array_unique($aTargetId);
|
||||
$aFavourites=array();
|
||||
$s=join(',',$aTargetId);
|
||||
if (false === ($data = $this->Cache_Get("favourite_{$sTargetType}_{$sUserId}_id_{$s}"))) {
|
||||
$data = $this->oMapper->GetFavouritesByArray($aTargetId,$sTargetType,$sUserId);
|
||||
foreach ($data as $oFavourite) {
|
||||
$aFavourites[$oFavourite->getTargetId()]=$oFavourite;
|
||||
}
|
||||
$this->Cache_Set($aFavourites, "favourite_{$sTargetType}_{$sUserId}_id_{$s}", array("favourite_{$sTargetType}_change_user_{$sUserId}"), 60*60*24*1);
|
||||
return $aFavourites;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает список таргеов из избранного
|
||||
* Получает список таргетов из избранного
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @param string $sTargetType
|
||||
* @param int $iCount
|
||||
* @param int $iCurrPage
|
||||
* @param int $iPerPage
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @param array $aExcludeTarget Список ID владельцев для исклчения
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouritesByUserId($sUserId,$sTargetType,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
|
||||
public function GetFavouritesByUserId($sUserId,$sTargetType,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
|
||||
$s=serialize($aExcludeTarget);
|
||||
if (false === ($data = $this->Cache_Get("{$sTargetType}_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_{$s}"))) {
|
||||
if (false === ($data = $this->Cache_Get("{$sTargetType}_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_{$s}"))) {
|
||||
$data = array(
|
||||
'collection' => $this->oMapper->GetFavouritesByUserId($sUserId,$sTargetType,$iCount,$iCurrPage,$iPerPage,$aExcludeTarget),
|
||||
'count' => $iCount
|
||||
);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"{$sTargetType}_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_{$s}",
|
||||
$data,
|
||||
"{$sTargetType}_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_{$s}",
|
||||
array(
|
||||
"favourite_{$sTargetType}_change",
|
||||
"favourite_{$sTargetType}_change_user_{$sUserId}"
|
||||
),
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Возвращает число таргетов определенного типа в избранном по ID пользователя
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @param string $sTargetType
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array $aExcludeTarget Список ID владельцев для исклчения
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouritesByUserId($sUserId,$sTargetType,$aExcludeTarget=array()) {
|
||||
$s=serialize($aExcludeTarget);
|
||||
if (false === ($data = $this->Cache_Get("{$sTargetType}_count_favourite_user_{$sUserId}_{$s}"))) {
|
||||
if (false === ($data = $this->Cache_Get("{$sTargetType}_count_favourite_user_{$sUserId}_{$s}"))) {
|
||||
$data = $this->oMapper->GetCountFavouritesByUserId($sUserId,$sTargetType,$aExcludeTarget);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"{$sTargetType}_count_favourite_user_{$sUserId}_{$s}",
|
||||
$data,
|
||||
"{$sTargetType}_count_favourite_user_{$sUserId}_{$s}",
|
||||
array(
|
||||
"favourite_{$sTargetType}_change",
|
||||
"favourite_{$sTargetType}_change_user_{$sUserId}"
|
||||
),
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает список комментариев к записям открытых блогов
|
||||
* Получает список комментариев к записям открытых блогов
|
||||
* из избранного указанного пользователя
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @param int $iCurrPage
|
||||
* @param int $iPerPage
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteOpenCommentsByUserId($sUserId,$iCurrPage,$iPerPage) {
|
||||
if (false === ($data = $this->Cache_Get("comment_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open"))) {
|
||||
public function GetFavouriteOpenCommentsByUserId($sUserId,$iCurrPage,$iPerPage) {
|
||||
if (false === ($data = $this->Cache_Get("comment_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open"))) {
|
||||
$data = array(
|
||||
'collection' => $this->oMapper->GetFavouriteOpenCommentsByUserId($sUserId,$iCount,$iCurrPage,$iPerPage),
|
||||
'count' => $iCount
|
||||
);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"comment_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open",
|
||||
$data,
|
||||
"comment_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open",
|
||||
array(
|
||||
"favourite_comment_change",
|
||||
"favourite_comment_change_user_{$sUserId}"
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Возвращает число комментариев к открытым блогам в избранном по ID пользователя
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouriteOpenCommentsByUserId($sUserId) {
|
||||
if (false === ($data = $this->Cache_Get("comment_count_favourite_user_{$sUserId}_open"))) {
|
||||
$data = $this->oMapper->GetCountFavouriteOpenCommentsByUserId($sUserId);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"comment_count_favourite_user_{$sUserId}_open",
|
||||
array(
|
||||
"favourite_comment_change",
|
||||
"favourite_comment_change_user_{$sUserId}"
|
||||
),
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Получает список топиков из открытых блогов
|
||||
* из избранного указанного пользователя
|
||||
* Возвращает число комментариев к открытым блогам в избранном по ID пользователя
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @param int $iCurrPage
|
||||
* @param int $iPerPage
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteOpenTopicsByUserId($sUserId,$iCurrPage,$iPerPage) {
|
||||
if (false === ($data = $this->Cache_Get("topic_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open"))) {
|
||||
public function GetCountFavouriteOpenCommentsByUserId($sUserId) {
|
||||
if (false === ($data = $this->Cache_Get("comment_count_favourite_user_{$sUserId}_open"))) {
|
||||
$data = $this->oMapper->GetCountFavouriteOpenCommentsByUserId($sUserId);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"comment_count_favourite_user_{$sUserId}_open",
|
||||
array(
|
||||
"favourite_comment_change",
|
||||
"favourite_comment_change_user_{$sUserId}"
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Получает список топиков из открытых блогов
|
||||
* из избранного указанного пользователя
|
||||
*
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteOpenTopicsByUserId($sUserId,$iCurrPage,$iPerPage) {
|
||||
if (false === ($data = $this->Cache_Get("topic_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open"))) {
|
||||
$data = array(
|
||||
'collection' => $this->oMapper->GetFavouriteOpenTopicsByUserId($sUserId,$iCount,$iCurrPage,$iPerPage),
|
||||
'count' => $iCount
|
||||
);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"topic_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open",
|
||||
$data,
|
||||
"topic_favourite_user_{$sUserId}_{$iCurrPage}_{$iPerPage}_open",
|
||||
array(
|
||||
"favourite_topic_change",
|
||||
"favourite_topic_change_user_{$sUserId}"
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Возвращает число топиков в открытых блогах
|
||||
* из избранного по ID пользователя
|
||||
*
|
||||
* @param string $sUserId
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouriteOpenTopicsByUserId($sUserId) {
|
||||
if (false === ($data = $this->Cache_Get("topic_count_favourite_user_{$sUserId}_open"))) {
|
||||
$data = $this->oMapper->GetCountFavouriteOpenTopicsByUserId($sUserId);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"topic_count_favourite_user_{$sUserId}_open",
|
||||
array(
|
||||
"favourite_topic_change",
|
||||
"favourite_topic_change_user_{$sUserId}"
|
||||
),
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Возвращает число топиков в открытых блогах из избранного по ID пользователя
|
||||
*
|
||||
* @param string $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouriteOpenTopicsByUserId($sUserId) {
|
||||
if (false === ($data = $this->Cache_Get("topic_count_favourite_user_{$sUserId}_open"))) {
|
||||
$data = $this->oMapper->GetCountFavouriteOpenTopicsByUserId($sUserId);
|
||||
$this->Cache_Set(
|
||||
$data,
|
||||
"topic_count_favourite_user_{$sUserId}_open",
|
||||
array(
|
||||
"favourite_topic_change",
|
||||
"favourite_topic_change_user_{$sUserId}"
|
||||
),
|
||||
60*60*24*1
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Добавляет таргет в избранное
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function AddFavourite(ModuleFavourite_EntityFavourite $oFavourite) {
|
||||
|
@ -300,15 +303,15 @@ class ModuleFavourite extends Module {
|
|||
}
|
||||
$this->SetFavouriteTags($oFavourite);
|
||||
//чистим зависимые кеши
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$oFavourite->getTargetType()}_change_user_{$oFavourite->getUserId()}"));
|
||||
$this->Cache_Delete("favourite_{$oFavourite->getTargetType()}_{$oFavourite->getTargetId()}_{$oFavourite->getUserId()}");
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$oFavourite->getTargetType()}_change_user_{$oFavourite->getUserId()}"));
|
||||
$this->Cache_Delete("favourite_{$oFavourite->getTargetType()}_{$oFavourite->getTargetId()}_{$oFavourite->getUserId()}");
|
||||
return $this->oMapper->AddFavourite($oFavourite);
|
||||
}
|
||||
/**
|
||||
* Обновляет запись об избранном
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite
|
||||
* @return mixed
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateFavourite(ModuleFavourite_EntityFavourite $oFavourite) {
|
||||
if (!$oFavourite->getTags()) {
|
||||
|
@ -322,7 +325,8 @@ class ModuleFavourite extends Module {
|
|||
/**
|
||||
* Устанавливает список тегов для избранного
|
||||
*
|
||||
* @param $oFavourite
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @param bool $bAddNew Добавлять новые теги или нет
|
||||
*/
|
||||
public function SetFavouriteTags($oFavourite,$bAddNew=true) {
|
||||
/**
|
||||
|
@ -358,7 +362,7 @@ class ModuleFavourite extends Module {
|
|||
/**
|
||||
* Удаляет таргет из избранного
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteFavourite(ModuleFavourite_EntityFavourite $oFavourite) {
|
||||
|
@ -371,22 +375,22 @@ class ModuleFavourite extends Module {
|
|||
/**
|
||||
* Меняет параметры публикации у таргета
|
||||
*
|
||||
* @param string $sTargetId
|
||||
* @param string $sTargetType
|
||||
* @param string $iPublish
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iPublish Флаг публикации
|
||||
* @return bool
|
||||
*/
|
||||
public function SetFavouriteTargetPublish($aTargetId,$sTargetType,$iPublish) {
|
||||
if(!is_array($aTargetId)) $aTargetId = array($aTargetId);
|
||||
|
||||
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$sTargetType}_change"));
|
||||
return $this->oMapper->SetFavouriteTargetPublish($aTargetId,$sTargetType,$iPublish);
|
||||
}
|
||||
/**
|
||||
* Удаляет избранное по списку идентификаторов таргетов
|
||||
*
|
||||
* @param array|int $aTargetId
|
||||
* @param string $sTargetType
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteFavouriteByTargetId($aTargetId, $sTargetType) {
|
||||
|
@ -396,14 +400,14 @@ class ModuleFavourite extends Module {
|
|||
*/
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("favourite_{$sTargetType}_change"));
|
||||
$this->DeleteTagByTarget($aTargetId,$sTargetType);
|
||||
return $this->oMapper->DeleteFavouriteByTargetId($aTargetId,$sTargetType);
|
||||
return $this->oMapper->DeleteFavouriteByTargetId($aTargetId,$sTargetType);
|
||||
}
|
||||
/**
|
||||
* Удаление тегов по таргету
|
||||
*
|
||||
* @param $aTargetId
|
||||
* @param $sTargetType
|
||||
* @return mixed
|
||||
* @param array $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteTagByTarget($aTargetId,$sTargetType) {
|
||||
return $this->oMapper->DeleteTagByTarget($aTargetId,$sTargetType);
|
||||
|
@ -411,9 +415,9 @@ class ModuleFavourite extends Module {
|
|||
/**
|
||||
* Возвращает список тегов для объекта избранного
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $iTargetId
|
||||
* @return bool | array
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool|array
|
||||
*/
|
||||
public function GetTagsTarget($sTargetType,$iTargetId) {
|
||||
$sMethod = 'GetTagsTarget'.func_camelize($sTargetType);
|
||||
|
@ -425,11 +429,11 @@ class ModuleFavourite extends Module {
|
|||
/**
|
||||
* Возвращает наиболее часто используемые теги
|
||||
*
|
||||
* @param $iUserId
|
||||
* @param $sTargetType
|
||||
* @param $bIsUser
|
||||
* @param $iLimit
|
||||
* @return mixed
|
||||
* @param int $iUserId ID пользователя
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param bool $bIsUser Возвращает все теги ли только пользовательские
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetGroupTags($iUserId,$sTargetType,$bIsUser,$iLimit) {
|
||||
return $this->oMapper->GetGroupTags($iUserId,$sTargetType,$bIsUser,$iLimit);
|
||||
|
@ -437,10 +441,10 @@ class ModuleFavourite extends Module {
|
|||
/**
|
||||
* Возвращает список тегов по фильтру
|
||||
*
|
||||
* @param $aFilter
|
||||
* @param $aOrder
|
||||
* @param $iCurrPage
|
||||
* @param $iPerPage
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('collection'=>array,'count'=>int)
|
||||
*/
|
||||
public function GetTags($aFilter,$aOrder,$iCurrPage,$iPerPage) {
|
||||
|
@ -448,9 +452,10 @@ class ModuleFavourite extends Module {
|
|||
}
|
||||
/**
|
||||
* Возвращает список тегов для топика, название метода формируется автоматически из GetTagsTarget()
|
||||
* @see GetTagsTarget
|
||||
*
|
||||
* @param $iTargetId
|
||||
* @return bool | array
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool|array
|
||||
*/
|
||||
public function GetTagsTargetTopic($iTargetId) {
|
||||
if ($oTopic=$this->Topic_GetTopicById($iTargetId)) {
|
||||
|
|
|
@ -15,38 +15,88 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ModuleFavourite_EntityFavourite extends Entity
|
||||
{
|
||||
public function getTargetId() {
|
||||
return $this->_getDataOne('target_id');
|
||||
}
|
||||
public function getUserId() {
|
||||
return $this->_getDataOne('user_id');
|
||||
}
|
||||
public function getTargetPublish() {
|
||||
return $this->_getDataOne('target_publish');
|
||||
}
|
||||
public function getTargetType() {
|
||||
return $this->_getDataOne('target_type');
|
||||
}
|
||||
/**
|
||||
* Объект сущности избрнного
|
||||
*
|
||||
* @package modules.favourite
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleFavourite_EntityFavourite extends Entity {
|
||||
/**
|
||||
* Возвращает ID владельца
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTargetId() {
|
||||
return $this->_getDataOne('target_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает ID пользователя
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getUserId() {
|
||||
return $this->_getDataOne('user_id');
|
||||
}
|
||||
/**
|
||||
* Возвращает флаг публикации владельца
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTargetPublish() {
|
||||
return $this->_getDataOne('target_publish');
|
||||
}
|
||||
/**
|
||||
* Возвращает тип владельца
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTargetType() {
|
||||
return $this->_getDataOne('target_type');
|
||||
}
|
||||
/**
|
||||
* Возващает список тегов
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTagsArray() {
|
||||
if ($this->getTags()) {
|
||||
return explode(',',$this->getTags());
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Устанавливает ID владельца
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setTargetId($data) {
|
||||
$this->_aData['target_id']=$data;
|
||||
}
|
||||
public function setUserId($data) {
|
||||
$this->_aData['user_id']=$data;
|
||||
}
|
||||
public function setTargetPublish($data) {
|
||||
$this->_aData['target_publish']=$data;
|
||||
}
|
||||
public function setTargetType($data) {
|
||||
$this->_aData['target_type']=$data;
|
||||
}
|
||||
$this->_aData['target_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает ID пользователя
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setUserId($data) {
|
||||
$this->_aData['user_id']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает статус публикации для владельца
|
||||
*
|
||||
* @param int $data
|
||||
*/
|
||||
public function setTargetPublish($data) {
|
||||
$this->_aData['target_publish']=$data;
|
||||
}
|
||||
/**
|
||||
* Устанавливает тип владельца
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function setTargetType($data) {
|
||||
$this->_aData['target_type']=$data;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -15,6 +15,12 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект сущности тега для избранного
|
||||
*
|
||||
* @package modules.favourite
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleFavourite_EntityTag extends Entity {
|
||||
|
||||
}
|
||||
|
|
|
@ -15,15 +15,26 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
class ModuleFavourite_MapperFavourite extends Mapper {
|
||||
|
||||
/**
|
||||
* Объект маппера для работы с БД
|
||||
*
|
||||
* @package modules.favourite
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleFavourite_MapperFavourite extends Mapper {
|
||||
/**
|
||||
* Добавляет таргет в избранное
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function AddFavourite(ModuleFavourite_EntityFavourite $oFavourite) {
|
||||
$sql = "
|
||||
INSERT INTO ".Config::Get('db.table.favourite')."
|
||||
( target_id, target_type, user_id, tags )
|
||||
VALUES
|
||||
(?d, ?, ?d, ?)
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query(
|
||||
$sql,
|
||||
$oFavourite->getTargetId(),
|
||||
|
@ -32,10 +43,15 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
$oFavourite->getTags()
|
||||
)===0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновляет запись об избранном
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateFavourite(ModuleFavourite_EntityFavourite $oFavourite) {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.favourite')."
|
||||
|
@ -52,11 +68,18 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить список избранного по списку айдишников
|
||||
*
|
||||
* @param array $aArrayId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouritesByArray($aArrayId,$sTargetType,$sUserId) {
|
||||
if (!is_array($aArrayId) or count($aArrayId)==0) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
$sql = "SELECT *
|
||||
FROM ".Config::Get('db.table.favourite')."
|
||||
WHERE
|
||||
|
@ -70,10 +93,15 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
foreach ($aRows as $aRow) {
|
||||
$aFavourites[]=Engine::GetEntity('Favourite',$aRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aFavourites;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Удаляет таргет из избранного
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteFavourite(ModuleFavourite_EntityFavourite $oFavourite) {
|
||||
$sql = "
|
||||
DELETE FROM ".Config::Get('db.table.favourite')."
|
||||
|
@ -83,7 +111,7 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
target_id = ?d
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
";
|
||||
if ($this->oDb->query(
|
||||
$sql,
|
||||
$oFavourite->getUserId(),
|
||||
|
@ -91,10 +119,15 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
$oFavourite->getTargetType()
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет теги
|
||||
*
|
||||
* @param ModuleFavourite_EntityFavourite $oFavourite Объект избранного
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteTags($oFavourite) {
|
||||
$sql = "
|
||||
DELETE FROM ".Config::Get('db.table.favourite_tag')."
|
||||
|
@ -115,7 +148,12 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет тег
|
||||
*
|
||||
* @param ModuleFavourite_EntityTag $oTag Объект тега
|
||||
* @return bool
|
||||
*/
|
||||
public function AddTag($oTag) {
|
||||
$sql = "
|
||||
INSERT INTO ".Config::Get('db.table.favourite_tag')."
|
||||
|
@ -133,7 +171,14 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Меняет параметры публикации у таргета
|
||||
*
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iPublish Флаг публикации
|
||||
* @return bool
|
||||
*/
|
||||
public function SetFavouriteTargetPublish($aTargetId,$sTargetType,$iPublish) {
|
||||
$sql = "
|
||||
UPDATE ".Config::Get('db.table.favourite')."
|
||||
|
@ -143,11 +188,21 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
target_id IN(?a)
|
||||
AND
|
||||
target_type = ?
|
||||
";
|
||||
return $this->oDb->query($sql,$iPublish,$aTargetId,$sTargetType);
|
||||
}
|
||||
|
||||
public function GetFavouritesByUserId($sUserId,$sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
|
||||
";
|
||||
return $this->oDb->query($sql,$iPublish,$aTargetId,$sTargetType);
|
||||
}
|
||||
/**
|
||||
* Получает список таргетов из избранного
|
||||
*
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @param array $aExcludeTarget Список ID владельцев для исклчения
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouritesByUserId($sUserId,$sTargetType,&$iCount,$iCurrPage,$iPerPage,$aExcludeTarget=array()) {
|
||||
$sql = "
|
||||
SELECT target_id
|
||||
FROM ".Config::Get('db.table.favourite')."
|
||||
|
@ -160,24 +215,31 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
{ AND target_id NOT IN (?a) }
|
||||
ORDER BY target_id DESC
|
||||
LIMIT ?d, ?d ";
|
||||
|
||||
$aFavourites=array();
|
||||
|
||||
$aFavourites=array();
|
||||
if ($aRows=$this->oDb->selectPage(
|
||||
$iCount,
|
||||
$sql,
|
||||
$sUserId,
|
||||
$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
||||
($iCurrPage-1)*$iPerPage,
|
||||
$iPerPage
|
||||
$iCount,
|
||||
$sql,
|
||||
$sUserId,
|
||||
$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP),
|
||||
($iCurrPage-1)*$iPerPage,
|
||||
$iPerPage
|
||||
)) {
|
||||
foreach ($aRows as $aFavourite) {
|
||||
$aFavourites[]=$aFavourite['target_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aFavourites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает число таргетов определенного типа в избранном по ID пользователя
|
||||
*
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array $aExcludeTarget Список ID владельцев для исклчения
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouritesByUserId($sUserId,$sTargetType,$aExcludeTarget) {
|
||||
$sql = "SELECT
|
||||
count(target_id) as count
|
||||
|
@ -192,16 +254,25 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
{ AND target_id NOT IN (?a) }
|
||||
;";
|
||||
return ( $aRow=$this->oDb->selectRow(
|
||||
$sql,$sUserId,
|
||||
$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP)
|
||||
)
|
||||
)
|
||||
? $aRow['count']
|
||||
: false;
|
||||
}
|
||||
|
||||
public function GetFavouriteOpenCommentsByUserId($sUserId,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$sql,$sUserId,
|
||||
$sTargetType,
|
||||
(count($aExcludeTarget) ? $aExcludeTarget : DBSIMPLE_SKIP)
|
||||
)
|
||||
)
|
||||
? $aRow['count']
|
||||
: false;
|
||||
}
|
||||
/**
|
||||
* Получает список комментариев к записям открытых блогов
|
||||
* из избранного указанного пользователя
|
||||
*
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteOpenCommentsByUserId($sUserId,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$sql = "
|
||||
SELECT f.target_id
|
||||
FROM
|
||||
|
@ -225,19 +296,24 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
b.blog_type IN ('open', 'personal')
|
||||
ORDER BY target_id DESC
|
||||
LIMIT ?d, ?d ";
|
||||
|
||||
$aFavourites=array();
|
||||
|
||||
$aFavourites=array();
|
||||
if ($aRows=$this->oDb->selectPage(
|
||||
$iCount, $sql, $sUserId,
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
$iCount, $sql, $sUserId,
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
)) {
|
||||
foreach ($aRows as $aFavourite) {
|
||||
$aFavourites[]=$aFavourite['target_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aFavourites;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Возвращает число комментариев к открытым блогам в избранном по ID пользователя
|
||||
*
|
||||
* @param int $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouriteOpenCommentsByUserId($sUserId) {
|
||||
$sql = "SELECT
|
||||
count(f.target_id) as count
|
||||
|
@ -260,13 +336,22 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
t.blog_id = b.blog_id
|
||||
AND
|
||||
b.blog_type IN ('open', 'personal')
|
||||
;";
|
||||
;";
|
||||
return ( $aRow=$this->oDb->selectRow($sql,$sUserId) )
|
||||
? $aRow['count']
|
||||
: false;
|
||||
? $aRow['count']
|
||||
: false;
|
||||
}
|
||||
|
||||
public function GetFavouriteOpenTopicsByUserId($sUserId,&$iCount,$iCurrPage,$iPerPage) {
|
||||
/**
|
||||
* Получает список топиков из открытых блогов
|
||||
* из избранного указанного пользователя
|
||||
*
|
||||
* @param int $sUserId ID пользователя
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetFavouriteOpenTopicsByUserId($sUserId,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$sql = "
|
||||
SELECT f.target_id
|
||||
FROM
|
||||
|
@ -287,19 +372,24 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
b.blog_type IN ('open', 'personal')
|
||||
ORDER BY target_id DESC
|
||||
LIMIT ?d, ?d ";
|
||||
|
||||
$aFavourites=array();
|
||||
|
||||
$aFavourites=array();
|
||||
if ($aRows=$this->oDb->selectPage(
|
||||
$iCount, $sql, $sUserId,
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
$iCount, $sql, $sUserId,
|
||||
($iCurrPage-1)*$iPerPage, $iPerPage
|
||||
)) {
|
||||
foreach ($aRows as $aFavourite) {
|
||||
$aFavourites[]=$aFavourite['target_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aFavourites;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Возвращает число топиков в открытых блогах из избранного по ID пользователя
|
||||
*
|
||||
* @param string $sUserId ID пользователя
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountFavouriteOpenTopicsByUserId($sUserId) {
|
||||
$sql = "SELECT
|
||||
count(f.target_id) as count
|
||||
|
@ -319,25 +409,37 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
t.blog_id = b.blog_id
|
||||
AND
|
||||
b.blog_type IN ('open', 'personal')
|
||||
;";
|
||||
;";
|
||||
return ( $aRow=$this->oDb->selectRow($sql,$sUserId) )
|
||||
? $aRow['count']
|
||||
: false;
|
||||
}
|
||||
|
||||
? $aRow['count']
|
||||
: false;
|
||||
}
|
||||
/**
|
||||
* Удаляет избранное по списку идентификаторов таргетов
|
||||
*
|
||||
* @param array|int $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteFavouriteByTargetId($aTargetId,$sTargetType) {
|
||||
$sql = "
|
||||
DELETE FROM ".Config::Get('db.table.favourite')."
|
||||
WHERE
|
||||
target_id IN(?a)
|
||||
AND
|
||||
target_type = ? ";
|
||||
target_type = ? ";
|
||||
if ($this->oDb->query($sql,$aTargetId,$sTargetType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаление тегов по таргету
|
||||
*
|
||||
* @param array $aTargetId Список ID владельцев
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteTagByTarget($aTargetId,$sTargetType) {
|
||||
$sql = "
|
||||
DELETE FROM ".Config::Get('db.table.favourite_tag')."
|
||||
|
@ -351,7 +453,15 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает наиболее часто используемые теги
|
||||
*
|
||||
* @param int $iUserId ID пользователя
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param bool $bIsUser Возвращает все теги ли только пользовательские
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetGroupTags($iUserId,$sTargetType,$bIsUser,$iLimit) {
|
||||
$sql = "SELECT
|
||||
text,
|
||||
|
@ -382,7 +492,16 @@ class ModuleFavourite_MapperFavourite extends Mapper {
|
|||
}
|
||||
return $aReturnSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список тегов по фильтру
|
||||
*
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetTags($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$aOrderAllow=array('target_id','user_id','is_user');
|
||||
$sOrder='';
|
||||
|
|
|
@ -20,10 +20,22 @@
|
|||
* Терминология:
|
||||
* объект - который привязываем к гео-объекту
|
||||
* гео-объект - географический объект(страна/регион/город)
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo extends Module {
|
||||
|
||||
/**
|
||||
* Объект маппера
|
||||
*
|
||||
* @var ModuleGeo_MapperGeo
|
||||
*/
|
||||
protected $oMapper;
|
||||
/**
|
||||
* Объект текущего пользователя
|
||||
*
|
||||
* @var ModuleUser_EntityUser|null
|
||||
*/
|
||||
protected $oUserCurrent;
|
||||
/**
|
||||
* Список доступных типов объектов
|
||||
|
@ -44,26 +56,28 @@ class ModuleGeo extends Module {
|
|||
'region',
|
||||
'city',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Инициализация
|
||||
*
|
||||
*/
|
||||
public function Init() {
|
||||
public function Init() {
|
||||
$this->oMapper=Engine::GetMapper(__CLASS__);
|
||||
$this->oUserCurrent=$this->User_GetUserCurrent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список типов объектов для облаты
|
||||
* Возвращает список типов объектов
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetTargetTypes() {
|
||||
return $this->aTargetTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет в разрешенные новый тип
|
||||
* @param unknown_type $sTargetType
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array $aParams Параметры
|
||||
* @return bool
|
||||
*/
|
||||
public function AddTargetType($sTargetType,$aParams=array()) {
|
||||
if (!array_key_exists($sTargetType,$this->aTargetTypes)) {
|
||||
|
@ -72,32 +86,30 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет разрешен ли данный тип
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function IsAllowTargetType($sTargetType) {
|
||||
return in_array($sTargetType,array_keys($this->aTargetTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет разрешен ли данный гео-тип
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param string $sGeoType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function IsAllowGeoType($sGeoType) {
|
||||
return in_array($sGeoType,$this->aGeoTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка объекта
|
||||
*
|
||||
* @param string $sTargetType
|
||||
* @param int $iTargetId
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function CheckTarget($sTargetType,$iTargetId) {
|
||||
if (!$this->IsAllowTargetType($sTargetType)) {
|
||||
|
@ -109,11 +121,10 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка на возможность нескольких связей
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @return bool
|
||||
*/
|
||||
public function IsAllowTargetMulti($sTargetType) {
|
||||
|
@ -124,12 +135,11 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет связь объекта с гео-объектом в БД
|
||||
*
|
||||
* @param $oTarget
|
||||
* @return ModuleGeo_EntityTarget | bool
|
||||
* @param ModuleGeo_EntityTarget $oTarget Объект связи с владельцем
|
||||
* @return ModuleGeo_EntityTarget|bool
|
||||
*/
|
||||
public function AddTarget($oTarget) {
|
||||
if ($this->oMapper->AddTarget($oTarget)) {
|
||||
|
@ -137,13 +147,12 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Создание связи
|
||||
*
|
||||
* @param $oGeoObject
|
||||
* @param $sTargetType
|
||||
* @param $iTargetId
|
||||
* @param ModuleGeo_EntityGeo $oGeoObject
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool|ModuleGeo_EntityTarget
|
||||
*/
|
||||
public function CreateTarget($oGeoObject,$sTargetType,$iTargetId) {
|
||||
|
@ -194,25 +203,23 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return $this->AddTarget($oTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список связей по фильтру
|
||||
*
|
||||
* @param $aFilter
|
||||
* @param $iCurrPage
|
||||
* @param $iPerPage
|
||||
* @return array
|
||||
* @param array $aFilter Фильтр
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('collection'=>array,'count'=>int)
|
||||
*/
|
||||
public function GetTargets($aFilter,$iCurrPage,$iPerPage) {
|
||||
return array('collection'=>$this->oMapper->GetTargets($aFilter,$iCount,$iCurrPage,$iPerPage),'count'=>$iCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает первый объект связи по объекту
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $iTargetId
|
||||
* @return null
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return null|ModuleGeo_EntityTarget
|
||||
*/
|
||||
public function GetTargetByTarget($sTargetType,$iTargetId) {
|
||||
$aTargets=$this->GetTargets(array('target_type'=>$sTargetType,'target_id'=>$iTargetId),1,1);
|
||||
|
@ -224,8 +231,8 @@ class ModuleGeo extends Module {
|
|||
/**
|
||||
* Возвращает список связей для списка объектов одного типа.
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $aTargetId
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param array $aTargetId Список ID владельцев
|
||||
* @return array В качестве ключей используется ID объекта, в качестве значений массив связей этого объекта
|
||||
*/
|
||||
public function GetTargetsByTargetArray($sTargetType,$aTargetId) {
|
||||
|
@ -247,68 +254,63 @@ class ModuleGeo extends Module {
|
|||
/**
|
||||
* Удаляет связи по фильтру
|
||||
*
|
||||
* @param $aFilter
|
||||
* @return mixed
|
||||
* @param array $aFilter Фильтр
|
||||
* @return bool|int
|
||||
*/
|
||||
public function DeleteTargets($aFilter) {
|
||||
return $this->oMapper->DeleteTargets($aFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаление всех связей объекта
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $iTargetId
|
||||
* @return mixed
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return bool|int
|
||||
*/
|
||||
public function DeleteTargetsByTarget($sTargetType,$iTargetId) {
|
||||
return $this->DeleteTargets(array('target_type'=>$sTargetType,'target_id'=>$iTargetId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список стран по фильтру
|
||||
*
|
||||
* @param $aFilter
|
||||
* @param $aOrder
|
||||
* @param $iCurrPage
|
||||
* @param $iPerPage
|
||||
* @return array
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('collection'=>array,'count'=>int)
|
||||
*/
|
||||
public function GetCountries($aFilter,$aOrder,$iCurrPage,$iPerPage) {
|
||||
return array('collection'=>$this->oMapper->GetCountries($aFilter,$aOrder,$iCount,$iCurrPage,$iPerPage),'count'=>$iCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список регионов по фильтру
|
||||
*
|
||||
* @param $aFilter
|
||||
* @param $aOrder
|
||||
* @param $iCurrPage
|
||||
* @param $iPerPage
|
||||
* @return array
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('collection'=>array,'count'=>int)
|
||||
*/
|
||||
public function GetRegions($aFilter,$aOrder,$iCurrPage,$iPerPage) {
|
||||
return array('collection'=>$this->oMapper->GetRegions($aFilter,$aOrder,$iCount,$iCurrPage,$iPerPage),'count'=>$iCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список городов по фильтру
|
||||
*
|
||||
* @param $aFilter
|
||||
* @param $aOrder
|
||||
* @param $iCurrPage
|
||||
* @param $iPerPage
|
||||
* @return array
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array('collection'=>array,'count'=>int)
|
||||
*/
|
||||
public function GetCities($aFilter,$aOrder,$iCurrPage,$iPerPage) {
|
||||
return array('collection'=>$this->oMapper->GetCities($aFilter,$aOrder,$iCount,$iCurrPage,$iPerPage),'count'=>$iCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает страну по ID
|
||||
*
|
||||
* @param $iId
|
||||
* @return ModuleGeo_EntityCountry
|
||||
* @param int $iId ID страны
|
||||
* @return ModuleGeo_EntityCountry|null
|
||||
*/
|
||||
public function GetCountryById($iId) {
|
||||
$aRes=$this->GetCountries(array('id'=>$iId),array(),1,1);
|
||||
|
@ -317,12 +319,11 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает регион по ID
|
||||
*
|
||||
* @param $iId
|
||||
* @return ModuleGeo_EntityRegion
|
||||
* @param int $iId ID региона
|
||||
* @return ModuleGeo_EntityRegion|null
|
||||
*/
|
||||
public function GetRegionById($iId) {
|
||||
$aRes=$this->GetRegions(array('id'=>$iId),array(),1,1);
|
||||
|
@ -331,12 +332,11 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает регион по ID
|
||||
*
|
||||
* @param $iId
|
||||
* @return ModuleGeo_EntityCity
|
||||
* @param int $iId ID города
|
||||
* @return ModuleGeo_EntityCity|null
|
||||
*/
|
||||
public function GetCityById($iId) {
|
||||
$aRes=$this->GetCities(array('id'=>$iId),array(),1,1);
|
||||
|
@ -345,12 +345,12 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает гео-объект
|
||||
*
|
||||
* @param $sType
|
||||
* @param $iId
|
||||
* @param string $sType Тип гео-объекта
|
||||
* @param int $iId ID гео-объекта
|
||||
* @return ModuleGeo_EntityGeo|null
|
||||
*/
|
||||
public function GetGeoObject($sType,$iId) {
|
||||
$sType=strtolower($sType);
|
||||
|
@ -371,12 +371,11 @@ class ModuleGeo extends Module {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает первый гео-объект для объекта
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $iTargetId
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iTargetId ID владельца
|
||||
* @return ModuleGeo_EntityCity|ModuleGeo_EntityCountry|ModuleGeo_EntityRegion|null
|
||||
*/
|
||||
public function GetGeoObjectByTarget($sTargetType,$iTargetId) {
|
||||
|
@ -387,34 +386,32 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список стран сгруппированных по количеству использований в данном типе объектов
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $iLimit
|
||||
* @return mixed
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetGroupCountriesByTargetType($sTargetType,$iLimit) {
|
||||
return $this->oMapper->GetGroupCountriesByTargetType($sTargetType,$iLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список городов сгруппированных по количеству использований в данном типе объектов
|
||||
*
|
||||
* @param $sTargetType
|
||||
* @param $iLimit
|
||||
* @return mixed
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetGroupCitiesByTargetType($sTargetType,$iLimit) {
|
||||
return $this->oMapper->GetGroupCitiesByTargetType($sTargetType,$iLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка объекта с типом "user"
|
||||
* Название метода формируется автоматически
|
||||
*
|
||||
* @param int $iTargetId
|
||||
* @param int $iTargetId ID пользователя
|
||||
* @return bool
|
||||
*/
|
||||
public function CheckTargetUser($iTargetId) {
|
||||
if ($oUser=$this->User_GetUserById($iTargetId)) {
|
||||
|
@ -422,6 +419,5 @@ class ModuleGeo extends Module {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -15,7 +15,13 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект сущности города
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo_EntityCity extends ModuleGeo_EntityGeo {
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -15,7 +15,13 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект сущности страны
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo_EntityCountry extends ModuleGeo_EntityGeo {
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -15,6 +15,12 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект сущности гео-объекта
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo_EntityGeo extends Entity {
|
||||
|
||||
/**
|
||||
|
@ -39,7 +45,6 @@ class ModuleGeo_EntityGeo extends Entity {
|
|||
}
|
||||
return $sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает тип гео-объекта
|
||||
*
|
||||
|
@ -55,7 +60,6 @@ class ModuleGeo_EntityGeo extends Entity {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает гео-объект страны
|
||||
*
|
||||
|
@ -74,7 +78,6 @@ class ModuleGeo_EntityGeo extends Entity {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает гео-объект региона
|
||||
*
|
||||
|
@ -93,7 +96,6 @@ class ModuleGeo_EntityGeo extends Entity {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает гео-объект города
|
||||
*
|
||||
|
@ -112,6 +114,5 @@ class ModuleGeo_EntityGeo extends Entity {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -15,7 +15,13 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект сущности региона
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo_EntityRegion extends ModuleGeo_EntityGeo {
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -15,6 +15,12 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект связи гео-объекта с владельцем
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo_EntityTarget extends Entity {
|
||||
|
||||
}
|
||||
|
|
|
@ -15,16 +15,35 @@
|
|||
---------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Объект маппера для работы с БД
|
||||
*
|
||||
* @package modules.geo
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleGeo_MapperGeo extends Mapper {
|
||||
|
||||
/**
|
||||
* Добавляет связь объекта с гео-объектом в БД
|
||||
*
|
||||
* @param ModuleGeo_EntityTarget $oTarget Объект связи с владельцем
|
||||
* @return ModuleGeo_EntityTarget|bool
|
||||
*/
|
||||
public function AddTarget($oTarget) {
|
||||
$sql = "INSERT INTO ".Config::Get('db.table.geo_target')." SET ?a ";
|
||||
if ($this->oDb->query($sql,$oTarget->_getData())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список связей по фильтру
|
||||
*
|
||||
* @param array $aFilter Фильтр
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetTargets($aFilter,&$iCount,$iCurrPage,$iPerPage) {
|
||||
if (isset($aFilter['target_id']) and !is_array($aFilter['target_id'])) {
|
||||
$aFilter['target_id']=array($aFilter['target_id']);
|
||||
|
@ -64,7 +83,13 @@ class ModuleGeo_MapperGeo extends Mapper {
|
|||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список стран сгруппированных по количеству использований в данном типе объектов
|
||||
*
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetGroupCountriesByTargetType($sTargetType,$iLimit) {
|
||||
$sql = "
|
||||
SELECT
|
||||
|
@ -90,7 +115,13 @@ class ModuleGeo_MapperGeo extends Mapper {
|
|||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список городов сгруппированных по количеству использований в данном типе объектов
|
||||
*
|
||||
* @param string $sTargetType Тип владельца
|
||||
* @param int $iLimit Количество элементов
|
||||
* @return array
|
||||
*/
|
||||
public function GetGroupCitiesByTargetType($sTargetType,$iLimit) {
|
||||
$sql = "
|
||||
SELECT
|
||||
|
@ -116,7 +147,12 @@ class ModuleGeo_MapperGeo extends Mapper {
|
|||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет связи по фильтру
|
||||
*
|
||||
* @param array $aFilter Фильтр
|
||||
* @return bool|int
|
||||
*/
|
||||
public function DeleteTargets($aFilter) {
|
||||
if (!$aFilter) {
|
||||
return false;
|
||||
|
@ -144,7 +180,16 @@ class ModuleGeo_MapperGeo extends Mapper {
|
|||
isset($aFilter['city_id']) ? $aFilter['city_id'] : DBSIMPLE_SKIP
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список стран по фильтру
|
||||
*
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetCountries($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$aOrderAllow=array('id','name_ru','name_en','sort');
|
||||
$sOrder='';
|
||||
|
@ -192,7 +237,16 @@ class ModuleGeo_MapperGeo extends Mapper {
|
|||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список стран по фильтру
|
||||
*
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetRegions($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$aOrderAllow=array('id','name_ru','name_en','sort','country_id');
|
||||
$sOrder='';
|
||||
|
@ -244,7 +298,16 @@ class ModuleGeo_MapperGeo extends Mapper {
|
|||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список стран по фильтру
|
||||
*
|
||||
* @param array $aFilter Фильтр
|
||||
* @param array $aOrder Сортировка
|
||||
* @param int $iCount Возвращает количество элементов
|
||||
* @param int $iCurrPage Номер страницы
|
||||
* @param int $iPerPage Количество элементов на страницу
|
||||
* @return array
|
||||
*/
|
||||
public function GetCities($aFilter,$aOrder,&$iCount,$iCurrPage,$iPerPage) {
|
||||
$aOrderAllow=array('id','name_ru','name_en','sort','country_id','region_id');
|
||||
$sOrder='';
|
||||
|
|
Loading…
Reference in a new issue