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 when a user comments on a dead discussion.
 5:  *
 6:  * @author Zachary Doll
 7:  * @since 0.3.4
 8:  * @package Yaga
 9:  */
10: class NecroPost implements YagaRule {
11: 
12:   public function Award($Sender, $User, $Criteria) {
13:     $NecroDate = strtotime($Criteria->Duration . ' ' . $Criteria->Period . ' ago');
14:     
15:     // Get the last comment date from the parent discussion
16:     $Args = $Sender->EventArguments;
17:     $DiscussionID = $Args['FormPostValues']['DiscussionID'];
18:     $DiscussionModel = new DiscussionModel();
19:     $Discussion = $DiscussionModel->GetID($DiscussionID);
20:     $LastCommentDate = strtotime($Discussion->DateLastComment);
21:     
22:     if($LastCommentDate < $NecroDate) {
23:       return TRUE;
24:     }
25:     else {
26:       return FALSE;
27:     }
28:   }
29: 
30:   public function Form($Form) {
31:     $Lengths = array(
32:         'day' => T('Days'),
33:         'week' => T('Weeks'),
34:         'year' => T('Years')
35:     );
36: 
37:     $String = $Form->Label('Yaga.Rules.NecroPost.Criteria.Head', 'NecroPost');
38:     $String .= $Form->Textbox('Duration', array('class' => 'SmallInput')) . ' ';
39:     $String .= $Form->DropDown('Period', $Lengths);
40: 
41:     return $String;
42:   }
43: 
44:   public function Validate($Criteria, $Form) {
45:     $Validation = new Gdn_Validation();
46:     $Validation->ApplyRules(array(
47:         array(
48:           'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
49:         ),
50:         array(
51:           'Name' => 'Period', 'Validation' => 'Required'
52:         )
53:     ));
54:     $Validation->Validate($Criteria);
55:     $Form->SetValidationResults($Validation->Results());
56:   }
57: 
58:   public function Hooks() {
59:     return array('CommentModel_AfterSaveComment');
60:   }
61: 
62:   public function Description() {
63:     $Description = T('Yaga.Rules.NecroPost.Desc');
64:     return Wrap($Description, 'div', array('class' => 'InfoMessage'));
65:   }
66: 
67:   public function Name() {
68:     return T('Yaga.Rules.NecroPost');
69:   }
70:   
71:   public function Interacts() {
72:     return FALSE;
73:   }
74: }
75: 
Yaga API documentation generated by ApiGen 2.8.0