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 comment count
 5:  *
 6:  * @author Zachary Doll
 7:  * @since 1.0
 8:  * @package Yaga
 9:  */
10: class CommentCount implements YagaRule{
11: 
12:   public function Award($Sender, $User, $Criteria) {
13:     $Result = FALSE;
14:     switch($Criteria->Comparison) {
15:       case 'gt':
16:         if($User->CountComments > $Criteria->Target) {
17:           $Result = TRUE;
18:         }
19:         break;
20:       case 'lt':
21:         if($User->CountComments < $Criteria->Target) {
22:           $Result = TRUE;
23:         }
24:         break;
25:       default:
26:       case 'gte':
27:         if($User->CountComments >= $Criteria->Target) {
28:           $Result = TRUE;
29:         }
30:         break;
31:     }
32: 
33:     return $Result;
34:   }
35: 
36:   public function Form($Form) {
37:     $Comparisons = array(
38:         'gt' => T('More than:'),
39:         'lt' => T('Less than:'),
40:         'gte' => T('More than or:')
41:     );
42: 
43:     $String = $Form->Label('Yaga.Rules.CommentCount.Criteria.Head', 'CommentCount');
44:     $String .= $Form->DropDown('Comparison', $Comparisons) . ' ';
45:     $String .= $Form->Textbox('Target', array('class' => 'SmallInput'));
46: 
47:     return $String;
48:   }
49: 
50:   public function Validate($Criteria, $Form) {
51:     $Validation = new Gdn_Validation();
52:     $Validation->ApplyRules(array(
53:         array(
54:           'Name' => 'Target', 'Validation' => array('Required', 'Integer')
55:         ),
56:         array(
57:           'Name' => 'Comparison', 'Validation' => 'Required'
58:         )
59:     ));
60:     $Validation->Validate($Criteria);
61:     $Form->SetValidationResults($Validation->Results());
62:   }
63:   public function Hooks() {
64:     return array('Gdn_Dispatcher_AppStartup');
65:   }
66: 
67:   public function Description() {
68:     $Description = T('Yaga.Rules.CommentCount.Desc');
69:     return Wrap($Description, 'div', array('class' => 'InfoMessage'));
70:   }
71: 
72:   public function Name() {
73:     return T('Yaga.Rules.CommentCount');
74:   }
75:   
76:   public function Interacts() {
77:     return FALSE;
78:   }
79: }
80: 
Yaga API documentation generated by ApiGen 2.8.0