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 withing a specified time frame.
 5:  *
 6:  * @author Zachary Doll
 7:  * @since 1.0
 8:  * @package Yaga
 9:  */
10: class CommentMarathon implements YagaRule {
11: 
12:   public function Award($Sender, $User, $Criteria) {
13:     $Target = $Criteria->Target;
14:     $TargetDate = date(DATE_ISO8601, strtotime($Criteria->Duration . ' ' . $Criteria->Period . ' ago'));
15: 
16:     $SQL = Gdn::SQL();
17:     $Count = $SQL->Select('count(CommentID) as Count')
18:          ->From('Comment')
19:          ->Where('InsertUserID', $User->UserID)
20:          ->Where('DateInserted >=', $TargetDate)
21:          ->Get()
22:             ->FirstRow();
23: 
24:     if($Count->Count >= $Target) {
25:       return TRUE;
26:     }
27:     else {
28:       return FALSE;
29:     }
30:   }
31: 
32:   public function Form($Form) {
33:     $Lengths = array(
34:         'day' => T('Days'),
35:         'week' => T('Weeks'),
36:         'year' => T('Years')
37:     );
38: 
39:     $String = $Form->Label('Yaga.Rules.CommentMarathon.Criteria.Head', 'CommentMarathon');
40:     $String .= $Form->Textbox('Target', array('class' => 'SmallInput'));
41:     $String .= $Form->Label('Time Frame');
42:     $String .= $Form->Textbox('Duration', array('class' => 'SmallInput')) . ' ';
43:     $String .= $Form->DropDown('Period', $Lengths);
44: 
45:     return $String;
46:   }
47: 
48:   public function Validate($Criteria, $Form) {
49:     $Validation = new Gdn_Validation();
50:     $Validation->ApplyRules(array(
51:         array(
52:           'Name' => 'Target', 'Validation' => array('Required', 'Integer')
53:         ),
54:         array(
55:           'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
56:         ),
57:         array(
58:           'Name' => 'Period', 'Validation' => 'Required'
59:         )
60:     ));
61:     $Validation->Validate($Criteria);
62:     $Form->SetValidationResults($Validation->Results());
63:   }
64: 
65:   public function Hooks() {
66:     return array('CommentModel_AfterSaveComment');
67:   }
68: 
69:   public function Description() {
70:     $Description = T('Yaga.Rules.CommentMarathon.Desc');
71:     return Wrap($Description, 'div', array('class' => 'InfoMessage'));
72:   }
73: 
74:   public function Name() {
75:     return T('Yaga.Rules.CommentMarathon');
76:   }
77:   
78:   public function Interacts() {
79:     return FALSE;
80:   }
81: }
82: 
Yaga API documentation generated by ApiGen 2.8.0