Permalink
Browse files

Updated ICF_Model::form_dropdown a little - closes #1 for now

  • Loading branch information...
1 parent 2aa0100 commit 01fb86f75baff6fc94c2da60949ed094c2fd543c Philipp Tempel committed Mar 25, 2012
Showing with 28 additions and 6 deletions.
  1. +28 −6 icf/core/ICF_Model.php
View
34 icf/core/ICF_Model.php
@@ -24,13 +24,12 @@
/**
- * Basic Model for CRUD-Operations on the model's table
+ * Basic Model for CRUD-Operations on a model's table
*
- * This is the basic model from which all other models inherit
- * their basic methods for CRUD-operations on database rows and
- * can even override them.
- * This base model helps maintain a uniform interface to program
- * with and makes module and model creation faster
+ * This is the basic model from which all other models inherit their basic methods
+ * for CRUD-operations on database rows and can even override them. This base model
+ * helps maintain a uniform interface to program with and makes module and model
+ * creation faster
*
*
* @name MY_Model
@@ -836,6 +835,11 @@ public function form_dropdown()
return 'No input name given';
}
+ if ( strtoupper($args['input_name']) == 'PRIMARY' )
+ {
+ $args['input_name'] = $this->_primary['field'];
+ }
+
$args['value'] OR ( $args['value'] = $this->_primary['field'] );
$args['text'] OR ( $args['text'] = $this->_primary['field']);
@@ -866,6 +870,7 @@ public function form_dropdown()
return "No rows to display";
}
+ // Initiate selected-variable so we don't get errors
$selected = NULL;
// That's the array holding our options
@@ -880,10 +885,13 @@ public function form_dropdown()
// Check the arguments for 'text' and 'value' are not empty
if ( ( ! empty($args['args']['prepend']['text']) ) && ( ! empty($args['args']['prepend']['value']) ) )
{
+ // Add the prepend value
$options[$args['args']['prepend']['value']] = $args['args']['prepend']['text'];
+ // And say it's selected by defau;t
$selected = $args['args']['prepend']['value'];
}
+ // No correct format. Screw you developer. Point him towards the error
else
{
return 'Wrong argument for prepend option given';
@@ -892,8 +900,10 @@ public function form_dropdown()
// Just some custom text (looks like controller or model deals with the option-value)
else
{
+ // Add it as first entry in options-array
$options[0] = $args['args']['prepend'];
+ // And select it
$selected = 0;
}
}
@@ -913,8 +923,10 @@ public function form_dropdown()
// Check the arguments for 'text' and 'value' are not empty
if ( ( ! empty($args['args']['append']['text']) ) && ( ! empty($args['args']['append']['value']) ) )
{
+ // Append the value to the array
$options[$args['args']['append']['value']] = $args['args']['append']['text'];
}
+ // Or not, so give the developer a message that he screwed up
else
{
return 'Wrong argument for append option given';
@@ -970,15 +982,25 @@ function_exists('form_dropdown') OR $this->load->helper('form');
$args['input_name'] = $args['input_name'] . $this->input['after'];
}
+ // Check to see if no specific value is selected
if ( ! isset($selected) )
{
+ // Use the form-helper's set_value-function
$selected = set_value($args['input_name'], reset($options));
}
+ // Are any extra-options set?
if ( ! isset($extra) )
{
+ // Nope, initiate extras with empty string
$extra = '';
}
+ // Or do we have an array of extras?
+ elseif ( is_array($extra) )
+ {
+ // Glue the attributes
+ $extra = glue_attributes($extra);
+ }
// Last bu not least build the form dropdown and return it
return form_dropdown($args['input_name'], $options, $selected, $extra);

0 comments on commit 01fb86f

Please sign in to comment.