@@ -11,17 +11,17 @@ |
||
11 | 11 | class EE_Submit_Input extends EE_Form_Input_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $options |
|
16 | - */ |
|
17 | - public function __construct($options = array()) |
|
18 | - { |
|
19 | - if (empty($options['default'])) { |
|
20 | - $options['default'] = esc_html__('Submit', 'event_espresso'); |
|
21 | - } |
|
22 | - $this->_set_display_strategy(new EE_Submit_Input_Display_Strategy()); |
|
23 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
24 | - $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy()); |
|
25 | - parent::__construct($options); |
|
26 | - } |
|
14 | + /** |
|
15 | + * @param array $options |
|
16 | + */ |
|
17 | + public function __construct($options = array()) |
|
18 | + { |
|
19 | + if (empty($options['default'])) { |
|
20 | + $options['default'] = esc_html__('Submit', 'event_espresso'); |
|
21 | + } |
|
22 | + $this->_set_display_strategy(new EE_Submit_Input_Display_Strategy()); |
|
23 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
24 | + $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy()); |
|
25 | + parent::__construct($options); |
|
26 | + } |
|
27 | 27 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | class EE_Checkbox_Multi_Input extends EE_Form_Input_With_Options_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param array $input_settings |
|
19 | - * @param array | EE_Question_Option[] $answer_options |
|
20 | - */ |
|
21 | - public function __construct($answer_options, $input_settings = array()) |
|
22 | - { |
|
23 | - $this->_set_display_strategy(new EE_Checkbox_Display_Strategy()); |
|
24 | - $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array( new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null) ))); |
|
25 | - $this->_multiple_selections = true; |
|
26 | - parent::__construct($answer_options, $input_settings); |
|
27 | - } |
|
17 | + /** |
|
18 | + * @param array $input_settings |
|
19 | + * @param array | EE_Question_Option[] $answer_options |
|
20 | + */ |
|
21 | + public function __construct($answer_options, $input_settings = array()) |
|
22 | + { |
|
23 | + $this->_set_display_strategy(new EE_Checkbox_Display_Strategy()); |
|
24 | + $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array( new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null) ))); |
|
25 | + $this->_multiple_selections = true; |
|
26 | + parent::__construct($answer_options, $input_settings); |
|
27 | + } |
|
28 | 28 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | public function __construct($answer_options, $input_settings = array()) |
22 | 22 | { |
23 | 23 | $this->_set_display_strategy(new EE_Checkbox_Display_Strategy()); |
24 | - $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array( new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null) ))); |
|
24 | + $this->_add_validation_strategy(new EE_Many_Valued_Validation_Strategy(array(new EE_Enum_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null)))); |
|
25 | 25 | $this->_multiple_selections = true; |
26 | 26 | parent::__construct($answer_options, $input_settings); |
27 | 27 | } |
@@ -9,36 +9,36 @@ |
||
9 | 9 | class EE_Month_Input extends EE_Select_Input |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param bool $leading_zero |
|
14 | - * @param array $input_settings |
|
15 | - * @param bool $january_is_month_1 whether january should have value of 1; or it should be month 0 |
|
16 | - */ |
|
17 | - public function __construct($leading_zero = false, $input_settings = array(), $january_is_month_1 = true) |
|
18 | - { |
|
19 | - $key_begin_range = $january_is_month_1 ? 1 : 0; |
|
20 | - $key_range = range($key_begin_range, $key_begin_range + 11); |
|
21 | - if ($leading_zero) { |
|
22 | - array_walk($key_range, array( $this, '_zero_pad' )); |
|
23 | - } |
|
24 | - $value_range = range(1, 12); |
|
25 | - array_walk($value_range, array( $this, '_zero_pad' )); |
|
26 | - parent::__construct( |
|
27 | - array_combine( |
|
28 | - $key_range, |
|
29 | - $value_range |
|
30 | - ), |
|
31 | - $input_settings |
|
32 | - ); |
|
33 | - } |
|
12 | + /** |
|
13 | + * @param bool $leading_zero |
|
14 | + * @param array $input_settings |
|
15 | + * @param bool $january_is_month_1 whether january should have value of 1; or it should be month 0 |
|
16 | + */ |
|
17 | + public function __construct($leading_zero = false, $input_settings = array(), $january_is_month_1 = true) |
|
18 | + { |
|
19 | + $key_begin_range = $january_is_month_1 ? 1 : 0; |
|
20 | + $key_range = range($key_begin_range, $key_begin_range + 11); |
|
21 | + if ($leading_zero) { |
|
22 | + array_walk($key_range, array( $this, '_zero_pad' )); |
|
23 | + } |
|
24 | + $value_range = range(1, 12); |
|
25 | + array_walk($value_range, array( $this, '_zero_pad' )); |
|
26 | + parent::__construct( |
|
27 | + array_combine( |
|
28 | + $key_range, |
|
29 | + $value_range |
|
30 | + ), |
|
31 | + $input_settings |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Changes int 1 to 01, etc. Useful with array_walk |
|
37 | - * @param int $input |
|
38 | - * @param mixed $key |
|
39 | - */ |
|
40 | - protected function _zero_pad(&$input, $key) |
|
41 | - { |
|
42 | - $input = str_pad($input, 2, '0', STR_PAD_LEFT); |
|
43 | - } |
|
35 | + /** |
|
36 | + * Changes int 1 to 01, etc. Useful with array_walk |
|
37 | + * @param int $input |
|
38 | + * @param mixed $key |
|
39 | + */ |
|
40 | + protected function _zero_pad(&$input, $key) |
|
41 | + { |
|
42 | + $input = str_pad($input, 2, '0', STR_PAD_LEFT); |
|
43 | + } |
|
44 | 44 | } |
@@ -19,10 +19,10 @@ |
||
19 | 19 | $key_begin_range = $january_is_month_1 ? 1 : 0; |
20 | 20 | $key_range = range($key_begin_range, $key_begin_range + 11); |
21 | 21 | if ($leading_zero) { |
22 | - array_walk($key_range, array( $this, '_zero_pad' )); |
|
22 | + array_walk($key_range, array($this, '_zero_pad')); |
|
23 | 23 | } |
24 | 24 | $value_range = range(1, 12); |
25 | - array_walk($value_range, array( $this, '_zero_pad' )); |
|
25 | + array_walk($value_range, array($this, '_zero_pad')); |
|
26 | 26 | parent::__construct( |
27 | 27 | array_combine( |
28 | 28 | $key_range, |
@@ -9,13 +9,13 @@ |
||
9 | 9 | class EE_Yes_No_Input extends EE_Select_Input |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param array $options |
|
14 | - */ |
|
15 | - public function __construct($options = array()) |
|
16 | - { |
|
17 | - $select_options = array(true=> __("Yes", "event_espresso"),false=> __("No", "event_espresso")); |
|
12 | + /** |
|
13 | + * @param array $options |
|
14 | + */ |
|
15 | + public function __construct($options = array()) |
|
16 | + { |
|
17 | + $select_options = array(true=> __("Yes", "event_espresso"),false=> __("No", "event_espresso")); |
|
18 | 18 | |
19 | - parent::__construct($select_options, $options); |
|
20 | - } |
|
19 | + parent::__construct($select_options, $options); |
|
20 | + } |
|
21 | 21 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | */ |
15 | 15 | public function __construct($options = array()) |
16 | 16 | { |
17 | - $select_options = array(true=> __("Yes", "event_espresso"),false=> __("No", "event_espresso")); |
|
17 | + $select_options = array(true=> __("Yes", "event_espresso"), false=> __("No", "event_espresso")); |
|
18 | 18 | |
19 | 19 | parent::__construct($select_options, $options); |
20 | 20 | } |
@@ -10,15 +10,15 @@ |
||
10 | 10 | class EE_Credit_Card_Year_Input extends EE_Year_Input |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - * @param bool $four_digit_year |
|
16 | - * @param int $years_behind |
|
17 | - * @param int $years_ahead |
|
18 | - */ |
|
19 | - public function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 0, $years_ahead = 15) |
|
20 | - { |
|
21 | - $this->set_sensitive_data_removal_strategy(new EE_All_Sensitive_Data_Removal()); |
|
22 | - parent::__construct($input_settings, $four_digit_year, $years_behind, $years_ahead); |
|
23 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + * @param bool $four_digit_year |
|
16 | + * @param int $years_behind |
|
17 | + * @param int $years_ahead |
|
18 | + */ |
|
19 | + public function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 0, $years_ahead = 15) |
|
20 | + { |
|
21 | + $this->set_sensitive_data_removal_strategy(new EE_All_Sensitive_Data_Removal()); |
|
22 | + parent::__construct($input_settings, $four_digit_year, $years_behind, $years_ahead); |
|
23 | + } |
|
24 | 24 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | ); |
68 | 68 | // make sure limit and caps are always set |
69 | 69 | $query_params = array_merge( |
70 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
70 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin), |
|
71 | 71 | $query_params |
72 | 72 | ); |
73 | 73 | $this->_value_field_name = EEH_Array::is_set( |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | $values_for_options = (array) $value; |
147 | 147 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
148 | 148 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
149 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
150 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
149 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
150 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
151 | 151 | $display_values = $this->_get_model()->get_all_wpdb_results( |
152 | 152 | array( |
153 | 153 | array( |
154 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
154 | + $this->_value_field_name => array('IN', $values_for_options) |
|
155 | 155 | ) |
156 | 156 | ), |
157 | 157 | ARRAY_A, |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | if (is_array($select_options)) { |
162 | 162 | foreach ($display_values as $db_rows) { |
163 | 163 | $db_rows = (array) $db_rows; |
164 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
164 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
165 | 165 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
166 | - $db_rows[ $this->_display_field_name ], |
|
166 | + $db_rows[$this->_display_field_name], |
|
167 | 167 | $db_rows |
168 | 168 | ); |
169 | 169 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function _get_model() |
181 | 181 | { |
182 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
182 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
183 | 183 | throw new EE_Error( |
184 | 184 | sprintf( |
185 | 185 | __( |
@@ -17,189 +17,189 @@ |
||
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $_model_name |
|
22 | - */ |
|
23 | - protected $_model_name; |
|
20 | + /** |
|
21 | + * @var string $_model_name |
|
22 | + */ |
|
23 | + protected $_model_name; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string $_display_field_name |
|
27 | - */ |
|
28 | - protected $_display_field_name; |
|
25 | + /** |
|
26 | + * @var string $_display_field_name |
|
27 | + */ |
|
28 | + protected $_display_field_name; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var string $_value_field_name |
|
32 | - */ |
|
33 | - protected $_value_field_name; |
|
30 | + /** |
|
31 | + * @var string $_value_field_name |
|
32 | + */ |
|
33 | + protected $_value_field_name; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var array $_extra_select_columns |
|
37 | - */ |
|
38 | - protected $_extra_select_columns = array(); |
|
35 | + /** |
|
36 | + * @var array $_extra_select_columns |
|
37 | + */ |
|
38 | + protected $_extra_select_columns = array(); |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param array $input_settings { |
|
43 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
44 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
45 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
46 | - * the string "where") |
|
47 | - * @type string $value_field_name the name of the model field on this model to |
|
48 | - * be used for the HTML select's option's values |
|
49 | - * @type string $display_field_name the name of the model field on this model |
|
50 | - * to be used for the HTML select's option's display text |
|
51 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
52 | - * } |
|
53 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
54 | - * } |
|
55 | - * @throws EE_Error |
|
56 | - * @throws InvalidArgumentException |
|
57 | - * @throws InvalidDataTypeException |
|
58 | - * @throws InvalidInterfaceException |
|
59 | - */ |
|
60 | - public function __construct($input_settings = array()) |
|
61 | - { |
|
62 | - // needed input settings: |
|
63 | - // select2_args |
|
64 | - $this->_model_name = EEH_Array::is_set( |
|
65 | - $input_settings, |
|
66 | - 'model_name', |
|
67 | - null |
|
68 | - ); |
|
69 | - $model = $this->_get_model(); |
|
70 | - $query_params = EEH_Array::is_set( |
|
71 | - $input_settings, |
|
72 | - 'query_params', |
|
73 | - array() |
|
74 | - ); |
|
75 | - // make sure limit and caps are always set |
|
76 | - $query_params = array_merge( |
|
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
78 | - $query_params |
|
79 | - ); |
|
80 | - $this->_value_field_name = EEH_Array::is_set( |
|
81 | - $input_settings, |
|
82 | - 'value_field_name', |
|
83 | - $model->primary_key_name() |
|
84 | - ); |
|
85 | - $this->_display_field_name = EEH_Array::is_set( |
|
86 | - $input_settings, |
|
87 | - 'display_field_name', |
|
88 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
89 | - ); |
|
90 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
91 | - $input_settings, |
|
92 | - 'extra_select_columns', |
|
93 | - array() |
|
94 | - ); |
|
95 | - $this->_add_validation_strategy( |
|
96 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
97 | - '', |
|
98 | - $this->_model_name, |
|
99 | - $query_params, |
|
100 | - $this->_value_field_name |
|
101 | - ) |
|
102 | - ); |
|
103 | - // get resource endpoint |
|
104 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
105 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
106 | - ); |
|
107 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
108 | - $default_select2_args = array( |
|
109 | - 'ajax' => array( |
|
110 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
111 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
112 | - ), |
|
113 | - 'dataType' => 'json', |
|
114 | - 'delay' => '250', |
|
115 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
116 | - 'data_interface_args' => array( |
|
117 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
118 | - $query_params, |
|
119 | - $model |
|
120 | - ), |
|
121 | - 'display_field' => $this->_display_field_name, |
|
122 | - 'value_field' => $this->_value_field_name, |
|
123 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
124 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
125 | - ), |
|
126 | - ), |
|
127 | - 'cache' => true, |
|
128 | - 'width' => 'resolve' |
|
129 | - ); |
|
130 | - $select2_args = array_replace_recursive( |
|
131 | - $default_select2_args, |
|
132 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
133 | - ); |
|
134 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
135 | - parent::__construct(array(), $input_settings); |
|
136 | - } |
|
41 | + /** |
|
42 | + * @param array $input_settings { |
|
43 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
44 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
45 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
46 | + * the string "where") |
|
47 | + * @type string $value_field_name the name of the model field on this model to |
|
48 | + * be used for the HTML select's option's values |
|
49 | + * @type string $display_field_name the name of the model field on this model |
|
50 | + * to be used for the HTML select's option's display text |
|
51 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
52 | + * } |
|
53 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
54 | + * } |
|
55 | + * @throws EE_Error |
|
56 | + * @throws InvalidArgumentException |
|
57 | + * @throws InvalidDataTypeException |
|
58 | + * @throws InvalidInterfaceException |
|
59 | + */ |
|
60 | + public function __construct($input_settings = array()) |
|
61 | + { |
|
62 | + // needed input settings: |
|
63 | + // select2_args |
|
64 | + $this->_model_name = EEH_Array::is_set( |
|
65 | + $input_settings, |
|
66 | + 'model_name', |
|
67 | + null |
|
68 | + ); |
|
69 | + $model = $this->_get_model(); |
|
70 | + $query_params = EEH_Array::is_set( |
|
71 | + $input_settings, |
|
72 | + 'query_params', |
|
73 | + array() |
|
74 | + ); |
|
75 | + // make sure limit and caps are always set |
|
76 | + $query_params = array_merge( |
|
77 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
78 | + $query_params |
|
79 | + ); |
|
80 | + $this->_value_field_name = EEH_Array::is_set( |
|
81 | + $input_settings, |
|
82 | + 'value_field_name', |
|
83 | + $model->primary_key_name() |
|
84 | + ); |
|
85 | + $this->_display_field_name = EEH_Array::is_set( |
|
86 | + $input_settings, |
|
87 | + 'display_field_name', |
|
88 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
89 | + ); |
|
90 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
91 | + $input_settings, |
|
92 | + 'extra_select_columns', |
|
93 | + array() |
|
94 | + ); |
|
95 | + $this->_add_validation_strategy( |
|
96 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
97 | + '', |
|
98 | + $this->_model_name, |
|
99 | + $query_params, |
|
100 | + $this->_value_field_name |
|
101 | + ) |
|
102 | + ); |
|
103 | + // get resource endpoint |
|
104 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
105 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
106 | + ); |
|
107 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
108 | + $default_select2_args = array( |
|
109 | + 'ajax' => array( |
|
110 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
111 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
112 | + ), |
|
113 | + 'dataType' => 'json', |
|
114 | + 'delay' => '250', |
|
115 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
116 | + 'data_interface_args' => array( |
|
117 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
118 | + $query_params, |
|
119 | + $model |
|
120 | + ), |
|
121 | + 'display_field' => $this->_display_field_name, |
|
122 | + 'value_field' => $this->_value_field_name, |
|
123 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
124 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
125 | + ), |
|
126 | + ), |
|
127 | + 'cache' => true, |
|
128 | + 'width' => 'resolve' |
|
129 | + ); |
|
130 | + $select2_args = array_replace_recursive( |
|
131 | + $default_select2_args, |
|
132 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
133 | + ); |
|
134 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
135 | + parent::__construct(array(), $input_settings); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * Before setting the raw value (usually because we're setting the default, |
|
142 | - * or we've received a form submission and this might be re-displayed to the user), |
|
143 | - * sets the options so that the current selections appear on initial display. |
|
144 | - * |
|
145 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
146 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
147 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
148 | - * |
|
149 | - * @param mixed $value |
|
150 | - * @return void |
|
151 | - * @throws \EE_Error |
|
152 | - */ |
|
153 | - public function _set_raw_value($value) |
|
154 | - { |
|
155 | - $values_for_options = (array) $value; |
|
156 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
157 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
160 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
161 | - array( |
|
162 | - array( |
|
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
164 | - ) |
|
165 | - ), |
|
166 | - ARRAY_A, |
|
167 | - implode(',', $this->_extra_select_columns) |
|
168 | - ); |
|
169 | - $select_options = array(); |
|
170 | - if (is_array($select_options)) { |
|
171 | - foreach ($display_values as $db_rows) { |
|
172 | - $db_rows = (array) $db_rows; |
|
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
174 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
175 | - $db_rows[ $this->_display_field_name ], |
|
176 | - $db_rows |
|
177 | - ); |
|
178 | - } |
|
179 | - } |
|
180 | - $this->set_select_options($select_options); |
|
181 | - parent::_set_raw_value($value); |
|
182 | - } |
|
140 | + /** |
|
141 | + * Before setting the raw value (usually because we're setting the default, |
|
142 | + * or we've received a form submission and this might be re-displayed to the user), |
|
143 | + * sets the options so that the current selections appear on initial display. |
|
144 | + * |
|
145 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
146 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
147 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
148 | + * |
|
149 | + * @param mixed $value |
|
150 | + * @return void |
|
151 | + * @throws \EE_Error |
|
152 | + */ |
|
153 | + public function _set_raw_value($value) |
|
154 | + { |
|
155 | + $values_for_options = (array) $value; |
|
156 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
157 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
160 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
161 | + array( |
|
162 | + array( |
|
163 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
164 | + ) |
|
165 | + ), |
|
166 | + ARRAY_A, |
|
167 | + implode(',', $this->_extra_select_columns) |
|
168 | + ); |
|
169 | + $select_options = array(); |
|
170 | + if (is_array($select_options)) { |
|
171 | + foreach ($display_values as $db_rows) { |
|
172 | + $db_rows = (array) $db_rows; |
|
173 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
174 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
175 | + $db_rows[ $this->_display_field_name ], |
|
176 | + $db_rows |
|
177 | + ); |
|
178 | + } |
|
179 | + } |
|
180 | + $this->set_select_options($select_options); |
|
181 | + parent::_set_raw_value($value); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
186 | - * @return EEM_Base |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - protected function _get_model() |
|
190 | - { |
|
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | - throw new EE_Error( |
|
193 | - sprintf( |
|
194 | - __( |
|
195 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - $this->_model_name |
|
199 | - ) |
|
200 | - ); |
|
201 | - } else { |
|
202 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
203 | - } |
|
204 | - } |
|
184 | + /** |
|
185 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
186 | + * @return EEM_Base |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + protected function _get_model() |
|
190 | + { |
|
191 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | + throw new EE_Error( |
|
193 | + sprintf( |
|
194 | + __( |
|
195 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + $this->_model_name |
|
199 | + ) |
|
200 | + ); |
|
201 | + } else { |
|
202 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
203 | + } |
|
204 | + } |
|
205 | 205 | } |
@@ -10,16 +10,16 @@ |
||
10 | 10 | class EE_Credit_Card_Input extends EE_Form_Input_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - */ |
|
16 | - public function __construct($input_settings = array()) |
|
17 | - { |
|
18 | - $input_settings['required'] = isset($input_settings['required']) ? $input_settings['required'] : true; |
|
19 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy()); |
|
20 | - $this->_set_normalization_strategy(new EE_Credit_Card_Normalization()); |
|
21 | - $this->_add_validation_strategy(new EE_Credit_Card_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null)); |
|
22 | - $this->set_sensitive_data_removal_strategy(new EE_Credit_Card_Sensitive_Data_Removal()); |
|
23 | - parent::__construct($input_settings); |
|
24 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + */ |
|
16 | + public function __construct($input_settings = array()) |
|
17 | + { |
|
18 | + $input_settings['required'] = isset($input_settings['required']) ? $input_settings['required'] : true; |
|
19 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy()); |
|
20 | + $this->_set_normalization_strategy(new EE_Credit_Card_Normalization()); |
|
21 | + $this->_add_validation_strategy(new EE_Credit_Card_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null)); |
|
22 | + $this->set_sensitive_data_removal_strategy(new EE_Credit_Card_Sensitive_Data_Removal()); |
|
23 | + parent::__construct($input_settings); |
|
24 | + } |
|
25 | 25 | } |
@@ -11,321 +11,321 @@ |
||
11 | 11 | class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * array of available options to choose as an answer |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $_options = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * whether to display the html_label_text above the checkbox/radio button options |
|
23 | - * |
|
24 | - * @var boolean |
|
25 | - */ |
|
26 | - protected $_display_html_label_text = true; |
|
27 | - |
|
28 | - /** |
|
29 | - * whether to display an question option description as part of the input label |
|
30 | - * |
|
31 | - * @var boolean |
|
32 | - */ |
|
33 | - protected $_use_desc_in_label = true; |
|
34 | - |
|
35 | - /** |
|
36 | - * strlen() result for the longest input value (what gets displayed in the label) |
|
37 | - * this is used to apply a css class to the input label |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - protected $_label_size = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * whether to enforce the label size value passed in the constructor |
|
45 | - * |
|
46 | - * @var boolean |
|
47 | - */ |
|
48 | - protected $_enforce_label_size = false; |
|
49 | - |
|
50 | - /** |
|
51 | - * whether to allow multiple selections (ie, the value of this input should be an array) |
|
52 | - * or not (ie, the value should be a simple int, string, etc) |
|
53 | - * |
|
54 | - * @var boolean |
|
55 | - */ |
|
56 | - protected $_multiple_selections = false; |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param array $answer_options |
|
62 | - * @param array $input_settings { |
|
63 | - * @type int|string $label_size |
|
64 | - * @type boolean $display_html_label_text |
|
65 | - * } |
|
66 | - * And all the options accepted by EE_Form_Input_Base |
|
67 | - */ |
|
68 | - public function __construct($answer_options = array(), $input_settings = array()) |
|
69 | - { |
|
70 | - if (isset($input_settings['label_size'])) { |
|
71 | - $this->_set_label_size($input_settings['label_size']); |
|
72 | - if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
73 | - $this->_enforce_label_size = true; |
|
74 | - } |
|
75 | - } |
|
76 | - if (isset($input_settings['display_html_label_text'])) { |
|
77 | - $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
78 | - } |
|
79 | - $this->set_select_options($answer_options); |
|
80 | - parent::__construct($input_settings); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Sets the allowed options for this input. Also has the side-effect of |
|
87 | - * updating the normalization strategy to match the keys provided in the array |
|
88 | - * |
|
89 | - * @param array $answer_options |
|
90 | - * @return void just has the side-effect of setting the options for this input |
|
91 | - */ |
|
92 | - public function set_select_options($answer_options = array()) |
|
93 | - { |
|
94 | - $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
95 | - // get the first item in the select options and check it's type |
|
96 | - $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
97 | - ? $this->_process_question_options($answer_options) |
|
98 | - : $answer_options; |
|
99 | - // d( $this->_options ); |
|
100 | - $select_option_keys = array_keys($this->_options); |
|
101 | - // attempt to determine data type for values in order to set normalization type |
|
102 | - // purposefully only |
|
103 | - if (count($this->_options) === 2 |
|
104 | - && ( |
|
105 | - (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
106 | - || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
107 | - ) |
|
108 | - ) { |
|
109 | - // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
110 | - $normalization = new EE_Boolean_Normalization(); |
|
111 | - } else { |
|
112 | - // are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
113 | - $all_ints = true; |
|
114 | - array_walk_recursive( |
|
115 | - $this->_options, |
|
116 | - function ($value, $key) use (&$all_ints) { |
|
117 | - // is this a top-level key? ignore it |
|
118 | - if (! is_array($value) |
|
119 | - && ! is_int($key) |
|
120 | - && $key !== '' |
|
121 | - && $key !== null) { |
|
122 | - $all_ints = false; |
|
123 | - } |
|
124 | - } |
|
125 | - ); |
|
126 | - if ($all_ints) { |
|
127 | - $normalization = new EE_Int_Normalization(); |
|
128 | - } else { |
|
129 | - $normalization = new EE_Text_Normalization(); |
|
130 | - } |
|
131 | - } |
|
132 | - // does input type have multiple options ? |
|
133 | - if ($this->_multiple_selections) { |
|
134 | - $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
135 | - } else { |
|
136 | - $this->_set_normalization_strategy($normalization); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function options() |
|
146 | - { |
|
147 | - return $this->_options; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns an array which is guaranteed to not be multidimensional |
|
154 | - * |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - public function flat_options() |
|
158 | - { |
|
159 | - return $this->_flatten_select_options($this->options()); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Makes sure $arr is a flat array, not a multidimensional one |
|
166 | - * |
|
167 | - * @param array $arr |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - protected function _flatten_select_options($arr) |
|
171 | - { |
|
172 | - $flat_array = array(); |
|
173 | - if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
174 | - foreach ($arr as $sub_array) { |
|
175 | - foreach ((array) $sub_array as $key => $value) { |
|
176 | - $flat_array[ $key ] = $value; |
|
177 | - $this->_set_label_size($value); |
|
178 | - } |
|
179 | - } |
|
180 | - } else { |
|
181 | - foreach ($arr as $key => $value) { |
|
182 | - $flat_array[ $key ] = $value; |
|
183 | - $this->_set_label_size($value); |
|
184 | - } |
|
185 | - } |
|
186 | - return $flat_array; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param EE_Question_Option[] $question_options_array |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - protected function _process_question_options($question_options_array = array()) |
|
196 | - { |
|
197 | - $flat_array = array(); |
|
198 | - foreach ($question_options_array as $question_option) { |
|
199 | - if ($question_option instanceof EE_Question_Option) { |
|
200 | - $desc = ''; |
|
201 | - if ($this->_use_desc_in_label) { |
|
202 | - $desc = $question_option->desc(); |
|
203 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
204 | - } |
|
205 | - $value = $question_option->value(); |
|
206 | - // add value even if it's empty |
|
207 | - $flat_array[ $value ] = $value; |
|
208 | - // if both value and desc are not empty, then separate with a dash |
|
209 | - if (! empty($value) && ! empty($desc)) { |
|
210 | - $flat_array[ $value ] .= ' - ' . $desc; |
|
211 | - } else { |
|
212 | - // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
213 | - $flat_array[ $value ] .= $desc; |
|
214 | - } |
|
215 | - } elseif (is_array($question_option)) { |
|
216 | - $flat_array += $this->_flatten_select_options($question_option); |
|
217 | - } |
|
218 | - } |
|
219 | - return $flat_array; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * set_label_sizes |
|
226 | - * |
|
227 | - * @return void |
|
228 | - */ |
|
229 | - public function set_label_sizes() |
|
230 | - { |
|
231 | - // did the input settings specifically say to NOT set the label size dynamically ? |
|
232 | - if (! $this->_enforce_label_size) { |
|
233 | - foreach ($this->_options as $option) { |
|
234 | - // calculate the strlen of the label |
|
235 | - $this->_set_label_size($option); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * _set_label_size_class |
|
244 | - * |
|
245 | - * @param int|string $value |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - private function _set_label_size($value = '') |
|
249 | - { |
|
250 | - // don't change label size if it has already been set and is being enforced |
|
251 | - if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
252 | - return; |
|
253 | - } |
|
254 | - // determine length of option value |
|
255 | - $val_size = is_int($value) ? $value : strlen($value); |
|
256 | - // use new value if bigger than existing |
|
257 | - $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * get_label_size_class |
|
264 | - * |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function get_label_size_class() |
|
268 | - { |
|
269 | - $size = ' medium-lbl'; |
|
270 | - // use maximum option value length to determine label size |
|
271 | - if ($this->_label_size < 3) { |
|
272 | - $size = ' nano-lbl'; |
|
273 | - } elseif ($this->_label_size < 6) { |
|
274 | - $size = ' micro-lbl'; |
|
275 | - } elseif ($this->_label_size < 12) { |
|
276 | - $size = ' tiny-lbl'; |
|
277 | - } elseif ($this->_label_size < 25) { |
|
278 | - $size = ' small-lbl'; |
|
279 | - } elseif ($this->_label_size < 50) { |
|
280 | - $size = ' medium-lbl'; |
|
281 | - } elseif ($this->_label_size >= 100) { |
|
282 | - $size = ' big-lbl'; |
|
283 | - } |
|
284 | - return $size; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Returns the pretty value for the normalized value |
|
291 | - * |
|
292 | - * @return string |
|
293 | - */ |
|
294 | - public function pretty_value() |
|
295 | - { |
|
296 | - $options = $this->flat_options(); |
|
297 | - $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
298 | - if (! $this->_multiple_selections) { |
|
299 | - $unnormalized_value_choices = array($unnormalized_value_choices); |
|
300 | - } |
|
301 | - $pretty_strings = array(); |
|
302 | - foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
303 | - if (isset($options[ $unnormalized_value_choice ])) { |
|
304 | - $pretty_strings[] = $options[ $unnormalized_value_choice ]; |
|
305 | - } else { |
|
306 | - $pretty_strings[] = $this->normalized_value(); |
|
307 | - } |
|
308 | - } |
|
309 | - return implode(', ', $pretty_strings); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @return boolean |
|
316 | - */ |
|
317 | - public function display_html_label_text() |
|
318 | - { |
|
319 | - return $this->_display_html_label_text; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @param boolean $display_html_label_text |
|
326 | - */ |
|
327 | - public function set_display_html_label_text($display_html_label_text) |
|
328 | - { |
|
329 | - $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
330 | - } |
|
14 | + /** |
|
15 | + * array of available options to choose as an answer |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $_options = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * whether to display the html_label_text above the checkbox/radio button options |
|
23 | + * |
|
24 | + * @var boolean |
|
25 | + */ |
|
26 | + protected $_display_html_label_text = true; |
|
27 | + |
|
28 | + /** |
|
29 | + * whether to display an question option description as part of the input label |
|
30 | + * |
|
31 | + * @var boolean |
|
32 | + */ |
|
33 | + protected $_use_desc_in_label = true; |
|
34 | + |
|
35 | + /** |
|
36 | + * strlen() result for the longest input value (what gets displayed in the label) |
|
37 | + * this is used to apply a css class to the input label |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + protected $_label_size = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * whether to enforce the label size value passed in the constructor |
|
45 | + * |
|
46 | + * @var boolean |
|
47 | + */ |
|
48 | + protected $_enforce_label_size = false; |
|
49 | + |
|
50 | + /** |
|
51 | + * whether to allow multiple selections (ie, the value of this input should be an array) |
|
52 | + * or not (ie, the value should be a simple int, string, etc) |
|
53 | + * |
|
54 | + * @var boolean |
|
55 | + */ |
|
56 | + protected $_multiple_selections = false; |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param array $answer_options |
|
62 | + * @param array $input_settings { |
|
63 | + * @type int|string $label_size |
|
64 | + * @type boolean $display_html_label_text |
|
65 | + * } |
|
66 | + * And all the options accepted by EE_Form_Input_Base |
|
67 | + */ |
|
68 | + public function __construct($answer_options = array(), $input_settings = array()) |
|
69 | + { |
|
70 | + if (isset($input_settings['label_size'])) { |
|
71 | + $this->_set_label_size($input_settings['label_size']); |
|
72 | + if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
73 | + $this->_enforce_label_size = true; |
|
74 | + } |
|
75 | + } |
|
76 | + if (isset($input_settings['display_html_label_text'])) { |
|
77 | + $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
78 | + } |
|
79 | + $this->set_select_options($answer_options); |
|
80 | + parent::__construct($input_settings); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Sets the allowed options for this input. Also has the side-effect of |
|
87 | + * updating the normalization strategy to match the keys provided in the array |
|
88 | + * |
|
89 | + * @param array $answer_options |
|
90 | + * @return void just has the side-effect of setting the options for this input |
|
91 | + */ |
|
92 | + public function set_select_options($answer_options = array()) |
|
93 | + { |
|
94 | + $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
95 | + // get the first item in the select options and check it's type |
|
96 | + $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
97 | + ? $this->_process_question_options($answer_options) |
|
98 | + : $answer_options; |
|
99 | + // d( $this->_options ); |
|
100 | + $select_option_keys = array_keys($this->_options); |
|
101 | + // attempt to determine data type for values in order to set normalization type |
|
102 | + // purposefully only |
|
103 | + if (count($this->_options) === 2 |
|
104 | + && ( |
|
105 | + (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
106 | + || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
107 | + ) |
|
108 | + ) { |
|
109 | + // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
110 | + $normalization = new EE_Boolean_Normalization(); |
|
111 | + } else { |
|
112 | + // are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
113 | + $all_ints = true; |
|
114 | + array_walk_recursive( |
|
115 | + $this->_options, |
|
116 | + function ($value, $key) use (&$all_ints) { |
|
117 | + // is this a top-level key? ignore it |
|
118 | + if (! is_array($value) |
|
119 | + && ! is_int($key) |
|
120 | + && $key !== '' |
|
121 | + && $key !== null) { |
|
122 | + $all_ints = false; |
|
123 | + } |
|
124 | + } |
|
125 | + ); |
|
126 | + if ($all_ints) { |
|
127 | + $normalization = new EE_Int_Normalization(); |
|
128 | + } else { |
|
129 | + $normalization = new EE_Text_Normalization(); |
|
130 | + } |
|
131 | + } |
|
132 | + // does input type have multiple options ? |
|
133 | + if ($this->_multiple_selections) { |
|
134 | + $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
135 | + } else { |
|
136 | + $this->_set_normalization_strategy($normalization); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function options() |
|
146 | + { |
|
147 | + return $this->_options; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns an array which is guaranteed to not be multidimensional |
|
154 | + * |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + public function flat_options() |
|
158 | + { |
|
159 | + return $this->_flatten_select_options($this->options()); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Makes sure $arr is a flat array, not a multidimensional one |
|
166 | + * |
|
167 | + * @param array $arr |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + protected function _flatten_select_options($arr) |
|
171 | + { |
|
172 | + $flat_array = array(); |
|
173 | + if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
174 | + foreach ($arr as $sub_array) { |
|
175 | + foreach ((array) $sub_array as $key => $value) { |
|
176 | + $flat_array[ $key ] = $value; |
|
177 | + $this->_set_label_size($value); |
|
178 | + } |
|
179 | + } |
|
180 | + } else { |
|
181 | + foreach ($arr as $key => $value) { |
|
182 | + $flat_array[ $key ] = $value; |
|
183 | + $this->_set_label_size($value); |
|
184 | + } |
|
185 | + } |
|
186 | + return $flat_array; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param EE_Question_Option[] $question_options_array |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + protected function _process_question_options($question_options_array = array()) |
|
196 | + { |
|
197 | + $flat_array = array(); |
|
198 | + foreach ($question_options_array as $question_option) { |
|
199 | + if ($question_option instanceof EE_Question_Option) { |
|
200 | + $desc = ''; |
|
201 | + if ($this->_use_desc_in_label) { |
|
202 | + $desc = $question_option->desc(); |
|
203 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
204 | + } |
|
205 | + $value = $question_option->value(); |
|
206 | + // add value even if it's empty |
|
207 | + $flat_array[ $value ] = $value; |
|
208 | + // if both value and desc are not empty, then separate with a dash |
|
209 | + if (! empty($value) && ! empty($desc)) { |
|
210 | + $flat_array[ $value ] .= ' - ' . $desc; |
|
211 | + } else { |
|
212 | + // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
213 | + $flat_array[ $value ] .= $desc; |
|
214 | + } |
|
215 | + } elseif (is_array($question_option)) { |
|
216 | + $flat_array += $this->_flatten_select_options($question_option); |
|
217 | + } |
|
218 | + } |
|
219 | + return $flat_array; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * set_label_sizes |
|
226 | + * |
|
227 | + * @return void |
|
228 | + */ |
|
229 | + public function set_label_sizes() |
|
230 | + { |
|
231 | + // did the input settings specifically say to NOT set the label size dynamically ? |
|
232 | + if (! $this->_enforce_label_size) { |
|
233 | + foreach ($this->_options as $option) { |
|
234 | + // calculate the strlen of the label |
|
235 | + $this->_set_label_size($option); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * _set_label_size_class |
|
244 | + * |
|
245 | + * @param int|string $value |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + private function _set_label_size($value = '') |
|
249 | + { |
|
250 | + // don't change label size if it has already been set and is being enforced |
|
251 | + if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
252 | + return; |
|
253 | + } |
|
254 | + // determine length of option value |
|
255 | + $val_size = is_int($value) ? $value : strlen($value); |
|
256 | + // use new value if bigger than existing |
|
257 | + $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * get_label_size_class |
|
264 | + * |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function get_label_size_class() |
|
268 | + { |
|
269 | + $size = ' medium-lbl'; |
|
270 | + // use maximum option value length to determine label size |
|
271 | + if ($this->_label_size < 3) { |
|
272 | + $size = ' nano-lbl'; |
|
273 | + } elseif ($this->_label_size < 6) { |
|
274 | + $size = ' micro-lbl'; |
|
275 | + } elseif ($this->_label_size < 12) { |
|
276 | + $size = ' tiny-lbl'; |
|
277 | + } elseif ($this->_label_size < 25) { |
|
278 | + $size = ' small-lbl'; |
|
279 | + } elseif ($this->_label_size < 50) { |
|
280 | + $size = ' medium-lbl'; |
|
281 | + } elseif ($this->_label_size >= 100) { |
|
282 | + $size = ' big-lbl'; |
|
283 | + } |
|
284 | + return $size; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Returns the pretty value for the normalized value |
|
291 | + * |
|
292 | + * @return string |
|
293 | + */ |
|
294 | + public function pretty_value() |
|
295 | + { |
|
296 | + $options = $this->flat_options(); |
|
297 | + $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
298 | + if (! $this->_multiple_selections) { |
|
299 | + $unnormalized_value_choices = array($unnormalized_value_choices); |
|
300 | + } |
|
301 | + $pretty_strings = array(); |
|
302 | + foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
303 | + if (isset($options[ $unnormalized_value_choice ])) { |
|
304 | + $pretty_strings[] = $options[ $unnormalized_value_choice ]; |
|
305 | + } else { |
|
306 | + $pretty_strings[] = $this->normalized_value(); |
|
307 | + } |
|
308 | + } |
|
309 | + return implode(', ', $pretty_strings); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @return boolean |
|
316 | + */ |
|
317 | + public function display_html_label_text() |
|
318 | + { |
|
319 | + return $this->_display_html_label_text; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @param boolean $display_html_label_text |
|
326 | + */ |
|
327 | + public function set_display_html_label_text($display_html_label_text) |
|
328 | + { |
|
329 | + $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
330 | + } |
|
331 | 331 | } |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | $all_ints = true; |
114 | 114 | array_walk_recursive( |
115 | 115 | $this->_options, |
116 | - function ($value, $key) use (&$all_ints) { |
|
116 | + function($value, $key) use (&$all_ints) { |
|
117 | 117 | // is this a top-level key? ignore it |
118 | - if (! is_array($value) |
|
118 | + if ( ! is_array($value) |
|
119 | 119 | && ! is_int($key) |
120 | 120 | && $key !== '' |
121 | 121 | && $key !== null) { |
@@ -173,13 +173,13 @@ discard block |
||
173 | 173 | if (EEH_Array::is_multi_dimensional_array($arr)) { |
174 | 174 | foreach ($arr as $sub_array) { |
175 | 175 | foreach ((array) $sub_array as $key => $value) { |
176 | - $flat_array[ $key ] = $value; |
|
176 | + $flat_array[$key] = $value; |
|
177 | 177 | $this->_set_label_size($value); |
178 | 178 | } |
179 | 179 | } |
180 | 180 | } else { |
181 | 181 | foreach ($arr as $key => $value) { |
182 | - $flat_array[ $key ] = $value; |
|
182 | + $flat_array[$key] = $value; |
|
183 | 183 | $this->_set_label_size($value); |
184 | 184 | } |
185 | 185 | } |
@@ -200,17 +200,17 @@ discard block |
||
200 | 200 | $desc = ''; |
201 | 201 | if ($this->_use_desc_in_label) { |
202 | 202 | $desc = $question_option->desc(); |
203 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
203 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : ''; |
|
204 | 204 | } |
205 | 205 | $value = $question_option->value(); |
206 | 206 | // add value even if it's empty |
207 | - $flat_array[ $value ] = $value; |
|
207 | + $flat_array[$value] = $value; |
|
208 | 208 | // if both value and desc are not empty, then separate with a dash |
209 | - if (! empty($value) && ! empty($desc)) { |
|
210 | - $flat_array[ $value ] .= ' - ' . $desc; |
|
209 | + if ( ! empty($value) && ! empty($desc)) { |
|
210 | + $flat_array[$value] .= ' - '.$desc; |
|
211 | 211 | } else { |
212 | 212 | // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
213 | - $flat_array[ $value ] .= $desc; |
|
213 | + $flat_array[$value] .= $desc; |
|
214 | 214 | } |
215 | 215 | } elseif (is_array($question_option)) { |
216 | 216 | $flat_array += $this->_flatten_select_options($question_option); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | public function set_label_sizes() |
230 | 230 | { |
231 | 231 | // did the input settings specifically say to NOT set the label size dynamically ? |
232 | - if (! $this->_enforce_label_size) { |
|
232 | + if ( ! $this->_enforce_label_size) { |
|
233 | 233 | foreach ($this->_options as $option) { |
234 | 234 | // calculate the strlen of the label |
235 | 235 | $this->_set_label_size($option); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | private function _set_label_size($value = '') |
249 | 249 | { |
250 | 250 | // don't change label size if it has already been set and is being enforced |
251 | - if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
251 | + if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | // determine length of option value |
@@ -295,13 +295,13 @@ discard block |
||
295 | 295 | { |
296 | 296 | $options = $this->flat_options(); |
297 | 297 | $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
298 | - if (! $this->_multiple_selections) { |
|
298 | + if ( ! $this->_multiple_selections) { |
|
299 | 299 | $unnormalized_value_choices = array($unnormalized_value_choices); |
300 | 300 | } |
301 | 301 | $pretty_strings = array(); |
302 | 302 | foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
303 | - if (isset($options[ $unnormalized_value_choice ])) { |
|
304 | - $pretty_strings[] = $options[ $unnormalized_value_choice ]; |
|
303 | + if (isset($options[$unnormalized_value_choice])) { |
|
304 | + $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
305 | 305 | } else { |
306 | 306 | $pretty_strings[] = $this->normalized_value(); |
307 | 307 | } |
@@ -12,35 +12,35 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @param array $input_settings |
|
17 | - */ |
|
18 | - public function __construct($input_settings = array()) |
|
19 | - { |
|
20 | - $this->_set_display_strategy( |
|
21 | - new EE_Number_Input_Display_Strategy( |
|
22 | - isset($input_settings['min_value']) |
|
23 | - ? $input_settings['min_value'] |
|
24 | - : null, |
|
25 | - isset($input_settings['max_value']) |
|
26 | - ? $input_settings['max_value'] |
|
27 | - : null |
|
28 | - ) |
|
29 | - ); |
|
30 | - $this->_set_normalization_strategy( |
|
31 | - new EE_Int_Normalization( |
|
32 | - isset($input_settings['validation_error_message']) |
|
33 | - ? $input_settings['validation_error_message'] |
|
34 | - : null |
|
35 | - ) |
|
36 | - ); |
|
37 | - $this->_add_validation_strategy( |
|
38 | - new EE_Int_Validation_Strategy( |
|
39 | - isset($input_settings['validation_error_message']) |
|
40 | - ? $input_settings['validation_error_message'] |
|
41 | - : null |
|
42 | - ) |
|
43 | - ); |
|
44 | - parent::__construct($input_settings); |
|
45 | - } |
|
15 | + /** |
|
16 | + * @param array $input_settings |
|
17 | + */ |
|
18 | + public function __construct($input_settings = array()) |
|
19 | + { |
|
20 | + $this->_set_display_strategy( |
|
21 | + new EE_Number_Input_Display_Strategy( |
|
22 | + isset($input_settings['min_value']) |
|
23 | + ? $input_settings['min_value'] |
|
24 | + : null, |
|
25 | + isset($input_settings['max_value']) |
|
26 | + ? $input_settings['max_value'] |
|
27 | + : null |
|
28 | + ) |
|
29 | + ); |
|
30 | + $this->_set_normalization_strategy( |
|
31 | + new EE_Int_Normalization( |
|
32 | + isset($input_settings['validation_error_message']) |
|
33 | + ? $input_settings['validation_error_message'] |
|
34 | + : null |
|
35 | + ) |
|
36 | + ); |
|
37 | + $this->_add_validation_strategy( |
|
38 | + new EE_Int_Validation_Strategy( |
|
39 | + isset($input_settings['validation_error_message']) |
|
40 | + ? $input_settings['validation_error_message'] |
|
41 | + : null |
|
42 | + ) |
|
43 | + ); |
|
44 | + parent::__construct($input_settings); |
|
45 | + } |
|
46 | 46 | } |