@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * Class EEI_Line_Item |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param mixed $field_value |
19 | 19 | * @param bool $use_default |
20 | 20 | */ |
21 | - public function set( $field_name, $field_value, $use_default = false ); |
|
21 | + public function set($field_name, $field_value, $use_default = false); |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * Sets quantity |
57 | 57 | * @param int $quantity |
58 | 58 | */ |
59 | - function set_quantity( $quantity ); |
|
59 | + function set_quantity($quantity); |
|
60 | 60 | |
61 | 61 | |
62 | 62 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
116 | 116 | * @return int count of items saved |
117 | 117 | */ |
118 | - function save_this_and_descendants_to_txn( $txn_id = null ); |
|
118 | + function save_this_and_descendants_to_txn($txn_id = null); |
|
119 | 119 | |
120 | 120 | |
121 | 121 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param bool $set_order |
143 | 143 | * @return bool true for success, false for fail |
144 | 144 | */ |
145 | - function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ); |
|
145 | + function add_child_line_item(EEI_Line_Item $line_item, $set_order = true); |
|
146 | 146 | |
147 | 147 | |
148 | 148 | |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | * @param float $total |
198 | 198 | * @return boolean |
199 | 199 | */ |
200 | - function set_total( $total ); |
|
200 | + function set_total($total); |
|
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Sets unit_price |
204 | 204 | * @param float $unit_price |
205 | 205 | * @return boolean |
206 | 206 | */ |
207 | - function set_unit_price( $unit_price ); |
|
207 | + function set_unit_price($unit_price); |
|
208 | 208 | |
209 | 209 | /** |
210 | 210 | * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param bool $stop_search_once_found |
216 | 216 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
217 | 217 | */ |
218 | - function delete_child_line_item( $code, $stop_search_once_found = true ); |
|
218 | + function delete_child_line_item($code, $stop_search_once_found = true); |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Forgets the cached model of the given relation Name. So the next time we request it, |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param boolean $allow_persist |
239 | 239 | * @return boolean |
240 | 240 | */ |
241 | - function set_allow_persist( $allow_persist ); |
|
241 | + function set_allow_persist($allow_persist); |
|
242 | 242 | |
243 | 243 | |
244 | 244 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param \EEI_Line_Item $line_item |
27 | 27 | * @return \EEI_Line_Item |
28 | 28 | */ |
29 | - public function process( EEI_Line_Item $line_item ); |
|
29 | + public function process(EEI_Line_Item $line_item); |
|
30 | 30 | |
31 | 31 | |
32 | 32 |
@@ -1,20 +1,20 @@ discard block |
||
1 | 1 | <?php |
2 | -class EE_Sample_Form extends EE_Form_Section_Proper{ |
|
3 | - function __construct(){ |
|
2 | +class EE_Sample_Form extends EE_Form_Section_Proper { |
|
3 | + function __construct() { |
|
4 | 4 | $this->_subsections = array( |
5 | 5 | 'h1'=>new EE_Form_Section_HTML('hello wordl'), |
6 | - 'name'=>new EE_Text_Input(array('required'=>true,'default'=>'your name here')), |
|
6 | + 'name'=>new EE_Text_Input(array('required'=>true, 'default'=>'your name here')), |
|
7 | 7 | 'email'=>new EE_Email_Input(array('required'=>false)), |
8 | - 'shirt_size'=>new EE_Select_Input(array(''=>'Please select...', 's'=> __("Small", "event_espresso"),'m'=> __("Medium", "event_espresso"),'l'=> __("Large", "event_espresso")),array('required'=>true,'default'=>'s')), |
|
8 | + 'shirt_size'=>new EE_Select_Input(array(''=>'Please select...', 's'=> __("Small", "event_espresso"), 'm'=> __("Medium", "event_espresso"), 'l'=> __("Large", "event_espresso")), array('required'=>true, 'default'=>'s')), |
|
9 | 9 | 'month_normal'=>new EE_Month_Input(), |
10 | 10 | 'month_leading_zero'=>new EE_Month_Input(true), |
11 | 11 | 'year_2'=>new EE_Year_Input(false, 1, 1), |
12 | - 'year_4'=>new EE_Year_Input(true, 0,10,array('default'=>'2017')), |
|
12 | + 'year_4'=>new EE_Year_Input(true, 0, 10, array('default'=>'2017')), |
|
13 | 13 | 'yes_no'=>new EE_Yes_No_Input(array('html_label_text'=> __("Yes or No", "event_espresso"))), |
14 | 14 | 'credit_card'=>new EE_Credit_Card_Input(), |
15 | 15 | 'image_1'=>new EE_Admin_File_Uploader_Input(), |
16 | 16 | 'image_2'=>new EE_Admin_File_Uploader_Input(), |
17 | - 'skillz'=>new EE_Checkbox_Multi_Input(array('php'=>'PHP','mysql'=>'MYSQL'),array('default'=>array('php'))), |
|
17 | + 'skillz'=>new EE_Checkbox_Multi_Input(array('php'=>'PHP', 'mysql'=>'MYSQL'), array('default'=>array('php'))), |
|
18 | 18 | 'float'=>new EE_Float_Input(), |
19 | 19 | 'essay'=>new EE_Text_Area_Input(), |
20 | 20 | 'amenities'=>new EE_Select_Multiple_Input( |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | * Extra validation for the 'name' input. |
41 | 41 | * @param EE_Text_Input $form_input |
42 | 42 | */ |
43 | - function _validate_name($form_input){ |
|
44 | - if($form_input->raw_value() != 'Mike'){ |
|
43 | + function _validate_name($form_input) { |
|
44 | + if ($form_input->raw_value() != 'Mike') { |
|
45 | 45 | $form_input->add_validation_error(__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike'); |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | - function _validate(){ |
|
49 | + function _validate() { |
|
50 | 50 | parent::_validate(); |
51 | - if($this->_subsections['shirt_size']->normalized_value() =='s' |
|
52 | - && $this->_subsections['year_4']->normalized_value() < 2010){ |
|
51 | + if ($this->_subsections['shirt_size']->normalized_value() == 's' |
|
52 | + && $this->_subsections['year_4']->normalized_value() < 2010) { |
|
53 | 53 | $this->add_validation_error(__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old'); |
54 | 54 | } |
55 | 55 | } |
@@ -1,7 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | +} |
|
5 | 6 | |
6 | 7 | /** |
7 | 8 | * Event Espresso |
@@ -175,7 +176,7 @@ discard block |
||
175 | 176 | if( ! $this->_html_id ){ |
176 | 177 | if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper ){ |
177 | 178 | $this->_html_id = $this->_parent_section->html_id() . '-' . $this->_prep_name_for_html_id( $this->name() ); |
178 | - }else{ |
|
179 | + } else{ |
|
179 | 180 | $this->_html_id = $this->_prep_name_for_html_id( $this->name() ); |
180 | 181 | } |
181 | 182 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @type $name string the name for this form section, if you want to explicitly define it |
96 | 96 | * } |
97 | 97 | */ |
98 | - function __construct( $options_array = array() ) { |
|
98 | + function __construct($options_array = array()) { |
|
99 | 99 | // used by display strategies |
100 | 100 | EE_Registry::instance()->load_helper('HTML'); |
101 | 101 | // assign incoming values to properties |
102 | - foreach( $options_array as $key => $value ) { |
|
103 | - $key = '_' . $key; |
|
104 | - if ( property_exists( $this, $key ) && empty( $this->{$key} )) { |
|
102 | + foreach ($options_array as $key => $value) { |
|
103 | + $key = '_'.$key; |
|
104 | + if (property_exists($this, $key) && empty($this->{$key} )) { |
|
105 | 105 | $this->{$key} = $value; |
106 | 106 | } |
107 | 107 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param $parent_form_section |
114 | 114 | * @param $name |
115 | 115 | */ |
116 | - protected function _construct_finalize( $parent_form_section, $name ){ |
|
116 | + protected function _construct_finalize($parent_form_section, $name) { |
|
117 | 117 | $this->_construction_finalized = TRUE; |
118 | 118 | $this->_parent_section = $parent_form_section; |
119 | 119 | $this->_name = $name; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | /** |
135 | 135 | * @param string $action |
136 | 136 | */ |
137 | - public function set_action( $action ) { |
|
137 | + public function set_action($action) { |
|
138 | 138 | $this->_action = $action; |
139 | 139 | } |
140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return string |
145 | 145 | */ |
146 | 146 | public function method() { |
147 | - return ! empty( $this->_method ) ? $this->_method : 'POST'; |
|
147 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * @param string $method |
154 | 154 | */ |
155 | - public function set_method( $method ) { |
|
156 | - switch ( $method ) { |
|
155 | + public function set_method($method) { |
|
156 | + switch ($method) { |
|
157 | 157 | case 'get' : |
158 | 158 | case 'GET' : |
159 | 159 | $this->_method = 'GET'; |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | * Calculation involves using the name and the parent's html id |
172 | 172 | * return void |
173 | 173 | */ |
174 | - protected function _set_default_html_id_if_empty(){ |
|
175 | - if( ! $this->_html_id ){ |
|
176 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper ){ |
|
177 | - $this->_html_id = $this->_parent_section->html_id() . '-' . $this->_prep_name_for_html_id( $this->name() ); |
|
178 | - }else{ |
|
179 | - $this->_html_id = $this->_prep_name_for_html_id( $this->name() ); |
|
174 | + protected function _set_default_html_id_if_empty() { |
|
175 | + if ( ! $this->_html_id) { |
|
176 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
177 | + $this->_html_id = $this->_parent_section->html_id().'-'.$this->_prep_name_for_html_id($this->name()); |
|
178 | + } else { |
|
179 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param $name |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - private function _prep_name_for_html_id( $name ) { |
|
192 | - return sanitize_key( str_replace( array( ' ', ' ', '_' ), '-', $name )); |
|
191 | + private function _prep_name_for_html_id($name) { |
|
192 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | * @param bool $add_pound_sign |
207 | 207 | * @return string |
208 | 208 | */ |
209 | - public function html_id( $add_pound_sign = FALSE ){ |
|
210 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
209 | + public function html_id($add_pound_sign = FALSE) { |
|
210 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | /** |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function html_class(){ |
|
218 | + public function html_class() { |
|
219 | 219 | return $this->_html_class; |
220 | 220 | } |
221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | /** |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - public function html_style(){ |
|
227 | + public function html_style() { |
|
228 | 228 | return $this->_html_style; |
229 | 229 | } |
230 | 230 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | /** |
234 | 234 | * @param mixed $html_class |
235 | 235 | */ |
236 | - public function set_html_class( $html_class ) { |
|
236 | + public function set_html_class($html_class) { |
|
237 | 237 | $this->_html_class = $html_class; |
238 | 238 | } |
239 | 239 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * @param mixed $html_id |
244 | 244 | */ |
245 | - public function set_html_id( $html_id ) { |
|
245 | + public function set_html_id($html_id) { |
|
246 | 246 | $this->_html_id = $html_id; |
247 | 247 | } |
248 | 248 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | /** |
252 | 252 | * @param mixed $html_style |
253 | 253 | */ |
254 | - public function set_html_style( $html_style ) { |
|
254 | + public function set_html_style($html_style) { |
|
255 | 255 | $this->_html_style = $html_style; |
256 | 256 | } |
257 | 257 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * @param string $other_html_attributes |
262 | 262 | */ |
263 | - public function set_other_html_attributes( $other_html_attributes ) { |
|
263 | + public function set_other_html_attributes($other_html_attributes) { |
|
264 | 264 | $this->_other_html_attributes = $other_html_attributes; |
265 | 265 | } |
266 | 266 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @throws EE_Error |
281 | 281 | * @return string |
282 | 282 | */ |
283 | - function name(){ |
|
284 | - if( ! $this->_construction_finalized ){ |
|
285 | - throw new EE_Error(sprintf( __( 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso' ), get_class($this) ) ); |
|
283 | + function name() { |
|
284 | + if ( ! $this->_construction_finalized) { |
|
285 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso'), get_class($this))); |
|
286 | 286 | } |
287 | 287 | return $this->_name; |
288 | 288 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * Gets the parent section |
294 | 294 | * @return EE_Form_Section_Proper |
295 | 295 | */ |
296 | - function parent_section(){ |
|
296 | + function parent_section() { |
|
297 | 297 | return $this->_parent_section; |
298 | 298 | } |
299 | 299 | |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - public function form_open( $action = '', $method = '', $other_attributes = '' ) { |
|
310 | - if ( ! empty( $action )) { |
|
311 | - $this->set_action( $action ); |
|
309 | + public function form_open($action = '', $method = '', $other_attributes = '') { |
|
310 | + if ( ! empty($action)) { |
|
311 | + $this->set_action($action); |
|
312 | 312 | } |
313 | - if ( ! empty( $method )) { |
|
314 | - $this->set_method( $method ); |
|
313 | + if ( ! empty($method)) { |
|
314 | + $this->set_method($method); |
|
315 | 315 | } |
316 | - $html = EEH_HTML::nl( 1, 'form' ) . '<form'; |
|
317 | - $html .= $this->html_id() !== '' ? ' id="' . $this->html_id() . '"' : ''; |
|
318 | - $html .= ' action="' . $this->action() . '"'; |
|
319 | - $html .= ' method="' . $this->method() . '"'; |
|
320 | - $html .= $other_attributes . '>'; |
|
316 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
317 | + $html .= $this->html_id() !== '' ? ' id="'.$this->html_id().'"' : ''; |
|
318 | + $html .= ' action="'.$this->action().'"'; |
|
319 | + $html .= ' method="'.$this->method().'"'; |
|
320 | + $html .= $other_attributes.'>'; |
|
321 | 321 | return $html; |
322 | 322 | } |
323 | 323 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @return string |
329 | 329 | */ |
330 | 330 | public function form_close() { |
331 | - return EEH_HTML::nl( -1, 'form' ) . '</form>' . EEH_HTML::nl() . '<!-- end of ee-' . $this->html_id() . '-form -->' . EEH_HTML::nl(); |
|
331 | + return EEH_HTML::nl( -1, 'form' ).'</form>'.EEH_HTML::nl().'<!-- end of ee-'.$this->html_id().'-form -->'.EEH_HTML::nl(); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 |
@@ -2,16 +2,16 @@ |
||
2 | 2 | if (!defined('EVENT_ESPRESSO_VERSION')) |
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | /** |
5 | - * EE_Form_Section_HTML |
|
6 | - * HTML to be laid out like a proper subsection |
|
7 | - * |
|
8 | - * |
|
9 | - * @package Event Espresso |
|
10 | - * @subpackage |
|
11 | - * @author Mike Nelson |
|
12 | - * |
|
13 | - * ------------------------------------------------------------------------ |
|
14 | - */ |
|
5 | + * EE_Form_Section_HTML |
|
6 | + * HTML to be laid out like a proper subsection |
|
7 | + * |
|
8 | + * |
|
9 | + * @package Event Espresso |
|
10 | + * @subpackage |
|
11 | + * @author Mike Nelson |
|
12 | + * |
|
13 | + * ------------------------------------------------------------------------ |
|
14 | + */ |
|
15 | 15 | class EE_Form_Section_HTML extends EE_Form_Section_Base{ |
16 | 16 | |
17 | 17 | protected $_html = ''; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | /** |
5 | 5 | * EE_Form_Section_HTML |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * ------------------------------------------------------------------------ |
14 | 14 | */ |
15 | -class EE_Form_Section_HTML extends EE_Form_Section_Base{ |
|
15 | +class EE_Form_Section_HTML extends EE_Form_Section_Base { |
|
16 | 16 | |
17 | 17 | protected $_html = ''; |
18 | 18 | |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | * @param string $html |
23 | 23 | * @param array $options_array |
24 | 24 | */ |
25 | - public function __construct( $html = '', $options_array = array() ) { |
|
25 | + public function __construct($html = '', $options_array = array()) { |
|
26 | 26 | $this->_html = $html; |
27 | - parent::__construct( $options_array ); |
|
27 | + parent::__construct($options_array); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 |
@@ -1,6 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | +} |
|
4 | 5 | /** |
5 | 6 | * EE_Form_Section_HTML |
6 | 7 | * HTML to be laid out like a proper subsection |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EE_Form_Section_HTML_From_Template extends EE_Form_Section_HTML{ |
|
29 | - public function __construct($template_file,$args = array(), $options_array = array()) { |
|
28 | +class EE_Form_Section_HTML_From_Template extends EE_Form_Section_HTML { |
|
29 | + public function __construct($template_file, $args = array(), $options_array = array()) { |
|
30 | 30 | EE_Registry::instance()->load_helper('Template'); |
31 | - $html = EEH_Template::locate_template( $template_file, $args ); |
|
31 | + $html = EEH_Template::locate_template($template_file, $args); |
|
32 | 32 | |
33 | 33 | // echo " filepath:$template_file html $html"; |
34 | 34 | parent::__construct($html, $options_array); |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | +} |
|
5 | 6 | |
6 | 7 | /** |
7 | 8 | * Event Espresso |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | if(isset($default_data[$subsection_name])){ |
210 | 210 | if($subsection instanceof EE_Form_Input_Base){ |
211 | 211 | $subsection->set_default($default_data[$subsection_name]); |
212 | - }elseif($subsection instanceof EE_Form_Section_Proper){ |
|
212 | + } elseif($subsection instanceof EE_Form_Section_Proper){ |
|
213 | 213 | $subsection->populate_defaults($default_data[$subsection_name]); |
214 | 214 | } |
215 | 215 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | foreach($this->subsections() as $subsection){ |
441 | 441 | if( $subsection instanceof EE_Form_Input_Base ){ |
442 | 442 | $inputs[ $subsection->html_name() ] = $subsection; |
443 | - }elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
443 | + } elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
444 | 444 | $inputs += $subsection->inputs_in_subsections(); |
445 | 445 | } |
446 | 446 | } |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | foreach($this->get_validatable_subsections() as $subsection){ |
549 | 549 | try{ |
550 | 550 | $subsection->_normalize($req_data); |
551 | - }catch( EE_Validation_Error $e ){ |
|
551 | + } catch( EE_Validation_Error $e ){ |
|
552 | 552 | $subsection->add_validation_error( $e ); |
553 | 553 | } |
554 | 554 | } |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | public function html_name_prefix(){ |
867 | 867 | if( $this->parent_section() instanceof EE_Form_Section_Proper ){ |
868 | 868 | return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
869 | - }else{ |
|
869 | + } else{ |
|
870 | 870 | return $this->name(); |
871 | 871 | } |
872 | 872 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | if( $subsection->form_data_present_in( $req_data ) ) { |
919 | 919 | return TRUE; |
920 | 920 | } |
921 | - }elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
921 | + } elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
922 | 922 | if( $subsection->form_data_present_in( $req_data ) ) { |
923 | 923 | return TRUE; |
924 | 924 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * before the hook wp_enqueue_scripts is called (so that the form section can enqueue its needed scripts). |
8 | 8 | * However, you may output the form (usually by calling get_html_and_js) anywhere you like. |
9 | 9 | */ |
10 | -class EE_Form_Section_Proper extends EE_Form_Section_Validatable{ |
|
10 | +class EE_Form_Section_Proper extends EE_Form_Section_Validatable { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Subsections |
@@ -68,38 +68,38 @@ discard block |
||
68 | 68 | * } @see EE_Form_Section_Validatable::__construct() |
69 | 69 | * |
70 | 70 | */ |
71 | - public function __construct( $options_array = array() ){ |
|
71 | + public function __construct($options_array = array()) { |
|
72 | 72 | EE_Registry::instance()->load_helper('Formatter'); |
73 | - $options_array = apply_filters( 'FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this ); |
|
73 | + $options_array = apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this); |
|
74 | 74 | //call parent first, as it may be setting the name |
75 | 75 | parent::__construct($options_array); |
76 | 76 | //if they've included subsections in the constructor, add them now |
77 | - if( isset( $options_array['include'] )){ |
|
77 | + if (isset($options_array['include'])) { |
|
78 | 78 | //we are going to make sure we ONLY have those subsections to include |
79 | 79 | //AND we are going to make sure they're in that specified order |
80 | 80 | $reordered_subsections = array(); |
81 | - foreach($options_array['include'] as $input_name){ |
|
82 | - if(isset($this->_subsections[$input_name])){ |
|
81 | + foreach ($options_array['include'] as $input_name) { |
|
82 | + if (isset($this->_subsections[$input_name])) { |
|
83 | 83 | $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
84 | 84 | } |
85 | 85 | } |
86 | 86 | $this->_subsections = $reordered_subsections; |
87 | 87 | } |
88 | - if(isset($options_array['exclude'])){ |
|
88 | + if (isset($options_array['exclude'])) { |
|
89 | 89 | $exclude = $options_array['exclude']; |
90 | 90 | $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
91 | 91 | } |
92 | - if(isset($options_array['layout_strategy'])){ |
|
92 | + if (isset($options_array['layout_strategy'])) { |
|
93 | 93 | $this->_layout_strategy = $options_array['layout_strategy']; |
94 | 94 | } |
95 | - if( ! $this->_layout_strategy){ |
|
95 | + if ( ! $this->_layout_strategy) { |
|
96 | 96 | $this->_layout_strategy = new EE_Two_Column_Layout(); |
97 | 97 | } |
98 | 98 | $this->_layout_strategy->_construct_finalize($this); |
99 | 99 | |
100 | - add_action( 'wp_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
101 | - add_action( 'admin_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
102 | - add_action( 'wp_footer', array( $this, 'ensure_scripts_localized' ), 1 ); |
|
100 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
101 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
102 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -111,25 +111,25 @@ discard block |
||
111 | 111 | * @param string $name |
112 | 112 | * @throws \EE_Error |
113 | 113 | */ |
114 | - public function _construct_finalize( $parent_form_section, $name ) { |
|
114 | + public function _construct_finalize($parent_form_section, $name) { |
|
115 | 115 | parent::_construct_finalize($parent_form_section, $name); |
116 | 116 | $this->_set_default_name_if_empty(); |
117 | 117 | $this->_set_default_html_id_if_empty(); |
118 | - foreach( $this->_subsections as $subsection_name => $subsection ){ |
|
119 | - if ( $subsection instanceof EE_Form_Section_Base ) { |
|
120 | - $subsection->_construct_finalize( $this, $subsection_name ); |
|
118 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
119 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
120 | + $subsection->_construct_finalize($this, $subsection_name); |
|
121 | 121 | } else { |
122 | 122 | throw new EE_Error( |
123 | 123 | sprintf( |
124 | - __( 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso' ), |
|
124 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso'), |
|
125 | 125 | $subsection_name, |
126 | 126 | get_class($this), |
127 | - $subsection ? get_class($subsection) : __( 'NULL', 'event_espresso' ) |
|
127 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
128 | 128 | ) |
129 | 129 | ); |
130 | 130 | } |
131 | 131 | } |
132 | - do_action( 'AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name ); |
|
132 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * Gets the layout strategy for this form section |
139 | 139 | * @return EE_Form_Section_Layout_Base |
140 | 140 | */ |
141 | - public function get_layout_strategy(){ |
|
141 | + public function get_layout_strategy() { |
|
142 | 142 | return $this->_layout_strategy; |
143 | 143 | } |
144 | 144 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param EE_Form_Input_Base $input |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function get_html_for_input($input){ |
|
153 | + public function get_html_for_input($input) { |
|
154 | 154 | return $this->_layout_strategy->layout_input($input); |
155 | 155 | } |
156 | 156 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param null $form_data |
164 | 164 | * @return boolean |
165 | 165 | */ |
166 | - public function was_submitted($form_data = NULL){ |
|
166 | + public function was_submitted($form_data = NULL) { |
|
167 | 167 | return $this->form_data_present_in($form_data); |
168 | 168 | } |
169 | 169 | |
@@ -184,16 +184,16 @@ discard block |
||
184 | 184 | * to skip this step. |
185 | 185 | * @return void |
186 | 186 | */ |
187 | - public function receive_form_submission($req_data = NULL, $validate = TRUE){ |
|
188 | - $req_data = apply_filters( 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, $validate ); |
|
189 | - if( $req_data === NULL){ |
|
187 | + public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
|
188 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, $validate); |
|
189 | + if ($req_data === NULL) { |
|
190 | 190 | $req_data = $_REQUEST; |
191 | 191 | } |
192 | 192 | $this->_normalize($req_data); |
193 | - if( $validate ){ |
|
193 | + if ($validate) { |
|
194 | 194 | $this->_validate(); |
195 | 195 | } |
196 | - do_action( 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate ); |
|
196 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | * the value being an array formatted in teh same way |
207 | 207 | * @param array $default_data |
208 | 208 | */ |
209 | - public function populate_defaults($default_data){ |
|
210 | - foreach($this->subsections() as $subsection_name => $subsection){ |
|
211 | - if(isset($default_data[$subsection_name])){ |
|
212 | - if($subsection instanceof EE_Form_Input_Base){ |
|
209 | + public function populate_defaults($default_data) { |
|
210 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
211 | + if (isset($default_data[$subsection_name])) { |
|
212 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
213 | 213 | $subsection->set_default($default_data[$subsection_name]); |
214 | - }elseif($subsection instanceof EE_Form_Section_Proper){ |
|
214 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
215 | 215 | $subsection->populate_defaults($default_data[$subsection_name]); |
216 | 216 | } |
217 | 217 | } |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | * (realizing that the subsections' html names might not be set yet, etc.) |
230 | 230 | * @return EE_Form_Section_Base |
231 | 231 | */ |
232 | - public function get_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
233 | - if( $require_construction_to_be_finalized ){ |
|
232 | + public function get_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
233 | + if ($require_construction_to_be_finalized) { |
|
234 | 234 | $this->ensure_construct_finalized_called(); |
235 | 235 | } |
236 | 236 | return isset($this->_subsections[$name]) ? $this->_subsections[$name] : NULL; |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | * Gets all the validatable subsections of this form section |
243 | 243 | * @return EE_Form_Section_Validatable[] |
244 | 244 | */ |
245 | - public function get_validatable_subsections(){ |
|
245 | + public function get_validatable_subsections() { |
|
246 | 246 | $validatable_subsections = array(); |
247 | - foreach($this->subsections() as $name=>$obj){ |
|
248 | - if($obj instanceof EE_Form_Section_Validatable){ |
|
247 | + foreach ($this->subsections() as $name=>$obj) { |
|
248 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
249 | 249 | $validatable_subsections[$name] = $obj; |
250 | 250 | } |
251 | 251 | } |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | * @return EE_Form_Input_Base |
266 | 266 | * @throws EE_Error |
267 | 267 | */ |
268 | - public function get_input($name, $require_construction_to_be_finalized = TRUE ){ |
|
268 | + public function get_input($name, $require_construction_to_be_finalized = TRUE) { |
|
269 | 269 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
270 | - if( ! $subsection instanceof EE_Form_Input_Base){ |
|
271 | - throw new EE_Error(sprintf(__("Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", 'event_espresso'),$name, get_class($this),$subsection ? get_class($subsection) : __("NULL", 'event_espresso'))); |
|
270 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
271 | + throw new EE_Error(sprintf(__("Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", 'event_espresso'), $name, get_class($this), $subsection ? get_class($subsection) : __("NULL", 'event_espresso'))); |
|
272 | 272 | } |
273 | 273 | return $subsection; |
274 | 274 | } |
@@ -286,10 +286,10 @@ discard block |
||
286 | 286 | * @return EE_Form_Section_Proper |
287 | 287 | * @throws EE_Error |
288 | 288 | */ |
289 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
290 | - $subsection = $this->get_subsection( $name, $require_construction_to_be_finalized ); |
|
291 | - if( ! $subsection instanceof EE_Form_Section_Proper){ |
|
292 | - throw new EE_Error(sprintf(__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),$name, get_class($this))); |
|
289 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
290 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
291 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
292 | + throw new EE_Error(sprintf(__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), $name, get_class($this))); |
|
293 | 293 | } |
294 | 294 | return $subsection; |
295 | 295 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * @param string $name |
303 | 303 | * @return mixed depending on the input's type and its normalization strategy |
304 | 304 | */ |
305 | - public function get_input_value($name){ |
|
305 | + public function get_input_value($name) { |
|
306 | 306 | $input = $this->get_input($name); |
307 | 307 | return $input->normalized_value(); |
308 | 308 | } |
@@ -315,16 +315,16 @@ discard block |
||
315 | 315 | * @return boolean |
316 | 316 | */ |
317 | 317 | public function is_valid() { |
318 | - if( ! $this->has_received_submission()){ |
|
318 | + if ( ! $this->has_received_submission()) { |
|
319 | 319 | throw new EE_Error(sprintf(__("You cannot check if a form is valid before receiving the form submission using receive_form_submission", "event_espresso"))); |
320 | 320 | } |
321 | - if( ! parent::is_valid()){ |
|
321 | + if ( ! parent::is_valid()) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | 324 | //ok so no errors general to this entire form section. so let's check the subsections |
325 | - foreach( $this->get_validatable_subsections() as $subsection ){ |
|
326 | - if( ! $subsection->is_valid() || $subsection->get_validation_error_string() != '' ){ |
|
327 | - $this->set_submission_error_message( $subsection->get_validation_error_string() ); |
|
325 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
326 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() != '') { |
|
327 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | } |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | * gets teh default name of this form section if none is specified |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - protected function _set_default_name_if_empty(){ |
|
341 | - if( ! $this->_name ){ |
|
340 | + protected function _set_default_name_if_empty() { |
|
341 | + if ( ! $this->_name) { |
|
342 | 342 | $classname = get_class($this); |
343 | 343 | $default_name = str_replace("EE_", "", $classname); |
344 | - $this->_name = $default_name; |
|
344 | + $this->_name = $default_name; |
|
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * Also returns the HTML for the form, except for the form opening and closing tags |
353 | 353 | * (as the form section doesn't know where you necessarily want to send the information to), and except for a submit button. |
354 | 354 | */ |
355 | - public function get_html_and_js(){ |
|
355 | + public function get_html_and_js() { |
|
356 | 356 | $this->enqueue_js(); |
357 | 357 | return $this->get_html(); |
358 | 358 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
364 | 364 | * @return string |
365 | 365 | */ |
366 | - public function get_html(){ |
|
366 | + public function get_html() { |
|
367 | 367 | $this->ensure_construct_finalized_called(); |
368 | 368 | return $this->_layout_strategy->layout_form(); |
369 | 369 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * enqueues JS for the form |
375 | 375 | * @return string |
376 | 376 | */ |
377 | - public function enqueue_js(){ |
|
377 | + public function enqueue_js() { |
|
378 | 378 | $this->_enqueue_and_localize_form_js(); |
379 | 379 | } |
380 | 380 | |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | * @param boolean $init_form_validation_automatically whether or not we want the form validation to be triggered automatically or not |
391 | 391 | * @return void |
392 | 392 | */ |
393 | - public static function wp_enqueue_scripts( $init_form_validation_automatically = false ){ |
|
394 | - add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
395 | - wp_register_script( 'ee_form_section_validation', EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', array( 'jquery-validate', 'jquery-ui-datepicker' ), EVENT_ESPRESSO_VERSION, TRUE ); |
|
393 | + public static function wp_enqueue_scripts($init_form_validation_automatically = false) { |
|
394 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
395 | + wp_register_script('ee_form_section_validation', EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', array('jquery-validate', 'jquery-ui-datepicker'), EVENT_ESPRESSO_VERSION, TRUE); |
|
396 | 396 | |
397 | - wp_localize_script( 'ee_form_section_validation', 'ee_form_section_validation_init', array( 'init' => $init_form_validation_automatically ) ); |
|
397 | + wp_localize_script('ee_form_section_validation', 'ee_form_section_validation_init', array('init' => $init_form_validation_automatically)); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
405 | 405 | * but before the wordpress hook wp_loaded |
406 | 406 | */ |
407 | - public function _enqueue_and_localize_form_js(){ |
|
407 | + public function _enqueue_and_localize_form_js() { |
|
408 | 408 | $this->ensure_construct_finalized_called(); |
409 | 409 | //actually, we don't want to localize just yet. There may be other forms on the page. |
410 | 410 | //so we need to add our form section data to a static variable accessible by all form sections |
411 | 411 | //and localize it just before the footer |
412 | 412 | $this->localize_validation_rules(); |
413 | - add_action( 'wp_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ), 2 ); |
|
414 | - add_action( 'admin_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ) ); |
|
413 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
414 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -421,11 +421,11 @@ discard block |
||
421 | 421 | * @param bool $return_for_subsection |
422 | 422 | * @return void |
423 | 423 | */ |
424 | - public function localize_validation_rules( $return_for_subsection = FALSE ){ |
|
424 | + public function localize_validation_rules($return_for_subsection = FALSE) { |
|
425 | 425 | // we only want to localize vars ONCE for the entire form, so if the form section doesn't have a parent, then it must be the top dog |
426 | - if ( ! $this->parent_section() || $return_for_subsection ) { |
|
427 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
428 | - 'form_section_id'=> $this->html_id( TRUE ), |
|
426 | + if ( ! $this->parent_section() || $return_for_subsection) { |
|
427 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
428 | + 'form_section_id'=> $this->html_id(TRUE), |
|
429 | 429 | 'validation_rules'=> $this->get_jquery_validation_rules(), |
430 | 430 | 'errors'=> $this->subsection_validation_errors_by_html_name() |
431 | 431 | ); |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | * Keys are their form names, and values are the inputs themselves |
441 | 441 | * @return EE_Form_Input_Base |
442 | 442 | */ |
443 | - public function inputs_in_subsections(){ |
|
443 | + public function inputs_in_subsections() { |
|
444 | 444 | $inputs = array(); |
445 | - foreach($this->subsections() as $subsection){ |
|
446 | - if( $subsection instanceof EE_Form_Input_Base ){ |
|
447 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
448 | - }elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
445 | + foreach ($this->subsections() as $subsection) { |
|
446 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
447 | + $inputs[$subsection->html_name()] = $subsection; |
|
448 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
449 | 449 | $inputs += $subsection->inputs_in_subsections(); |
450 | 450 | } |
451 | 451 | } |
@@ -458,12 +458,12 @@ discard block |
||
458 | 458 | * and values are a string of all their validation errors |
459 | 459 | * @return string[] |
460 | 460 | */ |
461 | - public function subsection_validation_errors_by_html_name(){ |
|
461 | + public function subsection_validation_errors_by_html_name() { |
|
462 | 462 | $inputs = $this->inputs(); |
463 | 463 | $errors = array(); |
464 | - foreach( $inputs as $form_input ){ |
|
465 | - if ( $form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors() ){ |
|
466 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
464 | + foreach ($inputs as $form_input) { |
|
465 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
466 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | return $errors; |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
476 | 476 | * Should be setup by each form during the _enqueues_and_localize_form_js |
477 | 477 | */ |
478 | - public static function localize_script_for_all_forms(){ |
|
478 | + public static function localize_script_for_all_forms() { |
|
479 | 479 | //allow inputs and stuff to hook in their JS and stuff here |
480 | 480 | do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
481 | 481 | EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
482 | - wp_enqueue_script( 'ee_form_section_validation' ); |
|
483 | - wp_localize_script( 'ee_form_section_validation', 'ee_form_section_vars', EE_Form_Section_Proper::$_js_localization ); |
|
482 | + wp_enqueue_script('ee_form_section_validation'); |
|
483 | + wp_localize_script('ee_form_section_validation', 'ee_form_section_vars', EE_Form_Section_Proper::$_js_localization); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | |
@@ -488,8 +488,8 @@ discard block |
||
488 | 488 | /** |
489 | 489 | * ensure_scripts_localized |
490 | 490 | */ |
491 | - public function ensure_scripts_localized(){ |
|
492 | - if ( ! EE_Form_Section_Proper::$_scripts_localized ) { |
|
491 | + public function ensure_scripts_localized() { |
|
492 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
493 | 493 | $this->_enqueue_and_localize_form_js(); |
494 | 494 | } |
495 | 495 | } |
@@ -501,10 +501,10 @@ discard block |
||
501 | 501 | * is that the key here should be the same as the custom validation rule put in the JS file |
502 | 502 | * @return array keys are custom validation rules, and values are internationalized strings |
503 | 503 | */ |
504 | - private static function _get_localized_error_messages(){ |
|
504 | + private static function _get_localized_error_messages() { |
|
505 | 505 | return array( |
506 | 506 | 'validUrl'=> __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
507 | - 'regex' => __( 'Please check your input', 'event_espresso' ), |
|
507 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
508 | 508 | ); |
509 | 509 | } |
510 | 510 | |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | * Gets the JS to put inside the jquery validation rules for subsection of this form section. See parent function for more... |
533 | 533 | * @return array |
534 | 534 | */ |
535 | - function get_jquery_validation_rules(){ |
|
535 | + function get_jquery_validation_rules() { |
|
536 | 536 | $jquery_validation_rules = array(); |
537 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
538 | - $jquery_validation_rules = array_merge( $jquery_validation_rules, $subsection->get_jquery_validation_rules() ); |
|
537 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
538 | + $jquery_validation_rules = array_merge($jquery_validation_rules, $subsection->get_jquery_validation_rules()); |
|
539 | 539 | } |
540 | 540 | return $jquery_validation_rules; |
541 | 541 | } |
@@ -550,11 +550,11 @@ discard block |
||
550 | 550 | protected function _normalize($req_data) { |
551 | 551 | $this->_received_submission = TRUE; |
552 | 552 | $this->_validation_errors = array(); |
553 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
554 | - try{ |
|
553 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
554 | + try { |
|
555 | 555 | $subsection->_normalize($req_data); |
556 | - }catch( EE_Validation_Error $e ){ |
|
557 | - $subsection->add_validation_error( $e ); |
|
556 | + } catch (EE_Validation_Error $e) { |
|
557 | + $subsection->add_validation_error($e); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | } |
@@ -568,9 +568,9 @@ discard block |
||
568 | 568 | * calling parent::_validate() first. |
569 | 569 | */ |
570 | 570 | protected function _validate() { |
571 | - foreach($this->get_validatable_subsections() as $subsection_name => $subsection){ |
|
572 | - if(method_exists($this,'_validate_'.$subsection_name)){ |
|
573 | - call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
571 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
572 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
573 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
574 | 574 | } |
575 | 575 | $subsection->_validate(); |
576 | 576 | } |
@@ -582,13 +582,13 @@ discard block |
||
582 | 582 | * Gets all the validated inputs for the form section |
583 | 583 | * @return array |
584 | 584 | */ |
585 | - public function valid_data(){ |
|
585 | + public function valid_data() { |
|
586 | 586 | $inputs = array(); |
587 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
588 | - if ( $subsection instanceof EE_Form_Section_Proper ) { |
|
589 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
590 | - } else if ( $subsection instanceof EE_Form_Input_Base ){ |
|
591 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
587 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
588 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
589 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
590 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
591 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | return $inputs; |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | * Gets all the inputs on this form section |
601 | 601 | * @return EE_Form_Input_Base[] |
602 | 602 | */ |
603 | - public function inputs(){ |
|
603 | + public function inputs() { |
|
604 | 604 | $inputs = array(); |
605 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
606 | - if ( $subsection instanceof EE_Form_Input_Base ){ |
|
607 | - $inputs[ $subsection_name ] = $subsection; |
|
605 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
606 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
607 | + $inputs[$subsection_name] = $subsection; |
|
608 | 608 | } |
609 | 609 | } |
610 | 610 | return $inputs; |
@@ -616,10 +616,10 @@ discard block |
||
616 | 616 | * Gets all the subsections which are a proper form |
617 | 617 | * @return EE_Form_Section_Proper[] |
618 | 618 | */ |
619 | - public function subforms(){ |
|
619 | + public function subforms() { |
|
620 | 620 | $form_sections = array(); |
621 | - foreach($this->subsections() as $name=>$obj){ |
|
622 | - if($obj instanceof EE_Form_Section_Proper){ |
|
621 | + foreach ($this->subsections() as $name=>$obj) { |
|
622 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
623 | 623 | $form_sections[$name] = $obj; |
624 | 624 | } |
625 | 625 | } |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | * if you only want form inputs or proper form sections. |
635 | 635 | * @return EE_Form_Section_Proper[] |
636 | 636 | */ |
637 | - public function subsections(){ |
|
637 | + public function subsections() { |
|
638 | 638 | $this->ensure_construct_finalized_called(); |
639 | 639 | return $this->_subsections; |
640 | 640 | } |
@@ -652,8 +652,8 @@ discard block |
||
652 | 652 | * it can be a multidimensional array where keys are always subsection names and values are either the |
653 | 653 | * input's normalized value, or an array like the top-level array |
654 | 654 | */ |
655 | - public function input_values( $include_subform_inputs = false, $flatten = false ){ |
|
656 | - return $this->_input_values( false, $include_subform_inputs, $flatten ); |
|
655 | + public function input_values($include_subform_inputs = false, $flatten = false) { |
|
656 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -669,8 +669,8 @@ discard block |
||
669 | 669 | * it can be a multidimensional array where keys are always subsection names and values are either the |
670 | 670 | * input's normalized value, or an array like the top-level array |
671 | 671 | */ |
672 | - public function input_pretty_values( $include_subform_inputs = false, $flatten = false ){ |
|
673 | - return $this->_input_values( true, $include_subform_inputs, $flatten ); |
|
672 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) { |
|
673 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
@@ -683,17 +683,17 @@ discard block |
||
683 | 683 | * it can be a multidimensional array where keys are always subsection names and values are either the |
684 | 684 | * input's normalized value, or an array like the top-level array |
685 | 685 | */ |
686 | - public function _input_values( $pretty = false, $include_subform_inputs = false, $flatten = false ) { |
|
686 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) { |
|
687 | 687 | $input_values = array(); |
688 | - foreach( $this->subsections() as $subsection_name => $subsection ) { |
|
689 | - if( $subsection instanceof EE_Form_Input_Base ) { |
|
690 | - $input_values[ $subsection_name ] = $pretty ? $subsection->pretty_value() : $subsection->normalized_value(); |
|
691 | - } else if( $subsection instanceof EE_Form_Section_Proper && $include_subform_inputs ) { |
|
692 | - $subform_input_values = $subsection->_input_values( $pretty, $include_subform_inputs, $flatten ); |
|
693 | - if( $flatten ) { |
|
694 | - $input_values = array_merge( $input_values, $subform_input_values ); |
|
688 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
689 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
690 | + $input_values[$subsection_name] = $pretty ? $subsection->pretty_value() : $subsection->normalized_value(); |
|
691 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
692 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
693 | + if ($flatten) { |
|
694 | + $input_values = array_merge($input_values, $subform_input_values); |
|
695 | 695 | } else { |
696 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
696 | + $input_values[$subsection_name] = $subform_input_values; |
|
697 | 697 | } |
698 | 698 | } |
699 | 699 | } |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | * (ie, had receive_form_submission called on it yet) |
708 | 708 | * @return boolean |
709 | 709 | */ |
710 | - public function has_received_submission(){ |
|
710 | + public function has_received_submission() { |
|
711 | 711 | $this->ensure_construct_finalized_called(); |
712 | 712 | return $this->_received_submission; |
713 | 713 | } |
@@ -720,8 +720,8 @@ discard block |
||
720 | 720 | * @param array $inputs_to_exclude values are the input names |
721 | 721 | * @return void |
722 | 722 | */ |
723 | - public function exclude($inputs_to_exclude = array()){ |
|
724 | - foreach($inputs_to_exclude as $input_to_exclude_name){ |
|
723 | + public function exclude($inputs_to_exclude = array()) { |
|
724 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
725 | 725 | unset($this->_subsections[$input_to_exclude_name]); |
726 | 726 | } |
727 | 727 | } |
@@ -731,8 +731,8 @@ discard block |
||
731 | 731 | /** |
732 | 732 | * @param array $inputs_to_hide |
733 | 733 | */ |
734 | - public function hide($inputs_to_hide= array()){ |
|
735 | - foreach($inputs_to_hide as $input_to_hide){ |
|
734 | + public function hide($inputs_to_hide = array()) { |
|
735 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
736 | 736 | $input = $this->get_input($input_to_hide); |
737 | 737 | |
738 | 738 | $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
@@ -757,13 +757,13 @@ discard block |
||
757 | 757 | * or if $subsection_name_to_target is null, before or after entire subsections array |
758 | 758 | * @return void |
759 | 759 | */ |
760 | - public function add_subsections( $new_subsections, $subsection_name_to_target = NULL, $add_before = true ){ |
|
761 | - foreach($new_subsections as $subsection_name => $subsection){ |
|
762 | - if( ! $subsection instanceof EE_Form_Section_Base){ |
|
760 | + public function add_subsections($new_subsections, $subsection_name_to_target = NULL, $add_before = true) { |
|
761 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
762 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
763 | 763 | EE_Error::add_error( |
764 | 764 | sprintf( |
765 | 765 | __("Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", "event_espresso"), |
766 | - get_class( $subsection ), |
|
766 | + get_class($subsection), |
|
767 | 767 | $subsection_name, |
768 | 768 | $this->name() |
769 | 769 | ) |
@@ -772,8 +772,8 @@ discard block |
||
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - EE_Registry::instance()->load_helper( 'Array' ); |
|
776 | - $this->_subsections = EEH_Array::insert_into_array( $this->_subsections, $new_subsections, $subsection_name_to_target, $add_before ); |
|
775 | + EE_Registry::instance()->load_helper('Array'); |
|
776 | + $this->_subsections = EEH_Array::insert_into_array($this->_subsections, $new_subsections, $subsection_name_to_target, $add_before); |
|
777 | 777 | |
778 | 778 | /*$subsections_before = array(); |
779 | 779 | if( $subsection_name_to_target ){ |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | $this->_subsections = $new_subsections; |
805 | 805 | } |
806 | 806 | }*/ |
807 | - if( $this->_construction_finalized ){ |
|
808 | - foreach($this->_subsections as $name => $subsection){ |
|
807 | + if ($this->_construction_finalized) { |
|
808 | + foreach ($this->_subsections as $name => $subsection) { |
|
809 | 809 | $subsection->_construct_finalize($this, $name); |
810 | 810 | } |
811 | 811 | } |
@@ -816,8 +816,8 @@ discard block |
||
816 | 816 | /** |
817 | 817 | * Just gets all validatable subsections to clean their sensitive data |
818 | 818 | */ |
819 | - public function clean_sensitive_data(){ |
|
820 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
819 | + public function clean_sensitive_data() { |
|
820 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
821 | 821 | $subsection->clean_sensitive_data(); |
822 | 822 | } |
823 | 823 | } |
@@ -827,8 +827,8 @@ discard block |
||
827 | 827 | /** |
828 | 828 | * @param string $form_submission_error_message |
829 | 829 | */ |
830 | - public function set_submission_error_message( $form_submission_error_message = '' ) { |
|
831 | - $this->_form_submission_error_message .= ! empty( $form_submission_error_message ) ? $form_submission_error_message : __( 'Form submission failed due to errors', 'event_espresso' ); |
|
830 | + public function set_submission_error_message($form_submission_error_message = '') { |
|
831 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) ? $form_submission_error_message : __('Form submission failed due to errors', 'event_espresso'); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | |
@@ -845,8 +845,8 @@ discard block |
||
845 | 845 | /** |
846 | 846 | * @param string $form_submission_success_message |
847 | 847 | */ |
848 | - public function set_submission_success_message( $form_submission_success_message ) { |
|
849 | - $this->_form_submission_success_message .= ! empty( $form_submission_success_message ) ? $form_submission_success_message : __( 'Form submitted successfully', 'event_espresso' ); |
|
848 | + public function set_submission_success_message($form_submission_success_message) { |
|
849 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) ? $form_submission_success_message : __('Form submitted successfully', 'event_espresso'); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | |
@@ -868,10 +868,10 @@ discard block |
||
868 | 868 | * EE_Form_Input_Base::_set_default_html_name_if_empty |
869 | 869 | * @return string |
870 | 870 | */ |
871 | - public function html_name_prefix(){ |
|
872 | - if( $this->parent_section() instanceof EE_Form_Section_Proper ){ |
|
873 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
874 | - }else{ |
|
871 | + public function html_name_prefix() { |
|
872 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
873 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
874 | + } else { |
|
875 | 875 | return $this->name(); |
876 | 876 | } |
877 | 877 | } |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | * was set, which is probably nothing, or the classname) |
883 | 883 | * @return string |
884 | 884 | */ |
885 | - public function name(){ |
|
885 | + public function name() { |
|
886 | 886 | $this->ensure_construct_finalized_called(); |
887 | 887 | return parent::name(); |
888 | 888 | } |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | * |
892 | 892 | * @return EE_Form_Section_Proper |
893 | 893 | */ |
894 | - public function parent_section(){ |
|
894 | + public function parent_section() { |
|
895 | 895 | $this->ensure_construct_finalized_called(); |
896 | 896 | return parent::parent_section(); |
897 | 897 | } |
@@ -900,9 +900,9 @@ discard block |
||
900 | 900 | * make sure construction finalized was called, otherwise children might not be ready |
901 | 901 | * @return void |
902 | 902 | */ |
903 | - public function ensure_construct_finalized_called(){ |
|
904 | - if( ! $this->_construction_finalized ){ |
|
905 | - $this->_construct_finalize($this->_parent_section, $this->_name ); |
|
903 | + public function ensure_construct_finalized_called() { |
|
904 | + if ( ! $this->_construction_finalized) { |
|
905 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
906 | 906 | } |
907 | 907 | } |
908 | 908 | |
@@ -914,17 +914,17 @@ discard block |
||
914 | 914 | * @param array $req_data |
915 | 915 | * @return boolean |
916 | 916 | */ |
917 | - public function form_data_present_in( $req_data = NULL ) { |
|
918 | - if( $req_data === NULL){ |
|
917 | + public function form_data_present_in($req_data = NULL) { |
|
918 | + if ($req_data === NULL) { |
|
919 | 919 | $req_data = $_POST; |
920 | 920 | } |
921 | - foreach( $this->subsections() as $subsection ) { |
|
922 | - if($subsection instanceof EE_Form_Input_Base ) { |
|
923 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
921 | + foreach ($this->subsections() as $subsection) { |
|
922 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
923 | + if ($subsection->form_data_present_in($req_data)) { |
|
924 | 924 | return TRUE; |
925 | 925 | } |
926 | - }elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
927 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
926 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
927 | + if ($subsection->form_data_present_in($req_data)) { |
|
928 | 928 | return TRUE; |
929 | 929 | } |
930 | 930 | } |
@@ -941,14 +941,14 @@ discard block |
||
941 | 941 | */ |
942 | 942 | public function get_validation_errors_accumulated() { |
943 | 943 | $validation_errors = $this->get_validation_errors(); |
944 | - foreach($this->get_validatable_subsections() as $subsection ) { |
|
945 | - if( $subsection instanceof EE_Form_Section_Proper ) { |
|
944 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
945 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
946 | 946 | $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
947 | 947 | } else { |
948 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
948 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
949 | 949 | } |
950 | - if( $validation_errors_on_this_subsection ){ |
|
951 | - $validation_errors = array_merge( $validation_errors, $validation_errors_on_this_subsection ); |
|
950 | + if ($validation_errors_on_this_subsection) { |
|
951 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
952 | 952 | } |
953 | 953 | } |
954 | 954 | return $validation_errors; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * ------------------------------------------------------------------------ |
36 | 36 | */ |
37 | -abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base{ |
|
37 | +abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base { |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Array of validation errors in this section. Does not contain validation errors in subsections, however. |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * called get_validation_errors_accumulated |
50 | 50 | * @return EE_Validation_Error[] |
51 | 51 | */ |
52 | - public function get_validation_errors(){ |
|
52 | + public function get_validation_errors() { |
|
53 | 53 | return $this->_validation_errors; |
54 | 54 | } |
55 | 55 | /** |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | * If we want this to be customizable, we may decide to create a strategy for displaying it. |
58 | 58 | * @return string |
59 | 59 | */ |
60 | - public function get_validation_error_string(){ |
|
60 | + public function get_validation_error_string() { |
|
61 | 61 | $validation_error_messages = array(); |
62 | - if($this->get_validation_errors()){ |
|
63 | - foreach($this->get_validation_errors() as $validation_error){ |
|
64 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
65 | - $validation_error_messages[] =$validation_error->getMessage(); |
|
62 | + if ($this->get_validation_errors()) { |
|
63 | + foreach ($this->get_validation_errors() as $validation_error) { |
|
64 | + if ($validation_error instanceof EE_Validation_Error) { |
|
65 | + $validation_error_messages[] = $validation_error->getMessage(); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | - return implode(", ",$validation_error_messages); |
|
69 | + return implode(", ", $validation_error_messages); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @return boolean |
83 | 83 | */ |
84 | 84 | public function is_valid() { |
85 | - if(count($this->_validation_errors)){ |
|
85 | + if (count($this->_validation_errors)) { |
|
86 | 86 | return false; |
87 | - }else{ |
|
87 | + } else { |
|
88 | 88 | return true; |
89 | 89 | } |
90 | 90 | } |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * @param Exception $previous_exception if there was an exception that caused the error, that exception |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - function add_validation_error( $message_or_object, $error_code = NULL, $previous_exception = NULL ){ |
|
113 | - if($message_or_object instanceof EE_Validation_Error){ |
|
114 | - $validation_error= $message_or_object; |
|
112 | + function add_validation_error($message_or_object, $error_code = NULL, $previous_exception = NULL) { |
|
113 | + if ($message_or_object instanceof EE_Validation_Error) { |
|
114 | + $validation_error = $message_or_object; |
|
115 | 115 | $validation_error->set_form_section($this); |
116 | - }else{ |
|
116 | + } else { |
|
117 | 117 | $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
118 | 118 | } |
119 | 119 | $this->_validation_errors[] = $validation_error; |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | +} |
|
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Event Espresso |
@@ -84,7 +85,7 @@ discard block |
||
84 | 85 | public function is_valid() { |
85 | 86 | if(count($this->_validation_errors)){ |
86 | 87 | return false; |
87 | - }else{ |
|
88 | + } else{ |
|
88 | 89 | return true; |
89 | 90 | } |
90 | 91 | } |
@@ -113,7 +114,7 @@ discard block |
||
113 | 114 | if($message_or_object instanceof EE_Validation_Error){ |
114 | 115 | $validation_error= $message_or_object; |
115 | 116 | $validation_error->set_form_section($this); |
116 | - }else{ |
|
117 | + } else{ |
|
117 | 118 | $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
118 | 119 | } |
119 | 120 | $this->_validation_errors[] = $validation_error; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @since 4.5.0 |
12 | 12 | * |
13 | 13 | */ |
14 | -class EE_Model_Form_Section extends EE_Form_Section_Proper{ |
|
14 | +class EE_Model_Form_Section extends EE_Form_Section_Proper { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * |
@@ -36,36 +36,36 @@ discard block |
||
36 | 36 | * } |
37 | 37 | * @throws EE_Error |
38 | 38 | */ |
39 | - public function __construct($options_array = array()){ |
|
40 | - if(isset($options_array['model']) && $options_array['model'] instanceof EEM_Base){ |
|
39 | + public function __construct($options_array = array()) { |
|
40 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
41 | 41 | $this->_model = $options_array['model']; |
42 | 42 | } |
43 | - if( ! $this->_model || ! $this->_model instanceof EEM_Base ){ |
|
43 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | 44 | throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", "event_espresso"))); |
45 | 45 | } |
46 | 46 | |
47 | - if(isset($options_array['subsection_args'])){ |
|
47 | + if (isset($options_array['subsection_args'])) { |
|
48 | 48 | $subsection_args = $options_array['subsection_args']; |
49 | - }else{ |
|
49 | + } else { |
|
50 | 50 | $subsection_args = array(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | //gather fields and relations to convert to inputs |
54 | 54 | //but if they're just going to exclude a field anyways, don't bother converting it to an input |
55 | 55 | $exclude = $this->_subsections; |
56 | - if(isset($options_array['exclude'])){ |
|
57 | - $exclude = array_merge($exclude,array_flip($options_array['exclude'])); |
|
56 | + if (isset($options_array['exclude'])) { |
|
57 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
58 | 58 | } |
59 | 59 | $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
60 | 60 | $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
61 | 61 | //convert fields and relations to inputs |
62 | 62 | $this->_subsections = array_merge( |
63 | 63 | $this->_convert_model_fields_to_inputs($model_fields), |
64 | - $this->_convert_model_relations_to_inputs($model_relations,$subsection_args), |
|
64 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
65 | 65 | $this->_subsections |
66 | 66 | ); |
67 | 67 | parent::__construct($options_array); |
68 | - if(isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class){ |
|
68 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
69 | 69 | $this->populate_model_obj($options_array['model_object']); |
70 | 70 | } |
71 | 71 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * } |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - protected function _convert_model_relations_to_inputs($relations,$subsection_args = array()){ |
|
86 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) { |
|
87 | 87 | $inputs = array(); |
88 | - foreach( $relations as $relation_name => $relation_obj ) { |
|
88 | + foreach ($relations as $relation_name => $relation_obj) { |
|
89 | 89 | $input_constructor_args = array( |
90 | 90 | array_merge( |
91 | 91 | array( |
@@ -96,19 +96,19 @@ discard block |
||
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | $input = NULL; |
99 | - switch(get_class($relation_obj)){ |
|
99 | + switch (get_class($relation_obj)) { |
|
100 | 100 | case 'EE_HABTM_Relation': |
101 | - if(isset($subsection_args[$relation_name]) && |
|
102 | - isset($subsection_args[$relation_name]['model_objects'])){ |
|
101 | + if (isset($subsection_args[$relation_name]) && |
|
102 | + isset($subsection_args[$relation_name]['model_objects'])) { |
|
103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
104 | - }else{ |
|
104 | + } else { |
|
105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
106 | 106 | } |
107 | - $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
|
107 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
108 | 108 | break; |
109 | 109 | default: |
110 | 110 | } |
111 | - if($input){ |
|
111 | + if ($input) { |
|
112 | 112 | $inputs[$relation_name] = $input; |
113 | 113 | } |
114 | 114 | } |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | * @throws EE_Error |
124 | 124 | * @return EE_Form_Input_Base[] |
125 | 125 | */ |
126 | - protected function _convert_model_fields_to_inputs( $model_fields = array() ){ |
|
126 | + protected function _convert_model_fields_to_inputs($model_fields = array()) { |
|
127 | 127 | $inputs = array(); |
128 | - foreach( $model_fields as $field_name=>$model_field ){ |
|
129 | - if ( $model_field instanceof EE_Model_Field_Base ) { |
|
128 | + foreach ($model_fields as $field_name=>$model_field) { |
|
129 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
130 | 130 | $input_constructor_args = array( |
131 | 131 | array( |
132 | 132 | 'required'=> ! $model_field->is_nullable() && $model_field->get_default_value() === NULL, |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | 'default'=>$model_field->get_default_value(), |
135 | 135 | ) |
136 | 136 | ); |
137 | - switch(get_class($model_field)){ |
|
137 | + switch (get_class($model_field)) { |
|
138 | 138 | case 'EE_All_Caps_Text_Field': |
139 | 139 | case 'EE_Any_Foreign_Model_Name_Field': |
140 | 140 | $input_class = 'EE_Text_Input'; |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | $input_class = 'EE_Yes_No_Input'; |
144 | 144 | break; |
145 | 145 | case 'EE_Datetime_Field': |
146 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
146 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
147 | 147 | break; |
148 | 148 | case 'EE_Email_Field': |
149 | 149 | $input_class = 'EE_Email_Input'; |
150 | 150 | break; |
151 | 151 | case 'EE_Enum_Integer_Field': |
152 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
152 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
153 | 153 | break; |
154 | 154 | case 'EE_Enum_Text_Field': |
155 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
155 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
156 | 156 | break; |
157 | 157 | case 'EE_Float_Field': |
158 | 158 | $input_class = 'EE_Float_Input'; |
@@ -161,15 +161,15 @@ discard block |
||
161 | 161 | case 'EE_Foreign_Key_String_Field': |
162 | 162 | case 'EE_WP_User_Field': |
163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
164 | - if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
|
164 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
165 | 165 | $input_class = 'EE_Text_Input'; |
166 | - }else{ |
|
166 | + } else { |
|
167 | 167 | //so its just one model |
168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
170 | 170 | $model_names = $model->get_all_names(array('limit'=>10)); |
171 | - if($model_field->is_nullable()){ |
|
172 | - array_unshift( $model_names, __( "Please Select", 'event_espresso' )); |
|
171 | + if ($model_field->is_nullable()) { |
|
172 | + array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
173 | 173 | } |
174 | 174 | $input_constructor_args[1] = $input_constructor_args[0]; |
175 | 175 | $input_constructor_args[0] = $model_names; |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | break; |
179 | 179 | case 'EE_Full_HTML_Field': |
180 | 180 | $input_class = 'EE_Text_Area_Input'; |
181 | - $input_constructor_args[ 0 ]['validation_strategies'] = array( new EE_Full_HTML_Validation_Strategy() ); |
|
181 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
182 | 182 | break; |
183 | 183 | case 'EE_Infinite_Integer': |
184 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
184 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
185 | 185 | break; |
186 | 186 | case 'EE_Integer_Field': |
187 | 187 | $input_class = 'EE_Text_Input'; |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | $input_class = 'EE_Text_Area_Input'; |
191 | 191 | break; |
192 | 192 | case 'EE_Money_Field': |
193 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
193 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
194 | 194 | break; |
195 | 195 | case 'EE_Post_Content_Field': |
196 | 196 | $input_class = 'EE_Text_Area_Input'; |
197 | - $input_constructor_args[ 0 ][ 'validation_strategies' ] = array( new EE_Full_HTML_Validation_Strategy() ); |
|
197 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
198 | 198 | break; |
199 | 199 | case 'EE_Plain_Text_Field': |
200 | 200 | $input_class = 'EE_Text_Input'; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | break; |
212 | 212 | case 'EE_Simple_HTML_Field': |
213 | 213 | $input_class = 'EE_Text_Area_Input'; |
214 | - $input_constructor_args[ 0 ][ 'validation_strategies' ] = array( new EE_Simple_HTML_Validation_Strategy() ); |
|
214 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
215 | 215 | break; |
216 | 216 | case 'EE_Slug_Field': |
217 | 217 | $input_class = 'EE_Text_Input'; |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | $input_class = 'EE_Yes_No_Input'; |
221 | 221 | break; |
222 | 222 | case 'EE_WP_Post_Status_Field': |
223 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
223 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
224 | 224 | break; |
225 | 225 | case 'EE_WP_Post_Type_Field': |
226 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
226 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
227 | 227 | break; |
228 | 228 | default: |
229 | - throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"),get_class($model_field))); |
|
229 | + throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"), get_class($model_field))); |
|
230 | 230 | } |
231 | 231 | $reflection = new ReflectionClass($input_class); |
232 | 232 | $input = $reflection->newInstanceArgs($input_constructor_args); |
@@ -244,21 +244,21 @@ discard block |
||
244 | 244 | * @param EE_Base_Class $model_obj |
245 | 245 | * @return void |
246 | 246 | */ |
247 | - public function populate_model_obj($model_obj){ |
|
247 | + public function populate_model_obj($model_obj) { |
|
248 | 248 | $model_obj = $this->_model->ensure_is_obj($model_obj); |
249 | 249 | $this->_model_object = $model_obj; |
250 | 250 | $defaults = $model_obj->model_field_array(); |
251 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
251 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
252 | 252 | $form_inputs = $this->inputs(); |
253 | - if(isset($form_inputs[$relation_name])){ |
|
254 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
253 | + if (isset($form_inputs[$relation_name])) { |
|
254 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
255 | 255 | //then we only expect there to be one |
256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
258 | - }else{ |
|
258 | + } else { |
|
259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
260 | 260 | $ids = array(); |
261 | - foreach($related_items as $related_item){ |
|
261 | + foreach ($related_items as $related_item) { |
|
262 | 262 | $ids[] = $related_item->ID(); |
263 | 263 | } |
264 | 264 | $defaults[$relation_name] = $ids; |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * values are their normalized values |
276 | 276 | * @return array |
277 | 277 | */ |
278 | - public function inputs_values_corresponding_to_model_fields(){ |
|
279 | - return array_intersect_key($this->input_values(),$this->_model->field_settings()); |
|
278 | + public function inputs_values_corresponding_to_model_fields() { |
|
279 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -299,21 +299,21 @@ discard block |
||
299 | 299 | public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
300 | 300 | parent::receive_form_submission($req_data, $validate); |
301 | 301 | //create or set the model object, if it isn't already |
302 | - if( ! $this->_model_object ){ |
|
302 | + if ( ! $this->_model_object) { |
|
303 | 303 | //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
304 | 304 | $pk_name = $this->_model->primary_key_name(); |
305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
306 | - if($model_obj){ |
|
306 | + if ($model_obj) { |
|
307 | 307 | $this->_model_object = $model_obj; |
308 | - }else{ |
|
309 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
|
308 | + } else { |
|
309 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | //ok so the model object is set. Just set it with the submitted form data (don't save yet though) |
313 | - foreach($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value){ |
|
313 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value) { |
|
314 | 314 | //only set the non-primary key |
315 | - if($field_name != $this->_model->primary_key_name()){ |
|
316 | - $this->_model_object->set($field_name,$field_value); |
|
315 | + if ($field_name != $this->_model->primary_key_name()) { |
|
316 | + $this->_model_object->set($field_name, $field_value); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
@@ -329,13 +329,13 @@ discard block |
||
329 | 329 | * @return int, 1 on a successful update, the ID of |
330 | 330 | * the new entry on insert; 0 on failure |
331 | 331 | */ |
332 | - public function save(){ |
|
333 | - if( ! $this->_model_object){ |
|
334 | - throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"),get_class($this->_model))); |
|
332 | + public function save() { |
|
333 | + if ( ! $this->_model_object) { |
|
334 | + throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"), get_class($this->_model))); |
|
335 | 335 | } |
336 | - $success = $this->_model_object->save(); |
|
337 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
338 | - if(isset($this->_subsections[$relation_name])){ |
|
336 | + $success = $this->_model_object->save(); |
|
337 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
338 | + if (isset($this->_subsections[$relation_name])) { |
|
339 | 339 | $success = $this->_save_related_info($relation_name); |
340 | 340 | } |
341 | 341 | } |
@@ -351,29 +351,29 @@ discard block |
||
351 | 351 | * @return bool |
352 | 352 | * @throws EE_Error |
353 | 353 | */ |
354 | - protected function _save_related_info($relation_name){ |
|
354 | + protected function _save_related_info($relation_name) { |
|
355 | 355 | $relation_obj = $this->_model->related_settings_for($relation_name); |
356 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
356 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
357 | 357 | //there is just a foreign key on this model pointing to that one |
358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
359 | + }elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
360 | 360 | //then we want to consider all of its currently-related things. |
361 | 361 | //if they're in this list, keep them |
362 | 362 | //if they're not in this list, remove them |
363 | 363 | //and lastly add all the new items |
364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
365 | + }elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
366 | 366 | //delete everything NOT in this list |
367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
368 | - if($normalized_input_value && is_array($normalized_input_value)){ |
|
368 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
369 | 369 | $where_query_params = array( |
370 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
|
371 | - }else{ |
|
370 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value)); |
|
371 | + } else { |
|
372 | 372 | $where_query_params = array(); |
373 | 373 | } |
374 | - $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
|
375 | - foreach($normalized_input_value as $id){ |
|
376 | - $this->_model_object->_add_relation_to( $id, $relation_name ); |
|
374 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
375 | + foreach ($normalized_input_value as $id) { |
|
376 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | return TRUE; |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * Gets the model of this model form |
386 | 386 | * @return EEM_Base |
387 | 387 | */ |
388 | - public function get_model(){ |
|
388 | + public function get_model() { |
|
389 | 389 | return $this->_model; |
390 | 390 | } |
391 | 391 | |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * when receive_form_submission($req_data) was called. |
399 | 399 | * @return EE_Base_Class |
400 | 400 | */ |
401 | - public function get_model_object(){ |
|
401 | + public function get_model_object() { |
|
402 | 402 | return $this->_model_object; |
403 | 403 | } |
404 | 404 | |
@@ -408,10 +408,10 @@ discard block |
||
408 | 408 | * gets teh default name of this form section if none is specified |
409 | 409 | * @return string |
410 | 410 | */ |
411 | - protected function _set_default_name_if_empty(){ |
|
412 | - if( ! $this->_name ){ |
|
413 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
414 | - $this->_name = $default_name; |
|
411 | + protected function _set_default_name_if_empty() { |
|
412 | + if ( ! $this->_name) { |
|
413 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
414 | + $this->_name = $default_name; |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | if(isset($options_array['subsection_args'])){ |
48 | 48 | $subsection_args = $options_array['subsection_args']; |
49 | - }else{ |
|
49 | + } else{ |
|
50 | 50 | $subsection_args = array(); |
51 | 51 | } |
52 | 52 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | if(isset($subsection_args[$relation_name]) && |
102 | 102 | isset($subsection_args[$relation_name]['model_objects'])){ |
103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
104 | - }else{ |
|
104 | + } else{ |
|
105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
106 | 106 | } |
107 | 107 | $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
164 | 164 | if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
165 | 165 | $input_class = 'EE_Text_Input'; |
166 | - }else{ |
|
166 | + } else{ |
|
167 | 167 | //so its just one model |
168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | //then we only expect there to be one |
256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
258 | - }else{ |
|
258 | + } else{ |
|
259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
260 | 260 | $ids = array(); |
261 | 261 | foreach($related_items as $related_item){ |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
306 | 306 | if($model_obj){ |
307 | 307 | $this->_model_object = $model_obj; |
308 | - }else{ |
|
308 | + } else{ |
|
309 | 309 | $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
310 | 310 | } |
311 | 311 | } |
@@ -356,19 +356,19 @@ discard block |
||
356 | 356 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
357 | 357 | //there is just a foreign key on this model pointing to that one |
358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
359 | + } elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
360 | 360 | //then we want to consider all of its currently-related things. |
361 | 361 | //if they're in this list, keep them |
362 | 362 | //if they're not in this list, remove them |
363 | 363 | //and lastly add all the new items |
364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
365 | + } elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
366 | 366 | //delete everything NOT in this list |
367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
368 | 368 | if($normalized_input_value && is_array($normalized_input_value)){ |
369 | 369 | $where_query_params = array( |
370 | 370 | $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
371 | - }else{ |
|
371 | + } else{ |
|
372 | 372 | $where_query_params = array(); |
373 | 373 | } |
374 | 374 | $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |