1: <?php if(!defined('APPLICATION')) exit();
2:
3: 4: 5: 6: 7: 8: 9: 10:
11: class PostReactions implements YagaRule {
12:
13: public function Award($Sender, $User, $Criteria) {
14: $Args = $Sender->EventArguments;
15:
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:
28: $ReactionModel = Yaga::ReactionModel();
29: $Reactions = $ReactionModel->GetList($Args['ParentID'], $Args['ParentType']);
30:
31:
32: $Counts = array();
33: foreach($Reactions as $Reaction) {
34: $Counts['ActionID_' . $Reaction->ActionID] = $Reaction->Count;
35: }
36:
37:
38: foreach($Criteria as $ActionID => $Target) {
39: if($Counts[$ActionID] < $Target) {
40: return FALSE;
41: }
42: }
43:
44:
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: