/** * Вспомогательный метод проверки прав пользователя блога * * @param ModuleBlog_EntityBlog $oBlog * @param ModuleUser_EntityUser $oUser * @param string $sRights * * @return bool */ protected function _checkBlogUserRights($oBlog, $oUser, $sRights) { $sUserRole = ''; $bCurrentUser = false; $bResult = false; if (!$oBlog) { return false; } // Если пользователь не передан, то берется текущий if (!$oUser) { if ($oUser = E::ModuleUser()->GetUserCurrent()) { $bCurrentUser = true; } else { return false; } } elseif (E::ModuleUser()->GetUserCurrent() && E::ModuleUser()->GetUserCurrent()->getId() == $oUser->getId()) { $bCurrentUser = true; } $sCacheKey = 'acl_blog_user_rights' . serialize(array($oBlog->GetId(), $oUser ? $oUser->GetId() : 0, $bCurrentUser, $sRights)); // Сначала проверяем кеш if (is_int($xCacheResult = E::ModuleCache()->Get($sCacheKey, 'tmp'))) { return $xCacheResult; } if ($bCurrentUser) { // Blog owner has any rights if ($oBlog->getUserOwnerId() == $oUser->getId()) { return true; } // * Для авторизованного пользователя данный код будет работать быстрее if ($oBlog->getUserIsAdministrator()) { $sUserRole = 'administrator'; } elseif ($oBlog->getUserIsModerator()) { $sUserRole = 'moderator'; } } else { $oBlogUser = E::ModuleBlog()->GetBlogUserByBlogIdAndUserId($oBlog->getId(), $oUser->getId()); if ($oBlogUser) { if ($oBlogUser->IsBlogAdministrator()) { $sUserRole = 'administrator'; } elseif ($oBlogUser->IsBlogModerator()) { $sUserRole = 'moderator'; } } } if ($sUserRole) { $aUserRights = $this->GetUserRights('blogs', $sUserRole); $bResult = isset($aUserRights[$sRights]) && (bool) $aUserRights[$sRights]; } E::ModuleCache()->Set($sCacheKey, $bResult ? 1 : 0, array('blog_update', 'user_update'), 0, 'tmp'); return $bResult; }