Reactions now apply their award value to the parent's row in the score column
This commit is contained in:
parent
8210b0c078
commit
424714c500
@ -170,7 +170,7 @@ class ReactController extends Gdn_Controller {
|
||||
}
|
||||
|
||||
private function _RenderActions($ID, $Type, $Echo = TRUE) {
|
||||
$Reactions = $this->ReactionModel->GetReactions($ID, $Type);
|
||||
$Reactions = $this->ReactionModel->GetAllReactions($ID, $Type);
|
||||
$ActionsString = '';
|
||||
foreach($Reactions as $Action) {
|
||||
$ActionsString .= Anchor(
|
||||
|
@ -69,7 +69,7 @@ class ReactionModel extends Gdn_Model {
|
||||
* @param int $ID
|
||||
* @param enum $Type is the kind of ID. Valid: comment, discussion, activity
|
||||
*/
|
||||
public function GetReactions($ID, $Type) {
|
||||
public function GetAllReactions($ID, $Type) {
|
||||
if(in_array($Type, array('discussion', 'comment', 'activity')) && $ID > 0) {
|
||||
$ReactionSet = array();
|
||||
if(empty(self::$_Reactions[$Type . $ID])) {
|
||||
@ -109,6 +109,22 @@ class ReactionModel extends Gdn_Model {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo document this
|
||||
* @param type $ID
|
||||
* @param type $Type
|
||||
*/
|
||||
public function GetReactions($ID, $Type) {
|
||||
return $this->SQL->
|
||||
Select('a.ActionID, a.AwardValue, COUNT(a.ActionID) as Count')
|
||||
->From('Action a')
|
||||
->Join('Reaction r', 'a.ActionID = r.ActionID', 'left')
|
||||
->Where('r.ParentID', $ID)
|
||||
->Where('r.ParentType', $Type)
|
||||
->GroupBy('a.ActionID')
|
||||
->Get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of reactions a user has received
|
||||
@ -201,7 +217,47 @@ class ReactionModel extends Gdn_Model {
|
||||
$EventArgs['Exists'] = TRUE;
|
||||
}
|
||||
|
||||
$this->CalculateScore($ID, $Type);
|
||||
$this->FireEvent('AfterReactionSave', $EventArgs);
|
||||
return $Reaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @param type $ID
|
||||
* @param type $Type
|
||||
* @param type $Increment
|
||||
* @return type
|
||||
*/
|
||||
private function CalculateScore($ID, $Type) {
|
||||
// Activities don't have scores
|
||||
if($Type == 'activity') {
|
||||
return;
|
||||
}
|
||||
|
||||
$Reactions = $this->GetReactions($ID, $Type);
|
||||
$Score = 0;
|
||||
foreach($Reactions as $Reaction) {
|
||||
$Score += $Reaction->AwardValue * $Reaction->Count;
|
||||
}
|
||||
switch($Type) {
|
||||
default:
|
||||
return;
|
||||
case 'discussion':
|
||||
$this->SQL
|
||||
->Update('Discussion')
|
||||
->Set('Score', $Score)
|
||||
->Where('DiscussionID', $ID)
|
||||
->Put();
|
||||
break;
|
||||
case 'comment':
|
||||
$this->SQL
|
||||
->Update('Comment')
|
||||
->Set('Score', $Score)
|
||||
->Where('CommentID', $ID)
|
||||
->Put();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
@ -31,17 +31,6 @@ class YagaHooks implements Gdn_IPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display points in the user info list
|
||||
* @param object $Sender
|
||||
* @todo Use the unused Points column in the User Table to store the points
|
||||
*/
|
||||
public function UserInfoModule_OnBasicInfo_Handler($Sender) {
|
||||
$Model = new YagaModel();
|
||||
$Points = $Model->GetUserPoints($Sender->User->UserID);
|
||||
echo Wrap(T('Yaga.Points', 'Points'), 'dt') . ' ' . Wrap($Points, 'dd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the reaction counts on the profile page
|
||||
* @param object $Sender
|
||||
@ -135,7 +124,7 @@ class YagaHooks implements Gdn_IPlugin {
|
||||
$this->_ReactionModel = new ReactionModel();
|
||||
}
|
||||
|
||||
$Reactions = $this->_ReactionModel->GetReactions($ID, $Type);
|
||||
$Reactions = $this->_ReactionModel->GetAllReactions($ID, $Type);
|
||||
foreach($Reactions as $Reaction) {
|
||||
if($Reaction->UserIDs) {
|
||||
foreach($Reaction->UserIDs as $Index => $UserID) {
|
||||
@ -226,7 +215,7 @@ class YagaHooks implements Gdn_IPlugin {
|
||||
$this->_ReactionModel = new ReactionModel();
|
||||
}
|
||||
|
||||
$Reactions = $this->_ReactionModel->GetReactions($ID, $Type);
|
||||
$Reactions = $this->_ReactionModel->GetAllReactions($ID, $Type);
|
||||
$ActionsString = '';
|
||||
foreach($Reactions as $Action) {
|
||||
if(CheckPermission($Action->Permission)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user