From 154a5b64527657952db05cb8c6474ecf385604af Mon Sep 17 00:00:00 2001 From: Zachary Doll Date: Thu, 7 Nov 2013 17:44:36 -0600 Subject: [PATCH] Render first rule criteria form and require at least one valid rule set to add or edit a badge --- controllers/class.badgescontroller.php | 4 +++- rules/interface.yagarule.php | 3 ++- views/badges/add.php | 14 +++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/controllers/class.badgescontroller.php b/controllers/class.badgescontroller.php index fef7c4d..f57e9a7 100644 --- a/controllers/class.badgescontroller.php +++ b/controllers/class.badgescontroller.php @@ -122,7 +122,9 @@ class BadgesController extends DashboardController { $this->Form->SetModel($this->BadgeModel); // Only allow editing if some rules exist - + if(!$this->GetRules()) { + throw ForbiddenException('add or edit badges without rules'); + } $Edit = FALSE; if($BadgeID) { diff --git a/rules/interface.yagarule.php b/rules/interface.yagarule.php index c6d92e3..776899e 100644 --- a/rules/interface.yagarule.php +++ b/rules/interface.yagarule.php @@ -11,7 +11,8 @@ interface YagaRule { * This performs the grunt work of an award rule. Given an expected criteria, * it determines if a specific user meets muster. * - * @param Mixed $Criteria + * @param string $Criteria This is a serialized array with key value pairs + * that match the criteria that were previously rendered * @param int $UserID * @return bool True if the user meets the criteria, false otherwise */ diff --git a/views/badges/add.php b/views/badges/add.php index 388eadd..ad72d75 100644 --- a/views/badges/add.php +++ b/views/badges/add.php @@ -1,12 +1,17 @@ GetRules(); + if(property_exists($this, 'Badge')) { echo Wrap(T('Edit Badge'), 'h1'); $RuleClass = $this->Badge->RuleClass; } else { echo Wrap(T('Add Badge'), 'h1'); - $RuleClass = ''; + reset($Rules); + $RuleClass = key($array); } echo $this->Form->Open(array('enctype' => 'multipart/form-data', 'class' => 'Badge')); @@ -41,12 +46,11 @@ echo $this->Form->Errors();
  • Form->Label('Rule', 'RuleClass'); - echo $this->Form->Dropdown('RuleClass', $this->GetRules()); + echo $this->Form->Dropdown('RuleClass', $Rules); ?>
  • Form->InputPrefix; $this->Form->InputPrefix = $Prefix . '_Rules'; @@ -54,10 +58,6 @@ echo $this->Form->Errors(); $Rule->RenderCriteriaInterface($this->Form); // Restore the prefix $this->Form->InputPrefix = $Prefix; - } - else { - echo 'No rule criteria needed.'; - } ?>