Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 01fb86f75baff6fc94c2da60949ed094c2fd543c 1 parent 2aa0100
Philipp Tempel philipptempel authored

Showing 1 changed file with 28 additions and 6 deletions. Show diff stats Hide diff stats

  1. +28 6 icf/core/ICF_Model.php
34 icf/core/ICF_Model.php
@@ -24,13 +24,12 @@
24 24
25 25
26 26 /**
27   - * Basic Model for CRUD-Operations on the model's table
  27 + * Basic Model for CRUD-Operations on a model's table
28 28 *
29   - * This is the basic model from which all other models inherit
30   - * their basic methods for CRUD-operations on database rows and
31   - * can even override them.
32   - * This base model helps maintain a uniform interface to program
33   - * with and makes module and model creation faster
  29 + * This is the basic model from which all other models inherit their basic methods
  30 + * for CRUD-operations on database rows and can even override them. This base model
  31 + * helps maintain a uniform interface to program with and makes module and model
  32 + * creation faster
34 33 *
35 34 *
36 35 * @name MY_Model
@@ -836,6 +835,11 @@ public function form_dropdown()
836 835 return 'No input name given';
837 836 }
838 837
  838 + if ( strtoupper($args['input_name']) == 'PRIMARY' )
  839 + {
  840 + $args['input_name'] = $this->_primary['field'];
  841 + }
  842 +
839 843 $args['value'] OR ( $args['value'] = $this->_primary['field'] );
840 844
841 845 $args['text'] OR ( $args['text'] = $this->_primary['field']);
@@ -866,6 +870,7 @@ public function form_dropdown()
866 870 return "No rows to display";
867 871 }
868 872
  873 + // Initiate selected-variable so we don't get errors
869 874 $selected = NULL;
870 875
871 876 // That's the array holding our options
@@ -880,10 +885,13 @@ public function form_dropdown()
880 885 // Check the arguments for 'text' and 'value' are not empty
881 886 if ( ( ! empty($args['args']['prepend']['text']) ) && ( ! empty($args['args']['prepend']['value']) ) )
882 887 {
  888 + // Add the prepend value
883 889 $options[$args['args']['prepend']['value']] = $args['args']['prepend']['text'];
884 890
  891 + // And say it's selected by defau;t
885 892 $selected = $args['args']['prepend']['value'];
886 893 }
  894 + // No correct format. Screw you developer. Point him towards the error
887 895 else
888 896 {
889 897 return 'Wrong argument for prepend option given';
@@ -892,8 +900,10 @@ public function form_dropdown()
892 900 // Just some custom text (looks like controller or model deals with the option-value)
893 901 else
894 902 {
  903 + // Add it as first entry in options-array
895 904 $options[0] = $args['args']['prepend'];
896 905
  906 + // And select it
897 907 $selected = 0;
898 908 }
899 909 }
@@ -913,8 +923,10 @@ public function form_dropdown()
913 923 // Check the arguments for 'text' and 'value' are not empty
914 924 if ( ( ! empty($args['args']['append']['text']) ) && ( ! empty($args['args']['append']['value']) ) )
915 925 {
  926 + // Append the value to the array
916 927 $options[$args['args']['append']['value']] = $args['args']['append']['text'];
917 928 }
  929 + // Or not, so give the developer a message that he screwed up
918 930 else
919 931 {
920 932 return 'Wrong argument for append option given';
@@ -970,15 +982,25 @@ function_exists('form_dropdown') OR $this->load->helper('form');
970 982 $args['input_name'] = $args['input_name'] . $this->input['after'];
971 983 }
972 984
  985 + // Check to see if no specific value is selected
973 986 if ( ! isset($selected) )
974 987 {
  988 + // Use the form-helper's set_value-function
975 989 $selected = set_value($args['input_name'], reset($options));
976 990 }
977 991
  992 + // Are any extra-options set?
978 993 if ( ! isset($extra) )
979 994 {
  995 + // Nope, initiate extras with empty string
980 996 $extra = '';
981 997 }
  998 + // Or do we have an array of extras?
  999 + elseif ( is_array($extra) )
  1000 + {
  1001 + // Glue the attributes
  1002 + $extra = glue_attributes($extra);
  1003 + }
982 1004
983 1005 // Last bu not least build the form dropdown and return it
984 1006 return form_dropdown($args['input_name'], $options, $selected, $extra);

0 comments on commit 01fb86f

Please sign in to comment.
Something went wrong with that request. Please try again.