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 if a comment is placed on a new member's first discussion
 5:  *
 6:  * @author Zachary Doll
 7:  * @since 1.0
 8:  * @package Yaga
 9:  */
10: class NewbieComment implements YagaRule{
11: 
12:   public function Award($Sender, $User, $Criteria) {
13:     $Discussion = $Sender->EventArguments['Discussion'];
14:     $NewbUserID = $Discussion->InsertUserID;
15:     
16:     // Don't award to the newb on his own discussion
17:     if($NewbUserID == $User->UserID) {
18:       return FALSE;
19:     }
20:     
21:     $CurrentDiscussionID = $Discussion->DiscussionID;
22:     $TargetDate = strtotime($Criteria->Duration . ' ' . $Criteria->Period . ' ago');
23: 
24:     $SQL = Gdn::SQL();
25:     $FirstDiscussion = $SQL->Select('DiscussionID, DateInserted')
26:             ->From('Discussion')
27:             ->Where('InsertUserID', $NewbUserID)
28:             ->OrderBy('DateInserted')
29:             ->Get()
30:             ->FirstRow();
31: 
32:     $InsertDate = strtotime($FirstDiscussion->DateInserted);
33: 
34:     if($CurrentDiscussionID == $FirstDiscussion->DiscussionID
35:             && $InsertDate > $TargetDate) {
36:       return $User->UserID;
37:     }
38:     else {
39:       return FALSE;
40:     }
41:   }
42: 
43:   public function Form($Form) {
44:     $Lengths = array(
45:         'day' => T('Days'),
46:         'week' => T('Weeks'),
47:         'year' => T('Years')
48:     );
49: 
50:     $String = $Form->Label('Yaga.Rules.NewbieComment.Criteria.Head', 'NewbieComment');
51:     $String .= $Form->Textbox('Duration', array('class' => 'SmallInput')) . ' ';
52:     $String .= $Form->DropDown('Period', $Lengths);
53: 
54:     return $String;
55:   }
56: 
57:   public function Validate($Criteria, $Form) {
58:     $Validation = new Gdn_Validation();
59:     $Validation->ApplyRules(array(
60:         array(
61:           'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
62:         ),
63:         array(
64:           'Name' => 'Period', 'Validation' => 'Required'
65:         )
66:     ));
67:     $Validation->Validate($Criteria);
68:     $Form->SetValidationResults($Validation->Results());
69:   }
70: 
71:   public function Hooks() {
72:     return array('CommentModel_BeforeNotification');
73:   }
74: 
75:   public function Description() {
76:     $Description = T('Yaga.Rules.NewbieComment.Desc');
77:     return Wrap($Description, 'div', array('class' => 'InfoMessage'));
78:   }
79: 
80:   public function Name() {
81:     return T('Yaga.Rules.NewbieComment');
82:   }
83:   
84:   public function Interacts() {
85:     return FALSE;
86:   }
87: }
88: 
Yaga API documentation generated by ApiGen 2.8.0