@@ -18,133 +18,133 @@ |
||
18 | 18 | */ |
19 | 19 | class ExportRegistration implements PersonalDataExporterInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var EEM_Registration |
|
23 | - */ |
|
24 | - protected $registration_model; |
|
21 | + /** |
|
22 | + * @var EEM_Registration |
|
23 | + */ |
|
24 | + protected $registration_model; |
|
25 | 25 | |
26 | - /** |
|
27 | - * ExportRegistration constructor. |
|
28 | - * |
|
29 | - * @param EEM_Registration $registration_model |
|
30 | - */ |
|
31 | - public function __construct(EEM_Registration $registration_model) |
|
32 | - { |
|
33 | - $this->registration_model = $registration_model; |
|
34 | - } |
|
26 | + /** |
|
27 | + * ExportRegistration constructor. |
|
28 | + * |
|
29 | + * @param EEM_Registration $registration_model |
|
30 | + */ |
|
31 | + public function __construct(EEM_Registration $registration_model) |
|
32 | + { |
|
33 | + $this->registration_model = $registration_model; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Returns data for export. |
|
39 | - * |
|
40 | - * @param string $email_address , |
|
41 | - * @param int $page starts at 1, not 0 |
|
42 | - * @return array { |
|
43 | - * @type array $data { |
|
44 | - * @type array { |
|
45 | - * @type string $group_id (not translated, same for all exports) |
|
46 | - * @type string $group_label (translated string) |
|
47 | - * @type string|int $item_id |
|
48 | - * @type array $data { |
|
49 | - * @type array { |
|
50 | - * @type string $name what's shown in the left-column of the export row |
|
51 | - * @type string $value what's showin the right-column of the export row |
|
52 | - * } |
|
53 | - * } |
|
54 | - * } |
|
55 | - * } |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function export($email_address, $page = 1) |
|
59 | - { |
|
60 | - $page_size = 10; |
|
61 | - $registrations = $this->registration_model->get_all( |
|
62 | - array( |
|
63 | - array( |
|
64 | - 'Attendee.ATT_email' => $email_address, |
|
65 | - ), |
|
66 | - 'limit' => array( |
|
67 | - ($page - 1) * $page_size, |
|
68 | - $page_size, |
|
69 | - ), |
|
70 | - ) |
|
71 | - ); |
|
72 | - $export_fields = array_intersect_key( |
|
73 | - $this->registration_model->field_settings(), |
|
74 | - array_flip( |
|
75 | - array( |
|
76 | - 'REG_code', |
|
77 | - 'REG_date', |
|
78 | - 'REG_final_price', |
|
79 | - 'REG_paid', |
|
80 | - 'REG_url_link', |
|
81 | - 'REG_count', |
|
82 | - 'REG_group_size', |
|
83 | - 'REG_att_is_going', |
|
84 | - ) |
|
85 | - ) |
|
86 | - ); |
|
87 | - $export_items = array(); |
|
88 | - $found_something = false; |
|
89 | - foreach ($registrations as $registration) { |
|
90 | - /** |
|
91 | - * @var $registration EE_Registration |
|
92 | - */ |
|
93 | - $found_something = true; |
|
94 | - $data = array(); |
|
95 | - foreach ($export_fields as $field_name => $field_obj) { |
|
96 | - $data[] = array( |
|
97 | - 'name' => $field_obj->get_nicename(), |
|
98 | - 'value' => $registration->get_pretty($field_name), |
|
99 | - ); |
|
100 | - } |
|
101 | - $answers = $registration->answers( |
|
102 | - array( |
|
103 | - 'force_join' => array( |
|
104 | - 'Question', |
|
105 | - ), |
|
106 | - ) |
|
107 | - ); |
|
108 | - foreach ($answers as $answer) { |
|
109 | - $data[] = array( |
|
110 | - 'name' => $answer->question()->display_text(), |
|
111 | - 'value' => $answer->pretty_value(), |
|
112 | - ); |
|
113 | - } |
|
114 | - $ticket = $registration->ticket(); |
|
115 | - if ($ticket instanceof EE_Ticket) { |
|
116 | - $data[] = array( |
|
117 | - 'name' => esc_html__('Ticket', 'event_espresso'), |
|
118 | - 'value' => $ticket->name_and_info(), |
|
119 | - ); |
|
120 | - $data[] = array( |
|
121 | - 'name' => esc_html__('Event', 'event_espresso'), |
|
122 | - 'value' => $ticket->get_event_name(), |
|
123 | - ); |
|
124 | - } |
|
37 | + /** |
|
38 | + * Returns data for export. |
|
39 | + * |
|
40 | + * @param string $email_address , |
|
41 | + * @param int $page starts at 1, not 0 |
|
42 | + * @return array { |
|
43 | + * @type array $data { |
|
44 | + * @type array { |
|
45 | + * @type string $group_id (not translated, same for all exports) |
|
46 | + * @type string $group_label (translated string) |
|
47 | + * @type string|int $item_id |
|
48 | + * @type array $data { |
|
49 | + * @type array { |
|
50 | + * @type string $name what's shown in the left-column of the export row |
|
51 | + * @type string $value what's showin the right-column of the export row |
|
52 | + * } |
|
53 | + * } |
|
54 | + * } |
|
55 | + * } |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function export($email_address, $page = 1) |
|
59 | + { |
|
60 | + $page_size = 10; |
|
61 | + $registrations = $this->registration_model->get_all( |
|
62 | + array( |
|
63 | + array( |
|
64 | + 'Attendee.ATT_email' => $email_address, |
|
65 | + ), |
|
66 | + 'limit' => array( |
|
67 | + ($page - 1) * $page_size, |
|
68 | + $page_size, |
|
69 | + ), |
|
70 | + ) |
|
71 | + ); |
|
72 | + $export_fields = array_intersect_key( |
|
73 | + $this->registration_model->field_settings(), |
|
74 | + array_flip( |
|
75 | + array( |
|
76 | + 'REG_code', |
|
77 | + 'REG_date', |
|
78 | + 'REG_final_price', |
|
79 | + 'REG_paid', |
|
80 | + 'REG_url_link', |
|
81 | + 'REG_count', |
|
82 | + 'REG_group_size', |
|
83 | + 'REG_att_is_going', |
|
84 | + ) |
|
85 | + ) |
|
86 | + ); |
|
87 | + $export_items = array(); |
|
88 | + $found_something = false; |
|
89 | + foreach ($registrations as $registration) { |
|
90 | + /** |
|
91 | + * @var $registration EE_Registration |
|
92 | + */ |
|
93 | + $found_something = true; |
|
94 | + $data = array(); |
|
95 | + foreach ($export_fields as $field_name => $field_obj) { |
|
96 | + $data[] = array( |
|
97 | + 'name' => $field_obj->get_nicename(), |
|
98 | + 'value' => $registration->get_pretty($field_name), |
|
99 | + ); |
|
100 | + } |
|
101 | + $answers = $registration->answers( |
|
102 | + array( |
|
103 | + 'force_join' => array( |
|
104 | + 'Question', |
|
105 | + ), |
|
106 | + ) |
|
107 | + ); |
|
108 | + foreach ($answers as $answer) { |
|
109 | + $data[] = array( |
|
110 | + 'name' => $answer->question()->display_text(), |
|
111 | + 'value' => $answer->pretty_value(), |
|
112 | + ); |
|
113 | + } |
|
114 | + $ticket = $registration->ticket(); |
|
115 | + if ($ticket instanceof EE_Ticket) { |
|
116 | + $data[] = array( |
|
117 | + 'name' => esc_html__('Ticket', 'event_espresso'), |
|
118 | + 'value' => $ticket->name_and_info(), |
|
119 | + ); |
|
120 | + $data[] = array( |
|
121 | + 'name' => esc_html__('Event', 'event_espresso'), |
|
122 | + 'value' => $ticket->get_event_name(), |
|
123 | + ); |
|
124 | + } |
|
125 | 125 | |
126 | - $export_items[] = array( |
|
127 | - 'group_id' => 'registration', |
|
128 | - 'group_label' => esc_html__('Event Registrations', 'event_espresso'), |
|
129 | - 'item_id' => $registration->ID(), |
|
130 | - 'data' => $data, |
|
131 | - ); |
|
132 | - } |
|
133 | - return array( |
|
134 | - 'data' => $export_items, |
|
135 | - 'done' => ! $found_something, |
|
136 | - ); |
|
137 | - } |
|
126 | + $export_items[] = array( |
|
127 | + 'group_id' => 'registration', |
|
128 | + 'group_label' => esc_html__('Event Registrations', 'event_espresso'), |
|
129 | + 'item_id' => $registration->ID(), |
|
130 | + 'data' => $data, |
|
131 | + ); |
|
132 | + } |
|
133 | + return array( |
|
134 | + 'data' => $export_items, |
|
135 | + 'done' => ! $found_something, |
|
136 | + ); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Gets the Translated name of this exporter |
|
141 | - * |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function name() |
|
145 | - { |
|
146 | - return esc_html__('Event Espresso Registration Data Exporter', 'event_espresso'); |
|
147 | - } |
|
139 | + /** |
|
140 | + * Gets the Translated name of this exporter |
|
141 | + * |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function name() |
|
145 | + { |
|
146 | + return esc_html__('Event Espresso Registration Data Exporter', 'event_espresso'); |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | // End of file ExportRegistration.php |
150 | 150 | // Location: EventEspresso\core\domain\services\admin\privacy\export/ExportRegistration.php |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $JSON_response['success'] = $this->success(); |
123 | 123 | } |
124 | 124 | // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
125 | - if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
125 | + if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | 126 | $JSON_response['success'] = null; |
127 | 127 | } |
128 | 128 | // set redirect_url, IF it exists |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | // and finally, add return_data array to main JSON response array, IF it contains anything |
163 | 163 | // why did we add some of the above properties to the return data array? |
164 | 164 | // because it is easier and cleaner in the Javascript to deal with this way |
165 | - if (! empty($return_data)) { |
|
165 | + if ( ! empty($return_data)) { |
|
166 | 166 | $JSON_response['return_data'] = $return_data; |
167 | 167 | } |
168 | 168 | // filter final array |
@@ -15,403 +15,403 @@ |
||
15 | 15 | class EE_SPCO_JSON_Response |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $_errors = ''; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $_unexpected_errors = ''; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_attention = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_success = ''; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $_plz_select_method_of_payment = ''; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $_redirect_url = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - protected $_registration_time_limit = ''; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_redirect_form = ''; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $_reg_step_html = ''; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $_method_of_payment = ''; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var float |
|
70 | - */ |
|
71 | - protected $_payment_amount; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - protected $_return_data = array(); |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @var array |
|
81 | - */ |
|
82 | - protected $_validation_rules = array(); |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * class constructor |
|
87 | - */ |
|
88 | - public function __construct() |
|
89 | - { |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * __toString |
|
95 | - * |
|
96 | - * allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a JSON encoded string |
|
97 | - * ie: $json_response = new EE_SPCO_JSON_Response(); |
|
98 | - * echo $json_response; |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function __toString() |
|
104 | - { |
|
105 | - $JSON_response = array(); |
|
106 | - // grab notices |
|
107 | - $notices = EE_Error::get_notices(false); |
|
108 | - $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
109 | - $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
110 | - $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
111 | - // add notices to JSON response, but only if they exist |
|
112 | - if ($this->attention()) { |
|
113 | - $JSON_response['attention'] = $this->attention(); |
|
114 | - } |
|
115 | - if ($this->errors()) { |
|
116 | - $JSON_response['errors'] = $this->errors(); |
|
117 | - } |
|
118 | - if ($this->unexpected_errors()) { |
|
119 | - $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
|
120 | - } |
|
121 | - if ($this->success()) { |
|
122 | - $JSON_response['success'] = $this->success(); |
|
123 | - } |
|
124 | - // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
|
125 | - if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | - $JSON_response['success'] = null; |
|
127 | - } |
|
128 | - // set redirect_url, IF it exists |
|
129 | - if ($this->redirect_url()) { |
|
130 | - $JSON_response['redirect_url'] = $this->redirect_url(); |
|
131 | - } |
|
132 | - // set registration_time_limit, IF it exists |
|
133 | - if ($this->registration_time_limit()) { |
|
134 | - $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
|
135 | - } |
|
136 | - // set payment_amount, IF it exists |
|
137 | - if ($this->payment_amount() !== null) { |
|
138 | - $JSON_response['payment_amount'] = $this->payment_amount(); |
|
139 | - } |
|
140 | - // grab generic return data |
|
141 | - $return_data = $this->return_data(); |
|
142 | - // add billing form validation rules |
|
143 | - if ($this->validation_rules()) { |
|
144 | - $return_data['validation_rules'] = $this->validation_rules(); |
|
145 | - } |
|
146 | - // set reg_step_html, IF it exists |
|
147 | - if ($this->reg_step_html()) { |
|
148 | - $return_data['reg_step_html'] = $this->reg_step_html(); |
|
149 | - } |
|
150 | - // set method of payment, IF it exists |
|
151 | - if ($this->method_of_payment()) { |
|
152 | - $return_data['method_of_payment'] = $this->method_of_payment(); |
|
153 | - } |
|
154 | - // set "plz_select_method_of_payment" message, IF it exists |
|
155 | - if ($this->plz_select_method_of_payment()) { |
|
156 | - $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
|
157 | - } |
|
158 | - // set redirect_form, IF it exists |
|
159 | - if ($this->redirect_form()) { |
|
160 | - $return_data['redirect_form'] = $this->redirect_form(); |
|
161 | - } |
|
162 | - // and finally, add return_data array to main JSON response array, IF it contains anything |
|
163 | - // why did we add some of the above properties to the return data array? |
|
164 | - // because it is easier and cleaner in the Javascript to deal with this way |
|
165 | - if (! empty($return_data)) { |
|
166 | - $JSON_response['return_data'] = $return_data; |
|
167 | - } |
|
168 | - // filter final array |
|
169 | - $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
170 | - // return encoded array |
|
171 | - return (string) wp_json_encode($JSON_response); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param string $attention |
|
177 | - */ |
|
178 | - public function set_attention($attention) |
|
179 | - { |
|
180 | - $this->_attention = $attention; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function attention() |
|
188 | - { |
|
189 | - return $this->_attention; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param string $errors |
|
195 | - */ |
|
196 | - public function set_errors($errors) |
|
197 | - { |
|
198 | - $this->_errors = $errors; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function errors() |
|
206 | - { |
|
207 | - return $this->_errors; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function unexpected_errors() |
|
215 | - { |
|
216 | - return $this->_unexpected_errors; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $unexpected_errors |
|
222 | - */ |
|
223 | - public function set_unexpected_errors($unexpected_errors) |
|
224 | - { |
|
225 | - $this->_unexpected_errors = $unexpected_errors; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string $success |
|
231 | - */ |
|
232 | - public function set_success($success) |
|
233 | - { |
|
234 | - $this->_success = $success; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public function success() |
|
242 | - { |
|
243 | - return $this->_success; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param string $method_of_payment |
|
249 | - */ |
|
250 | - public function set_method_of_payment($method_of_payment) |
|
251 | - { |
|
252 | - $this->_method_of_payment = $method_of_payment; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - public function method_of_payment() |
|
260 | - { |
|
261 | - return $this->_method_of_payment; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return float |
|
267 | - */ |
|
268 | - public function payment_amount() |
|
269 | - { |
|
270 | - return $this->_payment_amount; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param float $payment_amount |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function set_payment_amount($payment_amount) |
|
279 | - { |
|
280 | - $this->_payment_amount = (float) $payment_amount; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param string $next_step_html |
|
286 | - */ |
|
287 | - public function set_reg_step_html($next_step_html) |
|
288 | - { |
|
289 | - $this->_reg_step_html = $next_step_html; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function reg_step_html() |
|
297 | - { |
|
298 | - return $this->_reg_step_html; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * @param string $redirect_form |
|
304 | - */ |
|
305 | - public function set_redirect_form($redirect_form) |
|
306 | - { |
|
307 | - $this->_redirect_form = $redirect_form; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function redirect_form() |
|
315 | - { |
|
316 | - return ! empty($this->_redirect_form) ? $this->_redirect_form : false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param string $plz_select_method_of_payment |
|
322 | - */ |
|
323 | - public function set_plz_select_method_of_payment($plz_select_method_of_payment) |
|
324 | - { |
|
325 | - $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - public function plz_select_method_of_payment() |
|
333 | - { |
|
334 | - return $this->_plz_select_method_of_payment; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $redirect_url |
|
340 | - */ |
|
341 | - public function set_redirect_url($redirect_url) |
|
342 | - { |
|
343 | - $this->_redirect_url = $redirect_url; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - public function redirect_url() |
|
351 | - { |
|
352 | - return $this->_redirect_url; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function registration_time_limit() |
|
360 | - { |
|
361 | - return $this->_registration_time_limit; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * @param string $registration_time_limit |
|
367 | - */ |
|
368 | - public function set_registration_time_limit($registration_time_limit) |
|
369 | - { |
|
370 | - $this->_registration_time_limit = $registration_time_limit; |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * @param array $return_data |
|
376 | - */ |
|
377 | - public function set_return_data($return_data) |
|
378 | - { |
|
379 | - $this->_return_data = array_merge($this->_return_data, $return_data); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @return array |
|
385 | - */ |
|
386 | - public function return_data() |
|
387 | - { |
|
388 | - return $this->_return_data; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * @param array $validation_rules |
|
394 | - */ |
|
395 | - public function add_validation_rules(array $validation_rules = array()) |
|
396 | - { |
|
397 | - if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
398 | - $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @return array | bool |
|
405 | - */ |
|
406 | - public function validation_rules() |
|
407 | - { |
|
408 | - return ! empty($this->_validation_rules) ? $this->_validation_rules : false; |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - public function echoAndExit() |
|
413 | - { |
|
414 | - echo $this; // already escaped |
|
415 | - exit(); |
|
416 | - } |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $_errors = ''; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $_unexpected_errors = ''; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_attention = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_success = ''; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $_plz_select_method_of_payment = ''; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $_redirect_url = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + protected $_registration_time_limit = ''; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_redirect_form = ''; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $_reg_step_html = ''; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $_method_of_payment = ''; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var float |
|
70 | + */ |
|
71 | + protected $_payment_amount; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + protected $_return_data = array(); |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @var array |
|
81 | + */ |
|
82 | + protected $_validation_rules = array(); |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * class constructor |
|
87 | + */ |
|
88 | + public function __construct() |
|
89 | + { |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * __toString |
|
95 | + * |
|
96 | + * allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a JSON encoded string |
|
97 | + * ie: $json_response = new EE_SPCO_JSON_Response(); |
|
98 | + * echo $json_response; |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function __toString() |
|
104 | + { |
|
105 | + $JSON_response = array(); |
|
106 | + // grab notices |
|
107 | + $notices = EE_Error::get_notices(false); |
|
108 | + $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
109 | + $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
110 | + $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
111 | + // add notices to JSON response, but only if they exist |
|
112 | + if ($this->attention()) { |
|
113 | + $JSON_response['attention'] = $this->attention(); |
|
114 | + } |
|
115 | + if ($this->errors()) { |
|
116 | + $JSON_response['errors'] = $this->errors(); |
|
117 | + } |
|
118 | + if ($this->unexpected_errors()) { |
|
119 | + $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
|
120 | + } |
|
121 | + if ($this->success()) { |
|
122 | + $JSON_response['success'] = $this->success(); |
|
123 | + } |
|
124 | + // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
|
125 | + if (! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
126 | + $JSON_response['success'] = null; |
|
127 | + } |
|
128 | + // set redirect_url, IF it exists |
|
129 | + if ($this->redirect_url()) { |
|
130 | + $JSON_response['redirect_url'] = $this->redirect_url(); |
|
131 | + } |
|
132 | + // set registration_time_limit, IF it exists |
|
133 | + if ($this->registration_time_limit()) { |
|
134 | + $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
|
135 | + } |
|
136 | + // set payment_amount, IF it exists |
|
137 | + if ($this->payment_amount() !== null) { |
|
138 | + $JSON_response['payment_amount'] = $this->payment_amount(); |
|
139 | + } |
|
140 | + // grab generic return data |
|
141 | + $return_data = $this->return_data(); |
|
142 | + // add billing form validation rules |
|
143 | + if ($this->validation_rules()) { |
|
144 | + $return_data['validation_rules'] = $this->validation_rules(); |
|
145 | + } |
|
146 | + // set reg_step_html, IF it exists |
|
147 | + if ($this->reg_step_html()) { |
|
148 | + $return_data['reg_step_html'] = $this->reg_step_html(); |
|
149 | + } |
|
150 | + // set method of payment, IF it exists |
|
151 | + if ($this->method_of_payment()) { |
|
152 | + $return_data['method_of_payment'] = $this->method_of_payment(); |
|
153 | + } |
|
154 | + // set "plz_select_method_of_payment" message, IF it exists |
|
155 | + if ($this->plz_select_method_of_payment()) { |
|
156 | + $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
|
157 | + } |
|
158 | + // set redirect_form, IF it exists |
|
159 | + if ($this->redirect_form()) { |
|
160 | + $return_data['redirect_form'] = $this->redirect_form(); |
|
161 | + } |
|
162 | + // and finally, add return_data array to main JSON response array, IF it contains anything |
|
163 | + // why did we add some of the above properties to the return data array? |
|
164 | + // because it is easier and cleaner in the Javascript to deal with this way |
|
165 | + if (! empty($return_data)) { |
|
166 | + $JSON_response['return_data'] = $return_data; |
|
167 | + } |
|
168 | + // filter final array |
|
169 | + $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
170 | + // return encoded array |
|
171 | + return (string) wp_json_encode($JSON_response); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param string $attention |
|
177 | + */ |
|
178 | + public function set_attention($attention) |
|
179 | + { |
|
180 | + $this->_attention = $attention; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function attention() |
|
188 | + { |
|
189 | + return $this->_attention; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param string $errors |
|
195 | + */ |
|
196 | + public function set_errors($errors) |
|
197 | + { |
|
198 | + $this->_errors = $errors; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function errors() |
|
206 | + { |
|
207 | + return $this->_errors; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function unexpected_errors() |
|
215 | + { |
|
216 | + return $this->_unexpected_errors; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $unexpected_errors |
|
222 | + */ |
|
223 | + public function set_unexpected_errors($unexpected_errors) |
|
224 | + { |
|
225 | + $this->_unexpected_errors = $unexpected_errors; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string $success |
|
231 | + */ |
|
232 | + public function set_success($success) |
|
233 | + { |
|
234 | + $this->_success = $success; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public function success() |
|
242 | + { |
|
243 | + return $this->_success; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param string $method_of_payment |
|
249 | + */ |
|
250 | + public function set_method_of_payment($method_of_payment) |
|
251 | + { |
|
252 | + $this->_method_of_payment = $method_of_payment; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + public function method_of_payment() |
|
260 | + { |
|
261 | + return $this->_method_of_payment; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return float |
|
267 | + */ |
|
268 | + public function payment_amount() |
|
269 | + { |
|
270 | + return $this->_payment_amount; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param float $payment_amount |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function set_payment_amount($payment_amount) |
|
279 | + { |
|
280 | + $this->_payment_amount = (float) $payment_amount; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param string $next_step_html |
|
286 | + */ |
|
287 | + public function set_reg_step_html($next_step_html) |
|
288 | + { |
|
289 | + $this->_reg_step_html = $next_step_html; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function reg_step_html() |
|
297 | + { |
|
298 | + return $this->_reg_step_html; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * @param string $redirect_form |
|
304 | + */ |
|
305 | + public function set_redirect_form($redirect_form) |
|
306 | + { |
|
307 | + $this->_redirect_form = $redirect_form; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function redirect_form() |
|
315 | + { |
|
316 | + return ! empty($this->_redirect_form) ? $this->_redirect_form : false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param string $plz_select_method_of_payment |
|
322 | + */ |
|
323 | + public function set_plz_select_method_of_payment($plz_select_method_of_payment) |
|
324 | + { |
|
325 | + $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + public function plz_select_method_of_payment() |
|
333 | + { |
|
334 | + return $this->_plz_select_method_of_payment; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $redirect_url |
|
340 | + */ |
|
341 | + public function set_redirect_url($redirect_url) |
|
342 | + { |
|
343 | + $this->_redirect_url = $redirect_url; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + public function redirect_url() |
|
351 | + { |
|
352 | + return $this->_redirect_url; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function registration_time_limit() |
|
360 | + { |
|
361 | + return $this->_registration_time_limit; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * @param string $registration_time_limit |
|
367 | + */ |
|
368 | + public function set_registration_time_limit($registration_time_limit) |
|
369 | + { |
|
370 | + $this->_registration_time_limit = $registration_time_limit; |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * @param array $return_data |
|
376 | + */ |
|
377 | + public function set_return_data($return_data) |
|
378 | + { |
|
379 | + $this->_return_data = array_merge($this->_return_data, $return_data); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @return array |
|
385 | + */ |
|
386 | + public function return_data() |
|
387 | + { |
|
388 | + return $this->_return_data; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * @param array $validation_rules |
|
394 | + */ |
|
395 | + public function add_validation_rules(array $validation_rules = array()) |
|
396 | + { |
|
397 | + if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
398 | + $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @return array | bool |
|
405 | + */ |
|
406 | + public function validation_rules() |
|
407 | + { |
|
408 | + return ! empty($this->_validation_rules) ? $this->_validation_rules : false; |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + public function echoAndExit() |
|
413 | + { |
|
414 | + echo $this; // already escaped |
|
415 | + exit(); |
|
416 | + } |
|
417 | 417 | } |
@@ -16,14 +16,14 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - public function __construct(EE_Admin_Page $admin_page) |
|
20 | - { |
|
21 | - parent::__construct($admin_page); |
|
22 | - } |
|
19 | + public function __construct(EE_Admin_Page $admin_page) |
|
20 | + { |
|
21 | + parent::__construct($admin_page); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - protected function _set_hooks_properties() |
|
26 | - { |
|
27 | - $this->_name = 'messages'; |
|
28 | - } |
|
25 | + protected function _set_hooks_properties() |
|
26 | + { |
|
27 | + $this->_name = 'messages'; |
|
28 | + } |
|
29 | 29 | } |
@@ -12,15 +12,15 @@ |
||
12 | 12 | class Extend_Events_Admin_List_Table extends Events_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - protected function _column_name_action_setup(EE_Event $item) |
|
16 | - { |
|
17 | - $export_query_args = array( |
|
18 | - 'action' => 'export_events', |
|
19 | - 'EVT_ID' => $item->ID(), |
|
20 | - ); |
|
21 | - $export_event_link = EE_Admin_Page::add_query_args_and_nonce($export_query_args, EVENTS_ADMIN_URL); |
|
15 | + protected function _column_name_action_setup(EE_Event $item) |
|
16 | + { |
|
17 | + $export_query_args = array( |
|
18 | + 'action' => 'export_events', |
|
19 | + 'EVT_ID' => $item->ID(), |
|
20 | + ); |
|
21 | + $export_event_link = EE_Admin_Page::add_query_args_and_nonce($export_query_args, EVENTS_ADMIN_URL); |
|
22 | 22 | |
23 | - $actions = parent::_column_name_action_setup($item); |
|
24 | - return $actions; |
|
25 | - } |
|
23 | + $actions = parent::_column_name_action_setup($item); |
|
24 | + return $actions; |
|
25 | + } |
|
26 | 26 | } |
@@ -11,80 +11,80 @@ |
||
11 | 11 | class EE_Term_Taxonomy extends EE_Base_Class |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $props_n_values |
|
16 | - * @return EE_Term_Taxonomy |
|
17 | - */ |
|
18 | - public static function new_instance($props_n_values = array()) |
|
19 | - { |
|
20 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
21 | - return $has_object ? $has_object : new self($props_n_values); |
|
22 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values |
|
16 | + * @return EE_Term_Taxonomy |
|
17 | + */ |
|
18 | + public static function new_instance($props_n_values = array()) |
|
19 | + { |
|
20 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
21 | + return $has_object ? $has_object : new self($props_n_values); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Term_Taxonomy |
|
28 | - */ |
|
29 | - public static function new_instance_from_db($props_n_values = array()) |
|
30 | - { |
|
31 | - return new self($props_n_values, true); |
|
32 | - } |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Term_Taxonomy |
|
28 | + */ |
|
29 | + public static function new_instance_from_db($props_n_values = array()) |
|
30 | + { |
|
31 | + return new self($props_n_values, true); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Gets taxonomy |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function taxonomy() |
|
41 | - { |
|
42 | - return $this->get('taxonomy'); |
|
43 | - } |
|
35 | + /** |
|
36 | + * Gets taxonomy |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function taxonomy() |
|
41 | + { |
|
42 | + return $this->get('taxonomy'); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Sets taxonomy |
|
48 | - * |
|
49 | - * @param string $taxonomy |
|
50 | - * @return boolean |
|
51 | - */ |
|
52 | - public function set_taxonomy($taxonomy) |
|
53 | - { |
|
54 | - $this->set('taxonomy', $taxonomy); |
|
55 | - } |
|
46 | + /** |
|
47 | + * Sets taxonomy |
|
48 | + * |
|
49 | + * @param string $taxonomy |
|
50 | + * @return boolean |
|
51 | + */ |
|
52 | + public function set_taxonomy($taxonomy) |
|
53 | + { |
|
54 | + $this->set('taxonomy', $taxonomy); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Gets term_count |
|
60 | - * |
|
61 | - * @return int |
|
62 | - */ |
|
63 | - public function count() |
|
64 | - { |
|
65 | - return $this->get('term_count'); |
|
66 | - } |
|
58 | + /** |
|
59 | + * Gets term_count |
|
60 | + * |
|
61 | + * @return int |
|
62 | + */ |
|
63 | + public function count() |
|
64 | + { |
|
65 | + return $this->get('term_count'); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Sets term_count |
|
71 | - * |
|
72 | - * @param int $term_count |
|
73 | - * @return boolean |
|
74 | - */ |
|
75 | - public function set_count($term_count) |
|
76 | - { |
|
77 | - $this->set('term_count', $term_count); |
|
78 | - } |
|
69 | + /** |
|
70 | + * Sets term_count |
|
71 | + * |
|
72 | + * @param int $term_count |
|
73 | + * @return boolean |
|
74 | + */ |
|
75 | + public function set_count($term_count) |
|
76 | + { |
|
77 | + $this->set('term_count', $term_count); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Gets the term for this term taxonomy |
|
83 | - * |
|
84 | - * @return EE_Term |
|
85 | - */ |
|
86 | - public function term() |
|
87 | - { |
|
88 | - return $this->get_first_related('Term'); |
|
89 | - } |
|
81 | + /** |
|
82 | + * Gets the term for this term taxonomy |
|
83 | + * |
|
84 | + * @return EE_Term |
|
85 | + */ |
|
86 | + public function term() |
|
87 | + { |
|
88 | + return $this->get_first_related('Term'); |
|
89 | + } |
|
90 | 90 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function set_message_type($message_type = false) |
50 | 50 | { |
51 | - if (! $message_type) { |
|
51 | + if ( ! $message_type) { |
|
52 | 52 | throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
53 | 53 | } |
54 | 54 | $this->set('MTP_message_type', $message_type); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function set_messenger($messenger = false) |
63 | 63 | { |
64 | - if (! $messenger) { |
|
64 | + if ( ! $messenger) { |
|
65 | 65 | throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
66 | 66 | } |
67 | 67 | $this->set('MTP_messenger', $messenger); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function set_group_template_id($GRP_ID = false) |
76 | 76 | { |
77 | - if (! $GRP_ID) { |
|
77 | + if ( ! $GRP_ID) { |
|
78 | 78 | throw new EE_Error( |
79 | 79 | esc_html__( |
80 | 80 | 'Missing required value for the message template group id', |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } |
291 | 291 | // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
292 | 292 | foreach ($mtps as $mtp) { |
293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
293 | + $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
294 | 294 | } |
295 | 295 | return $mtps_arr; |
296 | 296 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | public function deactivate_context($context) |
431 | 431 | { |
432 | 432 | $this->validate_context($context); |
433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | public function activate_context($context) |
446 | 446 | { |
447 | 447 | $this->validate_context($context); |
448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | { |
466 | 466 | $this->validate_context($context); |
467 | 467 | return filter_var( |
468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true), |
|
469 | 469 | FILTER_VALIDATE_BOOLEAN |
470 | 470 | ); |
471 | 471 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | public function validate_context($context) |
482 | 482 | { |
483 | 483 | $contexts = $this->contexts_config(); |
484 | - if (! isset($contexts[ $context ])) { |
|
484 | + if ( ! isset($contexts[$context])) { |
|
485 | 485 | throw new InvalidIdentifierException( |
486 | 486 | '', |
487 | 487 | '', |
@@ -13,487 +13,487 @@ |
||
13 | 13 | class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
18 | - */ |
|
19 | - const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
20 | - |
|
21 | - /** |
|
22 | - * @param array $props_n_values |
|
23 | - * @param string $timezone |
|
24 | - * @return EE_Message_Template_Group|mixed |
|
25 | - * @throws EE_Error |
|
26 | - */ |
|
27 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
28 | - { |
|
29 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
30 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param array $props_n_values |
|
36 | - * @param string $timezone |
|
37 | - * @return EE_Message_Template_Group |
|
38 | - */ |
|
39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
40 | - { |
|
41 | - return new self($props_n_values, true, $timezone); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param bool $message_type |
|
47 | - * @throws EE_Error |
|
48 | - */ |
|
49 | - public function set_message_type($message_type = false) |
|
50 | - { |
|
51 | - if (! $message_type) { |
|
52 | - throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
53 | - } |
|
54 | - $this->set('MTP_message_type', $message_type); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param bool $messenger |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function set_messenger($messenger = false) |
|
63 | - { |
|
64 | - if (! $messenger) { |
|
65 | - throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
66 | - } |
|
67 | - $this->set('MTP_messenger', $messenger); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param bool $GRP_ID |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - public function set_group_template_id($GRP_ID = false) |
|
76 | - { |
|
77 | - if (! $GRP_ID) { |
|
78 | - throw new EE_Error( |
|
79 | - esc_html__( |
|
80 | - 'Missing required value for the message template group id', |
|
81 | - 'event_espresso' |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
85 | - $this->set('GRP_ID', $GRP_ID); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * get Group ID |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return int |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public function GRP_ID() |
|
97 | - { |
|
98 | - return $this->get('GRP_ID'); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * get User ID |
|
104 | - * |
|
105 | - * @access public |
|
106 | - * @return int |
|
107 | - * @throws EE_Error |
|
108 | - */ |
|
109 | - public function user() |
|
110 | - { |
|
111 | - $user_id = $this->get('MTP_user_id'); |
|
112 | - return empty($user_id) ? get_current_user_id() : $user_id; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Wrapper for the user function() (preserve backward compat) |
|
118 | - * |
|
119 | - * @since 4.5.0 |
|
120 | - * @return int |
|
121 | - * @throws EE_Error |
|
122 | - */ |
|
123 | - public function wp_user() |
|
124 | - { |
|
125 | - return $this->user(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * This simply returns a count of all related events to this message template group |
|
131 | - * |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function count_events() |
|
135 | - { |
|
136 | - return $this->count_related('Event'); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * returns the name saved in the db for this template |
|
142 | - * |
|
143 | - * @return string |
|
144 | - * @throws EE_Error |
|
145 | - */ |
|
146 | - public function name() |
|
147 | - { |
|
148 | - return $this->get('MTP_name'); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns the description saved in the db for this template group |
|
154 | - * |
|
155 | - * @return string |
|
156 | - * @throws EE_Error |
|
157 | - */ |
|
158 | - public function description() |
|
159 | - { |
|
160 | - return $this->get('MTP_description'); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * returns all related EE_Message_Template objects |
|
166 | - * |
|
167 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
168 | - * @return EE_Message_Template[] |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
171 | - public function message_templates($query_params = array()) |
|
172 | - { |
|
173 | - return $this->get_many_related('Message_Template', $query_params); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * get Message Messenger |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @return string |
|
182 | - * @throws EE_Error |
|
183 | - */ |
|
184 | - public function messenger() |
|
185 | - { |
|
186 | - return $this->get('MTP_messenger'); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * get Message Messenger OBJECT |
|
192 | - * If an attempt to get the corresponding messenger object fails, then we set this message |
|
193 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
194 | - * appropriately. |
|
195 | - * |
|
196 | - * @return EE_messenger |
|
197 | - * @throws EE_Error |
|
198 | - */ |
|
199 | - public function messenger_obj() |
|
200 | - { |
|
201 | - $messenger = $this->messenger(); |
|
202 | - try { |
|
203 | - $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
206 | - // class for this messenger in this group. |
|
207 | - $this->set('MTP_is_active', false); |
|
208 | - $this->save(); |
|
209 | - return null; |
|
210 | - } |
|
211 | - return $messenger; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get Message Type |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @return string |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function message_type() |
|
223 | - { |
|
224 | - return $this->get('MTP_message_type'); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * get Message type OBJECT |
|
230 | - * If an attempt to get the corresponding message type object fails, then we set this message |
|
231 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
232 | - * appropriately. |
|
233 | - * |
|
234 | - * @throws EE_Error |
|
235 | - * @return EE_message_type|false if exception thrown. |
|
236 | - */ |
|
237 | - public function message_type_obj() |
|
238 | - { |
|
239 | - $message_type = $this->message_type(); |
|
240 | - try { |
|
241 | - $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
244 | - // class for the message type in this group. |
|
245 | - $this->set('MTP_is_active', false); |
|
246 | - $this->save(); |
|
247 | - return null; |
|
248 | - } |
|
249 | - return $message_type; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @return array |
|
255 | - * @throws EE_Error |
|
256 | - */ |
|
257 | - public function contexts_config() |
|
258 | - { |
|
259 | - return $this->message_type_obj()->get_contexts(); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * This returns the context_label for contexts as set in the message type object |
|
265 | - * Note this is an array with singular and plural keys |
|
266 | - * |
|
267 | - * @access public |
|
268 | - * @return array labels for "context" |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - public function context_label() |
|
272 | - { |
|
273 | - $obj = $this->message_type_obj(); |
|
274 | - return $obj->get_context_label(); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * This returns an array of EE_Message_Template objects indexed by context and field. |
|
280 | - * |
|
281 | - * @return array () |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function context_templates() |
|
285 | - { |
|
286 | - $mtps_arr = array(); |
|
287 | - $mtps = $this->get_many_related('Message_Template'); |
|
288 | - if (empty($mtps)) { |
|
289 | - return array(); |
|
290 | - } |
|
291 | - // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
292 | - foreach ($mtps as $mtp) { |
|
293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
294 | - } |
|
295 | - return $mtps_arr; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * this returns if the template group this template belongs to is global |
|
301 | - * |
|
302 | - * @return bool true if it is, false if it isn't |
|
303 | - * @throws EE_Error |
|
304 | - */ |
|
305 | - public function is_global() |
|
306 | - { |
|
307 | - return $this->get('MTP_is_global'); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
313 | - * |
|
314 | - * @return bool true if it is, false if it isn't |
|
315 | - * @throws EE_Error |
|
316 | - */ |
|
317 | - public function is_active() |
|
318 | - { |
|
319 | - return $this->get('MTP_is_active'); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
325 | - * this template. |
|
326 | - * |
|
327 | - * @since 4.3.0 |
|
328 | - * @uses EEH_MSG_Template::get_shortcodes() |
|
329 | - * @param string $context what context we're going to return shortcodes for |
|
330 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
331 | - * to be returned. |
|
332 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
333 | - * unique shortcodes for all the given (or all) fields. |
|
334 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
335 | - * shortcodes found. |
|
336 | - * @throws EE_Error |
|
337 | - */ |
|
338 | - public function get_shortcodes($context, $fields = array(), $merged = false) |
|
339 | - { |
|
340 | - $messenger = $this->messenger(); |
|
341 | - $message_type = $this->message_type(); |
|
342 | - return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
348 | - * use the default template pack. |
|
349 | - * |
|
350 | - * @since 4.5.0 |
|
351 | - * @return string |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public function get_template_pack_name() |
|
355 | - { |
|
356 | - return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * This returns the specific template pack object referenced by the template pack name attached to this message |
|
362 | - * template group. If no template pack is assigned then the default template pack is retrieved. |
|
363 | - * |
|
364 | - * @since 4.5.0 |
|
365 | - * @return EE_Messages_Template_Pack |
|
366 | - * @throws EE_Error |
|
367 | - * @throws InvalidArgumentException |
|
368 | - * @throws ReflectionException |
|
369 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
370 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
371 | - */ |
|
372 | - public function get_template_pack() |
|
373 | - { |
|
374 | - $pack_name = $this->get_template_pack_name(); |
|
375 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
376 | - return EEH_MSG_Template::get_template_pack($pack_name); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
382 | - * use the default template variation. |
|
383 | - * |
|
384 | - * @since 4.5.0 |
|
385 | - * @return string |
|
386 | - * @throws EE_Error |
|
387 | - */ |
|
388 | - public function get_template_pack_variation() |
|
389 | - { |
|
390 | - return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * This just sets the template pack name attached to this message template group. |
|
396 | - * |
|
397 | - * @since 4.5.0 |
|
398 | - * @param string $template_pack_name What message template pack is assigned. |
|
399 | - * @return int |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function set_template_pack_name($template_pack_name) |
|
403 | - { |
|
404 | - return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * This just sets the template pack variation attached to this message template group. |
|
410 | - * |
|
411 | - * @since 4.5.0 |
|
412 | - * @param string $variation What variation is being set on the message template group. |
|
413 | - * @return int |
|
414 | - * @throws EE_Error |
|
415 | - */ |
|
416 | - public function set_template_pack_variation($variation) |
|
417 | - { |
|
418 | - return $this->update_extra_meta('MTP_variation', $variation); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Deactivates the given context. |
|
424 | - * |
|
425 | - * @param $context |
|
426 | - * @return bool|int |
|
427 | - * @throws EE_Error |
|
428 | - * @throws InvalidIdentifierException |
|
429 | - */ |
|
430 | - public function deactivate_context($context) |
|
431 | - { |
|
432 | - $this->validate_context($context); |
|
433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * Activates the given context. |
|
439 | - * |
|
440 | - * @param $context |
|
441 | - * @return bool|int |
|
442 | - * @throws EE_Error |
|
443 | - * @throws InvalidIdentifierException |
|
444 | - */ |
|
445 | - public function activate_context($context) |
|
446 | - { |
|
447 | - $this->validate_context($context); |
|
448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Returns whether the context is active or not. |
|
454 | - * Note, this will default to true if the extra meta record doesn't exist. |
|
455 | - * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
456 | - * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
457 | - * whether a context is "active" or not. |
|
458 | - * |
|
459 | - * @param $context |
|
460 | - * @return bool |
|
461 | - * @throws EE_Error |
|
462 | - * @throws InvalidIdentifierException |
|
463 | - */ |
|
464 | - public function is_context_active($context) |
|
465 | - { |
|
466 | - $this->validate_context($context); |
|
467 | - return filter_var( |
|
468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
469 | - FILTER_VALIDATE_BOOLEAN |
|
470 | - ); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Validates the incoming context to verify it matches a registered context for the related message type. |
|
476 | - * |
|
477 | - * @param string $context |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidIdentifierException |
|
480 | - */ |
|
481 | - public function validate_context($context) |
|
482 | - { |
|
483 | - $contexts = $this->contexts_config(); |
|
484 | - if (! isset($contexts[ $context ])) { |
|
485 | - throw new InvalidIdentifierException( |
|
486 | - '', |
|
487 | - '', |
|
488 | - sprintf( |
|
489 | - esc_html__( |
|
490 | - 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
491 | - 'event_espresso' |
|
492 | - ), |
|
493 | - $context, |
|
494 | - implode(',', array_keys($contexts)) |
|
495 | - ) |
|
496 | - ); |
|
497 | - } |
|
498 | - } |
|
16 | + /** |
|
17 | + * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
18 | + */ |
|
19 | + const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
20 | + |
|
21 | + /** |
|
22 | + * @param array $props_n_values |
|
23 | + * @param string $timezone |
|
24 | + * @return EE_Message_Template_Group|mixed |
|
25 | + * @throws EE_Error |
|
26 | + */ |
|
27 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
28 | + { |
|
29 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
30 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param array $props_n_values |
|
36 | + * @param string $timezone |
|
37 | + * @return EE_Message_Template_Group |
|
38 | + */ |
|
39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
40 | + { |
|
41 | + return new self($props_n_values, true, $timezone); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param bool $message_type |
|
47 | + * @throws EE_Error |
|
48 | + */ |
|
49 | + public function set_message_type($message_type = false) |
|
50 | + { |
|
51 | + if (! $message_type) { |
|
52 | + throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
53 | + } |
|
54 | + $this->set('MTP_message_type', $message_type); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param bool $messenger |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function set_messenger($messenger = false) |
|
63 | + { |
|
64 | + if (! $messenger) { |
|
65 | + throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
66 | + } |
|
67 | + $this->set('MTP_messenger', $messenger); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param bool $GRP_ID |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + public function set_group_template_id($GRP_ID = false) |
|
76 | + { |
|
77 | + if (! $GRP_ID) { |
|
78 | + throw new EE_Error( |
|
79 | + esc_html__( |
|
80 | + 'Missing required value for the message template group id', |
|
81 | + 'event_espresso' |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | + $this->set('GRP_ID', $GRP_ID); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * get Group ID |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return int |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public function GRP_ID() |
|
97 | + { |
|
98 | + return $this->get('GRP_ID'); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * get User ID |
|
104 | + * |
|
105 | + * @access public |
|
106 | + * @return int |
|
107 | + * @throws EE_Error |
|
108 | + */ |
|
109 | + public function user() |
|
110 | + { |
|
111 | + $user_id = $this->get('MTP_user_id'); |
|
112 | + return empty($user_id) ? get_current_user_id() : $user_id; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Wrapper for the user function() (preserve backward compat) |
|
118 | + * |
|
119 | + * @since 4.5.0 |
|
120 | + * @return int |
|
121 | + * @throws EE_Error |
|
122 | + */ |
|
123 | + public function wp_user() |
|
124 | + { |
|
125 | + return $this->user(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * This simply returns a count of all related events to this message template group |
|
131 | + * |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function count_events() |
|
135 | + { |
|
136 | + return $this->count_related('Event'); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * returns the name saved in the db for this template |
|
142 | + * |
|
143 | + * @return string |
|
144 | + * @throws EE_Error |
|
145 | + */ |
|
146 | + public function name() |
|
147 | + { |
|
148 | + return $this->get('MTP_name'); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns the description saved in the db for this template group |
|
154 | + * |
|
155 | + * @return string |
|
156 | + * @throws EE_Error |
|
157 | + */ |
|
158 | + public function description() |
|
159 | + { |
|
160 | + return $this->get('MTP_description'); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * returns all related EE_Message_Template objects |
|
166 | + * |
|
167 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
168 | + * @return EE_Message_Template[] |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | + public function message_templates($query_params = array()) |
|
172 | + { |
|
173 | + return $this->get_many_related('Message_Template', $query_params); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * get Message Messenger |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @return string |
|
182 | + * @throws EE_Error |
|
183 | + */ |
|
184 | + public function messenger() |
|
185 | + { |
|
186 | + return $this->get('MTP_messenger'); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * get Message Messenger OBJECT |
|
192 | + * If an attempt to get the corresponding messenger object fails, then we set this message |
|
193 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
194 | + * appropriately. |
|
195 | + * |
|
196 | + * @return EE_messenger |
|
197 | + * @throws EE_Error |
|
198 | + */ |
|
199 | + public function messenger_obj() |
|
200 | + { |
|
201 | + $messenger = $this->messenger(); |
|
202 | + try { |
|
203 | + $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
206 | + // class for this messenger in this group. |
|
207 | + $this->set('MTP_is_active', false); |
|
208 | + $this->save(); |
|
209 | + return null; |
|
210 | + } |
|
211 | + return $messenger; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get Message Type |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @return string |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function message_type() |
|
223 | + { |
|
224 | + return $this->get('MTP_message_type'); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * get Message type OBJECT |
|
230 | + * If an attempt to get the corresponding message type object fails, then we set this message |
|
231 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
232 | + * appropriately. |
|
233 | + * |
|
234 | + * @throws EE_Error |
|
235 | + * @return EE_message_type|false if exception thrown. |
|
236 | + */ |
|
237 | + public function message_type_obj() |
|
238 | + { |
|
239 | + $message_type = $this->message_type(); |
|
240 | + try { |
|
241 | + $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
244 | + // class for the message type in this group. |
|
245 | + $this->set('MTP_is_active', false); |
|
246 | + $this->save(); |
|
247 | + return null; |
|
248 | + } |
|
249 | + return $message_type; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @return array |
|
255 | + * @throws EE_Error |
|
256 | + */ |
|
257 | + public function contexts_config() |
|
258 | + { |
|
259 | + return $this->message_type_obj()->get_contexts(); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * This returns the context_label for contexts as set in the message type object |
|
265 | + * Note this is an array with singular and plural keys |
|
266 | + * |
|
267 | + * @access public |
|
268 | + * @return array labels for "context" |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + public function context_label() |
|
272 | + { |
|
273 | + $obj = $this->message_type_obj(); |
|
274 | + return $obj->get_context_label(); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * This returns an array of EE_Message_Template objects indexed by context and field. |
|
280 | + * |
|
281 | + * @return array () |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function context_templates() |
|
285 | + { |
|
286 | + $mtps_arr = array(); |
|
287 | + $mtps = $this->get_many_related('Message_Template'); |
|
288 | + if (empty($mtps)) { |
|
289 | + return array(); |
|
290 | + } |
|
291 | + // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
292 | + foreach ($mtps as $mtp) { |
|
293 | + $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
294 | + } |
|
295 | + return $mtps_arr; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * this returns if the template group this template belongs to is global |
|
301 | + * |
|
302 | + * @return bool true if it is, false if it isn't |
|
303 | + * @throws EE_Error |
|
304 | + */ |
|
305 | + public function is_global() |
|
306 | + { |
|
307 | + return $this->get('MTP_is_global'); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
313 | + * |
|
314 | + * @return bool true if it is, false if it isn't |
|
315 | + * @throws EE_Error |
|
316 | + */ |
|
317 | + public function is_active() |
|
318 | + { |
|
319 | + return $this->get('MTP_is_active'); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
325 | + * this template. |
|
326 | + * |
|
327 | + * @since 4.3.0 |
|
328 | + * @uses EEH_MSG_Template::get_shortcodes() |
|
329 | + * @param string $context what context we're going to return shortcodes for |
|
330 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
331 | + * to be returned. |
|
332 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
333 | + * unique shortcodes for all the given (or all) fields. |
|
334 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
335 | + * shortcodes found. |
|
336 | + * @throws EE_Error |
|
337 | + */ |
|
338 | + public function get_shortcodes($context, $fields = array(), $merged = false) |
|
339 | + { |
|
340 | + $messenger = $this->messenger(); |
|
341 | + $message_type = $this->message_type(); |
|
342 | + return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
348 | + * use the default template pack. |
|
349 | + * |
|
350 | + * @since 4.5.0 |
|
351 | + * @return string |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public function get_template_pack_name() |
|
355 | + { |
|
356 | + return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * This returns the specific template pack object referenced by the template pack name attached to this message |
|
362 | + * template group. If no template pack is assigned then the default template pack is retrieved. |
|
363 | + * |
|
364 | + * @since 4.5.0 |
|
365 | + * @return EE_Messages_Template_Pack |
|
366 | + * @throws EE_Error |
|
367 | + * @throws InvalidArgumentException |
|
368 | + * @throws ReflectionException |
|
369 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
370 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
371 | + */ |
|
372 | + public function get_template_pack() |
|
373 | + { |
|
374 | + $pack_name = $this->get_template_pack_name(); |
|
375 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
376 | + return EEH_MSG_Template::get_template_pack($pack_name); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
382 | + * use the default template variation. |
|
383 | + * |
|
384 | + * @since 4.5.0 |
|
385 | + * @return string |
|
386 | + * @throws EE_Error |
|
387 | + */ |
|
388 | + public function get_template_pack_variation() |
|
389 | + { |
|
390 | + return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * This just sets the template pack name attached to this message template group. |
|
396 | + * |
|
397 | + * @since 4.5.0 |
|
398 | + * @param string $template_pack_name What message template pack is assigned. |
|
399 | + * @return int |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function set_template_pack_name($template_pack_name) |
|
403 | + { |
|
404 | + return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * This just sets the template pack variation attached to this message template group. |
|
410 | + * |
|
411 | + * @since 4.5.0 |
|
412 | + * @param string $variation What variation is being set on the message template group. |
|
413 | + * @return int |
|
414 | + * @throws EE_Error |
|
415 | + */ |
|
416 | + public function set_template_pack_variation($variation) |
|
417 | + { |
|
418 | + return $this->update_extra_meta('MTP_variation', $variation); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Deactivates the given context. |
|
424 | + * |
|
425 | + * @param $context |
|
426 | + * @return bool|int |
|
427 | + * @throws EE_Error |
|
428 | + * @throws InvalidIdentifierException |
|
429 | + */ |
|
430 | + public function deactivate_context($context) |
|
431 | + { |
|
432 | + $this->validate_context($context); |
|
433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * Activates the given context. |
|
439 | + * |
|
440 | + * @param $context |
|
441 | + * @return bool|int |
|
442 | + * @throws EE_Error |
|
443 | + * @throws InvalidIdentifierException |
|
444 | + */ |
|
445 | + public function activate_context($context) |
|
446 | + { |
|
447 | + $this->validate_context($context); |
|
448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Returns whether the context is active or not. |
|
454 | + * Note, this will default to true if the extra meta record doesn't exist. |
|
455 | + * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
456 | + * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
457 | + * whether a context is "active" or not. |
|
458 | + * |
|
459 | + * @param $context |
|
460 | + * @return bool |
|
461 | + * @throws EE_Error |
|
462 | + * @throws InvalidIdentifierException |
|
463 | + */ |
|
464 | + public function is_context_active($context) |
|
465 | + { |
|
466 | + $this->validate_context($context); |
|
467 | + return filter_var( |
|
468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
469 | + FILTER_VALIDATE_BOOLEAN |
|
470 | + ); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Validates the incoming context to verify it matches a registered context for the related message type. |
|
476 | + * |
|
477 | + * @param string $context |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidIdentifierException |
|
480 | + */ |
|
481 | + public function validate_context($context) |
|
482 | + { |
|
483 | + $contexts = $this->contexts_config(); |
|
484 | + if (! isset($contexts[ $context ])) { |
|
485 | + throw new InvalidIdentifierException( |
|
486 | + '', |
|
487 | + '', |
|
488 | + sprintf( |
|
489 | + esc_html__( |
|
490 | + 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
491 | + 'event_espresso' |
|
492 | + ), |
|
493 | + $context, |
|
494 | + implode(',', array_keys($contexts)) |
|
495 | + ) |
|
496 | + ); |
|
497 | + } |
|
498 | + } |
|
499 | 499 | } |
@@ -11,25 +11,25 @@ |
||
11 | 11 | class EE_Ticket_Price extends EE_Base_Class |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $props_n_values |
|
16 | - * @param string $timezone |
|
17 | - * @return EE_Ticket_Price|mixed |
|
18 | - */ |
|
19 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
20 | - { |
|
21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
22 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
23 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values |
|
16 | + * @param string $timezone |
|
17 | + * @return EE_Ticket_Price|mixed |
|
18 | + */ |
|
19 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
20 | + { |
|
21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
22 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @param array $props_n_values |
|
28 | - * @param string $timezone |
|
29 | - * @return EE_Ticket_Price |
|
30 | - */ |
|
31 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
32 | - { |
|
33 | - return new self($props_n_values, true, $timezone); |
|
34 | - } |
|
26 | + /** |
|
27 | + * @param array $props_n_values |
|
28 | + * @param string $timezone |
|
29 | + * @return EE_Ticket_Price |
|
30 | + */ |
|
31 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
32 | + { |
|
33 | + return new self($props_n_values, true, $timezone); |
|
34 | + } |
|
35 | 35 | } |
@@ -12,25 +12,25 @@ |
||
12 | 12 | class EE_Ticket_Template extends EE_Base_Class |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @param array $props_n_values |
|
17 | - * @param string $timezone |
|
18 | - * @return EE_Ticket_Template|mixed |
|
19 | - */ |
|
20 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | - { |
|
22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | - } |
|
15 | + /** |
|
16 | + * @param array $props_n_values |
|
17 | + * @param string $timezone |
|
18 | + * @return EE_Ticket_Template|mixed |
|
19 | + */ |
|
20 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | + { |
|
22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param array $props_n_values |
|
29 | - * @param string $timezone |
|
30 | - * @return EE_Ticket_Template |
|
31 | - */ |
|
32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | - { |
|
34 | - return new self($props_n_values, true, $timezone); |
|
35 | - } |
|
27 | + /** |
|
28 | + * @param array $props_n_values |
|
29 | + * @param string $timezone |
|
30 | + * @return EE_Ticket_Template |
|
31 | + */ |
|
32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | + { |
|
34 | + return new self($props_n_values, true, $timezone); |
|
35 | + } |
|
36 | 36 | } |
@@ -10,115 +10,115 @@ |
||
10 | 10 | class EE_Extra_Meta extends EE_Base_Class |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $props_n_values |
|
15 | - * @return EE_Extra_Meta|mixed |
|
16 | - */ |
|
17 | - public static function new_instance($props_n_values = array()) |
|
18 | - { |
|
19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | - return $has_object ? $has_object : new self($props_n_values); |
|
21 | - } |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param array $props_n_values |
|
26 | - * @return EE_Extra_Meta |
|
27 | - */ |
|
28 | - public static function new_instance_from_db($props_n_values = array()) |
|
29 | - { |
|
30 | - return new self($props_n_values, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Gets FK_ID |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function FK_ID() |
|
40 | - { |
|
41 | - return $this->get('FK_ID'); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Sets FK_ID |
|
47 | - * |
|
48 | - * @param int $FK_ID |
|
49 | - * @return boolean |
|
50 | - */ |
|
51 | - public function set_FK_ID($FK_ID) |
|
52 | - { |
|
53 | - $this->set('FK_ID', $FK_ID); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets model |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function model() |
|
63 | - { |
|
64 | - return $this->get('EXM_model'); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Sets model |
|
70 | - * |
|
71 | - * @param string $model |
|
72 | - * @return boolean |
|
73 | - */ |
|
74 | - public function set_model($model) |
|
75 | - { |
|
76 | - $this->set('EXM_model', $model); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Gets key |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function key() |
|
86 | - { |
|
87 | - return $this->get('EXM_key'); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets key |
|
93 | - * |
|
94 | - * @param string $key |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public function set_key($key) |
|
98 | - { |
|
99 | - $this->set('EXM_key', $key); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Gets value |
|
105 | - * |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function value() |
|
109 | - { |
|
110 | - return $this->get('EXM_value'); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Sets value |
|
116 | - * |
|
117 | - * @param string $value |
|
118 | - * @return boolean |
|
119 | - */ |
|
120 | - public function set_value($value) |
|
121 | - { |
|
122 | - $this->set('EXM_value', $value); |
|
123 | - } |
|
13 | + /** |
|
14 | + * @param array $props_n_values |
|
15 | + * @return EE_Extra_Meta|mixed |
|
16 | + */ |
|
17 | + public static function new_instance($props_n_values = array()) |
|
18 | + { |
|
19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | + return $has_object ? $has_object : new self($props_n_values); |
|
21 | + } |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param array $props_n_values |
|
26 | + * @return EE_Extra_Meta |
|
27 | + */ |
|
28 | + public static function new_instance_from_db($props_n_values = array()) |
|
29 | + { |
|
30 | + return new self($props_n_values, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Gets FK_ID |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function FK_ID() |
|
40 | + { |
|
41 | + return $this->get('FK_ID'); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Sets FK_ID |
|
47 | + * |
|
48 | + * @param int $FK_ID |
|
49 | + * @return boolean |
|
50 | + */ |
|
51 | + public function set_FK_ID($FK_ID) |
|
52 | + { |
|
53 | + $this->set('FK_ID', $FK_ID); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets model |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function model() |
|
63 | + { |
|
64 | + return $this->get('EXM_model'); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Sets model |
|
70 | + * |
|
71 | + * @param string $model |
|
72 | + * @return boolean |
|
73 | + */ |
|
74 | + public function set_model($model) |
|
75 | + { |
|
76 | + $this->set('EXM_model', $model); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Gets key |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function key() |
|
86 | + { |
|
87 | + return $this->get('EXM_key'); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets key |
|
93 | + * |
|
94 | + * @param string $key |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public function set_key($key) |
|
98 | + { |
|
99 | + $this->set('EXM_key', $key); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Gets value |
|
105 | + * |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function value() |
|
109 | + { |
|
110 | + return $this->get('EXM_value'); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Sets value |
|
116 | + * |
|
117 | + * @param string $value |
|
118 | + * @return boolean |
|
119 | + */ |
|
120 | + public function set_value($value) |
|
121 | + { |
|
122 | + $this->set('EXM_value', $value); |
|
123 | + } |
|
124 | 124 | } |