コード例 #1
0
ファイル: ActionAdmin.class.php プロジェクト: ZeoNish/altocms
 /**
  * Голосование админа
  */
 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
0
ファイル: ActionAjax.class.php プロジェクト: anp135/altocms
 /**
  * Голосование за пользователя
  *
  */
 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;
     }
 }