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