Implemented all rules in repo

This commit is contained in:
Zachary Doll 2013-11-15 13:56:14 -06:00
parent d3a2fbc079
commit e123468009
5 changed files with 35 additions and 19 deletions

View File

@ -151,6 +151,7 @@ class ReactionModel extends Gdn_Model {
*
* Events: AfterReactionSave
*
* @todo Add points to the parent score column on discussions and comments
* @param int $ID
* @param enum $Type activity, comment, discussion
* @param int $AuthorID
@ -162,7 +163,7 @@ 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);
$EventArgs = array('ParentID' => $ID, 'ParentType' => $Type, 'ParentUserID' => $AuthorID, 'InsertUserID' => $UserID, 'ActionID' => $ActionID);
$CurrentReaction = $this->GetUserReaction($ID, $Type, $UserID);
if($CurrentReaction) {

View File

@ -13,9 +13,13 @@ include_once 'interface.yagarule.php';
class HasMentioned implements YagaRule{
public function Award($Sender, $User, $Criteria) {
$Result = FALSE;
return $Result;
$HasMentioned = count($Sender->EventArguments['MentionedUsers']);
if($HasMentioned) {
return TRUE;
}
else {
return FALSE;
}
}
public function Form($Form) {
@ -23,7 +27,7 @@ class HasMentioned implements YagaRule{
}
public function Hooks() {
return array('CommentModel_AfterSaveComment', 'DiscussionModel_AfterSaveDiscussion', 'ActivityModel_BeforeSaveComment');
return array('CommentModel_BeforeNotification', 'DiscussionModel_BeforeNotification');
}
public function Description() {

View File

@ -17,10 +17,11 @@ class ReactionCount implements YagaRule{
}
$ReactionModel = new ReactionModel();
$Count = $ReactionModel->GetUserReactionCount($Sender->EventArguments['UserID'], $Criteria->ActionID);
$Count = $ReactionModel->GetUserReactionCount($Sender->EventArguments['ParentUserID'], $ActionID);
if($Count >= $Criteria->Target) {
return $Sender->EventArguments['InsertUserID'];
if($Count >= $Criteria->Target) {
// Award the badge to the user that got the reaction
return $Sender->EventArguments['ParentUserID'];
}
else {
return FALSE;

View File

@ -2,7 +2,7 @@
include_once 'interface.yagarule.php';
/**
* This rule awards badges when the user connects social accounts
* @todo Implement social connection rule
* @todo test this on a live db
*
* @author Zachary Doll
* @since 1.0
@ -11,15 +11,20 @@ include_once 'interface.yagarule.php';
class SocialConnection implements YagaRule{
public function Award($Sender, $User, $Criteria) {
$Result = FALSE;
return $Result;
$Network = $Sender->EventArguments['Provider'];
if($Network == $Criteria->SocialNetwork) {
return TRUE;
}
else {
return FALSE;
}
}
public function Form($Form) {
$SocialNetworks = array(
'twitter' => 'Twitter',
'facebook' => 'Facebook'
'Twitter' => 'Twitter',
'Facebook' => 'Facebook'
);
$String = $Form->Label('Social Networks', 'SocialConnection');
@ -34,7 +39,7 @@ class SocialConnection implements YagaRule{
}
public function Description() {
$Description = 'This rule checks a users connection to social networks. If the user chooses to connect to the target network, this will return true.';
$Description = 'This rule checks if a user has connected to the target social network. If the user has, this will return true.';
return $Description;
}

View File

@ -34,6 +34,7 @@ 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();
@ -276,13 +277,17 @@ class YagaHooks implements Gdn_IPlugin {
$this->_AwardBadges($Sender, 'CommentModel_AfterSaveComment');
}
public function ActivityModel_BeforeSaveComment_Handler($Sender) {
$this->_AwardBadges($Sender, 'ActivityModel_BeforeSaveComment');
}
public function DiscussionModel_AfterSaveDiscussion_Handler($Sender) {
$this->_AwardBadges($Sender, 'DiscussionModel_AfterSaveDiscussion');
}
public function CommentModel_BeforeNotification_Handler($Sender) {
$this->_AwardBadges($Sender, 'CommentModel_BeforeNotification');
}
public function DiscussionModel_BeforeNotification_Handler($Sender) {
$this->_AwardBadges($Sender, 'DiscussionModel_BeforeNotification');
}
public function Base_AfterSignIn_Handler($Sender) {
$this->_AwardBadges($Sender, 'Base_AfterSignIn');