@@ -15,88 +15,88 @@ |
||
15 | 15 | * ------------------------------------------------------------------------ |
16 | 16 | */ |
17 | 17 | /** |
18 | - * |
|
19 | - * Class EE_Receipt_Line_Item_Display_Strategy |
|
20 | - * |
|
21 | - * Description |
|
22 | - * |
|
23 | - * @package Event Espresso |
|
24 | - * @subpackage core |
|
25 | - * @author Brent Christensen |
|
26 | - * |
|
27 | - * |
|
28 | - */ |
|
18 | + * |
|
19 | + * Class EE_Receipt_Line_Item_Display_Strategy |
|
20 | + * |
|
21 | + * Description |
|
22 | + * |
|
23 | + * @package Event Espresso |
|
24 | + * @subpackage core |
|
25 | + * @author Brent Christensen |
|
26 | + * |
|
27 | + * |
|
28 | + */ |
|
29 | 29 | |
30 | 30 | class EE_Receipt_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * @param EE_Line_Item $line_item |
|
35 | - * @param array $options |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
39 | - { |
|
33 | + /** |
|
34 | + * @param EE_Line_Item $line_item |
|
35 | + * @param array $options |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
39 | + { |
|
40 | 40 | |
41 | - $html = ''; |
|
42 | - // set some default options and merge with incoming |
|
43 | - $default_options = array( |
|
44 | - 'show_desc' => true, |
|
45 | - 'odd' => false |
|
46 | - ); |
|
47 | - $options = array_merge($default_options, (array) $options); |
|
48 | - switch ($line_item->type()) { |
|
49 | - case EEM_Line_Item::type_total: |
|
50 | - // loop thru children |
|
51 | - foreach ($line_item->children() as $child_line_item) { |
|
52 | - // recursively feed children back into this method |
|
41 | + $html = ''; |
|
42 | + // set some default options and merge with incoming |
|
43 | + $default_options = array( |
|
44 | + 'show_desc' => true, |
|
45 | + 'odd' => false |
|
46 | + ); |
|
47 | + $options = array_merge($default_options, (array) $options); |
|
48 | + switch ($line_item->type()) { |
|
49 | + case EEM_Line_Item::type_total: |
|
50 | + // loop thru children |
|
51 | + foreach ($line_item->children() as $child_line_item) { |
|
52 | + // recursively feed children back into this method |
|
53 | 53 | // $html .= $this->display_line_item( $child_line_item, $options ); |
54 | - } |
|
54 | + } |
|
55 | 55 | // $html .= $this->_separator_row( $options ); |
56 | 56 | // $html .= $this->_total_row( $line_item, esc_html__('Total', 'event_espresso'), $options ); |
57 | - break; |
|
57 | + break; |
|
58 | 58 | |
59 | 59 | |
60 | - case EEM_Line_Item::type_sub_total: |
|
61 | - // loop thru children |
|
62 | - foreach ($line_item->children() as $child_line_item) { |
|
63 | - // recursively feed children back into this method |
|
60 | + case EEM_Line_Item::type_sub_total: |
|
61 | + // loop thru children |
|
62 | + foreach ($line_item->children() as $child_line_item) { |
|
63 | + // recursively feed children back into this method |
|
64 | 64 | // $html .= $this->display_line_item( $child_line_item, $options ); |
65 | - } |
|
65 | + } |
|
66 | 66 | // $html .= $this->_total_row( $line_item, esc_html__('Sub-Total', 'event_espresso'), $options ); |
67 | - break; |
|
67 | + break; |
|
68 | 68 | |
69 | 69 | |
70 | - case EEM_Line_Item::type_tax_sub_total: |
|
71 | - // loop thru children |
|
72 | - foreach ($line_item->children() as $child_line_item) { |
|
73 | - // recursively feed children back into this method |
|
70 | + case EEM_Line_Item::type_tax_sub_total: |
|
71 | + // loop thru children |
|
72 | + foreach ($line_item->children() as $child_line_item) { |
|
73 | + // recursively feed children back into this method |
|
74 | 74 | // $html .= $this->display_line_item( $child_line_item, $options ); |
75 | - } |
|
75 | + } |
|
76 | 76 | // $html .= $this->_total_row( $line_item, esc_html__('Tax Total', 'event_espresso'), $options ); |
77 | - break; |
|
77 | + break; |
|
78 | 78 | |
79 | 79 | |
80 | - case EEM_Line_Item::type_line_item: |
|
81 | - // item row |
|
80 | + case EEM_Line_Item::type_line_item: |
|
81 | + // item row |
|
82 | 82 | // $html .= $this->_item_row( $line_item, $options ); |
83 | - // got any kids? |
|
84 | - foreach ($line_item->children() as $child_line_item) { |
|
83 | + // got any kids? |
|
84 | + foreach ($line_item->children() as $child_line_item) { |
|
85 | 85 | // $this->display_line_item( $child_line_item, $options ); |
86 | - } |
|
87 | - break; |
|
86 | + } |
|
87 | + break; |
|
88 | 88 | |
89 | 89 | |
90 | - case EEM_Line_Item::type_sub_line_item: |
|
90 | + case EEM_Line_Item::type_sub_line_item: |
|
91 | 91 | // $html .= $this->_sub_item_row( $line_item, $options ); |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | 94 | |
95 | - case EEM_Line_Item::type_tax: |
|
95 | + case EEM_Line_Item::type_tax: |
|
96 | 96 | // $html .= $this->_tax_row( $line_item, $options ); |
97 | - break; |
|
98 | - } |
|
97 | + break; |
|
98 | + } |
|
99 | 99 | |
100 | - return $html; |
|
101 | - } |
|
100 | + return $html; |
|
101 | + } |
|
102 | 102 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $html .= $this->_taxes_html; |
119 | 119 | $html .= $this->_total_row($line_item, $options); |
120 | 120 | if ($options['use_table_wrapper']) { |
121 | - $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
121 | + $html = $this->_table_header($options).$html.$this->_table_footer($options); |
|
122 | 122 | } |
123 | 123 | break; |
124 | 124 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function _table_footer($options) |
159 | 159 | { |
160 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
160 | + return EEH_HTML::tbodyx().EEH_HTML::tablex(); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | |
189 | 189 | |
190 | 190 | $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
191 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
191 | + $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>' : $name_html; |
|
192 | 192 | $name_html .= $line_item->is_taxable() ? ' *' : ''; |
193 | 193 | // maybe preface with icon? |
194 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
195 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
196 | - $name_html .= sprintf( |
|
194 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon().$name_html : $name_html; |
|
195 | + $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>'; |
|
196 | + $name_html .= sprintf( |
|
197 | 197 | _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
198 | 198 | '<span class="ee-line-item-related-parent-object">', |
199 | 199 | $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : esc_html__('Item:', 'event_espresso'), |
200 | - $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
200 | + $parent_related_object_link ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>' : $parent_related_object_name, |
|
201 | 201 | '</span>' |
202 | 202 | ); |
203 | 203 | |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | $type_html .= $this->_get_cancellations($line_item); |
215 | 215 | $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
216 | 216 | $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
217 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
217 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(esc_html__('Code: %s', 'event_espresso'), $code).'</span>' : ''; |
|
218 | 218 | $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
219 | 219 | |
220 | 220 | |
221 | 221 | // Amount Column |
222 | 222 | if ($line_item->is_percent()) { |
223 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
223 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght'); |
|
224 | 224 | } else { |
225 | 225 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
226 | 226 | } |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | // start of row |
296 | 296 | $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
297 | 297 | // name th |
298 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
298 | + $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="4"'); |
|
299 | 299 | // total th |
300 | 300 | $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
301 | 301 | // end of row |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | // start of row |
335 | 335 | $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
336 | 336 | // Total th label |
337 | - $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
337 | + $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')'); |
|
338 | 338 | $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
339 | 339 | // total th |
340 | 340 |
@@ -13,332 +13,332 @@ |
||
13 | 13 | |
14 | 14 | class EE_Admin_Table_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
15 | 15 | { |
16 | - /** |
|
17 | - * whether to display the taxes row or not |
|
18 | - * @type bool $_show_taxes |
|
19 | - */ |
|
20 | - protected $_show_taxes = false; |
|
21 | - |
|
22 | - /** |
|
23 | - * html for any tax rows |
|
24 | - * @type string $_show_taxes |
|
25 | - */ |
|
26 | - protected $_taxes_html = ''; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * total amount including tax we can bill for at this time |
|
31 | - * @type float $_grand_total |
|
32 | - */ |
|
33 | - protected $_grand_total = 0.00; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return float |
|
39 | - */ |
|
40 | - public function grand_total() |
|
41 | - { |
|
42 | - return $this->_grand_total; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This is used to output a single |
|
49 | - * @param EE_Line_Item $line_item |
|
50 | - * @param array $options |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
54 | - { |
|
55 | - |
|
56 | - $html = ''; |
|
57 | - // set some default options and merge with incoming |
|
58 | - $default_options = array( |
|
59 | - 'odd' => true, |
|
60 | - 'use_table_wrapper' => true, |
|
61 | - 'table_css_class' => 'admin-primary-mbox-tbl', |
|
62 | - 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', |
|
63 | - 'total_tr_css_class' => 'admin-primary-mbox-total-tr' |
|
64 | - ); |
|
65 | - $options = array_merge($default_options, (array) $options); |
|
66 | - |
|
67 | - switch ($line_item->type()) { |
|
68 | - case EEM_Line_Item::type_line_item: |
|
69 | - // item row |
|
70 | - $html .= $this->_item_row($line_item, $options); |
|
71 | - break; |
|
72 | - |
|
73 | - case EEM_Line_Item::type_sub_line_item: |
|
74 | - $html .= $this->_sub_item_row($line_item, $options); |
|
75 | - break; |
|
76 | - |
|
77 | - case EEM_Line_Item::type_sub_total: |
|
78 | - if ($line_item->quantity() === 0) { |
|
79 | - return $html; |
|
80 | - } |
|
81 | - // loop through children |
|
82 | - $child_line_items = $line_item->children(); |
|
83 | - // loop through children |
|
84 | - foreach ($child_line_items as $child_line_item) { |
|
85 | - // recursively feed children back into this method |
|
86 | - $html .= $this->display_line_item($child_line_item, $options); |
|
87 | - } |
|
88 | - $html .= $this->_sub_total_row($line_item, $options); |
|
89 | - break; |
|
90 | - |
|
91 | - case EEM_Line_Item::type_tax: |
|
92 | - if ($this->_show_taxes) { |
|
93 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
94 | - } |
|
95 | - break; |
|
96 | - |
|
97 | - case EEM_Line_Item::type_tax_sub_total: |
|
98 | - foreach ($line_item->children() as $child_line_item) { |
|
99 | - if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
100 | - $this->display_line_item($child_line_item, $options); |
|
101 | - } |
|
102 | - } |
|
103 | - break; |
|
104 | - |
|
105 | - case EEM_Line_Item::type_total: |
|
106 | - // determine whether to display taxes or not |
|
107 | - $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; |
|
108 | - // get all child line items |
|
109 | - $children = $line_item->children(); |
|
110 | - |
|
111 | - // loop thru all non-tax child line items |
|
112 | - foreach ($children as $child_line_item) { |
|
113 | - $html .= $this->display_line_item($child_line_item, $options); |
|
114 | - } |
|
115 | - |
|
116 | - $html .= $this->_taxes_html; |
|
117 | - $html .= $this->_total_row($line_item, $options); |
|
118 | - if ($options['use_table_wrapper']) { |
|
119 | - $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
120 | - } |
|
121 | - break; |
|
122 | - } |
|
123 | - |
|
124 | - return $html; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Table header for display. |
|
131 | - * @since 4.8 |
|
132 | - * @param array $options |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - protected function _table_header($options) |
|
136 | - { |
|
137 | - $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
138 | - $html .= EEH_HTML::thead(); |
|
139 | - $html .= EEH_HTML::tr(); |
|
140 | - $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left'); |
|
141 | - $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left'); |
|
142 | - $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
143 | - $html .= EEH_HTML::th(esc_html__('Qty', 'event_espresso'), '', 'jst-cntr'); |
|
144 | - $html .= EEH_HTML::th(esc_html__('Line Total', 'event_espresso'), '', 'jst-cntr'); |
|
145 | - $html .= EEH_HTML::tbody(); |
|
146 | - return $html; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Table footer for display |
|
152 | - * @since 4.8 |
|
153 | - * @param array $options array of options for the table. |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - protected function _table_footer($options) |
|
157 | - { |
|
158 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * _item_row |
|
165 | - * |
|
166 | - * @param EE_Line_Item $line_item |
|
167 | - * @param array $options |
|
168 | - * @return mixed |
|
169 | - */ |
|
170 | - protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
171 | - { |
|
172 | - $line_item_related_object = $line_item->get_object(); |
|
173 | - $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null; |
|
174 | - // start of row |
|
175 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
176 | - $html = EEH_HTML::tr('', '', $row_class); |
|
177 | - |
|
178 | - |
|
179 | - // Name Column |
|
180 | - $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
181 | - |
|
182 | - // related object scope. |
|
183 | - $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : ''; |
|
184 | - $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name; |
|
185 | - $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : ''; |
|
186 | - |
|
187 | - |
|
188 | - $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
|
189 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
190 | - $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
191 | - // maybe preface with icon? |
|
192 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
193 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
194 | - $name_html .= sprintf( |
|
195 | - _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
196 | - '<span class="ee-line-item-related-parent-object">', |
|
197 | - $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : esc_html__('Item:', 'event_espresso'), |
|
198 | - $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
199 | - '</span>' |
|
200 | - ); |
|
201 | - |
|
202 | - $name_html = apply_filters( |
|
203 | - 'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html', |
|
204 | - $name_html, |
|
205 | - $line_item, |
|
206 | - $options |
|
207 | - ); |
|
208 | - |
|
209 | - $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
210 | - // Type Column |
|
211 | - $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
212 | - $type_html .= $this->_get_cancellations($line_item); |
|
213 | - $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
214 | - $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
215 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
216 | - $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
217 | - |
|
218 | - |
|
219 | - // Amount Column |
|
220 | - if ($line_item->is_percent()) { |
|
221 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
222 | - } else { |
|
223 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
224 | - } |
|
225 | - |
|
226 | - // QTY column |
|
227 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght'); |
|
228 | - |
|
229 | - // total column |
|
230 | - $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
231 | - |
|
232 | - // finish things off and return |
|
233 | - $html .= EEH_HTML::trx(); |
|
234 | - return $html; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * _get_cancellations |
|
241 | - * |
|
242 | - * @param EE_Line_Item $line_item |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function _get_cancellations(EE_Line_Item $line_item) |
|
246 | - { |
|
247 | - $html = ''; |
|
248 | - $cancellations = $line_item->get_cancellations(); |
|
249 | - $cancellation = reset($cancellations); |
|
250 | - // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ ); |
|
251 | - if ($cancellation instanceof EE_Line_Item) { |
|
252 | - $html .= ' <span class="ee-line-item-id">'; |
|
253 | - $html .= sprintf( |
|
254 | - _n( |
|
255 | - '(%1$s Cancellation)', |
|
256 | - '(%1$s Cancellations)', |
|
257 | - $cancellation->quantity(), |
|
258 | - 'event_espresso' |
|
259 | - ), |
|
260 | - $cancellation->quantity() |
|
261 | - ); |
|
262 | - $html .= '</span>'; |
|
263 | - } |
|
264 | - return $html; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * _sub_item_row |
|
271 | - * |
|
272 | - * @param EE_Line_Item $line_item |
|
273 | - * @param array $options |
|
274 | - * @return mixed |
|
275 | - */ |
|
276 | - protected function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
277 | - { |
|
278 | - // for now we're not showing sub-items |
|
279 | - return ''; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * _tax_row |
|
286 | - * |
|
287 | - * @param EE_Line_Item $line_item |
|
288 | - * @param array $options |
|
289 | - * @return mixed |
|
290 | - */ |
|
291 | - protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
292 | - { |
|
293 | - // start of row |
|
294 | - $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
295 | - // name th |
|
296 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
297 | - // total th |
|
298 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
299 | - // end of row |
|
300 | - $html .= EEH_HTML::trx(); |
|
301 | - return $html; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * _total_row |
|
309 | - * |
|
310 | - * @param EE_Line_Item $line_item |
|
311 | - * @param string $text |
|
312 | - * @param array $options |
|
313 | - * @return mixed |
|
314 | - */ |
|
315 | - protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
316 | - { |
|
317 | - // currently not showing subtotal row |
|
318 | - return ''; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * _total_row |
|
325 | - * |
|
326 | - * @param EE_Line_Item $line_item |
|
327 | - * @param array $options |
|
328 | - * @return mixed |
|
329 | - */ |
|
330 | - protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
331 | - { |
|
332 | - // start of row |
|
333 | - $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
334 | - // Total th label |
|
335 | - $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
336 | - $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
|
337 | - // total th |
|
338 | - |
|
339 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
340 | - // end of row |
|
341 | - $html .= EEH_HTML::trx(); |
|
342 | - return $html; |
|
343 | - } |
|
16 | + /** |
|
17 | + * whether to display the taxes row or not |
|
18 | + * @type bool $_show_taxes |
|
19 | + */ |
|
20 | + protected $_show_taxes = false; |
|
21 | + |
|
22 | + /** |
|
23 | + * html for any tax rows |
|
24 | + * @type string $_show_taxes |
|
25 | + */ |
|
26 | + protected $_taxes_html = ''; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * total amount including tax we can bill for at this time |
|
31 | + * @type float $_grand_total |
|
32 | + */ |
|
33 | + protected $_grand_total = 0.00; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return float |
|
39 | + */ |
|
40 | + public function grand_total() |
|
41 | + { |
|
42 | + return $this->_grand_total; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This is used to output a single |
|
49 | + * @param EE_Line_Item $line_item |
|
50 | + * @param array $options |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
54 | + { |
|
55 | + |
|
56 | + $html = ''; |
|
57 | + // set some default options and merge with incoming |
|
58 | + $default_options = array( |
|
59 | + 'odd' => true, |
|
60 | + 'use_table_wrapper' => true, |
|
61 | + 'table_css_class' => 'admin-primary-mbox-tbl', |
|
62 | + 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', |
|
63 | + 'total_tr_css_class' => 'admin-primary-mbox-total-tr' |
|
64 | + ); |
|
65 | + $options = array_merge($default_options, (array) $options); |
|
66 | + |
|
67 | + switch ($line_item->type()) { |
|
68 | + case EEM_Line_Item::type_line_item: |
|
69 | + // item row |
|
70 | + $html .= $this->_item_row($line_item, $options); |
|
71 | + break; |
|
72 | + |
|
73 | + case EEM_Line_Item::type_sub_line_item: |
|
74 | + $html .= $this->_sub_item_row($line_item, $options); |
|
75 | + break; |
|
76 | + |
|
77 | + case EEM_Line_Item::type_sub_total: |
|
78 | + if ($line_item->quantity() === 0) { |
|
79 | + return $html; |
|
80 | + } |
|
81 | + // loop through children |
|
82 | + $child_line_items = $line_item->children(); |
|
83 | + // loop through children |
|
84 | + foreach ($child_line_items as $child_line_item) { |
|
85 | + // recursively feed children back into this method |
|
86 | + $html .= $this->display_line_item($child_line_item, $options); |
|
87 | + } |
|
88 | + $html .= $this->_sub_total_row($line_item, $options); |
|
89 | + break; |
|
90 | + |
|
91 | + case EEM_Line_Item::type_tax: |
|
92 | + if ($this->_show_taxes) { |
|
93 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
94 | + } |
|
95 | + break; |
|
96 | + |
|
97 | + case EEM_Line_Item::type_tax_sub_total: |
|
98 | + foreach ($line_item->children() as $child_line_item) { |
|
99 | + if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
100 | + $this->display_line_item($child_line_item, $options); |
|
101 | + } |
|
102 | + } |
|
103 | + break; |
|
104 | + |
|
105 | + case EEM_Line_Item::type_total: |
|
106 | + // determine whether to display taxes or not |
|
107 | + $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; |
|
108 | + // get all child line items |
|
109 | + $children = $line_item->children(); |
|
110 | + |
|
111 | + // loop thru all non-tax child line items |
|
112 | + foreach ($children as $child_line_item) { |
|
113 | + $html .= $this->display_line_item($child_line_item, $options); |
|
114 | + } |
|
115 | + |
|
116 | + $html .= $this->_taxes_html; |
|
117 | + $html .= $this->_total_row($line_item, $options); |
|
118 | + if ($options['use_table_wrapper']) { |
|
119 | + $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
120 | + } |
|
121 | + break; |
|
122 | + } |
|
123 | + |
|
124 | + return $html; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Table header for display. |
|
131 | + * @since 4.8 |
|
132 | + * @param array $options |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + protected function _table_header($options) |
|
136 | + { |
|
137 | + $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
138 | + $html .= EEH_HTML::thead(); |
|
139 | + $html .= EEH_HTML::tr(); |
|
140 | + $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left'); |
|
141 | + $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left'); |
|
142 | + $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
143 | + $html .= EEH_HTML::th(esc_html__('Qty', 'event_espresso'), '', 'jst-cntr'); |
|
144 | + $html .= EEH_HTML::th(esc_html__('Line Total', 'event_espresso'), '', 'jst-cntr'); |
|
145 | + $html .= EEH_HTML::tbody(); |
|
146 | + return $html; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Table footer for display |
|
152 | + * @since 4.8 |
|
153 | + * @param array $options array of options for the table. |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + protected function _table_footer($options) |
|
157 | + { |
|
158 | + return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * _item_row |
|
165 | + * |
|
166 | + * @param EE_Line_Item $line_item |
|
167 | + * @param array $options |
|
168 | + * @return mixed |
|
169 | + */ |
|
170 | + protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
171 | + { |
|
172 | + $line_item_related_object = $line_item->get_object(); |
|
173 | + $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null; |
|
174 | + // start of row |
|
175 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
176 | + $html = EEH_HTML::tr('', '', $row_class); |
|
177 | + |
|
178 | + |
|
179 | + // Name Column |
|
180 | + $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
181 | + |
|
182 | + // related object scope. |
|
183 | + $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : ''; |
|
184 | + $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name; |
|
185 | + $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : ''; |
|
186 | + |
|
187 | + |
|
188 | + $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
|
189 | + $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
190 | + $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
191 | + // maybe preface with icon? |
|
192 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
193 | + $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
194 | + $name_html .= sprintf( |
|
195 | + _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
196 | + '<span class="ee-line-item-related-parent-object">', |
|
197 | + $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : esc_html__('Item:', 'event_espresso'), |
|
198 | + $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
199 | + '</span>' |
|
200 | + ); |
|
201 | + |
|
202 | + $name_html = apply_filters( |
|
203 | + 'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html', |
|
204 | + $name_html, |
|
205 | + $line_item, |
|
206 | + $options |
|
207 | + ); |
|
208 | + |
|
209 | + $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
210 | + // Type Column |
|
211 | + $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
212 | + $type_html .= $this->_get_cancellations($line_item); |
|
213 | + $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
214 | + $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
215 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
216 | + $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
217 | + |
|
218 | + |
|
219 | + // Amount Column |
|
220 | + if ($line_item->is_percent()) { |
|
221 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
222 | + } else { |
|
223 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
224 | + } |
|
225 | + |
|
226 | + // QTY column |
|
227 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght'); |
|
228 | + |
|
229 | + // total column |
|
230 | + $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
231 | + |
|
232 | + // finish things off and return |
|
233 | + $html .= EEH_HTML::trx(); |
|
234 | + return $html; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * _get_cancellations |
|
241 | + * |
|
242 | + * @param EE_Line_Item $line_item |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function _get_cancellations(EE_Line_Item $line_item) |
|
246 | + { |
|
247 | + $html = ''; |
|
248 | + $cancellations = $line_item->get_cancellations(); |
|
249 | + $cancellation = reset($cancellations); |
|
250 | + // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ ); |
|
251 | + if ($cancellation instanceof EE_Line_Item) { |
|
252 | + $html .= ' <span class="ee-line-item-id">'; |
|
253 | + $html .= sprintf( |
|
254 | + _n( |
|
255 | + '(%1$s Cancellation)', |
|
256 | + '(%1$s Cancellations)', |
|
257 | + $cancellation->quantity(), |
|
258 | + 'event_espresso' |
|
259 | + ), |
|
260 | + $cancellation->quantity() |
|
261 | + ); |
|
262 | + $html .= '</span>'; |
|
263 | + } |
|
264 | + return $html; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * _sub_item_row |
|
271 | + * |
|
272 | + * @param EE_Line_Item $line_item |
|
273 | + * @param array $options |
|
274 | + * @return mixed |
|
275 | + */ |
|
276 | + protected function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
277 | + { |
|
278 | + // for now we're not showing sub-items |
|
279 | + return ''; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * _tax_row |
|
286 | + * |
|
287 | + * @param EE_Line_Item $line_item |
|
288 | + * @param array $options |
|
289 | + * @return mixed |
|
290 | + */ |
|
291 | + protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
292 | + { |
|
293 | + // start of row |
|
294 | + $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
295 | + // name th |
|
296 | + $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
297 | + // total th |
|
298 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
299 | + // end of row |
|
300 | + $html .= EEH_HTML::trx(); |
|
301 | + return $html; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * _total_row |
|
309 | + * |
|
310 | + * @param EE_Line_Item $line_item |
|
311 | + * @param string $text |
|
312 | + * @param array $options |
|
313 | + * @return mixed |
|
314 | + */ |
|
315 | + protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
316 | + { |
|
317 | + // currently not showing subtotal row |
|
318 | + return ''; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * _total_row |
|
325 | + * |
|
326 | + * @param EE_Line_Item $line_item |
|
327 | + * @param array $options |
|
328 | + * @return mixed |
|
329 | + */ |
|
330 | + protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
331 | + { |
|
332 | + // start of row |
|
333 | + $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
334 | + // Total th label |
|
335 | + $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
336 | + $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
|
337 | + // total th |
|
338 | + |
|
339 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
340 | + // end of row |
|
341 | + $html .= EEH_HTML::trx(); |
|
342 | + return $html; |
|
343 | + } |
|
344 | 344 | } |
@@ -14,191 +14,191 @@ |
||
14 | 14 | class EE_Admin_Table_Registration_Line_Item_Display_Strategy extends EE_Admin_Table_Line_Item_Display_Strategy |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Table header for display. |
|
19 | - * @since 4.8 |
|
20 | - * @param array $options |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - protected function _table_header($options) |
|
24 | - { |
|
25 | - $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
26 | - $html .= EEH_HTML::thead(); |
|
27 | - $html .= EEH_HTML::tr(); |
|
28 | - $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left'); |
|
29 | - $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left'); |
|
30 | - $html .= EEH_HTML::th(esc_html__('Date(s)', 'event_espresso'), '', 'jst-left'); |
|
31 | - $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
32 | - $html .= EEH_HTML::tbody(); |
|
33 | - return $html; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * _item_row |
|
42 | - * |
|
43 | - * @param EE_Line_Item $line_item |
|
44 | - * @param array $options |
|
45 | - * @return mixed |
|
46 | - */ |
|
47 | - protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
48 | - { |
|
49 | - $line_item_related_object = $line_item->get_object(); |
|
50 | - $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item |
|
51 | - ? $line_item->parent()->get_object() |
|
52 | - : null; |
|
53 | - // start of row |
|
54 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
55 | - $html = EEH_HTML::tr('', '', $row_class); |
|
56 | - |
|
57 | - |
|
58 | - // Name Column |
|
59 | - $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
60 | - |
|
61 | - // related object scope. |
|
62 | - $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object |
|
63 | - ? $parent_line_item_related_object->name() |
|
64 | - : ''; |
|
65 | - $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item |
|
66 | - ? $line_item->parent()->name() |
|
67 | - : $parent_related_object_name; |
|
68 | - $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links |
|
69 | - ? $parent_line_item_related_object->get_admin_details_link() |
|
70 | - : ''; |
|
71 | - |
|
72 | - |
|
73 | - $name_html = $line_item_related_object instanceof EEI_Line_Item_Object |
|
74 | - ? $line_item_related_object->name() : $line_item->name(); |
|
75 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' |
|
76 | - : $name_html; |
|
77 | - $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
78 | - // maybe preface with icon? |
|
79 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon |
|
80 | - ? $line_item_related_object->get_icon() . $name_html |
|
81 | - : $name_html; |
|
82 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
83 | - $name_html .= sprintf( |
|
84 | - _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
85 | - '<span class="ee-line-item-related-parent-object">', |
|
86 | - $line_item->parent() instanceof EE_Line_Item |
|
87 | - ? $line_item->parent()->OBJ_type_i18n() |
|
88 | - : esc_html__('Item:', 'event_espresso'), |
|
89 | - $parent_related_object_link |
|
90 | - ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' |
|
91 | - : $parent_related_object_name, |
|
92 | - '</span>' |
|
93 | - ); |
|
94 | - |
|
95 | - $name_html = apply_filters( |
|
96 | - 'FHEE__EE_Admin_Table_Registration_Line_Item_Display_Strategy___item_row__name_html', |
|
97 | - $name_html, |
|
98 | - $line_item, |
|
99 | - $options |
|
100 | - ); |
|
101 | - |
|
102 | - $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
103 | - // Type Column |
|
104 | - $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
105 | - $type_html .= $this->_get_cancellations($line_item); |
|
106 | - $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
107 | - $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
108 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
109 | - $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
110 | - |
|
111 | - // Date column |
|
112 | - $datetime_content = ''; |
|
113 | - if ($line_item_related_object instanceof EE_Ticket) { |
|
114 | - $datetimes = $line_item_related_object->datetimes(); |
|
115 | - foreach ($datetimes as $datetime) { |
|
116 | - if ($datetime instanceof EE_Datetime) { |
|
117 | - $datetime_content .= $datetime->get_dtt_display_name() . '<br>'; |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
121 | - $html .= EEH_HTML::td($datetime_content, '', 'jst-left'); |
|
122 | - |
|
123 | - // Amount Column |
|
124 | - if ($line_item->is_percent()) { |
|
125 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
126 | - } else { |
|
127 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - // finish things off and return |
|
132 | - $html .= EEH_HTML::trx(); |
|
133 | - return $html; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * _tax_row |
|
140 | - * |
|
141 | - * @param EE_Line_Item $line_item |
|
142 | - * @param array $options |
|
143 | - * @return mixed |
|
144 | - */ |
|
145 | - protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
146 | - { |
|
147 | - // start of row |
|
148 | - $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
149 | - // name th |
|
150 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"'); |
|
151 | - // total th |
|
152 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
153 | - // end of row |
|
154 | - $html .= EEH_HTML::trx(); |
|
155 | - return $html; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * _total_row |
|
164 | - * |
|
165 | - * @param EE_Line_Item $line_item |
|
166 | - * @param array $options |
|
167 | - * @return mixed |
|
168 | - */ |
|
169 | - protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
170 | - { |
|
171 | - |
|
172 | - $registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null; |
|
173 | - $registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0; |
|
174 | - // if no valid registration object then we're not going to show the approximate text. |
|
175 | - $total_match = $registration instanceof EE_Registration |
|
176 | - ? $registration->final_price() === $line_item->total() |
|
177 | - : true; |
|
178 | - |
|
179 | - // start of row |
|
180 | - $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
181 | - // Total th label |
|
182 | - if ($total_match) { |
|
183 | - $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
184 | - } else { |
|
185 | - $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
186 | - $total_label .= '<br>'; |
|
187 | - $total_label .= '<p class="ee-footnote-text">' |
|
188 | - . sprintf( |
|
189 | - esc_html__('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others. This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'), |
|
190 | - '<strong>', |
|
191 | - $registration_total, |
|
192 | - '</strong>' |
|
193 | - ) |
|
194 | - . '</p>'; |
|
195 | - } |
|
196 | - $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"'); |
|
197 | - // total th |
|
198 | - |
|
199 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
200 | - // end of row |
|
201 | - $html .= EEH_HTML::trx(); |
|
202 | - return $html; |
|
203 | - } |
|
17 | + /** |
|
18 | + * Table header for display. |
|
19 | + * @since 4.8 |
|
20 | + * @param array $options |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + protected function _table_header($options) |
|
24 | + { |
|
25 | + $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
26 | + $html .= EEH_HTML::thead(); |
|
27 | + $html .= EEH_HTML::tr(); |
|
28 | + $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left'); |
|
29 | + $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left'); |
|
30 | + $html .= EEH_HTML::th(esc_html__('Date(s)', 'event_espresso'), '', 'jst-left'); |
|
31 | + $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
32 | + $html .= EEH_HTML::tbody(); |
|
33 | + return $html; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * _item_row |
|
42 | + * |
|
43 | + * @param EE_Line_Item $line_item |
|
44 | + * @param array $options |
|
45 | + * @return mixed |
|
46 | + */ |
|
47 | + protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
48 | + { |
|
49 | + $line_item_related_object = $line_item->get_object(); |
|
50 | + $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item |
|
51 | + ? $line_item->parent()->get_object() |
|
52 | + : null; |
|
53 | + // start of row |
|
54 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
55 | + $html = EEH_HTML::tr('', '', $row_class); |
|
56 | + |
|
57 | + |
|
58 | + // Name Column |
|
59 | + $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
60 | + |
|
61 | + // related object scope. |
|
62 | + $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object |
|
63 | + ? $parent_line_item_related_object->name() |
|
64 | + : ''; |
|
65 | + $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item |
|
66 | + ? $line_item->parent()->name() |
|
67 | + : $parent_related_object_name; |
|
68 | + $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links |
|
69 | + ? $parent_line_item_related_object->get_admin_details_link() |
|
70 | + : ''; |
|
71 | + |
|
72 | + |
|
73 | + $name_html = $line_item_related_object instanceof EEI_Line_Item_Object |
|
74 | + ? $line_item_related_object->name() : $line_item->name(); |
|
75 | + $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' |
|
76 | + : $name_html; |
|
77 | + $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
78 | + // maybe preface with icon? |
|
79 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon |
|
80 | + ? $line_item_related_object->get_icon() . $name_html |
|
81 | + : $name_html; |
|
82 | + $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
83 | + $name_html .= sprintf( |
|
84 | + _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
85 | + '<span class="ee-line-item-related-parent-object">', |
|
86 | + $line_item->parent() instanceof EE_Line_Item |
|
87 | + ? $line_item->parent()->OBJ_type_i18n() |
|
88 | + : esc_html__('Item:', 'event_espresso'), |
|
89 | + $parent_related_object_link |
|
90 | + ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' |
|
91 | + : $parent_related_object_name, |
|
92 | + '</span>' |
|
93 | + ); |
|
94 | + |
|
95 | + $name_html = apply_filters( |
|
96 | + 'FHEE__EE_Admin_Table_Registration_Line_Item_Display_Strategy___item_row__name_html', |
|
97 | + $name_html, |
|
98 | + $line_item, |
|
99 | + $options |
|
100 | + ); |
|
101 | + |
|
102 | + $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
103 | + // Type Column |
|
104 | + $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
105 | + $type_html .= $this->_get_cancellations($line_item); |
|
106 | + $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
107 | + $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
108 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
109 | + $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
110 | + |
|
111 | + // Date column |
|
112 | + $datetime_content = ''; |
|
113 | + if ($line_item_related_object instanceof EE_Ticket) { |
|
114 | + $datetimes = $line_item_related_object->datetimes(); |
|
115 | + foreach ($datetimes as $datetime) { |
|
116 | + if ($datetime instanceof EE_Datetime) { |
|
117 | + $datetime_content .= $datetime->get_dtt_display_name() . '<br>'; |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | + $html .= EEH_HTML::td($datetime_content, '', 'jst-left'); |
|
122 | + |
|
123 | + // Amount Column |
|
124 | + if ($line_item->is_percent()) { |
|
125 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
126 | + } else { |
|
127 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + // finish things off and return |
|
132 | + $html .= EEH_HTML::trx(); |
|
133 | + return $html; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * _tax_row |
|
140 | + * |
|
141 | + * @param EE_Line_Item $line_item |
|
142 | + * @param array $options |
|
143 | + * @return mixed |
|
144 | + */ |
|
145 | + protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
146 | + { |
|
147 | + // start of row |
|
148 | + $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
149 | + // name th |
|
150 | + $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"'); |
|
151 | + // total th |
|
152 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
153 | + // end of row |
|
154 | + $html .= EEH_HTML::trx(); |
|
155 | + return $html; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * _total_row |
|
164 | + * |
|
165 | + * @param EE_Line_Item $line_item |
|
166 | + * @param array $options |
|
167 | + * @return mixed |
|
168 | + */ |
|
169 | + protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
170 | + { |
|
171 | + |
|
172 | + $registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null; |
|
173 | + $registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0; |
|
174 | + // if no valid registration object then we're not going to show the approximate text. |
|
175 | + $total_match = $registration instanceof EE_Registration |
|
176 | + ? $registration->final_price() === $line_item->total() |
|
177 | + : true; |
|
178 | + |
|
179 | + // start of row |
|
180 | + $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
181 | + // Total th label |
|
182 | + if ($total_match) { |
|
183 | + $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
184 | + } else { |
|
185 | + $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
186 | + $total_label .= '<br>'; |
|
187 | + $total_label .= '<p class="ee-footnote-text">' |
|
188 | + . sprintf( |
|
189 | + esc_html__('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others. This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'), |
|
190 | + '<strong>', |
|
191 | + $registration_total, |
|
192 | + '</strong>' |
|
193 | + ) |
|
194 | + . '</p>'; |
|
195 | + } |
|
196 | + $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"'); |
|
197 | + // total th |
|
198 | + |
|
199 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
200 | + // end of row |
|
201 | + $html .= EEH_HTML::trx(); |
|
202 | + return $html; |
|
203 | + } |
|
204 | 204 | } |
@@ -72,22 +72,22 @@ discard block |
||
72 | 72 | |
73 | 73 | $name_html = $line_item_related_object instanceof EEI_Line_Item_Object |
74 | 74 | ? $line_item_related_object->name() : $line_item->name(); |
75 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' |
|
75 | + $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>' |
|
76 | 76 | : $name_html; |
77 | 77 | $name_html .= $line_item->is_taxable() ? ' *' : ''; |
78 | 78 | // maybe preface with icon? |
79 | 79 | $name_html = $line_item_related_object instanceof EEI_Has_Icon |
80 | - ? $line_item_related_object->get_icon() . $name_html |
|
80 | + ? $line_item_related_object->get_icon().$name_html |
|
81 | 81 | : $name_html; |
82 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
83 | - $name_html .= sprintf( |
|
82 | + $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>'; |
|
83 | + $name_html .= sprintf( |
|
84 | 84 | _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
85 | 85 | '<span class="ee-line-item-related-parent-object">', |
86 | 86 | $line_item->parent() instanceof EE_Line_Item |
87 | 87 | ? $line_item->parent()->OBJ_type_i18n() |
88 | 88 | : esc_html__('Item:', 'event_espresso'), |
89 | 89 | $parent_related_object_link |
90 | - ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' |
|
90 | + ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>' |
|
91 | 91 | : $parent_related_object_name, |
92 | 92 | '</span>' |
93 | 93 | ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $type_html .= $this->_get_cancellations($line_item); |
106 | 106 | $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
107 | 107 | $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
108 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
108 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(esc_html__('Code: %s', 'event_espresso'), $code).'</span>' : ''; |
|
109 | 109 | $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
110 | 110 | |
111 | 111 | // Date column |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $datetimes = $line_item_related_object->datetimes(); |
115 | 115 | foreach ($datetimes as $datetime) { |
116 | 116 | if ($datetime instanceof EE_Datetime) { |
117 | - $datetime_content .= $datetime->get_dtt_display_name() . '<br>'; |
|
117 | + $datetime_content .= $datetime->get_dtt_display_name().'<br>'; |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | // Amount Column |
124 | 124 | if ($line_item->is_percent()) { |
125 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
125 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght'); |
|
126 | 126 | } else { |
127 | 127 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
128 | 128 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | // start of row |
148 | 148 | $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
149 | 149 | // name th |
150 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"'); |
|
150 | + $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="3"'); |
|
151 | 151 | // total th |
152 | 152 | $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
153 | 153 | // end of row |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
181 | 181 | // Total th label |
182 | 182 | if ($total_match) { |
183 | - $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
183 | + $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')'); |
|
184 | 184 | } else { |
185 | - $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
185 | + $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')'); |
|
186 | 186 | $total_label .= '<br>'; |
187 | 187 | $total_label .= '<p class="ee-footnote-text">' |
188 | 188 | . sprintf( |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | // used by display strategies |
96 | 96 | // assign incoming values to properties |
97 | 97 | foreach ($options_array as $key => $value) { |
98 | - $key = '_' . $key; |
|
98 | + $key = '_'.$key; |
|
99 | 99 | if (property_exists($this, $key) && empty($this->{$key})) { |
100 | 100 | $this->{$key} = $value; |
101 | 101 | if ($key === '_subsections' && ! is_array($value)) { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function ensure_construct_finalized_called() |
137 | 137 | { |
138 | - if (! $this->_construction_finalized) { |
|
138 | + if ( ! $this->_construction_finalized) { |
|
139 | 139 | $this->_construct_finalize($this->_parent_section, $this->_name); |
140 | 140 | } |
141 | 141 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function _set_default_html_id_if_empty() |
200 | 200 | { |
201 | - if (! $this->_html_id) { |
|
201 | + if ( ! $this->_html_id) { |
|
202 | 202 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
203 | 203 | $this->_html_id = $this->_parent_section->html_id() |
204 | 204 | . '-' |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | public function html_id($add_pound_sign = false) |
258 | 258 | { |
259 | 259 | $this->_set_default_html_id_if_empty(); |
260 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
260 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public function other_html_attributes() |
329 | 329 | { |
330 | - return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : ''; |
|
330 | + return ! empty($this->_other_html_attributes) ? ' '.$this->_other_html_attributes : ''; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | */ |
341 | 341 | public function name() |
342 | 342 | { |
343 | - if (! $this->_construction_finalized) { |
|
343 | + if ( ! $this->_construction_finalized) { |
|
344 | 344 | throw new EE_Error(sprintf(esc_html__( |
345 | 345 | '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\'', |
346 | 346 | 'event_espresso' |
@@ -373,18 +373,18 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function form_open($action = '', $method = '', $other_attributes = '') |
375 | 375 | { |
376 | - if (! empty($action)) { |
|
376 | + if ( ! empty($action)) { |
|
377 | 377 | $this->set_action($action); |
378 | 378 | } |
379 | - if (! empty($method)) { |
|
379 | + if ( ! empty($method)) { |
|
380 | 380 | $this->set_method($method); |
381 | 381 | } |
382 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
383 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
384 | - $html .= ' action="' . $this->action() . '"'; |
|
385 | - $html .= ' method="' . $this->method() . '"'; |
|
386 | - $html .= ' name="' . $this->name() . '"'; |
|
387 | - $html .= $other_attributes . '>'; |
|
382 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
383 | + $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : ''; |
|
384 | + $html .= ' action="'.$this->action().'"'; |
|
385 | + $html .= ' method="'.$this->method().'"'; |
|
386 | + $html .= ' name="'.$this->name().'"'; |
|
387 | + $html .= $other_attributes.'>'; |
|
388 | 388 | return $html; |
389 | 389 | } |
390 | 390 | |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $strlen = strlen($html_id); |
403 | 403 | $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
404 | 404 | ? $html_id |
405 | - : $html_id . '-frm'; |
|
405 | + : $html_id.'-frm'; |
|
406 | 406 | return $html_id; |
407 | 407 | } |
408 | 408 |
@@ -14,486 +14,486 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EE_Form_Section_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * the URL the form is submitted to |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_action; |
|
23 | - |
|
24 | - /** |
|
25 | - * POST (default) or GET |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $_method; |
|
30 | - |
|
31 | - /** |
|
32 | - * html_id and html_name are derived from this by default |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_name; |
|
37 | - |
|
38 | - /** |
|
39 | - * $_html_id |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_html_id; |
|
43 | - |
|
44 | - /** |
|
45 | - * $_html_class |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $_html_class; |
|
49 | - |
|
50 | - /** |
|
51 | - * $_html_style |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $_html_style; |
|
55 | - |
|
56 | - /** |
|
57 | - * $_other_html_attributes |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - protected $_other_html_attributes; |
|
61 | - |
|
62 | - /** |
|
63 | - * The form section of which this form section is a part |
|
64 | - * |
|
65 | - * @var EE_Form_Section_Proper |
|
66 | - */ |
|
67 | - protected $_parent_section; |
|
68 | - |
|
69 | - /** |
|
70 | - * flag indicating that _construct_finalize has been called. |
|
71 | - * If it has not been called and we try to use functions which require it, we call it |
|
72 | - * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
73 | - * |
|
74 | - * @var boolean |
|
75 | - */ |
|
76 | - protected $_construction_finalized; |
|
77 | - |
|
78 | - /** |
|
79 | - * Strategy for parsing the form HTML upon display |
|
80 | - * |
|
81 | - * @var FormHtmlFilter |
|
82 | - */ |
|
83 | - protected $_form_html_filter; |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param array $options_array { |
|
88 | - * @type $name string the name for this form section, if you want to explicitly define it |
|
89 | - * } |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - */ |
|
92 | - public function __construct($options_array = array()) |
|
93 | - { |
|
94 | - // used by display strategies |
|
95 | - // assign incoming values to properties |
|
96 | - foreach ($options_array as $key => $value) { |
|
97 | - $key = '_' . $key; |
|
98 | - if (property_exists($this, $key) && empty($this->{$key})) { |
|
99 | - $this->{$key} = $value; |
|
100 | - if ($key === '_subsections' && ! is_array($value)) { |
|
101 | - throw new InvalidDataTypeException($key, $value, 'array'); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - // set parser which allows the form section's rendered HTML to be filtered |
|
106 | - if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
107 | - $this->_form_html_filter = $options_array['form_html_filter']; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @param $parent_form_section |
|
115 | - * @param $name |
|
116 | - * @throws \EE_Error |
|
117 | - */ |
|
118 | - protected function _construct_finalize($parent_form_section, $name) |
|
119 | - { |
|
120 | - $this->_construction_finalized = true; |
|
121 | - $this->_parent_section = $parent_form_section; |
|
122 | - if ($name !== null) { |
|
123 | - $this->_name = $name; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * make sure construction finalized was called, otherwise children might not be ready |
|
131 | - * |
|
132 | - * @return void |
|
133 | - * @throws \EE_Error |
|
134 | - */ |
|
135 | - public function ensure_construct_finalized_called() |
|
136 | - { |
|
137 | - if (! $this->_construction_finalized) { |
|
138 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - public function action() |
|
148 | - { |
|
149 | - return $this->_action; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param string $action |
|
156 | - */ |
|
157 | - public function set_action($action) |
|
158 | - { |
|
159 | - $this->_action = $action; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function method() |
|
168 | - { |
|
169 | - return ! empty($this->_method) ? $this->_method : 'POST'; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $method |
|
176 | - */ |
|
177 | - public function set_method($method) |
|
178 | - { |
|
179 | - switch ($method) { |
|
180 | - case 'get': |
|
181 | - case 'GET': |
|
182 | - $this->_method = 'GET'; |
|
183 | - break; |
|
184 | - default: |
|
185 | - $this->_method = 'POST'; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Sets the html_id to its default value, if none was specified in the constructor. |
|
193 | - * Calculation involves using the name and the parent's html id |
|
194 | - * return void |
|
195 | - * |
|
196 | - * @throws \EE_Error |
|
197 | - */ |
|
198 | - protected function _set_default_html_id_if_empty() |
|
199 | - { |
|
200 | - if (! $this->_html_id) { |
|
201 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
202 | - $this->_html_id = $this->_parent_section->html_id() |
|
203 | - . '-' |
|
204 | - . $this->_prep_name_for_html_id($this->name()); |
|
205 | - } else { |
|
206 | - $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
207 | - } |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * _prep_name_for_html_id |
|
215 | - * |
|
216 | - * @param $name |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - private function _prep_name_for_html_id($name) |
|
220 | - { |
|
221 | - return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
222 | - } |
|
17 | + /** |
|
18 | + * the URL the form is submitted to |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_action; |
|
23 | + |
|
24 | + /** |
|
25 | + * POST (default) or GET |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $_method; |
|
30 | + |
|
31 | + /** |
|
32 | + * html_id and html_name are derived from this by default |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_name; |
|
37 | + |
|
38 | + /** |
|
39 | + * $_html_id |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_html_id; |
|
43 | + |
|
44 | + /** |
|
45 | + * $_html_class |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $_html_class; |
|
49 | + |
|
50 | + /** |
|
51 | + * $_html_style |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $_html_style; |
|
55 | + |
|
56 | + /** |
|
57 | + * $_other_html_attributes |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + protected $_other_html_attributes; |
|
61 | + |
|
62 | + /** |
|
63 | + * The form section of which this form section is a part |
|
64 | + * |
|
65 | + * @var EE_Form_Section_Proper |
|
66 | + */ |
|
67 | + protected $_parent_section; |
|
68 | + |
|
69 | + /** |
|
70 | + * flag indicating that _construct_finalize has been called. |
|
71 | + * If it has not been called and we try to use functions which require it, we call it |
|
72 | + * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
73 | + * |
|
74 | + * @var boolean |
|
75 | + */ |
|
76 | + protected $_construction_finalized; |
|
77 | + |
|
78 | + /** |
|
79 | + * Strategy for parsing the form HTML upon display |
|
80 | + * |
|
81 | + * @var FormHtmlFilter |
|
82 | + */ |
|
83 | + protected $_form_html_filter; |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param array $options_array { |
|
88 | + * @type $name string the name for this form section, if you want to explicitly define it |
|
89 | + * } |
|
90 | + * @throws InvalidDataTypeException |
|
91 | + */ |
|
92 | + public function __construct($options_array = array()) |
|
93 | + { |
|
94 | + // used by display strategies |
|
95 | + // assign incoming values to properties |
|
96 | + foreach ($options_array as $key => $value) { |
|
97 | + $key = '_' . $key; |
|
98 | + if (property_exists($this, $key) && empty($this->{$key})) { |
|
99 | + $this->{$key} = $value; |
|
100 | + if ($key === '_subsections' && ! is_array($value)) { |
|
101 | + throw new InvalidDataTypeException($key, $value, 'array'); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + // set parser which allows the form section's rendered HTML to be filtered |
|
106 | + if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
107 | + $this->_form_html_filter = $options_array['form_html_filter']; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @param $parent_form_section |
|
115 | + * @param $name |
|
116 | + * @throws \EE_Error |
|
117 | + */ |
|
118 | + protected function _construct_finalize($parent_form_section, $name) |
|
119 | + { |
|
120 | + $this->_construction_finalized = true; |
|
121 | + $this->_parent_section = $parent_form_section; |
|
122 | + if ($name !== null) { |
|
123 | + $this->_name = $name; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * make sure construction finalized was called, otherwise children might not be ready |
|
131 | + * |
|
132 | + * @return void |
|
133 | + * @throws \EE_Error |
|
134 | + */ |
|
135 | + public function ensure_construct_finalized_called() |
|
136 | + { |
|
137 | + if (! $this->_construction_finalized) { |
|
138 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + public function action() |
|
148 | + { |
|
149 | + return $this->_action; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param string $action |
|
156 | + */ |
|
157 | + public function set_action($action) |
|
158 | + { |
|
159 | + $this->_action = $action; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function method() |
|
168 | + { |
|
169 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $method |
|
176 | + */ |
|
177 | + public function set_method($method) |
|
178 | + { |
|
179 | + switch ($method) { |
|
180 | + case 'get': |
|
181 | + case 'GET': |
|
182 | + $this->_method = 'GET'; |
|
183 | + break; |
|
184 | + default: |
|
185 | + $this->_method = 'POST'; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Sets the html_id to its default value, if none was specified in the constructor. |
|
193 | + * Calculation involves using the name and the parent's html id |
|
194 | + * return void |
|
195 | + * |
|
196 | + * @throws \EE_Error |
|
197 | + */ |
|
198 | + protected function _set_default_html_id_if_empty() |
|
199 | + { |
|
200 | + if (! $this->_html_id) { |
|
201 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
202 | + $this->_html_id = $this->_parent_section->html_id() |
|
203 | + . '-' |
|
204 | + . $this->_prep_name_for_html_id($this->name()); |
|
205 | + } else { |
|
206 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
207 | + } |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * _prep_name_for_html_id |
|
215 | + * |
|
216 | + * @param $name |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + private function _prep_name_for_html_id($name) |
|
220 | + { |
|
221 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
228 | - * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
229 | - * and call get_html when you want to output the html. Calling get_html_and_js after |
|
230 | - * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
231 | - * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
232 | - * and so might stop working anytime. |
|
233 | - * |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function get_html_and_js() |
|
237 | - { |
|
238 | - return $this->get_html(); |
|
239 | - } |
|
226 | + /** |
|
227 | + * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
228 | + * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
229 | + * and call get_html when you want to output the html. Calling get_html_and_js after |
|
230 | + * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
231 | + * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
232 | + * and so might stop working anytime. |
|
233 | + * |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function get_html_and_js() |
|
237 | + { |
|
238 | + return $this->get_html(); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | - |
|
243 | - /** |
|
244 | - * Gets the HTML for displaying this form section |
|
245 | - * |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - abstract public function get_html(); |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * @param bool $add_pound_sign |
|
253 | - * @return string |
|
254 | - * @throws EE_Error |
|
255 | - */ |
|
256 | - public function html_id($add_pound_sign = false) |
|
257 | - { |
|
258 | - $this->_set_default_html_id_if_empty(); |
|
259 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function html_class() |
|
268 | - { |
|
269 | - return $this->_html_class; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public function html_style() |
|
278 | - { |
|
279 | - return $this->_html_style; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param mixed $html_class |
|
286 | - */ |
|
287 | - public function set_html_class($html_class) |
|
288 | - { |
|
289 | - $this->_html_class = $html_class; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param mixed $html_id |
|
296 | - */ |
|
297 | - public function set_html_id($html_id) |
|
298 | - { |
|
299 | - $this->_html_id = $html_id; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * @param mixed $html_style |
|
306 | - */ |
|
307 | - public function set_html_style($html_style) |
|
308 | - { |
|
309 | - $this->_html_style = $html_style; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $other_html_attributes |
|
316 | - */ |
|
317 | - public function set_other_html_attributes($other_html_attributes) |
|
318 | - { |
|
319 | - $this->_other_html_attributes = $other_html_attributes; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function other_html_attributes() |
|
328 | - { |
|
329 | - return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : ''; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Gets the name of the form section. This is not the same as the HTML name. |
|
336 | - * |
|
337 | - * @throws EE_Error |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - public function name() |
|
341 | - { |
|
342 | - if (! $this->_construction_finalized) { |
|
343 | - throw new EE_Error(sprintf(esc_html__( |
|
344 | - '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\'', |
|
345 | - 'event_espresso' |
|
346 | - ), get_class($this))); |
|
347 | - } |
|
348 | - return $this->_name; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Gets the parent section |
|
355 | - * |
|
356 | - * @return EE_Form_Section_Proper |
|
357 | - */ |
|
358 | - public function parent_section() |
|
359 | - { |
|
360 | - return $this->_parent_section; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * returns HTML for generating the opening form HTML tag (<form>) |
|
366 | - * |
|
367 | - * @param string $action the URL the form is submitted to |
|
368 | - * @param string $method POST (default) or GET |
|
369 | - * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
370 | - * @return string |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - public function form_open($action = '', $method = '', $other_attributes = '') |
|
374 | - { |
|
375 | - if (! empty($action)) { |
|
376 | - $this->set_action($action); |
|
377 | - } |
|
378 | - if (! empty($method)) { |
|
379 | - $this->set_method($method); |
|
380 | - } |
|
381 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | - $html .= ' action="' . $this->action() . '"'; |
|
384 | - $html .= ' method="' . $this->method() . '"'; |
|
385 | - $html .= ' name="' . $this->name() . '"'; |
|
386 | - $html .= $other_attributes . '>'; |
|
387 | - return $html; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * ensures that html id for form either ends in "-form" or "-frm" |
|
394 | - * so that id doesn't conflict/collide with other elements |
|
395 | - * |
|
396 | - * @param string $html_id |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - protected function get_html_id_for_form($html_id) |
|
400 | - { |
|
401 | - $strlen = strlen($html_id); |
|
402 | - $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
|
403 | - ? $html_id |
|
404 | - : $html_id . '-frm'; |
|
405 | - return $html_id; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * returns HTML for generating the closing form HTML tag (</form>) |
|
411 | - * |
|
412 | - * @return string |
|
413 | - * @throws EE_Error |
|
414 | - */ |
|
415 | - public function form_close() |
|
416 | - { |
|
417 | - return EEH_HTML::nl(-1, 'form') |
|
418 | - . '</form>' |
|
419 | - . EEH_HTML::nl() |
|
420 | - . '<!-- end of ee-' |
|
421 | - . $this->html_id() |
|
422 | - . '-form -->' |
|
423 | - . EEH_HTML::nl(); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
430 | - * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
431 | - * Default does nothing, but child classes can override |
|
432 | - * |
|
433 | - * @return void |
|
434 | - */ |
|
435 | - public function enqueue_js() |
|
436 | - { |
|
437 | - // defaults to enqueue NO js or css |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
444 | - * with it, and it will be on each form section's 'other_data' property. |
|
445 | - * By default nothing is added, but child classes can extend this method to add something. |
|
446 | - * Eg, if you have an input that will cause a modal dialog to appear, |
|
447 | - * here you could add an entry like 'modal_dialog_inputs' to this array |
|
448 | - * to map between the input's html ID and the modal dialogue's ID, so that |
|
449 | - * your JS code will know where to find the modal dialog when the input is pressed. |
|
450 | - * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
451 | - * |
|
452 | - * @param array $form_other_js_data |
|
453 | - * @return array |
|
454 | - */ |
|
455 | - public function get_other_js_data($form_other_js_data = array()) |
|
456 | - { |
|
457 | - return $form_other_js_data; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
464 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
465 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
466 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
467 | - * which will be returned. |
|
468 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
469 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
470 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
471 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
472 | - * Etc |
|
473 | - * |
|
474 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
475 | - * @return EE_Form_Section_Base |
|
476 | - */ |
|
477 | - public function find_section_from_path($form_section_path) |
|
478 | - { |
|
479 | - if (strpos($form_section_path, '/') === 0) { |
|
480 | - $form_section_path = substr($form_section_path, strlen('/')); |
|
481 | - } |
|
482 | - if (empty($form_section_path)) { |
|
483 | - return $this; |
|
484 | - } |
|
485 | - if (strpos($form_section_path, '../') === 0) { |
|
486 | - $parent = $this->parent_section(); |
|
487 | - $form_section_path = substr($form_section_path, strlen('../')); |
|
488 | - if ($parent instanceof EE_Form_Section_Base) { |
|
489 | - return $parent->find_section_from_path($form_section_path); |
|
490 | - } |
|
491 | - if (empty($form_section_path)) { |
|
492 | - return $this; |
|
493 | - } |
|
494 | - } |
|
495 | - // couldn't find it using simple parent following |
|
496 | - return null; |
|
497 | - } |
|
242 | + |
|
243 | + /** |
|
244 | + * Gets the HTML for displaying this form section |
|
245 | + * |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + abstract public function get_html(); |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * @param bool $add_pound_sign |
|
253 | + * @return string |
|
254 | + * @throws EE_Error |
|
255 | + */ |
|
256 | + public function html_id($add_pound_sign = false) |
|
257 | + { |
|
258 | + $this->_set_default_html_id_if_empty(); |
|
259 | + return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function html_class() |
|
268 | + { |
|
269 | + return $this->_html_class; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public function html_style() |
|
278 | + { |
|
279 | + return $this->_html_style; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param mixed $html_class |
|
286 | + */ |
|
287 | + public function set_html_class($html_class) |
|
288 | + { |
|
289 | + $this->_html_class = $html_class; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param mixed $html_id |
|
296 | + */ |
|
297 | + public function set_html_id($html_id) |
|
298 | + { |
|
299 | + $this->_html_id = $html_id; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * @param mixed $html_style |
|
306 | + */ |
|
307 | + public function set_html_style($html_style) |
|
308 | + { |
|
309 | + $this->_html_style = $html_style; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $other_html_attributes |
|
316 | + */ |
|
317 | + public function set_other_html_attributes($other_html_attributes) |
|
318 | + { |
|
319 | + $this->_other_html_attributes = $other_html_attributes; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function other_html_attributes() |
|
328 | + { |
|
329 | + return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : ''; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Gets the name of the form section. This is not the same as the HTML name. |
|
336 | + * |
|
337 | + * @throws EE_Error |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + public function name() |
|
341 | + { |
|
342 | + if (! $this->_construction_finalized) { |
|
343 | + throw new EE_Error(sprintf(esc_html__( |
|
344 | + '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\'', |
|
345 | + 'event_espresso' |
|
346 | + ), get_class($this))); |
|
347 | + } |
|
348 | + return $this->_name; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Gets the parent section |
|
355 | + * |
|
356 | + * @return EE_Form_Section_Proper |
|
357 | + */ |
|
358 | + public function parent_section() |
|
359 | + { |
|
360 | + return $this->_parent_section; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * returns HTML for generating the opening form HTML tag (<form>) |
|
366 | + * |
|
367 | + * @param string $action the URL the form is submitted to |
|
368 | + * @param string $method POST (default) or GET |
|
369 | + * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
370 | + * @return string |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + public function form_open($action = '', $method = '', $other_attributes = '') |
|
374 | + { |
|
375 | + if (! empty($action)) { |
|
376 | + $this->set_action($action); |
|
377 | + } |
|
378 | + if (! empty($method)) { |
|
379 | + $this->set_method($method); |
|
380 | + } |
|
381 | + $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | + $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | + $html .= ' action="' . $this->action() . '"'; |
|
384 | + $html .= ' method="' . $this->method() . '"'; |
|
385 | + $html .= ' name="' . $this->name() . '"'; |
|
386 | + $html .= $other_attributes . '>'; |
|
387 | + return $html; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * ensures that html id for form either ends in "-form" or "-frm" |
|
394 | + * so that id doesn't conflict/collide with other elements |
|
395 | + * |
|
396 | + * @param string $html_id |
|
397 | + * @return string |
|
398 | + */ |
|
399 | + protected function get_html_id_for_form($html_id) |
|
400 | + { |
|
401 | + $strlen = strlen($html_id); |
|
402 | + $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
|
403 | + ? $html_id |
|
404 | + : $html_id . '-frm'; |
|
405 | + return $html_id; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * returns HTML for generating the closing form HTML tag (</form>) |
|
411 | + * |
|
412 | + * @return string |
|
413 | + * @throws EE_Error |
|
414 | + */ |
|
415 | + public function form_close() |
|
416 | + { |
|
417 | + return EEH_HTML::nl(-1, 'form') |
|
418 | + . '</form>' |
|
419 | + . EEH_HTML::nl() |
|
420 | + . '<!-- end of ee-' |
|
421 | + . $this->html_id() |
|
422 | + . '-form -->' |
|
423 | + . EEH_HTML::nl(); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
430 | + * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
431 | + * Default does nothing, but child classes can override |
|
432 | + * |
|
433 | + * @return void |
|
434 | + */ |
|
435 | + public function enqueue_js() |
|
436 | + { |
|
437 | + // defaults to enqueue NO js or css |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
444 | + * with it, and it will be on each form section's 'other_data' property. |
|
445 | + * By default nothing is added, but child classes can extend this method to add something. |
|
446 | + * Eg, if you have an input that will cause a modal dialog to appear, |
|
447 | + * here you could add an entry like 'modal_dialog_inputs' to this array |
|
448 | + * to map between the input's html ID and the modal dialogue's ID, so that |
|
449 | + * your JS code will know where to find the modal dialog when the input is pressed. |
|
450 | + * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
451 | + * |
|
452 | + * @param array $form_other_js_data |
|
453 | + * @return array |
|
454 | + */ |
|
455 | + public function get_other_js_data($form_other_js_data = array()) |
|
456 | + { |
|
457 | + return $form_other_js_data; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
464 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
465 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
466 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
467 | + * which will be returned. |
|
468 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
469 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
470 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
471 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
472 | + * Etc |
|
473 | + * |
|
474 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
475 | + * @return EE_Form_Section_Base |
|
476 | + */ |
|
477 | + public function find_section_from_path($form_section_path) |
|
478 | + { |
|
479 | + if (strpos($form_section_path, '/') === 0) { |
|
480 | + $form_section_path = substr($form_section_path, strlen('/')); |
|
481 | + } |
|
482 | + if (empty($form_section_path)) { |
|
483 | + return $this; |
|
484 | + } |
|
485 | + if (strpos($form_section_path, '../') === 0) { |
|
486 | + $parent = $this->parent_section(); |
|
487 | + $form_section_path = substr($form_section_path, strlen('../')); |
|
488 | + if ($parent instanceof EE_Form_Section_Base) { |
|
489 | + return $parent->find_section_from_path($form_section_path); |
|
490 | + } |
|
491 | + if (empty($form_section_path)) { |
|
492 | + return $this; |
|
493 | + } |
|
494 | + } |
|
495 | + // couldn't find it using simple parent following |
|
496 | + return null; |
|
497 | + } |
|
498 | 498 | } |
499 | 499 | // End of file EE_Form_Section_Base.form.php |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
39 | 39 | $this->_model = $options_array['model']; |
40 | 40 | } |
41 | - if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
41 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
42 | 42 | throw new EE_Error(sprintf(esc_html__( |
43 | 43 | "Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
44 | 44 | "event_espresso" |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | switch (get_class($relation_obj)) { |
104 | 104 | case 'EE_HABTM_Relation': |
105 | 105 | if ( |
106 | - isset($subsection_args[ $relation_name ]) |
|
107 | - && isset($subsection_args[ $relation_name ]['model_objects']) |
|
106 | + isset($subsection_args[$relation_name]) |
|
107 | + && isset($subsection_args[$relation_name]['model_objects']) |
|
108 | 108 | ) { |
109 | - $model_objects = $subsection_args[ $relation_name ]['model_objects']; |
|
109 | + $model_objects = $subsection_args[$relation_name]['model_objects']; |
|
110 | 110 | } else { |
111 | 111 | $model_objects = $relation_obj->get_other_model()->get_all(); |
112 | 112 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | default: |
116 | 116 | } |
117 | 117 | if ($input) { |
118 | - $inputs[ $relation_name ] = $input; |
|
118 | + $inputs[$relation_name] = $input; |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | return $inputs; |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | } |
266 | 266 | $reflection = new ReflectionClass($input_class); |
267 | 267 | $input = $reflection->newInstanceArgs($input_constructor_args); |
268 | - $inputs[ $field_name ] = $input; |
|
268 | + $inputs[$field_name] = $input; |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | return $inputs; |
@@ -291,14 +291,14 @@ discard block |
||
291 | 291 | if ($relation_obj instanceof EE_Belongs_To_Relation) { |
292 | 292 | // then we only expect there to be one |
293 | 293 | $related_item = $this->_model_object->get_first_related($relation_name); |
294 | - $defaults[ $relation_name ] = $related_item->ID(); |
|
294 | + $defaults[$relation_name] = $related_item->ID(); |
|
295 | 295 | } else { |
296 | 296 | $related_items = $this->_model_object->get_many_related($relation_name); |
297 | 297 | $ids = array(); |
298 | 298 | foreach ($related_items as $related_item) { |
299 | 299 | $ids[] = $related_item->ID(); |
300 | 300 | } |
301 | - $defaults[ $relation_name ] = $ids; |
|
301 | + $defaults[$relation_name] = $ids; |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | { |
337 | 337 | parent::_normalize($req_data); |
338 | 338 | // create or set the model object, if it isn't already |
339 | - if (! $this->_model_object) { |
|
339 | + if ( ! $this->_model_object) { |
|
340 | 340 | // check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
341 | 341 | $pk_name = $this->_model->primary_key_name(); |
342 | 342 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public function save() |
363 | 363 | { |
364 | - if (! $this->_model_object) { |
|
364 | + if ( ! $this->_model_object) { |
|
365 | 365 | throw new EE_Error(sprintf(esc_html__( |
366 | 366 | "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", |
367 | 367 | "event_espresso" |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | } |
377 | 377 | $success = $this->_model_object->save(); |
378 | 378 | foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
379 | - if (isset($this->_subsections[ $relation_name ])) { |
|
379 | + if (isset($this->_subsections[$relation_name])) { |
|
380 | 380 | $success = $this->_save_related_info($relation_name); |
381 | 381 | } |
382 | 382 | } |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | */ |
464 | 464 | protected function _set_default_name_if_empty() |
465 | 465 | { |
466 | - if (! $this->_name) { |
|
467 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
466 | + if ( ! $this->_name) { |
|
467 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
468 | 468 | $this->_name = $default_name; |
469 | 469 | } |
470 | 470 | } |
@@ -11,460 +11,460 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Model_Form_Section extends EE_Form_Section_Proper |
13 | 13 | { |
14 | - /** |
|
15 | - * @var EEM_Base |
|
16 | - */ |
|
17 | - protected $_model = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var EE_Base_Class |
|
21 | - */ |
|
22 | - protected $_model_object = null; |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @param array $options_array keys: { |
|
28 | - * @type EEM_Base $model |
|
29 | - * @type EE_Base_Class $model_object |
|
30 | - * @type array $subsection_args array keys should be subsection names (that either do or will exist), and |
|
31 | - * values are the arrays as you would pass them to that subsection |
|
32 | - * } |
|
33 | - * @throws EE_Error |
|
34 | - */ |
|
35 | - public function __construct($options_array = array()) |
|
36 | - { |
|
37 | - if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
38 | - $this->_model = $options_array['model']; |
|
39 | - } |
|
40 | - if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
41 | - throw new EE_Error(sprintf(esc_html__( |
|
42 | - "Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
|
43 | - "event_espresso" |
|
44 | - ))); |
|
45 | - } |
|
46 | - if (isset($options_array['subsection_args'])) { |
|
47 | - $subsection_args = $options_array['subsection_args']; |
|
48 | - } else { |
|
49 | - $subsection_args = array(); |
|
50 | - } |
|
51 | - // gather fields and relations to convert to inputs |
|
52 | - // but if they're just going to exclude a field anyways, don't bother converting it to an input |
|
53 | - $exclude = $this->_subsections; |
|
54 | - if (isset($options_array['exclude'])) { |
|
55 | - $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
56 | - } |
|
57 | - $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
|
58 | - $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
|
59 | - // convert fields and relations to inputs |
|
60 | - $this->_subsections = array_merge( |
|
61 | - $this->_convert_model_fields_to_inputs($model_fields), |
|
62 | - $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
63 | - $this->_subsections |
|
64 | - ); |
|
65 | - parent::__construct($options_array); |
|
66 | - if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
67 | - $this->populate_model_obj($options_array['model_object']); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * For now, just makes inputs for only HABTM relations |
|
75 | - * |
|
76 | - * @param EE_Model_Relation_Base[] $relations |
|
77 | - * @param array $subsection_args keys should be existing or soon-to-be-existing input names, and |
|
78 | - * their values are { |
|
79 | - * @type array { |
|
80 | - * @type EE_Base_Class[] $model_objects if the subsection is an EE_Select_Multi_Model_Input |
|
81 | - * } |
|
82 | - * } |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) |
|
86 | - { |
|
87 | - $inputs = array(); |
|
88 | - foreach ($relations as $relation_name => $relation_obj) { |
|
89 | - $input_constructor_args = array( |
|
90 | - array_merge( |
|
91 | - array( |
|
92 | - 'required' => $relation_obj instanceof EE_Belongs_To_Relation, |
|
93 | - 'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation |
|
94 | - ? $relation_obj->get_other_model()->item_name(1) |
|
95 | - : $relation_obj->get_other_model() |
|
96 | - ->item_name(2), |
|
97 | - ), |
|
98 | - $subsection_args |
|
99 | - ), |
|
100 | - ); |
|
101 | - $input = null; |
|
102 | - switch (get_class($relation_obj)) { |
|
103 | - case 'EE_HABTM_Relation': |
|
104 | - if ( |
|
105 | - isset($subsection_args[ $relation_name ]) |
|
106 | - && isset($subsection_args[ $relation_name ]['model_objects']) |
|
107 | - ) { |
|
108 | - $model_objects = $subsection_args[ $relation_name ]['model_objects']; |
|
109 | - } else { |
|
110 | - $model_objects = $relation_obj->get_other_model()->get_all(); |
|
111 | - } |
|
112 | - $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
113 | - break; |
|
114 | - default: |
|
115 | - } |
|
116 | - if ($input) { |
|
117 | - $inputs[ $relation_name ] = $input; |
|
118 | - } |
|
119 | - } |
|
120 | - return $inputs; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Changes model fields into form section inputs |
|
127 | - * |
|
128 | - * @param EE_Model_Field_Base[] $model_fields keys are the model's name |
|
129 | - * @throws EE_Error |
|
130 | - * @return EE_Form_Input_Base[] |
|
131 | - */ |
|
132 | - protected function _convert_model_fields_to_inputs($model_fields = array()) |
|
133 | - { |
|
134 | - $inputs = array(); |
|
135 | - foreach ($model_fields as $field_name => $model_field) { |
|
136 | - if ($model_field instanceof EE_Model_Field_Base) { |
|
137 | - $input_constructor_args = array( |
|
138 | - array( |
|
139 | - 'required' => ! $model_field->is_nullable() |
|
140 | - && $model_field->get_default_value() |
|
141 | - === null, |
|
142 | - 'html_label_text' => $model_field->get_nicename(), |
|
143 | - 'default' => $model_field->get_default_value(), |
|
144 | - ), |
|
145 | - ); |
|
146 | - switch (get_class($model_field)) { |
|
147 | - case 'EE_All_Caps_Text_Field': |
|
148 | - case 'EE_Any_Foreign_Model_Name_Field': |
|
149 | - $input_class = 'EE_Text_Input'; |
|
150 | - break; |
|
151 | - case 'EE_Boolean_Field': |
|
152 | - $input_class = 'EE_Yes_No_Input'; |
|
153 | - break; |
|
154 | - case 'EE_Datetime_Field': |
|
155 | - throw new EE_Error(sprintf(esc_html__( |
|
156 | - "Model field '%s' does not yet have a known conversion to form input", |
|
157 | - "event_espresso" |
|
158 | - ), get_class($model_field))); |
|
159 | - break; |
|
160 | - case 'EE_Email_Field': |
|
161 | - $input_class = 'EE_Email_Input'; |
|
162 | - break; |
|
163 | - case 'EE_Enum_Integer_Field': |
|
164 | - throw new EE_Error(sprintf(esc_html__( |
|
165 | - "Model field '%s' does not yet have a known conversion to form input", |
|
166 | - "event_espresso" |
|
167 | - ), get_class($model_field))); |
|
168 | - break; |
|
169 | - case 'EE_Enum_Text_Field': |
|
170 | - throw new EE_Error(sprintf(esc_html__( |
|
171 | - "Model field '%s' does not yet have a known conversion to form input", |
|
172 | - "event_espresso" |
|
173 | - ), get_class($model_field))); |
|
174 | - break; |
|
175 | - case 'EE_Float_Field': |
|
176 | - $input_class = 'EE_Float_Input'; |
|
177 | - break; |
|
178 | - case 'EE_Foreign_Key_Int_Field': |
|
179 | - case 'EE_Foreign_Key_String_Field': |
|
180 | - case 'EE_WP_User_Field': |
|
181 | - $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name |
|
182 | - ? $model_field->get_model_class_names_pointed_to() : array(); |
|
183 | - if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
184 | - $input_class = 'EE_Text_Input'; |
|
185 | - } else { |
|
186 | - // so its just one model |
|
187 | - $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
|
188 | - $model = EE_Registry::instance()->load_model($model_name); |
|
189 | - $model_names = $model->get_all_names(array('limit' => 10)); |
|
190 | - if ($model_field->is_nullable()) { |
|
191 | - array_unshift($model_names, esc_html__("Please Select", 'event_espresso')); |
|
192 | - } |
|
193 | - $input_constructor_args[1] = $input_constructor_args[0]; |
|
194 | - $input_constructor_args[0] = $model_names; |
|
195 | - $input_class = 'EE_Select_Input'; |
|
196 | - } |
|
197 | - break; |
|
198 | - case 'EE_Full_HTML_Field': |
|
199 | - $input_class = 'EE_Text_Area_Input'; |
|
200 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
201 | - break; |
|
202 | - case 'EE_Infinite_Integer': |
|
203 | - throw new EE_Error(sprintf(esc_html__( |
|
204 | - "Model field '%s' does not yet have a known conversion to form input", |
|
205 | - "event_espresso" |
|
206 | - ), get_class($model_field))); |
|
207 | - break; |
|
208 | - case 'EE_Integer_Field': |
|
209 | - $input_class = 'EE_Text_Input'; |
|
210 | - break; |
|
211 | - case 'EE_Maybe_Serialized_Text_Field': |
|
212 | - $input_class = 'EE_Text_Area_Input'; |
|
213 | - break; |
|
214 | - case 'EE_Money_Field': |
|
215 | - throw new EE_Error(sprintf(esc_html__( |
|
216 | - "Model field '%s' does not yet have a known conversion to form input", |
|
217 | - "event_espresso" |
|
218 | - ), get_class($model_field))); |
|
219 | - break; |
|
220 | - case 'EE_Post_Content_Field': |
|
221 | - $input_class = 'EE_Text_Area_Input'; |
|
222 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
223 | - break; |
|
224 | - case 'EE_Plain_Text_Field': |
|
225 | - $input_class = 'EE_Text_Input'; |
|
226 | - break; |
|
227 | - case 'EE_Primary_Key_Int_Field': |
|
228 | - $input_class = 'EE_Hidden_Input'; |
|
229 | - $input_constructor_args[0]['normalization_strategy'] = new EE_Int_Normalization(); |
|
230 | - break; |
|
231 | - case 'EE_Primary_Key_String_Field': |
|
232 | - $input_class = 'EE_Hidden_Input'; |
|
233 | - break; |
|
234 | - case 'EE_Serialized_Text_Field': |
|
235 | - $input_class = 'EE_Text_Area_Input'; |
|
236 | - break; |
|
237 | - case 'EE_Simple_HTML_Field': |
|
238 | - $input_class = 'EE_Text_Area_Input'; |
|
239 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
240 | - break; |
|
241 | - case 'EE_Slug_Field': |
|
242 | - $input_class = 'EE_Text_Input'; |
|
243 | - break; |
|
244 | - case 'EE_Trashed_Flag_Field': |
|
245 | - $input_class = 'EE_Yes_No_Input'; |
|
246 | - break; |
|
247 | - case 'EE_WP_Post_Status_Field': |
|
248 | - throw new EE_Error(sprintf(esc_html__( |
|
249 | - "Model field '%s' does not yet have a known conversion to form input", |
|
250 | - "event_espresso" |
|
251 | - ), get_class($model_field))); |
|
252 | - break; |
|
253 | - case 'EE_WP_Post_Type_Field': |
|
254 | - throw new EE_Error(sprintf(esc_html__( |
|
255 | - "Model field '%s' does not yet have a known conversion to form input", |
|
256 | - "event_espresso" |
|
257 | - ), get_class($model_field))); |
|
258 | - break; |
|
259 | - default: |
|
260 | - throw new EE_Error(sprintf(esc_html__( |
|
261 | - "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", |
|
262 | - "event_espresso" |
|
263 | - ), get_class($model_field))); |
|
264 | - } |
|
265 | - $reflection = new ReflectionClass($input_class); |
|
266 | - $input = $reflection->newInstanceArgs($input_constructor_args); |
|
267 | - $inputs[ $field_name ] = $input; |
|
268 | - } |
|
269 | - } |
|
270 | - return $inputs; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Mostly the same as populate_defaults , except takes a model object as input, not an array, |
|
277 | - * and also sets the form's _model_object |
|
278 | - * |
|
279 | - * @param EE_Base_Class $model_obj |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public function populate_model_obj($model_obj) |
|
283 | - { |
|
284 | - $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
285 | - $this->_model_object = $model_obj; |
|
286 | - $defaults = $model_obj->model_field_array(); |
|
287 | - foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
288 | - $subsection = $this->get_subsection($relation_name, false); |
|
289 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
290 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
291 | - // then we only expect there to be one |
|
292 | - $related_item = $this->_model_object->get_first_related($relation_name); |
|
293 | - $defaults[ $relation_name ] = $related_item->ID(); |
|
294 | - } else { |
|
295 | - $related_items = $this->_model_object->get_many_related($relation_name); |
|
296 | - $ids = array(); |
|
297 | - foreach ($related_items as $related_item) { |
|
298 | - $ids[] = $related_item->ID(); |
|
299 | - } |
|
300 | - $defaults[ $relation_name ] = $ids; |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - $defaults = apply_filters( |
|
305 | - 'FHEE__EE_Model_Form_Section__populate_model_obj', |
|
306 | - $defaults, |
|
307 | - $this |
|
308 | - ); |
|
309 | - $this->populate_defaults($defaults); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Gets all the input values that correspond to model fields. Keys are the input/field names, |
|
316 | - * values are their normalized values |
|
317 | - * |
|
318 | - * @return array |
|
319 | - */ |
|
320 | - public function inputs_values_corresponding_to_model_fields() |
|
321 | - { |
|
322 | - return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * After we've normalized the data as normal, set the corresponding model object |
|
329 | - * on the form. |
|
330 | - * |
|
331 | - * @param array $req_data should usually be the form post/request data (the default). |
|
332 | - * @return void |
|
333 | - */ |
|
334 | - public function _normalize($req_data) |
|
335 | - { |
|
336 | - parent::_normalize($req_data); |
|
337 | - // create or set the model object, if it isn't already |
|
338 | - if (! $this->_model_object) { |
|
339 | - // check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
|
340 | - $pk_name = $this->_model->primary_key_name(); |
|
341 | - $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
|
342 | - if ($model_obj) { |
|
343 | - $this->_model_object = $model_obj; |
|
344 | - } else { |
|
345 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
346 | - } |
|
347 | - } |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * After this form has been initialized and is verified to be valid, |
|
354 | - * either creates a model object from its data and saves it, or updates |
|
355 | - * the model object its data represents |
|
356 | - * |
|
357 | - * @throws EE_Error |
|
358 | - * @return int, 1 on a successful update, the ID of |
|
359 | - * the new entry on insert; 0 on failure |
|
360 | - */ |
|
361 | - public function save() |
|
362 | - { |
|
363 | - if (! $this->_model_object) { |
|
364 | - throw new EE_Error(sprintf(esc_html__( |
|
365 | - "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", |
|
366 | - "event_espresso" |
|
367 | - ), get_class($this->_model))); |
|
368 | - } |
|
369 | - // ok so the model object is set. Just set it with the submitted form data |
|
370 | - foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) { |
|
371 | - // only set the non-primary key |
|
372 | - if ($field_name != $this->_model->primary_key_name()) { |
|
373 | - $this->_model_object->set($field_name, $field_value); |
|
374 | - } |
|
375 | - } |
|
376 | - $success = $this->_model_object->save(); |
|
377 | - foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
378 | - if (isset($this->_subsections[ $relation_name ])) { |
|
379 | - $success = $this->_save_related_info($relation_name); |
|
380 | - } |
|
381 | - } |
|
382 | - do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success); |
|
383 | - return $success; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Automatically finds the related model info from the form, if present, and |
|
390 | - * save the relations indicated |
|
391 | - * |
|
392 | - * @type string $relation_name |
|
393 | - * @return bool |
|
394 | - * @throws EE_Error |
|
395 | - */ |
|
396 | - protected function _save_related_info($relation_name) |
|
397 | - { |
|
398 | - $relation_obj = $this->_model->related_settings_for($relation_name); |
|
399 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
400 | - // there is just a foreign key on this model pointing to that one |
|
401 | - $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
|
402 | - } elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
403 | - // then we want to consider all of its currently-related things. |
|
404 | - // if they're in this list, keep them |
|
405 | - // if they're not in this list, remove them |
|
406 | - // and lastly add all the new items |
|
407 | - throw new EE_Error(sprintf(esc_html__( |
|
408 | - 'Automatic saving of related info across a "has many" relation is not yet supported', |
|
409 | - "event_espresso" |
|
410 | - ))); |
|
411 | - } elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
412 | - // delete everything NOT in this list |
|
413 | - $normalized_input_value = $this->get_input_value($relation_name); |
|
414 | - if ($normalized_input_value && is_array($normalized_input_value)) { |
|
415 | - $where_query_params = array( |
|
416 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value), |
|
417 | - ); |
|
418 | - } else { |
|
419 | - $where_query_params = array(); |
|
420 | - } |
|
421 | - $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
422 | - foreach ($normalized_input_value as $id) { |
|
423 | - $this->_model_object->_add_relation_to($id, $relation_name); |
|
424 | - } |
|
425 | - } |
|
426 | - return true; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Gets the model of this model form |
|
433 | - * |
|
434 | - * @return EEM_Base |
|
435 | - */ |
|
436 | - public function get_model() |
|
437 | - { |
|
438 | - return $this->_model; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * Gets the model object for this model form, which was either set |
|
445 | - * upon construction (using the $options_array arg 'model_object'), by using |
|
446 | - * set_model_object($model_obj), or implicitly |
|
447 | - * when receive_form_submission($req_data) was called. |
|
448 | - * |
|
449 | - * @return EE_Base_Class |
|
450 | - */ |
|
451 | - public function get_model_object() |
|
452 | - { |
|
453 | - return $this->_model_object; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * gets teh default name of this form section if none is specified |
|
460 | - * |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - protected function _set_default_name_if_empty() |
|
464 | - { |
|
465 | - if (! $this->_name) { |
|
466 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
467 | - $this->_name = $default_name; |
|
468 | - } |
|
469 | - } |
|
14 | + /** |
|
15 | + * @var EEM_Base |
|
16 | + */ |
|
17 | + protected $_model = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var EE_Base_Class |
|
21 | + */ |
|
22 | + protected $_model_object = null; |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @param array $options_array keys: { |
|
28 | + * @type EEM_Base $model |
|
29 | + * @type EE_Base_Class $model_object |
|
30 | + * @type array $subsection_args array keys should be subsection names (that either do or will exist), and |
|
31 | + * values are the arrays as you would pass them to that subsection |
|
32 | + * } |
|
33 | + * @throws EE_Error |
|
34 | + */ |
|
35 | + public function __construct($options_array = array()) |
|
36 | + { |
|
37 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
38 | + $this->_model = $options_array['model']; |
|
39 | + } |
|
40 | + if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
41 | + throw new EE_Error(sprintf(esc_html__( |
|
42 | + "Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
|
43 | + "event_espresso" |
|
44 | + ))); |
|
45 | + } |
|
46 | + if (isset($options_array['subsection_args'])) { |
|
47 | + $subsection_args = $options_array['subsection_args']; |
|
48 | + } else { |
|
49 | + $subsection_args = array(); |
|
50 | + } |
|
51 | + // gather fields and relations to convert to inputs |
|
52 | + // but if they're just going to exclude a field anyways, don't bother converting it to an input |
|
53 | + $exclude = $this->_subsections; |
|
54 | + if (isset($options_array['exclude'])) { |
|
55 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
56 | + } |
|
57 | + $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
|
58 | + $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
|
59 | + // convert fields and relations to inputs |
|
60 | + $this->_subsections = array_merge( |
|
61 | + $this->_convert_model_fields_to_inputs($model_fields), |
|
62 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
63 | + $this->_subsections |
|
64 | + ); |
|
65 | + parent::__construct($options_array); |
|
66 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
67 | + $this->populate_model_obj($options_array['model_object']); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * For now, just makes inputs for only HABTM relations |
|
75 | + * |
|
76 | + * @param EE_Model_Relation_Base[] $relations |
|
77 | + * @param array $subsection_args keys should be existing or soon-to-be-existing input names, and |
|
78 | + * their values are { |
|
79 | + * @type array { |
|
80 | + * @type EE_Base_Class[] $model_objects if the subsection is an EE_Select_Multi_Model_Input |
|
81 | + * } |
|
82 | + * } |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) |
|
86 | + { |
|
87 | + $inputs = array(); |
|
88 | + foreach ($relations as $relation_name => $relation_obj) { |
|
89 | + $input_constructor_args = array( |
|
90 | + array_merge( |
|
91 | + array( |
|
92 | + 'required' => $relation_obj instanceof EE_Belongs_To_Relation, |
|
93 | + 'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation |
|
94 | + ? $relation_obj->get_other_model()->item_name(1) |
|
95 | + : $relation_obj->get_other_model() |
|
96 | + ->item_name(2), |
|
97 | + ), |
|
98 | + $subsection_args |
|
99 | + ), |
|
100 | + ); |
|
101 | + $input = null; |
|
102 | + switch (get_class($relation_obj)) { |
|
103 | + case 'EE_HABTM_Relation': |
|
104 | + if ( |
|
105 | + isset($subsection_args[ $relation_name ]) |
|
106 | + && isset($subsection_args[ $relation_name ]['model_objects']) |
|
107 | + ) { |
|
108 | + $model_objects = $subsection_args[ $relation_name ]['model_objects']; |
|
109 | + } else { |
|
110 | + $model_objects = $relation_obj->get_other_model()->get_all(); |
|
111 | + } |
|
112 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
113 | + break; |
|
114 | + default: |
|
115 | + } |
|
116 | + if ($input) { |
|
117 | + $inputs[ $relation_name ] = $input; |
|
118 | + } |
|
119 | + } |
|
120 | + return $inputs; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Changes model fields into form section inputs |
|
127 | + * |
|
128 | + * @param EE_Model_Field_Base[] $model_fields keys are the model's name |
|
129 | + * @throws EE_Error |
|
130 | + * @return EE_Form_Input_Base[] |
|
131 | + */ |
|
132 | + protected function _convert_model_fields_to_inputs($model_fields = array()) |
|
133 | + { |
|
134 | + $inputs = array(); |
|
135 | + foreach ($model_fields as $field_name => $model_field) { |
|
136 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
137 | + $input_constructor_args = array( |
|
138 | + array( |
|
139 | + 'required' => ! $model_field->is_nullable() |
|
140 | + && $model_field->get_default_value() |
|
141 | + === null, |
|
142 | + 'html_label_text' => $model_field->get_nicename(), |
|
143 | + 'default' => $model_field->get_default_value(), |
|
144 | + ), |
|
145 | + ); |
|
146 | + switch (get_class($model_field)) { |
|
147 | + case 'EE_All_Caps_Text_Field': |
|
148 | + case 'EE_Any_Foreign_Model_Name_Field': |
|
149 | + $input_class = 'EE_Text_Input'; |
|
150 | + break; |
|
151 | + case 'EE_Boolean_Field': |
|
152 | + $input_class = 'EE_Yes_No_Input'; |
|
153 | + break; |
|
154 | + case 'EE_Datetime_Field': |
|
155 | + throw new EE_Error(sprintf(esc_html__( |
|
156 | + "Model field '%s' does not yet have a known conversion to form input", |
|
157 | + "event_espresso" |
|
158 | + ), get_class($model_field))); |
|
159 | + break; |
|
160 | + case 'EE_Email_Field': |
|
161 | + $input_class = 'EE_Email_Input'; |
|
162 | + break; |
|
163 | + case 'EE_Enum_Integer_Field': |
|
164 | + throw new EE_Error(sprintf(esc_html__( |
|
165 | + "Model field '%s' does not yet have a known conversion to form input", |
|
166 | + "event_espresso" |
|
167 | + ), get_class($model_field))); |
|
168 | + break; |
|
169 | + case 'EE_Enum_Text_Field': |
|
170 | + throw new EE_Error(sprintf(esc_html__( |
|
171 | + "Model field '%s' does not yet have a known conversion to form input", |
|
172 | + "event_espresso" |
|
173 | + ), get_class($model_field))); |
|
174 | + break; |
|
175 | + case 'EE_Float_Field': |
|
176 | + $input_class = 'EE_Float_Input'; |
|
177 | + break; |
|
178 | + case 'EE_Foreign_Key_Int_Field': |
|
179 | + case 'EE_Foreign_Key_String_Field': |
|
180 | + case 'EE_WP_User_Field': |
|
181 | + $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name |
|
182 | + ? $model_field->get_model_class_names_pointed_to() : array(); |
|
183 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
184 | + $input_class = 'EE_Text_Input'; |
|
185 | + } else { |
|
186 | + // so its just one model |
|
187 | + $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
|
188 | + $model = EE_Registry::instance()->load_model($model_name); |
|
189 | + $model_names = $model->get_all_names(array('limit' => 10)); |
|
190 | + if ($model_field->is_nullable()) { |
|
191 | + array_unshift($model_names, esc_html__("Please Select", 'event_espresso')); |
|
192 | + } |
|
193 | + $input_constructor_args[1] = $input_constructor_args[0]; |
|
194 | + $input_constructor_args[0] = $model_names; |
|
195 | + $input_class = 'EE_Select_Input'; |
|
196 | + } |
|
197 | + break; |
|
198 | + case 'EE_Full_HTML_Field': |
|
199 | + $input_class = 'EE_Text_Area_Input'; |
|
200 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
201 | + break; |
|
202 | + case 'EE_Infinite_Integer': |
|
203 | + throw new EE_Error(sprintf(esc_html__( |
|
204 | + "Model field '%s' does not yet have a known conversion to form input", |
|
205 | + "event_espresso" |
|
206 | + ), get_class($model_field))); |
|
207 | + break; |
|
208 | + case 'EE_Integer_Field': |
|
209 | + $input_class = 'EE_Text_Input'; |
|
210 | + break; |
|
211 | + case 'EE_Maybe_Serialized_Text_Field': |
|
212 | + $input_class = 'EE_Text_Area_Input'; |
|
213 | + break; |
|
214 | + case 'EE_Money_Field': |
|
215 | + throw new EE_Error(sprintf(esc_html__( |
|
216 | + "Model field '%s' does not yet have a known conversion to form input", |
|
217 | + "event_espresso" |
|
218 | + ), get_class($model_field))); |
|
219 | + break; |
|
220 | + case 'EE_Post_Content_Field': |
|
221 | + $input_class = 'EE_Text_Area_Input'; |
|
222 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
223 | + break; |
|
224 | + case 'EE_Plain_Text_Field': |
|
225 | + $input_class = 'EE_Text_Input'; |
|
226 | + break; |
|
227 | + case 'EE_Primary_Key_Int_Field': |
|
228 | + $input_class = 'EE_Hidden_Input'; |
|
229 | + $input_constructor_args[0]['normalization_strategy'] = new EE_Int_Normalization(); |
|
230 | + break; |
|
231 | + case 'EE_Primary_Key_String_Field': |
|
232 | + $input_class = 'EE_Hidden_Input'; |
|
233 | + break; |
|
234 | + case 'EE_Serialized_Text_Field': |
|
235 | + $input_class = 'EE_Text_Area_Input'; |
|
236 | + break; |
|
237 | + case 'EE_Simple_HTML_Field': |
|
238 | + $input_class = 'EE_Text_Area_Input'; |
|
239 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
240 | + break; |
|
241 | + case 'EE_Slug_Field': |
|
242 | + $input_class = 'EE_Text_Input'; |
|
243 | + break; |
|
244 | + case 'EE_Trashed_Flag_Field': |
|
245 | + $input_class = 'EE_Yes_No_Input'; |
|
246 | + break; |
|
247 | + case 'EE_WP_Post_Status_Field': |
|
248 | + throw new EE_Error(sprintf(esc_html__( |
|
249 | + "Model field '%s' does not yet have a known conversion to form input", |
|
250 | + "event_espresso" |
|
251 | + ), get_class($model_field))); |
|
252 | + break; |
|
253 | + case 'EE_WP_Post_Type_Field': |
|
254 | + throw new EE_Error(sprintf(esc_html__( |
|
255 | + "Model field '%s' does not yet have a known conversion to form input", |
|
256 | + "event_espresso" |
|
257 | + ), get_class($model_field))); |
|
258 | + break; |
|
259 | + default: |
|
260 | + throw new EE_Error(sprintf(esc_html__( |
|
261 | + "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", |
|
262 | + "event_espresso" |
|
263 | + ), get_class($model_field))); |
|
264 | + } |
|
265 | + $reflection = new ReflectionClass($input_class); |
|
266 | + $input = $reflection->newInstanceArgs($input_constructor_args); |
|
267 | + $inputs[ $field_name ] = $input; |
|
268 | + } |
|
269 | + } |
|
270 | + return $inputs; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Mostly the same as populate_defaults , except takes a model object as input, not an array, |
|
277 | + * and also sets the form's _model_object |
|
278 | + * |
|
279 | + * @param EE_Base_Class $model_obj |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public function populate_model_obj($model_obj) |
|
283 | + { |
|
284 | + $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
285 | + $this->_model_object = $model_obj; |
|
286 | + $defaults = $model_obj->model_field_array(); |
|
287 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
288 | + $subsection = $this->get_subsection($relation_name, false); |
|
289 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
290 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
291 | + // then we only expect there to be one |
|
292 | + $related_item = $this->_model_object->get_first_related($relation_name); |
|
293 | + $defaults[ $relation_name ] = $related_item->ID(); |
|
294 | + } else { |
|
295 | + $related_items = $this->_model_object->get_many_related($relation_name); |
|
296 | + $ids = array(); |
|
297 | + foreach ($related_items as $related_item) { |
|
298 | + $ids[] = $related_item->ID(); |
|
299 | + } |
|
300 | + $defaults[ $relation_name ] = $ids; |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + $defaults = apply_filters( |
|
305 | + 'FHEE__EE_Model_Form_Section__populate_model_obj', |
|
306 | + $defaults, |
|
307 | + $this |
|
308 | + ); |
|
309 | + $this->populate_defaults($defaults); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Gets all the input values that correspond to model fields. Keys are the input/field names, |
|
316 | + * values are their normalized values |
|
317 | + * |
|
318 | + * @return array |
|
319 | + */ |
|
320 | + public function inputs_values_corresponding_to_model_fields() |
|
321 | + { |
|
322 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * After we've normalized the data as normal, set the corresponding model object |
|
329 | + * on the form. |
|
330 | + * |
|
331 | + * @param array $req_data should usually be the form post/request data (the default). |
|
332 | + * @return void |
|
333 | + */ |
|
334 | + public function _normalize($req_data) |
|
335 | + { |
|
336 | + parent::_normalize($req_data); |
|
337 | + // create or set the model object, if it isn't already |
|
338 | + if (! $this->_model_object) { |
|
339 | + // check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
|
340 | + $pk_name = $this->_model->primary_key_name(); |
|
341 | + $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
|
342 | + if ($model_obj) { |
|
343 | + $this->_model_object = $model_obj; |
|
344 | + } else { |
|
345 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
346 | + } |
|
347 | + } |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * After this form has been initialized and is verified to be valid, |
|
354 | + * either creates a model object from its data and saves it, or updates |
|
355 | + * the model object its data represents |
|
356 | + * |
|
357 | + * @throws EE_Error |
|
358 | + * @return int, 1 on a successful update, the ID of |
|
359 | + * the new entry on insert; 0 on failure |
|
360 | + */ |
|
361 | + public function save() |
|
362 | + { |
|
363 | + if (! $this->_model_object) { |
|
364 | + throw new EE_Error(sprintf(esc_html__( |
|
365 | + "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", |
|
366 | + "event_espresso" |
|
367 | + ), get_class($this->_model))); |
|
368 | + } |
|
369 | + // ok so the model object is set. Just set it with the submitted form data |
|
370 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) { |
|
371 | + // only set the non-primary key |
|
372 | + if ($field_name != $this->_model->primary_key_name()) { |
|
373 | + $this->_model_object->set($field_name, $field_value); |
|
374 | + } |
|
375 | + } |
|
376 | + $success = $this->_model_object->save(); |
|
377 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
378 | + if (isset($this->_subsections[ $relation_name ])) { |
|
379 | + $success = $this->_save_related_info($relation_name); |
|
380 | + } |
|
381 | + } |
|
382 | + do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success); |
|
383 | + return $success; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Automatically finds the related model info from the form, if present, and |
|
390 | + * save the relations indicated |
|
391 | + * |
|
392 | + * @type string $relation_name |
|
393 | + * @return bool |
|
394 | + * @throws EE_Error |
|
395 | + */ |
|
396 | + protected function _save_related_info($relation_name) |
|
397 | + { |
|
398 | + $relation_obj = $this->_model->related_settings_for($relation_name); |
|
399 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
400 | + // there is just a foreign key on this model pointing to that one |
|
401 | + $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
|
402 | + } elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
403 | + // then we want to consider all of its currently-related things. |
|
404 | + // if they're in this list, keep them |
|
405 | + // if they're not in this list, remove them |
|
406 | + // and lastly add all the new items |
|
407 | + throw new EE_Error(sprintf(esc_html__( |
|
408 | + 'Automatic saving of related info across a "has many" relation is not yet supported', |
|
409 | + "event_espresso" |
|
410 | + ))); |
|
411 | + } elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
412 | + // delete everything NOT in this list |
|
413 | + $normalized_input_value = $this->get_input_value($relation_name); |
|
414 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
415 | + $where_query_params = array( |
|
416 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value), |
|
417 | + ); |
|
418 | + } else { |
|
419 | + $where_query_params = array(); |
|
420 | + } |
|
421 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
422 | + foreach ($normalized_input_value as $id) { |
|
423 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
424 | + } |
|
425 | + } |
|
426 | + return true; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Gets the model of this model form |
|
433 | + * |
|
434 | + * @return EEM_Base |
|
435 | + */ |
|
436 | + public function get_model() |
|
437 | + { |
|
438 | + return $this->_model; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * Gets the model object for this model form, which was either set |
|
445 | + * upon construction (using the $options_array arg 'model_object'), by using |
|
446 | + * set_model_object($model_obj), or implicitly |
|
447 | + * when receive_form_submission($req_data) was called. |
|
448 | + * |
|
449 | + * @return EE_Base_Class |
|
450 | + */ |
|
451 | + public function get_model_object() |
|
452 | + { |
|
453 | + return $this->_model_object; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * gets teh default name of this form section if none is specified |
|
460 | + * |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + protected function _set_default_name_if_empty() |
|
464 | + { |
|
465 | + if (! $this->_name) { |
|
466 | + $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
467 | + $this->_name = $default_name; |
|
468 | + } |
|
469 | + } |
|
470 | 470 | } |
@@ -2,62 +2,62 @@ |
||
2 | 2 | |
3 | 3 | class EE_Sample_Form extends EE_Form_Section_Proper |
4 | 4 | { |
5 | - public function __construct() |
|
6 | - { |
|
7 | - $this->_subsections = array( |
|
8 | - 'h1' => new EE_Form_Section_HTML('hello wordl'), |
|
9 | - 'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')), |
|
10 | - 'email' => new EE_Email_Input(array('required' => false)), |
|
11 | - 'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' => esc_html__("Small", "event_espresso"),'m' => esc_html__("Medium", "event_espresso"),'l' => esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')), |
|
12 | - 'month_normal' => new EE_Month_Input(), |
|
13 | - 'month_leading_zero' => new EE_Month_Input(true), |
|
14 | - 'year_2' => new EE_Year_Input(false, 1, 1), |
|
15 | - 'year_4' => new EE_Year_Input(true, 0, 10, array('default' => '2017')), |
|
16 | - 'yes_no' => new EE_Yes_No_Input(array('html_label_text' => esc_html__("Yes or No", "event_espresso"))), |
|
17 | - 'credit_card' => new EE_Credit_Card_Input(), |
|
18 | - 'image_1' => new EE_Admin_File_Uploader_Input(), |
|
19 | - 'image_2' => new EE_Admin_File_Uploader_Input(), |
|
20 | - 'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))), |
|
21 | - 'float' => new EE_Float_Input(), |
|
22 | - 'essay' => new EE_Text_Area_Input(), |
|
23 | - 'amenities' => new EE_Select_Multiple_Input( |
|
24 | - array( |
|
25 | - 'hottub' => 'Hot Tub', |
|
26 | - 'balcony' => "Balcony", |
|
27 | - 'skylight' => 'SkyLight', |
|
28 | - 'no_axe' => 'No Axe Murderers' |
|
29 | - ), |
|
30 | - array( |
|
31 | - 'default' => array( |
|
32 | - 'hottub', |
|
33 | - 'no_axe' ), |
|
34 | - ) |
|
35 | - ), |
|
36 | - 'payment_methods' => new EE_Select_Multi_Model_Input(EEM_Payment_Method::instance()->get_all()), |
|
37 | - ); |
|
38 | - $this->_layout_strategy = new EE_Div_Per_Section_Layout(); |
|
39 | - parent::__construct(); |
|
40 | - } |
|
5 | + public function __construct() |
|
6 | + { |
|
7 | + $this->_subsections = array( |
|
8 | + 'h1' => new EE_Form_Section_HTML('hello wordl'), |
|
9 | + 'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')), |
|
10 | + 'email' => new EE_Email_Input(array('required' => false)), |
|
11 | + 'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' => esc_html__("Small", "event_espresso"),'m' => esc_html__("Medium", "event_espresso"),'l' => esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')), |
|
12 | + 'month_normal' => new EE_Month_Input(), |
|
13 | + 'month_leading_zero' => new EE_Month_Input(true), |
|
14 | + 'year_2' => new EE_Year_Input(false, 1, 1), |
|
15 | + 'year_4' => new EE_Year_Input(true, 0, 10, array('default' => '2017')), |
|
16 | + 'yes_no' => new EE_Yes_No_Input(array('html_label_text' => esc_html__("Yes or No", "event_espresso"))), |
|
17 | + 'credit_card' => new EE_Credit_Card_Input(), |
|
18 | + 'image_1' => new EE_Admin_File_Uploader_Input(), |
|
19 | + 'image_2' => new EE_Admin_File_Uploader_Input(), |
|
20 | + 'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))), |
|
21 | + 'float' => new EE_Float_Input(), |
|
22 | + 'essay' => new EE_Text_Area_Input(), |
|
23 | + 'amenities' => new EE_Select_Multiple_Input( |
|
24 | + array( |
|
25 | + 'hottub' => 'Hot Tub', |
|
26 | + 'balcony' => "Balcony", |
|
27 | + 'skylight' => 'SkyLight', |
|
28 | + 'no_axe' => 'No Axe Murderers' |
|
29 | + ), |
|
30 | + array( |
|
31 | + 'default' => array( |
|
32 | + 'hottub', |
|
33 | + 'no_axe' ), |
|
34 | + ) |
|
35 | + ), |
|
36 | + 'payment_methods' => new EE_Select_Multi_Model_Input(EEM_Payment_Method::instance()->get_all()), |
|
37 | + ); |
|
38 | + $this->_layout_strategy = new EE_Div_Per_Section_Layout(); |
|
39 | + parent::__construct(); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Extra validation for the 'name' input. |
|
44 | - * @param EE_Text_Input $form_input |
|
45 | - */ |
|
46 | - public function _validate_name($form_input) |
|
47 | - { |
|
48 | - if ($form_input->raw_value() != 'Mike') { |
|
49 | - $form_input->add_validation_error(esc_html__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike'); |
|
50 | - } |
|
51 | - } |
|
42 | + /** |
|
43 | + * Extra validation for the 'name' input. |
|
44 | + * @param EE_Text_Input $form_input |
|
45 | + */ |
|
46 | + public function _validate_name($form_input) |
|
47 | + { |
|
48 | + if ($form_input->raw_value() != 'Mike') { |
|
49 | + $form_input->add_validation_error(esc_html__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike'); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - public function _validate() |
|
54 | - { |
|
55 | - parent::_validate(); |
|
56 | - if ( |
|
57 | - $this->_subsections['shirt_size']->normalized_value() == 's' |
|
58 | - && $this->_subsections['year_4']->normalized_value() < 2010 |
|
59 | - ) { |
|
60 | - $this->add_validation_error(esc_html__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old'); |
|
61 | - } |
|
62 | - } |
|
53 | + public function _validate() |
|
54 | + { |
|
55 | + parent::_validate(); |
|
56 | + if ( |
|
57 | + $this->_subsections['shirt_size']->normalized_value() == 's' |
|
58 | + && $this->_subsections['year_4']->normalized_value() < 2010 |
|
59 | + ) { |
|
60 | + $this->add_validation_error(esc_html__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old'); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
@@ -6,9 +6,9 @@ discard block |
||
6 | 6 | { |
7 | 7 | $this->_subsections = array( |
8 | 8 | 'h1' => new EE_Form_Section_HTML('hello wordl'), |
9 | - 'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')), |
|
9 | + 'name' => new EE_Text_Input(array('required' => true, 'default' => 'your name here')), |
|
10 | 10 | 'email' => new EE_Email_Input(array('required' => false)), |
11 | - 'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' => esc_html__("Small", "event_espresso"),'m' => esc_html__("Medium", "event_espresso"),'l' => esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')), |
|
11 | + 'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' => esc_html__("Small", "event_espresso"), 'm' => esc_html__("Medium", "event_espresso"), 'l' => esc_html__("Large", "event_espresso")), array('required' => true, 'default' => 's')), |
|
12 | 12 | 'month_normal' => new EE_Month_Input(), |
13 | 13 | 'month_leading_zero' => new EE_Month_Input(true), |
14 | 14 | 'year_2' => new EE_Year_Input(false, 1, 1), |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | 'credit_card' => new EE_Credit_Card_Input(), |
18 | 18 | 'image_1' => new EE_Admin_File_Uploader_Input(), |
19 | 19 | 'image_2' => new EE_Admin_File_Uploader_Input(), |
20 | - 'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))), |
|
20 | + 'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP', 'mysql' => 'MYSQL'), array('default' => array('php'))), |
|
21 | 21 | 'float' => new EE_Float_Input(), |
22 | 22 | 'essay' => new EE_Text_Area_Input(), |
23 | 23 | 'amenities' => new EE_Select_Multiple_Input( |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | { |
24 | 24 | $options_array['subsections'] = array_merge( |
25 | 25 | array( |
26 | - 'first_name' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )), |
|
27 | - 'last_name' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )), |
|
28 | - 'email' => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )), |
|
29 | - 'address' => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
30 | - 'address2' => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
31 | - 'city' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )), |
|
32 | - 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))), |
|
33 | - 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))), |
|
34 | - 'zip' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )), |
|
35 | - 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )), |
|
26 | + 'first_name' => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso'))), |
|
27 | + 'last_name' => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso'))), |
|
28 | + 'email' => new EE_Email_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso'))), |
|
29 | + 'address' => new EE_Text_Input(array('html_label_text' => esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address')), |
|
30 | + 'address2' => new EE_Text_Input(array('html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2')), |
|
31 | + 'city' => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso'))), |
|
32 | + 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso')))), |
|
33 | + 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso')))), |
|
34 | + 'zip' => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso'))), |
|
35 | + 'phone' => new EE_Text_Input(array('html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso'))), |
|
36 | 36 | ), |
37 | 37 | isset($options_array['subsections']) ? $options_array['subsections'] : array() |
38 | 38 | ); |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
81 | 81 | { |
82 | 82 | // If the state input was removed, just return a blank string. |
83 | - if (! $this->has_subsection('state')) { |
|
83 | + if ( ! $this->has_subsection('state')) { |
|
84 | 84 | return ''; |
85 | 85 | } |
86 | - $state_input = $this->get_input('state', false); |
|
86 | + $state_input = $this->get_input('state', false); |
|
87 | 87 | if ($state_input instanceof EE_State_Select_Input) { |
88 | - $state_field_to_use = $state_input->valueFieldName(); |
|
88 | + $state_field_to_use = $state_input->valueFieldName(); |
|
89 | 89 | } else { |
90 | 90 | $state_field_to_use = 'STA_ID'; |
91 | 91 | } |
@@ -115,43 +115,43 @@ discard block |
||
115 | 115 | // grab billing form data |
116 | 116 | $data = $this->valid_data(); |
117 | 117 | // copy first_name |
118 | - if (! empty($data['first_name'])) { |
|
118 | + if ( ! empty($data['first_name'])) { |
|
119 | 119 | $attendee->set_fname($data['first_name']); |
120 | 120 | } |
121 | 121 | // copy last_name |
122 | - if (! empty($data['last_name'])) { |
|
122 | + if ( ! empty($data['last_name'])) { |
|
123 | 123 | $attendee->set_lname($data['last_name']); |
124 | 124 | } |
125 | 125 | // copy email |
126 | - if (! empty($data['email'])) { |
|
126 | + if ( ! empty($data['email'])) { |
|
127 | 127 | $attendee->set_email($data['email']); |
128 | 128 | } |
129 | 129 | // copy address |
130 | - if (! empty($data['address'])) { |
|
130 | + if ( ! empty($data['address'])) { |
|
131 | 131 | $attendee->set_address($data['address']); |
132 | 132 | } |
133 | 133 | // copy address2 |
134 | - if (! empty($data['address2'])) { |
|
134 | + if ( ! empty($data['address2'])) { |
|
135 | 135 | $attendee->set_address2($data['address2']); |
136 | 136 | } |
137 | 137 | // copy city |
138 | - if (! empty($data['city'])) { |
|
138 | + if ( ! empty($data['city'])) { |
|
139 | 139 | $attendee->set_city($data['city']); |
140 | 140 | } |
141 | 141 | // copy state |
142 | - if (! empty($data['state'])) { |
|
142 | + if ( ! empty($data['state'])) { |
|
143 | 143 | $attendee->set_state($data['state']); |
144 | 144 | } |
145 | 145 | // copy country |
146 | - if (! empty($data['country'])) { |
|
146 | + if ( ! empty($data['country'])) { |
|
147 | 147 | $attendee->set_country($data['country']); |
148 | 148 | } |
149 | 149 | // copy zip |
150 | - if (! empty($data['zip'])) { |
|
150 | + if ( ! empty($data['zip'])) { |
|
151 | 151 | $attendee->set_zip($data['zip']); |
152 | 152 | } |
153 | 153 | // copy phone |
154 | - if (! empty($data['phone'])) { |
|
154 | + if ( ! empty($data['phone'])) { |
|
155 | 155 | $attendee->set_phone($data['phone']); |
156 | 156 | } |
157 | 157 | return $attendee; |
@@ -13,172 +13,172 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Billing_Attendee_Info_Form extends EE_Billing_Info_Form |
15 | 15 | { |
16 | - /** |
|
17 | - * |
|
18 | - * @param EE_Payment_Method $payment_method |
|
19 | - * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
20 | - */ |
|
21 | - public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
22 | - { |
|
23 | - $options_array['subsections'] = array_merge( |
|
24 | - array( |
|
25 | - 'first_name' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )), |
|
26 | - 'last_name' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )), |
|
27 | - 'email' => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )), |
|
28 | - 'address' => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
29 | - 'address2' => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
30 | - 'city' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )), |
|
31 | - 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))), |
|
32 | - 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))), |
|
33 | - 'zip' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )), |
|
34 | - 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )), |
|
35 | - ), |
|
36 | - isset($options_array['subsections']) ? $options_array['subsections'] : array() |
|
37 | - ); |
|
16 | + /** |
|
17 | + * |
|
18 | + * @param EE_Payment_Method $payment_method |
|
19 | + * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
20 | + */ |
|
21 | + public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
22 | + { |
|
23 | + $options_array['subsections'] = array_merge( |
|
24 | + array( |
|
25 | + 'first_name' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )), |
|
26 | + 'last_name' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )), |
|
27 | + 'email' => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )), |
|
28 | + 'address' => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
29 | + 'address2' => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
30 | + 'city' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )), |
|
31 | + 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))), |
|
32 | + 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))), |
|
33 | + 'zip' => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )), |
|
34 | + 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )), |
|
35 | + ), |
|
36 | + isset($options_array['subsections']) ? $options_array['subsections'] : array() |
|
37 | + ); |
|
38 | 38 | |
39 | - parent::__construct($payment_method, $options_array); |
|
40 | - } |
|
39 | + parent::__construct($payment_method, $options_array); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Sets the defaults for the billing form according to the attendee's details |
|
44 | - * @param EE_Attendee $attendee |
|
45 | - */ |
|
46 | - public function populate_from_attendee($attendee) |
|
47 | - { |
|
48 | - $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee); |
|
42 | + /** |
|
43 | + * Sets the defaults for the billing form according to the attendee's details |
|
44 | + * @param EE_Attendee $attendee |
|
45 | + */ |
|
46 | + public function populate_from_attendee($attendee) |
|
47 | + { |
|
48 | + $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee); |
|
49 | 49 | |
50 | - /** @var $attendee EE_Attendee */ |
|
51 | - $this->populate_defaults( |
|
52 | - apply_filters( |
|
53 | - 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', |
|
54 | - array( |
|
55 | - 'first_name' => $attendee->fname(), |
|
56 | - 'last_name' => $attendee->lname(), |
|
57 | - 'email' => $attendee->email(), |
|
58 | - 'address' => $attendee->address(), |
|
59 | - 'address2' => $attendee->address2(), |
|
60 | - 'city' => $attendee->city(), |
|
61 | - 'state' => $this->getAttendeeStateValueForForm($attendee), |
|
62 | - 'country' => $attendee->country_ID(), |
|
63 | - 'zip' => $attendee->zip(), |
|
64 | - 'phone' => $attendee->phone(), |
|
65 | - ), |
|
66 | - $attendee, |
|
67 | - $this |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
50 | + /** @var $attendee EE_Attendee */ |
|
51 | + $this->populate_defaults( |
|
52 | + apply_filters( |
|
53 | + 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', |
|
54 | + array( |
|
55 | + 'first_name' => $attendee->fname(), |
|
56 | + 'last_name' => $attendee->lname(), |
|
57 | + 'email' => $attendee->email(), |
|
58 | + 'address' => $attendee->address(), |
|
59 | + 'address2' => $attendee->address2(), |
|
60 | + 'city' => $attendee->city(), |
|
61 | + 'state' => $this->getAttendeeStateValueForForm($attendee), |
|
62 | + 'country' => $attendee->country_ID(), |
|
63 | + 'zip' => $attendee->zip(), |
|
64 | + 'phone' => $attendee->phone(), |
|
65 | + ), |
|
66 | + $attendee, |
|
67 | + $this |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Gets the default value to use for the billing form's state value. |
|
74 | - * @since 4.10.0.p |
|
75 | - * @param EE_Attendee $attendee |
|
76 | - * @return string |
|
77 | - * @throws EE_Error2 |
|
78 | - */ |
|
79 | - protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
|
80 | - { |
|
81 | - // If the state input was removed, just return a blank string. |
|
82 | - if (! $this->has_subsection('state')) { |
|
83 | - return ''; |
|
84 | - } |
|
85 | - $state_input = $this->get_input('state', false); |
|
86 | - if ($state_input instanceof EE_State_Select_Input) { |
|
87 | - $state_field_to_use = $state_input->valueFieldName(); |
|
88 | - } else { |
|
89 | - $state_field_to_use = 'STA_ID'; |
|
90 | - } |
|
91 | - switch ($state_field_to_use) { |
|
92 | - case 'STA_abbrev': |
|
93 | - $state_value = $attendee->state_abbrev(); |
|
94 | - break; |
|
95 | - case 'STA_name': |
|
96 | - $state_value = $attendee->state_name(); |
|
97 | - break; |
|
98 | - default: |
|
99 | - $state_value = $attendee->state_ID(); |
|
100 | - } |
|
101 | - return $state_value; |
|
102 | - } |
|
72 | + /** |
|
73 | + * Gets the default value to use for the billing form's state value. |
|
74 | + * @since 4.10.0.p |
|
75 | + * @param EE_Attendee $attendee |
|
76 | + * @return string |
|
77 | + * @throws EE_Error2 |
|
78 | + */ |
|
79 | + protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
|
80 | + { |
|
81 | + // If the state input was removed, just return a blank string. |
|
82 | + if (! $this->has_subsection('state')) { |
|
83 | + return ''; |
|
84 | + } |
|
85 | + $state_input = $this->get_input('state', false); |
|
86 | + if ($state_input instanceof EE_State_Select_Input) { |
|
87 | + $state_field_to_use = $state_input->valueFieldName(); |
|
88 | + } else { |
|
89 | + $state_field_to_use = 'STA_ID'; |
|
90 | + } |
|
91 | + switch ($state_field_to_use) { |
|
92 | + case 'STA_abbrev': |
|
93 | + $state_value = $attendee->state_abbrev(); |
|
94 | + break; |
|
95 | + case 'STA_name': |
|
96 | + $state_value = $attendee->state_name(); |
|
97 | + break; |
|
98 | + default: |
|
99 | + $state_value = $attendee->state_ID(); |
|
100 | + } |
|
101 | + return $state_value; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * copy_billing_form_data_to_attendee |
|
108 | - * copies info from the billing form to the attendee's details |
|
109 | - * @param \EE_Attendee $attendee - the attendee object to copy details to |
|
110 | - * @return \EE_Attendee |
|
111 | - */ |
|
112 | - public function copy_billing_form_data_to_attendee(EE_Attendee $attendee) |
|
113 | - { |
|
114 | - // grab billing form data |
|
115 | - $data = $this->valid_data(); |
|
116 | - // copy first_name |
|
117 | - if (! empty($data['first_name'])) { |
|
118 | - $attendee->set_fname($data['first_name']); |
|
119 | - } |
|
120 | - // copy last_name |
|
121 | - if (! empty($data['last_name'])) { |
|
122 | - $attendee->set_lname($data['last_name']); |
|
123 | - } |
|
124 | - // copy email |
|
125 | - if (! empty($data['email'])) { |
|
126 | - $attendee->set_email($data['email']); |
|
127 | - } |
|
128 | - // copy address |
|
129 | - if (! empty($data['address'])) { |
|
130 | - $attendee->set_address($data['address']); |
|
131 | - } |
|
132 | - // copy address2 |
|
133 | - if (! empty($data['address2'])) { |
|
134 | - $attendee->set_address2($data['address2']); |
|
135 | - } |
|
136 | - // copy city |
|
137 | - if (! empty($data['city'])) { |
|
138 | - $attendee->set_city($data['city']); |
|
139 | - } |
|
140 | - // copy state |
|
141 | - if (! empty($data['state'])) { |
|
142 | - $attendee->set_state($data['state']); |
|
143 | - } |
|
144 | - // copy country |
|
145 | - if (! empty($data['country'])) { |
|
146 | - $attendee->set_country($data['country']); |
|
147 | - } |
|
148 | - // copy zip |
|
149 | - if (! empty($data['zip'])) { |
|
150 | - $attendee->set_zip($data['zip']); |
|
151 | - } |
|
152 | - // copy phone |
|
153 | - if (! empty($data['phone'])) { |
|
154 | - $attendee->set_phone($data['phone']); |
|
155 | - } |
|
156 | - return $attendee; |
|
157 | - } |
|
106 | + /** |
|
107 | + * copy_billing_form_data_to_attendee |
|
108 | + * copies info from the billing form to the attendee's details |
|
109 | + * @param \EE_Attendee $attendee - the attendee object to copy details to |
|
110 | + * @return \EE_Attendee |
|
111 | + */ |
|
112 | + public function copy_billing_form_data_to_attendee(EE_Attendee $attendee) |
|
113 | + { |
|
114 | + // grab billing form data |
|
115 | + $data = $this->valid_data(); |
|
116 | + // copy first_name |
|
117 | + if (! empty($data['first_name'])) { |
|
118 | + $attendee->set_fname($data['first_name']); |
|
119 | + } |
|
120 | + // copy last_name |
|
121 | + if (! empty($data['last_name'])) { |
|
122 | + $attendee->set_lname($data['last_name']); |
|
123 | + } |
|
124 | + // copy email |
|
125 | + if (! empty($data['email'])) { |
|
126 | + $attendee->set_email($data['email']); |
|
127 | + } |
|
128 | + // copy address |
|
129 | + if (! empty($data['address'])) { |
|
130 | + $attendee->set_address($data['address']); |
|
131 | + } |
|
132 | + // copy address2 |
|
133 | + if (! empty($data['address2'])) { |
|
134 | + $attendee->set_address2($data['address2']); |
|
135 | + } |
|
136 | + // copy city |
|
137 | + if (! empty($data['city'])) { |
|
138 | + $attendee->set_city($data['city']); |
|
139 | + } |
|
140 | + // copy state |
|
141 | + if (! empty($data['state'])) { |
|
142 | + $attendee->set_state($data['state']); |
|
143 | + } |
|
144 | + // copy country |
|
145 | + if (! empty($data['country'])) { |
|
146 | + $attendee->set_country($data['country']); |
|
147 | + } |
|
148 | + // copy zip |
|
149 | + if (! empty($data['zip'])) { |
|
150 | + $attendee->set_zip($data['zip']); |
|
151 | + } |
|
152 | + // copy phone |
|
153 | + if (! empty($data['phone'])) { |
|
154 | + $attendee->set_phone($data['phone']); |
|
155 | + } |
|
156 | + return $attendee; |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * create_attendee_from_billing_form_data |
|
162 | - * uses info from the billing form to create a new attendee |
|
163 | - * @return \EE_Attendee |
|
164 | - */ |
|
165 | - public function create_attendee_from_billing_form_data() |
|
166 | - { |
|
167 | - // grab billing form data |
|
168 | - $data = $this->valid_data(); |
|
169 | - return EE_Attendee::new_instance(array( |
|
170 | - 'ATT_fname' => ! empty($data['first_name']) ? $data['first_name'] : '', |
|
171 | - 'ATT_lname' => ! empty($data['last_name']) ? $data['last_name'] : '', |
|
172 | - 'ATT_email' => ! empty($data['email']) ? $data['email'] : '', |
|
173 | - 'ATT_address' => ! empty($data['address']) ? $data['address'] : '', |
|
174 | - 'ATT_address2' => ! empty($data['address2']) ? $data['address2'] : '', |
|
175 | - 'ATT_city' => ! empty($data['city']) ? $data['city'] : '', |
|
176 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : '', |
|
177 | - 'CNT_ISO' => ! empty($data['country']) ? $data['country'] : '', |
|
178 | - 'ATT_zip' => ! empty($data['zip']) ? $data['zip'] : '', |
|
179 | - 'ATT_phone' => ! empty($data['phone']) ? $data['phone'] : '', |
|
180 | - )); |
|
181 | - } |
|
160 | + /** |
|
161 | + * create_attendee_from_billing_form_data |
|
162 | + * uses info from the billing form to create a new attendee |
|
163 | + * @return \EE_Attendee |
|
164 | + */ |
|
165 | + public function create_attendee_from_billing_form_data() |
|
166 | + { |
|
167 | + // grab billing form data |
|
168 | + $data = $this->valid_data(); |
|
169 | + return EE_Attendee::new_instance(array( |
|
170 | + 'ATT_fname' => ! empty($data['first_name']) ? $data['first_name'] : '', |
|
171 | + 'ATT_lname' => ! empty($data['last_name']) ? $data['last_name'] : '', |
|
172 | + 'ATT_email' => ! empty($data['email']) ? $data['email'] : '', |
|
173 | + 'ATT_address' => ! empty($data['address']) ? $data['address'] : '', |
|
174 | + 'ATT_address2' => ! empty($data['address2']) ? $data['address2'] : '', |
|
175 | + 'ATT_city' => ! empty($data['city']) ? $data['city'] : '', |
|
176 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : '', |
|
177 | + 'CNT_ISO' => ! empty($data['country']) ? $data['country'] : '', |
|
178 | + 'ATT_zip' => ! empty($data['zip']) ? $data['zip'] : '', |
|
179 | + 'ATT_phone' => ! empty($data['phone']) ? $data['phone'] : '', |
|
180 | + )); |
|
181 | + } |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // End of file EE_Billing_Attendee_Info_Form.form.php |
@@ -104,14 +104,14 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function _construct_finalize($parent_form_section, $name) |
106 | 106 | { |
107 | - if (! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
107 | + if ( ! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
108 | 108 | throw new EE_Error(sprintf(esc_html__( |
109 | 109 | 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', |
110 | 110 | 'event_espresso' |
111 | 111 | ))); |
112 | 112 | } |
113 | 113 | // set the name of this form based on the payment method type |
114 | - if (! $this->_name && ! $name) { |
|
114 | + if ( ! $this->_name && ! $name) { |
|
115 | 115 | $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name())))) |
116 | 116 | . "_Settings_Form"; |
117 | 117 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function set_payment_method_type($payment_method_type) |
128 | 128 | { |
129 | - if (! $payment_method_type instanceof EE_PMT_Base) { |
|
129 | + if ( ! $payment_method_type instanceof EE_PMT_Base) { |
|
130 | 130 | throw new EE_Error(sprintf(esc_html__( |
131 | 131 | "Payment Method forms MUST set a payment method type by using _set_payment_method_type", |
132 | 132 | "event_espresso" |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | parent::populate_model_obj($model_obj); |
167 | 167 | $extra_meta = $model_obj->all_extra_meta_array(); |
168 | 168 | foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
169 | - if (isset($extra_meta[ $input_name ])) { |
|
170 | - $extra_meta_input->set_default($extra_meta[ $input_name ]); |
|
169 | + if (isset($extra_meta[$input_name])) { |
|
170 | + $extra_meta_input->set_default($extra_meta[$input_name]); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function _set_default_name_if_empty() |
183 | 183 | { |
184 | - if (! $this->_name) { |
|
185 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
184 | + if ( ! $this->_name) { |
|
185 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
186 | 186 | $this->_name = $default_name; |
187 | 187 | } |
188 | 188 | } |
@@ -6,195 +6,195 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Payment_Method_Form extends EE_Model_Form_Section |
8 | 8 | { |
9 | - /** |
|
10 | - * All the subsection inputs that correspond ot extra meta rows |
|
11 | - * for this payment method |
|
12 | - * |
|
13 | - * @var EE_Form_Input_Base[] |
|
14 | - */ |
|
15 | - protected $_extra_meta_inputs = array(); |
|
16 | - |
|
17 | - /** |
|
18 | - * Because payment method form might DELAY part of construction, we want to remember |
|
19 | - * what options were passed in |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $_options_array = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * The payment method type for this form |
|
27 | - * |
|
28 | - * @var EE_PMT_Base |
|
29 | - */ |
|
30 | - protected $_payment_method_type; |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param array $options_array { |
|
36 | - * @type string $extra_meta_inputs should be EE_Form_Section_Validatable[] which |
|
37 | - * will be _subsections and will be saved as extra meta on the payment |
|
38 | - * method object; |
|
39 | - * @type EE_PMT_Base $payment_method_type the payment method type this form is for |
|
40 | - * @see EE_Model_Form_Section::__construct() for more |
|
41 | - * } |
|
42 | - */ |
|
43 | - public function __construct($options_array = array()) |
|
44 | - { |
|
45 | - $this->_model = EEM_Payment_Method::instance(); |
|
46 | - $this->_options_array = $options_array; |
|
47 | - if (isset($options_array['payment_method_type'])) { |
|
48 | - $this->_payment_method_type = $options_array['payment_method_type']; |
|
49 | - } |
|
50 | - $options_array = $this->_options_array; |
|
51 | - if (isset($options_array['extra_meta_inputs'])) { |
|
52 | - $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']); |
|
53 | - } |
|
54 | - if ($this->_extra_meta_inputs) { |
|
55 | - $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs); |
|
56 | - } |
|
57 | - $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input( |
|
58 | - array('html_label_text' => esc_html__('Button URL', 'event_espresso')) |
|
59 | - ); |
|
60 | - $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input( |
|
61 | - EEM_Payment_Method::instance()->scopes(), |
|
62 | - array( |
|
63 | - 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() |
|
64 | - . EEH_Template::get_help_tab_link('payment_methods_overview'), |
|
65 | - ) |
|
66 | - ); |
|
67 | - // setup the currency options |
|
68 | - $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input( |
|
69 | - EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type), |
|
70 | - array( |
|
71 | - 'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'), |
|
72 | - 'required' => true, |
|
73 | - ) |
|
74 | - ); |
|
75 | - $this->_subsections['PMD_order'] = new EE_Text_Input(array( |
|
76 | - 'html_label_text' => esc_html__('Order', 'event_espresso'), |
|
77 | - 'html_help_text' => esc_html__('Lowest numbers will be shown first', 'event_espresso'), |
|
78 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
79 | - 'validation_strategies' => array( |
|
80 | - new EE_Int_Validation_Strategy(), |
|
81 | - ), |
|
82 | - 'default' => 0, |
|
83 | - )); |
|
84 | - $this->_layout_strategy = new EE_Admin_Two_Column_Layout(); |
|
85 | - parent::__construct($options_array); |
|
86 | - $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null; |
|
87 | - if ($debug_mode instanceof EE_Form_Input_Base) { |
|
88 | - $debug_mode->set_html_help_text(esc_html__( |
|
89 | - 'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.', |
|
90 | - 'event_espresso' |
|
91 | - )); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Finishes construction given the parent form section and this form section's name |
|
99 | - * |
|
100 | - * @param EE_Form_Section_Proper $parent_form_section |
|
101 | - * @param string $name |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - public function _construct_finalize($parent_form_section, $name) |
|
105 | - { |
|
106 | - if (! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
107 | - throw new EE_Error(sprintf(esc_html__( |
|
108 | - 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', |
|
109 | - 'event_espresso' |
|
110 | - ))); |
|
111 | - } |
|
112 | - // set the name of this form based on the payment method type |
|
113 | - if (! $this->_name && ! $name) { |
|
114 | - $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name())))) |
|
115 | - . "_Settings_Form"; |
|
116 | - } |
|
117 | - parent::_construct_finalize($parent_form_section, $name); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param $payment_method_type |
|
124 | - * @throws EE_Error |
|
125 | - */ |
|
126 | - public function set_payment_method_type($payment_method_type) |
|
127 | - { |
|
128 | - if (! $payment_method_type instanceof EE_PMT_Base) { |
|
129 | - throw new EE_Error(sprintf(esc_html__( |
|
130 | - "Payment Method forms MUST set a payment method type by using _set_payment_method_type", |
|
131 | - "event_espresso" |
|
132 | - ))); |
|
133 | - } |
|
134 | - $this->_payment_method_type = $payment_method_type; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * extends the model form section's save method to also save the extra meta field values |
|
141 | - * |
|
142 | - * @return int ID of the payment method inserted, or true on update |
|
143 | - */ |
|
144 | - public function save() |
|
145 | - { |
|
146 | - $parent_save_val = parent::save(); |
|
147 | - if ($this->_model_object && $this->_model_object->ID()) { |
|
148 | - foreach ($this->_extra_meta_inputs as $input_name => $input) { |
|
149 | - $this->_model_object->update_extra_meta($input_name, $input->normalized_value()); |
|
150 | - } |
|
151 | - } |
|
152 | - return $parent_save_val; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Overrides parent's populate_model_obj to also populate the extra meta fields |
|
159 | - * |
|
160 | - * @param EE_Base_Class $model_obj |
|
161 | - */ |
|
162 | - public function populate_model_obj($model_obj) |
|
163 | - { |
|
164 | - $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
165 | - parent::populate_model_obj($model_obj); |
|
166 | - $extra_meta = $model_obj->all_extra_meta_array(); |
|
167 | - foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
|
168 | - if (isset($extra_meta[ $input_name ])) { |
|
169 | - $extra_meta_input->set_default($extra_meta[ $input_name ]); |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * gets the default name of this form section if none is specified |
|
178 | - * |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - protected function _set_default_name_if_empty() |
|
182 | - { |
|
183 | - if (! $this->_name) { |
|
184 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
185 | - $this->_name = $default_name; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Gets all the extra meta inputs in this form |
|
193 | - * |
|
194 | - * @return EE_Form_Input_Base[] |
|
195 | - */ |
|
196 | - public function extra_meta_inputs() |
|
197 | - { |
|
198 | - return $this->_extra_meta_inputs; |
|
199 | - } |
|
9 | + /** |
|
10 | + * All the subsection inputs that correspond ot extra meta rows |
|
11 | + * for this payment method |
|
12 | + * |
|
13 | + * @var EE_Form_Input_Base[] |
|
14 | + */ |
|
15 | + protected $_extra_meta_inputs = array(); |
|
16 | + |
|
17 | + /** |
|
18 | + * Because payment method form might DELAY part of construction, we want to remember |
|
19 | + * what options were passed in |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $_options_array = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * The payment method type for this form |
|
27 | + * |
|
28 | + * @var EE_PMT_Base |
|
29 | + */ |
|
30 | + protected $_payment_method_type; |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param array $options_array { |
|
36 | + * @type string $extra_meta_inputs should be EE_Form_Section_Validatable[] which |
|
37 | + * will be _subsections and will be saved as extra meta on the payment |
|
38 | + * method object; |
|
39 | + * @type EE_PMT_Base $payment_method_type the payment method type this form is for |
|
40 | + * @see EE_Model_Form_Section::__construct() for more |
|
41 | + * } |
|
42 | + */ |
|
43 | + public function __construct($options_array = array()) |
|
44 | + { |
|
45 | + $this->_model = EEM_Payment_Method::instance(); |
|
46 | + $this->_options_array = $options_array; |
|
47 | + if (isset($options_array['payment_method_type'])) { |
|
48 | + $this->_payment_method_type = $options_array['payment_method_type']; |
|
49 | + } |
|
50 | + $options_array = $this->_options_array; |
|
51 | + if (isset($options_array['extra_meta_inputs'])) { |
|
52 | + $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']); |
|
53 | + } |
|
54 | + if ($this->_extra_meta_inputs) { |
|
55 | + $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs); |
|
56 | + } |
|
57 | + $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input( |
|
58 | + array('html_label_text' => esc_html__('Button URL', 'event_espresso')) |
|
59 | + ); |
|
60 | + $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input( |
|
61 | + EEM_Payment_Method::instance()->scopes(), |
|
62 | + array( |
|
63 | + 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() |
|
64 | + . EEH_Template::get_help_tab_link('payment_methods_overview'), |
|
65 | + ) |
|
66 | + ); |
|
67 | + // setup the currency options |
|
68 | + $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input( |
|
69 | + EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type), |
|
70 | + array( |
|
71 | + 'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'), |
|
72 | + 'required' => true, |
|
73 | + ) |
|
74 | + ); |
|
75 | + $this->_subsections['PMD_order'] = new EE_Text_Input(array( |
|
76 | + 'html_label_text' => esc_html__('Order', 'event_espresso'), |
|
77 | + 'html_help_text' => esc_html__('Lowest numbers will be shown first', 'event_espresso'), |
|
78 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
79 | + 'validation_strategies' => array( |
|
80 | + new EE_Int_Validation_Strategy(), |
|
81 | + ), |
|
82 | + 'default' => 0, |
|
83 | + )); |
|
84 | + $this->_layout_strategy = new EE_Admin_Two_Column_Layout(); |
|
85 | + parent::__construct($options_array); |
|
86 | + $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null; |
|
87 | + if ($debug_mode instanceof EE_Form_Input_Base) { |
|
88 | + $debug_mode->set_html_help_text(esc_html__( |
|
89 | + 'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.', |
|
90 | + 'event_espresso' |
|
91 | + )); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Finishes construction given the parent form section and this form section's name |
|
99 | + * |
|
100 | + * @param EE_Form_Section_Proper $parent_form_section |
|
101 | + * @param string $name |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + public function _construct_finalize($parent_form_section, $name) |
|
105 | + { |
|
106 | + if (! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
107 | + throw new EE_Error(sprintf(esc_html__( |
|
108 | + 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', |
|
109 | + 'event_espresso' |
|
110 | + ))); |
|
111 | + } |
|
112 | + // set the name of this form based on the payment method type |
|
113 | + if (! $this->_name && ! $name) { |
|
114 | + $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name())))) |
|
115 | + . "_Settings_Form"; |
|
116 | + } |
|
117 | + parent::_construct_finalize($parent_form_section, $name); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param $payment_method_type |
|
124 | + * @throws EE_Error |
|
125 | + */ |
|
126 | + public function set_payment_method_type($payment_method_type) |
|
127 | + { |
|
128 | + if (! $payment_method_type instanceof EE_PMT_Base) { |
|
129 | + throw new EE_Error(sprintf(esc_html__( |
|
130 | + "Payment Method forms MUST set a payment method type by using _set_payment_method_type", |
|
131 | + "event_espresso" |
|
132 | + ))); |
|
133 | + } |
|
134 | + $this->_payment_method_type = $payment_method_type; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * extends the model form section's save method to also save the extra meta field values |
|
141 | + * |
|
142 | + * @return int ID of the payment method inserted, or true on update |
|
143 | + */ |
|
144 | + public function save() |
|
145 | + { |
|
146 | + $parent_save_val = parent::save(); |
|
147 | + if ($this->_model_object && $this->_model_object->ID()) { |
|
148 | + foreach ($this->_extra_meta_inputs as $input_name => $input) { |
|
149 | + $this->_model_object->update_extra_meta($input_name, $input->normalized_value()); |
|
150 | + } |
|
151 | + } |
|
152 | + return $parent_save_val; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Overrides parent's populate_model_obj to also populate the extra meta fields |
|
159 | + * |
|
160 | + * @param EE_Base_Class $model_obj |
|
161 | + */ |
|
162 | + public function populate_model_obj($model_obj) |
|
163 | + { |
|
164 | + $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
165 | + parent::populate_model_obj($model_obj); |
|
166 | + $extra_meta = $model_obj->all_extra_meta_array(); |
|
167 | + foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
|
168 | + if (isset($extra_meta[ $input_name ])) { |
|
169 | + $extra_meta_input->set_default($extra_meta[ $input_name ]); |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * gets the default name of this form section if none is specified |
|
178 | + * |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + protected function _set_default_name_if_empty() |
|
182 | + { |
|
183 | + if (! $this->_name) { |
|
184 | + $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
185 | + $this->_name = $default_name; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Gets all the extra meta inputs in this form |
|
193 | + * |
|
194 | + * @return EE_Form_Input_Base[] |
|
195 | + */ |
|
196 | + public function extra_meta_inputs() |
|
197 | + { |
|
198 | + return $this->_extra_meta_inputs; |
|
199 | + } |
|
200 | 200 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015'); |
28 | 28 | wp_enqueue_media(); |
29 | 29 | wp_enqueue_script('media-upload'); |
30 | - wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js'); |
|
30 | + wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | wp_enqueue_media(); |
39 | 39 | wp_enqueue_script('media-upload'); |
40 | - wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js'); |
|
40 | + wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js'); |
|
41 | 41 | parent::enqueue_js(); |
42 | 42 | } |
43 | 43 | |
@@ -52,16 +52,16 @@ discard block |
||
52 | 52 | { |
53 | 53 | // the actual input |
54 | 54 | $input = '<input type="text" size="34" '; |
55 | - $input .= 'name="' . $this->_input->html_name() . '" '; |
|
56 | - $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" '; |
|
57 | - $input .= 'value="' . $this->_input->raw_value_in_form() . '" '; |
|
58 | - $input .= $this->_input->other_html_attributes() . '>'; |
|
55 | + $input .= 'name="'.$this->_input->html_name().'" '; |
|
56 | + $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url '.$this->_input->html_class().'" ' : 'class="large-text ee_media_url" '; |
|
57 | + $input .= 'value="'.$this->_input->raw_value_in_form().'" '; |
|
58 | + $input .= $this->_input->other_html_attributes().'>'; |
|
59 | 59 | // image uploader |
60 | - $uploader = EEH_HTML::link('#', '<img src="' . admin_url('images/media-button-image.gif') . '" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload'); |
|
60 | + $uploader = EEH_HTML::link('#', '<img src="'.admin_url('images/media-button-image.gif').'" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload'); |
|
61 | 61 | // only attempt to show the image if it at least exists |
62 | - $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : ''; |
|
62 | + $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2).EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : ''; |
|
63 | 63 | // html string |
64 | - return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area'); |
|
64 | + return EEH_HTML::div($input.EEH_HTML::nbsp().$uploader.$image, '', 'ee_media_uploader_area'); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 |
@@ -11,73 +11,73 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Admin_File_Uploader_Display_Strategy extends EE_Display_Strategy_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Its important this media only get enqueued AFTER init, but before the footer... where the |
|
16 | - * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine, |
|
17 | - * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error |
|
18 | - * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button |
|
19 | - * to select media). |
|
20 | - * Besides that, no special consideration should be required to make the media uploader appear, besides having |
|
21 | - * this input displayed. |
|
22 | - * @deprecated. enqueue_js should be called automatically now |
|
23 | - */ |
|
24 | - public static function enqueue_scripts() |
|
25 | - { |
|
26 | - EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015'); |
|
27 | - wp_enqueue_media(); |
|
28 | - wp_enqueue_script('media-upload'); |
|
29 | - wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js'); |
|
30 | - } |
|
14 | + /** |
|
15 | + * Its important this media only get enqueued AFTER init, but before the footer... where the |
|
16 | + * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine, |
|
17 | + * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error |
|
18 | + * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button |
|
19 | + * to select media). |
|
20 | + * Besides that, no special consideration should be required to make the media uploader appear, besides having |
|
21 | + * this input displayed. |
|
22 | + * @deprecated. enqueue_js should be called automatically now |
|
23 | + */ |
|
24 | + public static function enqueue_scripts() |
|
25 | + { |
|
26 | + EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015'); |
|
27 | + wp_enqueue_media(); |
|
28 | + wp_enqueue_script('media-upload'); |
|
29 | + wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js'); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Enqueues the JS and CSS needed to display this input |
|
34 | - */ |
|
35 | - public function enqueue_js() |
|
36 | - { |
|
37 | - wp_enqueue_media(); |
|
38 | - wp_enqueue_script('media-upload'); |
|
39 | - wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js'); |
|
40 | - parent::enqueue_js(); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Enqueues the JS and CSS needed to display this input |
|
34 | + */ |
|
35 | + public function enqueue_js() |
|
36 | + { |
|
37 | + wp_enqueue_media(); |
|
38 | + wp_enqueue_script('media-upload'); |
|
39 | + wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js'); |
|
40 | + parent::enqueue_js(); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * |
|
47 | - * @return string of html to display the field |
|
48 | - */ |
|
45 | + /** |
|
46 | + * |
|
47 | + * @return string of html to display the field |
|
48 | + */ |
|
49 | 49 | |
50 | - public function display() |
|
51 | - { |
|
52 | - // the actual input |
|
53 | - $input = '<input type="text" size="34" '; |
|
54 | - $input .= 'name="' . $this->_input->html_name() . '" '; |
|
55 | - $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" '; |
|
56 | - $input .= 'value="' . $this->_input->raw_value_in_form() . '" '; |
|
57 | - $input .= $this->_input->other_html_attributes() . '>'; |
|
58 | - // image uploader |
|
59 | - $uploader = EEH_HTML::link('#', '<img src="' . admin_url('images/media-button-image.gif') . '" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload'); |
|
60 | - // only attempt to show the image if it at least exists |
|
61 | - $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : ''; |
|
62 | - // html string |
|
63 | - return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area'); |
|
64 | - } |
|
50 | + public function display() |
|
51 | + { |
|
52 | + // the actual input |
|
53 | + $input = '<input type="text" size="34" '; |
|
54 | + $input .= 'name="' . $this->_input->html_name() . '" '; |
|
55 | + $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" '; |
|
56 | + $input .= 'value="' . $this->_input->raw_value_in_form() . '" '; |
|
57 | + $input .= $this->_input->other_html_attributes() . '>'; |
|
58 | + // image uploader |
|
59 | + $uploader = EEH_HTML::link('#', '<img src="' . admin_url('images/media-button-image.gif') . '" >', esc_html__('click to add an image', 'event_espresso'), '', 'ee_media_upload'); |
|
60 | + // only attempt to show the image if it at least exists |
|
61 | + $image = $this->src_exists($this->_input->raw_value()) ? EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image') : ''; |
|
62 | + // html string |
|
63 | + return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area'); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Asserts an image actually exists as quickly as possible by sending a HEAD |
|
70 | - * request |
|
71 | - * @param string $src |
|
72 | - * @return boolean |
|
73 | - */ |
|
74 | - protected function src_exists($src) |
|
75 | - { |
|
76 | - $results = wp_remote_head($src); |
|
77 | - if (is_array($results) && ! $results instanceof WP_Error) { |
|
78 | - return strpos($results['headers']['content-type'], "image") !== false; |
|
79 | - } else { |
|
80 | - return false; |
|
81 | - } |
|
82 | - } |
|
68 | + /** |
|
69 | + * Asserts an image actually exists as quickly as possible by sending a HEAD |
|
70 | + * request |
|
71 | + * @param string $src |
|
72 | + * @return boolean |
|
73 | + */ |
|
74 | + protected function src_exists($src) |
|
75 | + { |
|
76 | + $results = wp_remote_head($src); |
|
77 | + if (is_array($results) && ! $results instanceof WP_Error) { |
|
78 | + return strpos($results['headers']['content-type'], "image") !== false; |
|
79 | + } else { |
|
80 | + return false; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | } |