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

Доработка Ленты - отображения закрытых блогов

This commit is contained in:
Mzhelskiy Maxim 2014-12-01 14:09:09 +07:00
parent e59218c3a7
commit 3fa8097a8a
4 changed files with 48 additions and 42 deletions

View file

@ -1405,22 +1405,6 @@ class ActionBlog extends Action
if ($oBlog->getOwnerId() != $this->oUserCurrent->getId() and !$this->oUserCurrent->isAdministrator() and !$bIsAdministratorBlog) {
return $this->EventErrorDebug();
}
/**
* Получаем список пользователей блога (любого статуса)
* todo: Это полный АХТУНГ - исправить!
*/
$aBlogUsersResult = $this->Blog_GetBlogUsersByBlogId(
$oBlog->getId(),
array(
ModuleBlog::BLOG_USER_ROLE_BAN,
ModuleBlog::BLOG_USER_ROLE_REJECT,
ModuleBlog::BLOG_USER_ROLE_INVITE,
ModuleBlog::BLOG_USER_ROLE_USER,
ModuleBlog::BLOG_USER_ROLE_MODERATOR,
ModuleBlog::BLOG_USER_ROLE_ADMINISTRATOR
), null // пока костылем
);
$aBlogUsers = $aBlogUsersResult['collection'];
$aResult = array();
/**
@ -1431,18 +1415,6 @@ class ActionBlog extends Action
if ($sUser == '') {
continue;
}
/**
* Если пользователь пытается добавить инвайт
* самому себе, возвращаем ошибку
*/
if (strtolower($sUser) == strtolower($this->oUserCurrent->getLogin())) {
$aResult[] = array(
'bStateError' => true,
'sMsgTitle' => $this->Lang_Get('error'),
'sMsg' => $this->Lang_Get('blog.invite.notices.add_self')
);
continue;
}
/**
* Если пользователь не найден или неактивен,
* возвращаем ошибку
@ -1457,8 +1429,19 @@ class ActionBlog extends Action
);
continue;
}
/**
* Запрещаем отправлять инвайт создателю блога
*/
if ($oUser->getId() == $oBlog->getOwnerId()) {
$aResult[] = array(
'bStateError' => true,
'sMsgTitle' => $this->Lang_Get('error'),
'sMsg' => $this->Lang_Get('blog.invite.notices.add_self')
);
continue;
}
if (!isset($aBlogUsers[$oUser->getId()])) {
if (!($oBlogUser = $this->Blog_GetBlogUserByBlogIdAndUserId($oBlog->getId(), $oUser->getId()))) {
/**
* Создаем нового блог-пользователя со статусом INVITED
*/
@ -1498,15 +1481,15 @@ class ActionBlog extends Action
* возвращаем ошибку (сначала определяя ее точный текст)
*/
switch (true) {
case ($aBlogUsers[$oUser->getId()]->getUserRole() == ModuleBlog::BLOG_USER_ROLE_INVITE):
case ($oBlogUser->getUserRole() == ModuleBlog::BLOG_USER_ROLE_INVITE):
$sErrorMessage = $this->Lang_Get('blog.invite.notices.already_invited',
array('login' => htmlspecialchars($sUser)));
break;
case ($aBlogUsers[$oUser->getId()]->getUserRole() > ModuleBlog::BLOG_USER_ROLE_GUEST):
case ($oBlogUser->getUserRole() > ModuleBlog::BLOG_USER_ROLE_GUEST):
$sErrorMessage = $this->Lang_Get('blog.invite.notices.already_joined',
array('login' => htmlspecialchars($sUser)));
break;
case ($aBlogUsers[$oUser->getId()]->getUserRole() == ModuleBlog::BLOG_USER_ROLE_REJECT):
case ($oBlogUser->getUserRole() == ModuleBlog::BLOG_USER_ROLE_REJECT):
$sErrorMessage = $this->Lang_Get('blog.invite.notices.reject',
array('login' => htmlspecialchars($sUser)));
break;

View file

@ -119,7 +119,7 @@ class ActionUserfeed extends Action
/**
* Проверяем существование блога
*/
if (!$this->Blog_GetBlogById(getRequestStr('id'))) {
if (!($oBlog=$this->Blog_GetBlogById(getRequestStr('id'))) or !$this->ACL_IsAllowShowBlog($oBlog,$this->oUserCurrent)) {
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
return;
}

View file

@ -41,6 +41,12 @@ class ModuleUserfeed extends Module
* @var ModuleUserfeed_MapperUserfeed|null
*/
protected $oMapper = null;
/**
* Объект текущего пользователя
*
* @var ModuleUser_EntityUser|null
*/
protected $oUserCurrent = null;
/**
* Инициализация модуля
@ -48,6 +54,7 @@ class ModuleUserfeed extends Module
public function Init()
{
$this->oMapper = Engine::GetMapper(__CLASS__);
$this->oUserCurrent = $this->User_GetUserCurrent();
}
/**
@ -90,7 +97,17 @@ class ModuleUserfeed extends Module
$iPerPage = Config::Get('module.userfeed.count_default');
}
$aSubscribes = $this->oMapper->getUserSubscribes($iUserId);
$aTopicsIds = $this->oMapper->ReadFeed($aSubscribes['users'], $aSubscribes['blogs'], $iCount, $iCurrPage,
/**
* Добавляем в выдачу закрытые блоги
*/
$aOpenBlogs = array();
if ($this->oUserCurrent) {
if ($aOpenBlogs = $this->Blog_GetAccessibleBlogsByUser($this->oUserCurrent)) {
$aOpenBlogs = array_intersect($aOpenBlogs, $aSubscribes['blogs']);
}
}
$aTopicsIds = $this->oMapper->ReadFeed($aSubscribes['users'], $aSubscribes['blogs'], $aOpenBlogs, $iCount,
$iCurrPage,
$iPerPage);
return array(
'collection' => $this->Topic_GetTopicsAdditionalData($aTopicsIds),

View file

@ -93,20 +93,24 @@ class ModuleUserfeed_MapperUserfeed extends Mapper
/**
* Получить ленту топиков по подписке
*
* @param $aUserId Список ID юзеров
* @param $aBlogId Список ID блогов
* @param $aUserId array Список ID юзеров
* @param $aBlogId array Список ID блогов
* @param $aBlogIdClose array Список ID закрытых блогов пользователя блогов
* @param $iCount
* @param $iCurrPage
* @param $iPerPage
* @return array
*/
public function ReadFeed($aUserId, $aBlogId, &$iCount, $iCurrPage, $iPerPage)
public function ReadFeed($aUserId, $aBlogId, $aBlogIdClose, &$iCount, $iCurrPage, $iPerPage)
{
if (!is_array($aUserId)) {
$aUserId=array($aUserId);
$aUserId = array($aUserId);
}
if (!is_array($aBlogId)) {
$aBlogId=array($aBlogId);
$aBlogId = array($aBlogId);
}
if (!is_array($aBlogIdClose)) {
$aBlogIdClose = array($aBlogIdClose);
}
$sql = "
SELECT
@ -117,16 +121,18 @@ class ModuleUserfeed_MapperUserfeed extends Mapper
WHERE
t.topic_publish = 1
AND t.blog_id=b.blog_id
AND b.blog_type!='close'
AND ( 1=0 { OR t.blog_id IN (?a) } { OR t.user_id IN (?a) } )
AND ( b.blog_type!='close' { OR t.blog_id IN (?a) } )
AND ( 1=0 { OR t.blog_id IN (?a) } { OR t.user_id IN (?a) } )
ORDER BY t.topic_id DESC
LIMIT ?d, ?d ";
$aTopics = array();
if ($aRows = $this->oDb->selectPage($iCount, $sql,
count($aBlogIdClose) ? $aBlogIdClose : DBSIMPLE_SKIP,
count($aBlogId) ? $aBlogId : DBSIMPLE_SKIP,
count($aUserId) ? $aUserId : DBSIMPLE_SKIP,
($iCurrPage - 1) * $iPerPage, $iPerPage)) {
($iCurrPage - 1) * $iPerPage, $iPerPage)
) {
foreach ($aRows as $aTopic) {
$aTopics[] = $aTopic['topic_id'];
}