本文整理汇总了PHP中E::ModuleRating方法的典型用法代码示例。如果您正苦于以下问题:PHP E::ModuleRating方法的具体用法?PHP E::ModuleRating怎么用?PHP E::ModuleRating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类E
的用法示例。
在下文中一共展示了E::ModuleRating方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: EventAjaxVote
/**
* Голосование админа
*/
public function EventAjaxVote()
{
// * Устанавливаем формат ответа
E::ModuleViewer()->SetResponseAjax('json');
if (!E::IsAdmin()) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error'));
return;
}
$nUserId = $this->GetPost('idUser');
if (!$nUserId || !($oUser = E::ModuleUser()->GetUserById($nUserId))) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_not_found'), E::ModuleLang()->Get('error'));
return;
}
$nValue = $this->GetPost('value');
$oUserVote = E::GetEntity('Vote');
$oUserVote->setTargetId($oUser->getId());
$oUserVote->setTargetType('user');
$oUserVote->setVoterId($this->oUserCurrent->getId());
$oUserVote->setDirection($nValue);
$oUserVote->setDate(F::Now());
$iVal = (double) E::ModuleRating()->VoteUser($this->oUserCurrent, $oUser, $nValue);
$oUserVote->setValue($iVal);
$oUser->setCountVote($oUser->getCountVote() + 1);
if (E::ModuleVote()->AddVote($oUserVote) && E::ModuleUser()->Update($oUser)) {
E::ModuleViewer()->AssignAjax('iRating', $oUser->getRating());
E::ModuleViewer()->AssignAjax('iSkill', $oUser->getSkill());
E::ModuleViewer()->AssignAjax('iCountVote', $oUser->getCountVote());
E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('user_vote_ok'), E::ModuleLang()->Get('attention'));
} else {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('action.admin.vote_error'), E::ModuleLang()->Get('error'));
}
}
示例2: EventVoteUser
/**
* Голосование за пользователя
*
*/
protected function EventVoteUser()
{
// * Пользователь авторизован?
if (!$this->oUserCurrent) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error'));
return;
}
// * Пользователь существует?
if (!($oUser = E::ModuleUser()->GetUserById(F::GetRequestStr('idUser', null, 'post')))) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error'));
return;
}
// * Голосует за себя?
if ($oUser->getId() == $this->oUserCurrent->getId()) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_vote_error_self'), E::ModuleLang()->Get('attention'));
return;
}
// * Уже голосовал?
if ($oUserVote = E::ModuleVote()->GetVote($oUser->getId(), 'user', $this->oUserCurrent->getId())) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_vote_error_already'), E::ModuleLang()->Get('attention'));
return;
}
// * Имеет право на голосование?
if (!E::ModuleACL()->CanVoteUser($this->oUserCurrent, $oUser)) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_vote_error_acl'), E::ModuleLang()->Get('attention'));
return;
}
// * Как проголосовал
$iValue = F::GetRequestStr('value', null, 'post');
if (!in_array($iValue, array('1', '-1'))) {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('attention'));
return;
}
// * Голосуем
/** @var ModuleVote_EntityVote $oUserVote */
$oUserVote = E::GetEntity('Vote');
$oUserVote->setTarget($oUser);
$oUserVote->setTargetId($oUser->getId());
$oUserVote->setTargetType('user');
$oUserVote->setVoter($this->oUserCurrent);
$oUserVote->setVoterId($this->oUserCurrent->getId());
$oUserVote->setDirection($iValue);
$oUserVote->setDate(F::Now());
if ($iValue != 0) {
$nDeltaRating = (double) E::ModuleRating()->VoteUser($this->oUserCurrent, $oUser, $iValue);
} else {
$nDeltaRating = 0.0;
}
$oUserVote->setValue($nDeltaRating);
$oUser->setCountVote($oUser->getCountVote() + 1);
if (E::ModuleVote()->AddVote($oUserVote) && E::ModuleUser()->Update($oUser)) {
E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('user_vote_ok'), E::ModuleLang()->Get('attention'));
E::ModuleViewer()->AssignAjax('iRating', number_format($oUser->getRating(), Config::Get('view.skill_length')));
E::ModuleViewer()->AssignAjax('iSkill', number_format($oUser->getSkill(), Config::Get('view.rating_length')));
E::ModuleViewer()->AssignAjax('iCountVote', $oUser->getCountVote());
// * Добавляем событие в ленту
E::ModuleStream()->Write($oUserVote->getVoterId(), 'vote_user', $oUser->getId());
} else {
E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error'));
return;
}
}