1: <?php if(!defined('APPLICATION')) exit();
2:
3: 4: 5: 6: 7: 8: 9:
10: class PostCount implements YagaRule{
11:
12: public function Award($Sender, $User, $Criteria) {
13: $Result = FALSE;
14: $CountPosts = $User->CountDiscussions + $User->CountComments;
15: switch($Criteria->Comparison) {
16: case 'gt':
17: if($CountPosts > $Criteria->Target) {
18: $Result = TRUE;
19: }
20: break;
21: case 'lt':
22: if($CountPosts < $Criteria->Target) {
23: $Result = TRUE;
24: }
25: break;
26: default:
27: case 'gte':
28: if($CountPosts >= $Criteria->Target) {
29: $Result = TRUE;
30: }
31: break;
32: }
33:
34: return $Result;
35: }
36:
37: public function Form($Form) {
38: $Comparisons = array(
39: 'gt' => T('More than:'),
40: 'lt' => T('Less than:'),
41: 'gte' => T('More than or:')
42: );
43:
44: $String = $Form->Label('Yaga.Rules.PostCount.Criteria.Head', 'PostCount');
45: $String .= $Form->DropDown('Comparison', $Comparisons) . ' ';
46: $String .= $Form->Textbox('Target', array('class' => 'SmallInput'));
47:
48: return $String;
49: }
50:
51: public function Validate($Criteria, $Form) {
52: $Validation = new Gdn_Validation();
53: $Validation->ApplyRules(array(
54: array(
55: 'Name' => 'Target', 'Validation' => array('Required', 'Integer')
56: ),
57: array(
58: 'Name' => 'Comparison', 'Validation' => 'Required'
59: )
60: ));
61: $Validation->Validate($Criteria);
62: $Form->SetValidationResults($Validation->Results());
63: }
64:
65: public function Hooks() {
66: return array('Gdn_Dispatcher_AppStartup');
67: }
68:
69: public function Description() {
70: $Description = T('Yaga.Rules.PostCount.Desc');
71: return Wrap($Description, 'div', array('class' => 'InfoMessage'));
72: }
73:
74: public function Name() {
75: return T('Yaga.Rules.PostCount');
76: }
77:
78: public function Interacts() {
79: return FALSE;
80: }
81: }
82: