Overview

Packages

  • None
  • Yaga

Classes

  • ActedModel
  • ActionController
  • ActionModel
  • AwardCombo
  • BadgeAwardModel
  • BadgeController
  • BadgeModel
  • BadgesController
  • BadgesModule
  • BestController
  • BestFilterModule
  • CakeDayPost
  • CommentCount
  • CommentMarathon
  • DiscussionBodyLength
  • DiscussionCategory
  • DiscussionCount
  • DiscussionPageCount
  • HasMentioned
  • HolidayVisit
  • LeaderBoardModule
  • LengthOfService
  • ManualAward
  • NecroPost
  • NewbieComment
  • PhotoExists
  • PostCount
  • PostReactions
  • QnAAnserCount
  • RankController
  • RankModel
  • ReactController
  • ReactionCount
  • ReactionModel
  • ReflexComment
  • RulesController
  • SocialConnection
  • Yaga
  • YagaController
  • YagaHooks

Interfaces

  • YagaRule
  • Overview
  • Package
  • Class
  • Tree
  • Todo
  • Download
 1: <?php if(!defined('APPLICATION')) exit();
 2: 
 3: /**
 4:  * This rule awards badges to a particular post's owner when it receives the
 5:  * target number of reactions.
 6:  *
 7:  * @author Zachary Doll
 8:  * @since 1.0
 9:  * @package Yaga
10:  */
11: class PostReactions implements YagaRule {
12: 
13:   public function Award($Sender, $User, $Criteria) {
14:     $Args = $Sender->EventArguments;
15:     // Check to see if the submitted action is a target
16:     $Prop = 'ActionID_' . $Sender->EventArguments['ActionID'];
17:     if(property_exists($Criteria, $Prop)) {
18:       $Value = $Criteria->$Prop;
19:       if($Value <= 0 || $Value == FALSE) {
20:         return FALSE;
21:       }
22:     }
23:     else {
24:       return FALSE;
25:     }
26: 
27:     // Get the reaction counts for this parent item
28:     $ReactionModel = Yaga::ReactionModel();
29:     $Reactions = $ReactionModel->GetList($Args['ParentID'], $Args['ParentType']);
30: 
31:     // Squash the dataset into an array
32:     $Counts = array();
33:     foreach($Reactions as $Reaction) {
34:       $Counts['ActionID_' . $Reaction->ActionID] = $Reaction->Count;
35:     }
36:     
37:     // Actually check for the reaction counts
38:     foreach($Criteria as $ActionID => $Target) {
39:       if($Counts[$ActionID] < $Target) {
40:         return FALSE;
41:       }
42:     }
43: 
44:     // The owner should be awarded
45:     return $Args['ParentUserID'];
46:   }
47: 
48:   public function Form($Form) {
49:     $ActionModel = new ActionModel();
50:     $Actions = $ActionModel->Get();
51: 
52:     $String = $Form->Label('Yaga.Rules.PostReactions.Criteria.Head', 'ReactionCount');
53: 
54:     $ActionList = '';
55:     foreach($Actions as $Action) {
56:       $ActionList .= Wrap(sprintf(T('Yaga.Rules.PostReactions.LabelFormat'), $Action->Name) . ' ' . $Form->Textbox('ActionID_' . $Action->ActionID, array('class' => 'SmallInput')), 'li');
57:     }
58: 
59:     if($ActionList == '') {
60:       $String .= T('Yaga.Error.NoActions');
61:     }
62:     else {
63:       $String .= Wrap($ActionList, 'ul');
64:     }
65: 
66:     return $String;
67:   }
68: 
69:   public function Validate($Criteria, $Form) {
70:     $Validation = new Gdn_Validation();
71: 
72:     foreach($Criteria as $ActionID => $Target) {
73:       $Validation->ApplyRule($ActionID, 'Integer');
74:     }
75: 
76:     $Validation->Validate($Criteria);
77:     $Form->SetValidationResults($Validation->Results());
78:   }
79: 
80:   public function Hooks() {
81:     return array('ReactionModel_AfterReactionSave');
82:   }
83: 
84:   public function Description() {
85:     $Description = T('Yaga.Rules.PostReactions.Desc');
86:     return Wrap($Description, 'div', array('class' => 'InfoMessage'));
87:   }
88: 
89:   public function Name() {
90:     return T('Yaga.Rules.PostReactions');
91:   }
92: 
93:   public function Interacts() {
94:     return TRUE;
95:   }
96: 
97: }
98: 
Yaga API documentation generated by ApiGen 2.8.0