当前位置: 首页>>代码示例>>PHP>>正文


PHP DiscussionModel::GetUserScore方法代码示例

本文整理汇总了PHP中DiscussionModel::GetUserScore方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::GetUserScore方法的具体用法?PHP DiscussionModel::GetUserScore怎么用?PHP DiscussionModel::GetUserScore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DiscussionModel的用法示例。


在下文中一共展示了DiscussionModel::GetUserScore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: DiscussionController_VoteDiscussion_Create

 /**
  * Increment/decrement discussion scores
  */
 public function DiscussionController_VoteDiscussion_Create($Sender)
 {
     //		if (!C('Plugins.Voting.Enabled'))
     //			return;
     $DiscussionID = GetValue(0, $Sender->RequestArgs, 0);
     $TransientKey = GetValue(1, $Sender->RequestArgs);
     $VoteType = FALSE;
     if ($TransientKey == 'voteup' || $TransientKey == 'votedown') {
         $VoteType = $TransientKey;
         $TransientKey = GetValue(2, $Sender->RequestArgs);
     }
     $Session = Gdn::Session();
     $NewUserVote = 0;
     $Total = 0;
     if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $DiscussionID > 0) {
         $DiscussionModel = new DiscussionModel();
         $OldUserVote = $DiscussionModel->GetUserScore($DiscussionID, $Session->UserID);
         if ($VoteType == 'voteup') {
             $NewUserVote = 1;
         } else {
             if ($VoteType == 'votedown') {
                 $NewUserVote = -1;
             } else {
                 $NewUserVote = $OldUserVote == 1 ? -1 : 1;
             }
         }
         $FinalVote = intval($OldUserVote) + intval($NewUserVote);
         // Allow admins to vote unlimited.
         $AllowVote = $Session->CheckPermission('Garden.Moderation.Manage');
         // Only allow users to vote up or down by 1.
         if (!$AllowVote) {
             $AllowVote = $FinalVote > -2 && $FinalVote < 2;
         }
         if ($AllowVote) {
             $Total = $DiscussionModel->SetUserScore($DiscussionID, $Session->UserID, $FinalVote);
         } else {
             $Discussion = $DiscussionModel->GetID($DiscussionID);
             $Total = GetValue('Score', $Discussion, 0);
             $FinalVote = $OldUserVote;
         }
         // Move the comment into or out of moderation.
         if (class_exists('LogModel')) {
             $Moderate = FALSE;
             if ($Total <= C('Plugins.Voting.ModThreshold1', -10)) {
                 $LogOptions = array('GroupBy' => array('RecordID'));
                 // Get the comment row.
                 if (isset($Discussion)) {
                     $Data = (array) $Discussion;
                 } else {
                     $Data = (array) $DiscussionModel->GetID($DiscussionID);
                 }
                 if ($Data) {
                     // Get the users that voted the comment down.
                     $OtherUserIDs = $DiscussionModel->SQL->Select('UserID')->From('UserComment')->Where('CommentID', $DiscussionID)->Where('Score <', 0)->Get()->ResultArray();
                     $OtherUserIDs = array_column($OtherUserIDs, 'UserID');
                     $LogOptions['OtherUserIDs'] = $OtherUserIDs;
                     // Add the comment to moderation.
                     if ($Total > C('Plugins.Voting.ModThreshold2', -20)) {
                         LogModel::Insert('Moderate', 'Discussion', $Data, $LogOptions);
                     }
                 }
                 $Moderate = TRUE;
             }
             if ($Total <= C('Plugins.Voting.ModThreshold2', -20)) {
                 // Remove the comment.
                 $DiscussionModel->Delete($DiscussionID, array('Log' => 'Moderate'));
                 $Sender->InformMessage(sprintf(T('The %s has been removed for moderation.'), T('discussion')));
             } elseif ($Moderate) {
                 $Sender->InformMessage(sprintf(T('The %s has been flagged for moderation.'), T('discussion')));
             }
         }
     }
     $Sender->DeliveryType(DELIVERY_TYPE_BOOL);
     $Sender->SetJson('TotalScore', $Total);
     $Sender->SetJson('FinalVote', $FinalVote);
     $Sender->Render();
 }
开发者ID:vanilla,项目名称:addons,代码行数:80,代码来源:class.voting.plugin.php

示例2: DiscussionController_VoteDiscussion_Create

   /**
    * Increment/decrement discussion scores
    */
   public function DiscussionController_VoteDiscussion_Create($Sender) {
		if (!C('Plugins.Voting.Enabled'))
			return;

      $DiscussionID = GetValue(0, $Sender->RequestArgs, 0);
      $TransientKey = GetValue(1, $Sender->RequestArgs);
      $VoteType = FALSE;
      if ($TransientKey == 'voteup' || $TransientKey == 'votedown') {
         $VoteType = $TransientKey;
         $TransientKey = GetValue(2, $Sender->RequestArgs);
      }
      $Session = Gdn::Session();
      $NewUserVote = 0;
      $Total = 0;
      if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $DiscussionID > 0) {
         $DiscussionModel = new DiscussionModel();
         $OldUserVote = $DiscussionModel->GetUserScore($DiscussionID, $Session->UserID);

         if ($VoteType == 'voteup')
            $NewUserVote = 1;
         else if ($VoteType == 'votedown')
            $NewUserVote = -1;
         else
            $NewUserVote = $OldUserVote == 1 ? -1 : 1;
         
         $FinalVote = intval($OldUserVote) + intval($NewUserVote);
         // Allow admins to vote unlimited.
         $AllowVote = $Session->CheckPermission('Vanilla.Comments.Edit');
         // Only allow users to vote up or down by 1.
         if (!$AllowVote)
            $AllowVote = $FinalVote > -2 && $FinalVote < 2;
         
         if ($AllowVote) {
            $Total = $DiscussionModel->SetUserScore($DiscussionID, $Session->UserID, $FinalVote);
         } else {
				$Discussion = $DiscussionModel->GetID($DiscussionID);
				$Total = GetValue('Score', $Discussion, 0);
				$FinalVote = $OldUserVote;
			}
      }
      $Sender->DeliveryType(DELIVERY_TYPE_BOOL);
      $Sender->SetJson('TotalScore', $Total);
      $Sender->SetJson('FinalVote', $FinalVote);
      $Sender->Render();
   }
开发者ID:nerdgirl,项目名称:Forums-ILoveBadTV,代码行数:48,代码来源:class.voting.plugin.php


注:本文中的DiscussionModel::GetUserScore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。