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