Added validation to rules criteria
This commit is contained in:
parent
7922ecf188
commit
5c4120a41e
@ -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()) {
|
||||
|
@ -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
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ class HasMentioned implements YagaRule{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function Validate($Criteria, $Form) {
|
||||
return;
|
||||
}
|
||||
|
||||
public function Hooks() {
|
||||
return array('CommentModel_BeforeNotification', 'DiscussionModel_BeforeNotification');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -17,7 +17,11 @@ class ManualAward implements YagaRule {
|
||||
public function Form($Form) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
public function Validate($Criteria, $Form) {
|
||||
return;
|
||||
}
|
||||
|
||||
public function Hooks() {
|
||||
return array();
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ class PhotoExists implements YagaRule {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function Validate($Criteria, $Form) {
|
||||
return;
|
||||
}
|
||||
|
||||
public function Hooks() {
|
||||
return array('UserModel_AfterSave');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user