Added validation to rules criteria

This commit is contained in:
Zachary Doll 2013-12-11 16:56:37 -06:00
parent 7922ecf188
commit 5c4120a41e
16 changed files with 169 additions and 2 deletions

View File

@ -112,6 +112,13 @@ class BadgeController extends DashboardController {
$Criteria[$RealKey] = $Value;
}
}
// Validate the criteria
$RuleClass = new $FormValues['RuleClass'];
$Rule = new $RuleClass();
$Rule->Validate($Criteria, $this->Form);
$SerializedCriteria = serialize($Criteria);
$this->Form->SetFormValue('RuleCriteria', $SerializedCriteria);
if($this->Form->Save()) {

View File

@ -17,7 +17,7 @@ Yet Another Gamification Application
* ~~Rule criteria form help~~
* ~~Add pager to badge settings screen~~
* Create/find reusable badge images
* Add validation of rule criteria
* ~~Add validation of rule criteria~~
* Refactor reaction CSS
* Refactor all models to get rid of uneeded/duplicate methods
* Aggregate Rule Support

View File

@ -50,6 +50,24 @@ class AwardCombo implements YagaRule {
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Target', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Period', 'Validation' => 'Required'
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('BadgeAwardModel_AfterBadgeAward');
}

View File

@ -48,6 +48,19 @@ class CommentCount implements YagaRule{
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('CommentModel_AfterSaveComment');
}

View File

@ -45,6 +45,23 @@ class CommentMarathon implements YagaRule {
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Target', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Period', 'Validation' => 'Required'
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('CommentModel_AfterSaveComment');
}

View File

@ -50,6 +50,20 @@ class DiscussionCount implements YagaRule{
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('DiscussionModel_AfterSaveDiscussion');
}

View File

@ -24,6 +24,10 @@ class HasMentioned implements YagaRule{
return '';
}
public function Validate($Criteria, $Form) {
return;
}
public function Hooks() {
return array('CommentModel_BeforeNotification', 'DiscussionModel_BeforeNotification');
}

View File

@ -39,6 +39,20 @@ class HolidayVisit implements YagaRule {
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Month', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Day', 'Validation' => array('Required', 'Integer')
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('Base_AfterSignIn');
}

View File

@ -34,6 +34,20 @@ class LengthOfService implements YagaRule {
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Period', 'Validation' => 'Required'
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('Base_AfterSignIn');
}

View File

@ -17,7 +17,11 @@ class ManualAward implements YagaRule {
public function Form($Form) {
return '';
}
public function Validate($Criteria, $Form) {
return;
}
public function Hooks() {
return array();
}

View File

@ -48,6 +48,20 @@ class NewbieComment implements YagaRule{
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'Period', 'Validation' => 'Required'
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('CommentModel_BeforeNotification');
}

View File

@ -22,6 +22,10 @@ class PhotoExists implements YagaRule {
return '';
}
public function Validate($Criteria, $Form) {
return;
}
public function Hooks() {
return array('UserModel_AfterSave');
}

View File

@ -44,6 +44,20 @@ class ReactionCount implements YagaRule{
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Target', 'Validation' => array('Required', 'Integer')
),
array(
'Name' => 'ActionID', 'Validation' => array('Required', 'Integer')
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('ReactionModel_AfterReactionSave');
}

View File

@ -33,6 +33,17 @@ class ReflexComment implements YagaRule{
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'Seconds', 'Validation' => array('Required', 'Integer')
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('CommentModel_BeforeNotification');
}

View File

@ -33,6 +33,17 @@ class SocialConnection implements YagaRule{
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(array(
array(
'Name' => 'SocialNetwork', 'Validation' => array('Required')
)
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('Base_AfterConnection');
}

View File

@ -34,6 +34,14 @@ interface YagaRule {
*/
public function Form($Form);
/**
* This validates the submitted criteria and does what it wants with the form
*
* @param array $Criteria
* @param Gdn_Form $Form
*/
public function Validate($Criteria, $Form);
/**
* Returns a string representing a user friendly name of this rule.
*