1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00

Доработка уведомлений о новом топике #587

This commit is contained in:
Mzhelskiy Maxim 2015-01-29 15:33:08 +07:00
parent 2fcd0e5402
commit b795b5cb45
5 changed files with 88 additions and 60 deletions

View file

@ -421,7 +421,7 @@ class ActionContent extends Action
* Рассылаем о новом топике подписчикам блога
*/
if ($bSendNotify) {
$this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $oTopic->getUser());
$this->Topic_SendNotifyTopicNew($oTopic, $oTopic->getUser());
}
if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId() != $oTopic->getUserId()) {
$sUrlRedirect = $oBlog->getUrlFull();
@ -562,7 +562,7 @@ class ActionContent extends Action
* Делаем рассылку спама всем, кто состоит в этом блоге
*/
if ($oTopic->getPublish() == 1 and $oBlog->getType() != 'personal') {
$this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $oUser);
$this->Topic_SendNotifyTopicNew($oTopic, $oUser);
}
/**
* Добавляем событие в ленту

View file

@ -495,7 +495,7 @@ class ModuleBlog extends Module
public function GetBlogsByType($sType)
{
$aBlogs=$this->GetBlogsByFilter(array('type' => $sType), array('blog_title'=>'asc'), 1, 100);
$aBlogs = $this->GetBlogsByFilter(array('type' => $sType), array('blog_title' => 'asc'), 1, 100);
return $aBlogs['collection'];
}
@ -513,14 +513,14 @@ class ModuleBlog extends Module
* Блоги в которых состоит
*/
$aBlogs = $this->GetBlogsByFilter(array(
'type' => $sType,
'roles_user_id' => $iUserId,
'roles' => array(
self::BLOG_USER_ROLE_USER,
self::BLOG_USER_ROLE_MODERATOR,
self::BLOG_USER_ROLE_ADMINISTRATOR
)
), array(), 1, 100);
'type' => $sType,
'roles_user_id' => $iUserId,
'roles' => array(
self::BLOG_USER_ROLE_USER,
self::BLOG_USER_ROLE_MODERATOR,
self::BLOG_USER_ROLE_ADMINISTRATOR
)
), array(), 1, 100);
foreach ($aBlogs['collection'] as $oBlog) {
$aResult[$oBlog->getId()] = $oBlog;
}
@ -540,16 +540,19 @@ class ModuleBlog extends Module
* Получает список пользователей блога.
* Если роль не указана, то считаем что поиск производиться по положительным значениям (статусом выше GUEST).
*
* @param int $sBlogId ID блога
* @param int|array $aBlogId ID блога или список ID блогов
* @param int|null $iRole Роль пользователей в блоге
* @param int $iPage Номер текущей страницы
* @param int $iPerPage Количество элементов на одну страницу
* @return array
*/
public function GetBlogUsersByBlogId($sBlogId, $iRole = null, $iPage = 1, $iPerPage = 100)
public function GetBlogUsersByBlogId($aBlogId, $iRole = null, $iPage = 1, $iPerPage = 100)
{
if (!is_array($aBlogId)) {
$aBlogId = array($aBlogId);
}
$aFilter = array(
'blog_id' => $sBlogId,
'blog_id' => $aBlogId,
);
if ($iRole !== null) {
$aFilter['user_role'] = $iRole;
@ -560,8 +563,11 @@ class ModuleBlog extends Module
'collection' => $this->oMapperBlog->GetBlogUsers($aFilter, $iCount, $iPage, $iPerPage),
'count' => $iCount
);
$this->Cache_Set($data, "blog_relation_user_by_filter_{$s}_{$iPage}_{$iPerPage}",
array("blog_relation_change_blog_{$sBlogId}"), 60 * 60 * 24 * 3);
$aTags = array();
foreach ($aBlogId as $iBlogId) {
$aTags[] = "blog_relation_change_blog_{$iBlogId}";
}
$this->Cache_Set($data, "blog_relation_user_by_filter_{$s}_{$iPage}_{$iPerPage}", $aTags, 60 * 60 * 24 * 3);
}
/**
* Достаем дополнительные данные, для этого формируем список юзеров и делаем мульти-запрос
@ -572,7 +578,7 @@ class ModuleBlog extends Module
$aUserId[] = $oBlogUser->getUserId();
}
$aUsers = $this->User_GetUsersAdditionalData($aUserId);
$aBlogs = $this->Blog_GetBlogsAdditionalData($sBlogId);
$aBlogs = $this->Blog_GetBlogsAdditionalData($aBlogId);
$aResults = array();
foreach ($data['collection'] as $oBlogUser) {
@ -1118,10 +1124,10 @@ class ModuleBlog extends Module
public function RecalculateCountTopicByBlogId($aBlogIds)
{
if (!is_array($aBlogIds)) {
$aBlogIds=array($aBlogIds);
$aBlogIds = array($aBlogIds);
}
if ($aBlogIds) {
foreach($aBlogIds as $iBlogId) {
foreach ($aBlogIds as $iBlogId) {
//чистим зависимые кеши
$this->oMapperBlog->RecalculateCountTopic($iBlogId);
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("blog_update_{$iBlogId}"));

View file

@ -207,43 +207,49 @@ class ModuleBlog_MapperBlog extends Mapper
*/
public function GetBlogUsers($aFilter, &$iCount = null, $iCurrPage = null, $iPerPage = null)
{
$sWhere = ' 1=1 ';
if (isset($aFilter['blog_id'])) {
$sWhere .= " AND bu.blog_id = " . (int)$aFilter['blog_id'];
if (isset($aFilter['blog_id']) and !is_array($aFilter['blog_id'])) {
$aFilter['blog_id']=array($aFilter['blog_id']);
}
if (isset($aFilter['user_id'])) {
$sWhere .= " AND bu.user_id = " . (int)$aFilter['user_id'];
if (isset($aFilter['user_role']) and !is_array($aFilter['user_role'])) {
$aFilter['user_role']=array($aFilter['user_role']);
}
if (isset($aFilter['user_role'])) {
if (!is_array($aFilter['user_role'])) {
$aFilter['user_role'] = array($aFilter['user_role']);
}
$sWhere .= " AND bu.user_role IN ('" . join("', '", $aFilter['user_role']) . "')";
} else {
$sWhere .= " AND bu.user_role>" . ModuleBlog::BLOG_USER_ROLE_GUEST;
if (is_null($iCurrPage)) {
$iCurrPage=1;
}
if (is_null($iPerPage)) {
$iPerPage=1000;
}
$sql = "SELECT
bu.*
FROM
bu.*
FROM
" . Config::Get('db.table.blog_user') . " as bu
WHERE
" . $sWhere . " ";
WHERE
1=1
{ AND bu.blog_id IN (?a) }
{ AND bu.user_id = ?d }
{ AND bu.user_role IN (?a) }
{ AND bu.user_role > ?d }
if (is_null($iCurrPage)) {
$aRows = $this->oDb->select($sql);
} else {
$sql .= " LIMIT ?d, ?d ";
$aRows = $this->oDb->selectPage($iCount, $sql, ($iCurrPage - 1) * $iPerPage, $iPerPage);
}
LIMIT ?d, ?d
";
$aBlogUsers = array();
if ($aRows) {
foreach ($aRows as $aUser) {
$aBlogUsers[] = Engine::GetEntity('Blog_BlogUser', $aUser);
$aResult = array();
if ($aRows = $this->oDb->selectPage($iCount, $sql,
(isset($aFilter['blog_id']) and count($aFilter['blog_id'])) ? $aFilter['blog_id'] : DBSIMPLE_SKIP,
isset($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP,
(isset($aFilter['user_role']) and count($aFilter['user_role'])) ? $aFilter['user_role'] : DBSIMPLE_SKIP,
!isset($aFilter['user_role']) ? ModuleBlog::BLOG_USER_ROLE_GUEST : DBSIMPLE_SKIP,
($iCurrPage - 1) * $iPerPage, $iPerPage
)
) {
foreach ($aRows as $aRow) {
$aResult[] = Engine::GetEntity('Blog_BlogUser', $aRow);
}
}
return $aBlogUsers;
return $aResult;
}
/**

View file

@ -1583,26 +1583,42 @@ class ModuleTopic extends Module
}
/**
* Рассылает уведомления о новом топике подписчикам блога
* Рассылает уведомления о новом топике подписчикам блогов
*
* @param ModuleBlog_EntityBlog $oBlog Объект блога
* @param ModuleTopic_EntityTopic $oTopic Объект топика
* @param ModuleUser_EntityUser $oUserTopic Объект пользователя
*/
public function SendNotifyTopicNew($oBlog, $oTopic, $oUserTopic)
public function SendNotifyTopicNew($oTopic, $oUserTopic)
{
$aBlogUsersResult = $this->Blog_GetBlogUsersByBlogId($oBlog->getId(), null,
null); // нужно постранично пробегаться по всем
$aBlogUsers = $aBlogUsersResult['collection'];
foreach ($aBlogUsers as $oBlogUser) {
if ($oBlogUser->getUserId() == $oUserTopic->getId()) {
continue;
/**
* Сначала отправляем подписчикам блогов
*/
$iPage = 1;
$aBlogs = $oTopic->getBlogsId();
$aUserIdSend = array($oUserTopic->getId());
while ($aBlogUsersResult = $this->Blog_GetBlogUsersByBlogId($aBlogs, null, $iPage,
50) and $aBlogUsersResult['collection']) {
$aBlogUsers = $aBlogUsersResult['collection'];
foreach ($aBlogUsers as $oBlogUser) {
if (in_array($oBlogUser->getUserId(), $aUserIdSend)) {
continue;
}
$this->Notify_SendTopicNewToSubscribeBlog($oBlogUser->getUser(), $oTopic, $oBlogUser->getBlog(),
$oUserTopic);
$aUserIdSend[] = $oBlogUser->getUserId();
}
$this->Notify_SendTopicNewToSubscribeBlog($oBlogUser->getUser(), $oTopic, $oBlog, $oUserTopic);
$iPage++;
}
//отправляем создателю блога
if ($oBlog->getOwnerId() != $oUserTopic->getId()) {
$this->Notify_SendTopicNewToSubscribeBlog($oBlog->getOwner(), $oTopic, $oBlog, $oUserTopic);
/**
* Теперь отправляем авторам блогов
*/
$aBlogs = $this->Blog_GetBlogsAdditionalData($aBlogs);
foreach ($aBlogs as $oBlog) {
if ($oBlog->getOwnerId() != $oUserTopic->getId() and !in_array($oBlog->getOwnerId(), $aUserIdSend)) {
$this->Notify_SendTopicNewToSubscribeBlog($oBlog->getOwner(), $oTopic, $oBlog, $oUserTopic);
$aUserIdSend[] = $oBlog->getOwnerId();
}
}
}

@ -1 +1 @@
Subproject commit 0d4967faa800171b82cc82ec4f11f4eef2464272
Subproject commit 810dcd94245088816cb94284b3ec1a837421757b