@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $all_ints = true; |
116 | 116 | array_walk_recursive( |
117 | 117 | $this->_options, |
118 | - function ($value, $key) use (&$all_ints) { |
|
118 | + function($value, $key) use (&$all_ints) { |
|
119 | 119 | // is this a top-level key? ignore it |
120 | 120 | if ( |
121 | 121 | ! is_array($value) |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | if (EEH_Array::is_multi_dimensional_array($arr)) { |
178 | 178 | foreach ($arr as $sub_array) { |
179 | 179 | foreach ((array) $sub_array as $key => $value) { |
180 | - $flat_array[ $key ] = $value; |
|
180 | + $flat_array[$key] = $value; |
|
181 | 181 | $this->_set_label_size($value); |
182 | 182 | } |
183 | 183 | } |
184 | 184 | } else { |
185 | 185 | foreach ($arr as $key => $value) { |
186 | - $flat_array[ $key ] = $value; |
|
186 | + $flat_array[$key] = $value; |
|
187 | 187 | $this->_set_label_size($value); |
188 | 188 | } |
189 | 189 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | $desc = ''; |
205 | 205 | if ($this->_use_desc_in_label) { |
206 | 206 | $desc = $question_option->desc(); |
207 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
207 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : ''; |
|
208 | 208 | } |
209 | 209 | $value = $question_option->value(); |
210 | 210 | // add value even if it's empty |
211 | - $flat_array[ $value ] = $value; |
|
211 | + $flat_array[$value] = $value; |
|
212 | 212 | // if both value and desc are not empty, then separate with a dash |
213 | - if (! empty($value) && ! empty($desc)) { |
|
214 | - $flat_array[ $value ] .= ' - ' . $desc; |
|
213 | + if ( ! empty($value) && ! empty($desc)) { |
|
214 | + $flat_array[$value] .= ' - '.$desc; |
|
215 | 215 | } else { |
216 | 216 | // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
217 | - $flat_array[ $value ] .= $desc; |
|
217 | + $flat_array[$value] .= $desc; |
|
218 | 218 | } |
219 | 219 | } elseif (is_array($question_option)) { |
220 | 220 | $flat_array += $this->_flatten_select_options($question_option); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | public function set_label_sizes() |
234 | 234 | { |
235 | 235 | // did the input settings specifically say to NOT set the label size dynamically ? |
236 | - if (! $this->_enforce_label_size) { |
|
236 | + if ( ! $this->_enforce_label_size) { |
|
237 | 237 | foreach ($this->_options as $option) { |
238 | 238 | // calculate the strlen of the label |
239 | 239 | $this->_set_label_size($option); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | private function _set_label_size($value = '') |
253 | 253 | { |
254 | 254 | // don't change label size if it has already been set and is being enforced |
255 | - if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
255 | + if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | // determine length of option value |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | { |
300 | 300 | $options = $this->flat_options(); |
301 | 301 | $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
302 | - if (! $this->_multiple_selections) { |
|
302 | + if ( ! $this->_multiple_selections) { |
|
303 | 303 | $unnormalized_value_choices = array($unnormalized_value_choices); |
304 | 304 | } |
305 | 305 | $pretty_strings = array(); |
306 | 306 | foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
307 | - if (isset($options[ $unnormalized_value_choice ])) { |
|
308 | - $pretty_strings[] = $options[ $unnormalized_value_choice ]; |
|
307 | + if (isset($options[$unnormalized_value_choice])) { |
|
308 | + $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
309 | 309 | } else { |
310 | 310 | $pretty_strings[] = $this->normalized_value(); |
311 | 311 | } |
@@ -11,324 +11,324 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base |
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 ( |
|
104 | - count($this->_options) === 2 |
|
105 | - && ( |
|
106 | - (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
107 | - || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
108 | - ) |
|
109 | - ) { |
|
110 | - // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
111 | - $normalization = new EE_Boolean_Normalization(); |
|
112 | - } else { |
|
113 | - // are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
114 | - $all_ints = true; |
|
115 | - array_walk_recursive( |
|
116 | - $this->_options, |
|
117 | - function ($value, $key) use (&$all_ints) { |
|
118 | - // is this a top-level key? ignore it |
|
119 | - if ( |
|
120 | - ! is_array($value) |
|
121 | - && ! is_int($key) |
|
122 | - && $key !== '' |
|
123 | - && $key !== null |
|
124 | - ) { |
|
125 | - $all_ints = false; |
|
126 | - } |
|
127 | - } |
|
128 | - ); |
|
129 | - if ($all_ints) { |
|
130 | - $normalization = new EE_Int_Normalization(); |
|
131 | - } else { |
|
132 | - $normalization = new EE_Text_Normalization(); |
|
133 | - } |
|
134 | - } |
|
135 | - // does input type have multiple options ? |
|
136 | - if ($this->_multiple_selections) { |
|
137 | - $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
138 | - } else { |
|
139 | - $this->_set_normalization_strategy($normalization); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function options() |
|
149 | - { |
|
150 | - return $this->_options; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Returns an array which is guaranteed to not be multidimensional |
|
157 | - * |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - public function flat_options() |
|
161 | - { |
|
162 | - return $this->_flatten_select_options($this->options()); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Makes sure $arr is a flat array, not a multidimensional one |
|
169 | - * |
|
170 | - * @param array $arr |
|
171 | - * @return array |
|
172 | - */ |
|
173 | - protected function _flatten_select_options($arr) |
|
174 | - { |
|
175 | - $flat_array = array(); |
|
176 | - if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
177 | - foreach ($arr as $sub_array) { |
|
178 | - foreach ((array) $sub_array as $key => $value) { |
|
179 | - $flat_array[ $key ] = $value; |
|
180 | - $this->_set_label_size($value); |
|
181 | - } |
|
182 | - } |
|
183 | - } else { |
|
184 | - foreach ($arr as $key => $value) { |
|
185 | - $flat_array[ $key ] = $value; |
|
186 | - $this->_set_label_size($value); |
|
187 | - } |
|
188 | - } |
|
189 | - return $flat_array; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @param EE_Question_Option[] $question_options_array |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - protected function _process_question_options($question_options_array = array()) |
|
199 | - { |
|
200 | - $flat_array = array(); |
|
201 | - foreach ($question_options_array as $question_option) { |
|
202 | - if ($question_option instanceof EE_Question_Option) { |
|
203 | - $desc = ''; |
|
204 | - if ($this->_use_desc_in_label) { |
|
205 | - $desc = $question_option->desc(); |
|
206 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
207 | - } |
|
208 | - $value = $question_option->value(); |
|
209 | - // add value even if it's empty |
|
210 | - $flat_array[ $value ] = $value; |
|
211 | - // if both value and desc are not empty, then separate with a dash |
|
212 | - if (! empty($value) && ! empty($desc)) { |
|
213 | - $flat_array[ $value ] .= ' - ' . $desc; |
|
214 | - } else { |
|
215 | - // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
216 | - $flat_array[ $value ] .= $desc; |
|
217 | - } |
|
218 | - } elseif (is_array($question_option)) { |
|
219 | - $flat_array += $this->_flatten_select_options($question_option); |
|
220 | - } |
|
221 | - } |
|
222 | - return $flat_array; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * set_label_sizes |
|
229 | - * |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public function set_label_sizes() |
|
233 | - { |
|
234 | - // did the input settings specifically say to NOT set the label size dynamically ? |
|
235 | - if (! $this->_enforce_label_size) { |
|
236 | - foreach ($this->_options as $option) { |
|
237 | - // calculate the strlen of the label |
|
238 | - $this->_set_label_size($option); |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * _set_label_size_class |
|
247 | - * |
|
248 | - * @param int|string $value |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - private function _set_label_size($value = '') |
|
252 | - { |
|
253 | - // don't change label size if it has already been set and is being enforced |
|
254 | - if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
255 | - return; |
|
256 | - } |
|
257 | - // determine length of option value |
|
258 | - $val_size = is_int($value) ? $value : strlen($value); |
|
259 | - // use new value if bigger than existing |
|
260 | - $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * get_label_size_class |
|
267 | - * |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function get_label_size_class() |
|
271 | - { |
|
272 | - $size = ' medium-lbl'; |
|
273 | - // use maximum option value length to determine label size |
|
274 | - if ($this->_label_size < 3) { |
|
275 | - $size = ' nano-lbl'; |
|
276 | - } elseif ($this->_label_size < 6) { |
|
277 | - $size = ' micro-lbl'; |
|
278 | - } elseif ($this->_label_size < 12) { |
|
279 | - $size = ' tiny-lbl'; |
|
280 | - } elseif ($this->_label_size < 25) { |
|
281 | - $size = ' small-lbl'; |
|
282 | - } elseif ($this->_label_size < 50) { |
|
283 | - $size = ' medium-lbl'; |
|
284 | - } elseif ($this->_label_size >= 100) { |
|
285 | - $size = ' big-lbl'; |
|
286 | - } |
|
287 | - return $size; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Returns the pretty value for the normalized value |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function pretty_value() |
|
298 | - { |
|
299 | - $options = $this->flat_options(); |
|
300 | - $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
301 | - if (! $this->_multiple_selections) { |
|
302 | - $unnormalized_value_choices = array($unnormalized_value_choices); |
|
303 | - } |
|
304 | - $pretty_strings = array(); |
|
305 | - foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
306 | - if (isset($options[ $unnormalized_value_choice ])) { |
|
307 | - $pretty_strings[] = $options[ $unnormalized_value_choice ]; |
|
308 | - } else { |
|
309 | - $pretty_strings[] = $this->normalized_value(); |
|
310 | - } |
|
311 | - } |
|
312 | - return implode(', ', $pretty_strings); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @return boolean |
|
319 | - */ |
|
320 | - public function display_html_label_text() |
|
321 | - { |
|
322 | - return $this->_display_html_label_text; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @param boolean $display_html_label_text |
|
329 | - */ |
|
330 | - public function set_display_html_label_text($display_html_label_text) |
|
331 | - { |
|
332 | - $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
333 | - } |
|
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 ( |
|
104 | + count($this->_options) === 2 |
|
105 | + && ( |
|
106 | + (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
107 | + || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
108 | + ) |
|
109 | + ) { |
|
110 | + // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
111 | + $normalization = new EE_Boolean_Normalization(); |
|
112 | + } else { |
|
113 | + // are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
114 | + $all_ints = true; |
|
115 | + array_walk_recursive( |
|
116 | + $this->_options, |
|
117 | + function ($value, $key) use (&$all_ints) { |
|
118 | + // is this a top-level key? ignore it |
|
119 | + if ( |
|
120 | + ! is_array($value) |
|
121 | + && ! is_int($key) |
|
122 | + && $key !== '' |
|
123 | + && $key !== null |
|
124 | + ) { |
|
125 | + $all_ints = false; |
|
126 | + } |
|
127 | + } |
|
128 | + ); |
|
129 | + if ($all_ints) { |
|
130 | + $normalization = new EE_Int_Normalization(); |
|
131 | + } else { |
|
132 | + $normalization = new EE_Text_Normalization(); |
|
133 | + } |
|
134 | + } |
|
135 | + // does input type have multiple options ? |
|
136 | + if ($this->_multiple_selections) { |
|
137 | + $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
138 | + } else { |
|
139 | + $this->_set_normalization_strategy($normalization); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function options() |
|
149 | + { |
|
150 | + return $this->_options; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Returns an array which is guaranteed to not be multidimensional |
|
157 | + * |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + public function flat_options() |
|
161 | + { |
|
162 | + return $this->_flatten_select_options($this->options()); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Makes sure $arr is a flat array, not a multidimensional one |
|
169 | + * |
|
170 | + * @param array $arr |
|
171 | + * @return array |
|
172 | + */ |
|
173 | + protected function _flatten_select_options($arr) |
|
174 | + { |
|
175 | + $flat_array = array(); |
|
176 | + if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
177 | + foreach ($arr as $sub_array) { |
|
178 | + foreach ((array) $sub_array as $key => $value) { |
|
179 | + $flat_array[ $key ] = $value; |
|
180 | + $this->_set_label_size($value); |
|
181 | + } |
|
182 | + } |
|
183 | + } else { |
|
184 | + foreach ($arr as $key => $value) { |
|
185 | + $flat_array[ $key ] = $value; |
|
186 | + $this->_set_label_size($value); |
|
187 | + } |
|
188 | + } |
|
189 | + return $flat_array; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @param EE_Question_Option[] $question_options_array |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + protected function _process_question_options($question_options_array = array()) |
|
199 | + { |
|
200 | + $flat_array = array(); |
|
201 | + foreach ($question_options_array as $question_option) { |
|
202 | + if ($question_option instanceof EE_Question_Option) { |
|
203 | + $desc = ''; |
|
204 | + if ($this->_use_desc_in_label) { |
|
205 | + $desc = $question_option->desc(); |
|
206 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
207 | + } |
|
208 | + $value = $question_option->value(); |
|
209 | + // add value even if it's empty |
|
210 | + $flat_array[ $value ] = $value; |
|
211 | + // if both value and desc are not empty, then separate with a dash |
|
212 | + if (! empty($value) && ! empty($desc)) { |
|
213 | + $flat_array[ $value ] .= ' - ' . $desc; |
|
214 | + } else { |
|
215 | + // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
216 | + $flat_array[ $value ] .= $desc; |
|
217 | + } |
|
218 | + } elseif (is_array($question_option)) { |
|
219 | + $flat_array += $this->_flatten_select_options($question_option); |
|
220 | + } |
|
221 | + } |
|
222 | + return $flat_array; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * set_label_sizes |
|
229 | + * |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public function set_label_sizes() |
|
233 | + { |
|
234 | + // did the input settings specifically say to NOT set the label size dynamically ? |
|
235 | + if (! $this->_enforce_label_size) { |
|
236 | + foreach ($this->_options as $option) { |
|
237 | + // calculate the strlen of the label |
|
238 | + $this->_set_label_size($option); |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * _set_label_size_class |
|
247 | + * |
|
248 | + * @param int|string $value |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + private function _set_label_size($value = '') |
|
252 | + { |
|
253 | + // don't change label size if it has already been set and is being enforced |
|
254 | + if ($this->_enforce_label_size && $this->_label_size > 0) { |
|
255 | + return; |
|
256 | + } |
|
257 | + // determine length of option value |
|
258 | + $val_size = is_int($value) ? $value : strlen($value); |
|
259 | + // use new value if bigger than existing |
|
260 | + $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * get_label_size_class |
|
267 | + * |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function get_label_size_class() |
|
271 | + { |
|
272 | + $size = ' medium-lbl'; |
|
273 | + // use maximum option value length to determine label size |
|
274 | + if ($this->_label_size < 3) { |
|
275 | + $size = ' nano-lbl'; |
|
276 | + } elseif ($this->_label_size < 6) { |
|
277 | + $size = ' micro-lbl'; |
|
278 | + } elseif ($this->_label_size < 12) { |
|
279 | + $size = ' tiny-lbl'; |
|
280 | + } elseif ($this->_label_size < 25) { |
|
281 | + $size = ' small-lbl'; |
|
282 | + } elseif ($this->_label_size < 50) { |
|
283 | + $size = ' medium-lbl'; |
|
284 | + } elseif ($this->_label_size >= 100) { |
|
285 | + $size = ' big-lbl'; |
|
286 | + } |
|
287 | + return $size; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Returns the pretty value for the normalized value |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function pretty_value() |
|
298 | + { |
|
299 | + $options = $this->flat_options(); |
|
300 | + $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
301 | + if (! $this->_multiple_selections) { |
|
302 | + $unnormalized_value_choices = array($unnormalized_value_choices); |
|
303 | + } |
|
304 | + $pretty_strings = array(); |
|
305 | + foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
306 | + if (isset($options[ $unnormalized_value_choice ])) { |
|
307 | + $pretty_strings[] = $options[ $unnormalized_value_choice ]; |
|
308 | + } else { |
|
309 | + $pretty_strings[] = $this->normalized_value(); |
|
310 | + } |
|
311 | + } |
|
312 | + return implode(', ', $pretty_strings); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @return boolean |
|
319 | + */ |
|
320 | + public function display_html_label_text() |
|
321 | + { |
|
322 | + return $this->_display_html_label_text; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @param boolean $display_html_label_text |
|
329 | + */ |
|
330 | + public function set_display_html_label_text($display_html_label_text) |
|
331 | + { |
|
332 | + $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
333 | + } |
|
334 | 334 | } |
@@ -11,18 +11,18 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_CCV_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base |
13 | 13 | { |
14 | - public function remove_sensitive_data($normalized_value) |
|
15 | - { |
|
16 | - // Get the ccv Length |
|
17 | - $ccv_lenght = strlen($normalized_value); |
|
18 | - // Replace all characters of credit card except the last four and dashes |
|
19 | - for ($i = 0; $i < $ccv_lenght; $i++) { |
|
20 | - if ($normalized_value[ $i ] == '-') { |
|
21 | - continue; |
|
22 | - } |
|
23 | - $normalized_value[ $i ] = 'X'; |
|
24 | - } |
|
25 | - // Return the masked Credit Card # |
|
26 | - return $normalized_value; |
|
27 | - } |
|
14 | + public function remove_sensitive_data($normalized_value) |
|
15 | + { |
|
16 | + // Get the ccv Length |
|
17 | + $ccv_lenght = strlen($normalized_value); |
|
18 | + // Replace all characters of credit card except the last four and dashes |
|
19 | + for ($i = 0; $i < $ccv_lenght; $i++) { |
|
20 | + if ($normalized_value[ $i ] == '-') { |
|
21 | + continue; |
|
22 | + } |
|
23 | + $normalized_value[ $i ] = 'X'; |
|
24 | + } |
|
25 | + // Return the masked Credit Card # |
|
26 | + return $normalized_value; |
|
27 | + } |
|
28 | 28 | } |
@@ -17,10 +17,10 @@ |
||
17 | 17 | $ccv_lenght = strlen($normalized_value); |
18 | 18 | // Replace all characters of credit card except the last four and dashes |
19 | 19 | for ($i = 0; $i < $ccv_lenght; $i++) { |
20 | - if ($normalized_value[ $i ] == '-') { |
|
20 | + if ($normalized_value[$i] == '-') { |
|
21 | 21 | continue; |
22 | 22 | } |
23 | - $normalized_value[ $i ] = 'X'; |
|
23 | + $normalized_value[$i] = 'X'; |
|
24 | 24 | } |
25 | 25 | // Return the masked Credit Card # |
26 | 26 | return $normalized_value; |
@@ -11,18 +11,18 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Credit_Card_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base |
13 | 13 | { |
14 | - public function remove_sensitive_data($normalized_value) |
|
15 | - { |
|
16 | - // Get the cc Length |
|
17 | - $cc_length = strlen($normalized_value); |
|
18 | - // Replace all characters of credit card except the last four and dashes |
|
19 | - for ($i = 0; $i < $cc_length - 4; $i++) { |
|
20 | - if ($normalized_value[ $i ] == '-') { |
|
21 | - continue; |
|
22 | - } |
|
23 | - $normalized_value[ $i ] = 'X'; |
|
24 | - } |
|
25 | - // Return the masked Credit Card # |
|
26 | - return $normalized_value; |
|
27 | - } |
|
14 | + public function remove_sensitive_data($normalized_value) |
|
15 | + { |
|
16 | + // Get the cc Length |
|
17 | + $cc_length = strlen($normalized_value); |
|
18 | + // Replace all characters of credit card except the last four and dashes |
|
19 | + for ($i = 0; $i < $cc_length - 4; $i++) { |
|
20 | + if ($normalized_value[ $i ] == '-') { |
|
21 | + continue; |
|
22 | + } |
|
23 | + $normalized_value[ $i ] = 'X'; |
|
24 | + } |
|
25 | + // Return the masked Credit Card # |
|
26 | + return $normalized_value; |
|
27 | + } |
|
28 | 28 | } |
@@ -17,10 +17,10 @@ |
||
17 | 17 | $cc_length = strlen($normalized_value); |
18 | 18 | // Replace all characters of credit card except the last four and dashes |
19 | 19 | for ($i = 0; $i < $cc_length - 4; $i++) { |
20 | - if ($normalized_value[ $i ] == '-') { |
|
20 | + if ($normalized_value[$i] == '-') { |
|
21 | 21 | continue; |
22 | 22 | } |
23 | - $normalized_value[ $i ] = 'X'; |
|
23 | + $normalized_value[$i] = 'X'; |
|
24 | 24 | } |
25 | 25 | // Return the masked Credit Card # |
26 | 26 | return $normalized_value; |
@@ -44,7 +44,7 @@ |
||
44 | 44 | public function get_jquery_validation_rule_array() |
45 | 45 | { |
46 | 46 | if ($this->_max_length !== EE_INF) { |
47 | - return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) ); |
|
47 | + return array('maxlength' => $this->_max_length, 'messages' => array('maxlength' => $this->get_validation_error_message())); |
|
48 | 48 | } else { |
49 | 49 | return array(); |
50 | 50 | } |
@@ -11,41 +11,41 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base |
13 | 13 | { |
14 | - protected $_max_length; |
|
14 | + protected $_max_length; |
|
15 | 15 | |
16 | - public function __construct($validation_error_message = null, $max_length = EE_INF) |
|
17 | - { |
|
18 | - $this->_max_length = $max_length; |
|
19 | - if ($validation_error_message === null) { |
|
20 | - $validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length); |
|
21 | - } |
|
22 | - parent::__construct($validation_error_message); |
|
23 | - } |
|
16 | + public function __construct($validation_error_message = null, $max_length = EE_INF) |
|
17 | + { |
|
18 | + $this->_max_length = $max_length; |
|
19 | + if ($validation_error_message === null) { |
|
20 | + $validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length); |
|
21 | + } |
|
22 | + parent::__construct($validation_error_message); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param $normalized_value |
|
27 | - */ |
|
28 | - public function validate($normalized_value) |
|
29 | - { |
|
30 | - if ( |
|
31 | - $this->_max_length !== EE_INF && |
|
32 | - $normalized_value && |
|
33 | - is_string($normalized_value) && |
|
34 | - strlen($normalized_value) > $this->_max_length |
|
35 | - ) { |
|
36 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength'); |
|
37 | - } |
|
38 | - } |
|
25 | + /** |
|
26 | + * @param $normalized_value |
|
27 | + */ |
|
28 | + public function validate($normalized_value) |
|
29 | + { |
|
30 | + if ( |
|
31 | + $this->_max_length !== EE_INF && |
|
32 | + $normalized_value && |
|
33 | + is_string($normalized_value) && |
|
34 | + strlen($normalized_value) > $this->_max_length |
|
35 | + ) { |
|
36 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength'); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function get_jquery_validation_rule_array() |
|
44 | - { |
|
45 | - if ($this->_max_length !== EE_INF) { |
|
46 | - return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) ); |
|
47 | - } else { |
|
48 | - return array(); |
|
49 | - } |
|
50 | - } |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function get_jquery_validation_rule_array() |
|
44 | + { |
|
45 | + if ($this->_max_length !== EE_INF) { |
|
46 | + return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) ); |
|
47 | + } else { |
|
48 | + return array(); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |
@@ -40,6 +40,6 @@ |
||
40 | 40 | */ |
41 | 41 | public function get_jquery_validation_rule_array() |
42 | 42 | { |
43 | - return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) ); |
|
43 | + return array('minlength' => $this->_min_length, 'messages' => array('minlength' => $this->get_validation_error_message())); |
|
44 | 44 | } |
45 | 45 | } |
@@ -11,34 +11,34 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Min_Length_Validation_Strategy extends EE_Validation_Strategy_Base |
13 | 13 | { |
14 | - protected $_min_length; |
|
14 | + protected $_min_length; |
|
15 | 15 | |
16 | - public function __construct($validation_error_message = null, $min_length = 0) |
|
17 | - { |
|
18 | - $this->_min_length = $min_length; |
|
19 | - parent::__construct($validation_error_message); |
|
20 | - } |
|
16 | + public function __construct($validation_error_message = null, $min_length = 0) |
|
17 | + { |
|
18 | + $this->_min_length = $min_length; |
|
19 | + parent::__construct($validation_error_message); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param $normalized_value |
|
24 | - */ |
|
25 | - public function validate($normalized_value) |
|
26 | - { |
|
27 | - if ( |
|
28 | - $this->_min_length > 0 && |
|
29 | - $normalized_value && |
|
30 | - is_string($normalized_value) && |
|
31 | - strlen($normalized_value) < $this->_min_length |
|
32 | - ) { |
|
33 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength'); |
|
34 | - } |
|
35 | - } |
|
22 | + /** |
|
23 | + * @param $normalized_value |
|
24 | + */ |
|
25 | + public function validate($normalized_value) |
|
26 | + { |
|
27 | + if ( |
|
28 | + $this->_min_length > 0 && |
|
29 | + $normalized_value && |
|
30 | + is_string($normalized_value) && |
|
31 | + strlen($normalized_value) < $this->_min_length |
|
32 | + ) { |
|
33 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength'); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function get_jquery_validation_rule_array() |
|
41 | - { |
|
42 | - return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) ); |
|
43 | - } |
|
37 | + /** |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function get_jquery_validation_rule_array() |
|
41 | + { |
|
42 | + return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) ); |
|
43 | + } |
|
44 | 44 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | public function validate($normalized_value) |
30 | 30 | { |
31 | 31 | $string_normalized_value = (string) $normalized_value; |
32 | - if ($this->_regex && $string_normalized_value) { |
|
33 | - if (! preg_match($this->_regex, $string_normalized_value)) { |
|
32 | + if ($this->_regex && $string_normalized_value) { |
|
33 | + if ( ! preg_match($this->_regex, $string_normalized_value)) { |
|
34 | 34 | throw new EE_Validation_Error($this->get_validation_error_message(), 'regex'); |
35 | 35 | } |
36 | 36 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function get_jquery_validation_rule_array() |
43 | 43 | { |
44 | 44 | if ($this->_regex !== null) { |
45 | - return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) ); |
|
45 | + return array('regex' => $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message())); |
|
46 | 46 | } else { |
47 | 47 | return array(); |
48 | 48 | } |
@@ -10,53 +10,53 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base |
12 | 12 | { |
13 | - protected $_regex = null; |
|
14 | - /** |
|
15 | - * |
|
16 | - * @param string $validation_error_message |
|
17 | - * @param string $regex a PHP regex; the javascript regex will be derived from this |
|
18 | - */ |
|
19 | - public function __construct($validation_error_message = null, $regex = null) |
|
20 | - { |
|
21 | - $this->_regex = $regex; |
|
22 | - parent::__construct($validation_error_message); |
|
23 | - } |
|
13 | + protected $_regex = null; |
|
14 | + /** |
|
15 | + * |
|
16 | + * @param string $validation_error_message |
|
17 | + * @param string $regex a PHP regex; the javascript regex will be derived from this |
|
18 | + */ |
|
19 | + public function __construct($validation_error_message = null, $regex = null) |
|
20 | + { |
|
21 | + $this->_regex = $regex; |
|
22 | + parent::__construct($validation_error_message); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param $normalized_value |
|
27 | - */ |
|
28 | - public function validate($normalized_value) |
|
29 | - { |
|
30 | - $string_normalized_value = (string) $normalized_value; |
|
31 | - if ($this->_regex && $string_normalized_value) { |
|
32 | - if (! preg_match($this->_regex, $string_normalized_value)) { |
|
33 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'regex'); |
|
34 | - } |
|
35 | - } |
|
36 | - } |
|
25 | + /** |
|
26 | + * @param $normalized_value |
|
27 | + */ |
|
28 | + public function validate($normalized_value) |
|
29 | + { |
|
30 | + $string_normalized_value = (string) $normalized_value; |
|
31 | + if ($this->_regex && $string_normalized_value) { |
|
32 | + if (! preg_match($this->_regex, $string_normalized_value)) { |
|
33 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'regex'); |
|
34 | + } |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function get_jquery_validation_rule_array() |
|
42 | - { |
|
43 | - if ($this->_regex !== null) { |
|
44 | - return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) ); |
|
45 | - } else { |
|
46 | - return array(); |
|
47 | - } |
|
48 | - } |
|
38 | + /** |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function get_jquery_validation_rule_array() |
|
42 | + { |
|
43 | + if ($this->_regex !== null) { |
|
44 | + return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) ); |
|
45 | + } else { |
|
46 | + return array(); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas |
52 | 52 | * javscript does not |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - public function regex_js() |
|
56 | - { |
|
57 | - // first character must be the delimiter |
|
58 | - $delimeter = $this->_regex[0]; |
|
59 | - $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter); |
|
60 | - return substr($this->_regex, 1, $last_occurence_of_delimieter - 1); |
|
61 | - } |
|
55 | + public function regex_js() |
|
56 | + { |
|
57 | + // first character must be the delimiter |
|
58 | + $delimeter = $this->_regex[0]; |
|
59 | + $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter); |
|
60 | + return substr($this->_regex, 1, $last_occurence_of_delimieter - 1); |
|
61 | + } |
|
62 | 62 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function form($for_display = false) |
173 | 173 | { |
174 | - if (! $this->formIsValid()) { |
|
174 | + if ( ! $this->formIsValid()) { |
|
175 | 175 | return null; |
176 | 176 | } |
177 | 177 | if ($for_display) { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public function setFormName($form_name) |
276 | 276 | { |
277 | - if (! is_string($form_name)) { |
|
277 | + if ( ! is_string($form_name)) { |
|
278 | 278 | throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
279 | 279 | } |
280 | 280 | $this->form_name = $form_name; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function setAdminName($admin_name) |
300 | 300 | { |
301 | - if (! is_string($admin_name)) { |
|
301 | + if ( ! is_string($admin_name)) { |
|
302 | 302 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
303 | 303 | } |
304 | 304 | $this->admin_name = $admin_name; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function setSlug($slug) |
324 | 324 | { |
325 | - if (! is_string($slug)) { |
|
325 | + if ( ! is_string($slug)) { |
|
326 | 326 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
327 | 327 | } |
328 | 328 | $this->slug = $slug; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function setSubmitBtnText($submit_btn_text) |
347 | 347 | { |
348 | - if (! is_string($submit_btn_text)) { |
|
348 | + if ( ! is_string($submit_btn_text)) { |
|
349 | 349 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
350 | 350 | } |
351 | 351 | if (empty($submit_btn_text)) { |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function setFormAction($form_action) |
376 | 376 | { |
377 | - if (! is_string($form_action)) { |
|
377 | + if ( ! is_string($form_action)) { |
|
378 | 378 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
379 | 379 | } |
380 | 380 | $this->form_action = $form_action; |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
494 | 494 | return new EE_Submit_Input( |
495 | 495 | array( |
496 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
497 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
497 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
498 | 498 | 'html_class' => 'ee-form-submit', |
499 | 499 | 'html_label' => ' ', |
500 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
500 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
501 | 501 | 'default' => $text, |
502 | 502 | ) |
503 | 503 | ); |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public function appendSubmitButton($text = '') |
515 | 515 | { |
516 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
516 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | $this->form->add_subsections( |
520 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
520 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
521 | 521 | null, |
522 | 522 | false |
523 | 523 | ); |
@@ -534,11 +534,11 @@ discard block |
||
534 | 534 | { |
535 | 535 | $cancel_button = new EE_Submit_Input( |
536 | 536 | array( |
537 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
538 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
538 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
539 | 539 | 'html_class' => 'ee-cancel-form', |
540 | 540 | 'html_label' => ' ', |
541 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
541 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
542 | 542 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
543 | 543 | ) |
544 | 544 | ); |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | $this->form->add_subsections( |
559 | 559 | array( |
560 | 560 | 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
561 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
561 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
562 | 562 | ), |
563 | 563 | ), |
564 | 564 | null, |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | */ |
645 | 645 | public function process($submitted_form_data = array()) |
646 | 646 | { |
647 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
647 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
648 | 648 | throw new InvalidFormSubmissionException($this->form_name); |
649 | 649 | } |
650 | 650 | $this->form(true)->receive_form_submission($submitted_form_data); |
651 | - if (! $this->form()->is_valid()) { |
|
651 | + if ( ! $this->form()->is_valid()) { |
|
652 | 652 | throw new InvalidFormSubmissionException( |
653 | 653 | $this->form_name, |
654 | 654 | sprintf( |
@@ -29,642 +29,642 @@ |
||
29 | 29 | */ |
30 | 30 | abstract class FormHandler implements FormHandlerInterface |
31 | 31 | { |
32 | - /** |
|
33 | - * will add opening and closing HTML form tags as well as a submit button |
|
34 | - */ |
|
35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | - |
|
37 | - /** |
|
38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
39 | - */ |
|
40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | - |
|
42 | - /** |
|
43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | - */ |
|
45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | - |
|
47 | - /** |
|
48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | - */ |
|
50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | - |
|
52 | - /** |
|
53 | - * if set to false, then this form has no displayable content, |
|
54 | - * and will only be used for processing data sent passed via GET or POST |
|
55 | - * defaults to true ( ie: form has displayable content ) |
|
56 | - * |
|
57 | - * @var boolean $displayable |
|
58 | - */ |
|
59 | - private $displayable = true; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $form_name |
|
63 | - */ |
|
64 | - private $form_name; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $admin_name |
|
68 | - */ |
|
69 | - private $admin_name; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string $slug |
|
73 | - */ |
|
74 | - private $slug; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string $submit_btn_text |
|
78 | - */ |
|
79 | - private $submit_btn_text; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string $form_action |
|
83 | - */ |
|
84 | - private $form_action; |
|
85 | - |
|
86 | - /** |
|
87 | - * form params in key value pairs |
|
88 | - * can be added to form action URL or as hidden inputs |
|
89 | - * |
|
90 | - * @var array $form_args |
|
91 | - */ |
|
92 | - private $form_args = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * value of one of the string constant above |
|
96 | - * |
|
97 | - * @var string $form_config |
|
98 | - */ |
|
99 | - private $form_config; |
|
100 | - |
|
101 | - /** |
|
102 | - * whether or not the form was determined to be invalid |
|
103 | - * |
|
104 | - * @var boolean $form_has_errors |
|
105 | - */ |
|
106 | - private $form_has_errors; |
|
107 | - |
|
108 | - /** |
|
109 | - * the absolute top level form section being used on the page |
|
110 | - * |
|
111 | - * @var EE_Form_Section_Proper $form |
|
112 | - */ |
|
113 | - private $form; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var EE_Registry $registry |
|
117 | - */ |
|
118 | - protected $registry; |
|
119 | - |
|
120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Form constructor. |
|
125 | - * |
|
126 | - * @param string $form_name |
|
127 | - * @param string $admin_name |
|
128 | - * @param string $slug |
|
129 | - * @param string $form_action |
|
130 | - * @param string $form_config |
|
131 | - * @param EE_Registry|null $registry |
|
132 | - */ |
|
133 | - public function __construct( |
|
134 | - $form_name, |
|
135 | - $admin_name, |
|
136 | - $slug, |
|
137 | - $form_action = '', |
|
138 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
139 | - EE_Registry $registry = null |
|
140 | - ) { |
|
141 | - $this->setFormName($form_name); |
|
142 | - $this->setAdminName($admin_name); |
|
143 | - $this->setSlug($slug); |
|
144 | - $this->setFormAction($form_action); |
|
145 | - $this->setFormConfig($form_config); |
|
146 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
147 | - $this->registry = $registry; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public static function getFormConfigConstants() |
|
155 | - { |
|
156 | - return array( |
|
157 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
158 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
159 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
160 | - FormHandler::DO_NOT_SETUP_FORM, |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param bool $for_display |
|
167 | - * @return EE_Form_Section_Proper |
|
168 | - * @throws EE_Error |
|
169 | - * @throws LogicException |
|
170 | - */ |
|
171 | - public function form($for_display = false) |
|
172 | - { |
|
173 | - if (! $this->formIsValid()) { |
|
174 | - return null; |
|
175 | - } |
|
176 | - if ($for_display) { |
|
177 | - $form_config = $this->formConfig(); |
|
178 | - if ( |
|
179 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
180 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
181 | - ) { |
|
182 | - $this->appendSubmitButton(); |
|
183 | - $this->clearFormButtonFloats(); |
|
184 | - } |
|
185 | - } |
|
186 | - return $this->form; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @return boolean |
|
192 | - * @throws LogicException |
|
193 | - */ |
|
194 | - public function formIsValid() |
|
195 | - { |
|
196 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
197 | - return true; |
|
198 | - } |
|
199 | - $form = apply_filters( |
|
200 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
201 | - $this->generate(), |
|
202 | - $this |
|
203 | - ); |
|
204 | - if ($this->verifyForm($form)) { |
|
205 | - $this->setForm($form); |
|
206 | - } |
|
207 | - return true; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param EE_Form_Section_Proper|null $form |
|
213 | - * @return bool |
|
214 | - * @throws LogicException |
|
215 | - */ |
|
216 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
217 | - { |
|
218 | - $form = $form !== null ? $form : $this->form; |
|
219 | - if ($form instanceof EE_Form_Section_Proper) { |
|
220 | - return true; |
|
221 | - } |
|
222 | - throw new LogicException( |
|
223 | - sprintf( |
|
224 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
225 | - $this->form_name, |
|
226 | - var_export($form, true) |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param EE_Form_Section_Proper $form |
|
234 | - */ |
|
235 | - public function setForm(EE_Form_Section_Proper $form) |
|
236 | - { |
|
237 | - $this->form = $form; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return boolean |
|
243 | - */ |
|
244 | - public function displayable() |
|
245 | - { |
|
246 | - return $this->displayable; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param boolean $displayable |
|
252 | - */ |
|
253 | - public function setDisplayable($displayable = false) |
|
254 | - { |
|
255 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * a public name for the form that can be displayed on the frontend of a site |
|
261 | - * |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function formName() |
|
265 | - { |
|
266 | - return $this->form_name; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @param string $form_name |
|
272 | - * @throws InvalidDataTypeException |
|
273 | - */ |
|
274 | - public function setFormName($form_name) |
|
275 | - { |
|
276 | - if (! is_string($form_name)) { |
|
277 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
278 | - } |
|
279 | - $this->form_name = $form_name; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * a public name for the form that can be displayed, but only in the admin |
|
285 | - * |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function adminName() |
|
289 | - { |
|
290 | - return $this->admin_name; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $admin_name |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - */ |
|
298 | - public function setAdminName($admin_name) |
|
299 | - { |
|
300 | - if (! is_string($admin_name)) { |
|
301 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
302 | - } |
|
303 | - $this->admin_name = $admin_name; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * a URL friendly string that can be used for identifying the form |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function slug() |
|
313 | - { |
|
314 | - return $this->slug; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @param string $slug |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - */ |
|
322 | - public function setSlug($slug) |
|
323 | - { |
|
324 | - if (! is_string($slug)) { |
|
325 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
326 | - } |
|
327 | - $this->slug = $slug; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function submitBtnText() |
|
335 | - { |
|
336 | - return $this->submit_btn_text; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * @param string $submit_btn_text |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidArgumentException |
|
344 | - */ |
|
345 | - public function setSubmitBtnText($submit_btn_text) |
|
346 | - { |
|
347 | - if (! is_string($submit_btn_text)) { |
|
348 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
349 | - } |
|
350 | - if (empty($submit_btn_text)) { |
|
351 | - throw new InvalidArgumentException( |
|
352 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
353 | - ); |
|
354 | - } |
|
355 | - $this->submit_btn_text = $submit_btn_text; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - public function formAction() |
|
363 | - { |
|
364 | - return ! empty($this->form_args) |
|
365 | - ? add_query_arg($this->form_args, $this->form_action) |
|
366 | - : $this->form_action; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param string $form_action |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - */ |
|
374 | - public function setFormAction($form_action) |
|
375 | - { |
|
376 | - if (! is_string($form_action)) { |
|
377 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
378 | - } |
|
379 | - $this->form_action = $form_action; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @param array $form_args |
|
385 | - * @throws InvalidDataTypeException |
|
386 | - * @throws InvalidArgumentException |
|
387 | - */ |
|
388 | - public function addFormActionArgs($form_args = array()) |
|
389 | - { |
|
390 | - if (is_object($form_args)) { |
|
391 | - throw new InvalidDataTypeException( |
|
392 | - '$form_args', |
|
393 | - $form_args, |
|
394 | - 'anything other than an object was expected.' |
|
395 | - ); |
|
396 | - } |
|
397 | - if (empty($form_args)) { |
|
398 | - throw new InvalidArgumentException( |
|
399 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
400 | - ); |
|
401 | - } |
|
402 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public function formConfig() |
|
410 | - { |
|
411 | - return $this->form_config; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $form_config |
|
417 | - * @throws DomainException |
|
418 | - */ |
|
419 | - public function setFormConfig($form_config) |
|
420 | - { |
|
421 | - if ( |
|
422 | - ! in_array( |
|
423 | - $form_config, |
|
424 | - array( |
|
425 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
426 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
427 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
428 | - FormHandler::DO_NOT_SETUP_FORM, |
|
429 | - ), |
|
430 | - true |
|
431 | - ) |
|
432 | - ) { |
|
433 | - throw new DomainException( |
|
434 | - sprintf( |
|
435 | - esc_html__( |
|
436 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
437 | - 'event_espresso' |
|
438 | - ), |
|
439 | - $form_config |
|
440 | - ) |
|
441 | - ); |
|
442 | - } |
|
443 | - $this->form_config = $form_config; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * called after the form is instantiated |
|
449 | - * and used for performing any logic that needs to occur early |
|
450 | - * before any of the other methods are called. |
|
451 | - * returns true if everything is ok to proceed, |
|
452 | - * and false if no further form logic should be implemented |
|
453 | - * |
|
454 | - * @return boolean |
|
455 | - */ |
|
456 | - public function initialize() |
|
457 | - { |
|
458 | - $this->form_has_errors = EE_Error::has_error(true); |
|
459 | - return true; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * used for setting up css and js |
|
465 | - * |
|
466 | - * @return void |
|
467 | - * @throws LogicException |
|
468 | - * @throws EE_Error |
|
469 | - */ |
|
470 | - public function enqueueStylesAndScripts() |
|
471 | - { |
|
472 | - $this->form()->enqueue_js(); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * creates and returns the actual form |
|
478 | - * |
|
479 | - * @return EE_Form_Section_Proper |
|
480 | - */ |
|
481 | - abstract public function generate(); |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
486 | - * |
|
487 | - * @param string $text |
|
488 | - * @return EE_Submit_Input |
|
489 | - */ |
|
490 | - public function generateSubmitButton($text = '') |
|
491 | - { |
|
492 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
493 | - return new EE_Submit_Input( |
|
494 | - array( |
|
495 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
496 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
497 | - 'html_class' => 'ee-form-submit', |
|
498 | - 'html_label' => ' ', |
|
499 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
500 | - 'default' => $text, |
|
501 | - ) |
|
502 | - ); |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
508 | - * |
|
509 | - * @param string $text |
|
510 | - * @return void |
|
511 | - * @throws EE_Error |
|
512 | - */ |
|
513 | - public function appendSubmitButton($text = '') |
|
514 | - { |
|
515 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
516 | - return; |
|
517 | - } |
|
518 | - $this->form->add_subsections( |
|
519 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
520 | - null, |
|
521 | - false |
|
522 | - ); |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
528 | - * |
|
529 | - * @param string $text |
|
530 | - * @return EE_Submit_Input |
|
531 | - */ |
|
532 | - public function generateCancelButton($text = '') |
|
533 | - { |
|
534 | - $cancel_button = new EE_Submit_Input( |
|
535 | - array( |
|
536 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
537 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
538 | - 'html_class' => 'ee-cancel-form', |
|
539 | - 'html_label' => ' ', |
|
540 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
541 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
542 | - ) |
|
543 | - ); |
|
544 | - $cancel_button->set_button_css_attributes(false); |
|
545 | - return $cancel_button; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * appends a float clearing div onto end of form |
|
551 | - * |
|
552 | - * @return void |
|
553 | - * @throws EE_Error |
|
554 | - */ |
|
555 | - public function clearFormButtonFloats() |
|
556 | - { |
|
557 | - $this->form->add_subsections( |
|
558 | - array( |
|
559 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
560 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
561 | - ), |
|
562 | - ), |
|
563 | - null, |
|
564 | - false |
|
565 | - ); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
571 | - * returns a string of HTML that can be directly echoed in a template |
|
572 | - * |
|
573 | - * @return string |
|
574 | - * @throws InvalidArgumentException |
|
575 | - * @throws InvalidInterfaceException |
|
576 | - * @throws InvalidDataTypeException |
|
577 | - * @throws LogicException |
|
578 | - * @throws EE_Error |
|
579 | - */ |
|
580 | - public function display() |
|
581 | - { |
|
582 | - $form_html = apply_filters( |
|
583 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
584 | - '' |
|
585 | - ); |
|
586 | - $form_config = $this->formConfig(); |
|
587 | - if ( |
|
588 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
589 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
590 | - ) { |
|
591 | - $additional_props = $this->requiresMultipartEnctype() |
|
592 | - ? ' enctype="multipart/form-data"' |
|
593 | - : ''; |
|
594 | - $form_html .= $this->form()->form_open( |
|
595 | - $this->formAction(), |
|
596 | - 'POST', |
|
597 | - $additional_props |
|
598 | - ); |
|
599 | - } |
|
600 | - $form_html .= $this->form(true)->get_html(); |
|
601 | - if ( |
|
602 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
603 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
604 | - ) { |
|
605 | - $form_html .= $this->form()->form_close(); |
|
606 | - } |
|
607 | - $form_html .= apply_filters( |
|
608 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
609 | - '' |
|
610 | - ); |
|
611 | - return $form_html; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
616 | - * @since 4.9.80.p |
|
617 | - * @return bool |
|
618 | - * @throws EE_Error |
|
619 | - */ |
|
620 | - public function requiresMultipartEnctype() |
|
621 | - { |
|
622 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
623 | - if ($input instanceof EE_File_Input) { |
|
624 | - return true; |
|
625 | - } |
|
626 | - } |
|
627 | - return false; |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * handles processing the form submission |
|
633 | - * returns true or false depending on whether the form was processed successfully or not |
|
634 | - * |
|
635 | - * @param array $submitted_form_data |
|
636 | - * @return array |
|
637 | - * @throws InvalidArgumentException |
|
638 | - * @throws InvalidInterfaceException |
|
639 | - * @throws InvalidDataTypeException |
|
640 | - * @throws EE_Error |
|
641 | - * @throws LogicException |
|
642 | - * @throws InvalidFormSubmissionException |
|
643 | - */ |
|
644 | - public function process($submitted_form_data = array()) |
|
645 | - { |
|
646 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
647 | - throw new InvalidFormSubmissionException($this->form_name); |
|
648 | - } |
|
649 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
650 | - if (! $this->form()->is_valid()) { |
|
651 | - throw new InvalidFormSubmissionException( |
|
652 | - $this->form_name, |
|
653 | - sprintf( |
|
654 | - esc_html__( |
|
655 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
656 | - 'event_espresso' |
|
657 | - ), |
|
658 | - $this->form_name, |
|
659 | - '<br />', |
|
660 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
661 | - ) |
|
662 | - ); |
|
663 | - } |
|
664 | - return (array) apply_filters( |
|
665 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
666 | - $this->form()->valid_data(), |
|
667 | - $this |
|
668 | - ); |
|
669 | - } |
|
32 | + /** |
|
33 | + * will add opening and closing HTML form tags as well as a submit button |
|
34 | + */ |
|
35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | + |
|
37 | + /** |
|
38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
39 | + */ |
|
40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | + |
|
42 | + /** |
|
43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | + */ |
|
45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | + |
|
47 | + /** |
|
48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | + */ |
|
50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | + |
|
52 | + /** |
|
53 | + * if set to false, then this form has no displayable content, |
|
54 | + * and will only be used for processing data sent passed via GET or POST |
|
55 | + * defaults to true ( ie: form has displayable content ) |
|
56 | + * |
|
57 | + * @var boolean $displayable |
|
58 | + */ |
|
59 | + private $displayable = true; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $form_name |
|
63 | + */ |
|
64 | + private $form_name; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $admin_name |
|
68 | + */ |
|
69 | + private $admin_name; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string $slug |
|
73 | + */ |
|
74 | + private $slug; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string $submit_btn_text |
|
78 | + */ |
|
79 | + private $submit_btn_text; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string $form_action |
|
83 | + */ |
|
84 | + private $form_action; |
|
85 | + |
|
86 | + /** |
|
87 | + * form params in key value pairs |
|
88 | + * can be added to form action URL or as hidden inputs |
|
89 | + * |
|
90 | + * @var array $form_args |
|
91 | + */ |
|
92 | + private $form_args = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * value of one of the string constant above |
|
96 | + * |
|
97 | + * @var string $form_config |
|
98 | + */ |
|
99 | + private $form_config; |
|
100 | + |
|
101 | + /** |
|
102 | + * whether or not the form was determined to be invalid |
|
103 | + * |
|
104 | + * @var boolean $form_has_errors |
|
105 | + */ |
|
106 | + private $form_has_errors; |
|
107 | + |
|
108 | + /** |
|
109 | + * the absolute top level form section being used on the page |
|
110 | + * |
|
111 | + * @var EE_Form_Section_Proper $form |
|
112 | + */ |
|
113 | + private $form; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var EE_Registry $registry |
|
117 | + */ |
|
118 | + protected $registry; |
|
119 | + |
|
120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Form constructor. |
|
125 | + * |
|
126 | + * @param string $form_name |
|
127 | + * @param string $admin_name |
|
128 | + * @param string $slug |
|
129 | + * @param string $form_action |
|
130 | + * @param string $form_config |
|
131 | + * @param EE_Registry|null $registry |
|
132 | + */ |
|
133 | + public function __construct( |
|
134 | + $form_name, |
|
135 | + $admin_name, |
|
136 | + $slug, |
|
137 | + $form_action = '', |
|
138 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
139 | + EE_Registry $registry = null |
|
140 | + ) { |
|
141 | + $this->setFormName($form_name); |
|
142 | + $this->setAdminName($admin_name); |
|
143 | + $this->setSlug($slug); |
|
144 | + $this->setFormAction($form_action); |
|
145 | + $this->setFormConfig($form_config); |
|
146 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
147 | + $this->registry = $registry; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public static function getFormConfigConstants() |
|
155 | + { |
|
156 | + return array( |
|
157 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
158 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
159 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
160 | + FormHandler::DO_NOT_SETUP_FORM, |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param bool $for_display |
|
167 | + * @return EE_Form_Section_Proper |
|
168 | + * @throws EE_Error |
|
169 | + * @throws LogicException |
|
170 | + */ |
|
171 | + public function form($for_display = false) |
|
172 | + { |
|
173 | + if (! $this->formIsValid()) { |
|
174 | + return null; |
|
175 | + } |
|
176 | + if ($for_display) { |
|
177 | + $form_config = $this->formConfig(); |
|
178 | + if ( |
|
179 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
180 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
181 | + ) { |
|
182 | + $this->appendSubmitButton(); |
|
183 | + $this->clearFormButtonFloats(); |
|
184 | + } |
|
185 | + } |
|
186 | + return $this->form; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @return boolean |
|
192 | + * @throws LogicException |
|
193 | + */ |
|
194 | + public function formIsValid() |
|
195 | + { |
|
196 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
197 | + return true; |
|
198 | + } |
|
199 | + $form = apply_filters( |
|
200 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
201 | + $this->generate(), |
|
202 | + $this |
|
203 | + ); |
|
204 | + if ($this->verifyForm($form)) { |
|
205 | + $this->setForm($form); |
|
206 | + } |
|
207 | + return true; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param EE_Form_Section_Proper|null $form |
|
213 | + * @return bool |
|
214 | + * @throws LogicException |
|
215 | + */ |
|
216 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
217 | + { |
|
218 | + $form = $form !== null ? $form : $this->form; |
|
219 | + if ($form instanceof EE_Form_Section_Proper) { |
|
220 | + return true; |
|
221 | + } |
|
222 | + throw new LogicException( |
|
223 | + sprintf( |
|
224 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
225 | + $this->form_name, |
|
226 | + var_export($form, true) |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param EE_Form_Section_Proper $form |
|
234 | + */ |
|
235 | + public function setForm(EE_Form_Section_Proper $form) |
|
236 | + { |
|
237 | + $this->form = $form; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return boolean |
|
243 | + */ |
|
244 | + public function displayable() |
|
245 | + { |
|
246 | + return $this->displayable; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param boolean $displayable |
|
252 | + */ |
|
253 | + public function setDisplayable($displayable = false) |
|
254 | + { |
|
255 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * a public name for the form that can be displayed on the frontend of a site |
|
261 | + * |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function formName() |
|
265 | + { |
|
266 | + return $this->form_name; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @param string $form_name |
|
272 | + * @throws InvalidDataTypeException |
|
273 | + */ |
|
274 | + public function setFormName($form_name) |
|
275 | + { |
|
276 | + if (! is_string($form_name)) { |
|
277 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
278 | + } |
|
279 | + $this->form_name = $form_name; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * a public name for the form that can be displayed, but only in the admin |
|
285 | + * |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function adminName() |
|
289 | + { |
|
290 | + return $this->admin_name; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $admin_name |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + */ |
|
298 | + public function setAdminName($admin_name) |
|
299 | + { |
|
300 | + if (! is_string($admin_name)) { |
|
301 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
302 | + } |
|
303 | + $this->admin_name = $admin_name; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * a URL friendly string that can be used for identifying the form |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function slug() |
|
313 | + { |
|
314 | + return $this->slug; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @param string $slug |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + */ |
|
322 | + public function setSlug($slug) |
|
323 | + { |
|
324 | + if (! is_string($slug)) { |
|
325 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
326 | + } |
|
327 | + $this->slug = $slug; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function submitBtnText() |
|
335 | + { |
|
336 | + return $this->submit_btn_text; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * @param string $submit_btn_text |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidArgumentException |
|
344 | + */ |
|
345 | + public function setSubmitBtnText($submit_btn_text) |
|
346 | + { |
|
347 | + if (! is_string($submit_btn_text)) { |
|
348 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
349 | + } |
|
350 | + if (empty($submit_btn_text)) { |
|
351 | + throw new InvalidArgumentException( |
|
352 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
353 | + ); |
|
354 | + } |
|
355 | + $this->submit_btn_text = $submit_btn_text; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + public function formAction() |
|
363 | + { |
|
364 | + return ! empty($this->form_args) |
|
365 | + ? add_query_arg($this->form_args, $this->form_action) |
|
366 | + : $this->form_action; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param string $form_action |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + */ |
|
374 | + public function setFormAction($form_action) |
|
375 | + { |
|
376 | + if (! is_string($form_action)) { |
|
377 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
378 | + } |
|
379 | + $this->form_action = $form_action; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @param array $form_args |
|
385 | + * @throws InvalidDataTypeException |
|
386 | + * @throws InvalidArgumentException |
|
387 | + */ |
|
388 | + public function addFormActionArgs($form_args = array()) |
|
389 | + { |
|
390 | + if (is_object($form_args)) { |
|
391 | + throw new InvalidDataTypeException( |
|
392 | + '$form_args', |
|
393 | + $form_args, |
|
394 | + 'anything other than an object was expected.' |
|
395 | + ); |
|
396 | + } |
|
397 | + if (empty($form_args)) { |
|
398 | + throw new InvalidArgumentException( |
|
399 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
400 | + ); |
|
401 | + } |
|
402 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public function formConfig() |
|
410 | + { |
|
411 | + return $this->form_config; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $form_config |
|
417 | + * @throws DomainException |
|
418 | + */ |
|
419 | + public function setFormConfig($form_config) |
|
420 | + { |
|
421 | + if ( |
|
422 | + ! in_array( |
|
423 | + $form_config, |
|
424 | + array( |
|
425 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
426 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
427 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
428 | + FormHandler::DO_NOT_SETUP_FORM, |
|
429 | + ), |
|
430 | + true |
|
431 | + ) |
|
432 | + ) { |
|
433 | + throw new DomainException( |
|
434 | + sprintf( |
|
435 | + esc_html__( |
|
436 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
437 | + 'event_espresso' |
|
438 | + ), |
|
439 | + $form_config |
|
440 | + ) |
|
441 | + ); |
|
442 | + } |
|
443 | + $this->form_config = $form_config; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * called after the form is instantiated |
|
449 | + * and used for performing any logic that needs to occur early |
|
450 | + * before any of the other methods are called. |
|
451 | + * returns true if everything is ok to proceed, |
|
452 | + * and false if no further form logic should be implemented |
|
453 | + * |
|
454 | + * @return boolean |
|
455 | + */ |
|
456 | + public function initialize() |
|
457 | + { |
|
458 | + $this->form_has_errors = EE_Error::has_error(true); |
|
459 | + return true; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * used for setting up css and js |
|
465 | + * |
|
466 | + * @return void |
|
467 | + * @throws LogicException |
|
468 | + * @throws EE_Error |
|
469 | + */ |
|
470 | + public function enqueueStylesAndScripts() |
|
471 | + { |
|
472 | + $this->form()->enqueue_js(); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * creates and returns the actual form |
|
478 | + * |
|
479 | + * @return EE_Form_Section_Proper |
|
480 | + */ |
|
481 | + abstract public function generate(); |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
486 | + * |
|
487 | + * @param string $text |
|
488 | + * @return EE_Submit_Input |
|
489 | + */ |
|
490 | + public function generateSubmitButton($text = '') |
|
491 | + { |
|
492 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
493 | + return new EE_Submit_Input( |
|
494 | + array( |
|
495 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
496 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
497 | + 'html_class' => 'ee-form-submit', |
|
498 | + 'html_label' => ' ', |
|
499 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
500 | + 'default' => $text, |
|
501 | + ) |
|
502 | + ); |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
508 | + * |
|
509 | + * @param string $text |
|
510 | + * @return void |
|
511 | + * @throws EE_Error |
|
512 | + */ |
|
513 | + public function appendSubmitButton($text = '') |
|
514 | + { |
|
515 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
516 | + return; |
|
517 | + } |
|
518 | + $this->form->add_subsections( |
|
519 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
520 | + null, |
|
521 | + false |
|
522 | + ); |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
528 | + * |
|
529 | + * @param string $text |
|
530 | + * @return EE_Submit_Input |
|
531 | + */ |
|
532 | + public function generateCancelButton($text = '') |
|
533 | + { |
|
534 | + $cancel_button = new EE_Submit_Input( |
|
535 | + array( |
|
536 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
537 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
538 | + 'html_class' => 'ee-cancel-form', |
|
539 | + 'html_label' => ' ', |
|
540 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
541 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
542 | + ) |
|
543 | + ); |
|
544 | + $cancel_button->set_button_css_attributes(false); |
|
545 | + return $cancel_button; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * appends a float clearing div onto end of form |
|
551 | + * |
|
552 | + * @return void |
|
553 | + * @throws EE_Error |
|
554 | + */ |
|
555 | + public function clearFormButtonFloats() |
|
556 | + { |
|
557 | + $this->form->add_subsections( |
|
558 | + array( |
|
559 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
560 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
561 | + ), |
|
562 | + ), |
|
563 | + null, |
|
564 | + false |
|
565 | + ); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
571 | + * returns a string of HTML that can be directly echoed in a template |
|
572 | + * |
|
573 | + * @return string |
|
574 | + * @throws InvalidArgumentException |
|
575 | + * @throws InvalidInterfaceException |
|
576 | + * @throws InvalidDataTypeException |
|
577 | + * @throws LogicException |
|
578 | + * @throws EE_Error |
|
579 | + */ |
|
580 | + public function display() |
|
581 | + { |
|
582 | + $form_html = apply_filters( |
|
583 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
584 | + '' |
|
585 | + ); |
|
586 | + $form_config = $this->formConfig(); |
|
587 | + if ( |
|
588 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
589 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
590 | + ) { |
|
591 | + $additional_props = $this->requiresMultipartEnctype() |
|
592 | + ? ' enctype="multipart/form-data"' |
|
593 | + : ''; |
|
594 | + $form_html .= $this->form()->form_open( |
|
595 | + $this->formAction(), |
|
596 | + 'POST', |
|
597 | + $additional_props |
|
598 | + ); |
|
599 | + } |
|
600 | + $form_html .= $this->form(true)->get_html(); |
|
601 | + if ( |
|
602 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
603 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
604 | + ) { |
|
605 | + $form_html .= $this->form()->form_close(); |
|
606 | + } |
|
607 | + $form_html .= apply_filters( |
|
608 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
609 | + '' |
|
610 | + ); |
|
611 | + return $form_html; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
616 | + * @since 4.9.80.p |
|
617 | + * @return bool |
|
618 | + * @throws EE_Error |
|
619 | + */ |
|
620 | + public function requiresMultipartEnctype() |
|
621 | + { |
|
622 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
623 | + if ($input instanceof EE_File_Input) { |
|
624 | + return true; |
|
625 | + } |
|
626 | + } |
|
627 | + return false; |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * handles processing the form submission |
|
633 | + * returns true or false depending on whether the form was processed successfully or not |
|
634 | + * |
|
635 | + * @param array $submitted_form_data |
|
636 | + * @return array |
|
637 | + * @throws InvalidArgumentException |
|
638 | + * @throws InvalidInterfaceException |
|
639 | + * @throws InvalidDataTypeException |
|
640 | + * @throws EE_Error |
|
641 | + * @throws LogicException |
|
642 | + * @throws InvalidFormSubmissionException |
|
643 | + */ |
|
644 | + public function process($submitted_form_data = array()) |
|
645 | + { |
|
646 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
647 | + throw new InvalidFormSubmissionException($this->form_name); |
|
648 | + } |
|
649 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
650 | + if (! $this->form()->is_valid()) { |
|
651 | + throw new InvalidFormSubmissionException( |
|
652 | + $this->form_name, |
|
653 | + sprintf( |
|
654 | + esc_html__( |
|
655 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
656 | + 'event_espresso' |
|
657 | + ), |
|
658 | + $this->form_name, |
|
659 | + '<br />', |
|
660 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
661 | + ) |
|
662 | + ); |
|
663 | + } |
|
664 | + return (array) apply_filters( |
|
665 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
666 | + $this->form()->valid_data(), |
|
667 | + $this |
|
668 | + ); |
|
669 | + } |
|
670 | 670 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | public function setOrder($order) |
114 | 114 | { |
115 | 115 | $order = absint($order); |
116 | - if (! $order > 0) { |
|
116 | + if ( ! $order > 0) { |
|
117 | 117 | throw new InvalidArgumentException( |
118 | 118 | esc_html__('The form order property must be a positive integer.', 'event_espresso') |
119 | 119 | ); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function setRedirectUrl($redirect_url) |
144 | 144 | { |
145 | - if (! is_string($redirect_url)) { |
|
145 | + if ( ! is_string($redirect_url)) { |
|
146 | 146 | throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
147 | 147 | } |
148 | 148 | if (empty($redirect_url)) { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ); |
200 | 200 | } |
201 | 201 | foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
202 | - unset($this->redirect_args[ $redirect_arg_key ]); |
|
202 | + unset($this->redirect_args[$redirect_arg_key]); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 |
@@ -18,227 +18,227 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface |
20 | 20 | { |
21 | - const REDIRECT_TO_NEXT_STEP = 'redirect_to_next_step'; |
|
22 | - |
|
23 | - const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step'; |
|
24 | - |
|
25 | - const REDIRECT_TO_PREV_STEP = 'redirect_to_prev_step'; |
|
26 | - |
|
27 | - const REDIRECT_TO_OTHER = 'redirect_to_other'; |
|
28 | - |
|
29 | - /** |
|
30 | - * numerical value used for sorting form steps |
|
31 | - * |
|
32 | - * @var int $order |
|
33 | - */ |
|
34 | - private $order = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * a final URL with all form related parameters added |
|
38 | - * that will be used to advance to the next step |
|
39 | - * |
|
40 | - * @var string $redirect_url |
|
41 | - */ |
|
42 | - private $redirect_url = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * URL params in key value pairs |
|
46 | - * |
|
47 | - * @var array $redirect_args |
|
48 | - */ |
|
49 | - private $redirect_args = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * Which step should be redirected to after form processing. |
|
53 | - * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP |
|
54 | - * If a form is invalid and requires errors to be corrected, |
|
55 | - * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted |
|
56 | - * Some form handlers do not have a form that is displayable, |
|
57 | - * and only perform data processing, but if an error occurs, |
|
58 | - * then this value needs to be set to REDIRECT_TO_PREV_STEP |
|
59 | - * since the current step has no displayable content. |
|
60 | - * if the form is completely finished, and needs to redirect to somewhere |
|
61 | - * completely different, then this value will be REDIRECT_TO_OTHER |
|
62 | - * |
|
63 | - * @var string $redirect_to |
|
64 | - */ |
|
65 | - private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * SequentialStepForm constructor |
|
70 | - * |
|
71 | - * @param int $order |
|
72 | - * @param string $form_name |
|
73 | - * @param string $admin_name |
|
74 | - * @param string $slug |
|
75 | - * @param string $form_action |
|
76 | - * @param string $form_config |
|
77 | - * @param EE_Registry|null $registry |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws DomainException |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - $order, |
|
84 | - $form_name, |
|
85 | - $admin_name, |
|
86 | - $slug, |
|
87 | - $form_action = '', |
|
88 | - $form_config = 'add_form_tags_and_submit', |
|
89 | - ?EE_Registry $registry = null |
|
90 | - ) { |
|
91 | - $this->setOrder($order); |
|
92 | - parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - public function order() |
|
101 | - { |
|
102 | - return $this->order; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param int $order |
|
109 | - * @throws InvalidArgumentException |
|
110 | - */ |
|
111 | - public function setOrder($order) |
|
112 | - { |
|
113 | - $order = absint($order); |
|
114 | - if (! $order > 0) { |
|
115 | - throw new InvalidArgumentException( |
|
116 | - esc_html__('The form order property must be a positive integer.', 'event_espresso') |
|
117 | - ); |
|
118 | - } |
|
119 | - $this->order = $order; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function redirectUrl() |
|
128 | - { |
|
129 | - return ! empty($this->redirect_args) |
|
130 | - ? add_query_arg($this->redirect_args, $this->redirect_url) |
|
131 | - : $this->redirect_url; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $redirect_url |
|
138 | - * @throws InvalidDataTypeException |
|
139 | - * @throws InvalidArgumentException |
|
140 | - */ |
|
141 | - public function setRedirectUrl($redirect_url) |
|
142 | - { |
|
143 | - if (! is_string($redirect_url)) { |
|
144 | - throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
|
145 | - } |
|
146 | - if (empty($redirect_url)) { |
|
147 | - throw new InvalidArgumentException( |
|
148 | - esc_html__('The redirect URL can not be an empty string.', 'event_espresso') |
|
149 | - ); |
|
150 | - } |
|
151 | - $this->redirect_url = $redirect_url; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param array $redirect_args |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws InvalidArgumentException |
|
160 | - */ |
|
161 | - public function addRedirectArgs($redirect_args = array()) |
|
162 | - { |
|
163 | - if (is_object($redirect_args)) { |
|
164 | - throw new InvalidDataTypeException( |
|
165 | - '$redirect_args', |
|
166 | - $redirect_args, |
|
167 | - 'anything other than an object was expected.' |
|
168 | - ); |
|
169 | - } |
|
170 | - if (empty($redirect_args)) { |
|
171 | - throw new InvalidArgumentException( |
|
172 | - esc_html__('The redirect argument can not be an empty array.', 'event_espresso') |
|
173 | - ); |
|
174 | - } |
|
175 | - $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @param array $redirect_arg_keys_to_remove |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidArgumentException |
|
184 | - */ |
|
185 | - public function removeRedirectArgs($redirect_arg_keys_to_remove = array()) |
|
186 | - { |
|
187 | - if (is_object($redirect_arg_keys_to_remove)) { |
|
188 | - throw new InvalidDataTypeException( |
|
189 | - '$redirect_arg_keys_to_remove', |
|
190 | - $redirect_arg_keys_to_remove, |
|
191 | - 'anything other than an object was expected.' |
|
192 | - ); |
|
193 | - } |
|
194 | - if (empty($redirect_arg_keys_to_remove)) { |
|
195 | - throw new InvalidArgumentException( |
|
196 | - esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso') |
|
197 | - ); |
|
198 | - } |
|
199 | - foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
|
200 | - unset($this->redirect_args[ $redirect_arg_key ]); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public function redirectTo() |
|
210 | - { |
|
211 | - return $this->redirect_to; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param string $redirect_to |
|
218 | - * @throws InvalidDataTypeException |
|
219 | - */ |
|
220 | - public function setRedirectTo($redirect_to) |
|
221 | - { |
|
222 | - if ( |
|
223 | - ! in_array( |
|
224 | - $redirect_to, |
|
225 | - array( |
|
226 | - SequentialStepForm::REDIRECT_TO_NEXT_STEP, |
|
227 | - SequentialStepForm::REDIRECT_TO_CURRENT_STEP, |
|
228 | - SequentialStepForm::REDIRECT_TO_PREV_STEP, |
|
229 | - SequentialStepForm::REDIRECT_TO_OTHER, |
|
230 | - ), |
|
231 | - true |
|
232 | - ) |
|
233 | - ) { |
|
234 | - throw new InvalidDataTypeException( |
|
235 | - 'setRedirectTo()', |
|
236 | - $redirect_to, |
|
237 | - 'one of the SequentialStepForm class constants was expected.' |
|
238 | - ); |
|
239 | - } |
|
240 | - $this->redirect_to = $redirect_to; |
|
241 | - } |
|
21 | + const REDIRECT_TO_NEXT_STEP = 'redirect_to_next_step'; |
|
22 | + |
|
23 | + const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step'; |
|
24 | + |
|
25 | + const REDIRECT_TO_PREV_STEP = 'redirect_to_prev_step'; |
|
26 | + |
|
27 | + const REDIRECT_TO_OTHER = 'redirect_to_other'; |
|
28 | + |
|
29 | + /** |
|
30 | + * numerical value used for sorting form steps |
|
31 | + * |
|
32 | + * @var int $order |
|
33 | + */ |
|
34 | + private $order = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * a final URL with all form related parameters added |
|
38 | + * that will be used to advance to the next step |
|
39 | + * |
|
40 | + * @var string $redirect_url |
|
41 | + */ |
|
42 | + private $redirect_url = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * URL params in key value pairs |
|
46 | + * |
|
47 | + * @var array $redirect_args |
|
48 | + */ |
|
49 | + private $redirect_args = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * Which step should be redirected to after form processing. |
|
53 | + * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP |
|
54 | + * If a form is invalid and requires errors to be corrected, |
|
55 | + * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted |
|
56 | + * Some form handlers do not have a form that is displayable, |
|
57 | + * and only perform data processing, but if an error occurs, |
|
58 | + * then this value needs to be set to REDIRECT_TO_PREV_STEP |
|
59 | + * since the current step has no displayable content. |
|
60 | + * if the form is completely finished, and needs to redirect to somewhere |
|
61 | + * completely different, then this value will be REDIRECT_TO_OTHER |
|
62 | + * |
|
63 | + * @var string $redirect_to |
|
64 | + */ |
|
65 | + private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * SequentialStepForm constructor |
|
70 | + * |
|
71 | + * @param int $order |
|
72 | + * @param string $form_name |
|
73 | + * @param string $admin_name |
|
74 | + * @param string $slug |
|
75 | + * @param string $form_action |
|
76 | + * @param string $form_config |
|
77 | + * @param EE_Registry|null $registry |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws DomainException |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + $order, |
|
84 | + $form_name, |
|
85 | + $admin_name, |
|
86 | + $slug, |
|
87 | + $form_action = '', |
|
88 | + $form_config = 'add_form_tags_and_submit', |
|
89 | + ?EE_Registry $registry = null |
|
90 | + ) { |
|
91 | + $this->setOrder($order); |
|
92 | + parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + public function order() |
|
101 | + { |
|
102 | + return $this->order; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param int $order |
|
109 | + * @throws InvalidArgumentException |
|
110 | + */ |
|
111 | + public function setOrder($order) |
|
112 | + { |
|
113 | + $order = absint($order); |
|
114 | + if (! $order > 0) { |
|
115 | + throw new InvalidArgumentException( |
|
116 | + esc_html__('The form order property must be a positive integer.', 'event_espresso') |
|
117 | + ); |
|
118 | + } |
|
119 | + $this->order = $order; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function redirectUrl() |
|
128 | + { |
|
129 | + return ! empty($this->redirect_args) |
|
130 | + ? add_query_arg($this->redirect_args, $this->redirect_url) |
|
131 | + : $this->redirect_url; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $redirect_url |
|
138 | + * @throws InvalidDataTypeException |
|
139 | + * @throws InvalidArgumentException |
|
140 | + */ |
|
141 | + public function setRedirectUrl($redirect_url) |
|
142 | + { |
|
143 | + if (! is_string($redirect_url)) { |
|
144 | + throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
|
145 | + } |
|
146 | + if (empty($redirect_url)) { |
|
147 | + throw new InvalidArgumentException( |
|
148 | + esc_html__('The redirect URL can not be an empty string.', 'event_espresso') |
|
149 | + ); |
|
150 | + } |
|
151 | + $this->redirect_url = $redirect_url; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param array $redirect_args |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws InvalidArgumentException |
|
160 | + */ |
|
161 | + public function addRedirectArgs($redirect_args = array()) |
|
162 | + { |
|
163 | + if (is_object($redirect_args)) { |
|
164 | + throw new InvalidDataTypeException( |
|
165 | + '$redirect_args', |
|
166 | + $redirect_args, |
|
167 | + 'anything other than an object was expected.' |
|
168 | + ); |
|
169 | + } |
|
170 | + if (empty($redirect_args)) { |
|
171 | + throw new InvalidArgumentException( |
|
172 | + esc_html__('The redirect argument can not be an empty array.', 'event_espresso') |
|
173 | + ); |
|
174 | + } |
|
175 | + $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @param array $redirect_arg_keys_to_remove |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidArgumentException |
|
184 | + */ |
|
185 | + public function removeRedirectArgs($redirect_arg_keys_to_remove = array()) |
|
186 | + { |
|
187 | + if (is_object($redirect_arg_keys_to_remove)) { |
|
188 | + throw new InvalidDataTypeException( |
|
189 | + '$redirect_arg_keys_to_remove', |
|
190 | + $redirect_arg_keys_to_remove, |
|
191 | + 'anything other than an object was expected.' |
|
192 | + ); |
|
193 | + } |
|
194 | + if (empty($redirect_arg_keys_to_remove)) { |
|
195 | + throw new InvalidArgumentException( |
|
196 | + esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso') |
|
197 | + ); |
|
198 | + } |
|
199 | + foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
|
200 | + unset($this->redirect_args[ $redirect_arg_key ]); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public function redirectTo() |
|
210 | + { |
|
211 | + return $this->redirect_to; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param string $redirect_to |
|
218 | + * @throws InvalidDataTypeException |
|
219 | + */ |
|
220 | + public function setRedirectTo($redirect_to) |
|
221 | + { |
|
222 | + if ( |
|
223 | + ! in_array( |
|
224 | + $redirect_to, |
|
225 | + array( |
|
226 | + SequentialStepForm::REDIRECT_TO_NEXT_STEP, |
|
227 | + SequentialStepForm::REDIRECT_TO_CURRENT_STEP, |
|
228 | + SequentialStepForm::REDIRECT_TO_PREV_STEP, |
|
229 | + SequentialStepForm::REDIRECT_TO_OTHER, |
|
230 | + ), |
|
231 | + true |
|
232 | + ) |
|
233 | + ) { |
|
234 | + throw new InvalidDataTypeException( |
|
235 | + 'setRedirectTo()', |
|
236 | + $redirect_to, |
|
237 | + 'one of the SequentialStepForm class constants was expected.' |
|
238 | + ); |
|
239 | + } |
|
240 | + $this->redirect_to = $redirect_to; |
|
241 | + } |
|
242 | 242 | } |
243 | 243 | // End of file SequentialStepForm.php |
244 | 244 | // Location: /SequentialStepForm.php |
@@ -42,11 +42,11 @@ |
||
42 | 42 | 'Price' => new EE_Belongs_To_Relation() |
43 | 43 | ); |
44 | 44 | $this->_model_chain_to_wp_user = 'Ticket'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | 46 | // account for default tickets in the caps |
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | 50 | // follow the caps of the ticket |
51 | 51 | $this->_caps_slug = 'tickets'; |
52 | 52 | parent::__construct($timezone); |
@@ -11,43 +11,43 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Ticket_Price extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Ticket_Price object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Ticket_Price object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access protected |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Ticket Price', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Ticket Prices', 'event_espresso'); |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access protected |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Ticket Price', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Ticket Prices', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Ticket_Price' => array( |
|
34 | - 'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | - 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | - 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket' => new EE_Belongs_To_Relation(), |
|
41 | - 'Price' => new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | - // account for default tickets in the caps |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - // follow the caps of the ticket |
|
50 | - $this->_caps_slug = 'tickets'; |
|
51 | - parent::__construct($timezone); |
|
52 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Ticket_Price' => array( |
|
34 | + 'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | + 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | + 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket' => new EE_Belongs_To_Relation(), |
|
41 | + 'Price' => new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + // account for default tickets in the caps |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + // follow the caps of the ticket |
|
50 | + $this->_caps_slug = 'tickets'; |
|
51 | + parent::__construct($timezone); |
|
52 | + } |
|
53 | 53 | } |