Render first rule criteria form and require at least one valid rule set to add or edit a badge

This commit is contained in:
Zachary Doll 2013-11-07 17:44:36 -06:00
parent 9d0e1c90a3
commit 154a5b6452
3 changed files with 12 additions and 9 deletions

View File

@ -122,7 +122,9 @@ class BadgesController extends DashboardController {
$this->Form->SetModel($this->BadgeModel); $this->Form->SetModel($this->BadgeModel);
// Only allow editing if some rules exist // Only allow editing if some rules exist
if(!$this->GetRules()) {
throw ForbiddenException('add or edit badges without rules');
}
$Edit = FALSE; $Edit = FALSE;
if($BadgeID) { if($BadgeID) {

View File

@ -11,7 +11,8 @@ interface YagaRule {
* This performs the grunt work of an award rule. Given an expected criteria, * This performs the grunt work of an award rule. Given an expected criteria,
* it determines if a specific user meets muster. * 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 * @param int $UserID
* @return bool True if the user meets the criteria, false otherwise * @return bool True if the user meets the criteria, false otherwise
*/ */

View File

@ -1,12 +1,17 @@
<?php if(!defined('APPLICATION')) exit(); <?php if(!defined('APPLICATION')) exit();
/* Copyright 2013 Zachary Doll */ /* Copyright 2013 Zachary Doll */
// Gnab the rules so we can render the first criteria form by default
$Rules = $this->GetRules();
if(property_exists($this, 'Badge')) { if(property_exists($this, 'Badge')) {
echo Wrap(T('Edit Badge'), 'h1'); echo Wrap(T('Edit Badge'), 'h1');
$RuleClass = $this->Badge->RuleClass; $RuleClass = $this->Badge->RuleClass;
} }
else { else {
echo Wrap(T('Add Badge'), 'h1'); echo Wrap(T('Add Badge'), 'h1');
$RuleClass = ''; reset($Rules);
$RuleClass = key($array);
} }
echo $this->Form->Open(array('enctype' => 'multipart/form-data', 'class' => 'Badge')); echo $this->Form->Open(array('enctype' => 'multipart/form-data', 'class' => 'Badge'));
@ -41,12 +46,11 @@ echo $this->Form->Errors();
<li> <li>
<?php <?php
echo $this->Form->Label('Rule', 'RuleClass'); echo $this->Form->Label('Rule', 'RuleClass');
echo $this->Form->Dropdown('RuleClass', $this->GetRules()); echo $this->Form->Dropdown('RuleClass', $Rules);
?> ?>
</li> </li>
<li id="Rule-Criteria"> <li id="Rule-Criteria">
<?php <?php
if($RuleClass) {
// Save the Prefix for later // Save the Prefix for later
$Prefix = $this->Form->InputPrefix; $Prefix = $this->Form->InputPrefix;
$this->Form->InputPrefix = $Prefix . '_Rules'; $this->Form->InputPrefix = $Prefix . '_Rules';
@ -54,10 +58,6 @@ echo $this->Form->Errors();
$Rule->RenderCriteriaInterface($this->Form); $Rule->RenderCriteriaInterface($this->Form);
// Restore the prefix // Restore the prefix
$this->Form->InputPrefix = $Prefix; $this->Form->InputPrefix = $Prefix;
}
else {
echo 'No rule criteria needed.';
}
?> ?>
</li> </li>
<li> <li>