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 based on a user's received reactions
 5:  *
 6:  * @author Zachary Doll
 7:  * @since 1.0
 8:  * @package Yaga
 9:  */
10: class ReactionCount implements YagaRule{
11: 
12:   public function Award($Sender, $User, $Criteria) {
13:     $ActionID = $Sender->EventArguments['ActionID'];
14: 
15:     if($Criteria->ActionID != $ActionID) {
16:       return FALSE;
17:     }
18: 
19:     $ReactionModel = new ReactionModel();
20:     $Count = $ReactionModel->GetUserCount($Sender->EventArguments['ParentUserID'], $ActionID);
21: 
22:     if($Count >= $Criteria->Target) {
23:       // Award the badge to the user that got the reaction
24:       return $Sender->EventArguments['ParentUserID'];
25:     }
26:     else {
27:       return FALSE;
28:     }
29:   }
30: 
31:   public function Form($Form) {
32:     $ActionModel = new ActionModel();
33:     $Actions = $ActionModel->Get();
34:     $Reactions = array();
35:     foreach($Actions as $Action) {
36:       $Reactions[$Action->ActionID] = $Action->Name;
37:     }
38: 
39:     $String = $Form->Label('Yaga.Rules.ReactionCount.Criteria.Head', 'ReactionCount');
40:     $String .= $Form->Textbox('Target', array('class' => 'SmallInput')) . ' ';
41:     $String .= $Form->DropDown('ActionID', $Reactions);
42: 
43:     return $String;
44:   }
45: 
46:   public function Validate($Criteria, $Form) {
47:     $Validation = new Gdn_Validation();
48:     $Validation->ApplyRules(array(
49:         array(
50:           'Name' => 'Target', 'Validation' => array('Required', 'Integer')
51:         ),
52:         array(
53:           'Name' => 'ActionID', 'Validation' => array('Required', 'Integer')
54:         )
55:     ));
56:     $Validation->Validate($Criteria);
57:     $Form->SetValidationResults($Validation->Results());
58:   }
59: 
60:   public function Hooks() {
61:     return array('ReactionModel_AfterReactionSave');
62:   }
63: 
64:   public function Description() {
65:     $Description = T('Yaga.Rules.ReactionCount.Desc');
66:     return Wrap($Description, 'div', array('class' => 'InfoMessage'));
67:   }
68: 
69:   public function Name() {
70:     return T('Yaga.Rules.ReactionCount');
71:   }
72:   
73:   public function Interacts() {
74:     return TRUE;
75:   }
76: }
77: 
Yaga API documentation generated by ApiGen 2.8.0