Activity reactions fixing
This commit is contained in:
parent
e362147ddb
commit
88f2308562
@ -58,6 +58,11 @@ class BadgesController extends Gdn_Controller {
|
||||
* @param string $Slug
|
||||
*/
|
||||
public function Detail($BadgeID, $Slug = NULL) {
|
||||
$UserID = Gdn::Session()->UserID;
|
||||
|
||||
$Badges = $this->BadgeModel->GetBadgesToCheckForUser($UserID);
|
||||
decho($Badges);
|
||||
|
||||
$this->Render('Blank', 'Utility', 'Dashboard');
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,8 @@ class ReactController extends Gdn_Controller {
|
||||
|
||||
$ActivityModel = new ActivityModel();
|
||||
$Activity = $ActivityModel->GetID($ActivityID);
|
||||
|
||||
// decho($Activity);
|
||||
// die();
|
||||
if($Activity) {
|
||||
$Anchor = '#Activity_' . $ActivityID . ' .ReactMenu';
|
||||
}
|
||||
@ -145,12 +146,12 @@ class ReactController extends Gdn_Controller {
|
||||
|
||||
$UserID = Gdn::Session()->UserID;
|
||||
|
||||
if($Activity->InsertUserID == $UserID) {
|
||||
if($Activity['ActivityUserID'] == $UserID) {
|
||||
throw new Gdn_UserException('You cannot react to your own content.');
|
||||
}
|
||||
|
||||
// It has passed through the gauntlet
|
||||
$this->ReactionModel->SetReaction($ActivityID, 'activity', $Activity->RegardingUserID, $UserID, $ActionID);
|
||||
$this->ReactionModel->SetReaction($ActivityID, 'activity', $Activity['ActivityUserID'], $UserID, $ActionID);
|
||||
|
||||
$this->JsonTarget($Anchor, $this->_RenderActions($ActivityID, 'activity', FALSE), 'ReplaceWith');
|
||||
|
||||
|
@ -235,4 +235,23 @@ class BadgeModel extends Gdn_Model {
|
||||
->Get()
|
||||
->Result();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of unobtained but enabled badges for a specific user
|
||||
*
|
||||
* @param int $UserID
|
||||
* @param bool $Enabled Description
|
||||
* @return DataSet
|
||||
*/
|
||||
public function GetBadgesToCheckForUser($UserID) {
|
||||
return $this->SQL
|
||||
->Select()
|
||||
->From('Badge b')
|
||||
->Join('BadgeAward ba', 'b.BadgeID = ba.BadgeID', 'left')
|
||||
->Where('ba.UserID', $UserID)
|
||||
->Where('b.Enabled', 1)
|
||||
//->OrWhere('b.BadgeID is not null') // needed to get the full set of badges
|
||||
->Get()
|
||||
->Result();
|
||||
}
|
||||
}
|
@ -162,6 +162,8 @@ class ReactionModel extends Gdn_Model {
|
||||
// clear the cache
|
||||
unset(self::$_Reactions[$Type . $ID]);
|
||||
|
||||
$EventArgs = array('ID' => $ID, 'Type' => $Type, 'UserID' => $AuthorID, 'InsertUserID' => $UserID, 'Action' => $ActionID);
|
||||
|
||||
$CurrentReaction = $this->GetUserReaction($ID, $Type, $UserID);
|
||||
if($CurrentReaction) {
|
||||
if($ActionID == $CurrentReaction->ActionID) {
|
||||
@ -170,6 +172,7 @@ class ReactionModel extends Gdn_Model {
|
||||
'ParentType' => $Type,
|
||||
'InsertUserID' => $UserID,
|
||||
'ActionID' => $ActionID));
|
||||
$EventArgs['Exists'] = FALSE;
|
||||
}
|
||||
else {
|
||||
// update the record
|
||||
@ -181,6 +184,7 @@ class ReactionModel extends Gdn_Model {
|
||||
->Where('ParentType', $Type)
|
||||
->Where('InsertUserID', $UserID)
|
||||
->Put();
|
||||
$EventArgs['Exists'] = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -193,10 +197,10 @@ class ReactionModel extends Gdn_Model {
|
||||
'ParentAuthorID' => $AuthorID,
|
||||
'InsertUserID' => $UserID,
|
||||
'DateInserted' => date(DATE_ISO8601)));
|
||||
$EventArgs['Exists'] = TRUE;
|
||||
}
|
||||
$EventArgs['Reaction'] = $Reaction->Result();
|
||||
$this->FireEvent('AfterReactionSave', $EventArgs);
|
||||
|
||||
$this->FireEvent('AfterReactionSave', $EventArgs);
|
||||
return $Reaction;
|
||||
}
|
||||
}
|
@ -10,21 +10,19 @@ include_once 'interface.yagarule.php';
|
||||
class ReactionCount implements YagaRule{
|
||||
|
||||
public function Award($Sender, $User, $Criteria) {
|
||||
$Reaction = $Sender->EventArguments['Reaction'][0];
|
||||
decho($Criteria->ActionID);
|
||||
decho($Reaction);
|
||||
die();
|
||||
$ReactionModel = new ReactionModel();
|
||||
$Count = $ReactionModel->GetUserReactionCount($Reaction->ParentAuthorID, $Criteria->ActionID);
|
||||
$ActionID = $Sender->EventArguments['ActionID'];
|
||||
|
||||
decho($Count);
|
||||
if($Count >= $Criteria->Target) {
|
||||
decho($Reaction);
|
||||
|
||||
return $Reaction->InsertUserID;
|
||||
if($Criteria->ActionID != $ActionID) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$ReactionModel = new ReactionModel();
|
||||
$Count = $ReactionModel->GetUserReactionCount($Sender->EventArguments['UserID'], $Criteria->ActionID);
|
||||
|
||||
if($Count >= $Criteria->Target) {
|
||||
return $Sender->EventArguments['InsertUserID'];
|
||||
}
|
||||
else {
|
||||
die();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ class YagaHooks implements Gdn_IPlugin {
|
||||
* This is the dispatcher to check badge awards
|
||||
* @todo Optimize this by caching the rules... or something
|
||||
*
|
||||
* @param string $Hook What rules will be checked this pass around
|
||||
* @param string $Hook The rule hooks to check
|
||||
*/
|
||||
private function _AwardBadges($Sender, $Hook) {
|
||||
$Session = Gdn::Session();
|
||||
|
Loading…
x
Reference in New Issue
Block a user