/** * Обновляет юзера * * @param ModuleUser_EntityUser $oUser Объект пользователя * @return bool */ public function Update(ModuleUser_EntityUser $oUser) { $sql = "UPDATE " . Config::Get('db.table.user') . "\n SET\n user_password = ? ,\n user_mail = ? ,\n user_skill = ? ,\n user_date_activate = ? ,\n user_date_comment_last = ? ,\n user_rating = ? ,\n user_count_vote = ? ,\n user_activate = ? ,\n user_activate_key = ? ,\n user_profile_name = ? ,\n user_profile_sex = ? ,\n user_profile_country = ? ,\n user_profile_region = ? ,\n user_profile_city = ? ,\n user_profile_birthday = ? ,\n user_profile_about = ? ,\n user_profile_date = ? ,\n user_profile_avatar = ? ,\n user_profile_foto = ? ,\n user_settings_notice_new_topic = ? ,\n user_settings_notice_new_comment = ? ,\n user_settings_notice_new_talk = ? ,\n user_settings_notice_reply_comment = ? ,\n user_settings_notice_new_friend = ? ,\n user_settings_timezone = ?\n WHERE user_id = ?\n "; if ($this->oDb->query($sql, $oUser->getPassword(), $oUser->getMail(), $oUser->getSkill(), $oUser->getDateActivate(), $oUser->getDateCommentLast(), $oUser->getRating(), $oUser->getCountVote(), $oUser->getActivate(), $oUser->getActivateKey(), $oUser->getProfileName(), $oUser->getProfileSex(), $oUser->getProfileCountry(), $oUser->getProfileRegion(), $oUser->getProfileCity(), $oUser->getProfileBirthday(), $oUser->getProfileAbout(), $oUser->getProfileDate(), $oUser->getProfileAvatar(), $oUser->getProfileFoto(), $oUser->getSettingsNoticeNewTopic(), $oUser->getSettingsNoticeNewComment(), $oUser->getSettingsNoticeNewTalk(), $oUser->getSettingsNoticeReplyComment(), $oUser->getSettingsNoticeNewFriend(), $oUser->getSettingsTimezone(), $oUser->getId())) { return true; } return false; }
/** * * Can create album * * @param ModuleUser_EntityUser $oUser * @return boolean */ public function CanCreateAlbum($oUser) { if (Config::Get('plugin.lsgallery.aldbum_create_rating') === false) { return true; } if ($oUser->getRating() < Config::Get('plugin.lsgallery.aldbum_create_rating') && !$oUser->isAdministrator()) { return false; } return true; }
/** * Проверяет может ли пользователь создавать запись по времени */ public function CanPostTestimonialTime(ModuleUser_EntityUser $oUser) { // Для администраторов ограничение по времени не действует if ($oUser->isAdministrator() or Config::Get('plugin.testimonials.acl.create.limit_time') == 0 or $oUser->getRating() >= Config::Get('plugin.testimonials.acl.create.limit_time_rating')) { return true; } /** * Проверяем, если топик опубликованный меньше чем acl.create.topic.limit_time секунд назад */ $aTestimonials = $this->PluginTestimonials_Testimonials_GetTestimonialsItemsByFilter(array('#page' => array(1, 20), '#order' => array('id' => 'desc'), 'user_id' => $oUser->getId(), 'date_add >' => date("Y-m-d H:i:s", time() - Config::Get('plugin.testimonials.acl.create.limit_time')))); if (isset($aTestimonials['count']) and $aTestimonials['count'] > 0) { return false; } return true; }
/** * Получаем число доступных приглашений для юзера * * @param unknown_type $oUserFrom * @return unknown */ public function GetCountInviteAvailable(ModuleUser_EntityUser $oUserFrom) { $sDay = 7; $iCountUsed = $this->GetCountInviteUsedByDate($oUserFrom->getId(), date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d") - $sDay, date("Y")))); $iCountAllAvailable = round($oUserFrom->getRating() + $oUserFrom->getSkill()); $iCountAllAvailable = $iCountAllAvailable < 0 ? 0 : $iCountAllAvailable; $iCountAvailable = $iCountAllAvailable - $iCountUsed; $iCountAvailable = $iCountAvailable < 0 ? 0 : $iCountAvailable; return $iCountAvailable; }
/** * Проверяет может ли пользователь голосовать за конкретный пост * * @param ModuleUser_EntityUser $oUser Пользователь * @param PluginForum_ModuleForum_EntityPost $oPost Сообщение * @return bool */ public function CanVoteForumPost(ModuleUser_EntityUser $oUser, $oPost) { if ($oUser->getRating() >= Config::Get('plugin.forum.acl.vote.post.rating')) { return true; } return false; }
/** * Расчет рейтинга и силы при голосовании за пользователя * * @param ModuleUser_EntityUser $oUser * @param ModuleUser_EntityUser $oUserTarget * @param int $iValue * * @return float */ public function VoteUser($oUser, $oUserTarget, $iValue) { if (!C::Get('plugin.rating.user.vote')) { return 0; } if (!C::Get('plugin.rating.user.dislike') && $iValue < 0) { return 0; } /** * Начисляем силу и рейтинг юзеру, используя логарифмическое распределение */ $skill = $oUser->getSkill(); $iMinSize = C::Get('plugin.rating.user.min_change'); //0.42; $iMaxSize = C::Get('plugin.rating.user.max_change'); //3.2; $iSizeRange = $iMaxSize - $iMinSize; $iMinCount = log(0 + 1); $iMaxCount = log(C::Get('plugin.rating.user.max_rating') + 1); // 500 $iCountRange = $iMaxCount - $iMinCount; if ($iCountRange == 0) { $iCountRange = 1; } if ($skill > C::Get('plugin.rating.user.left_border') and $skill < C::Get('plugin.rating.user.right_border')) { // 50-200 $skill_new = $skill / C::Get('plugin.rating.user.mid_divider'); //70 } elseif ($skill >= C::Get('plugin.rating.user.right_border')) { // 200 $skill_new = $skill / C::Get('plugin.rating.user.right_divider'); //2 } else { $skill_new = $skill / C::Get('plugin.rating.user.left_divider'); //40 } $iDelta = $iMinSize + (log($skill_new + 1) - $iMinCount) * ($iSizeRange / $iCountRange); /** * Определяем новый рейтинг */ $iRatingNew = $oUserTarget->getRating() + $iValue * $iDelta; $oUserTarget->setRating($iRatingNew); return $iValue * $iDelta; }
/** * Голосуем за картинку */ public function EventVoteImage() { if (!$this->oUserCurrent) { $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error')); return; } /* @var $oImage PluginLsgallery_ModuleImage_EntityImage */ if (!($oImage = $this->PluginLsgallery_Image_GetImageById(getRequest('idImage', null, 'post')))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } /* @var $oAlbum PluginLsgallery_ModuleAlbum_EntityAlbum */ if (!($oAlbum = $this->PluginLsgallery_Album_GetAlbumById($oImage->getAlbumId()))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } if (!$this->ACL_AllowViewAlbumImages($this->oUserCurrent, $oAlbum)) { $this->Message_AddErrorSingle($this->Lang_Get('not_access'), $this->Lang_Get('error')); return; } if ($oImage->getUserId() == $this->oUserCurrent->getId()) { $this->Message_AddErrorSingle($this->Lang_Get('plugin.lsgallery.lsgallery_image_vote_error_self'), $this->Lang_Get('attention')); return; } if ($oImageVote = $this->Vote_GetVote($oImage->getId(), 'image', $this->oUserCurrent->getId())) { $this->Message_AddErrorSingle($this->Lang_Get('plugin.lsgallery.lsgallery_image_vote_error_already'), $this->Lang_Get('attention')); return; } if (strtotime($oImage->getDateAdd()) <= time() - Config::Get('acl.vote.image.limit_time')) { $this->Message_AddErrorSingle($this->Lang_Get('plugin.lsgallery.lsgallery_image_vote_error_time'), $this->Lang_Get('attention')); return; } $iValue = getRequest('value', null, 'post'); if (!in_array($iValue, array('1', '-1', '0'))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('attention')); return; } if ($this->oUserCurrent->getRating() < Config::Get('acl.vote.image.rating')) { $this->Message_AddErrorSingle($this->Lang_Get('plugin.lsgallery.lsgallery_image_vote_error_acl'), $this->Lang_Get('attention')); return; } $oImageVote = Engine::GetEntity('Vote'); $oImageVote->setTargetId($oImage->getId()); $oImageVote->setTargetType('image'); $oImageVote->setVoterId($this->oUserCurrent->getId()); $oImageVote->setDirection($iValue); $oImageVote->setDate(date("Y-m-d H:i:s")); $iVal = 0; if ($iValue != 0) { $iVal = (double) $this->Rating_VoteImage($this->oUserCurrent, $oImage, $iValue); } $oImageVote->setValue($iVal); $oImage->setCountVote($oImage->getCountVote() + 1); if ($iValue == 1) { $oImage->setCountVoteUp($oImage->getCountVoteUp() + 1); } elseif ($iValue == -1) { $oImage->setCountVoteDown($oImage->getCountVoteDown() + 1); } elseif ($iValue == 0) { $oImage->setCountVoteAbstain($oImage->getCountVoteAbstain() + 1); } if ($this->Vote_AddVote($oImageVote) && $this->PluginLsgallery_Image_UpdateImage($oImage)) { if ($iValue) { $this->Message_AddNoticeSingle($this->Lang_Get('plugin.lsgallery.lsgallery_image_vote_ok'), $this->Lang_Get('attention')); } else { $this->Message_AddNoticeSingle($this->Lang_Get('plugin.lsgallery.lsgallery_image_vote_ok_abstain'), $this->Lang_Get('attention')); } $this->Viewer_AssignAjax('iRating', $oImage->getRating()); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } }
/** * Расчет рейтинга и силы при голосовании за пользователя * * @param ModuleUser_EntityUser $oUser * @param ModuleUser_EntityUser $oUserTarget * @param int $iValue * * @return float */ public function VoteUser($oUser, $oUserTarget, $iValue) { if (!C::Get('plugin.simplerating.user.vote')) { return 0; } if (!C::Get('plugin.simplerating.user.dislike') && $iValue < 0) { return 0; } /** * Начисляем рейтинг пользователя */ $oUserTarget->setRating((double) $oUserTarget->getRating() + $iValue * (double) C::Get('plugin.simplerating.user.add')); /** * Убавляем рейтинг голосующего, если нужно */ if (C::Get('plugin.simplerating.user_remove')) { $oUser->setRating((double) $oUser->getRating() + (double) C::Get('plugin.simplerating.user.remove')); $this->User_Update($oUser); } return (double) C::Get('plugin.simplerating.user.add'); }
/** * Проверяет может ли пользователь голосовать за конкретного пользователя * * @param Entity_User $oUser * @param Entity_User $oUserTarget * @return bool */ public function CanVoteUser(ModuleUser_EntityUser $oUser, ModuleUser_EntityUser $oUserTarget) { if ($oUser->getRating() >= Config::Get('acl.vote.user.rating')) { return true; } return false; }
/** * Получает список блогов, которые доступны пользователю для заданного действия. * Или проверяет на заданное действие конкретный блог * * @param string $sAllow * @param ModuleUser_EntityUser $oUser * @param int|ModuleBlog_EntityBlog $xBlog * @param bool $bCheckOnly * @param bool $bSortByTitle * * @return array|bool */ public function GetBlogsAllowTo($sAllow, $oUser, $xBlog = null, $bCheckOnly = false, $bSortByTitle = true) { /** @var ModuleBlog_EntityBlog $oRequestBlog */ $oRequestBlog = null; if (is_object($xBlog)) { $iRequestBlogId = intval($xBlog->GetId()); $oRequestBlog = $xBlog; } else { $iRequestBlogId = intval($xBlog); } $sCacheKey = 'blogs_allow_to_' . serialize(array($sAllow, $oUser ? $oUser->GetId() : 0, $iRequestBlogId, (bool) $bCheckOnly)); if ($iRequestBlogId && $bCheckOnly) { // Если только проверка прав, то проверяем временный кеш if (is_int($xCacheResult = E::ModuleCache()->Get($sCacheKey, 'tmp'))) { return $xCacheResult; } } if ($oUser->isAdministrator() || $oUser->isModerator()) { // Если админ и если проверка на конкретный блог, то возвращаем без проверки if ($iRequestBlogId) { return $iRequestBlogId; } $aAdditionalData = array('relation_user'); $aAllowBlogs = $this->GetBlogs($aAdditionalData); if ($iRequestBlogId) { return isset($aAllowBlogs[$iRequestBlogId]) ? $aAllowBlogs[$iRequestBlogId] : array(); } if ($bSortByTitle) { $this->_sortByTitle($aAllowBlogs); } return $aAllowBlogs; } if (false === ($aAllowBlogs = E::ModuleCache()->Get($sCacheKey))) { if ($oUser) { // User is owner of the blog if ($oRequestBlog && $oRequestBlog->getOwnerId() == $oUser->getId()) { return $oRequestBlog; } // Блоги, созданные пользователем $aAllowBlogs = $this->GetBlogsByOwnerId($oUser->getId()); if ($iRequestBlogId && isset($aAllowBlogs[$iRequestBlogId])) { return $aAllowBlogs[$iRequestBlogId]; } // Блоги, в которых состоит пользователь if ($iRequestBlogId) { // Requests one blog $aBlogUsers = $this->GetBlogUsersByArrayBlog($iRequestBlogId, $oUser->getId()); if ($oBlogUser = reset($aBlogUsers)) { if (!$oBlogUser->getBlog()) { if (!$oRequestBlog) { $oRequestBlog = $this->GetBlogById($iRequestBlogId); } $oBlogUser->setBlog($oRequestBlog); } } } else { // Requests any allowed blogs $aBlogUsers = $this->GetBlogUsersByUserId($oUser->getId()); } foreach ($aBlogUsers as $oBlogUser) { /** @var ModuleBlog_EntityBlogType $oBlog */ $oBlog = $oBlogUser->getBlog(); /** @var ModuleBlog_EntityBlogType $oBlogType */ $oBlogType = $oBlog->GetBlogType(); // админа и модератора блога не проверяем if ($oBlogUser->IsBlogAdministrator() || $oBlogUser->IsBlogModerator()) { $aAllowBlogs[$oBlog->getId()] = $oBlog; } elseif ($oBlogUser->getUserRole() !== self::BLOG_USER_ROLE_NOTMEMBER && $oBlogUser->getUserRole() > self::BLOG_USER_ROLE_GUEST) { $bAllow = false; if ($oBlogType) { if ($sAllow == 'write') { $bAllow = $oBlogType->GetAclWrite(self::BLOG_USER_ACL_MEMBER) && $oBlogType->GetMinRateWrite() <= $oUser->getRating() || E::ModuleACL()->CheckBlogEditContent($oBlog, $oUser); } elseif ($sAllow == 'read') { $bAllow = $oBlogType->GetAclRead(self::BLOG_USER_ACL_MEMBER) && $oBlogType->GetMinRateRead() <= $oUser->getRating(); } elseif ($sAllow == 'comment') { $bAllow = $oBlogType->GetAclComment(self::BLOG_USER_ACL_MEMBER) && $oBlogType->GetMinRateComment() <= $oUser->getRating(); } if ($bAllow) { $aAllowBlogs[$oBlog->getId()] = $oBlog; } } } // Если задан конкретный блог и он найден, то проверять больше не нужно if ($iRequestBlogId && isset($aAllowBlogs[$iRequestBlogId])) { return $aAllowBlogs[$iRequestBlogId]; } } } if ($sAllow == 'write') { // Блоги, в которые можно писать без вступления $aFilter = array('acl_write' => self::BLOG_USER_ACL_USER, 'min_rate_write' => $oUser->GetUserRating()); } elseif ($sAllow == 'read') { // Блоги, которые можно читать без вступления $aFilter = array('acl_read' => self::BLOG_USER_ACL_USER, 'min_rate_read' => $oUser->GetUserRating()); } elseif ($sAllow == 'comment') { // Блоги, в которые можно писать без вступления $aFilter = array('acl_comment' => self::BLOG_USER_ACL_USER, 'min_rate_comment' => $oUser->GetUserRating()); } // Получаем типы блогов if ($aBlogTypes = $this->GetBlogTypes($aFilter, true)) { // Получаем ID блогов $aCriteria = array('filter' => array('blog_type' => $aBlogTypes)); // Получаем ID блогов $aResult = $this->oMapper->GetBlogsIdByCriteria($aCriteria); // Получаем сами блоги if ($aResult['data']) { // если задана только проверка, то сам блог(и) не нужен if ($iRequestBlogId && $bCheckOnly) { return in_array($iRequestBlogId, $aResult['data']); } if ($aBlogs = $this->GetBlogsAdditionalData($aResult['data'], array())) { foreach ($aBlogs as $oBlog) { if (!isset($aAllowBlogs[$oBlog->getId()])) { $aAllowBlogs[$oBlog->getId()] = $oBlog; } } } } } if ($iRequestBlogId) { return isset($aAllowBlogs[$iRequestBlogId]) ? $aAllowBlogs[$iRequestBlogId] : array(); } if ($bSortByTitle) { $this->_sortByTitle($aAllowBlogs); } E::ModuleCache()->Set($aAllowBlogs, $sCacheKey, array('blog_update', 'user_update'), 'P1D'); } if ($iRequestBlogId && $bCheckOnly) { // Если только проверка прав, то сохраняем во временный кеш // Чтоб не было ложных сробатываний, используем в этом кеше числовое значение E::ModuleCache()->Set($sCacheKey, $aAllowBlogs ? 1 : 0, array('blog_update', 'user_update'), 0, 'tmp'); } return $aAllowBlogs; }
/** * Расчет рейтинга и силы при голосовании за пользователя * * @param ModuleUser_EntityUser $oUser * @param ModuleUser_EntityUser $oUserTarget * @param int $iValue * @return float */ public function VoteUser(ModuleUser_EntityUser $oUser, ModuleUser_EntityUser $oUserTarget, $iValue) { /** * Начисляем силу и рейтинг юзеру, используя логарифмическое распределение */ $skill = $oUser->getSkill(); $iMinSize = 0.42; $iMaxSize = 3.2; $iSizeRange = $iMaxSize - $iMinSize; $iMinCount = log(0 + 1); $iMaxCount = log(500 + 1); $iCountRange = $iMaxCount - $iMinCount; if ($iCountRange == 0) { $iCountRange = 1; } if ($skill > 50 and $skill < 200) { $skill_new = $skill / 40; } elseif ($skill >= 200) { $skill_new = $skill / 2; } else { $skill_new = $skill / 70; } $iDelta = $iMinSize + (log($skill_new + 1) - $iMinCount) * ($iSizeRange / $iCountRange); /** * Определяем новый рейтинг */ $iRatingNew = $oUserTarget->getRating() + $iValue * $iDelta; $oUserTarget->setRating($iRatingNew); return $iValue * $iDelta; }
/** * @param string $sParam * @param mixed $xValue * @param ModuleUser_EntityUser $oUser * @param array $aParams * * @return bool */ public function CheckRuleActionParam($sParam, $xValue, $oUser, $aParams = array()) { if ($sParam == 'registration_time') { if (time() - strtotime($oUser->getDateRegister()) >= $xValue) { return TRUE; } else { return FALSE; } } if ($sParam == 'rating') { if ($oUser->getRating() >= $xValue) { return TRUE; } else { return FALSE; } } if ($sParam == 'skill') { if ($oUser->getSkill() >= $xValue) { return TRUE; } else { return FALSE; } } if ($sParam == 'count_comment') { if (E::ModuleComment()->GetCountCommentsByUserId($oUser->getId(), 'topic') >= $xValue) { return TRUE; } else { return FALSE; } } if ($sParam == 'count_topic') { if (E::ModuleTopic()->GetCountTopicsPersonalByUser($oUser->getId(), 1) >= $xValue) { return TRUE; } else { return FALSE; } } if ($sParam == 'rating_sum_topic') { if (is_array($xValue) && count($xValue) > 1) { $iRating = $xValue[0]; $iTime = $xValue[1]; } else { $iRating = $xValue; $iTime = 60 * 60 * 24 * 14; } if ($this->GetSumRatingTopic($oUser->getId(), date('Y-m-d H:i:s', time() - $iTime)) >= $iRating) { return TRUE; } else { return FALSE; } } if ($sParam == 'rating_sum_comment') { if (is_array($xValue) && count($xValue) > 1) { $iRating = $xValue[0]; $iTime = $xValue[1]; } else { $iRating = $xValue; $iTime = 60 * 60 * 24 * 7; } if ($this->GetSumRatingComment($oUser->getId(), date('Y-m-d H:i:s', time() - $iTime)) >= $iRating) { return TRUE; } else { return FALSE; } } return FALSE; }
/** * Расчет рейтинга и силы при голосовании за пользователя * * @param ModuleUser_EntityUser $oUser * @param ModuleUser_EntityUser $oUserTarget * @param int $iValue * @return float */ public function VoteUser(ModuleUser_EntityUser $oUser, ModuleUser_EntityUser $oUserTarget, $iValue, $voted = false) { $iRatingNew = $oUserTarget->getRating() + $iValue; $oUserCurrent = $this->User_GetUserCurrent(); $oUserTarget->setRating($iRatingNew); if (!$voted) { if ($iValue > 0) { $oUserTarget->setSkill($oUserTarget->getSkill() + 10.0); } else { $oUserTarget->setSkill($oUserTarget->getSkill() - 10.0); } } $this->User_Update($oUserTarget); return $iValue; }
/** * @param string $sAllow * @param ModuleUser_EntityUser $oUser * @param int|ModuleBlog_EntityBlog $xBlog * @param bool $bCheckOnly * * @return array|bool|mixed|ModuleBlog_EntityBlog[] */ protected function _getBlogsAllowTo($sAllow, $oUser, $xBlog = null, $bCheckOnly = false) { /** @var ModuleBlog_EntityBlog $oRequestBlog */ $oRequestBlog = null; if (is_object($xBlog)) { $iRequestBlogId = intval($xBlog->GetId()); $oRequestBlog = $xBlog; } else { $iRequestBlogId = intval($xBlog); } if ($oUser->isAdministrator() || $oUser->isModerator()) { // Если админ и если проверка на конкретный блог, то возвращаем без проверки if ($iRequestBlogId) { return $iRequestBlogId; } $aAdditionalData = array('relation_user'); $aAllowBlogs = $this->GetBlogs($aAdditionalData); if ($iRequestBlogId) { return isset($aAllowBlogs[$iRequestBlogId]) ? $aAllowBlogs[$iRequestBlogId] : array(); } return $aAllowBlogs; } // User is owner of the blog if ($oRequestBlog && $oRequestBlog->getOwnerId() == $oUser->getId()) { return $oRequestBlog; } // Блоги, созданные пользователем $aAllowBlogs = $this->GetBlogsByOwnerId($oUser->getId()); if ($iRequestBlogId && isset($aAllowBlogs[$iRequestBlogId])) { return $aAllowBlogs[$iRequestBlogId]; } // Блоги, в которых состоит пользователь if ($iRequestBlogId) { // Requests one blog $aBlogUsers = $this->GetBlogUsersByArrayBlog($iRequestBlogId, $oUser->getId()); if ($oBlogUser = reset($aBlogUsers)) { if (!$oBlogUser->getBlog()) { if (!$oRequestBlog) { $oRequestBlog = $this->GetBlogById($iRequestBlogId); } $oBlogUser->setBlog($oRequestBlog); } } } else { // Requests any allowed blogs $aBlogUsers = $this->GetBlogUsersByUserId($oUser->getId()); } foreach ($aBlogUsers as $oBlogUser) { /** @var ModuleBlog_EntityBlog $oBlog */ $oBlog = $oBlogUser->getBlog(); /** @var ModuleBlog_EntityBlogType $oBlogType */ $oBlogType = $oBlog->GetBlogType(); // админа и модератора блога не проверяем if ($oBlogUser->IsBlogAdministrator() || $oBlogUser->IsBlogModerator()) { $aAllowBlogs[$oBlog->getId()] = $oBlog; } elseif ($oBlogUser->getUserRole() !== self::BLOG_USER_ROLE_NOTMEMBER && $oBlogUser->getUserRole() > self::BLOG_USER_ROLE_GUEST) { $bAllow = false; if ($oBlogType) { if ($sAllow == 'write') { $bAllow = $oBlogType->GetAclWrite(self::BLOG_USER_ACL_MEMBER) && $oBlogType->GetMinRateWrite() <= $oUser->getRating() || E::ModuleACL()->CheckBlogEditContent($oBlog, $oUser); } elseif ($sAllow == 'read') { $bAllow = $oBlogType->GetAclRead(self::BLOG_USER_ACL_MEMBER) && $oBlogType->GetMinRateRead() <= $oUser->getRating(); } elseif ($sAllow == 'comment') { $bAllow = $oBlogType->GetAclComment(self::BLOG_USER_ACL_MEMBER) && $oBlogType->GetMinRateComment() <= $oUser->getRating(); } if ($bAllow) { $aAllowBlogs[$oBlog->getId()] = $oBlog; } } } // Если задан конкретный блог и он найден, то проверять больше не нужно if ($iRequestBlogId && isset($aAllowBlogs[$iRequestBlogId])) { return $aAllowBlogs[$iRequestBlogId]; } } $aFilter = array(); if ($sAllow == 'list') { // Blogs which user can list $aFilter['allow_list'] = true; } elseif ($sAllow == 'read') { // Blogs which can be read without subscribing $aFilter = array('acl_read' => self::BLOG_USER_ACL_USER, 'min_rate_read' => $oUser->GetUserRating()); } elseif ($sAllow == 'comment') { // Blogs in which user can comment without subscription $aFilter = array('acl_comment' => self::BLOG_USER_ACL_USER, 'min_rate_comment' => $oUser->GetUserRating()); } elseif ($sAllow == 'write') { // Blogs in which user can write without subscription $aFilter = array('acl_write' => self::BLOG_USER_ACL_USER, 'min_rate_write' => $oUser->GetUserRating()); } // Получаем типы блогов if ($aFilter && ($aBlogTypes = $this->GetBlogTypes($aFilter, true))) { // Получаем ID блогов $aCriteria = array('filter' => array('blog_type' => $aBlogTypes)); // Получаем ID блогов $aResult = $this->oMapper->GetBlogsIdByCriteria($aCriteria); // Получаем сами блоги if ($aResult['data']) { // если задана только проверка, то сам блог(и) не нужен if ($iRequestBlogId && $bCheckOnly) { return in_array($iRequestBlogId, $aResult['data']); } if ($aBlogs = $this->GetBlogsAdditionalData($aResult['data'], array())) { foreach ($aBlogs as $oBlog) { if (!isset($aAllowBlogs[$oBlog->getId()])) { $aAllowBlogs[$oBlog->getId()] = $oBlog; } } } } } if ($iRequestBlogId) { return isset($aAllowBlogs[$iRequestBlogId]) ? $aAllowBlogs[$iRequestBlogId] : array(); } return $aAllowBlogs; }
/** * Получает список блогов в которые может постить юзер * * @param ModuleUser_EntityUser $oUser Объект пользователя * @return array */ public function GetBlogsAllowByUser($oUser) { if ($oUser->isAdministrator()) { return $this->GetBlogs(); } else { $aAllowBlogsUser = $this->GetBlogsByOwnerId($oUser->getId()); $aBlogUsers = $this->GetBlogUsersByUserId($oUser->getId()); foreach ($aBlogUsers as $oBlogUser) { $oBlog = $oBlogUser->getBlog(); if ($oUser->getRating() >= $oBlog->getLimitRatingTopic() or $oBlogUser->getIsAdministrator() or $oBlogUser->getIsModerator()) { $aAllowBlogsUser[$oBlog->getId()] = $oBlog; } } return $aAllowBlogsUser; } }
/** * Получаем число доступных приглашений для юзера * * @param ModuleUser_EntityUser $oUserFrom Объект пользователя * * @return int */ public function GetCountInviteAvailable($oUserFrom) { $sDay = 7; $iCountUsed = $this->GetCountInviteUsedByDate($oUserFrom->getId(), date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - $sDay, date('Y')))); $iCountAllAvailable = round($oUserFrom->getRating() + $oUserFrom->getSkill()); $iCountAllAvailable = $iCountAllAvailable < 0 ? 0 : $iCountAllAvailable; $iCountAvailable = $iCountAllAvailable - $iCountUsed; $iCountAvailable = $iCountAvailable < 0 ? 0 : $iCountAvailable; return $iCountAvailable; }
/** * Проверка на ограничение по времени на постинг на стене * * @param ModuleUser_EntityUser $oUser Пользователь * @param ModuleWall_EntityWall $oWall Объект сообщения на стене * * @return bool */ public function CanAddWallTime($oUser, $oWall) { // * Для администраторов ограничение по времени не действует if ($oUser->isAdministrator() || $oUser->isModerator() || Config::Get('acl.create.wall.limit_time') == 0 || $oUser->getRating() >= Config::Get('acl.create.wall.limit_time_rating')) { return true; } if ($oWall->getUserId() == $oWall->getWallUserId()) { return true; } // * Получаем последнее сообщение $aWall = E::ModuleWall()->GetWall(array('user_id' => $oWall->getUserId()), array('id' => 'desc'), 1, 1, array()); // * Если сообщений нет if ($aWall['count'] == 0) { return true; } $oWallLast = array_shift($aWall['collection']); $sDate = strtotime($oWallLast->getDateAdd()); if ($sDate && time() - $sDate < Config::Get('acl.create.wall.limit_time')) { return false; } return true; }
/** * @param ModuleUser_EntityUser $oUser * * @return bool */ public function AllowAddByUser($oUser) { if ($this->IsAllowAdd()) { return $oUser->getRating() > $this->getMinRateAdd(); } return false; }