@@ -13,803 +13,803 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * constructor. |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->_caf_hooks(); |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
27 | - * |
|
28 | - * @since 4.3.2 |
|
29 | - * |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - private function _caf_hooks() |
|
33 | - { |
|
34 | - add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
35 | - add_filter( |
|
36 | - 'FHEE__EE_Email_messenger__get_validator_config', |
|
37 | - array($this, 'email_messenger_validator_config'), |
|
38 | - 5, |
|
39 | - 2 |
|
40 | - ); |
|
41 | - add_filter( |
|
42 | - 'FHEE__EE_Email_messenger__get_template_fields', |
|
43 | - array($this, 'email_messenger_template_fields'), |
|
44 | - 5, |
|
45 | - 2 |
|
46 | - ); |
|
47 | - add_filter( |
|
48 | - 'FHEE__EE_Html_messenger__get_template_fields', |
|
49 | - array($this, 'html_messenger_template_fields'), |
|
50 | - 5, |
|
51 | - 2 |
|
52 | - ); |
|
53 | - add_filter( |
|
54 | - 'FHEE__EE_Html_messenger__get_validator_config', |
|
55 | - array($this, 'html_messenger_validator_config'), |
|
56 | - 5, |
|
57 | - 2 |
|
58 | - ); |
|
59 | - add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Pdf_messenger__get_validator_config', |
|
62 | - array($this, 'pdf_messenger_validator_config'), |
|
63 | - 5, |
|
64 | - 2 |
|
65 | - ); |
|
66 | - add_filter( |
|
67 | - 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
68 | - array($this, 'new_default_templates'), |
|
69 | - 5, |
|
70 | - 7 |
|
71 | - ); |
|
72 | - add_filter( |
|
73 | - 'FHEE__EE_Messages_Base__get_valid_shortcodes', |
|
74 | - array($this, 'message_types_valid_shortcodes'), |
|
75 | - 5, |
|
76 | - 2 |
|
77 | - ); |
|
78 | - |
|
79 | - // shortcode parsers |
|
80 | - add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
81 | - add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
82 | - add_filter( |
|
83 | - 'FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
84 | - array($this, 'additional_recipient_details_shortcodes'), |
|
85 | - 5, |
|
86 | - 2 |
|
87 | - ); |
|
88 | - add_filter( |
|
89 | - 'FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
90 | - array($this, 'additional_recipient_details_parser'), |
|
91 | - 5, |
|
92 | - 5 |
|
93 | - ); |
|
94 | - add_filter( |
|
95 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
96 | - array($this, 'additional_primary_registration_details_shortcodes'), |
|
97 | - 5, |
|
98 | - 2 |
|
99 | - ); |
|
100 | - add_filter( |
|
101 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
102 | - array($this, 'additional_primary_registration_details_parser'), |
|
103 | - 5, |
|
104 | - 5 |
|
105 | - ); |
|
106 | - |
|
107 | - /** |
|
108 | - * @since 4.2.0 |
|
109 | - */ |
|
110 | - add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
111 | - add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
112 | - |
|
113 | - /** |
|
114 | - * @since 4.3.0 |
|
115 | - */ |
|
116 | - // eat our own dog food! |
|
117 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
118 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
119 | - do_action('EE_Brewing_Regular___messages_caf'); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
125 | - * messages system. |
|
126 | - * |
|
127 | - * @param array $dir_ref original array of paths |
|
128 | - * |
|
129 | - * @return array appended paths |
|
130 | - */ |
|
131 | - public function messages_autoload_paths($dir_ref) |
|
132 | - { |
|
133 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
134 | - |
|
135 | - return $dir_ref; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
140 | - { |
|
141 | - $validator_config['attendee_list'] = array( |
|
142 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
143 | - 'required' => array('[ATTENDEE_LIST]'), |
|
144 | - ); |
|
145 | - $validator_config['question_list'] = array( |
|
146 | - 'shortcodes' => array('question'), |
|
147 | - 'required' => array('[QUESTION_LIST]'), |
|
148 | - ); |
|
149 | - |
|
150 | - return $validator_config; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
155 | - { |
|
156 | - $validator_config['attendee_list'] = array( |
|
157 | - 'shortcodes' => array('attendee', 'question_list'), |
|
158 | - 'required' => array('[ATTENDEE_LIST]'), |
|
159 | - ); |
|
160 | - $validator_config['question_list'] = array( |
|
161 | - 'shortcodes' => array('question'), |
|
162 | - 'required' => array('[QUESTION_LIST]'), |
|
163 | - ); |
|
164 | - |
|
165 | - return $validator_config; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
170 | - { |
|
171 | - $validator_config['attendee_list'] = array( |
|
172 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
173 | - 'required' => array('[ATTENDEE_LIST]'), |
|
174 | - ); |
|
175 | - $validator_config['question_list'] = array( |
|
176 | - 'shortcodes' => array('question'), |
|
177 | - 'required' => array('[QUESTION_LIST]'), |
|
178 | - ); |
|
179 | - |
|
180 | - return $validator_config; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
185 | - { |
|
186 | - $template_fields['extra']['content']['question_list'] = array( |
|
187 | - 'input' => 'textarea', |
|
188 | - 'label' => '[QUESTION_LIST]', |
|
189 | - 'type' => 'string', |
|
190 | - 'required' => true, |
|
191 | - 'validation' => true, |
|
192 | - 'format' => '%s', |
|
193 | - 'css_class' => 'large-text', |
|
194 | - 'rows' => '5', |
|
195 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
196 | - ); |
|
197 | - |
|
198 | - return $template_fields; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
203 | - { |
|
204 | - $template_fields['extra']['content']['question_list'] = array( |
|
205 | - 'input' => 'textarea', |
|
206 | - 'label' => '[QUESTION_LIST]', |
|
207 | - 'type' => 'string', |
|
208 | - 'required' => true, |
|
209 | - 'validation' => true, |
|
210 | - 'format' => '%s', |
|
211 | - 'css_class' => 'large-text', |
|
212 | - 'rows' => '5', |
|
213 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
214 | - ); |
|
215 | - |
|
216 | - return $template_fields; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
221 | - { |
|
222 | - $template_fields['extra']['content']['question_list'] = array( |
|
223 | - 'input' => 'textarea', |
|
224 | - 'label' => '[QUESTION_LIST]', |
|
225 | - 'type' => 'string', |
|
226 | - 'required' => true, |
|
227 | - 'validation' => true, |
|
228 | - 'format' => '%s', |
|
229 | - 'css_class' => 'large-text', |
|
230 | - 'rows' => '5', |
|
231 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
232 | - ); |
|
233 | - |
|
234 | - return $template_fields; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - public function new_default_templates( |
|
239 | - $contents, |
|
240 | - $actual_path, |
|
241 | - EE_messenger $messenger, |
|
242 | - EE_message_type $message_type, |
|
243 | - $field, |
|
244 | - $context, |
|
245 | - EE_Messages_Template_Pack $template_pack |
|
246 | - ) { |
|
247 | - |
|
248 | - // we're only modifying templates for the default template pack |
|
249 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
250 | - return $contents; |
|
251 | - } |
|
252 | - |
|
253 | - // the template file name we're replacing contents for. |
|
254 | - $template_file_prefix = $field . '_' . $context; |
|
255 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
256 | - |
|
257 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
258 | - |
|
259 | - if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
260 | - switch ($template_file_prefix) { |
|
261 | - case 'question_list_admin': |
|
262 | - case 'question_list_attendee': |
|
263 | - case 'question_list_primary_attendee': |
|
264 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
265 | - $contents = EEH_Template::display_template($path, array(), true); |
|
266 | - break; |
|
267 | - |
|
268 | - case 'attendee_list_primary_attendee': |
|
269 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
270 | - $contents = EEH_Template::display_template($path, array(), true); |
|
271 | - break; |
|
272 | - |
|
273 | - case 'attendee_list_admin': |
|
274 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
275 | - $contents = EEH_Template::display_template( |
|
276 | - $path, |
|
277 | - array(), |
|
278 | - true |
|
279 | - ); |
|
280 | - break; |
|
281 | - |
|
282 | - case 'attendee_list_attendee': |
|
283 | - $contents = ''; |
|
284 | - break; |
|
285 | - |
|
286 | - case 'event_list_attendee': |
|
287 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
288 | - $contents = EEH_Template::display_template($path, array(), true); |
|
289 | - break; |
|
290 | - } |
|
291 | - } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
292 | - switch ($template_file_prefix) { |
|
293 | - case 'content_attendee': |
|
294 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
295 | - $contents = EEH_Template::display_template($path, array(), true); |
|
296 | - break; |
|
297 | - |
|
298 | - case 'newsletter_content_attendee': |
|
299 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
300 | - $contents = EEH_Template::display_template($path, array(), true); |
|
301 | - break; |
|
302 | - |
|
303 | - case 'newsletter_subject_attendee': |
|
304 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
305 | - $contents = EEH_Template::display_template($path, array(), true); |
|
306 | - break; |
|
307 | - } |
|
308 | - } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
309 | - switch ($template_file_prefix) { |
|
310 | - case 'attendee_list_purchaser': |
|
311 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
312 | - $contents = EEH_Template::display_template($path, array(), true); |
|
313 | - break; |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - return $contents; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
322 | - { |
|
323 | - // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
324 | - $include_with = array( |
|
325 | - 'registration', |
|
326 | - 'cancelled_registration', |
|
327 | - 'declined_registration', |
|
328 | - 'not_approved_registration', |
|
329 | - 'payment_declined', |
|
330 | - 'payment_failed', |
|
331 | - 'payment_cancelled', |
|
332 | - 'payment', |
|
333 | - 'payment_reminder', |
|
334 | - 'pending_approval', |
|
335 | - 'registration_summary', |
|
336 | - 'invoice', |
|
337 | - 'receipt', |
|
338 | - ); |
|
339 | - if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
340 | - $contexts = array_keys($msg->get_contexts()); |
|
341 | - foreach ($contexts as $context) { |
|
342 | - $valid_shortcodes[ $context ][] = 'question_list'; |
|
343 | - $valid_shortcodes[ $context ][] = 'question'; |
|
344 | - } |
|
345 | - } |
|
346 | - |
|
347 | - return $valid_shortcodes; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
352 | - { |
|
353 | - $shortcodes['[ANSWER_*]'] = __( |
|
354 | - 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
355 | - 'event_espresso' |
|
356 | - ); |
|
357 | - |
|
358 | - return $shortcodes; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
363 | - { |
|
364 | - |
|
365 | - if (strpos($shortcode, '[ANSWER_*') === false |
|
366 | - || ! isset($extra_data['data']->questions) |
|
367 | - || ! isset($extra_data['data']->registrations) |
|
368 | - ) { |
|
369 | - return $parsed; |
|
370 | - } |
|
371 | - |
|
372 | - // let's get the question from the code. |
|
373 | - $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
374 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
375 | - |
|
376 | - $registration = $data instanceof EE_Registration ? $data : null; |
|
377 | - $registration = ! $registration instanceof EE_Registration && is_array( |
|
378 | - $extra_data |
|
379 | - ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
380 | - |
|
381 | - $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
382 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
383 | - $extra_data |
|
384 | - ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
385 | - |
|
386 | - if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | - return $parsed; |
|
388 | - } |
|
389 | - |
|
390 | - // now let's figure out which question has this text. |
|
391 | - foreach ($aee->questions as $ansid => $question) { |
|
392 | - if ($question instanceof EE_Question |
|
393 | - && trim($question->display_text()) == trim($shortcode) |
|
394 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
395 | - ) { |
|
396 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
397 | - 'ANS_value', |
|
398 | - 'no_wpautop' |
|
399 | - ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - // nothing! |
|
404 | - return $parsed; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
410 | - * |
|
411 | - * @since 4.2 |
|
412 | - * |
|
413 | - * @param array $shortcodes array of shortcodes and |
|
414 | - * descriptions |
|
415 | - * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
416 | - * |
|
417 | - * @return array array of shortcodes and |
|
418 | - * descriptions |
|
419 | - */ |
|
420 | - public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
421 | - { |
|
422 | - $shortcodes['[DTT_NAME]'] = __( |
|
423 | - 'This will be parsed to the Title given for a Datetime', |
|
424 | - 'event_espresso' |
|
425 | - ); |
|
426 | - $shortcodes['[DTT_DESCRIPTION]'] = __( |
|
427 | - 'This will be parsed to the description for a Datetime', |
|
428 | - 'event_espresso' |
|
429 | - ); |
|
430 | - $shortcodes['[DTT_NAME_OR_DATES]'] = __( |
|
431 | - 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
432 | - 'event_espresso' |
|
433 | - ); |
|
434 | - |
|
435 | - return $shortcodes; |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Callback for additional shortcodes parser filter used for adding parser for new |
|
441 | - * Datetime shortcodes |
|
442 | - * |
|
443 | - * @since 4.2 |
|
444 | - * |
|
445 | - * @param string $parsed The finished parsed string for the given shortcode. |
|
446 | - * @param string $shortcode The shortcode being parsed. |
|
447 | - * @param object $data The incoming data object for the Shortcode Parser. |
|
448 | - * @param object $extra_data The incoming extra date object for the Shortcode |
|
449 | - * Parser. |
|
450 | - * @param EE_Datetime_Shortcodes $shortcode_parser |
|
451 | - * |
|
452 | - * @return string The new parsed string. |
|
453 | - */ |
|
454 | - public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
455 | - { |
|
456 | - |
|
457 | - if (! $data instanceof EE_Datetime) { |
|
458 | - return ''; // get out because we can only parse with the datetime object. |
|
459 | - } |
|
460 | - |
|
461 | - switch ($shortcode) { |
|
462 | - case '[DTT_NAME]': |
|
463 | - return $data->name(); |
|
464 | - break; |
|
465 | - case '[DTT_DESCRIPTION]': |
|
466 | - return $data->description(); |
|
467 | - break; |
|
468 | - case '[DTT_NAME_OR_DATES]': |
|
469 | - return $data->get_dtt_display_name(true); |
|
470 | - break; |
|
471 | - default: |
|
472 | - return $parsed; |
|
473 | - break; |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
479 | - { |
|
480 | - $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __( |
|
481 | - 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
482 | - 'event_espresso' |
|
483 | - ); |
|
484 | - |
|
485 | - return $shortcodes; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
491 | - * |
|
492 | - * @param string $parsed The original parsed content for the shortcode |
|
493 | - * @param string $shortcode The shortcode being parsed |
|
494 | - * @param array $data The shortcode parser data array |
|
495 | - * @param array $extra_data The shortcode parser extra data array |
|
496 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
497 | - * |
|
498 | - * @return string |
|
499 | - */ |
|
500 | - public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
501 | - { |
|
502 | - |
|
503 | - if (array($data) && ! isset($data['data'])) { |
|
504 | - return $parsed; |
|
505 | - } |
|
506 | - |
|
507 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
508 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
509 | - |
|
510 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
511 | - return $parsed; |
|
512 | - } |
|
513 | - |
|
514 | - switch ($shortcode) { |
|
515 | - case '[RECIPIENT_QUESTION_LIST]': |
|
516 | - $att = $recipient->att_obj; |
|
517 | - $registrations_on_attendee = $att instanceof EE_Attendee |
|
518 | - ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
519 | - : array(); |
|
520 | - $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
521 | - $answers = array(); |
|
522 | - |
|
523 | - $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
524 | - ? $data['template']['question_list'] |
|
525 | - : $extra_data['template']['question_list']; |
|
526 | - $valid_shortcodes = array('question'); |
|
527 | - |
|
528 | - // if the context is main_content then get all answers for all registrations on this attendee |
|
529 | - if ($data['data'] instanceof EE_Messages_Addressee) { |
|
530 | - foreach ($registrations_on_attendee as $reg) { |
|
531 | - if ($reg instanceof EE_Registration) { |
|
532 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
533 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
534 | - : array(); |
|
535 | - foreach ($anss as $ans) { |
|
536 | - if ($ans instanceof EE_Answer) { |
|
537 | - $answers[ $ans->ID() ] = $ans; |
|
538 | - } |
|
539 | - } |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
545 | - if ($data['data'] instanceof EE_Event) { |
|
546 | - $event = $data['data']; |
|
547 | - foreach ($registrations_on_attendee as $reg) { |
|
548 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
549 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
550 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
551 | - : array(); |
|
552 | - foreach ($anss as $ans) { |
|
553 | - if ($ans instanceof EE_Answer) { |
|
554 | - $answers[ $ans->ID() ] = $ans; |
|
555 | - } |
|
556 | - } |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
560 | - |
|
561 | - $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
562 | - |
|
563 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
564 | - // object on it. |
|
565 | - if (! isset($extra_data['data'])) { |
|
566 | - $extra_data['data'] = $recipient; |
|
567 | - } |
|
568 | - |
|
569 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
570 | - $shortcode_parser, |
|
571 | - $questions, |
|
572 | - $answers, |
|
573 | - $template, |
|
574 | - $valid_shortcodes, |
|
575 | - $extra_data |
|
576 | - ); |
|
577 | - break; |
|
578 | - |
|
579 | - default: |
|
580 | - return $parsed; |
|
581 | - break; |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
587 | - { |
|
588 | - $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __( |
|
589 | - 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
590 | - 'event_espresso' |
|
591 | - ); |
|
592 | - |
|
593 | - return $shortcodes; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
599 | - * |
|
600 | - * @param string $parsed The original parsed content for the shortcode |
|
601 | - * @param string $shortcode The shortcode being parsed |
|
602 | - * @param array $data The shortcode parser data array |
|
603 | - * @param array $extra_data The shortcode parser extra data array |
|
604 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
605 | - * |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function additional_primary_registration_details_parser( |
|
609 | - $parsed, |
|
610 | - $shortcode, |
|
611 | - $data, |
|
612 | - $extra_data, |
|
613 | - $shortcode_parser |
|
614 | - ) { |
|
615 | - if (array($data) && ! isset($data['data'])) { |
|
616 | - return $parsed; |
|
617 | - } |
|
618 | - |
|
619 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
620 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
621 | - |
|
622 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
623 | - return $parsed; |
|
624 | - } |
|
625 | - |
|
626 | - switch ($shortcode) { |
|
627 | - case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
|
628 | - if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | - return ''; |
|
630 | - } |
|
631 | - $registration = $recipient->primary_reg_obj; |
|
632 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
633 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
634 | - : array(); |
|
635 | - if (empty($answers)) { |
|
636 | - return ''; |
|
637 | - } |
|
638 | - $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
639 | - ? $data['template']['question_list'] |
|
640 | - : $extra_data['template']['question_list']; |
|
641 | - $valid_shortcodes = array('question'); |
|
642 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
643 | - $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
644 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
645 | - // object on it. |
|
646 | - if (! isset($extra_data['data'])) { |
|
647 | - $extra_data['data'] = $recipient; |
|
648 | - } |
|
649 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
650 | - $shortcode_parser, |
|
651 | - $questions, |
|
652 | - $answers, |
|
653 | - $template, |
|
654 | - $valid_shortcodes, |
|
655 | - $extra_data |
|
656 | - ); |
|
657 | - break; |
|
658 | - |
|
659 | - default: |
|
660 | - return $parsed; |
|
661 | - break; |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - /** |
|
667 | - * Takes care of registering the message types that are only available in caffeinated EE. |
|
668 | - * |
|
669 | - * @since 4.3.2 |
|
670 | - * |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - public function register_caf_message_types() |
|
674 | - { |
|
675 | - // register newsletter message type |
|
676 | - $setup_args = array( |
|
677 | - 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
678 | - 'autoloadpaths' => array( |
|
679 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
680 | - ), |
|
681 | - 'messengers_to_activate_with' => array('email'), |
|
682 | - 'messengers_to_validate_with' => array('email'), |
|
683 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
684 | - ); |
|
685 | - EE_Register_Message_Type::register('newsletter', $setup_args); |
|
686 | - |
|
687 | - // register payment reminder message type |
|
688 | - $setup_args = array( |
|
689 | - 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
690 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
691 | - 'messengers_to_activate_with' => array('email'), |
|
692 | - 'messengers_to_validate_with' => array('email'), |
|
693 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
694 | - ); |
|
695 | - EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
696 | - |
|
697 | - // register payment declined message type |
|
698 | - $setup_args = array( |
|
699 | - 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
700 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
701 | - 'messengers_to_activate_with' => array('email'), |
|
702 | - 'messengers_to_validate_with' => array('email'), |
|
703 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
704 | - ); |
|
705 | - EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
706 | - |
|
707 | - // register registration declined message type |
|
708 | - $setup_args = array( |
|
709 | - 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
710 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
711 | - 'messengers_to_activate_with' => array('email'), |
|
712 | - 'messengers_to_validate_with' => array('email'), |
|
713 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
714 | - ); |
|
715 | - EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
716 | - |
|
717 | - // register registration cancelled message type |
|
718 | - $setup_args = array( |
|
719 | - 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
720 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
721 | - 'messengers_to_activate_with' => array('email'), |
|
722 | - 'messengers_to_validate_with' => array('email'), |
|
723 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
724 | - ); |
|
725 | - EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
726 | - |
|
727 | - |
|
728 | - // register payment failed message type |
|
729 | - $setup_args = array( |
|
730 | - 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
731 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
732 | - 'messengers_to_activate_with' => array('email'), |
|
733 | - 'messengers_to_validate_with' => array('email'), |
|
734 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
735 | - ); |
|
736 | - EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
737 | - |
|
738 | - // register payment declined message type |
|
739 | - $setup_args = array( |
|
740 | - 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
741 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
742 | - 'messengers_to_activate_with' => array('email'), |
|
743 | - 'messengers_to_validate_with' => array('email'), |
|
744 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
745 | - ); |
|
746 | - EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
752 | - * |
|
753 | - * @since 4.3.2 |
|
754 | - * |
|
755 | - * @return void |
|
756 | - */ |
|
757 | - public function register_caf_shortcodes() |
|
758 | - { |
|
759 | - $setup_args = array( |
|
760 | - 'autoloadpaths' => array( |
|
761 | - EE_CAF_LIBRARIES . 'shortcodes/', |
|
762 | - ), |
|
763 | - 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
764 | - 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
765 | - 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]'), |
|
766 | - ); |
|
767 | - EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * Parses a question list shortcode using given data and template |
|
773 | - * |
|
774 | - * @param \EE_Shortcodes $shortcode_parser |
|
775 | - * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
776 | - * @param EE_Answer[] $answers An array of answer objects |
|
777 | - * @param string $template Template content to be parsed. |
|
778 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
779 | - * @param array $extra_data Extra data that might be used when parsing the template. |
|
780 | - */ |
|
781 | - protected function _parse_question_list_for_primary_or_recipient_registration( |
|
782 | - $shortcode_parser, |
|
783 | - $questions, |
|
784 | - $answers, |
|
785 | - $template, |
|
786 | - $valid_shortcodes, |
|
787 | - $extra_data |
|
788 | - ) { |
|
789 | - $question_list = ''; |
|
790 | - /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
791 | - $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
792 | - foreach ($answers as $answer) { |
|
793 | - if ($answer instanceof EE_Answer) { |
|
794 | - // first see if the question is in our $questions array. If not then try to get from answer object. |
|
795 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
796 | - $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
797 | - if (! $question instanceof EE_Question |
|
798 | - || ( |
|
799 | - $question instanceof EE_Question |
|
800 | - && $question->admin_only() |
|
801 | - ) |
|
802 | - ) { |
|
803 | - continue; |
|
804 | - } |
|
805 | - $question_list .= $shortcode_helper->parse_question_list_template( |
|
806 | - $template, |
|
807 | - $answer, |
|
808 | - $valid_shortcodes, |
|
809 | - $extra_data |
|
810 | - ); |
|
811 | - } |
|
812 | - } |
|
813 | - return $question_list; |
|
814 | - } |
|
16 | + /** |
|
17 | + * constructor. |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->_caf_hooks(); |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
27 | + * |
|
28 | + * @since 4.3.2 |
|
29 | + * |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + private function _caf_hooks() |
|
33 | + { |
|
34 | + add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
35 | + add_filter( |
|
36 | + 'FHEE__EE_Email_messenger__get_validator_config', |
|
37 | + array($this, 'email_messenger_validator_config'), |
|
38 | + 5, |
|
39 | + 2 |
|
40 | + ); |
|
41 | + add_filter( |
|
42 | + 'FHEE__EE_Email_messenger__get_template_fields', |
|
43 | + array($this, 'email_messenger_template_fields'), |
|
44 | + 5, |
|
45 | + 2 |
|
46 | + ); |
|
47 | + add_filter( |
|
48 | + 'FHEE__EE_Html_messenger__get_template_fields', |
|
49 | + array($this, 'html_messenger_template_fields'), |
|
50 | + 5, |
|
51 | + 2 |
|
52 | + ); |
|
53 | + add_filter( |
|
54 | + 'FHEE__EE_Html_messenger__get_validator_config', |
|
55 | + array($this, 'html_messenger_validator_config'), |
|
56 | + 5, |
|
57 | + 2 |
|
58 | + ); |
|
59 | + add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Pdf_messenger__get_validator_config', |
|
62 | + array($this, 'pdf_messenger_validator_config'), |
|
63 | + 5, |
|
64 | + 2 |
|
65 | + ); |
|
66 | + add_filter( |
|
67 | + 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
68 | + array($this, 'new_default_templates'), |
|
69 | + 5, |
|
70 | + 7 |
|
71 | + ); |
|
72 | + add_filter( |
|
73 | + 'FHEE__EE_Messages_Base__get_valid_shortcodes', |
|
74 | + array($this, 'message_types_valid_shortcodes'), |
|
75 | + 5, |
|
76 | + 2 |
|
77 | + ); |
|
78 | + |
|
79 | + // shortcode parsers |
|
80 | + add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
81 | + add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
82 | + add_filter( |
|
83 | + 'FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
84 | + array($this, 'additional_recipient_details_shortcodes'), |
|
85 | + 5, |
|
86 | + 2 |
|
87 | + ); |
|
88 | + add_filter( |
|
89 | + 'FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
90 | + array($this, 'additional_recipient_details_parser'), |
|
91 | + 5, |
|
92 | + 5 |
|
93 | + ); |
|
94 | + add_filter( |
|
95 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
96 | + array($this, 'additional_primary_registration_details_shortcodes'), |
|
97 | + 5, |
|
98 | + 2 |
|
99 | + ); |
|
100 | + add_filter( |
|
101 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
102 | + array($this, 'additional_primary_registration_details_parser'), |
|
103 | + 5, |
|
104 | + 5 |
|
105 | + ); |
|
106 | + |
|
107 | + /** |
|
108 | + * @since 4.2.0 |
|
109 | + */ |
|
110 | + add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
111 | + add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
112 | + |
|
113 | + /** |
|
114 | + * @since 4.3.0 |
|
115 | + */ |
|
116 | + // eat our own dog food! |
|
117 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
118 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
119 | + do_action('EE_Brewing_Regular___messages_caf'); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
125 | + * messages system. |
|
126 | + * |
|
127 | + * @param array $dir_ref original array of paths |
|
128 | + * |
|
129 | + * @return array appended paths |
|
130 | + */ |
|
131 | + public function messages_autoload_paths($dir_ref) |
|
132 | + { |
|
133 | + $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
134 | + |
|
135 | + return $dir_ref; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
140 | + { |
|
141 | + $validator_config['attendee_list'] = array( |
|
142 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
143 | + 'required' => array('[ATTENDEE_LIST]'), |
|
144 | + ); |
|
145 | + $validator_config['question_list'] = array( |
|
146 | + 'shortcodes' => array('question'), |
|
147 | + 'required' => array('[QUESTION_LIST]'), |
|
148 | + ); |
|
149 | + |
|
150 | + return $validator_config; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
155 | + { |
|
156 | + $validator_config['attendee_list'] = array( |
|
157 | + 'shortcodes' => array('attendee', 'question_list'), |
|
158 | + 'required' => array('[ATTENDEE_LIST]'), |
|
159 | + ); |
|
160 | + $validator_config['question_list'] = array( |
|
161 | + 'shortcodes' => array('question'), |
|
162 | + 'required' => array('[QUESTION_LIST]'), |
|
163 | + ); |
|
164 | + |
|
165 | + return $validator_config; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
170 | + { |
|
171 | + $validator_config['attendee_list'] = array( |
|
172 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
173 | + 'required' => array('[ATTENDEE_LIST]'), |
|
174 | + ); |
|
175 | + $validator_config['question_list'] = array( |
|
176 | + 'shortcodes' => array('question'), |
|
177 | + 'required' => array('[QUESTION_LIST]'), |
|
178 | + ); |
|
179 | + |
|
180 | + return $validator_config; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
185 | + { |
|
186 | + $template_fields['extra']['content']['question_list'] = array( |
|
187 | + 'input' => 'textarea', |
|
188 | + 'label' => '[QUESTION_LIST]', |
|
189 | + 'type' => 'string', |
|
190 | + 'required' => true, |
|
191 | + 'validation' => true, |
|
192 | + 'format' => '%s', |
|
193 | + 'css_class' => 'large-text', |
|
194 | + 'rows' => '5', |
|
195 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
196 | + ); |
|
197 | + |
|
198 | + return $template_fields; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
203 | + { |
|
204 | + $template_fields['extra']['content']['question_list'] = array( |
|
205 | + 'input' => 'textarea', |
|
206 | + 'label' => '[QUESTION_LIST]', |
|
207 | + 'type' => 'string', |
|
208 | + 'required' => true, |
|
209 | + 'validation' => true, |
|
210 | + 'format' => '%s', |
|
211 | + 'css_class' => 'large-text', |
|
212 | + 'rows' => '5', |
|
213 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
214 | + ); |
|
215 | + |
|
216 | + return $template_fields; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
221 | + { |
|
222 | + $template_fields['extra']['content']['question_list'] = array( |
|
223 | + 'input' => 'textarea', |
|
224 | + 'label' => '[QUESTION_LIST]', |
|
225 | + 'type' => 'string', |
|
226 | + 'required' => true, |
|
227 | + 'validation' => true, |
|
228 | + 'format' => '%s', |
|
229 | + 'css_class' => 'large-text', |
|
230 | + 'rows' => '5', |
|
231 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
232 | + ); |
|
233 | + |
|
234 | + return $template_fields; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + public function new_default_templates( |
|
239 | + $contents, |
|
240 | + $actual_path, |
|
241 | + EE_messenger $messenger, |
|
242 | + EE_message_type $message_type, |
|
243 | + $field, |
|
244 | + $context, |
|
245 | + EE_Messages_Template_Pack $template_pack |
|
246 | + ) { |
|
247 | + |
|
248 | + // we're only modifying templates for the default template pack |
|
249 | + if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
250 | + return $contents; |
|
251 | + } |
|
252 | + |
|
253 | + // the template file name we're replacing contents for. |
|
254 | + $template_file_prefix = $field . '_' . $context; |
|
255 | + $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
256 | + |
|
257 | + $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
258 | + |
|
259 | + if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
260 | + switch ($template_file_prefix) { |
|
261 | + case 'question_list_admin': |
|
262 | + case 'question_list_attendee': |
|
263 | + case 'question_list_primary_attendee': |
|
264 | + $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
265 | + $contents = EEH_Template::display_template($path, array(), true); |
|
266 | + break; |
|
267 | + |
|
268 | + case 'attendee_list_primary_attendee': |
|
269 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
270 | + $contents = EEH_Template::display_template($path, array(), true); |
|
271 | + break; |
|
272 | + |
|
273 | + case 'attendee_list_admin': |
|
274 | + $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
275 | + $contents = EEH_Template::display_template( |
|
276 | + $path, |
|
277 | + array(), |
|
278 | + true |
|
279 | + ); |
|
280 | + break; |
|
281 | + |
|
282 | + case 'attendee_list_attendee': |
|
283 | + $contents = ''; |
|
284 | + break; |
|
285 | + |
|
286 | + case 'event_list_attendee': |
|
287 | + $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
288 | + $contents = EEH_Template::display_template($path, array(), true); |
|
289 | + break; |
|
290 | + } |
|
291 | + } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
292 | + switch ($template_file_prefix) { |
|
293 | + case 'content_attendee': |
|
294 | + $path = $base_path . $msg_prefix . 'content.template.php'; |
|
295 | + $contents = EEH_Template::display_template($path, array(), true); |
|
296 | + break; |
|
297 | + |
|
298 | + case 'newsletter_content_attendee': |
|
299 | + $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
300 | + $contents = EEH_Template::display_template($path, array(), true); |
|
301 | + break; |
|
302 | + |
|
303 | + case 'newsletter_subject_attendee': |
|
304 | + $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
305 | + $contents = EEH_Template::display_template($path, array(), true); |
|
306 | + break; |
|
307 | + } |
|
308 | + } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
309 | + switch ($template_file_prefix) { |
|
310 | + case 'attendee_list_purchaser': |
|
311 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
312 | + $contents = EEH_Template::display_template($path, array(), true); |
|
313 | + break; |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + return $contents; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
322 | + { |
|
323 | + // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
324 | + $include_with = array( |
|
325 | + 'registration', |
|
326 | + 'cancelled_registration', |
|
327 | + 'declined_registration', |
|
328 | + 'not_approved_registration', |
|
329 | + 'payment_declined', |
|
330 | + 'payment_failed', |
|
331 | + 'payment_cancelled', |
|
332 | + 'payment', |
|
333 | + 'payment_reminder', |
|
334 | + 'pending_approval', |
|
335 | + 'registration_summary', |
|
336 | + 'invoice', |
|
337 | + 'receipt', |
|
338 | + ); |
|
339 | + if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
340 | + $contexts = array_keys($msg->get_contexts()); |
|
341 | + foreach ($contexts as $context) { |
|
342 | + $valid_shortcodes[ $context ][] = 'question_list'; |
|
343 | + $valid_shortcodes[ $context ][] = 'question'; |
|
344 | + } |
|
345 | + } |
|
346 | + |
|
347 | + return $valid_shortcodes; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
352 | + { |
|
353 | + $shortcodes['[ANSWER_*]'] = __( |
|
354 | + 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
355 | + 'event_espresso' |
|
356 | + ); |
|
357 | + |
|
358 | + return $shortcodes; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
363 | + { |
|
364 | + |
|
365 | + if (strpos($shortcode, '[ANSWER_*') === false |
|
366 | + || ! isset($extra_data['data']->questions) |
|
367 | + || ! isset($extra_data['data']->registrations) |
|
368 | + ) { |
|
369 | + return $parsed; |
|
370 | + } |
|
371 | + |
|
372 | + // let's get the question from the code. |
|
373 | + $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
374 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
375 | + |
|
376 | + $registration = $data instanceof EE_Registration ? $data : null; |
|
377 | + $registration = ! $registration instanceof EE_Registration && is_array( |
|
378 | + $extra_data |
|
379 | + ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
380 | + |
|
381 | + $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
382 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
383 | + $extra_data |
|
384 | + ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
385 | + |
|
386 | + if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | + return $parsed; |
|
388 | + } |
|
389 | + |
|
390 | + // now let's figure out which question has this text. |
|
391 | + foreach ($aee->questions as $ansid => $question) { |
|
392 | + if ($question instanceof EE_Question |
|
393 | + && trim($question->display_text()) == trim($shortcode) |
|
394 | + && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
395 | + ) { |
|
396 | + return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
397 | + 'ANS_value', |
|
398 | + 'no_wpautop' |
|
399 | + ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + // nothing! |
|
404 | + return $parsed; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
410 | + * |
|
411 | + * @since 4.2 |
|
412 | + * |
|
413 | + * @param array $shortcodes array of shortcodes and |
|
414 | + * descriptions |
|
415 | + * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
416 | + * |
|
417 | + * @return array array of shortcodes and |
|
418 | + * descriptions |
|
419 | + */ |
|
420 | + public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
421 | + { |
|
422 | + $shortcodes['[DTT_NAME]'] = __( |
|
423 | + 'This will be parsed to the Title given for a Datetime', |
|
424 | + 'event_espresso' |
|
425 | + ); |
|
426 | + $shortcodes['[DTT_DESCRIPTION]'] = __( |
|
427 | + 'This will be parsed to the description for a Datetime', |
|
428 | + 'event_espresso' |
|
429 | + ); |
|
430 | + $shortcodes['[DTT_NAME_OR_DATES]'] = __( |
|
431 | + 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
432 | + 'event_espresso' |
|
433 | + ); |
|
434 | + |
|
435 | + return $shortcodes; |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Callback for additional shortcodes parser filter used for adding parser for new |
|
441 | + * Datetime shortcodes |
|
442 | + * |
|
443 | + * @since 4.2 |
|
444 | + * |
|
445 | + * @param string $parsed The finished parsed string for the given shortcode. |
|
446 | + * @param string $shortcode The shortcode being parsed. |
|
447 | + * @param object $data The incoming data object for the Shortcode Parser. |
|
448 | + * @param object $extra_data The incoming extra date object for the Shortcode |
|
449 | + * Parser. |
|
450 | + * @param EE_Datetime_Shortcodes $shortcode_parser |
|
451 | + * |
|
452 | + * @return string The new parsed string. |
|
453 | + */ |
|
454 | + public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
455 | + { |
|
456 | + |
|
457 | + if (! $data instanceof EE_Datetime) { |
|
458 | + return ''; // get out because we can only parse with the datetime object. |
|
459 | + } |
|
460 | + |
|
461 | + switch ($shortcode) { |
|
462 | + case '[DTT_NAME]': |
|
463 | + return $data->name(); |
|
464 | + break; |
|
465 | + case '[DTT_DESCRIPTION]': |
|
466 | + return $data->description(); |
|
467 | + break; |
|
468 | + case '[DTT_NAME_OR_DATES]': |
|
469 | + return $data->get_dtt_display_name(true); |
|
470 | + break; |
|
471 | + default: |
|
472 | + return $parsed; |
|
473 | + break; |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
479 | + { |
|
480 | + $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __( |
|
481 | + 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
482 | + 'event_espresso' |
|
483 | + ); |
|
484 | + |
|
485 | + return $shortcodes; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
491 | + * |
|
492 | + * @param string $parsed The original parsed content for the shortcode |
|
493 | + * @param string $shortcode The shortcode being parsed |
|
494 | + * @param array $data The shortcode parser data array |
|
495 | + * @param array $extra_data The shortcode parser extra data array |
|
496 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
497 | + * |
|
498 | + * @return string |
|
499 | + */ |
|
500 | + public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
501 | + { |
|
502 | + |
|
503 | + if (array($data) && ! isset($data['data'])) { |
|
504 | + return $parsed; |
|
505 | + } |
|
506 | + |
|
507 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
508 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
509 | + |
|
510 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
511 | + return $parsed; |
|
512 | + } |
|
513 | + |
|
514 | + switch ($shortcode) { |
|
515 | + case '[RECIPIENT_QUESTION_LIST]': |
|
516 | + $att = $recipient->att_obj; |
|
517 | + $registrations_on_attendee = $att instanceof EE_Attendee |
|
518 | + ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
519 | + : array(); |
|
520 | + $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
521 | + $answers = array(); |
|
522 | + |
|
523 | + $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
524 | + ? $data['template']['question_list'] |
|
525 | + : $extra_data['template']['question_list']; |
|
526 | + $valid_shortcodes = array('question'); |
|
527 | + |
|
528 | + // if the context is main_content then get all answers for all registrations on this attendee |
|
529 | + if ($data['data'] instanceof EE_Messages_Addressee) { |
|
530 | + foreach ($registrations_on_attendee as $reg) { |
|
531 | + if ($reg instanceof EE_Registration) { |
|
532 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
533 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
534 | + : array(); |
|
535 | + foreach ($anss as $ans) { |
|
536 | + if ($ans instanceof EE_Answer) { |
|
537 | + $answers[ $ans->ID() ] = $ans; |
|
538 | + } |
|
539 | + } |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
545 | + if ($data['data'] instanceof EE_Event) { |
|
546 | + $event = $data['data']; |
|
547 | + foreach ($registrations_on_attendee as $reg) { |
|
548 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
549 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
550 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
551 | + : array(); |
|
552 | + foreach ($anss as $ans) { |
|
553 | + if ($ans instanceof EE_Answer) { |
|
554 | + $answers[ $ans->ID() ] = $ans; |
|
555 | + } |
|
556 | + } |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | + |
|
561 | + $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
562 | + |
|
563 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
564 | + // object on it. |
|
565 | + if (! isset($extra_data['data'])) { |
|
566 | + $extra_data['data'] = $recipient; |
|
567 | + } |
|
568 | + |
|
569 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
570 | + $shortcode_parser, |
|
571 | + $questions, |
|
572 | + $answers, |
|
573 | + $template, |
|
574 | + $valid_shortcodes, |
|
575 | + $extra_data |
|
576 | + ); |
|
577 | + break; |
|
578 | + |
|
579 | + default: |
|
580 | + return $parsed; |
|
581 | + break; |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
587 | + { |
|
588 | + $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __( |
|
589 | + 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
590 | + 'event_espresso' |
|
591 | + ); |
|
592 | + |
|
593 | + return $shortcodes; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
599 | + * |
|
600 | + * @param string $parsed The original parsed content for the shortcode |
|
601 | + * @param string $shortcode The shortcode being parsed |
|
602 | + * @param array $data The shortcode parser data array |
|
603 | + * @param array $extra_data The shortcode parser extra data array |
|
604 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
605 | + * |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function additional_primary_registration_details_parser( |
|
609 | + $parsed, |
|
610 | + $shortcode, |
|
611 | + $data, |
|
612 | + $extra_data, |
|
613 | + $shortcode_parser |
|
614 | + ) { |
|
615 | + if (array($data) && ! isset($data['data'])) { |
|
616 | + return $parsed; |
|
617 | + } |
|
618 | + |
|
619 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
620 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
621 | + |
|
622 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
623 | + return $parsed; |
|
624 | + } |
|
625 | + |
|
626 | + switch ($shortcode) { |
|
627 | + case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
|
628 | + if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | + return ''; |
|
630 | + } |
|
631 | + $registration = $recipient->primary_reg_obj; |
|
632 | + $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
633 | + ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
634 | + : array(); |
|
635 | + if (empty($answers)) { |
|
636 | + return ''; |
|
637 | + } |
|
638 | + $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
639 | + ? $data['template']['question_list'] |
|
640 | + : $extra_data['template']['question_list']; |
|
641 | + $valid_shortcodes = array('question'); |
|
642 | + $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
643 | + $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
644 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
645 | + // object on it. |
|
646 | + if (! isset($extra_data['data'])) { |
|
647 | + $extra_data['data'] = $recipient; |
|
648 | + } |
|
649 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
650 | + $shortcode_parser, |
|
651 | + $questions, |
|
652 | + $answers, |
|
653 | + $template, |
|
654 | + $valid_shortcodes, |
|
655 | + $extra_data |
|
656 | + ); |
|
657 | + break; |
|
658 | + |
|
659 | + default: |
|
660 | + return $parsed; |
|
661 | + break; |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + /** |
|
667 | + * Takes care of registering the message types that are only available in caffeinated EE. |
|
668 | + * |
|
669 | + * @since 4.3.2 |
|
670 | + * |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + public function register_caf_message_types() |
|
674 | + { |
|
675 | + // register newsletter message type |
|
676 | + $setup_args = array( |
|
677 | + 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
678 | + 'autoloadpaths' => array( |
|
679 | + EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
680 | + ), |
|
681 | + 'messengers_to_activate_with' => array('email'), |
|
682 | + 'messengers_to_validate_with' => array('email'), |
|
683 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
684 | + ); |
|
685 | + EE_Register_Message_Type::register('newsletter', $setup_args); |
|
686 | + |
|
687 | + // register payment reminder message type |
|
688 | + $setup_args = array( |
|
689 | + 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
690 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
691 | + 'messengers_to_activate_with' => array('email'), |
|
692 | + 'messengers_to_validate_with' => array('email'), |
|
693 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
694 | + ); |
|
695 | + EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
696 | + |
|
697 | + // register payment declined message type |
|
698 | + $setup_args = array( |
|
699 | + 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
700 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
701 | + 'messengers_to_activate_with' => array('email'), |
|
702 | + 'messengers_to_validate_with' => array('email'), |
|
703 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
704 | + ); |
|
705 | + EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
706 | + |
|
707 | + // register registration declined message type |
|
708 | + $setup_args = array( |
|
709 | + 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
710 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
711 | + 'messengers_to_activate_with' => array('email'), |
|
712 | + 'messengers_to_validate_with' => array('email'), |
|
713 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
714 | + ); |
|
715 | + EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
716 | + |
|
717 | + // register registration cancelled message type |
|
718 | + $setup_args = array( |
|
719 | + 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
720 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
721 | + 'messengers_to_activate_with' => array('email'), |
|
722 | + 'messengers_to_validate_with' => array('email'), |
|
723 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
724 | + ); |
|
725 | + EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
726 | + |
|
727 | + |
|
728 | + // register payment failed message type |
|
729 | + $setup_args = array( |
|
730 | + 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
731 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
732 | + 'messengers_to_activate_with' => array('email'), |
|
733 | + 'messengers_to_validate_with' => array('email'), |
|
734 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
735 | + ); |
|
736 | + EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
737 | + |
|
738 | + // register payment declined message type |
|
739 | + $setup_args = array( |
|
740 | + 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
741 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
742 | + 'messengers_to_activate_with' => array('email'), |
|
743 | + 'messengers_to_validate_with' => array('email'), |
|
744 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
745 | + ); |
|
746 | + EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
752 | + * |
|
753 | + * @since 4.3.2 |
|
754 | + * |
|
755 | + * @return void |
|
756 | + */ |
|
757 | + public function register_caf_shortcodes() |
|
758 | + { |
|
759 | + $setup_args = array( |
|
760 | + 'autoloadpaths' => array( |
|
761 | + EE_CAF_LIBRARIES . 'shortcodes/', |
|
762 | + ), |
|
763 | + 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
764 | + 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
765 | + 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]'), |
|
766 | + ); |
|
767 | + EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * Parses a question list shortcode using given data and template |
|
773 | + * |
|
774 | + * @param \EE_Shortcodes $shortcode_parser |
|
775 | + * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
776 | + * @param EE_Answer[] $answers An array of answer objects |
|
777 | + * @param string $template Template content to be parsed. |
|
778 | + * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
779 | + * @param array $extra_data Extra data that might be used when parsing the template. |
|
780 | + */ |
|
781 | + protected function _parse_question_list_for_primary_or_recipient_registration( |
|
782 | + $shortcode_parser, |
|
783 | + $questions, |
|
784 | + $answers, |
|
785 | + $template, |
|
786 | + $valid_shortcodes, |
|
787 | + $extra_data |
|
788 | + ) { |
|
789 | + $question_list = ''; |
|
790 | + /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
791 | + $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
792 | + foreach ($answers as $answer) { |
|
793 | + if ($answer instanceof EE_Answer) { |
|
794 | + // first see if the question is in our $questions array. If not then try to get from answer object. |
|
795 | + $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
796 | + $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
797 | + if (! $question instanceof EE_Question |
|
798 | + || ( |
|
799 | + $question instanceof EE_Question |
|
800 | + && $question->admin_only() |
|
801 | + ) |
|
802 | + ) { |
|
803 | + continue; |
|
804 | + } |
|
805 | + $question_list .= $shortcode_helper->parse_question_list_template( |
|
806 | + $template, |
|
807 | + $answer, |
|
808 | + $valid_shortcodes, |
|
809 | + $extra_data |
|
810 | + ); |
|
811 | + } |
|
812 | + } |
|
813 | + return $question_list; |
|
814 | + } |
|
815 | 815 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function messages_autoload_paths($dir_ref) |
132 | 132 | { |
133 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
133 | + $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/'; |
|
134 | 134 | |
135 | 135 | return $dir_ref; |
136 | 136 | } |
@@ -246,32 +246,32 @@ discard block |
||
246 | 246 | ) { |
247 | 247 | |
248 | 248 | // we're only modifying templates for the default template pack |
249 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
249 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
250 | 250 | return $contents; |
251 | 251 | } |
252 | 252 | |
253 | 253 | // the template file name we're replacing contents for. |
254 | - $template_file_prefix = $field . '_' . $context; |
|
255 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
254 | + $template_file_prefix = $field.'_'.$context; |
|
255 | + $msg_prefix = $messenger->name.'_'.$message_type->name.'_'; |
|
256 | 256 | |
257 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
257 | + $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/'; |
|
258 | 258 | |
259 | 259 | if ($messenger->name == 'email' && $message_type->name == 'registration') { |
260 | 260 | switch ($template_file_prefix) { |
261 | 261 | case 'question_list_admin': |
262 | 262 | case 'question_list_attendee': |
263 | 263 | case 'question_list_primary_attendee': |
264 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
264 | + $path = $base_path.$msg_prefix.'question_list.template.php'; |
|
265 | 265 | $contents = EEH_Template::display_template($path, array(), true); |
266 | 266 | break; |
267 | 267 | |
268 | 268 | case 'attendee_list_primary_attendee': |
269 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
269 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
270 | 270 | $contents = EEH_Template::display_template($path, array(), true); |
271 | 271 | break; |
272 | 272 | |
273 | 273 | case 'attendee_list_admin': |
274 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
274 | + $path = $base_path.$msg_prefix.'attendee_list_admin.template.php'; |
|
275 | 275 | $contents = EEH_Template::display_template( |
276 | 276 | $path, |
277 | 277 | array(), |
@@ -284,31 +284,31 @@ discard block |
||
284 | 284 | break; |
285 | 285 | |
286 | 286 | case 'event_list_attendee': |
287 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
287 | + $path = $base_path.$msg_prefix.'event_list_attendee.template.php'; |
|
288 | 288 | $contents = EEH_Template::display_template($path, array(), true); |
289 | 289 | break; |
290 | 290 | } |
291 | 291 | } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
292 | 292 | switch ($template_file_prefix) { |
293 | 293 | case 'content_attendee': |
294 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
294 | + $path = $base_path.$msg_prefix.'content.template.php'; |
|
295 | 295 | $contents = EEH_Template::display_template($path, array(), true); |
296 | 296 | break; |
297 | 297 | |
298 | 298 | case 'newsletter_content_attendee': |
299 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
299 | + $path = $base_path.$msg_prefix.'newsletter_content.template.php'; |
|
300 | 300 | $contents = EEH_Template::display_template($path, array(), true); |
301 | 301 | break; |
302 | 302 | |
303 | 303 | case 'newsletter_subject_attendee': |
304 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
304 | + $path = $base_path.$msg_prefix.'subject.template.php'; |
|
305 | 305 | $contents = EEH_Template::display_template($path, array(), true); |
306 | 306 | break; |
307 | 307 | } |
308 | 308 | } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
309 | 309 | switch ($template_file_prefix) { |
310 | 310 | case 'attendee_list_purchaser': |
311 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
311 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
312 | 312 | $contents = EEH_Template::display_template($path, array(), true); |
313 | 313 | break; |
314 | 314 | } |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
340 | 340 | $contexts = array_keys($msg->get_contexts()); |
341 | 341 | foreach ($contexts as $context) { |
342 | - $valid_shortcodes[ $context ][] = 'question_list'; |
|
343 | - $valid_shortcodes[ $context ][] = 'question'; |
|
342 | + $valid_shortcodes[$context][] = 'question_list'; |
|
343 | + $valid_shortcodes[$context][] = 'question'; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | $extra_data |
384 | 384 | ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
385 | 385 | |
386 | - if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
386 | + if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | 387 | return $parsed; |
388 | 388 | } |
389 | 389 | |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | foreach ($aee->questions as $ansid => $question) { |
392 | 392 | if ($question instanceof EE_Question |
393 | 393 | && trim($question->display_text()) == trim($shortcode) |
394 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
394 | + && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
395 | 395 | ) { |
396 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
396 | + return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty( |
|
397 | 397 | 'ANS_value', |
398 | 398 | 'no_wpautop' |
399 | 399 | ); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
455 | 455 | { |
456 | 456 | |
457 | - if (! $data instanceof EE_Datetime) { |
|
457 | + if ( ! $data instanceof EE_Datetime) { |
|
458 | 458 | return ''; // get out because we can only parse with the datetime object. |
459 | 459 | } |
460 | 460 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
508 | 508 | $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
509 | 509 | |
510 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
510 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
511 | 511 | return $parsed; |
512 | 512 | } |
513 | 513 | |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | case '[RECIPIENT_QUESTION_LIST]': |
516 | 516 | $att = $recipient->att_obj; |
517 | 517 | $registrations_on_attendee = $att instanceof EE_Attendee |
518 | - ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
518 | + ? $recipient->attendees[$att->ID()]['reg_objs'] |
|
519 | 519 | : array(); |
520 | 520 | $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
521 | 521 | $answers = array(); |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | if ($data['data'] instanceof EE_Messages_Addressee) { |
530 | 530 | foreach ($registrations_on_attendee as $reg) { |
531 | 531 | if ($reg instanceof EE_Registration) { |
532 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
533 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
532 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) |
|
533 | + ? $recipient->registrations[$reg->ID()]['ans_objs'] |
|
534 | 534 | : array(); |
535 | 535 | foreach ($anss as $ans) { |
536 | 536 | if ($ans instanceof EE_Answer) { |
537 | - $answers[ $ans->ID() ] = $ans; |
|
537 | + $answers[$ans->ID()] = $ans; |
|
538 | 538 | } |
539 | 539 | } |
540 | 540 | } |
@@ -546,12 +546,12 @@ discard block |
||
546 | 546 | $event = $data['data']; |
547 | 547 | foreach ($registrations_on_attendee as $reg) { |
548 | 548 | if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
549 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
550 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
549 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) |
|
550 | + ? $recipient->registrations[$reg->ID()]['ans_objs'] |
|
551 | 551 | : array(); |
552 | 552 | foreach ($anss as $ans) { |
553 | 553 | if ($ans instanceof EE_Answer) { |
554 | - $answers[ $ans->ID() ] = $ans; |
|
554 | + $answers[$ans->ID()] = $ans; |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | } |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | |
563 | 563 | // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
564 | 564 | // object on it. |
565 | - if (! isset($extra_data['data'])) { |
|
565 | + if ( ! isset($extra_data['data'])) { |
|
566 | 566 | $extra_data['data'] = $recipient; |
567 | 567 | } |
568 | 568 | |
@@ -619,18 +619,18 @@ discard block |
||
619 | 619 | $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
620 | 620 | $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
621 | 621 | |
622 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
622 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
623 | 623 | return $parsed; |
624 | 624 | } |
625 | 625 | |
626 | 626 | switch ($shortcode) { |
627 | 627 | case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
628 | - if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
628 | + if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | 629 | return ''; |
630 | 630 | } |
631 | 631 | $registration = $recipient->primary_reg_obj; |
632 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
633 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
632 | + $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
633 | + ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
634 | 634 | : array(); |
635 | 635 | if (empty($answers)) { |
636 | 636 | return ''; |
@@ -639,11 +639,11 @@ discard block |
||
639 | 639 | ? $data['template']['question_list'] |
640 | 640 | : $extra_data['template']['question_list']; |
641 | 641 | $valid_shortcodes = array('question'); |
642 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
642 | + $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
643 | 643 | $questions = isset($recipient->questions) ? $recipient->questions : array(); |
644 | 644 | // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
645 | 645 | // object on it. |
646 | - if (! isset($extra_data['data'])) { |
|
646 | + if ( ! isset($extra_data['data'])) { |
|
647 | 647 | $extra_data['data'] = $recipient; |
648 | 648 | } |
649 | 649 | return $this->_parse_question_list_for_primary_or_recipient_registration( |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | $setup_args = array( |
677 | 677 | 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
678 | 678 | 'autoloadpaths' => array( |
679 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
679 | + EE_CAF_LIBRARIES.'messages/message_type/newsletter/', |
|
680 | 680 | ), |
681 | 681 | 'messengers_to_activate_with' => array('email'), |
682 | 682 | 'messengers_to_validate_with' => array('email'), |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | // register payment reminder message type |
688 | 688 | $setup_args = array( |
689 | 689 | 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
690 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
690 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'), |
|
691 | 691 | 'messengers_to_activate_with' => array('email'), |
692 | 692 | 'messengers_to_validate_with' => array('email'), |
693 | 693 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | // register payment declined message type |
698 | 698 | $setup_args = array( |
699 | 699 | 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
700 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
700 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'), |
|
701 | 701 | 'messengers_to_activate_with' => array('email'), |
702 | 702 | 'messengers_to_validate_with' => array('email'), |
703 | 703 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | // register registration declined message type |
708 | 708 | $setup_args = array( |
709 | 709 | 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
710 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
710 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'), |
|
711 | 711 | 'messengers_to_activate_with' => array('email'), |
712 | 712 | 'messengers_to_validate_with' => array('email'), |
713 | 713 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | // register registration cancelled message type |
718 | 718 | $setup_args = array( |
719 | 719 | 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
720 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
720 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'), |
|
721 | 721 | 'messengers_to_activate_with' => array('email'), |
722 | 722 | 'messengers_to_validate_with' => array('email'), |
723 | 723 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | // register payment failed message type |
729 | 729 | $setup_args = array( |
730 | 730 | 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
731 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
731 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'), |
|
732 | 732 | 'messengers_to_activate_with' => array('email'), |
733 | 733 | 'messengers_to_validate_with' => array('email'), |
734 | 734 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | // register payment declined message type |
739 | 739 | $setup_args = array( |
740 | 740 | 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
741 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
741 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'), |
|
742 | 742 | 'messengers_to_activate_with' => array('email'), |
743 | 743 | 'messengers_to_validate_with' => array('email'), |
744 | 744 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | { |
759 | 759 | $setup_args = array( |
760 | 760 | 'autoloadpaths' => array( |
761 | - EE_CAF_LIBRARIES . 'shortcodes/', |
|
761 | + EE_CAF_LIBRARIES.'shortcodes/', |
|
762 | 762 | ), |
763 | 763 | 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
764 | 764 | 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
@@ -792,9 +792,9 @@ discard block |
||
792 | 792 | foreach ($answers as $answer) { |
793 | 793 | if ($answer instanceof EE_Answer) { |
794 | 794 | // first see if the question is in our $questions array. If not then try to get from answer object. |
795 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
795 | + $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
796 | 796 | $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
797 | - if (! $question instanceof EE_Question |
|
797 | + if ( ! $question instanceof EE_Question |
|
798 | 798 | || ( |
799 | 799 | $question instanceof EE_Question |
800 | 800 | && $question->admin_only() |
@@ -16,220 +16,220 @@ |
||
16 | 16 | class Prices_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | 18 | |
19 | - private $_PRT; |
|
20 | - |
|
21 | - /** |
|
22 | - * Array of price types. |
|
23 | - * |
|
24 | - * @var EE_Price_Type[] |
|
25 | - */ |
|
26 | - protected $_price_types = array(); |
|
27 | - |
|
28 | - public function __construct($admin_page) |
|
29 | - { |
|
30 | - parent::__construct($admin_page); |
|
31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | - $this->_PRT = EEM_Price_Type::instance(); |
|
33 | - $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - protected function _setup_data() |
|
38 | - { |
|
39 | - $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
40 | - $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
41 | - $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false); |
|
42 | - $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - protected function _set_properties() |
|
47 | - { |
|
48 | - $this->_wp_list_args = array( |
|
49 | - 'singular' => __('price', 'event_espresso'), |
|
50 | - 'plural' => __('prices', 'event_espresso'), |
|
51 | - 'ajax' => true, |
|
52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | - ); |
|
54 | - |
|
55 | - $this->_columns = array( |
|
56 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
57 | - 'name' => __('Name', 'event_espresso'), |
|
58 | - 'type' => __('Price Type', 'event_espresso'), |
|
59 | - 'description' => __('Description', 'event_espresso'), |
|
60 | - 'amount' => __('Amount', 'event_espresso'), |
|
61 | - ); |
|
62 | - |
|
63 | - $this->_sortable_columns = array( |
|
64 | - // true means its already sorted |
|
65 | - 'name' => array('name' => false), |
|
66 | - 'type' => array('type' => false), |
|
67 | - 'amount' => array('amount' => false), |
|
68 | - ); |
|
69 | - |
|
70 | - $this->_hidden_columns = array(); |
|
71 | - |
|
72 | - $this->_ajax_sorting_callback = 'update_prices_order'; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - protected function _get_table_filters() |
|
77 | - { |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - protected function _add_view_counts() |
|
82 | - { |
|
83 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
84 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
85 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
92 | - * |
|
93 | - * @param object $item the current item |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - protected function _get_row_class($item) |
|
97 | - { |
|
98 | - static $row_class = ''; |
|
99 | - $row_class = ($row_class == '' ? 'alternate' : ''); |
|
100 | - |
|
101 | - $new_row = $row_class; |
|
102 | - |
|
103 | - if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) { |
|
104 | - $new_row .= ' rowsortable'; |
|
105 | - } |
|
106 | - |
|
107 | - return ' class="' . $new_row . '"'; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - public function column_cb($item) |
|
112 | - { |
|
113 | - if ($item->type_obj()->base_type() !== 1) { |
|
114 | - return sprintf( |
|
115 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
116 | - $item->ID() |
|
117 | - ); |
|
118 | - } |
|
119 | - return ''; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - public function column_name($item) |
|
124 | - { |
|
125 | - |
|
126 | - // Build row actions |
|
127 | - $actions = array(); |
|
128 | - // edit price link |
|
129 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
130 | - 'ee_edit_default_price', |
|
131 | - 'pricing_edit_price', |
|
132 | - $item->ID() |
|
133 | - )) { |
|
134 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
135 | - 'action' => 'edit_price', |
|
136 | - 'id' => $item->ID(), |
|
137 | - ), PRICING_ADMIN_URL); |
|
138 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | - . __('Edit', 'event_espresso') . '</a>'; |
|
141 | - } |
|
142 | - |
|
143 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
144 | - 'ee_edit_default_price', |
|
145 | - 'edit_price', |
|
146 | - $item->ID() |
|
147 | - ) |
|
148 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | - . stripslashes($item->name()) . '</a>' |
|
151 | - : $item->name(); |
|
152 | - |
|
153 | - if ($item->type_obj()->base_type() !== 1) { |
|
154 | - if ($this->_view == 'all') { |
|
155 | - // trash price link |
|
156 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
157 | - 'ee_delete_default_price', |
|
158 | - 'pricing_trash_price', |
|
159 | - $item->ID() |
|
160 | - )) { |
|
161 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
162 | - 'action' => 'trash_price', |
|
163 | - 'id' => $item->ID(), |
|
164 | - 'noheader' => true, |
|
165 | - ), PRICING_ADMIN_URL); |
|
166 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | - . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | - . __('Move to Trash', 'event_espresso') . '</a>'; |
|
169 | - } |
|
170 | - } else { |
|
171 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
172 | - 'ee_delete_default_price', |
|
173 | - 'pricing_restore_price', |
|
174 | - $item->ID() |
|
175 | - )) { |
|
176 | - // restore price link |
|
177 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
178 | - 'action' => 'restore_price', |
|
179 | - 'id' => $item->ID(), |
|
180 | - 'noheader' => true, |
|
181 | - ), PRICING_ADMIN_URL); |
|
182 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | - . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | - . __('Restore', 'event_espresso') . '</a>'; |
|
185 | - } |
|
186 | - |
|
187 | - // delete price link |
|
188 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
189 | - 'ee_delete_default_price', |
|
190 | - 'pricing_delete_price', |
|
191 | - $item->ID() |
|
192 | - )) { |
|
193 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
194 | - 'action' => 'delete_price', |
|
195 | - 'id' => $item->ID(), |
|
196 | - 'noheader' => true, |
|
197 | - ), PRICING_ADMIN_URL); |
|
198 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | - . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - // Return the name contents |
|
206 | - return sprintf( |
|
207 | - '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
208 | - $name_link, |
|
209 | - $item->ID(), |
|
210 | - $this->row_actions($actions) |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - public function column_type($item) |
|
216 | - { |
|
217 | - return $this->_price_types[ $item->type() ]->name(); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - public function column_description($item) |
|
222 | - { |
|
223 | - return stripslashes($item->desc()); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - public function column_amount($item) |
|
228 | - { |
|
229 | - if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | - return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
231 | - } else { |
|
232 | - return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
233 | - } |
|
234 | - } |
|
19 | + private $_PRT; |
|
20 | + |
|
21 | + /** |
|
22 | + * Array of price types. |
|
23 | + * |
|
24 | + * @var EE_Price_Type[] |
|
25 | + */ |
|
26 | + protected $_price_types = array(); |
|
27 | + |
|
28 | + public function __construct($admin_page) |
|
29 | + { |
|
30 | + parent::__construct($admin_page); |
|
31 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | + $this->_PRT = EEM_Price_Type::instance(); |
|
33 | + $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + protected function _setup_data() |
|
38 | + { |
|
39 | + $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
40 | + $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
41 | + $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false); |
|
42 | + $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + protected function _set_properties() |
|
47 | + { |
|
48 | + $this->_wp_list_args = array( |
|
49 | + 'singular' => __('price', 'event_espresso'), |
|
50 | + 'plural' => __('prices', 'event_espresso'), |
|
51 | + 'ajax' => true, |
|
52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | + ); |
|
54 | + |
|
55 | + $this->_columns = array( |
|
56 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
57 | + 'name' => __('Name', 'event_espresso'), |
|
58 | + 'type' => __('Price Type', 'event_espresso'), |
|
59 | + 'description' => __('Description', 'event_espresso'), |
|
60 | + 'amount' => __('Amount', 'event_espresso'), |
|
61 | + ); |
|
62 | + |
|
63 | + $this->_sortable_columns = array( |
|
64 | + // true means its already sorted |
|
65 | + 'name' => array('name' => false), |
|
66 | + 'type' => array('type' => false), |
|
67 | + 'amount' => array('amount' => false), |
|
68 | + ); |
|
69 | + |
|
70 | + $this->_hidden_columns = array(); |
|
71 | + |
|
72 | + $this->_ajax_sorting_callback = 'update_prices_order'; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + protected function _get_table_filters() |
|
77 | + { |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + protected function _add_view_counts() |
|
82 | + { |
|
83 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
84 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
85 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
92 | + * |
|
93 | + * @param object $item the current item |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + protected function _get_row_class($item) |
|
97 | + { |
|
98 | + static $row_class = ''; |
|
99 | + $row_class = ($row_class == '' ? 'alternate' : ''); |
|
100 | + |
|
101 | + $new_row = $row_class; |
|
102 | + |
|
103 | + if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) { |
|
104 | + $new_row .= ' rowsortable'; |
|
105 | + } |
|
106 | + |
|
107 | + return ' class="' . $new_row . '"'; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + public function column_cb($item) |
|
112 | + { |
|
113 | + if ($item->type_obj()->base_type() !== 1) { |
|
114 | + return sprintf( |
|
115 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
116 | + $item->ID() |
|
117 | + ); |
|
118 | + } |
|
119 | + return ''; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + public function column_name($item) |
|
124 | + { |
|
125 | + |
|
126 | + // Build row actions |
|
127 | + $actions = array(); |
|
128 | + // edit price link |
|
129 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
130 | + 'ee_edit_default_price', |
|
131 | + 'pricing_edit_price', |
|
132 | + $item->ID() |
|
133 | + )) { |
|
134 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
135 | + 'action' => 'edit_price', |
|
136 | + 'id' => $item->ID(), |
|
137 | + ), PRICING_ADMIN_URL); |
|
138 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | + . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | + . __('Edit', 'event_espresso') . '</a>'; |
|
141 | + } |
|
142 | + |
|
143 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
144 | + 'ee_edit_default_price', |
|
145 | + 'edit_price', |
|
146 | + $item->ID() |
|
147 | + ) |
|
148 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | + . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | + . stripslashes($item->name()) . '</a>' |
|
151 | + : $item->name(); |
|
152 | + |
|
153 | + if ($item->type_obj()->base_type() !== 1) { |
|
154 | + if ($this->_view == 'all') { |
|
155 | + // trash price link |
|
156 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
157 | + 'ee_delete_default_price', |
|
158 | + 'pricing_trash_price', |
|
159 | + $item->ID() |
|
160 | + )) { |
|
161 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
162 | + 'action' => 'trash_price', |
|
163 | + 'id' => $item->ID(), |
|
164 | + 'noheader' => true, |
|
165 | + ), PRICING_ADMIN_URL); |
|
166 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | + . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | + . __('Move to Trash', 'event_espresso') . '</a>'; |
|
169 | + } |
|
170 | + } else { |
|
171 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
172 | + 'ee_delete_default_price', |
|
173 | + 'pricing_restore_price', |
|
174 | + $item->ID() |
|
175 | + )) { |
|
176 | + // restore price link |
|
177 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
178 | + 'action' => 'restore_price', |
|
179 | + 'id' => $item->ID(), |
|
180 | + 'noheader' => true, |
|
181 | + ), PRICING_ADMIN_URL); |
|
182 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | + . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | + . __('Restore', 'event_espresso') . '</a>'; |
|
185 | + } |
|
186 | + |
|
187 | + // delete price link |
|
188 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
189 | + 'ee_delete_default_price', |
|
190 | + 'pricing_delete_price', |
|
191 | + $item->ID() |
|
192 | + )) { |
|
193 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
194 | + 'action' => 'delete_price', |
|
195 | + 'id' => $item->ID(), |
|
196 | + 'noheader' => true, |
|
197 | + ), PRICING_ADMIN_URL); |
|
198 | + $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | + . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | + . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + // Return the name contents |
|
206 | + return sprintf( |
|
207 | + '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
208 | + $name_link, |
|
209 | + $item->ID(), |
|
210 | + $this->row_actions($actions) |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + public function column_type($item) |
|
216 | + { |
|
217 | + return $this->_price_types[ $item->type() ]->name(); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + public function column_description($item) |
|
222 | + { |
|
223 | + return stripslashes($item->desc()); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + public function column_amount($item) |
|
228 | + { |
|
229 | + if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | + return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
231 | + } else { |
|
232 | + return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public function __construct($admin_page) |
29 | 29 | { |
30 | 30 | parent::__construct($admin_page); |
31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
31 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
32 | 32 | $this->_PRT = EEM_Price_Type::instance(); |
33 | 33 | $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
34 | 34 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $new_row .= ' rowsortable'; |
105 | 105 | } |
106 | 106 | |
107 | - return ' class="' . $new_row . '"'; |
|
107 | + return ' class="'.$new_row.'"'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | 'action' => 'edit_price', |
136 | 136 | 'id' => $item->ID(), |
137 | 137 | ), PRICING_ADMIN_URL); |
138 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | - . __('Edit', 'event_espresso') . '</a>'; |
|
138 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="' |
|
139 | + . esc_attr__('Edit Price', 'event_espresso').'">' |
|
140 | + . __('Edit', 'event_espresso').'</a>'; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | 'edit_price', |
146 | 146 | $item->ID() |
147 | 147 | ) |
148 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | - . stripslashes($item->name()) . '</a>' |
|
148 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
149 | + . esc_attr__('Edit Price', 'event_espresso').'">' |
|
150 | + . stripslashes($item->name()).'</a>' |
|
151 | 151 | : $item->name(); |
152 | 152 | |
153 | 153 | if ($item->type_obj()->base_type() !== 1) { |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | 'id' => $item->ID(), |
164 | 164 | 'noheader' => true, |
165 | 165 | ), PRICING_ADMIN_URL); |
166 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | - . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | - . __('Move to Trash', 'event_espresso') . '</a>'; |
|
166 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' |
|
167 | + . esc_attr__('Move Price to Trash', 'event_espresso').'">' |
|
168 | + . __('Move to Trash', 'event_espresso').'</a>'; |
|
169 | 169 | } |
170 | 170 | } else { |
171 | 171 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | 'id' => $item->ID(), |
180 | 180 | 'noheader' => true, |
181 | 181 | ), PRICING_ADMIN_URL); |
182 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | - . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | - . __('Restore', 'event_espresso') . '</a>'; |
|
182 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' |
|
183 | + . esc_attr__('Restore Price', 'event_espresso').'">' |
|
184 | + . __('Restore', 'event_espresso').'</a>'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | // delete price link |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | 'id' => $item->ID(), |
196 | 196 | 'noheader' => true, |
197 | 197 | ), PRICING_ADMIN_URL); |
198 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | - . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
198 | + $actions['delete'] = '<a href="'.$delete_lnk_url.'" title="' |
|
199 | + . esc_attr__('Delete Price Permanently', 'event_espresso').'">' |
|
200 | + . __('Delete Permanently', 'event_espresso').'</a>'; |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | |
215 | 215 | public function column_type($item) |
216 | 216 | { |
217 | - return $this->_price_types[ $item->type() ]->name(); |
|
217 | + return $this->_price_types[$item->type()]->name(); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | |
227 | 227 | public function column_amount($item) |
228 | 228 | { |
229 | - if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | - return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
229 | + if ($this->_price_types[$item->type()]->is_percent()) { |
|
230 | + return '<div class="pad-amnt-rght">'.number_format($item->amount(), 1).'%</div>'; |
|
231 | 231 | } else { |
232 | - return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
232 | + return '<div class="pad-amnt-rght">'.EEH_Template::format_currency($item->amount()).'</div>'; |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | } |
@@ -10,138 +10,138 @@ |
||
10 | 10 | class EE_Taxes extends EE_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * This is used for when EE_Taxes is used statically by the admin |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - private static $_subtotal = array(); |
|
13 | + /** |
|
14 | + * This is used for when EE_Taxes is used statically by the admin |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + private static $_subtotal = array(); |
|
19 | 19 | |
20 | - /** |
|
21 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
22 | - * |
|
23 | - * @var EE_Price[] |
|
24 | - */ |
|
25 | - private static $_default_taxes = array(); |
|
20 | + /** |
|
21 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
22 | + * |
|
23 | + * @var EE_Price[] |
|
24 | + */ |
|
25 | + private static $_default_taxes = array(); |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
30 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
31 | - * calc of taxes for tickets listed in the event editor. |
|
32 | - * |
|
33 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
34 | - * @return float total taxes to apply to ticket. |
|
35 | - * @throws \EE_Error |
|
36 | - */ |
|
37 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | - { |
|
39 | - $tax = 0; |
|
40 | - $total_tax = 0; |
|
41 | - // This first checks to see if the given ticket is taxable. |
|
42 | - if (! $ticket->get('TKT_taxable')) { |
|
43 | - return $tax; |
|
44 | - } |
|
45 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | - $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | - // get taxes |
|
48 | - $taxes = self::get_taxes_for_admin(); |
|
49 | - // apply taxes to subtotal |
|
50 | - foreach ($taxes as $tax) { |
|
51 | - // assuming taxes are not cumulative |
|
52 | - $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | - } |
|
54 | - return $total_tax; |
|
55 | - } |
|
28 | + /** |
|
29 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
30 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
31 | + * calc of taxes for tickets listed in the event editor. |
|
32 | + * |
|
33 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
34 | + * @return float total taxes to apply to ticket. |
|
35 | + * @throws \EE_Error |
|
36 | + */ |
|
37 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | + { |
|
39 | + $tax = 0; |
|
40 | + $total_tax = 0; |
|
41 | + // This first checks to see if the given ticket is taxable. |
|
42 | + if (! $ticket->get('TKT_taxable')) { |
|
43 | + return $tax; |
|
44 | + } |
|
45 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | + $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | + // get taxes |
|
48 | + $taxes = self::get_taxes_for_admin(); |
|
49 | + // apply taxes to subtotal |
|
50 | + foreach ($taxes as $tax) { |
|
51 | + // assuming taxes are not cumulative |
|
52 | + $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | + } |
|
54 | + return $total_tax; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | - * |
|
61 | - * @return float the percentage of tax that should be added to taxable items |
|
62 | - * @throws \EE_Error |
|
63 | - * eg 20 for %20 tax (NOT 0.20, which |
|
64 | - */ |
|
65 | - public static function get_total_taxes_percentage() |
|
66 | - { |
|
67 | - $total_tax_percent = 0; |
|
68 | - foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
70 | - } |
|
71 | - return $total_tax_percent; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | + * |
|
61 | + * @return float the percentage of tax that should be added to taxable items |
|
62 | + * @throws \EE_Error |
|
63 | + * eg 20 for %20 tax (NOT 0.20, which |
|
64 | + */ |
|
65 | + public static function get_total_taxes_percentage() |
|
66 | + { |
|
67 | + $total_tax_percent = 0; |
|
68 | + foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
70 | + } |
|
71 | + return $total_tax_percent; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * @param EE_Ticket $ticket |
|
77 | - * @return float |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
81 | - { |
|
82 | - $TKT_ID = $ticket->ID(); |
|
83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | - ? self::$_subtotal[ $TKT_ID ] |
|
85 | - : self::_get_subtotal_for_admin($ticket); |
|
86 | - } |
|
75 | + /** |
|
76 | + * @param EE_Ticket $ticket |
|
77 | + * @return float |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
81 | + { |
|
82 | + $TKT_ID = $ticket->ID(); |
|
83 | + return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | + ? self::$_subtotal[ $TKT_ID ] |
|
85 | + : self::_get_subtotal_for_admin($ticket); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
91 | - * |
|
92 | - * @param EE_Ticket $ticket |
|
93 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
94 | - * @throws \EE_Error |
|
95 | - */ |
|
96 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
97 | - { |
|
98 | - $subtotal = 0; |
|
99 | - // get all prices |
|
100 | - $prices = $ticket->get_many_related( |
|
101 | - 'Price', |
|
102 | - array( |
|
103 | - 'default_where_conditions' => 'none', |
|
104 | - 'order_by' => array('PRC_order' => 'ASC'), |
|
105 | - ) |
|
106 | - ); |
|
107 | - // let's loop through them (base price is always the first item) |
|
108 | - foreach ($prices as $price) { |
|
109 | - if ($price instanceof EE_Price) { |
|
110 | - $price_type = $price->type_obj(); |
|
111 | - if ($price_type instanceof EE_Price_Type) { |
|
112 | - switch ($price->type_obj()->base_type()) { |
|
113 | - case 1: // base price |
|
114 | - case 3: // surcharges |
|
115 | - $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
116 | - : $price->get('PRC_amount'); |
|
117 | - break; |
|
118 | - case 2: // discounts |
|
119 | - $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
120 | - : $price->get('PRC_amount'); |
|
121 | - break; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - $TKT_ID = $ticket->ID(); |
|
127 | - self::$_subtotal = array($TKT_ID => $subtotal); |
|
128 | - return $subtotal; |
|
129 | - } |
|
89 | + /** |
|
90 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
91 | + * |
|
92 | + * @param EE_Ticket $ticket |
|
93 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
94 | + * @throws \EE_Error |
|
95 | + */ |
|
96 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
97 | + { |
|
98 | + $subtotal = 0; |
|
99 | + // get all prices |
|
100 | + $prices = $ticket->get_many_related( |
|
101 | + 'Price', |
|
102 | + array( |
|
103 | + 'default_where_conditions' => 'none', |
|
104 | + 'order_by' => array('PRC_order' => 'ASC'), |
|
105 | + ) |
|
106 | + ); |
|
107 | + // let's loop through them (base price is always the first item) |
|
108 | + foreach ($prices as $price) { |
|
109 | + if ($price instanceof EE_Price) { |
|
110 | + $price_type = $price->type_obj(); |
|
111 | + if ($price_type instanceof EE_Price_Type) { |
|
112 | + switch ($price->type_obj()->base_type()) { |
|
113 | + case 1: // base price |
|
114 | + case 3: // surcharges |
|
115 | + $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
116 | + : $price->get('PRC_amount'); |
|
117 | + break; |
|
118 | + case 2: // discounts |
|
119 | + $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
120 | + : $price->get('PRC_amount'); |
|
121 | + break; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + $TKT_ID = $ticket->ID(); |
|
127 | + self::$_subtotal = array($TKT_ID => $subtotal); |
|
128 | + return $subtotal; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
134 | - * |
|
135 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
136 | - * @throws \EE_Error |
|
137 | - */ |
|
138 | - public static function get_taxes_for_admin() |
|
139 | - { |
|
140 | - if (empty(self::$_default_taxes)) { |
|
141 | - self::$_default_taxes = EE_Registry::instance()->load_model('Price')->get_all( |
|
142 | - array(array('Price_Type.PBT_ID' => 4)) |
|
143 | - ); |
|
144 | - } |
|
145 | - return self::$_default_taxes; |
|
146 | - } |
|
132 | + /** |
|
133 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
134 | + * |
|
135 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
136 | + * @throws \EE_Error |
|
137 | + */ |
|
138 | + public static function get_taxes_for_admin() |
|
139 | + { |
|
140 | + if (empty(self::$_default_taxes)) { |
|
141 | + self::$_default_taxes = EE_Registry::instance()->load_model('Price')->get_all( |
|
142 | + array(array('Price_Type.PBT_ID' => 4)) |
|
143 | + ); |
|
144 | + } |
|
145 | + return self::$_default_taxes; |
|
146 | + } |
|
147 | 147 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $tax = 0; |
40 | 40 | $total_tax = 0; |
41 | 41 | // This first checks to see if the given ticket is taxable. |
42 | - if (! $ticket->get('TKT_taxable')) { |
|
42 | + if ( ! $ticket->get('TKT_taxable')) { |
|
43 | 43 | return $tax; |
44 | 44 | } |
45 | 45 | // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | public static function get_subtotal_for_admin(EE_Ticket $ticket) |
81 | 81 | { |
82 | 82 | $TKT_ID = $ticket->ID(); |
83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | - ? self::$_subtotal[ $TKT_ID ] |
|
83 | + return isset(self::$_subtotal[$TKT_ID]) |
|
84 | + ? self::$_subtotal[$TKT_ID] |
|
85 | 85 | : self::_get_subtotal_for_admin($ticket); |
86 | 86 | } |
87 | 87 |
@@ -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 | } |
@@ -13,173 +13,173 @@ |
||
13 | 13 | class EE_Message_Template extends EE_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $props_n_values |
|
18 | - * @param string $timezone |
|
19 | - * @return EE_Message_Template|mixed |
|
20 | - */ |
|
21 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
22 | - { |
|
23 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
24 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @param array $props_n_values |
|
30 | - * @param string $timezone |
|
31 | - * @return EE_Message_Template |
|
32 | - */ |
|
33 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
34 | - { |
|
35 | - return new self($props_n_values, true, $timezone); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param bool $GRP_ID |
|
41 | - * @throws EE_Error |
|
42 | - */ |
|
43 | - public function set_group_template_id($GRP_ID = false) |
|
44 | - { |
|
45 | - if (! $GRP_ID) { |
|
46 | - throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
47 | - } |
|
48 | - $this->set('GRP_ID', $GRP_ID); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * get Group ID |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @return int |
|
57 | - */ |
|
58 | - public function GRP_ID() |
|
59 | - { |
|
60 | - return $this->get('GRP_ID'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * get User ID |
|
66 | - * |
|
67 | - * @access public |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - public function user() |
|
71 | - { |
|
72 | - return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * get Message Messenger |
|
78 | - * |
|
79 | - * @access public |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function messenger() |
|
83 | - { |
|
84 | - return $this->get_first_related('Message_Template_Group')->messenger(); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * get Message Messenger OBJECT |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @return object Messenger Object for the given messenger |
|
93 | - */ |
|
94 | - public function messenger_obj() |
|
95 | - { |
|
96 | - return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * get Message Type |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function message_type() |
|
107 | - { |
|
108 | - return $this->get_first_related('Message_Template_Group')->message_type(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * get Message type OBJECT |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @return object Message Type object for the given message type |
|
117 | - */ |
|
118 | - public function message_type_obj() |
|
119 | - { |
|
120 | - return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This returns the set context array configured in the message type object |
|
126 | - * |
|
127 | - * @access public |
|
128 | - * @return array array of contexts and their configuration. |
|
129 | - */ |
|
130 | - public function contexts_config() |
|
131 | - { |
|
132 | - return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This returns the context_label for contexts as set in the message type object |
|
138 | - * |
|
139 | - * @access public |
|
140 | - * @return string label for "context" |
|
141 | - */ |
|
142 | - public function context_label() |
|
143 | - { |
|
144 | - return $this->get_first_related('Message_Template_Group')->context_label(); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * this returns if the template group this template belongs to is global |
|
150 | - * |
|
151 | - * @return boolean true if it is, false if it isn't |
|
152 | - */ |
|
153 | - public function is_global() |
|
154 | - { |
|
155 | - return $this->get_first_related('Message_Template_Group')->is_global(); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
161 | - * |
|
162 | - * @return boolean true if it is, false if it isn't |
|
163 | - */ |
|
164 | - public function is_active() |
|
165 | - { |
|
166 | - return $this->get_first_related('Message_Template_Group')->is_active(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
172 | - * this template. |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @param string $context what context we're going to return shortcodes for |
|
176 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
177 | - * to be merged and returned. |
|
178 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
179 | - * shortcodes found. |
|
180 | - */ |
|
181 | - public function get_shortcodes($context, $fields = array()) |
|
182 | - { |
|
183 | - return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
184 | - } |
|
16 | + /** |
|
17 | + * @param array $props_n_values |
|
18 | + * @param string $timezone |
|
19 | + * @return EE_Message_Template|mixed |
|
20 | + */ |
|
21 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
22 | + { |
|
23 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
24 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @param array $props_n_values |
|
30 | + * @param string $timezone |
|
31 | + * @return EE_Message_Template |
|
32 | + */ |
|
33 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
34 | + { |
|
35 | + return new self($props_n_values, true, $timezone); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param bool $GRP_ID |
|
41 | + * @throws EE_Error |
|
42 | + */ |
|
43 | + public function set_group_template_id($GRP_ID = false) |
|
44 | + { |
|
45 | + if (! $GRP_ID) { |
|
46 | + throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
47 | + } |
|
48 | + $this->set('GRP_ID', $GRP_ID); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * get Group ID |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @return int |
|
57 | + */ |
|
58 | + public function GRP_ID() |
|
59 | + { |
|
60 | + return $this->get('GRP_ID'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * get User ID |
|
66 | + * |
|
67 | + * @access public |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + public function user() |
|
71 | + { |
|
72 | + return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * get Message Messenger |
|
78 | + * |
|
79 | + * @access public |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function messenger() |
|
83 | + { |
|
84 | + return $this->get_first_related('Message_Template_Group')->messenger(); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * get Message Messenger OBJECT |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @return object Messenger Object for the given messenger |
|
93 | + */ |
|
94 | + public function messenger_obj() |
|
95 | + { |
|
96 | + return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * get Message Type |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function message_type() |
|
107 | + { |
|
108 | + return $this->get_first_related('Message_Template_Group')->message_type(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * get Message type OBJECT |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @return object Message Type object for the given message type |
|
117 | + */ |
|
118 | + public function message_type_obj() |
|
119 | + { |
|
120 | + return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This returns the set context array configured in the message type object |
|
126 | + * |
|
127 | + * @access public |
|
128 | + * @return array array of contexts and their configuration. |
|
129 | + */ |
|
130 | + public function contexts_config() |
|
131 | + { |
|
132 | + return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This returns the context_label for contexts as set in the message type object |
|
138 | + * |
|
139 | + * @access public |
|
140 | + * @return string label for "context" |
|
141 | + */ |
|
142 | + public function context_label() |
|
143 | + { |
|
144 | + return $this->get_first_related('Message_Template_Group')->context_label(); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * this returns if the template group this template belongs to is global |
|
150 | + * |
|
151 | + * @return boolean true if it is, false if it isn't |
|
152 | + */ |
|
153 | + public function is_global() |
|
154 | + { |
|
155 | + return $this->get_first_related('Message_Template_Group')->is_global(); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
161 | + * |
|
162 | + * @return boolean true if it is, false if it isn't |
|
163 | + */ |
|
164 | + public function is_active() |
|
165 | + { |
|
166 | + return $this->get_first_related('Message_Template_Group')->is_active(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
172 | + * this template. |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @param string $context what context we're going to return shortcodes for |
|
176 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
177 | + * to be merged and returned. |
|
178 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
179 | + * shortcodes found. |
|
180 | + */ |
|
181 | + public function get_shortcodes($context, $fields = array()) |
|
182 | + { |
|
183 | + return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
184 | + } |
|
185 | 185 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function set_group_template_id($GRP_ID = false) |
44 | 44 | { |
45 | - if (! $GRP_ID) { |
|
45 | + if ( ! $GRP_ID) { |
|
46 | 46 | throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
47 | 47 | } |
48 | 48 | $this->set('GRP_ID', $GRP_ID); |
@@ -14,429 +14,429 @@ |
||
14 | 14 | abstract class EE_CPT_Base extends EE_Soft_Delete_Base_Class |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * This is a property for holding cached feature images on CPT objects. Cache's are set on the first |
|
19 | - * "feature_image()" method call. Each key in the array corresponds to the requested size. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $_feature_image = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
27 | - */ |
|
28 | - protected $_wp_post; |
|
29 | - |
|
30 | - |
|
31 | - abstract public function wp_user(); |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
36 | - * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
37 | - * |
|
38 | - * @return WP_Post |
|
39 | - */ |
|
40 | - public function wp_post() |
|
41 | - { |
|
42 | - global $wpdb; |
|
43 | - if (! $this->_wp_post instanceof WP_Post) { |
|
44 | - if ($this->ID()) { |
|
45 | - $this->_wp_post = get_post($this->ID()); |
|
46 | - } else { |
|
47 | - $simulated_db_result = new stdClass(); |
|
48 | - foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
49 | - if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() |
|
50 | - === $wpdb->posts |
|
51 | - ) { |
|
52 | - $column = $field_obj->get_table_column(); |
|
53 | - |
|
54 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
55 | - $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
56 | - } elseif ($field_obj->is_db_only_field()) { |
|
57 | - $value_on_model_obj = $field_obj->get_default_value(); |
|
58 | - } else { |
|
59 | - $value_on_model_obj = $this->get_raw($field_name); |
|
60 | - } |
|
61 | - $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
62 | - } |
|
63 | - } |
|
64 | - $this->_wp_post = new WP_Post($simulated_db_result); |
|
65 | - } |
|
66 | - // and let's make retrieving the EE CPT object easy too |
|
67 | - $classname = get_class($this); |
|
68 | - if (! isset($this->_wp_post->{$classname})) { |
|
69 | - $this->_wp_post->{$classname} = $this; |
|
70 | - } |
|
71 | - } |
|
72 | - return $this->_wp_post; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * When fetching a new value for a post field that uses the global $post for rendering, |
|
77 | - * set the global $post temporarily to be this model object; and afterwards restore it |
|
78 | - * |
|
79 | - * @param string $fieldname |
|
80 | - * @param bool $pretty |
|
81 | - * @param string $extra_cache_ref |
|
82 | - * @return mixed |
|
83 | - */ |
|
84 | - protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
85 | - { |
|
86 | - global $post; |
|
87 | - |
|
88 | - if ($pretty |
|
89 | - && ( |
|
90 | - ! ( |
|
91 | - $post instanceof WP_Post |
|
92 | - && $post->ID |
|
93 | - ) |
|
94 | - || (int) $post->ID !== $this->ID() |
|
95 | - ) |
|
96 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) { |
|
97 | - $old_post = $post; |
|
98 | - $post = $this->wp_post(); |
|
99 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
100 | - $post = $old_post; |
|
101 | - } else { |
|
102 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
103 | - } |
|
104 | - return $return_value; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Adds to the specified event category. If it category doesn't exist, creates it. |
|
109 | - * |
|
110 | - * @param string $category_name |
|
111 | - * @param string $category_description optional |
|
112 | - * @param int $parent_term_taxonomy_id optional |
|
113 | - * @return EE_Term_Taxonomy |
|
114 | - */ |
|
115 | - public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null) |
|
116 | - { |
|
117 | - return $this->get_model()->add_event_category( |
|
118 | - $this, |
|
119 | - $category_name, |
|
120 | - $category_description, |
|
121 | - $parent_term_taxonomy_id |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Removes the event category by specified name from being related ot this event |
|
128 | - * |
|
129 | - * @param string $category_name |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public function remove_event_category($category_name) |
|
133 | - { |
|
134 | - return $this->get_model()->remove_event_category($this, $category_name); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Removes the relation to the specified term taxonomy, and maintains the |
|
140 | - * data integrity of the term taxonomy provided |
|
141 | - * |
|
142 | - * @param EE_Term_Taxonomy $term_taxonomy |
|
143 | - * @return EE_Base_Class the relation was removed from |
|
144 | - */ |
|
145 | - public function remove_relation_to_term_taxonomy($term_taxonomy) |
|
146 | - { |
|
147 | - if (! $term_taxonomy) { |
|
148 | - EE_Error::add_error( |
|
149 | - sprintf( |
|
150 | - __( |
|
151 | - "No Term_Taxonomy provided which to remove from model object of type %s and id %d", |
|
152 | - "event_espresso" |
|
153 | - ), |
|
154 | - get_class($this), |
|
155 | - $this->ID() |
|
156 | - ), |
|
157 | - __FILE__, |
|
158 | - __FUNCTION__, |
|
159 | - __LINE__ |
|
160 | - ); |
|
161 | - return null; |
|
162 | - } |
|
163 | - $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
164 | - $term_taxonomy->save(); |
|
165 | - return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * The main purpose of this method is to return the post type for the model object |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function post_type() |
|
176 | - { |
|
177 | - return $this->get_model()->post_type(); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * The main purpose of this method is to return the parent for the model object |
|
183 | - * |
|
184 | - * @access public |
|
185 | - * @return int |
|
186 | - */ |
|
187 | - public function parent() |
|
188 | - { |
|
189 | - return $this->get('parent'); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * return the _status property |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function status() |
|
199 | - { |
|
200 | - return $this->get('status'); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param string $status |
|
206 | - */ |
|
207 | - public function set_status($status) |
|
208 | - { |
|
209 | - $this->set('status', $status); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for |
|
215 | - * WordPress' get_the_post_thumbnail() function. |
|
216 | - * |
|
217 | - * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
218 | - * @access protected |
|
219 | - * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
220 | - * representing width and height in pixels (i.e. array(32,32) ). |
|
221 | - * @param string|array $attr Optional. Query string or array of attributes. |
|
222 | - * @return string HTML image element |
|
223 | - */ |
|
224 | - protected function _get_feature_image($size, $attr) |
|
225 | - { |
|
226 | - // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
|
227 | - $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
228 | - $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
229 | - $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
230 | - ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | - return $this->_feature_image[ $cache_key ]; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * See _get_feature_image. Returns the HTML to display a featured image |
|
237 | - * |
|
238 | - * @param string $size |
|
239 | - * @param string|array $attr |
|
240 | - * @return string of html |
|
241 | - */ |
|
242 | - public function feature_image($size = 'thumbnail', $attr = '') |
|
243 | - { |
|
244 | - return $this->_get_feature_image($size, $attr); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class |
|
250 | - * using the given size params. |
|
251 | - * |
|
252 | - * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array |
|
253 | - * representing width and height in pixels eg. array(32,32). |
|
254 | - * @return string|boolean the url of the image or false if not found |
|
255 | - */ |
|
256 | - public function feature_image_url($size = 'thumbnail') |
|
257 | - { |
|
258 | - $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
259 | - return ! empty($attachment) ? $attachment[0] : false; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * This is a method for restoring this_obj using details from the given $revision_id |
|
265 | - * |
|
266 | - * @param int $revision_id ID of the revision we're getting data from |
|
267 | - * @param array $related_obj_names if included this will be used to restore for related obj |
|
268 | - * if not included then we just do restore on the meta. |
|
269 | - * We will accept an array of related_obj_names for restoration here. |
|
270 | - * @param array $where_query You can optionally include an array of key=>value pairs |
|
271 | - * that allow you to further constrict the relation to being added. |
|
272 | - * However, keep in mind that the columns (keys) given |
|
273 | - * must match a column on the JOIN table and currently |
|
274 | - * only the HABTM models accept these additional conditions. |
|
275 | - * Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
276 | - * then a NEW row is created in the join table. |
|
277 | - * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names |
|
278 | - * sent); |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) |
|
282 | - { |
|
283 | - // get revision object |
|
284 | - $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
285 | - if ($revision_obj instanceof EE_CPT_Base) { |
|
286 | - // no related_obj_name so we assume we're saving a revision on this object. |
|
287 | - if (empty($related_obj_names)) { |
|
288 | - $fields = $this->get_model()->get_meta_table_fields(); |
|
289 | - foreach ($fields as $field) { |
|
290 | - $this->set($field, $revision_obj->get($field)); |
|
291 | - } |
|
292 | - $this->save(); |
|
293 | - } |
|
294 | - $related_obj_names = (array) $related_obj_names; |
|
295 | - foreach ($related_obj_names as $related_name) { |
|
296 | - // related_obj_name so we're saving a revision on an object related to this object |
|
297 | - // do we have $where_query params for this related object? If we do then we include that. |
|
298 | - $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
299 | - $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
300 | - $related_objs = $this->get_many_related($related_name, $where_params); |
|
301 | - $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
302 | - // load helper |
|
303 | - // remove related objs from this object that are not in revision |
|
304 | - // array_diff *should* work cause I think objects are indexed by ID? |
|
305 | - $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
306 | - foreach ($related_to_remove as $rr) { |
|
307 | - $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
308 | - } |
|
309 | - // add all related objs attached to revision to this object |
|
310 | - foreach ($revision_related_objs as $r_obj) { |
|
311 | - $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta |
|
320 | - * |
|
321 | - * @param string $meta_key |
|
322 | - * @param boolean $single |
|
323 | - * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li> |
|
324 | - * <li>If $single is set to false, or left blank, the function returns an array containing all values of the |
|
325 | - * specified key.</li> |
|
326 | - * <li>If $single is set to true, the function returns the first value of the specified key (not in an |
|
327 | - * array</li></ul> |
|
328 | - */ |
|
329 | - public function get_post_meta($meta_key = null, $single = false) |
|
330 | - { |
|
331 | - return get_post_meta($this->ID(), $meta_key, $single); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta |
|
337 | - * |
|
338 | - * @param string $meta_key |
|
339 | - * @param mixed $meta_value |
|
340 | - * @param mixed $prev_value |
|
341 | - * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. |
|
342 | - * NOTE: If the meta_value passed to this function is the same as the value that is already in the |
|
343 | - * database, this function returns false. |
|
344 | - */ |
|
345 | - public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
|
346 | - { |
|
347 | - if (! $this->ID()) { |
|
348 | - $this->save(); |
|
349 | - } |
|
350 | - return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta |
|
356 | - * |
|
357 | - * @param mixed $meta_key |
|
358 | - * @param mixed $meta_value |
|
359 | - * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
|
360 | - * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given |
|
361 | - * key already exists, in which case false is returned. |
|
362 | - */ |
|
363 | - public function add_post_meta($meta_key, $meta_value, $unique = false) |
|
364 | - { |
|
365 | - if ($this->ID()) { |
|
366 | - $this->save(); |
|
367 | - } |
|
368 | - return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
374 | - * |
|
375 | - * @param mixed $meta_key |
|
376 | - * @param mixed $meta_value |
|
377 | - * @return boolean False for failure. True for success. |
|
378 | - */ |
|
379 | - public function delete_post_meta($meta_key, $meta_value = '') |
|
380 | - { |
|
381 | - if (! $this->ID()) { |
|
382 | - // there are obviously no postmetas for this if it's not saved |
|
383 | - // so let's just report this as a success |
|
384 | - return true; |
|
385 | - } |
|
386 | - return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Gets the URL for viewing this event on the front-end |
|
392 | - * |
|
393 | - * @return string |
|
394 | - */ |
|
395 | - public function get_permalink() |
|
396 | - { |
|
397 | - return get_permalink($this->ID()); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * Gets all the term-taxonomies for this CPT |
|
403 | - * |
|
404 | - * @param array $query_params |
|
405 | - * @return EE_Term_Taxonomy |
|
406 | - */ |
|
407 | - public function term_taxonomies($query_params = array()) |
|
408 | - { |
|
409 | - return $this->get_many_related('Term_Taxonomy', $query_params); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * @return mixed |
|
415 | - */ |
|
416 | - public function get_custom_post_statuses() |
|
417 | - { |
|
418 | - return $this->get_model()->get_custom_post_statuses(); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @return mixed |
|
424 | - */ |
|
425 | - public function get_all_post_statuses() |
|
426 | - { |
|
427 | - return $this->get_model()->get_status_array(); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
433 | - * |
|
434 | - * @return array |
|
435 | - */ |
|
436 | - public function __sleep() |
|
437 | - { |
|
438 | - $properties_to_serialize = parent::__sleep(); |
|
439 | - $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
440 | - return $properties_to_serialize; |
|
441 | - } |
|
17 | + /** |
|
18 | + * This is a property for holding cached feature images on CPT objects. Cache's are set on the first |
|
19 | + * "feature_image()" method call. Each key in the array corresponds to the requested size. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $_feature_image = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
27 | + */ |
|
28 | + protected $_wp_post; |
|
29 | + |
|
30 | + |
|
31 | + abstract public function wp_user(); |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
36 | + * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
37 | + * |
|
38 | + * @return WP_Post |
|
39 | + */ |
|
40 | + public function wp_post() |
|
41 | + { |
|
42 | + global $wpdb; |
|
43 | + if (! $this->_wp_post instanceof WP_Post) { |
|
44 | + if ($this->ID()) { |
|
45 | + $this->_wp_post = get_post($this->ID()); |
|
46 | + } else { |
|
47 | + $simulated_db_result = new stdClass(); |
|
48 | + foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
49 | + if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() |
|
50 | + === $wpdb->posts |
|
51 | + ) { |
|
52 | + $column = $field_obj->get_table_column(); |
|
53 | + |
|
54 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
55 | + $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
56 | + } elseif ($field_obj->is_db_only_field()) { |
|
57 | + $value_on_model_obj = $field_obj->get_default_value(); |
|
58 | + } else { |
|
59 | + $value_on_model_obj = $this->get_raw($field_name); |
|
60 | + } |
|
61 | + $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
62 | + } |
|
63 | + } |
|
64 | + $this->_wp_post = new WP_Post($simulated_db_result); |
|
65 | + } |
|
66 | + // and let's make retrieving the EE CPT object easy too |
|
67 | + $classname = get_class($this); |
|
68 | + if (! isset($this->_wp_post->{$classname})) { |
|
69 | + $this->_wp_post->{$classname} = $this; |
|
70 | + } |
|
71 | + } |
|
72 | + return $this->_wp_post; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * When fetching a new value for a post field that uses the global $post for rendering, |
|
77 | + * set the global $post temporarily to be this model object; and afterwards restore it |
|
78 | + * |
|
79 | + * @param string $fieldname |
|
80 | + * @param bool $pretty |
|
81 | + * @param string $extra_cache_ref |
|
82 | + * @return mixed |
|
83 | + */ |
|
84 | + protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
85 | + { |
|
86 | + global $post; |
|
87 | + |
|
88 | + if ($pretty |
|
89 | + && ( |
|
90 | + ! ( |
|
91 | + $post instanceof WP_Post |
|
92 | + && $post->ID |
|
93 | + ) |
|
94 | + || (int) $post->ID !== $this->ID() |
|
95 | + ) |
|
96 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) { |
|
97 | + $old_post = $post; |
|
98 | + $post = $this->wp_post(); |
|
99 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
100 | + $post = $old_post; |
|
101 | + } else { |
|
102 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
103 | + } |
|
104 | + return $return_value; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Adds to the specified event category. If it category doesn't exist, creates it. |
|
109 | + * |
|
110 | + * @param string $category_name |
|
111 | + * @param string $category_description optional |
|
112 | + * @param int $parent_term_taxonomy_id optional |
|
113 | + * @return EE_Term_Taxonomy |
|
114 | + */ |
|
115 | + public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null) |
|
116 | + { |
|
117 | + return $this->get_model()->add_event_category( |
|
118 | + $this, |
|
119 | + $category_name, |
|
120 | + $category_description, |
|
121 | + $parent_term_taxonomy_id |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Removes the event category by specified name from being related ot this event |
|
128 | + * |
|
129 | + * @param string $category_name |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public function remove_event_category($category_name) |
|
133 | + { |
|
134 | + return $this->get_model()->remove_event_category($this, $category_name); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Removes the relation to the specified term taxonomy, and maintains the |
|
140 | + * data integrity of the term taxonomy provided |
|
141 | + * |
|
142 | + * @param EE_Term_Taxonomy $term_taxonomy |
|
143 | + * @return EE_Base_Class the relation was removed from |
|
144 | + */ |
|
145 | + public function remove_relation_to_term_taxonomy($term_taxonomy) |
|
146 | + { |
|
147 | + if (! $term_taxonomy) { |
|
148 | + EE_Error::add_error( |
|
149 | + sprintf( |
|
150 | + __( |
|
151 | + "No Term_Taxonomy provided which to remove from model object of type %s and id %d", |
|
152 | + "event_espresso" |
|
153 | + ), |
|
154 | + get_class($this), |
|
155 | + $this->ID() |
|
156 | + ), |
|
157 | + __FILE__, |
|
158 | + __FUNCTION__, |
|
159 | + __LINE__ |
|
160 | + ); |
|
161 | + return null; |
|
162 | + } |
|
163 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
164 | + $term_taxonomy->save(); |
|
165 | + return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * The main purpose of this method is to return the post type for the model object |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function post_type() |
|
176 | + { |
|
177 | + return $this->get_model()->post_type(); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * The main purpose of this method is to return the parent for the model object |
|
183 | + * |
|
184 | + * @access public |
|
185 | + * @return int |
|
186 | + */ |
|
187 | + public function parent() |
|
188 | + { |
|
189 | + return $this->get('parent'); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * return the _status property |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function status() |
|
199 | + { |
|
200 | + return $this->get('status'); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param string $status |
|
206 | + */ |
|
207 | + public function set_status($status) |
|
208 | + { |
|
209 | + $this->set('status', $status); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for |
|
215 | + * WordPress' get_the_post_thumbnail() function. |
|
216 | + * |
|
217 | + * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
218 | + * @access protected |
|
219 | + * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
220 | + * representing width and height in pixels (i.e. array(32,32) ). |
|
221 | + * @param string|array $attr Optional. Query string or array of attributes. |
|
222 | + * @return string HTML image element |
|
223 | + */ |
|
224 | + protected function _get_feature_image($size, $attr) |
|
225 | + { |
|
226 | + // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
|
227 | + $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
228 | + $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
229 | + $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
230 | + ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | + return $this->_feature_image[ $cache_key ]; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * See _get_feature_image. Returns the HTML to display a featured image |
|
237 | + * |
|
238 | + * @param string $size |
|
239 | + * @param string|array $attr |
|
240 | + * @return string of html |
|
241 | + */ |
|
242 | + public function feature_image($size = 'thumbnail', $attr = '') |
|
243 | + { |
|
244 | + return $this->_get_feature_image($size, $attr); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class |
|
250 | + * using the given size params. |
|
251 | + * |
|
252 | + * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array |
|
253 | + * representing width and height in pixels eg. array(32,32). |
|
254 | + * @return string|boolean the url of the image or false if not found |
|
255 | + */ |
|
256 | + public function feature_image_url($size = 'thumbnail') |
|
257 | + { |
|
258 | + $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
259 | + return ! empty($attachment) ? $attachment[0] : false; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * This is a method for restoring this_obj using details from the given $revision_id |
|
265 | + * |
|
266 | + * @param int $revision_id ID of the revision we're getting data from |
|
267 | + * @param array $related_obj_names if included this will be used to restore for related obj |
|
268 | + * if not included then we just do restore on the meta. |
|
269 | + * We will accept an array of related_obj_names for restoration here. |
|
270 | + * @param array $where_query You can optionally include an array of key=>value pairs |
|
271 | + * that allow you to further constrict the relation to being added. |
|
272 | + * However, keep in mind that the columns (keys) given |
|
273 | + * must match a column on the JOIN table and currently |
|
274 | + * only the HABTM models accept these additional conditions. |
|
275 | + * Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
276 | + * then a NEW row is created in the join table. |
|
277 | + * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names |
|
278 | + * sent); |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) |
|
282 | + { |
|
283 | + // get revision object |
|
284 | + $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
285 | + if ($revision_obj instanceof EE_CPT_Base) { |
|
286 | + // no related_obj_name so we assume we're saving a revision on this object. |
|
287 | + if (empty($related_obj_names)) { |
|
288 | + $fields = $this->get_model()->get_meta_table_fields(); |
|
289 | + foreach ($fields as $field) { |
|
290 | + $this->set($field, $revision_obj->get($field)); |
|
291 | + } |
|
292 | + $this->save(); |
|
293 | + } |
|
294 | + $related_obj_names = (array) $related_obj_names; |
|
295 | + foreach ($related_obj_names as $related_name) { |
|
296 | + // related_obj_name so we're saving a revision on an object related to this object |
|
297 | + // do we have $where_query params for this related object? If we do then we include that. |
|
298 | + $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
299 | + $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
300 | + $related_objs = $this->get_many_related($related_name, $where_params); |
|
301 | + $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
302 | + // load helper |
|
303 | + // remove related objs from this object that are not in revision |
|
304 | + // array_diff *should* work cause I think objects are indexed by ID? |
|
305 | + $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
306 | + foreach ($related_to_remove as $rr) { |
|
307 | + $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
308 | + } |
|
309 | + // add all related objs attached to revision to this object |
|
310 | + foreach ($revision_related_objs as $r_obj) { |
|
311 | + $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta |
|
320 | + * |
|
321 | + * @param string $meta_key |
|
322 | + * @param boolean $single |
|
323 | + * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li> |
|
324 | + * <li>If $single is set to false, or left blank, the function returns an array containing all values of the |
|
325 | + * specified key.</li> |
|
326 | + * <li>If $single is set to true, the function returns the first value of the specified key (not in an |
|
327 | + * array</li></ul> |
|
328 | + */ |
|
329 | + public function get_post_meta($meta_key = null, $single = false) |
|
330 | + { |
|
331 | + return get_post_meta($this->ID(), $meta_key, $single); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta |
|
337 | + * |
|
338 | + * @param string $meta_key |
|
339 | + * @param mixed $meta_value |
|
340 | + * @param mixed $prev_value |
|
341 | + * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. |
|
342 | + * NOTE: If the meta_value passed to this function is the same as the value that is already in the |
|
343 | + * database, this function returns false. |
|
344 | + */ |
|
345 | + public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
|
346 | + { |
|
347 | + if (! $this->ID()) { |
|
348 | + $this->save(); |
|
349 | + } |
|
350 | + return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta |
|
356 | + * |
|
357 | + * @param mixed $meta_key |
|
358 | + * @param mixed $meta_value |
|
359 | + * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
|
360 | + * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given |
|
361 | + * key already exists, in which case false is returned. |
|
362 | + */ |
|
363 | + public function add_post_meta($meta_key, $meta_value, $unique = false) |
|
364 | + { |
|
365 | + if ($this->ID()) { |
|
366 | + $this->save(); |
|
367 | + } |
|
368 | + return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
374 | + * |
|
375 | + * @param mixed $meta_key |
|
376 | + * @param mixed $meta_value |
|
377 | + * @return boolean False for failure. True for success. |
|
378 | + */ |
|
379 | + public function delete_post_meta($meta_key, $meta_value = '') |
|
380 | + { |
|
381 | + if (! $this->ID()) { |
|
382 | + // there are obviously no postmetas for this if it's not saved |
|
383 | + // so let's just report this as a success |
|
384 | + return true; |
|
385 | + } |
|
386 | + return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Gets the URL for viewing this event on the front-end |
|
392 | + * |
|
393 | + * @return string |
|
394 | + */ |
|
395 | + public function get_permalink() |
|
396 | + { |
|
397 | + return get_permalink($this->ID()); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * Gets all the term-taxonomies for this CPT |
|
403 | + * |
|
404 | + * @param array $query_params |
|
405 | + * @return EE_Term_Taxonomy |
|
406 | + */ |
|
407 | + public function term_taxonomies($query_params = array()) |
|
408 | + { |
|
409 | + return $this->get_many_related('Term_Taxonomy', $query_params); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * @return mixed |
|
415 | + */ |
|
416 | + public function get_custom_post_statuses() |
|
417 | + { |
|
418 | + return $this->get_model()->get_custom_post_statuses(); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @return mixed |
|
424 | + */ |
|
425 | + public function get_all_post_statuses() |
|
426 | + { |
|
427 | + return $this->get_model()->get_status_array(); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
433 | + * |
|
434 | + * @return array |
|
435 | + */ |
|
436 | + public function __sleep() |
|
437 | + { |
|
438 | + $properties_to_serialize = parent::__sleep(); |
|
439 | + $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
440 | + return $properties_to_serialize; |
|
441 | + } |
|
442 | 442 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function wp_post() |
41 | 41 | { |
42 | 42 | global $wpdb; |
43 | - if (! $this->_wp_post instanceof WP_Post) { |
|
43 | + if ( ! $this->_wp_post instanceof WP_Post) { |
|
44 | 44 | if ($this->ID()) { |
45 | 45 | $this->_wp_post = get_post($this->ID()); |
46 | 46 | } else { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | // and let's make retrieving the EE CPT object easy too |
67 | 67 | $classname = get_class($this); |
68 | - if (! isset($this->_wp_post->{$classname})) { |
|
68 | + if ( ! isset($this->_wp_post->{$classname})) { |
|
69 | 69 | $this->_wp_post->{$classname} = $this; |
70 | 70 | } |
71 | 71 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function remove_relation_to_term_taxonomy($term_taxonomy) |
146 | 146 | { |
147 | - if (! $term_taxonomy) { |
|
147 | + if ( ! $term_taxonomy) { |
|
148 | 148 | EE_Error::add_error( |
149 | 149 | sprintf( |
150 | 150 | __( |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | { |
226 | 226 | // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
227 | 227 | $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
228 | - $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
229 | - $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
230 | - ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | - return $this->_feature_image[ $cache_key ]; |
|
228 | + $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key; |
|
229 | + $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key]) |
|
230 | + ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | + return $this->_feature_image[$cache_key]; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | foreach ($related_obj_names as $related_name) { |
296 | 296 | // related_obj_name so we're saving a revision on an object related to this object |
297 | 297 | // do we have $where_query params for this related object? If we do then we include that. |
298 | - $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
298 | + $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array(); |
|
299 | 299 | $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
300 | 300 | $related_objs = $this->get_many_related($related_name, $where_params); |
301 | 301 | $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
346 | 346 | { |
347 | - if (! $this->ID()) { |
|
347 | + if ( ! $this->ID()) { |
|
348 | 348 | $this->save(); |
349 | 349 | } |
350 | 350 | return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | */ |
379 | 379 | public function delete_post_meta($meta_key, $meta_value = '') |
380 | 380 | { |
381 | - if (! $this->ID()) { |
|
381 | + if ( ! $this->ID()) { |
|
382 | 382 | // there are obviously no postmetas for this if it's not saved |
383 | 383 | // so let's just report this as a success |
384 | 384 | return true; |
@@ -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 | } |