Add rule for QnA plugin

This commit is contained in:
Zachary Doll 2014-02-14 16:03:06 -06:00
parent 32577c0013
commit 0f2c0f4536
2 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,75 @@
<?php if(!defined('APPLICATION')) exit();
/**
* This rule awards badges based on a user's answer count from the QnA plugin
*
* @author Zachary Doll
* @since 0.5
* @package Yaga
*/
class QnAAnserCount implements YagaRule{
public function Award($Sender, $User, $Criteria) {
$Result = FALSE;
switch($Criteria->Comparison) {
case 'gt':
if($User->CountAcceptedAnswers > $Criteria->Target) {
$Result = TRUE;
}
break;
case 'lt':
if($User->CountAcceptedAnswers < $Criteria->Target) {
$Result = TRUE;
}
break;
default:
case 'gte':
if($User->CountAcceptedAnswers >= $Criteria->Target) {
$Result = TRUE;
}
break;
}
return $Result;
}
public function Form($Form) {
$Comparisons = array(
'gt' => T('More than:'),
'lt' => T('Less than:'),
'gte' => T('More than or:')
);
$String = $Form->Label('Yaga.Rules.QnAAnserCount.Criteria.Desc', 'QnAAnserCount');
$String .= $Form->DropDown('Comparison', $Comparisons) . ' ';
$String .= $Form->Textbox('Target', array('class' => 'SmallInput'));
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Target', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Comparison', 'Validation' => 'Required'
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('Gdn_Dispatcher_AppStartup');
}
public function Description() {
$Description = T('Yaga.Rules.QnAAnserCount.Desc');
return Wrap($Description, 'div', array('class' => 'InfoMessage'));
}
public function Name() {
return T('Yaga.Rules.QnAAnserCount');
}
}

View File

@ -186,3 +186,6 @@ $Definition['Yaga.Rules.DiscussionPageCount.Criteria.Desc'] = 'How many pages?';
$Definition['Yaga.Rules.DiscussionBodyLength'] = 'OP Length';
$Definition['Yaga.Rules.DiscussionBodyLength.Desc'] = 'Award this badge if the user has a discussion that reaches the target number of characters. Make sure you enter a number less than or equal to %s.';
$Definition['Yaga.Rules.DiscussionBodyLength.Criteria.Desc'] = 'How many characters?';
$Definition['Yaga.Rules.QnAAnserCount'] = 'Accepted Answers (QnA Plugin required)';
$Definition['Yaga.Rules.QnAAnserCount.Desc'] = 'Award this badge if the user has accepted answers that fit the criteria.';
$Definition['Yaga.Rules.QnAAnserCount.Criteria.Desc'] = 'How many accepted answers?';