/** * This determines if the current user can react on this item with this action * * @param string $Type valid options are 'discussion', 'comment', and 'activity' * @param int $ID * @param int $ActionID * @throws Gdn_UserException */ public function Index($Type, $ID, $ActionID) { $Type = strtolower($Type); $Action = $this->ActionModel->GetByID($ActionID); // Make sure the action exists and the user is allowed to react if (!$Action) { throw new Gdn_UserException(T('Yaga.Action.Invalid')); } if (!Gdn::Session()->CheckPermission($Action->Permission)) { throw PermissionException(); } switch ($Type) { case 'discussion': $Model = new DiscussionModel(); $AnchorID = '#Discussion_'; break; case 'comment': $Model = new CommentModel(); $AnchorID = '#Comment_'; break; case 'activity': $Model = new ActivityModel(); $AnchorID = '#Activity_'; break; default: throw new Gdn_UserException(T('Yaga.Action.InvalidTargetType')); break; } $Item = $Model->GetID($ID); if ($Item) { $Anchor = $AnchorID . $ID . ' .ReactMenu'; } else { throw new Gdn_UserException(T('Yaga.Action.InvalidTargetID')); } $UserID = Gdn::Session()->UserID; switch ($Type) { case 'comment': case 'discussion': $ItemOwnerID = $Item->InsertUserID; break; case 'activity': $ItemOwnerID = $Item['RegardingUserID']; break; default: throw new Gdn_UserException(T('Yaga.Action.InvalidTargetType')); break; } if ($ItemOwnerID == $UserID) { throw new Gdn_UserException(T('Yaga.Error.ReactToOwn')); } // It has passed through the gauntlet $this->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID); $this->JsonTarget($Anchor, RenderReactionList($ID, $Type, FALSE), 'ReplaceWith'); // Don't render anything $this->Render('Blank', 'Utility', 'Dashboard'); }
/** * Add the action list to any activity items that can be commented on * * @param ActivityController $Sender */ public function ActivityController_AfterActivityBody_Handler($Sender) { if (!C('Yaga.Reactions.Enabled')) { return; } $Activity = $Sender->EventArguments['Activity']; $CurrentUserID = Gdn::Session()->UserID; $Type = 'activity'; $ID = $Activity->ActivityID; // Only allow reactions on activities that allow comments if (!property_exists($Activity, 'AllowComments') || $Activity->AllowComments == 0) { return; } // check to see if allowed to add reactions if (!Gdn::Session()->CheckPermission('Yaga.Reactions.Add')) { return; } if ($CurrentUserID == $Activity->RegardingUserID) { // The current user made this activity item happen } else { echo Wrap(RenderReactionList($ID, $Type, FALSE), 'div', array('class' => 'Reactions')); } }