@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | '[TKT_USES_*]' => esc_html__( |
48 | 48 | 'This attribute based shortcode parses to show the number of uses the ticket has. The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite. Options are:', |
49 | 49 | 'event_espresso' |
50 | - ) . |
|
51 | - '<p><ul>' . |
|
52 | - '<li><strong>symbol</strong>:' . esc_html__( |
|
50 | + ). |
|
51 | + '<p><ul>'. |
|
52 | + '<li><strong>symbol</strong>:'.esc_html__( |
|
53 | 53 | 'This returns the ∞ symbol.', |
54 | 54 | 'event_espresso' |
55 | - ) . '</li>' . |
|
56 | - '<li><strong>text</strong>:' . esc_html__( |
|
55 | + ).'</li>'. |
|
56 | + '<li><strong>text</strong>:'.esc_html__( |
|
57 | 57 | 'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.', |
58 | 58 | 'event_espresso' |
59 | - ) . '</li>' . |
|
60 | - '<li><strong>{custom}</strong>:' . esc_html__( |
|
59 | + ).'</li>'. |
|
60 | + '<li><strong>{custom}</strong>:'.esc_html__( |
|
61 | 61 | 'You can put anything you want as a string instead and that will be used. So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".', |
62 | 62 | 'event_espresso' |
63 | - ) . '</li>' . |
|
63 | + ).'</li>'. |
|
64 | 64 | '</ul></p>', |
65 | 65 | ); |
66 | 66 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | $this->_ticket = empty($this->_ticket) |
83 | 83 | && $this->_data instanceof EE_Line_Item |
84 | 84 | && $aee instanceof EE_Messages_Addressee |
85 | - && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']) |
|
86 | - && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket |
|
87 | - ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] |
|
85 | + && ! empty($aee->line_items_with_children[$this->_data->ID()]['EE_Ticket']) |
|
86 | + && $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] instanceof EE_Ticket |
|
87 | + ? $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] |
|
88 | 88 | : $this->_ticket; |
89 | 89 | |
90 | 90 | // if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | |
97 | 97 | // If there is no event object by now then get out. |
98 | - if (! $this->_ticket instanceof EE_Ticket) { |
|
98 | + if ( ! $this->_ticket instanceof EE_Ticket) { |
|
99 | 99 | return ''; |
100 | 100 | } |
101 | 101 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | break; |
122 | 122 | |
123 | 123 | case '[TKT_QTY_PURCHASED]': |
124 | - return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : ''; |
|
124 | + return $aee instanceof EE_Messages_Addressee ? $aee->tickets[$this->_ticket->ID()]['count'] : ''; |
|
125 | 125 | break; |
126 | 126 | } |
127 | 127 |
@@ -17,123 +17,123 @@ |
||
17 | 17 | */ |
18 | 18 | class EE_Ticket_Shortcodes extends EE_Shortcodes |
19 | 19 | { |
20 | - /** |
|
21 | - * Will hold the EE_Ticket if available |
|
22 | - * |
|
23 | - * @var EE_Ticket |
|
24 | - */ |
|
25 | - protected $_ticket; |
|
26 | - |
|
27 | - |
|
28 | - protected function _init_props() |
|
29 | - { |
|
30 | - $this->label = esc_html__('Ticket Shortcodes', 'event_espresso'); |
|
31 | - $this->description = esc_html__('All shortcodes specific to ticket related data', 'event_espresso'); |
|
32 | - $this->_shortcodes = array( |
|
33 | - '[TICKET_ID]' => esc_html__('Will be replaced by the ticket ID of a ticket', 'event_espresso'), |
|
34 | - '[TICKET_NAME]' => esc_html__('The name of the ticket', 'event_espresso'), |
|
35 | - '[TICKET_DESCRIPTION]' => esc_html__('The description of the ticket', 'event_espresso'), |
|
36 | - '[TICKET_PRICE]' => esc_html__('The price of the ticket', 'event_espresso'), |
|
37 | - '[TICKET_PRICE_WITH_TAXES]' => esc_html__( |
|
38 | - 'The price of the ticket including any taxes that might be on the ticket', |
|
39 | - 'event_espresso' |
|
40 | - ), |
|
41 | - '[TKT_QTY_PURCHASED]' => esc_html__( |
|
42 | - 'The total quantity of the current ticket in the list that has been purchased in this transaction', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - '[TKT_USES_*]' => esc_html__( |
|
46 | - 'This attribute based shortcode parses to show the number of uses the ticket has. The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite. Options are:', |
|
47 | - 'event_espresso' |
|
48 | - ) . |
|
49 | - '<p><ul>' . |
|
50 | - '<li><strong>symbol</strong>:' . esc_html__( |
|
51 | - 'This returns the ∞ symbol.', |
|
52 | - 'event_espresso' |
|
53 | - ) . '</li>' . |
|
54 | - '<li><strong>text</strong>:' . esc_html__( |
|
55 | - 'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.', |
|
56 | - 'event_espresso' |
|
57 | - ) . '</li>' . |
|
58 | - '<li><strong>{custom}</strong>:' . esc_html__( |
|
59 | - 'You can put anything you want as a string instead and that will be used. So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".', |
|
60 | - 'event_espresso' |
|
61 | - ) . '</li>' . |
|
62 | - '</ul></p>', |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - protected function _parser($shortcode) |
|
68 | - { |
|
69 | - |
|
70 | - $this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null; |
|
71 | - |
|
72 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
73 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
74 | - $this->_extra_data |
|
75 | - ) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
76 | - ? $this->_extra_data['data'] : $aee; |
|
77 | - |
|
78 | - |
|
79 | - // possible EE_Line_Item may be incoming data |
|
80 | - $this->_ticket = empty($this->_ticket) |
|
81 | - && $this->_data instanceof EE_Line_Item |
|
82 | - && $aee instanceof EE_Messages_Addressee |
|
83 | - && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']) |
|
84 | - && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket |
|
85 | - ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] |
|
86 | - : $this->_ticket; |
|
87 | - |
|
88 | - // if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. |
|
89 | - if (empty($this->_ticket)) { |
|
90 | - $this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
91 | - ? $aee->reg_obj->ticket() : null; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - // If there is no event object by now then get out. |
|
96 | - if (! $this->_ticket instanceof EE_Ticket) { |
|
97 | - return ''; |
|
98 | - } |
|
99 | - |
|
100 | - switch ($shortcode) { |
|
101 | - case '[TICKET_ID]': |
|
102 | - return $this->_ticket->ID(); |
|
103 | - break; |
|
104 | - |
|
105 | - case '[TICKET_NAME]': |
|
106 | - return $this->_ticket->get('TKT_name'); |
|
107 | - break; |
|
108 | - |
|
109 | - case '[TICKET_DESCRIPTION]': |
|
110 | - return $this->_ticket->get('TKT_description'); |
|
111 | - break; |
|
112 | - |
|
113 | - case '[TICKET_PRICE]': |
|
114 | - return EEH_Template::format_currency($this->_ticket->get('TKT_price')); |
|
115 | - break; |
|
116 | - |
|
117 | - case '[TICKET_PRICE_WITH_TAXES]': |
|
118 | - return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes()); |
|
119 | - break; |
|
120 | - |
|
121 | - case '[TKT_QTY_PURCHASED]': |
|
122 | - return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : ''; |
|
123 | - break; |
|
124 | - } |
|
125 | - |
|
126 | - if (strpos($shortcode, '[TKT_USES_*') !== false) { |
|
127 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
128 | - $schema = empty($attrs['schema']) ? null : $attrs['schema']; |
|
129 | - return $this->_ticket->get_pretty('TKT_uses', $schema); |
|
130 | - } |
|
131 | - return ''; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - public function get_ticket_set() |
|
136 | - { |
|
137 | - return $this->_ticket; |
|
138 | - } |
|
20 | + /** |
|
21 | + * Will hold the EE_Ticket if available |
|
22 | + * |
|
23 | + * @var EE_Ticket |
|
24 | + */ |
|
25 | + protected $_ticket; |
|
26 | + |
|
27 | + |
|
28 | + protected function _init_props() |
|
29 | + { |
|
30 | + $this->label = esc_html__('Ticket Shortcodes', 'event_espresso'); |
|
31 | + $this->description = esc_html__('All shortcodes specific to ticket related data', 'event_espresso'); |
|
32 | + $this->_shortcodes = array( |
|
33 | + '[TICKET_ID]' => esc_html__('Will be replaced by the ticket ID of a ticket', 'event_espresso'), |
|
34 | + '[TICKET_NAME]' => esc_html__('The name of the ticket', 'event_espresso'), |
|
35 | + '[TICKET_DESCRIPTION]' => esc_html__('The description of the ticket', 'event_espresso'), |
|
36 | + '[TICKET_PRICE]' => esc_html__('The price of the ticket', 'event_espresso'), |
|
37 | + '[TICKET_PRICE_WITH_TAXES]' => esc_html__( |
|
38 | + 'The price of the ticket including any taxes that might be on the ticket', |
|
39 | + 'event_espresso' |
|
40 | + ), |
|
41 | + '[TKT_QTY_PURCHASED]' => esc_html__( |
|
42 | + 'The total quantity of the current ticket in the list that has been purchased in this transaction', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + '[TKT_USES_*]' => esc_html__( |
|
46 | + 'This attribute based shortcode parses to show the number of uses the ticket has. The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite. Options are:', |
|
47 | + 'event_espresso' |
|
48 | + ) . |
|
49 | + '<p><ul>' . |
|
50 | + '<li><strong>symbol</strong>:' . esc_html__( |
|
51 | + 'This returns the ∞ symbol.', |
|
52 | + 'event_espresso' |
|
53 | + ) . '</li>' . |
|
54 | + '<li><strong>text</strong>:' . esc_html__( |
|
55 | + 'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.', |
|
56 | + 'event_espresso' |
|
57 | + ) . '</li>' . |
|
58 | + '<li><strong>{custom}</strong>:' . esc_html__( |
|
59 | + 'You can put anything you want as a string instead and that will be used. So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".', |
|
60 | + 'event_espresso' |
|
61 | + ) . '</li>' . |
|
62 | + '</ul></p>', |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + protected function _parser($shortcode) |
|
68 | + { |
|
69 | + |
|
70 | + $this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null; |
|
71 | + |
|
72 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
73 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
74 | + $this->_extra_data |
|
75 | + ) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
76 | + ? $this->_extra_data['data'] : $aee; |
|
77 | + |
|
78 | + |
|
79 | + // possible EE_Line_Item may be incoming data |
|
80 | + $this->_ticket = empty($this->_ticket) |
|
81 | + && $this->_data instanceof EE_Line_Item |
|
82 | + && $aee instanceof EE_Messages_Addressee |
|
83 | + && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']) |
|
84 | + && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket |
|
85 | + ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] |
|
86 | + : $this->_ticket; |
|
87 | + |
|
88 | + // if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. |
|
89 | + if (empty($this->_ticket)) { |
|
90 | + $this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
91 | + ? $aee->reg_obj->ticket() : null; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + // If there is no event object by now then get out. |
|
96 | + if (! $this->_ticket instanceof EE_Ticket) { |
|
97 | + return ''; |
|
98 | + } |
|
99 | + |
|
100 | + switch ($shortcode) { |
|
101 | + case '[TICKET_ID]': |
|
102 | + return $this->_ticket->ID(); |
|
103 | + break; |
|
104 | + |
|
105 | + case '[TICKET_NAME]': |
|
106 | + return $this->_ticket->get('TKT_name'); |
|
107 | + break; |
|
108 | + |
|
109 | + case '[TICKET_DESCRIPTION]': |
|
110 | + return $this->_ticket->get('TKT_description'); |
|
111 | + break; |
|
112 | + |
|
113 | + case '[TICKET_PRICE]': |
|
114 | + return EEH_Template::format_currency($this->_ticket->get('TKT_price')); |
|
115 | + break; |
|
116 | + |
|
117 | + case '[TICKET_PRICE_WITH_TAXES]': |
|
118 | + return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes()); |
|
119 | + break; |
|
120 | + |
|
121 | + case '[TKT_QTY_PURCHASED]': |
|
122 | + return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : ''; |
|
123 | + break; |
|
124 | + } |
|
125 | + |
|
126 | + if (strpos($shortcode, '[TKT_USES_*') !== false) { |
|
127 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
128 | + $schema = empty($attrs['schema']) ? null : $attrs['schema']; |
|
129 | + return $this->_ticket->get_pretty('TKT_uses', $schema); |
|
130 | + } |
|
131 | + return ''; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + public function get_ticket_set() |
|
136 | + { |
|
137 | + return $this->_ticket; |
|
138 | + } |
|
139 | 139 | } |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults. Attributes that are available are:', |
30 | 30 | 'event_espresso' |
31 | 31 | ) |
32 | - . '<p><ul>' . |
|
33 | - '<li><strong>no_payments</strong>:' . sprintf( |
|
32 | + . '<p><ul>'. |
|
33 | + '<li><strong>no_payments</strong>:'.sprintf( |
|
34 | 34 | esc_html__( |
35 | 35 | 'Indicate with this attribute what will be used if there are no payments present. Default is: "%sNo approved payments have been received.%s"', |
36 | 36 | 'event_espresso' |
37 | 37 | ), |
38 | 38 | htmlspecialchars('<td class="aln-cntr" colspan="6">'), |
39 | 39 | htmlspecialchars('</td>') |
40 | - ) . '</li>' . |
|
40 | + ).'</li>'. |
|
41 | 41 | '</ul></p>', |
42 | 42 | ); |
43 | 43 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $this->_validate_list_requirements(); |
68 | 68 | |
69 | 69 | |
70 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
70 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
71 | 71 | return ''; |
72 | 72 | } |
73 | 73 |
@@ -18,88 +18,88 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Payment_List_Shortcodes extends EE_Shortcodes |
20 | 20 | { |
21 | - protected function _init_props() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Payment List Shortcodes', 'event_espresso'); |
|
24 | - $this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso'); |
|
25 | - $this->_shortcodes = array( |
|
26 | - '[PAYMENT_LIST_*]' => esc_html__( |
|
27 | - 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults. Attributes that are available are:', |
|
28 | - 'event_espresso' |
|
29 | - ) |
|
30 | - . '<p><ul>' . |
|
31 | - '<li><strong>no_payments</strong>:' . sprintf( |
|
32 | - esc_html__( |
|
33 | - 'Indicate with this attribute what will be used if there are no payments present. Default is: "%sNo approved payments have been received.%s"', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - htmlspecialchars('<td class="aln-cntr" colspan="6">'), |
|
37 | - htmlspecialchars('</td>') |
|
38 | - ) . '</li>' . |
|
39 | - '</ul></p>', |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _parser($shortcode) |
|
45 | - { |
|
46 | - |
|
47 | - if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) { |
|
48 | - return $this->_get_payment_list($shortcode); |
|
49 | - } |
|
50 | - return ''; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * verify incoming data contains what is needed for retrieving and parsing each payment for transaction. |
|
56 | - * |
|
57 | - * @since 4.5.0 |
|
58 | - * |
|
59 | - * @param string $shortcode The incoming shortcode. |
|
60 | - * |
|
61 | - * @return string parsed ticket line item list. |
|
62 | - */ |
|
63 | - private function _get_payment_list($shortcode) |
|
64 | - { |
|
65 | - $this->_validate_list_requirements(); |
|
66 | - |
|
67 | - |
|
68 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
69 | - return ''; |
|
70 | - } |
|
71 | - |
|
72 | - $valid_shortcodes = array('payment'); |
|
73 | - |
|
74 | - $addressee_obj = $this->_data['data']; |
|
75 | - $templates = $this->_extra_data['template']; |
|
76 | - $payments = apply_filters( |
|
77 | - 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', |
|
78 | - $addressee_obj->payments |
|
79 | - ); |
|
80 | - |
|
81 | - // let's get any attributes that may be present and set the defaults. |
|
82 | - $atts = $this->_get_shortcode_attrs($shortcode); |
|
83 | - |
|
84 | - $no_payments_msg = empty($atts['no_payments']) ? esc_html__( |
|
85 | - 'No approved payments have been received.', |
|
86 | - 'event_espresso' |
|
87 | - ) : $atts['no_payments']; |
|
88 | - |
|
89 | - // made it here so we have an array of paymnets, so we should have what we need. |
|
90 | - $payment_content = empty($payments) ? $no_payments_msg : ''; |
|
91 | - |
|
92 | - $payments = (array) $payments; |
|
93 | - |
|
94 | - foreach ($payments as $payment) { |
|
95 | - $payment_content .= $this->_shortcode_helper->parse_payment_list_template( |
|
96 | - $templates['payment_list'], |
|
97 | - $payment, |
|
98 | - $valid_shortcodes, |
|
99 | - $this->_extra_data |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - return $payment_content; |
|
104 | - } |
|
21 | + protected function _init_props() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Payment List Shortcodes', 'event_espresso'); |
|
24 | + $this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso'); |
|
25 | + $this->_shortcodes = array( |
|
26 | + '[PAYMENT_LIST_*]' => esc_html__( |
|
27 | + 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults. Attributes that are available are:', |
|
28 | + 'event_espresso' |
|
29 | + ) |
|
30 | + . '<p><ul>' . |
|
31 | + '<li><strong>no_payments</strong>:' . sprintf( |
|
32 | + esc_html__( |
|
33 | + 'Indicate with this attribute what will be used if there are no payments present. Default is: "%sNo approved payments have been received.%s"', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + htmlspecialchars('<td class="aln-cntr" colspan="6">'), |
|
37 | + htmlspecialchars('</td>') |
|
38 | + ) . '</li>' . |
|
39 | + '</ul></p>', |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _parser($shortcode) |
|
45 | + { |
|
46 | + |
|
47 | + if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) { |
|
48 | + return $this->_get_payment_list($shortcode); |
|
49 | + } |
|
50 | + return ''; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * verify incoming data contains what is needed for retrieving and parsing each payment for transaction. |
|
56 | + * |
|
57 | + * @since 4.5.0 |
|
58 | + * |
|
59 | + * @param string $shortcode The incoming shortcode. |
|
60 | + * |
|
61 | + * @return string parsed ticket line item list. |
|
62 | + */ |
|
63 | + private function _get_payment_list($shortcode) |
|
64 | + { |
|
65 | + $this->_validate_list_requirements(); |
|
66 | + |
|
67 | + |
|
68 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
69 | + return ''; |
|
70 | + } |
|
71 | + |
|
72 | + $valid_shortcodes = array('payment'); |
|
73 | + |
|
74 | + $addressee_obj = $this->_data['data']; |
|
75 | + $templates = $this->_extra_data['template']; |
|
76 | + $payments = apply_filters( |
|
77 | + 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', |
|
78 | + $addressee_obj->payments |
|
79 | + ); |
|
80 | + |
|
81 | + // let's get any attributes that may be present and set the defaults. |
|
82 | + $atts = $this->_get_shortcode_attrs($shortcode); |
|
83 | + |
|
84 | + $no_payments_msg = empty($atts['no_payments']) ? esc_html__( |
|
85 | + 'No approved payments have been received.', |
|
86 | + 'event_espresso' |
|
87 | + ) : $atts['no_payments']; |
|
88 | + |
|
89 | + // made it here so we have an array of paymnets, so we should have what we need. |
|
90 | + $payment_content = empty($payments) ? $no_payments_msg : ''; |
|
91 | + |
|
92 | + $payments = (array) $payments; |
|
93 | + |
|
94 | + foreach ($payments as $payment) { |
|
95 | + $payment_content .= $this->_shortcode_helper->parse_payment_list_template( |
|
96 | + $templates['payment_list'], |
|
97 | + $payment, |
|
98 | + $valid_shortcodes, |
|
99 | + $this->_extra_data |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + return $payment_content; |
|
104 | + } |
|
105 | 105 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $action = $request->getRequestParam('action'); |
62 | 62 | // show error message about buttons/urls not working as expected if messenger deactivated. |
63 | 63 | if ($action === 'update_message_template' && is_admin()) { |
64 | - if (! isset($this->_active_messengers['pdf'])) { |
|
64 | + if ( ! isset($this->_active_messengers['pdf'])) { |
|
65 | 65 | EE_Error::add_attention( |
66 | 66 | esc_html__( |
67 | 67 | 'Be aware that the pdf messenger is inactive. This means that any pdf related shortcodes will parse to an empty string.', |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | } |
72 | 72 | |
73 | - if (! isset($this->_active_messengers['html'])) { |
|
73 | + if ( ! isset($this->_active_messengers['html'])) { |
|
74 | 74 | EE_Error::add_attention( |
75 | 75 | esc_html__( |
76 | 76 | 'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
94 | 94 | ? $this->_extra_data['data'] : $recipient; |
95 | 95 | |
96 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
96 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
97 | 97 | return ''; |
98 | 98 | } |
99 | 99 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | 'event_espresso' |
133 | 133 | ); |
134 | 134 | $content = ' |
135 | -<form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" > |
|
136 | - <input class="print_button" type="submit" value="' . $download_text . '" /> |
|
135 | +<form method="post" action="' . $this->_get_url($recipient, $sending_messenger).'" > |
|
136 | + <input class="print_button" type="submit" value="' . $download_text.'" /> |
|
137 | 137 | </form> |
138 | 138 | '; |
139 | 139 | return $content; |
@@ -22,157 +22,157 @@ |
||
22 | 22 | */ |
23 | 23 | class EE_Messenger_Shortcodes extends EE_Shortcodes |
24 | 24 | { |
25 | - /** |
|
26 | - * Hold array of active messengers indexed by messenger name. |
|
27 | - * |
|
28 | - * @since 4.5.0 |
|
29 | - * |
|
30 | - * @var EE_messenger[] |
|
31 | - */ |
|
32 | - protected $_active_messengers = array(); |
|
33 | - |
|
34 | - |
|
35 | - protected function _init_props() |
|
36 | - { |
|
37 | - $this->label = esc_html__('Messenger Shortcodes', 'event_espresso'); |
|
38 | - $this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso'); |
|
39 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
40 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
41 | - // add messages about what happens when the messenger is active. |
|
42 | - $this->_active_messengers = $message_resource_manager->active_messengers(); |
|
43 | - |
|
44 | - $this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__( |
|
45 | - 'This will return a link to view the template in a browser if the html messenger is active.', |
|
46 | - 'event_espresso' |
|
47 | - ); |
|
48 | - $this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__( |
|
49 | - 'This will return a link to generate a pdf for the template if the pdf messenger is active.', |
|
50 | - 'event_espresso' |
|
51 | - ); |
|
52 | - $this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__( |
|
53 | - 'This will return html for a download pdf button trigger if the pdf messenger is active.', |
|
54 | - 'event_espresso' |
|
55 | - ); |
|
56 | - |
|
57 | - /** @var RequestInterface $request */ |
|
58 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
59 | - $action = $request->getRequestParam('action'); |
|
60 | - // show error message about buttons/urls not working as expected if messenger deactivated. |
|
61 | - if ($action === 'update_message_template' && is_admin()) { |
|
62 | - if (! isset($this->_active_messengers['pdf'])) { |
|
63 | - EE_Error::add_attention( |
|
64 | - esc_html__( |
|
65 | - 'Be aware that the pdf messenger is inactive. This means that any pdf related shortcodes will parse to an empty string.', |
|
66 | - 'event_espresso' |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
70 | - |
|
71 | - if (! isset($this->_active_messengers['html'])) { |
|
72 | - EE_Error::add_attention( |
|
73 | - esc_html__( |
|
74 | - 'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.', |
|
75 | - 'event_espresso' |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - protected function _parser($shortcode) |
|
84 | - { |
|
85 | - // make sure we end up with a copy of the EE_Messages_Addressee object |
|
86 | - $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
87 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && is_array( |
|
88 | - $this->_data |
|
89 | - ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] |
|
90 | - : $recipient; |
|
91 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
92 | - ? $this->_extra_data['data'] : $recipient; |
|
93 | - |
|
94 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
95 | - return ''; |
|
96 | - } |
|
97 | - |
|
98 | - switch ($shortcode) { |
|
99 | - case '[DISPLAY_HTML_URL]': |
|
100 | - return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : ''; |
|
101 | - break; |
|
102 | - case '[DISPLAY_PDF_URL]': |
|
103 | - return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : ''; |
|
104 | - break; |
|
105 | - case '[DISPLAY_PDF_BUTTON]': |
|
106 | - return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : ''; |
|
107 | - break; |
|
108 | - } |
|
109 | - return ''; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses |
|
115 | - * that to generate the html for a button in the template. |
|
116 | - * |
|
117 | - * @since 4.5.0 |
|
118 | - * |
|
119 | - * @param EE_Messages_Addressee $recipient |
|
120 | - * @param string $sending_messenger 'html' or 'pdf' |
|
121 | - * |
|
122 | - * @return string Generated html |
|
123 | - */ |
|
124 | - private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger) |
|
125 | - { |
|
126 | - $download_text = $sending_messenger == 'pdf' |
|
127 | - ? esc_html__('Download PDF', 'event_espresso') |
|
128 | - : esc_html__( |
|
129 | - 'Show HTML', |
|
130 | - 'event_espresso' |
|
131 | - ); |
|
132 | - $content = ' |
|
25 | + /** |
|
26 | + * Hold array of active messengers indexed by messenger name. |
|
27 | + * |
|
28 | + * @since 4.5.0 |
|
29 | + * |
|
30 | + * @var EE_messenger[] |
|
31 | + */ |
|
32 | + protected $_active_messengers = array(); |
|
33 | + |
|
34 | + |
|
35 | + protected function _init_props() |
|
36 | + { |
|
37 | + $this->label = esc_html__('Messenger Shortcodes', 'event_espresso'); |
|
38 | + $this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso'); |
|
39 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
40 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
41 | + // add messages about what happens when the messenger is active. |
|
42 | + $this->_active_messengers = $message_resource_manager->active_messengers(); |
|
43 | + |
|
44 | + $this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__( |
|
45 | + 'This will return a link to view the template in a browser if the html messenger is active.', |
|
46 | + 'event_espresso' |
|
47 | + ); |
|
48 | + $this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__( |
|
49 | + 'This will return a link to generate a pdf for the template if the pdf messenger is active.', |
|
50 | + 'event_espresso' |
|
51 | + ); |
|
52 | + $this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__( |
|
53 | + 'This will return html for a download pdf button trigger if the pdf messenger is active.', |
|
54 | + 'event_espresso' |
|
55 | + ); |
|
56 | + |
|
57 | + /** @var RequestInterface $request */ |
|
58 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
59 | + $action = $request->getRequestParam('action'); |
|
60 | + // show error message about buttons/urls not working as expected if messenger deactivated. |
|
61 | + if ($action === 'update_message_template' && is_admin()) { |
|
62 | + if (! isset($this->_active_messengers['pdf'])) { |
|
63 | + EE_Error::add_attention( |
|
64 | + esc_html__( |
|
65 | + 'Be aware that the pdf messenger is inactive. This means that any pdf related shortcodes will parse to an empty string.', |
|
66 | + 'event_espresso' |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | + |
|
71 | + if (! isset($this->_active_messengers['html'])) { |
|
72 | + EE_Error::add_attention( |
|
73 | + esc_html__( |
|
74 | + 'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.', |
|
75 | + 'event_espresso' |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + protected function _parser($shortcode) |
|
84 | + { |
|
85 | + // make sure we end up with a copy of the EE_Messages_Addressee object |
|
86 | + $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
87 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && is_array( |
|
88 | + $this->_data |
|
89 | + ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] |
|
90 | + : $recipient; |
|
91 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
92 | + ? $this->_extra_data['data'] : $recipient; |
|
93 | + |
|
94 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
95 | + return ''; |
|
96 | + } |
|
97 | + |
|
98 | + switch ($shortcode) { |
|
99 | + case '[DISPLAY_HTML_URL]': |
|
100 | + return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : ''; |
|
101 | + break; |
|
102 | + case '[DISPLAY_PDF_URL]': |
|
103 | + return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : ''; |
|
104 | + break; |
|
105 | + case '[DISPLAY_PDF_BUTTON]': |
|
106 | + return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : ''; |
|
107 | + break; |
|
108 | + } |
|
109 | + return ''; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses |
|
115 | + * that to generate the html for a button in the template. |
|
116 | + * |
|
117 | + * @since 4.5.0 |
|
118 | + * |
|
119 | + * @param EE_Messages_Addressee $recipient |
|
120 | + * @param string $sending_messenger 'html' or 'pdf' |
|
121 | + * |
|
122 | + * @return string Generated html |
|
123 | + */ |
|
124 | + private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger) |
|
125 | + { |
|
126 | + $download_text = $sending_messenger == 'pdf' |
|
127 | + ? esc_html__('Download PDF', 'event_espresso') |
|
128 | + : esc_html__( |
|
129 | + 'Show HTML', |
|
130 | + 'event_espresso' |
|
131 | + ); |
|
132 | + $content = ' |
|
133 | 133 | <form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" > |
134 | 134 | <input class="print_button" type="submit" value="' . $download_text . '" /> |
135 | 135 | </form> |
136 | 136 | '; |
137 | - return $content; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * This method takes the incoming data and figures out from it what the message type is and |
|
143 | - * evt_id/grp_id and uses that to generate the url for displaying the template in a browser. |
|
144 | - * |
|
145 | - * @since 4.5.0 |
|
146 | - * |
|
147 | - * @param EE_Messages_Addressee $recipient |
|
148 | - * @param string $sending_messenger |
|
149 | - * |
|
150 | - * @return string The generated url for displaying the link. |
|
151 | - * @throws EE_Error |
|
152 | - */ |
|
153 | - private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger) |
|
154 | - { |
|
155 | - |
|
156 | - $reg = $recipient->reg_obj; |
|
157 | - $reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg; |
|
158 | - |
|
159 | - |
|
160 | - if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) { |
|
161 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
162 | - try { |
|
163 | - return EEH_MSG_Template::get_url_trigger( |
|
164 | - $this->_message_type, |
|
165 | - $this->_message, |
|
166 | - $reg, |
|
167 | - $sending_messenger |
|
168 | - ); |
|
169 | - } catch (EE_Error $e) { |
|
170 | - if (WP_DEBUG) { |
|
171 | - $e->get_error(); |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - return ''; |
|
177 | - } |
|
137 | + return $content; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * This method takes the incoming data and figures out from it what the message type is and |
|
143 | + * evt_id/grp_id and uses that to generate the url for displaying the template in a browser. |
|
144 | + * |
|
145 | + * @since 4.5.0 |
|
146 | + * |
|
147 | + * @param EE_Messages_Addressee $recipient |
|
148 | + * @param string $sending_messenger |
|
149 | + * |
|
150 | + * @return string The generated url for displaying the link. |
|
151 | + * @throws EE_Error |
|
152 | + */ |
|
153 | + private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger) |
|
154 | + { |
|
155 | + |
|
156 | + $reg = $recipient->reg_obj; |
|
157 | + $reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg; |
|
158 | + |
|
159 | + |
|
160 | + if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) { |
|
161 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
162 | + try { |
|
163 | + return EEH_MSG_Template::get_url_trigger( |
|
164 | + $this->_message_type, |
|
165 | + $this->_message, |
|
166 | + $reg, |
|
167 | + $sending_messenger |
|
168 | + ); |
|
169 | + } catch (EE_Error $e) { |
|
170 | + if (WP_DEBUG) { |
|
171 | + $e->get_error(); |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + return ''; |
|
177 | + } |
|
178 | 178 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
119 | 119 | do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
120 | 120 | } |
121 | - if (! isset($this->_has_billing_form)) { |
|
121 | + if ( ! isset($this->_has_billing_form)) { |
|
122 | 122 | // by default, On Site gateways have a billing form |
123 | 123 | if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
124 | 124 | $this->set_has_billing_form(true); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
130 | - if (! $this->_pretty_name) { |
|
130 | + if ( ! $this->_pretty_name) { |
|
131 | 131 | throw new EE_Error( |
132 | 132 | sprintf( |
133 | 133 | esc_html__( |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | // if the child didn't specify a default button, use the credit card one |
141 | 141 | if ($this->_default_button_url === null) { |
142 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png'; |
|
142 | + $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods/pay-by-credit-card.png'; |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | { |
161 | 161 | $reflector = new ReflectionClass(get_class($this)); |
162 | 162 | $fn = $reflector->getFileName(); |
163 | - $this->_file_folder = dirname($fn) . '/'; |
|
163 | + $this->_file_folder = dirname($fn).'/'; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function file_folder() |
195 | 195 | { |
196 | - if (! $this->_file_folder) { |
|
196 | + if ( ! $this->_file_folder) { |
|
197 | 197 | $this->_set_file_folder(); |
198 | 198 | } |
199 | 199 | return $this->_file_folder; |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function file_url() |
207 | 207 | { |
208 | - if (! $this->_file_url) { |
|
208 | + if ( ! $this->_file_url) { |
|
209 | 209 | $this->_set_file_url(); |
210 | 210 | } |
211 | 211 | return $this->_file_url; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function settings_form() |
241 | 241 | { |
242 | - if (! $this->_settings_form) { |
|
242 | + if ( ! $this->_settings_form) { |
|
243 | 243 | $this->_settings_form = $this->generate_new_settings_form(); |
244 | 244 | $this->_settings_form->set_payment_method_type($this); |
245 | 245 | // if we have already assigned a model object to this pmt, make |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | public function billing_form(EE_Transaction $transaction = null, $extra_args = array()) |
294 | 294 | { |
295 | 295 | // has billing form already been regenerated ? or overwrite cache? |
296 | - if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
296 | + if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
297 | 297 | $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
298 | 298 | } |
299 | 299 | // if we know who the attendee is, and this is a billing form |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
398 | 398 | // if we didn't already have a payment in progress for the same thing, |
399 | 399 | // then we actually want to make a new payment |
400 | - if (! $payment instanceof EE_Payment) { |
|
400 | + if ( ! $payment instanceof EE_Payment) { |
|
401 | 401 | $payment = EE_Payment::new_instance( |
402 | 402 | array_merge( |
403 | 403 | $duplicate_properties, |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | public function handle_ipn($req_data, $transaction) |
499 | 499 | { |
500 | 500 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
501 | - if (! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
501 | + if ( ! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
502 | 502 | throw new EE_Error( |
503 | 503 | sprintf( |
504 | 504 | esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | */ |
522 | 522 | protected function _save_billing_info_to_attendee($billing_form, $transaction) |
523 | 523 | { |
524 | - if (! $transaction || ! $transaction instanceof EE_Transaction) { |
|
524 | + if ( ! $transaction || ! $transaction instanceof EE_Transaction) { |
|
525 | 525 | EE_Error::add_error( |
526 | 526 | esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"), |
527 | 527 | __FILE__, |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | return false; |
532 | 532 | } |
533 | 533 | $primary_reg = $transaction->primary_registration(); |
534 | - if (! $primary_reg) { |
|
534 | + if ( ! $primary_reg) { |
|
535 | 535 | EE_Error::add_error( |
536 | 536 | esc_html__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), |
537 | 537 | __FILE__, |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | return false; |
542 | 542 | } |
543 | 543 | $attendee = $primary_reg->attendee(); |
544 | - if (! $attendee) { |
|
544 | + if ( ! $attendee) { |
|
545 | 545 | EE_Error::add_error( |
546 | 546 | esc_html__( |
547 | 547 | "Cannot save billing info because the transaction's primary registration has no attendee!", |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | */ |
655 | 655 | public function payment_occurs() |
656 | 656 | { |
657 | - if (! $this->_gateway) { |
|
657 | + if ( ! $this->_gateway) { |
|
658 | 658 | return EE_PMT_Base::offline; |
659 | 659 | } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
660 | 660 | return EE_PMT_Base::onsite; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | public function payment_overview_content(EE_Payment $payment) |
686 | 686 | { |
687 | 687 | return EEH_Template::display_template( |
688 | - EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php', |
|
688 | + EE_LIBRARIES.'payment_methods/templates/payment_details_content.template.php', |
|
689 | 689 | array('payment_method' => $this->_pm_instance, 'payment' => $payment), |
690 | 690 | true |
691 | 691 | ); |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | */ |
784 | 784 | public function get_help_tab_name() |
785 | 785 | { |
786 | - return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
786 | + return 'ee_'.strtolower($this->system_name()).'_help_tab'; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | */ |
795 | 795 | public function cap_name() |
796 | 796 | { |
797 | - return 'ee_payment_method_' . strtolower($this->system_name()); |
|
797 | + return 'ee_payment_method_'.strtolower($this->system_name()); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | /** |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | public function introductory_html() |
829 | 829 | { |
830 | 830 | return EEH_Template::locate_template( |
831 | - $this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php', |
|
831 | + $this->file_folder().'templates/'.strtolower($this->system_name()).'_intro.template.php', |
|
832 | 832 | array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance) |
833 | 833 | ); |
834 | 834 | } |
@@ -21,814 +21,814 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class EE_PMT_Base |
23 | 23 | { |
24 | - const onsite = 'on-site'; |
|
25 | - const offsite = 'off-site'; |
|
26 | - const offline = 'off-line'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var EE_Payment_Method |
|
30 | - */ |
|
31 | - protected $_pm_instance = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var boolean |
|
35 | - */ |
|
36 | - protected $_requires_https = false; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var boolean |
|
40 | - */ |
|
41 | - protected $_has_billing_form; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Gateway |
|
45 | - */ |
|
46 | - protected $_gateway = null; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var EE_Payment_Method_Form |
|
50 | - */ |
|
51 | - protected $_settings_form = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EE_Form_Section_Proper |
|
55 | - */ |
|
56 | - protected $_billing_form = null; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var boolean |
|
60 | - */ |
|
61 | - protected $_cache_billing_form = true; |
|
62 | - |
|
63 | - /** |
|
64 | - * String of the absolute path to the folder containing this file, with a trailing slash. |
|
65 | - * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/' |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - protected $_file_folder = null; |
|
70 | - |
|
71 | - /** |
|
72 | - * String to the absolute URL to this file (useful for getting its web-accessible resources |
|
73 | - * like images, js, or css) |
|
74 | - * |
|
75 | - * @var string |
|
76 | - */ |
|
77 | - protected $_file_url = null; |
|
78 | - |
|
79 | - /** |
|
80 | - * Pretty name for the payment method |
|
81 | - * |
|
82 | - * @var string |
|
83 | - */ |
|
84 | - protected $_pretty_name = null; |
|
85 | - |
|
86 | - /** |
|
87 | - * |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - protected $_default_button_url = null; |
|
91 | - |
|
92 | - /** |
|
93 | - * |
|
94 | - * @var string |
|
95 | - */ |
|
96 | - protected $_default_description = null; |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * |
|
101 | - * @param EE_Payment_Method $pm_instance |
|
102 | - * @throws EE_Error |
|
103 | - * @return EE_PMT_Base |
|
104 | - */ |
|
105 | - public function __construct($pm_instance = null) |
|
106 | - { |
|
107 | - if ($pm_instance instanceof EE_Payment_Method) { |
|
108 | - $this->set_instance($pm_instance); |
|
109 | - } |
|
110 | - if ($this->_gateway) { |
|
111 | - $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
112 | - $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
113 | - $this->_gateway->set_template_helper(new EEH_Template()); |
|
114 | - $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
115 | - $this->_gateway->set_money_helper(new EEH_Money()); |
|
116 | - $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
117 | - $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
118 | - do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
119 | - } |
|
120 | - if (! isset($this->_has_billing_form)) { |
|
121 | - // by default, On Site gateways have a billing form |
|
122 | - if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
123 | - $this->set_has_billing_form(true); |
|
124 | - } else { |
|
125 | - $this->set_has_billing_form(false); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - if (! $this->_pretty_name) { |
|
130 | - throw new EE_Error( |
|
131 | - sprintf( |
|
132 | - esc_html__( |
|
133 | - "You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", |
|
134 | - "event_espresso" |
|
135 | - ) |
|
136 | - ) |
|
137 | - ); |
|
138 | - } |
|
139 | - // if the child didn't specify a default button, use the credit card one |
|
140 | - if ($this->_default_button_url === null) { |
|
141 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png'; |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @param boolean $has_billing_form |
|
148 | - */ |
|
149 | - public function set_has_billing_form($has_billing_form) |
|
150 | - { |
|
151 | - $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * sets the file_folder property |
|
157 | - */ |
|
158 | - protected function _set_file_folder() |
|
159 | - { |
|
160 | - $reflector = new ReflectionClass(get_class($this)); |
|
161 | - $fn = $reflector->getFileName(); |
|
162 | - $this->_file_folder = dirname($fn) . '/'; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * sets the file URL with a trailing slash for this PMT |
|
168 | - */ |
|
169 | - protected function _set_file_url() |
|
170 | - { |
|
171 | - $plugins_dir_fixed = str_replace('\\', '/', WP_PLUGIN_DIR); |
|
172 | - $file_folder_fixed = str_replace('\\', '/', $this->file_folder()); |
|
173 | - $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
174 | - $this->_file_url = set_url_scheme($file_path); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Gets the default description on all payment methods of this type |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function default_description() |
|
183 | - { |
|
184 | - return $this->_default_description; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Returns the folder containing the PMT child class, with a trailing slash |
|
190 | - * |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function file_folder() |
|
194 | - { |
|
195 | - if (! $this->_file_folder) { |
|
196 | - $this->_set_file_folder(); |
|
197 | - } |
|
198 | - return $this->_file_folder; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function file_url() |
|
206 | - { |
|
207 | - if (! $this->_file_url) { |
|
208 | - $this->_set_file_url(); |
|
209 | - } |
|
210 | - return $this->_file_url; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Sets the payment method instance this payment method type is for. |
|
216 | - * Its important teh payment method instance is set before |
|
217 | - * |
|
218 | - * @param EE_Payment_Method $payment_method_instance |
|
219 | - */ |
|
220 | - public function set_instance($payment_method_instance) |
|
221 | - { |
|
222 | - $this->_pm_instance = $payment_method_instance; |
|
223 | - // if they have already requested the settings form, make sure its |
|
224 | - // data matches this model object |
|
225 | - if ($this->_settings_form) { |
|
226 | - $this->settings_form()->populate_model_obj($payment_method_instance); |
|
227 | - } |
|
228 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
229 | - $this->_gateway->set_settings($payment_method_instance->settings_array()); |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * Gets teh form for displaying to admins where they setup the payment method |
|
236 | - * |
|
237 | - * @return EE_Payment_Method_Form |
|
238 | - */ |
|
239 | - public function settings_form() |
|
240 | - { |
|
241 | - if (! $this->_settings_form) { |
|
242 | - $this->_settings_form = $this->generate_new_settings_form(); |
|
243 | - $this->_settings_form->set_payment_method_type($this); |
|
244 | - // if we have already assigned a model object to this pmt, make |
|
245 | - // sure its reflected in teh form we just generated |
|
246 | - if ($this->_pm_instance) { |
|
247 | - $this->_settings_form->populate_model_obj($this->_pm_instance); |
|
248 | - } |
|
249 | - } |
|
250 | - return $this->_settings_form; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Gets the form for all the settings related to this payment method type |
|
256 | - * |
|
257 | - * @return EE_Payment_Method_Form |
|
258 | - */ |
|
259 | - abstract public function generate_new_settings_form(); |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Sets the form for settings. This may be useful if we have already received |
|
264 | - * a form submission and have form data it in, and want to use it anytime we're showing |
|
265 | - * this payment method type's settings form later in the request |
|
266 | - * |
|
267 | - * @param EE_Payment_Method_Form $form |
|
268 | - */ |
|
269 | - public function set_settings_form($form) |
|
270 | - { |
|
271 | - $this->_settings_form = $form; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return boolean |
|
277 | - */ |
|
278 | - public function has_billing_form() |
|
279 | - { |
|
280 | - return $this->_has_billing_form; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets the form for displaying to attendees where they can enter their billing info |
|
286 | - * which will be sent to teh gateway (can be null) |
|
287 | - * |
|
288 | - * @param \EE_Transaction $transaction |
|
289 | - * @param array $extra_args |
|
290 | - * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
|
291 | - */ |
|
292 | - public function billing_form(EE_Transaction $transaction = null, $extra_args = array()) |
|
293 | - { |
|
294 | - // has billing form already been regenerated ? or overwrite cache? |
|
295 | - if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
296 | - $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
297 | - } |
|
298 | - // if we know who the attendee is, and this is a billing form |
|
299 | - // that uses attendee info, populate it |
|
300 | - if ( |
|
301 | - apply_filters( |
|
302 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
303 | - ($this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
304 | - && $transaction instanceof EE_Transaction |
|
305 | - && $transaction->primary_registration() instanceof EE_Registration |
|
306 | - && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
307 | - ), |
|
308 | - $this->_billing_form, |
|
309 | - $transaction |
|
310 | - ) |
|
311 | - ) { |
|
312 | - $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
313 | - } |
|
314 | - return $this->_billing_form; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Creates the billing form for this payment method type |
|
320 | - * |
|
321 | - * @param \EE_Transaction $transaction |
|
322 | - * @return \EE_Billing_Info_Form |
|
323 | - */ |
|
324 | - abstract public function generate_new_billing_form(EE_Transaction $transaction = null); |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * apply_billing_form_debug_settings |
|
329 | - * applies debug data to the form |
|
330 | - * |
|
331 | - * @param \EE_Billing_Info_Form $billing_form |
|
332 | - * @return \EE_Billing_Info_Form |
|
333 | - */ |
|
334 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
335 | - { |
|
336 | - return $billing_form; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Sets the billing form for this payment method type. You may want to use this |
|
342 | - * if you have form |
|
343 | - * |
|
344 | - * @param EE_Payment_Method $form |
|
345 | - */ |
|
346 | - public function set_billing_form($form) |
|
347 | - { |
|
348 | - $this->_billing_form = $form; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Returns whether or not this payment method requires HTTPS to be used |
|
354 | - * |
|
355 | - * @return boolean |
|
356 | - */ |
|
357 | - public function requires_https() |
|
358 | - { |
|
359 | - return $this->_requires_https; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * |
|
365 | - * @param EE_Transaction $transaction |
|
366 | - * @param float $amount |
|
367 | - * @param EE_Billing_Info_Form $billing_info |
|
368 | - * @param string $return_url |
|
369 | - * @param string $fail_url |
|
370 | - * @param string $method |
|
371 | - * @param bool $by_admin |
|
372 | - * @return EE_Payment |
|
373 | - * @throws EE_Error |
|
374 | - */ |
|
375 | - public function process_payment( |
|
376 | - EE_Transaction $transaction, |
|
377 | - $amount = null, |
|
378 | - $billing_info = null, |
|
379 | - $return_url = null, |
|
380 | - $fail_url = '', |
|
381 | - $method = 'CART', |
|
382 | - $by_admin = false |
|
383 | - ) { |
|
384 | - // @todo: add surcharge for the payment method, if any |
|
385 | - if ($this->_gateway) { |
|
386 | - // there is a gateway, so we're going to make a payment object |
|
387 | - // but wait! do they already have a payment in progress that we thought was failed? |
|
388 | - $duplicate_properties = array( |
|
389 | - 'STS_ID' => EEM_Payment::status_id_failed, |
|
390 | - 'TXN_ID' => $transaction->ID(), |
|
391 | - 'PMD_ID' => $this->_pm_instance->ID(), |
|
392 | - 'PAY_source' => $method, |
|
393 | - 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
|
394 | - 'PAY_gateway_response' => null, |
|
395 | - ); |
|
396 | - $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
397 | - // if we didn't already have a payment in progress for the same thing, |
|
398 | - // then we actually want to make a new payment |
|
399 | - if (! $payment instanceof EE_Payment) { |
|
400 | - $payment = EE_Payment::new_instance( |
|
401 | - array_merge( |
|
402 | - $duplicate_properties, |
|
403 | - array( |
|
404 | - 'PAY_timestamp' => time(), |
|
405 | - 'PAY_txn_id_chq_nmbr' => null, |
|
406 | - 'PAY_po_number' => null, |
|
407 | - 'PAY_extra_accntng' => null, |
|
408 | - 'PAY_details' => null, |
|
409 | - ) |
|
410 | - ) |
|
411 | - ); |
|
412 | - } |
|
413 | - // make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
|
414 | - $payment->save(); |
|
415 | - $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
416 | - |
|
417 | - // Offsite Gateway |
|
418 | - if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
419 | - $payment = $this->_gateway->set_redirection_info( |
|
420 | - $payment, |
|
421 | - $billing_values, |
|
422 | - $return_url, |
|
423 | - EE_Config::instance()->core->txn_page_url( |
|
424 | - array( |
|
425 | - 'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), |
|
426 | - 'ee_payment_method' => $this->_pm_instance->slug(), |
|
427 | - ) |
|
428 | - ), |
|
429 | - $fail_url |
|
430 | - ); |
|
431 | - $payment->save(); |
|
432 | - // Onsite Gateway |
|
433 | - } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
434 | - $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
435 | - $payment->save(); |
|
436 | - } else { |
|
437 | - throw new EE_Error( |
|
438 | - sprintf( |
|
439 | - esc_html__( |
|
440 | - 'Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', |
|
441 | - 'event_espresso' |
|
442 | - ), |
|
443 | - get_class($this), |
|
444 | - gettype($this->_gateway) |
|
445 | - ) |
|
446 | - ); |
|
447 | - } |
|
448 | - } else { |
|
449 | - // no gateway provided |
|
450 | - // there is no payment. Must be an offline gateway |
|
451 | - // create a payment object anyways, but dont save it |
|
452 | - $payment = EE_Payment::new_instance( |
|
453 | - array( |
|
454 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
455 | - 'TXN_ID' => $transaction->ID(), |
|
456 | - 'PMD_ID' => $transaction->payment_method_ID(), |
|
457 | - 'PAY_amount' => 0.00, |
|
458 | - 'PAY_timestamp' => time(), |
|
459 | - ) |
|
460 | - ); |
|
461 | - } |
|
462 | - |
|
463 | - // if there is billing info, clean it and save it now |
|
464 | - if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
465 | - $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
466 | - } |
|
467 | - |
|
468 | - return $payment; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Gets the values we want to pass onto the gateway. Normally these |
|
473 | - * are just the 'pretty' values, but there may be times the data may need |
|
474 | - * a little massaging. Proper subsections will become arrays of inputs |
|
475 | - * |
|
476 | - * @param EE_Billing_Info_Form $billing_form |
|
477 | - * @return array |
|
478 | - */ |
|
479 | - protected function _get_billing_values_from_form($billing_form) |
|
480 | - { |
|
481 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
482 | - return $billing_form->input_pretty_values(true); |
|
483 | - } else { |
|
484 | - return null; |
|
485 | - } |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Handles an instant payment notification when the transaction is known (by default). |
|
491 | - * |
|
492 | - * @param array $req_data |
|
493 | - * @param EE_Transaction $transaction |
|
494 | - * @return EE_Payment |
|
495 | - * @throws EE_Error |
|
496 | - */ |
|
497 | - public function handle_ipn($req_data, $transaction) |
|
498 | - { |
|
499 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
500 | - if (! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
501 | - throw new EE_Error( |
|
502 | - sprintf( |
|
503 | - esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), |
|
504 | - print_r($this->_gateway, true) |
|
505 | - ) |
|
506 | - ); |
|
507 | - } |
|
508 | - $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
509 | - return $payment; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - /** |
|
514 | - * Saves the billing info onto the attendee of the primary registrant on this transaction, and |
|
515 | - * cleans it first. |
|
516 | - * |
|
517 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
518 | - * @param EE_Transaction $transaction |
|
519 | - * @return boolean success |
|
520 | - */ |
|
521 | - protected function _save_billing_info_to_attendee($billing_form, $transaction) |
|
522 | - { |
|
523 | - if (! $transaction || ! $transaction instanceof EE_Transaction) { |
|
524 | - EE_Error::add_error( |
|
525 | - esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"), |
|
526 | - __FILE__, |
|
527 | - __FUNCTION__, |
|
528 | - __LINE__ |
|
529 | - ); |
|
530 | - return false; |
|
531 | - } |
|
532 | - $primary_reg = $transaction->primary_registration(); |
|
533 | - if (! $primary_reg) { |
|
534 | - EE_Error::add_error( |
|
535 | - esc_html__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), |
|
536 | - __FILE__, |
|
537 | - __FUNCTION__, |
|
538 | - __LINE__ |
|
539 | - ); |
|
540 | - return false; |
|
541 | - } |
|
542 | - $attendee = $primary_reg->attendee(); |
|
543 | - if (! $attendee) { |
|
544 | - EE_Error::add_error( |
|
545 | - esc_html__( |
|
546 | - "Cannot save billing info because the transaction's primary registration has no attendee!", |
|
547 | - "event_espresso" |
|
548 | - ), |
|
549 | - __FILE__, |
|
550 | - __FUNCTION__, |
|
551 | - __LINE__ |
|
552 | - ); |
|
553 | - return false; |
|
554 | - } |
|
555 | - return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Gets the payment this IPN is for. Children may often want to |
|
561 | - * override this to inspect the request |
|
562 | - * |
|
563 | - * @param EE_Transaction $transaction |
|
564 | - * @param array $req_data |
|
565 | - * @return EE_Payment |
|
566 | - */ |
|
567 | - protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) |
|
568 | - { |
|
569 | - return $transaction->last_payment(); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * In case generic code cannot provide the payment processor with a specific payment method |
|
575 | - * and transaction, it will try calling this method on each activate payment method. |
|
576 | - * If the payment method is able to identify the request as being for it, it should fetch |
|
577 | - * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot |
|
578 | - * handle the IPN |
|
579 | - * |
|
580 | - * @param array $req_data |
|
581 | - * @return EE_Payment only if this payment method can find the info its needs from $req_data |
|
582 | - * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
|
583 | - * @throws EE_Error |
|
584 | - */ |
|
585 | - public function handle_unclaimed_ipn($req_data = array()) |
|
586 | - { |
|
587 | - throw new EE_Error( |
|
588 | - sprintf(esc_html__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)) |
|
589 | - ); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Logic to be accomplished when the payment attempt is complete. |
|
595 | - * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
596 | - * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
597 | - * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
598 | - * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
599 | - * we're dealing with. Returns that last payment (if there is one) |
|
600 | - * |
|
601 | - * @param EE_Transaction $transaction |
|
602 | - * @return EE_Payment |
|
603 | - */ |
|
604 | - public function finalize_payment_for($transaction) |
|
605 | - { |
|
606 | - return $transaction->last_payment(); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Whether or not this payment method's gateway supports sending refund requests |
|
612 | - * |
|
613 | - * @return boolean |
|
614 | - */ |
|
615 | - public function supports_sending_refunds() |
|
616 | - { |
|
617 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
618 | - return $this->_gateway->supports_sending_refunds(); |
|
619 | - } else { |
|
620 | - return false; |
|
621 | - } |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - /** |
|
626 | - * |
|
627 | - * @param EE_Payment $payment |
|
628 | - * @param array $refund_info |
|
629 | - * @throws EE_Error |
|
630 | - * @return EE_Payment |
|
631 | - */ |
|
632 | - public function process_refund(EE_Payment $payment, $refund_info = array()) |
|
633 | - { |
|
634 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
635 | - return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
636 | - } else { |
|
637 | - throw new EE_Error( |
|
638 | - sprintf( |
|
639 | - esc_html__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
640 | - get_class($this) |
|
641 | - ) |
|
642 | - ); |
|
643 | - } |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * Returns one the class's constants onsite,offsite, or offline, depending on this |
|
649 | - * payment method's gateway. |
|
650 | - * |
|
651 | - * @return string |
|
652 | - * @throws EE_Error |
|
653 | - */ |
|
654 | - public function payment_occurs() |
|
655 | - { |
|
656 | - if (! $this->_gateway) { |
|
657 | - return EE_PMT_Base::offline; |
|
658 | - } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
659 | - return EE_PMT_Base::onsite; |
|
660 | - } elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
661 | - return EE_PMT_Base::offsite; |
|
662 | - } else { |
|
663 | - throw new EE_Error( |
|
664 | - sprintf( |
|
665 | - esc_html__( |
|
666 | - "Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", |
|
667 | - "event_espresso" |
|
668 | - ), |
|
669 | - get_class($this) |
|
670 | - ) |
|
671 | - ); |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * For adding any html output ab ove the payment overview. |
|
678 | - * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
679 | - * Other gateways may want to override this, such as offline gateways. |
|
680 | - * |
|
681 | - * @param EE_Payment $payment |
|
682 | - * @return string |
|
683 | - */ |
|
684 | - public function payment_overview_content(EE_Payment $payment) |
|
685 | - { |
|
686 | - return EEH_Template::display_template( |
|
687 | - EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php', |
|
688 | - array('payment_method' => $this->_pm_instance, 'payment' => $payment), |
|
689 | - true |
|
690 | - ); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * @return array where keys are the help tab name, |
|
696 | - * values are: array { |
|
697 | - * @type string $title i18n name for the help tab |
|
698 | - * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file) |
|
699 | - * @type array $template_args any arguments you want passed to the template file while rendering. |
|
700 | - * Keys will be variable names and values with be their values. |
|
701 | - */ |
|
702 | - public function help_tabs_config() |
|
703 | - { |
|
704 | - return array(); |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into |
|
710 | - * the payment method's table's PMT_type column) |
|
711 | - * |
|
712 | - * @return string |
|
713 | - */ |
|
714 | - public function system_name() |
|
715 | - { |
|
716 | - $classname = get_class($this); |
|
717 | - return str_replace("EE_PMT_", '', $classname); |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - /** |
|
722 | - * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding |
|
723 | - * this method. |
|
724 | - * @return string |
|
725 | - */ |
|
726 | - public function defaultFrontendName() |
|
727 | - { |
|
728 | - return $this->pretty_name(); |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * A pretty i18n version of the PMT name |
|
734 | - * |
|
735 | - * @return string |
|
736 | - */ |
|
737 | - public function pretty_name() |
|
738 | - { |
|
739 | - return $this->_pretty_name; |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * Gets the default absolute URL to the payment method type's button |
|
745 | - * |
|
746 | - * @return string |
|
747 | - */ |
|
748 | - public function default_button_url() |
|
749 | - { |
|
750 | - return $this->_default_button_url; |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * Gets the gateway used by this payment method (if any) |
|
756 | - * |
|
757 | - * @return EE_Gateway |
|
758 | - */ |
|
759 | - public function get_gateway() |
|
760 | - { |
|
761 | - return $this->_gateway; |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - /** |
|
766 | - * @return string html for the link to a help tab |
|
767 | - */ |
|
768 | - public function get_help_tab_link() |
|
769 | - { |
|
770 | - return EEH_Template::get_help_tab_link( |
|
771 | - $this->get_help_tab_name(), |
|
772 | - 'espresso_payment_settings', |
|
773 | - 'default' |
|
774 | - ); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * Returns the name of the help tab for this PMT |
|
780 | - * |
|
781 | - * @return string |
|
782 | - */ |
|
783 | - public function get_help_tab_name() |
|
784 | - { |
|
785 | - return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
786 | - } |
|
787 | - |
|
788 | - /** |
|
789 | - * The name of the wp capability that should be associated with the usage of |
|
790 | - * this PMT by an admin |
|
791 | - * |
|
792 | - * @return string |
|
793 | - */ |
|
794 | - public function cap_name() |
|
795 | - { |
|
796 | - return 'ee_payment_method_' . strtolower($this->system_name()); |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Called by client code to tell the gateway that if it wants to change |
|
801 | - * the transaction or line items or registrations related to teh payment it already |
|
802 | - * processed (we think, but possibly not) that now's the time to do it. |
|
803 | - * It is expected that gateways will store any info they need for this on the PAY_details, |
|
804 | - * or maybe an extra meta value |
|
805 | - * |
|
806 | - * @param EE_Payment $payment |
|
807 | - * @return void |
|
808 | - */ |
|
809 | - public function update_txn_based_on_payment($payment) |
|
810 | - { |
|
811 | - if ($this->_gateway instanceof EE_Gateway) { |
|
812 | - $this->_gateway->update_txn_based_on_payment($payment); |
|
813 | - } |
|
814 | - } |
|
815 | - |
|
816 | - /** |
|
817 | - * Returns a string of HTML describing this payment method type for an admin, |
|
818 | - * primarily intended for them to read before activating it. |
|
819 | - * The easiest way to set this is to create a folder 'templates' alongside |
|
820 | - * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php". |
|
821 | - * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php", |
|
822 | - * then you'd create a file named "templates" in the same folder as it, and name the file |
|
823 | - * "foo_bar_intro.template.php", and its content will be returned by this method |
|
824 | - * |
|
825 | - * @return string |
|
826 | - */ |
|
827 | - public function introductory_html() |
|
828 | - { |
|
829 | - return EEH_Template::locate_template( |
|
830 | - $this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php', |
|
831 | - array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance) |
|
832 | - ); |
|
833 | - } |
|
24 | + const onsite = 'on-site'; |
|
25 | + const offsite = 'off-site'; |
|
26 | + const offline = 'off-line'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var EE_Payment_Method |
|
30 | + */ |
|
31 | + protected $_pm_instance = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var boolean |
|
35 | + */ |
|
36 | + protected $_requires_https = false; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var boolean |
|
40 | + */ |
|
41 | + protected $_has_billing_form; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Gateway |
|
45 | + */ |
|
46 | + protected $_gateway = null; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var EE_Payment_Method_Form |
|
50 | + */ |
|
51 | + protected $_settings_form = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EE_Form_Section_Proper |
|
55 | + */ |
|
56 | + protected $_billing_form = null; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var boolean |
|
60 | + */ |
|
61 | + protected $_cache_billing_form = true; |
|
62 | + |
|
63 | + /** |
|
64 | + * String of the absolute path to the folder containing this file, with a trailing slash. |
|
65 | + * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/' |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + protected $_file_folder = null; |
|
70 | + |
|
71 | + /** |
|
72 | + * String to the absolute URL to this file (useful for getting its web-accessible resources |
|
73 | + * like images, js, or css) |
|
74 | + * |
|
75 | + * @var string |
|
76 | + */ |
|
77 | + protected $_file_url = null; |
|
78 | + |
|
79 | + /** |
|
80 | + * Pretty name for the payment method |
|
81 | + * |
|
82 | + * @var string |
|
83 | + */ |
|
84 | + protected $_pretty_name = null; |
|
85 | + |
|
86 | + /** |
|
87 | + * |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + protected $_default_button_url = null; |
|
91 | + |
|
92 | + /** |
|
93 | + * |
|
94 | + * @var string |
|
95 | + */ |
|
96 | + protected $_default_description = null; |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * |
|
101 | + * @param EE_Payment_Method $pm_instance |
|
102 | + * @throws EE_Error |
|
103 | + * @return EE_PMT_Base |
|
104 | + */ |
|
105 | + public function __construct($pm_instance = null) |
|
106 | + { |
|
107 | + if ($pm_instance instanceof EE_Payment_Method) { |
|
108 | + $this->set_instance($pm_instance); |
|
109 | + } |
|
110 | + if ($this->_gateway) { |
|
111 | + $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
112 | + $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
113 | + $this->_gateway->set_template_helper(new EEH_Template()); |
|
114 | + $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
115 | + $this->_gateway->set_money_helper(new EEH_Money()); |
|
116 | + $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
117 | + $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
118 | + do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
119 | + } |
|
120 | + if (! isset($this->_has_billing_form)) { |
|
121 | + // by default, On Site gateways have a billing form |
|
122 | + if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
123 | + $this->set_has_billing_form(true); |
|
124 | + } else { |
|
125 | + $this->set_has_billing_form(false); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + if (! $this->_pretty_name) { |
|
130 | + throw new EE_Error( |
|
131 | + sprintf( |
|
132 | + esc_html__( |
|
133 | + "You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", |
|
134 | + "event_espresso" |
|
135 | + ) |
|
136 | + ) |
|
137 | + ); |
|
138 | + } |
|
139 | + // if the child didn't specify a default button, use the credit card one |
|
140 | + if ($this->_default_button_url === null) { |
|
141 | + $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods/pay-by-credit-card.png'; |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @param boolean $has_billing_form |
|
148 | + */ |
|
149 | + public function set_has_billing_form($has_billing_form) |
|
150 | + { |
|
151 | + $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * sets the file_folder property |
|
157 | + */ |
|
158 | + protected function _set_file_folder() |
|
159 | + { |
|
160 | + $reflector = new ReflectionClass(get_class($this)); |
|
161 | + $fn = $reflector->getFileName(); |
|
162 | + $this->_file_folder = dirname($fn) . '/'; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * sets the file URL with a trailing slash for this PMT |
|
168 | + */ |
|
169 | + protected function _set_file_url() |
|
170 | + { |
|
171 | + $plugins_dir_fixed = str_replace('\\', '/', WP_PLUGIN_DIR); |
|
172 | + $file_folder_fixed = str_replace('\\', '/', $this->file_folder()); |
|
173 | + $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
174 | + $this->_file_url = set_url_scheme($file_path); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Gets the default description on all payment methods of this type |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function default_description() |
|
183 | + { |
|
184 | + return $this->_default_description; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Returns the folder containing the PMT child class, with a trailing slash |
|
190 | + * |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function file_folder() |
|
194 | + { |
|
195 | + if (! $this->_file_folder) { |
|
196 | + $this->_set_file_folder(); |
|
197 | + } |
|
198 | + return $this->_file_folder; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function file_url() |
|
206 | + { |
|
207 | + if (! $this->_file_url) { |
|
208 | + $this->_set_file_url(); |
|
209 | + } |
|
210 | + return $this->_file_url; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Sets the payment method instance this payment method type is for. |
|
216 | + * Its important teh payment method instance is set before |
|
217 | + * |
|
218 | + * @param EE_Payment_Method $payment_method_instance |
|
219 | + */ |
|
220 | + public function set_instance($payment_method_instance) |
|
221 | + { |
|
222 | + $this->_pm_instance = $payment_method_instance; |
|
223 | + // if they have already requested the settings form, make sure its |
|
224 | + // data matches this model object |
|
225 | + if ($this->_settings_form) { |
|
226 | + $this->settings_form()->populate_model_obj($payment_method_instance); |
|
227 | + } |
|
228 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
229 | + $this->_gateway->set_settings($payment_method_instance->settings_array()); |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * Gets teh form for displaying to admins where they setup the payment method |
|
236 | + * |
|
237 | + * @return EE_Payment_Method_Form |
|
238 | + */ |
|
239 | + public function settings_form() |
|
240 | + { |
|
241 | + if (! $this->_settings_form) { |
|
242 | + $this->_settings_form = $this->generate_new_settings_form(); |
|
243 | + $this->_settings_form->set_payment_method_type($this); |
|
244 | + // if we have already assigned a model object to this pmt, make |
|
245 | + // sure its reflected in teh form we just generated |
|
246 | + if ($this->_pm_instance) { |
|
247 | + $this->_settings_form->populate_model_obj($this->_pm_instance); |
|
248 | + } |
|
249 | + } |
|
250 | + return $this->_settings_form; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Gets the form for all the settings related to this payment method type |
|
256 | + * |
|
257 | + * @return EE_Payment_Method_Form |
|
258 | + */ |
|
259 | + abstract public function generate_new_settings_form(); |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Sets the form for settings. This may be useful if we have already received |
|
264 | + * a form submission and have form data it in, and want to use it anytime we're showing |
|
265 | + * this payment method type's settings form later in the request |
|
266 | + * |
|
267 | + * @param EE_Payment_Method_Form $form |
|
268 | + */ |
|
269 | + public function set_settings_form($form) |
|
270 | + { |
|
271 | + $this->_settings_form = $form; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return boolean |
|
277 | + */ |
|
278 | + public function has_billing_form() |
|
279 | + { |
|
280 | + return $this->_has_billing_form; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets the form for displaying to attendees where they can enter their billing info |
|
286 | + * which will be sent to teh gateway (can be null) |
|
287 | + * |
|
288 | + * @param \EE_Transaction $transaction |
|
289 | + * @param array $extra_args |
|
290 | + * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
|
291 | + */ |
|
292 | + public function billing_form(EE_Transaction $transaction = null, $extra_args = array()) |
|
293 | + { |
|
294 | + // has billing form already been regenerated ? or overwrite cache? |
|
295 | + if (! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
296 | + $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
297 | + } |
|
298 | + // if we know who the attendee is, and this is a billing form |
|
299 | + // that uses attendee info, populate it |
|
300 | + if ( |
|
301 | + apply_filters( |
|
302 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
303 | + ($this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
304 | + && $transaction instanceof EE_Transaction |
|
305 | + && $transaction->primary_registration() instanceof EE_Registration |
|
306 | + && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
307 | + ), |
|
308 | + $this->_billing_form, |
|
309 | + $transaction |
|
310 | + ) |
|
311 | + ) { |
|
312 | + $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
313 | + } |
|
314 | + return $this->_billing_form; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Creates the billing form for this payment method type |
|
320 | + * |
|
321 | + * @param \EE_Transaction $transaction |
|
322 | + * @return \EE_Billing_Info_Form |
|
323 | + */ |
|
324 | + abstract public function generate_new_billing_form(EE_Transaction $transaction = null); |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * apply_billing_form_debug_settings |
|
329 | + * applies debug data to the form |
|
330 | + * |
|
331 | + * @param \EE_Billing_Info_Form $billing_form |
|
332 | + * @return \EE_Billing_Info_Form |
|
333 | + */ |
|
334 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
335 | + { |
|
336 | + return $billing_form; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Sets the billing form for this payment method type. You may want to use this |
|
342 | + * if you have form |
|
343 | + * |
|
344 | + * @param EE_Payment_Method $form |
|
345 | + */ |
|
346 | + public function set_billing_form($form) |
|
347 | + { |
|
348 | + $this->_billing_form = $form; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Returns whether or not this payment method requires HTTPS to be used |
|
354 | + * |
|
355 | + * @return boolean |
|
356 | + */ |
|
357 | + public function requires_https() |
|
358 | + { |
|
359 | + return $this->_requires_https; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * |
|
365 | + * @param EE_Transaction $transaction |
|
366 | + * @param float $amount |
|
367 | + * @param EE_Billing_Info_Form $billing_info |
|
368 | + * @param string $return_url |
|
369 | + * @param string $fail_url |
|
370 | + * @param string $method |
|
371 | + * @param bool $by_admin |
|
372 | + * @return EE_Payment |
|
373 | + * @throws EE_Error |
|
374 | + */ |
|
375 | + public function process_payment( |
|
376 | + EE_Transaction $transaction, |
|
377 | + $amount = null, |
|
378 | + $billing_info = null, |
|
379 | + $return_url = null, |
|
380 | + $fail_url = '', |
|
381 | + $method = 'CART', |
|
382 | + $by_admin = false |
|
383 | + ) { |
|
384 | + // @todo: add surcharge for the payment method, if any |
|
385 | + if ($this->_gateway) { |
|
386 | + // there is a gateway, so we're going to make a payment object |
|
387 | + // but wait! do they already have a payment in progress that we thought was failed? |
|
388 | + $duplicate_properties = array( |
|
389 | + 'STS_ID' => EEM_Payment::status_id_failed, |
|
390 | + 'TXN_ID' => $transaction->ID(), |
|
391 | + 'PMD_ID' => $this->_pm_instance->ID(), |
|
392 | + 'PAY_source' => $method, |
|
393 | + 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
|
394 | + 'PAY_gateway_response' => null, |
|
395 | + ); |
|
396 | + $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
397 | + // if we didn't already have a payment in progress for the same thing, |
|
398 | + // then we actually want to make a new payment |
|
399 | + if (! $payment instanceof EE_Payment) { |
|
400 | + $payment = EE_Payment::new_instance( |
|
401 | + array_merge( |
|
402 | + $duplicate_properties, |
|
403 | + array( |
|
404 | + 'PAY_timestamp' => time(), |
|
405 | + 'PAY_txn_id_chq_nmbr' => null, |
|
406 | + 'PAY_po_number' => null, |
|
407 | + 'PAY_extra_accntng' => null, |
|
408 | + 'PAY_details' => null, |
|
409 | + ) |
|
410 | + ) |
|
411 | + ); |
|
412 | + } |
|
413 | + // make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
|
414 | + $payment->save(); |
|
415 | + $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
416 | + |
|
417 | + // Offsite Gateway |
|
418 | + if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
419 | + $payment = $this->_gateway->set_redirection_info( |
|
420 | + $payment, |
|
421 | + $billing_values, |
|
422 | + $return_url, |
|
423 | + EE_Config::instance()->core->txn_page_url( |
|
424 | + array( |
|
425 | + 'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), |
|
426 | + 'ee_payment_method' => $this->_pm_instance->slug(), |
|
427 | + ) |
|
428 | + ), |
|
429 | + $fail_url |
|
430 | + ); |
|
431 | + $payment->save(); |
|
432 | + // Onsite Gateway |
|
433 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
434 | + $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
435 | + $payment->save(); |
|
436 | + } else { |
|
437 | + throw new EE_Error( |
|
438 | + sprintf( |
|
439 | + esc_html__( |
|
440 | + 'Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', |
|
441 | + 'event_espresso' |
|
442 | + ), |
|
443 | + get_class($this), |
|
444 | + gettype($this->_gateway) |
|
445 | + ) |
|
446 | + ); |
|
447 | + } |
|
448 | + } else { |
|
449 | + // no gateway provided |
|
450 | + // there is no payment. Must be an offline gateway |
|
451 | + // create a payment object anyways, but dont save it |
|
452 | + $payment = EE_Payment::new_instance( |
|
453 | + array( |
|
454 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
455 | + 'TXN_ID' => $transaction->ID(), |
|
456 | + 'PMD_ID' => $transaction->payment_method_ID(), |
|
457 | + 'PAY_amount' => 0.00, |
|
458 | + 'PAY_timestamp' => time(), |
|
459 | + ) |
|
460 | + ); |
|
461 | + } |
|
462 | + |
|
463 | + // if there is billing info, clean it and save it now |
|
464 | + if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
465 | + $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
466 | + } |
|
467 | + |
|
468 | + return $payment; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Gets the values we want to pass onto the gateway. Normally these |
|
473 | + * are just the 'pretty' values, but there may be times the data may need |
|
474 | + * a little massaging. Proper subsections will become arrays of inputs |
|
475 | + * |
|
476 | + * @param EE_Billing_Info_Form $billing_form |
|
477 | + * @return array |
|
478 | + */ |
|
479 | + protected function _get_billing_values_from_form($billing_form) |
|
480 | + { |
|
481 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
482 | + return $billing_form->input_pretty_values(true); |
|
483 | + } else { |
|
484 | + return null; |
|
485 | + } |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Handles an instant payment notification when the transaction is known (by default). |
|
491 | + * |
|
492 | + * @param array $req_data |
|
493 | + * @param EE_Transaction $transaction |
|
494 | + * @return EE_Payment |
|
495 | + * @throws EE_Error |
|
496 | + */ |
|
497 | + public function handle_ipn($req_data, $transaction) |
|
498 | + { |
|
499 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
500 | + if (! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
501 | + throw new EE_Error( |
|
502 | + sprintf( |
|
503 | + esc_html__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), |
|
504 | + print_r($this->_gateway, true) |
|
505 | + ) |
|
506 | + ); |
|
507 | + } |
|
508 | + $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
509 | + return $payment; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + /** |
|
514 | + * Saves the billing info onto the attendee of the primary registrant on this transaction, and |
|
515 | + * cleans it first. |
|
516 | + * |
|
517 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
518 | + * @param EE_Transaction $transaction |
|
519 | + * @return boolean success |
|
520 | + */ |
|
521 | + protected function _save_billing_info_to_attendee($billing_form, $transaction) |
|
522 | + { |
|
523 | + if (! $transaction || ! $transaction instanceof EE_Transaction) { |
|
524 | + EE_Error::add_error( |
|
525 | + esc_html__("Cannot save billing info because no transaction was specified", "event_espresso"), |
|
526 | + __FILE__, |
|
527 | + __FUNCTION__, |
|
528 | + __LINE__ |
|
529 | + ); |
|
530 | + return false; |
|
531 | + } |
|
532 | + $primary_reg = $transaction->primary_registration(); |
|
533 | + if (! $primary_reg) { |
|
534 | + EE_Error::add_error( |
|
535 | + esc_html__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), |
|
536 | + __FILE__, |
|
537 | + __FUNCTION__, |
|
538 | + __LINE__ |
|
539 | + ); |
|
540 | + return false; |
|
541 | + } |
|
542 | + $attendee = $primary_reg->attendee(); |
|
543 | + if (! $attendee) { |
|
544 | + EE_Error::add_error( |
|
545 | + esc_html__( |
|
546 | + "Cannot save billing info because the transaction's primary registration has no attendee!", |
|
547 | + "event_espresso" |
|
548 | + ), |
|
549 | + __FILE__, |
|
550 | + __FUNCTION__, |
|
551 | + __LINE__ |
|
552 | + ); |
|
553 | + return false; |
|
554 | + } |
|
555 | + return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Gets the payment this IPN is for. Children may often want to |
|
561 | + * override this to inspect the request |
|
562 | + * |
|
563 | + * @param EE_Transaction $transaction |
|
564 | + * @param array $req_data |
|
565 | + * @return EE_Payment |
|
566 | + */ |
|
567 | + protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) |
|
568 | + { |
|
569 | + return $transaction->last_payment(); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * In case generic code cannot provide the payment processor with a specific payment method |
|
575 | + * and transaction, it will try calling this method on each activate payment method. |
|
576 | + * If the payment method is able to identify the request as being for it, it should fetch |
|
577 | + * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot |
|
578 | + * handle the IPN |
|
579 | + * |
|
580 | + * @param array $req_data |
|
581 | + * @return EE_Payment only if this payment method can find the info its needs from $req_data |
|
582 | + * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
|
583 | + * @throws EE_Error |
|
584 | + */ |
|
585 | + public function handle_unclaimed_ipn($req_data = array()) |
|
586 | + { |
|
587 | + throw new EE_Error( |
|
588 | + sprintf(esc_html__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)) |
|
589 | + ); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Logic to be accomplished when the payment attempt is complete. |
|
595 | + * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
596 | + * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
597 | + * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
598 | + * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
599 | + * we're dealing with. Returns that last payment (if there is one) |
|
600 | + * |
|
601 | + * @param EE_Transaction $transaction |
|
602 | + * @return EE_Payment |
|
603 | + */ |
|
604 | + public function finalize_payment_for($transaction) |
|
605 | + { |
|
606 | + return $transaction->last_payment(); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Whether or not this payment method's gateway supports sending refund requests |
|
612 | + * |
|
613 | + * @return boolean |
|
614 | + */ |
|
615 | + public function supports_sending_refunds() |
|
616 | + { |
|
617 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
618 | + return $this->_gateway->supports_sending_refunds(); |
|
619 | + } else { |
|
620 | + return false; |
|
621 | + } |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + /** |
|
626 | + * |
|
627 | + * @param EE_Payment $payment |
|
628 | + * @param array $refund_info |
|
629 | + * @throws EE_Error |
|
630 | + * @return EE_Payment |
|
631 | + */ |
|
632 | + public function process_refund(EE_Payment $payment, $refund_info = array()) |
|
633 | + { |
|
634 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
635 | + return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
636 | + } else { |
|
637 | + throw new EE_Error( |
|
638 | + sprintf( |
|
639 | + esc_html__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
640 | + get_class($this) |
|
641 | + ) |
|
642 | + ); |
|
643 | + } |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * Returns one the class's constants onsite,offsite, or offline, depending on this |
|
649 | + * payment method's gateway. |
|
650 | + * |
|
651 | + * @return string |
|
652 | + * @throws EE_Error |
|
653 | + */ |
|
654 | + public function payment_occurs() |
|
655 | + { |
|
656 | + if (! $this->_gateway) { |
|
657 | + return EE_PMT_Base::offline; |
|
658 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
659 | + return EE_PMT_Base::onsite; |
|
660 | + } elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
661 | + return EE_PMT_Base::offsite; |
|
662 | + } else { |
|
663 | + throw new EE_Error( |
|
664 | + sprintf( |
|
665 | + esc_html__( |
|
666 | + "Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", |
|
667 | + "event_espresso" |
|
668 | + ), |
|
669 | + get_class($this) |
|
670 | + ) |
|
671 | + ); |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * For adding any html output ab ove the payment overview. |
|
678 | + * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
679 | + * Other gateways may want to override this, such as offline gateways. |
|
680 | + * |
|
681 | + * @param EE_Payment $payment |
|
682 | + * @return string |
|
683 | + */ |
|
684 | + public function payment_overview_content(EE_Payment $payment) |
|
685 | + { |
|
686 | + return EEH_Template::display_template( |
|
687 | + EE_LIBRARIES . 'payment_methods/templates/payment_details_content.template.php', |
|
688 | + array('payment_method' => $this->_pm_instance, 'payment' => $payment), |
|
689 | + true |
|
690 | + ); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * @return array where keys are the help tab name, |
|
696 | + * values are: array { |
|
697 | + * @type string $title i18n name for the help tab |
|
698 | + * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file) |
|
699 | + * @type array $template_args any arguments you want passed to the template file while rendering. |
|
700 | + * Keys will be variable names and values with be their values. |
|
701 | + */ |
|
702 | + public function help_tabs_config() |
|
703 | + { |
|
704 | + return array(); |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into |
|
710 | + * the payment method's table's PMT_type column) |
|
711 | + * |
|
712 | + * @return string |
|
713 | + */ |
|
714 | + public function system_name() |
|
715 | + { |
|
716 | + $classname = get_class($this); |
|
717 | + return str_replace("EE_PMT_", '', $classname); |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + /** |
|
722 | + * A pretty i18n version of the PMT name. Often the same as the "pretty_name", but you can change it by overriding |
|
723 | + * this method. |
|
724 | + * @return string |
|
725 | + */ |
|
726 | + public function defaultFrontendName() |
|
727 | + { |
|
728 | + return $this->pretty_name(); |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * A pretty i18n version of the PMT name |
|
734 | + * |
|
735 | + * @return string |
|
736 | + */ |
|
737 | + public function pretty_name() |
|
738 | + { |
|
739 | + return $this->_pretty_name; |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * Gets the default absolute URL to the payment method type's button |
|
745 | + * |
|
746 | + * @return string |
|
747 | + */ |
|
748 | + public function default_button_url() |
|
749 | + { |
|
750 | + return $this->_default_button_url; |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * Gets the gateway used by this payment method (if any) |
|
756 | + * |
|
757 | + * @return EE_Gateway |
|
758 | + */ |
|
759 | + public function get_gateway() |
|
760 | + { |
|
761 | + return $this->_gateway; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + /** |
|
766 | + * @return string html for the link to a help tab |
|
767 | + */ |
|
768 | + public function get_help_tab_link() |
|
769 | + { |
|
770 | + return EEH_Template::get_help_tab_link( |
|
771 | + $this->get_help_tab_name(), |
|
772 | + 'espresso_payment_settings', |
|
773 | + 'default' |
|
774 | + ); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * Returns the name of the help tab for this PMT |
|
780 | + * |
|
781 | + * @return string |
|
782 | + */ |
|
783 | + public function get_help_tab_name() |
|
784 | + { |
|
785 | + return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
786 | + } |
|
787 | + |
|
788 | + /** |
|
789 | + * The name of the wp capability that should be associated with the usage of |
|
790 | + * this PMT by an admin |
|
791 | + * |
|
792 | + * @return string |
|
793 | + */ |
|
794 | + public function cap_name() |
|
795 | + { |
|
796 | + return 'ee_payment_method_' . strtolower($this->system_name()); |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Called by client code to tell the gateway that if it wants to change |
|
801 | + * the transaction or line items or registrations related to teh payment it already |
|
802 | + * processed (we think, but possibly not) that now's the time to do it. |
|
803 | + * It is expected that gateways will store any info they need for this on the PAY_details, |
|
804 | + * or maybe an extra meta value |
|
805 | + * |
|
806 | + * @param EE_Payment $payment |
|
807 | + * @return void |
|
808 | + */ |
|
809 | + public function update_txn_based_on_payment($payment) |
|
810 | + { |
|
811 | + if ($this->_gateway instanceof EE_Gateway) { |
|
812 | + $this->_gateway->update_txn_based_on_payment($payment); |
|
813 | + } |
|
814 | + } |
|
815 | + |
|
816 | + /** |
|
817 | + * Returns a string of HTML describing this payment method type for an admin, |
|
818 | + * primarily intended for them to read before activating it. |
|
819 | + * The easiest way to set this is to create a folder 'templates' alongside |
|
820 | + * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php". |
|
821 | + * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php", |
|
822 | + * then you'd create a file named "templates" in the same folder as it, and name the file |
|
823 | + * "foo_bar_intro.template.php", and its content will be returned by this method |
|
824 | + * |
|
825 | + * @return string |
|
826 | + */ |
|
827 | + public function introductory_html() |
|
828 | + { |
|
829 | + return EEH_Template::locate_template( |
|
830 | + $this->file_folder() . 'templates/' . strtolower($this->system_name()) . '_intro.template.php', |
|
831 | + array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance) |
|
832 | + ); |
|
833 | + } |
|
834 | 834 | } |
@@ -37,74 +37,74 @@ |
||
37 | 37 | abstract class ChangesInBase |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * The version that these changes happened |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $version = null; |
|
40 | + /** |
|
41 | + * The version that these changes happened |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $version = null; |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Called when an EE4 REST API request is made to an earlier version than |
|
50 | - * what is indicated in this class' name. |
|
51 | - * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response |
|
52 | - * so that regardless of what version of EE4 core is running, API clients |
|
53 | - * will have a consistent response |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - abstract public function setHooks(); |
|
48 | + /** |
|
49 | + * Called when an EE4 REST API request is made to an earlier version than |
|
50 | + * what is indicated in this class' name. |
|
51 | + * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response |
|
52 | + * so that regardless of what version of EE4 core is running, API clients |
|
53 | + * will have a consistent response |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + abstract public function setHooks(); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Returns whether or not this class' name indicates its hooks should |
|
62 | - * apply when a request comes in for $requested_version. A class can use |
|
63 | - * other conditions when determining whether to perform their callbacks or not, |
|
64 | - * but this will typically be enough |
|
65 | - * |
|
66 | - * @param string $requested_version eg "4.8.33" |
|
67 | - * @return boolean true: this class' name indicates its filters and actions |
|
68 | - * should take effect. False: this class' name indicates it shouldn't do anything |
|
69 | - */ |
|
70 | - public function appliesToVersion($requested_version) |
|
71 | - { |
|
72 | - if ($this->version() > $requested_version) { |
|
73 | - return true; |
|
74 | - } |
|
75 | - return false; |
|
76 | - } |
|
60 | + /** |
|
61 | + * Returns whether or not this class' name indicates its hooks should |
|
62 | + * apply when a request comes in for $requested_version. A class can use |
|
63 | + * other conditions when determining whether to perform their callbacks or not, |
|
64 | + * but this will typically be enough |
|
65 | + * |
|
66 | + * @param string $requested_version eg "4.8.33" |
|
67 | + * @return boolean true: this class' name indicates its filters and actions |
|
68 | + * should take effect. False: this class' name indicates it shouldn't do anything |
|
69 | + */ |
|
70 | + public function appliesToVersion($requested_version) |
|
71 | + { |
|
72 | + if ($this->version() > $requested_version) { |
|
73 | + return true; |
|
74 | + } |
|
75 | + return false; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * Gets the EE core version when this changes were made to the rest api. |
|
81 | - * Any requests to earlier versions should have modifications made to them |
|
82 | - * by the callbacks of this class. |
|
83 | - * |
|
84 | - * @return string eg "4.8.33" |
|
85 | - * @throws EE_Error |
|
86 | - */ |
|
87 | - public function version() |
|
88 | - { |
|
89 | - if ($this->version === null) { |
|
90 | - $matches = array(); |
|
91 | - $regex = '~ChangesIn(\d)(\d\d)(\d\d)$~'; |
|
92 | - $success = preg_match( |
|
93 | - $regex, |
|
94 | - get_class($this), |
|
95 | - $matches |
|
96 | - ); |
|
97 | - if (! $success) { |
|
98 | - throw new EE_Error( |
|
99 | - sprintf( |
|
100 | - esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'), |
|
101 | - get_class($this), |
|
102 | - $regex |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
106 | - $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3]; |
|
107 | - } |
|
108 | - return $this->version; |
|
109 | - } |
|
79 | + /** |
|
80 | + * Gets the EE core version when this changes were made to the rest api. |
|
81 | + * Any requests to earlier versions should have modifications made to them |
|
82 | + * by the callbacks of this class. |
|
83 | + * |
|
84 | + * @return string eg "4.8.33" |
|
85 | + * @throws EE_Error |
|
86 | + */ |
|
87 | + public function version() |
|
88 | + { |
|
89 | + if ($this->version === null) { |
|
90 | + $matches = array(); |
|
91 | + $regex = '~ChangesIn(\d)(\d\d)(\d\d)$~'; |
|
92 | + $success = preg_match( |
|
93 | + $regex, |
|
94 | + get_class($this), |
|
95 | + $matches |
|
96 | + ); |
|
97 | + if (! $success) { |
|
98 | + throw new EE_Error( |
|
99 | + sprintf( |
|
100 | + esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'), |
|
101 | + get_class($this), |
|
102 | + $regex |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | + $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3]; |
|
107 | + } |
|
108 | + return $this->version; |
|
109 | + } |
|
110 | 110 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | get_class($this), |
95 | 95 | $matches |
96 | 96 | ); |
97 | - if (! $success) { |
|
97 | + if ( ! $success) { |
|
98 | 98 | throw new EE_Error( |
99 | 99 | sprintf( |
100 | 100 | esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'), |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | ) |
104 | 104 | ); |
105 | 105 | } |
106 | - $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3]; |
|
106 | + $this->version = (int) $matches[1].'.'.(int) $matches[2].'.'.(int) $matches[3]; |
|
107 | 107 | } |
108 | 108 | return $this->version; |
109 | 109 | } |
@@ -17,214 +17,214 @@ |
||
17 | 17 | |
18 | 18 | class Datetime extends DatetimeCalculationBase |
19 | 19 | { |
20 | - /** |
|
21 | - * @var EEM_Datetime |
|
22 | - */ |
|
23 | - protected $datetime_model; |
|
20 | + /** |
|
21 | + * @var EEM_Datetime |
|
22 | + */ |
|
23 | + protected $datetime_model; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var EEM_Registration |
|
27 | - */ |
|
28 | - protected $registration_model; |
|
29 | - public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model) |
|
30 | - { |
|
31 | - $this->datetime_model = $datetime_model; |
|
32 | - $this->registration_model = $registration_model; |
|
33 | - } |
|
25 | + /** |
|
26 | + * @var EEM_Registration |
|
27 | + */ |
|
28 | + protected $registration_model; |
|
29 | + public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model) |
|
30 | + { |
|
31 | + $this->datetime_model = $datetime_model; |
|
32 | + $this->registration_model = $registration_model; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Calculates the total spaces available on the datetime, taking into account |
|
37 | - * ticket limits too. |
|
38 | - * |
|
39 | - * @see EE_Datetime::spaces_remaining( true ) |
|
40 | - * @param array $wpdb_row |
|
41 | - * @param WP_REST_Request $request |
|
42 | - * @param DatetimeControllerBase $controller |
|
43 | - * @return int |
|
44 | - * @throws EE_Error |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
|
51 | - { |
|
52 | - if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
53 | - $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
54 | - } else { |
|
55 | - $dtt_obj = null; |
|
56 | - } |
|
57 | - if ($dtt_obj instanceof EE_Datetime) { |
|
58 | - return $dtt_obj->spaces_remaining(true); |
|
59 | - } |
|
60 | - throw new EE_Error( |
|
61 | - sprintf( |
|
62 | - esc_html__( |
|
63 | - // @codingStandardsIgnoreStart |
|
64 | - 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
65 | - // @codingStandardsIgnoreEnd |
|
66 | - 'event_espresso' |
|
67 | - ), |
|
68 | - $wpdb_row['Datetime.DTT_ID'], |
|
69 | - print_r($wpdb_row, true) |
|
70 | - ) |
|
71 | - ); |
|
72 | - } |
|
35 | + /** |
|
36 | + * Calculates the total spaces available on the datetime, taking into account |
|
37 | + * ticket limits too. |
|
38 | + * |
|
39 | + * @see EE_Datetime::spaces_remaining( true ) |
|
40 | + * @param array $wpdb_row |
|
41 | + * @param WP_REST_Request $request |
|
42 | + * @param DatetimeControllerBase $controller |
|
43 | + * @return int |
|
44 | + * @throws EE_Error |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
|
51 | + { |
|
52 | + if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
53 | + $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
54 | + } else { |
|
55 | + $dtt_obj = null; |
|
56 | + } |
|
57 | + if ($dtt_obj instanceof EE_Datetime) { |
|
58 | + return $dtt_obj->spaces_remaining(true); |
|
59 | + } |
|
60 | + throw new EE_Error( |
|
61 | + sprintf( |
|
62 | + esc_html__( |
|
63 | + // @codingStandardsIgnoreStart |
|
64 | + 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
65 | + // @codingStandardsIgnoreEnd |
|
66 | + 'event_espresso' |
|
67 | + ), |
|
68 | + $wpdb_row['Datetime.DTT_ID'], |
|
69 | + print_r($wpdb_row, true) |
|
70 | + ) |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * Counts registrations who have checked into this datetime |
|
77 | - * |
|
78 | - * @param array $wpdb_row |
|
79 | - * @param WP_REST_Request $request |
|
80 | - * @param DatetimeControllerBase $controller |
|
81 | - * @return int |
|
82 | - * @throws EE_Error |
|
83 | - * @throws InvalidArgumentException |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - * @throws InvalidInterfaceException |
|
86 | - * @throws RestException |
|
87 | - */ |
|
88 | - public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
89 | - { |
|
90 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - esc_html__( |
|
94 | - // @codingStandardsIgnoreStart |
|
95 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
96 | - // @codingStandardsIgnoreEnd |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - print_r($wpdb_row, true) |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
104 | - return $this->registration_model |
|
105 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
106 | - } |
|
75 | + /** |
|
76 | + * Counts registrations who have checked into this datetime |
|
77 | + * |
|
78 | + * @param array $wpdb_row |
|
79 | + * @param WP_REST_Request $request |
|
80 | + * @param DatetimeControllerBase $controller |
|
81 | + * @return int |
|
82 | + * @throws EE_Error |
|
83 | + * @throws InvalidArgumentException |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + * @throws InvalidInterfaceException |
|
86 | + * @throws RestException |
|
87 | + */ |
|
88 | + public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
89 | + { |
|
90 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + esc_html__( |
|
94 | + // @codingStandardsIgnoreStart |
|
95 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
96 | + // @codingStandardsIgnoreEnd |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + print_r($wpdb_row, true) |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
104 | + return $this->registration_model |
|
105 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Counts registrations who have checked out of this datetime |
|
111 | - * |
|
112 | - * @param array $wpdb_row |
|
113 | - * @param WP_REST_Request $request |
|
114 | - * @param DatetimeControllerBase $controller |
|
115 | - * @return int |
|
116 | - * @throws EE_Error |
|
117 | - * @throws InvalidArgumentException |
|
118 | - * @throws InvalidDataTypeException |
|
119 | - * @throws InvalidInterfaceException |
|
120 | - * @throws RestException |
|
121 | - */ |
|
122 | - public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
123 | - { |
|
124 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
125 | - throw new EE_Error( |
|
126 | - sprintf( |
|
127 | - esc_html__( |
|
128 | - // @codingStandardsIgnoreStart |
|
129 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
130 | - // @codingStandardsIgnoreEnd |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - print_r($wpdb_row, true) |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
137 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
138 | - return $this->registration_model |
|
139 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
140 | - } |
|
109 | + /** |
|
110 | + * Counts registrations who have checked out of this datetime |
|
111 | + * |
|
112 | + * @param array $wpdb_row |
|
113 | + * @param WP_REST_Request $request |
|
114 | + * @param DatetimeControllerBase $controller |
|
115 | + * @return int |
|
116 | + * @throws EE_Error |
|
117 | + * @throws InvalidArgumentException |
|
118 | + * @throws InvalidDataTypeException |
|
119 | + * @throws InvalidInterfaceException |
|
120 | + * @throws RestException |
|
121 | + */ |
|
122 | + public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
123 | + { |
|
124 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
125 | + throw new EE_Error( |
|
126 | + sprintf( |
|
127 | + esc_html__( |
|
128 | + // @codingStandardsIgnoreStart |
|
129 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
130 | + // @codingStandardsIgnoreEnd |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + print_r($wpdb_row, true) |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
138 | + return $this->registration_model |
|
139 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * Counts the number of pending-payment registrations for this event (regardless |
|
145 | - * of how many datetimes each registrations' ticket purchase is for) |
|
146 | - * |
|
147 | - * @param array $wpdb_row |
|
148 | - * @param WP_REST_Request $request |
|
149 | - * @param DatetimeControllerBase $controller |
|
150 | - * @return int |
|
151 | - * @throws EE_Error |
|
152 | - * @throws InvalidArgumentException |
|
153 | - * @throws InvalidDataTypeException |
|
154 | - * @throws InvalidInterfaceException |
|
155 | - * @throws RestException |
|
156 | - */ |
|
157 | - public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
158 | - { |
|
159 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
160 | - throw new EE_Error( |
|
161 | - sprintf( |
|
162 | - esc_html__( |
|
163 | - // @codingStandardsIgnoreStart |
|
164 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
165 | - // @codingStandardsIgnoreEnd |
|
166 | - 'event_espresso' |
|
167 | - ), |
|
168 | - print_r($wpdb_row, true) |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
173 | - return $this->registration_model->count( |
|
174 | - array( |
|
175 | - array( |
|
176 | - 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
177 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
178 | - ), |
|
179 | - ), |
|
180 | - 'REG_ID', |
|
181 | - true |
|
182 | - ); |
|
183 | - } |
|
143 | + /** |
|
144 | + * Counts the number of pending-payment registrations for this event (regardless |
|
145 | + * of how many datetimes each registrations' ticket purchase is for) |
|
146 | + * |
|
147 | + * @param array $wpdb_row |
|
148 | + * @param WP_REST_Request $request |
|
149 | + * @param DatetimeControllerBase $controller |
|
150 | + * @return int |
|
151 | + * @throws EE_Error |
|
152 | + * @throws InvalidArgumentException |
|
153 | + * @throws InvalidDataTypeException |
|
154 | + * @throws InvalidInterfaceException |
|
155 | + * @throws RestException |
|
156 | + */ |
|
157 | + public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
158 | + { |
|
159 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
160 | + throw new EE_Error( |
|
161 | + sprintf( |
|
162 | + esc_html__( |
|
163 | + // @codingStandardsIgnoreStart |
|
164 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
165 | + // @codingStandardsIgnoreEnd |
|
166 | + 'event_espresso' |
|
167 | + ), |
|
168 | + print_r($wpdb_row, true) |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
173 | + return $this->registration_model->count( |
|
174 | + array( |
|
175 | + array( |
|
176 | + 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
177 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
178 | + ), |
|
179 | + ), |
|
180 | + 'REG_ID', |
|
181 | + true |
|
182 | + ); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
188 | - * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
189 | - * |
|
190 | - * @since 4.9.68.p |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function schemaForCalculations() |
|
194 | - { |
|
195 | - return array( |
|
196 | - 'spaces_remaining_considering_tickets' => array( |
|
197 | - 'description' => esc_html__( |
|
198 | - 'Calculates the total spaces available on the datetime, taking into account ticket limits too.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - 'type' => 'number', |
|
202 | - 'protected' => true, |
|
203 | - ), |
|
204 | - 'registrations_checked_in_count' => array( |
|
205 | - 'description' => esc_html__( |
|
206 | - 'Counts registrations who have checked into this datetime.', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - 'type' => 'number', |
|
210 | - 'protected' => true, |
|
211 | - ), |
|
212 | - 'registrations_checked_out_count' => array( |
|
213 | - 'description' => esc_html__( |
|
214 | - 'Counts registrations who have checked out of this datetime.', |
|
215 | - 'event_espresso' |
|
216 | - ), |
|
217 | - 'type' => 'number', |
|
218 | - 'protected' => true, |
|
219 | - ), |
|
220 | - 'spots_taken_pending_payment' => array( |
|
221 | - 'description' => esc_html__( |
|
222 | - 'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for', |
|
223 | - 'event_espresso' |
|
224 | - ), |
|
225 | - 'type' => 'number', |
|
226 | - 'protected' => true, |
|
227 | - ), |
|
228 | - ); |
|
229 | - } |
|
186 | + /** |
|
187 | + * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
188 | + * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
189 | + * |
|
190 | + * @since 4.9.68.p |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function schemaForCalculations() |
|
194 | + { |
|
195 | + return array( |
|
196 | + 'spaces_remaining_considering_tickets' => array( |
|
197 | + 'description' => esc_html__( |
|
198 | + 'Calculates the total spaces available on the datetime, taking into account ticket limits too.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + 'type' => 'number', |
|
202 | + 'protected' => true, |
|
203 | + ), |
|
204 | + 'registrations_checked_in_count' => array( |
|
205 | + 'description' => esc_html__( |
|
206 | + 'Counts registrations who have checked into this datetime.', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + 'type' => 'number', |
|
210 | + 'protected' => true, |
|
211 | + ), |
|
212 | + 'registrations_checked_out_count' => array( |
|
213 | + 'description' => esc_html__( |
|
214 | + 'Counts registrations who have checked out of this datetime.', |
|
215 | + 'event_espresso' |
|
216 | + ), |
|
217 | + 'type' => 'number', |
|
218 | + 'protected' => true, |
|
219 | + ), |
|
220 | + 'spots_taken_pending_payment' => array( |
|
221 | + 'description' => esc_html__( |
|
222 | + 'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for', |
|
223 | + 'event_espresso' |
|
224 | + ), |
|
225 | + 'type' => 'number', |
|
226 | + 'protected' => true, |
|
227 | + ), |
|
228 | + ); |
|
229 | + } |
|
230 | 230 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
89 | 89 | { |
90 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
90 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
91 | 91 | throw new EE_Error( |
92 | 92 | sprintf( |
93 | 93 | esc_html__( |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
123 | 123 | { |
124 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
124 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
125 | 125 | throw new EE_Error( |
126 | 126 | sprintf( |
127 | 127 | esc_html__( |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
158 | 158 | { |
159 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
159 | + if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
160 | 160 | throw new EE_Error( |
161 | 161 | sprintf( |
162 | 162 | esc_html__( |
@@ -26,571 +26,571 @@ |
||
26 | 26 | */ |
27 | 27 | class Event extends EventCalculationBase |
28 | 28 | { |
29 | - /** |
|
30 | - * @var EEM_Event |
|
31 | - */ |
|
32 | - protected $event_model; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var EEM_Registration |
|
36 | - */ |
|
37 | - protected $registration_model; |
|
38 | - public function __construct(EEM_Event $event_model, EEM_Registration $registration_model) |
|
39 | - { |
|
40 | - $this->event_model = $event_model; |
|
41 | - $this->registration_model = $registration_model; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Calculates the total spaces on the event (not subtracting sales, but taking |
|
46 | - * sales into account; so this is the optimum sales that CAN still be achieved) |
|
47 | - * See EE_Event::total_available_spaces( true ); |
|
48 | - * |
|
49 | - * @param array $wpdb_row |
|
50 | - * @param WP_REST_Request $request |
|
51 | - * @param EventControllerBase $controller |
|
52 | - * @return int |
|
53 | - * @throws EE_Error |
|
54 | - * @throws DomainException |
|
55 | - * @throws InvalidDataTypeException |
|
56 | - * @throws InvalidInterfaceException |
|
57 | - * @throws UnexpectedEntityException |
|
58 | - * @throws InvalidArgumentException |
|
59 | - */ |
|
60 | - public function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
61 | - { |
|
62 | - $event_obj = null; |
|
63 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
64 | - $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
65 | - } |
|
66 | - if ($event_obj instanceof EE_Event) { |
|
67 | - return $event_obj->total_available_spaces(); |
|
68 | - } |
|
69 | - throw new EE_Error( |
|
70 | - sprintf( |
|
71 | - esc_html__( |
|
72 | - // @codingStandardsIgnoreStart |
|
73 | - 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
74 | - // @codingStandardsIgnoreEnd |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - $wpdb_row['Event_CPT.ID'], |
|
78 | - print_r($wpdb_row, true) |
|
79 | - ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
86 | - * sales that COULD have been achieved) |
|
87 | - * See EE_Event::total_available_spaces( true ); |
|
88 | - * |
|
89 | - * @param array $wpdb_row |
|
90 | - * @param WP_REST_Request $request |
|
91 | - * @param EventControllerBase $controller |
|
92 | - * @return int |
|
93 | - * @throws DomainException |
|
94 | - * @throws EE_Error |
|
95 | - * @throws InvalidArgumentException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws UnexpectedEntityException |
|
99 | - */ |
|
100 | - public function optimumSalesNow($wpdb_row, $request, $controller) |
|
101 | - { |
|
102 | - $event_obj = null; |
|
103 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
104 | - $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
105 | - } |
|
106 | - if ($event_obj instanceof EE_Event) { |
|
107 | - return $event_obj->total_available_spaces(true); |
|
108 | - } |
|
109 | - throw new EE_Error( |
|
110 | - sprintf( |
|
111 | - esc_html__( |
|
112 | - // @codingStandardsIgnoreStart |
|
113 | - 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
114 | - // @codingStandardsIgnoreEnd |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - $wpdb_row['Event_CPT.ID'], |
|
118 | - print_r($wpdb_row, true) |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Like optimum_sales_now, but minus total sales so far. |
|
126 | - * See EE_Event::spaces_remaining_for_sale( true ); |
|
127 | - * |
|
128 | - * @param array $wpdb_row |
|
129 | - * @param WP_REST_Request $request |
|
130 | - * @param EventControllerBase $controller |
|
131 | - * @return int |
|
132 | - * @throws DomainException |
|
133 | - * @throws EE_Error |
|
134 | - * @throws InvalidArgumentException |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - * @throws InvalidInterfaceException |
|
137 | - * @throws UnexpectedEntityException |
|
138 | - */ |
|
139 | - public function spacesRemaining($wpdb_row, $request, $controller) |
|
140 | - { |
|
141 | - $event_obj = null; |
|
142 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
143 | - $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
144 | - } |
|
145 | - if ($event_obj instanceof EE_Event) { |
|
146 | - return $event_obj->spaces_remaining_for_sale(); |
|
147 | - } |
|
148 | - throw new EE_Error( |
|
149 | - sprintf( |
|
150 | - esc_html__( |
|
151 | - // @codingStandardsIgnoreStart |
|
152 | - 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
153 | - // @codingStandardsIgnoreEnd |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - $wpdb_row['Event_CPT.ID'], |
|
157 | - print_r($wpdb_row, true) |
|
158 | - ) |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Counts the number of approved registrations for this event (regardless |
|
165 | - * of how many datetimes each registrations' ticket purchase is for) |
|
166 | - * |
|
167 | - * @param array $wpdb_row |
|
168 | - * @param WP_REST_Request $request |
|
169 | - * @param EventControllerBase $controller |
|
170 | - * @return int |
|
171 | - * @throws EE_Error |
|
172 | - * @throws InvalidArgumentException |
|
173 | - * @throws InvalidDataTypeException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - */ |
|
176 | - public function spotsTaken($wpdb_row, $request, $controller) |
|
177 | - { |
|
178 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
179 | - throw new EE_Error( |
|
180 | - sprintf( |
|
181 | - esc_html__( |
|
182 | - // @codingStandardsIgnoreStart |
|
183 | - 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
184 | - // @codingStandardsIgnoreEnd |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - print_r($wpdb_row, true) |
|
188 | - ) |
|
189 | - ); |
|
190 | - } |
|
191 | - return $this->registration_model->count( |
|
192 | - array( |
|
193 | - array( |
|
194 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
195 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
196 | - ), |
|
197 | - ), |
|
198 | - 'REG_ID', |
|
199 | - true |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Counts the number of pending-payment registrations for this event (regardless |
|
206 | - * of how many datetimes each registrations' ticket purchase is for) |
|
207 | - * |
|
208 | - * @param array $wpdb_row |
|
209 | - * @param WP_REST_Request $request |
|
210 | - * @param EventControllerBase $controller |
|
211 | - * @return int |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws RestException |
|
217 | - */ |
|
218 | - public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
219 | - { |
|
220 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
221 | - throw new EE_Error( |
|
222 | - sprintf( |
|
223 | - esc_html__( |
|
224 | - // @codingStandardsIgnoreStart |
|
225 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
226 | - // @codingStandardsIgnoreEnd |
|
227 | - 'event_espresso' |
|
228 | - ), |
|
229 | - print_r($wpdb_row, true) |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
234 | - return $this->registration_model->count( |
|
235 | - array( |
|
236 | - array( |
|
237 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
238 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
239 | - ), |
|
240 | - ), |
|
241 | - 'REG_ID', |
|
242 | - true |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Counts all the registrations who have checked into one of this events' datetimes |
|
249 | - * See EE_Event::total_available_spaces( false ); |
|
250 | - * |
|
251 | - * @param array $wpdb_row |
|
252 | - * @param WP_REST_Request $request |
|
253 | - * @param EventControllerBase $controller |
|
254 | - * @return int|null if permission denied |
|
255 | - * @throws EE_Error |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidDataTypeException |
|
258 | - * @throws InvalidInterfaceException |
|
259 | - * @throws RestException |
|
260 | - */ |
|
261 | - public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
262 | - { |
|
263 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
264 | - throw new EE_Error( |
|
265 | - sprintf( |
|
266 | - esc_html__( |
|
267 | - // @codingStandardsIgnoreStart |
|
268 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
269 | - // @codingStandardsIgnoreEnd |
|
270 | - 'event_espresso' |
|
271 | - ), |
|
272 | - print_r($wpdb_row, true) |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
277 | - return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Counts all the registrations who have checked out of one of this events' datetimes |
|
283 | - * See EE_Event::total_available_spaces( false ); |
|
284 | - * |
|
285 | - * @param array $wpdb_row |
|
286 | - * @param WP_REST_Request $request |
|
287 | - * @param EventControllerBase $controller |
|
288 | - * @return int |
|
289 | - * @throws EE_Error |
|
290 | - * @throws InvalidArgumentException |
|
291 | - * @throws InvalidDataTypeException |
|
292 | - * @throws InvalidInterfaceException |
|
293 | - * @throws RestException |
|
294 | - */ |
|
295 | - public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
296 | - { |
|
297 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
298 | - throw new EE_Error( |
|
299 | - sprintf( |
|
300 | - esc_html__( |
|
301 | - // @codingStandardsIgnoreStart |
|
302 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
303 | - // @codingStandardsIgnoreEnd |
|
304 | - 'event_espresso' |
|
305 | - ), |
|
306 | - print_r($wpdb_row, true) |
|
307 | - ) |
|
308 | - ); |
|
309 | - } |
|
310 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
311 | - return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Gets the thumbnail image |
|
317 | - * |
|
318 | - * @param array $wpdb_row |
|
319 | - * @param WP_REST_Request $request |
|
320 | - * @param EventControllerBase $controller |
|
321 | - * @return array |
|
322 | - * @throws EE_Error |
|
323 | - */ |
|
324 | - public function imageThumbnail($wpdb_row, $request, $controller) |
|
325 | - { |
|
326 | - return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Gets the medium image |
|
332 | - * |
|
333 | - * @param array $wpdb_row |
|
334 | - * @param WP_REST_Request $request |
|
335 | - * @param EventControllerBase $controller |
|
336 | - * @return array |
|
337 | - * @throws EE_Error |
|
338 | - */ |
|
339 | - public function imageMedium($wpdb_row, $request, $controller) |
|
340 | - { |
|
341 | - return self::calculateImageData($wpdb_row, 'medium'); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Gets the medium-large image |
|
347 | - * |
|
348 | - * @param array $wpdb_row |
|
349 | - * @param WP_REST_Request $request |
|
350 | - * @param EventControllerBase $controller |
|
351 | - * @return array |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public function imageMediumLarge($wpdb_row, $request, $controller) |
|
355 | - { |
|
356 | - return self::calculateImageData($wpdb_row, 'medium_large'); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Gets the large image |
|
362 | - * |
|
363 | - * @param array $wpdb_row |
|
364 | - * @param WP_REST_Request $request |
|
365 | - * @param EventControllerBase $controller |
|
366 | - * @return array |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - public function imageLarge($wpdb_row, $request, $controller) |
|
370 | - { |
|
371 | - return self::calculateImageData($wpdb_row, 'large'); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Gets the post-thumbnail image |
|
377 | - * |
|
378 | - * @param array $wpdb_row |
|
379 | - * @param WP_REST_Request $request |
|
380 | - * @param EventControllerBase $controller |
|
381 | - * @return array |
|
382 | - * @throws EE_Error |
|
383 | - */ |
|
384 | - public function imagePostThumbnail($wpdb_row, $request, $controller) |
|
385 | - { |
|
386 | - return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Gets the full size image |
|
392 | - * |
|
393 | - * @param array $wpdb_row |
|
394 | - * @param WP_REST_Request $request |
|
395 | - * @param EventControllerBase $controller |
|
396 | - * @return array |
|
397 | - * @throws EE_Error |
|
398 | - */ |
|
399 | - public function imageFull($wpdb_row, $request, $controller) |
|
400 | - { |
|
401 | - return self::calculateImageData($wpdb_row, 'full'); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Gets image specs and formats them for the display in the API, |
|
407 | - * according to the image size requested |
|
408 | - * |
|
409 | - * @param array $wpdb_row |
|
410 | - * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
411 | - * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - protected function calculateImageData($wpdb_row, $image_size) |
|
415 | - { |
|
416 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
417 | - throw new EE_Error( |
|
418 | - sprintf( |
|
419 | - esc_html__( |
|
420 | - // @codingStandardsIgnoreStart |
|
421 | - 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
422 | - // @codingStandardsIgnoreEnd |
|
423 | - 'event_espresso' |
|
424 | - ), |
|
425 | - print_r($wpdb_row, true) |
|
426 | - ) |
|
427 | - ); |
|
428 | - } |
|
429 | - $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
430 | - $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
431 | - $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
432 | - if (! $data) { |
|
433 | - return null; |
|
434 | - } |
|
435 | - $generated = true; |
|
436 | - if (isset($data[3])) { |
|
437 | - $generated = $data[3]; |
|
438 | - } |
|
439 | - return array( |
|
440 | - 'url' => $data[0], |
|
441 | - 'width' => $data[1], |
|
442 | - 'height' => $data[2], |
|
443 | - 'generated' => $generated, |
|
444 | - ); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
450 | - * |
|
451 | - * @param array $wpdb_row |
|
452 | - * @return bool |
|
453 | - */ |
|
454 | - protected function wpdbRowHasEventId($wpdb_row) |
|
455 | - { |
|
456 | - return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
462 | - * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
463 | - * |
|
464 | - * @since 4.9.68.p |
|
465 | - * @return array |
|
466 | - */ |
|
467 | - public function schemaForCalculations() |
|
468 | - { |
|
469 | - $image_object_properties = array( |
|
470 | - 'url' => array( |
|
471 | - 'type' => 'string', |
|
472 | - ), |
|
473 | - 'width' => array( |
|
474 | - 'type' => 'number', |
|
475 | - ), |
|
476 | - 'height' => array( |
|
477 | - 'type' => 'number', |
|
478 | - ), |
|
479 | - 'generated' => array( |
|
480 | - 'type' => 'boolean', |
|
481 | - ), |
|
482 | - ); |
|
483 | - return array( |
|
484 | - 'optimum_sales_at_start' => array( |
|
485 | - 'description' => esc_html__( |
|
486 | - 'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.', |
|
487 | - 'event_espresso' |
|
488 | - ), |
|
489 | - 'type' => 'number', |
|
490 | - 'protected' => true, |
|
491 | - ), |
|
492 | - 'optimum_sales_now' => array( |
|
493 | - 'description' => esc_html__( |
|
494 | - 'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.', |
|
495 | - 'event_espresso' |
|
496 | - ), |
|
497 | - 'type' => 'number', |
|
498 | - 'protected' => true, |
|
499 | - ), |
|
500 | - 'spaces_remaining' => array( |
|
501 | - 'description' => esc_html__( |
|
502 | - 'The optimum_sales_number result, minus total sales so far.', |
|
503 | - 'event_espresso' |
|
504 | - ), |
|
505 | - 'type' => 'number', |
|
506 | - 'protected' => true, |
|
507 | - ), |
|
508 | - 'spots_taken' => array( |
|
509 | - 'description' => esc_html__( |
|
510 | - 'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
511 | - 'event_espresso' |
|
512 | - ), |
|
513 | - 'type' => 'number', |
|
514 | - 'protected' => true, |
|
515 | - ), |
|
516 | - 'spots_taken_pending_payment' => array( |
|
517 | - 'description' => esc_html__( |
|
518 | - 'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
519 | - 'event_espresso' |
|
520 | - ), |
|
521 | - 'type' => 'number', |
|
522 | - 'protected' => true, |
|
523 | - ), |
|
524 | - 'registrations_checked_in_count' => array( |
|
525 | - 'description' => esc_html__( |
|
526 | - 'The count of all the registrations who have checked into one of this event\'s datetimes.', |
|
527 | - 'event_espresso' |
|
528 | - ), |
|
529 | - 'type' => 'number', |
|
530 | - 'protected' => true, |
|
531 | - ), |
|
532 | - 'registrations_checked_out_count' => array( |
|
533 | - 'description' => esc_html__( |
|
534 | - 'The count of all registrations who have checked out of one of this event\'s datetimes.', |
|
535 | - 'event_espresso' |
|
536 | - ), |
|
537 | - 'type' => 'number', |
|
538 | - 'protected' => true, |
|
539 | - ), |
|
540 | - 'image_thumbnail' => array( |
|
541 | - 'description' => esc_html__( |
|
542 | - 'The thumbnail image data.', |
|
543 | - 'event_espresso' |
|
544 | - ), |
|
545 | - 'type' => 'object', |
|
546 | - 'properties' => $image_object_properties, |
|
547 | - 'additionalProperties' => false, |
|
548 | - ), |
|
549 | - 'image_medium' => array( |
|
550 | - 'description' => esc_html__( |
|
551 | - 'The medium image data.', |
|
552 | - 'event_espresso' |
|
553 | - ), |
|
554 | - 'type' => 'object', |
|
555 | - 'properties' => $image_object_properties, |
|
556 | - 'additionalProperties' => false, |
|
557 | - ), |
|
558 | - 'image_medium_large' => array( |
|
559 | - 'description' => esc_html__( |
|
560 | - 'The medium-large image data.', |
|
561 | - 'event_espresso' |
|
562 | - ), |
|
563 | - 'type' => 'object', |
|
564 | - 'properties' => $image_object_properties, |
|
565 | - 'additionalProperties' => false, |
|
566 | - ), |
|
567 | - 'image_large' => array( |
|
568 | - 'description' => esc_html__( |
|
569 | - 'The large image data.', |
|
570 | - 'event_espresso' |
|
571 | - ), |
|
572 | - 'type' => 'object', |
|
573 | - 'properties' => $image_object_properties, |
|
574 | - 'additionalProperties' => false, |
|
575 | - ), |
|
576 | - 'image_post_thumbnail' => array( |
|
577 | - 'description' => esc_html__( |
|
578 | - 'The post-thumbnail image data.', |
|
579 | - 'event_espresso' |
|
580 | - ), |
|
581 | - 'type' => 'object', |
|
582 | - 'properties' => $image_object_properties, |
|
583 | - 'additionalProperties' => false, |
|
584 | - ), |
|
585 | - 'image_full' => array( |
|
586 | - 'description' => esc_html__( |
|
587 | - 'The full size image data', |
|
588 | - 'event_espresso' |
|
589 | - ), |
|
590 | - 'type' => 'object', |
|
591 | - 'properties' => $image_object_properties, |
|
592 | - 'additionalProperties' => false, |
|
593 | - ), |
|
594 | - ); |
|
595 | - } |
|
29 | + /** |
|
30 | + * @var EEM_Event |
|
31 | + */ |
|
32 | + protected $event_model; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var EEM_Registration |
|
36 | + */ |
|
37 | + protected $registration_model; |
|
38 | + public function __construct(EEM_Event $event_model, EEM_Registration $registration_model) |
|
39 | + { |
|
40 | + $this->event_model = $event_model; |
|
41 | + $this->registration_model = $registration_model; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Calculates the total spaces on the event (not subtracting sales, but taking |
|
46 | + * sales into account; so this is the optimum sales that CAN still be achieved) |
|
47 | + * See EE_Event::total_available_spaces( true ); |
|
48 | + * |
|
49 | + * @param array $wpdb_row |
|
50 | + * @param WP_REST_Request $request |
|
51 | + * @param EventControllerBase $controller |
|
52 | + * @return int |
|
53 | + * @throws EE_Error |
|
54 | + * @throws DomainException |
|
55 | + * @throws InvalidDataTypeException |
|
56 | + * @throws InvalidInterfaceException |
|
57 | + * @throws UnexpectedEntityException |
|
58 | + * @throws InvalidArgumentException |
|
59 | + */ |
|
60 | + public function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
61 | + { |
|
62 | + $event_obj = null; |
|
63 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
64 | + $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
65 | + } |
|
66 | + if ($event_obj instanceof EE_Event) { |
|
67 | + return $event_obj->total_available_spaces(); |
|
68 | + } |
|
69 | + throw new EE_Error( |
|
70 | + sprintf( |
|
71 | + esc_html__( |
|
72 | + // @codingStandardsIgnoreStart |
|
73 | + 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
74 | + // @codingStandardsIgnoreEnd |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + $wpdb_row['Event_CPT.ID'], |
|
78 | + print_r($wpdb_row, true) |
|
79 | + ) |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
86 | + * sales that COULD have been achieved) |
|
87 | + * See EE_Event::total_available_spaces( true ); |
|
88 | + * |
|
89 | + * @param array $wpdb_row |
|
90 | + * @param WP_REST_Request $request |
|
91 | + * @param EventControllerBase $controller |
|
92 | + * @return int |
|
93 | + * @throws DomainException |
|
94 | + * @throws EE_Error |
|
95 | + * @throws InvalidArgumentException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws UnexpectedEntityException |
|
99 | + */ |
|
100 | + public function optimumSalesNow($wpdb_row, $request, $controller) |
|
101 | + { |
|
102 | + $event_obj = null; |
|
103 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
104 | + $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
105 | + } |
|
106 | + if ($event_obj instanceof EE_Event) { |
|
107 | + return $event_obj->total_available_spaces(true); |
|
108 | + } |
|
109 | + throw new EE_Error( |
|
110 | + sprintf( |
|
111 | + esc_html__( |
|
112 | + // @codingStandardsIgnoreStart |
|
113 | + 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
114 | + // @codingStandardsIgnoreEnd |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + $wpdb_row['Event_CPT.ID'], |
|
118 | + print_r($wpdb_row, true) |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Like optimum_sales_now, but minus total sales so far. |
|
126 | + * See EE_Event::spaces_remaining_for_sale( true ); |
|
127 | + * |
|
128 | + * @param array $wpdb_row |
|
129 | + * @param WP_REST_Request $request |
|
130 | + * @param EventControllerBase $controller |
|
131 | + * @return int |
|
132 | + * @throws DomainException |
|
133 | + * @throws EE_Error |
|
134 | + * @throws InvalidArgumentException |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + * @throws InvalidInterfaceException |
|
137 | + * @throws UnexpectedEntityException |
|
138 | + */ |
|
139 | + public function spacesRemaining($wpdb_row, $request, $controller) |
|
140 | + { |
|
141 | + $event_obj = null; |
|
142 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
143 | + $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
144 | + } |
|
145 | + if ($event_obj instanceof EE_Event) { |
|
146 | + return $event_obj->spaces_remaining_for_sale(); |
|
147 | + } |
|
148 | + throw new EE_Error( |
|
149 | + sprintf( |
|
150 | + esc_html__( |
|
151 | + // @codingStandardsIgnoreStart |
|
152 | + 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
153 | + // @codingStandardsIgnoreEnd |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + $wpdb_row['Event_CPT.ID'], |
|
157 | + print_r($wpdb_row, true) |
|
158 | + ) |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Counts the number of approved registrations for this event (regardless |
|
165 | + * of how many datetimes each registrations' ticket purchase is for) |
|
166 | + * |
|
167 | + * @param array $wpdb_row |
|
168 | + * @param WP_REST_Request $request |
|
169 | + * @param EventControllerBase $controller |
|
170 | + * @return int |
|
171 | + * @throws EE_Error |
|
172 | + * @throws InvalidArgumentException |
|
173 | + * @throws InvalidDataTypeException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + */ |
|
176 | + public function spotsTaken($wpdb_row, $request, $controller) |
|
177 | + { |
|
178 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
179 | + throw new EE_Error( |
|
180 | + sprintf( |
|
181 | + esc_html__( |
|
182 | + // @codingStandardsIgnoreStart |
|
183 | + 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
184 | + // @codingStandardsIgnoreEnd |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + print_r($wpdb_row, true) |
|
188 | + ) |
|
189 | + ); |
|
190 | + } |
|
191 | + return $this->registration_model->count( |
|
192 | + array( |
|
193 | + array( |
|
194 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
195 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
196 | + ), |
|
197 | + ), |
|
198 | + 'REG_ID', |
|
199 | + true |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Counts the number of pending-payment registrations for this event (regardless |
|
206 | + * of how many datetimes each registrations' ticket purchase is for) |
|
207 | + * |
|
208 | + * @param array $wpdb_row |
|
209 | + * @param WP_REST_Request $request |
|
210 | + * @param EventControllerBase $controller |
|
211 | + * @return int |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws RestException |
|
217 | + */ |
|
218 | + public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
219 | + { |
|
220 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
221 | + throw new EE_Error( |
|
222 | + sprintf( |
|
223 | + esc_html__( |
|
224 | + // @codingStandardsIgnoreStart |
|
225 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
226 | + // @codingStandardsIgnoreEnd |
|
227 | + 'event_espresso' |
|
228 | + ), |
|
229 | + print_r($wpdb_row, true) |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
234 | + return $this->registration_model->count( |
|
235 | + array( |
|
236 | + array( |
|
237 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
238 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
239 | + ), |
|
240 | + ), |
|
241 | + 'REG_ID', |
|
242 | + true |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Counts all the registrations who have checked into one of this events' datetimes |
|
249 | + * See EE_Event::total_available_spaces( false ); |
|
250 | + * |
|
251 | + * @param array $wpdb_row |
|
252 | + * @param WP_REST_Request $request |
|
253 | + * @param EventControllerBase $controller |
|
254 | + * @return int|null if permission denied |
|
255 | + * @throws EE_Error |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidDataTypeException |
|
258 | + * @throws InvalidInterfaceException |
|
259 | + * @throws RestException |
|
260 | + */ |
|
261 | + public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
262 | + { |
|
263 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
264 | + throw new EE_Error( |
|
265 | + sprintf( |
|
266 | + esc_html__( |
|
267 | + // @codingStandardsIgnoreStart |
|
268 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
269 | + // @codingStandardsIgnoreEnd |
|
270 | + 'event_espresso' |
|
271 | + ), |
|
272 | + print_r($wpdb_row, true) |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
277 | + return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Counts all the registrations who have checked out of one of this events' datetimes |
|
283 | + * See EE_Event::total_available_spaces( false ); |
|
284 | + * |
|
285 | + * @param array $wpdb_row |
|
286 | + * @param WP_REST_Request $request |
|
287 | + * @param EventControllerBase $controller |
|
288 | + * @return int |
|
289 | + * @throws EE_Error |
|
290 | + * @throws InvalidArgumentException |
|
291 | + * @throws InvalidDataTypeException |
|
292 | + * @throws InvalidInterfaceException |
|
293 | + * @throws RestException |
|
294 | + */ |
|
295 | + public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
296 | + { |
|
297 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
298 | + throw new EE_Error( |
|
299 | + sprintf( |
|
300 | + esc_html__( |
|
301 | + // @codingStandardsIgnoreStart |
|
302 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
303 | + // @codingStandardsIgnoreEnd |
|
304 | + 'event_espresso' |
|
305 | + ), |
|
306 | + print_r($wpdb_row, true) |
|
307 | + ) |
|
308 | + ); |
|
309 | + } |
|
310 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
311 | + return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Gets the thumbnail image |
|
317 | + * |
|
318 | + * @param array $wpdb_row |
|
319 | + * @param WP_REST_Request $request |
|
320 | + * @param EventControllerBase $controller |
|
321 | + * @return array |
|
322 | + * @throws EE_Error |
|
323 | + */ |
|
324 | + public function imageThumbnail($wpdb_row, $request, $controller) |
|
325 | + { |
|
326 | + return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Gets the medium image |
|
332 | + * |
|
333 | + * @param array $wpdb_row |
|
334 | + * @param WP_REST_Request $request |
|
335 | + * @param EventControllerBase $controller |
|
336 | + * @return array |
|
337 | + * @throws EE_Error |
|
338 | + */ |
|
339 | + public function imageMedium($wpdb_row, $request, $controller) |
|
340 | + { |
|
341 | + return self::calculateImageData($wpdb_row, 'medium'); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Gets the medium-large image |
|
347 | + * |
|
348 | + * @param array $wpdb_row |
|
349 | + * @param WP_REST_Request $request |
|
350 | + * @param EventControllerBase $controller |
|
351 | + * @return array |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public function imageMediumLarge($wpdb_row, $request, $controller) |
|
355 | + { |
|
356 | + return self::calculateImageData($wpdb_row, 'medium_large'); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Gets the large image |
|
362 | + * |
|
363 | + * @param array $wpdb_row |
|
364 | + * @param WP_REST_Request $request |
|
365 | + * @param EventControllerBase $controller |
|
366 | + * @return array |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + public function imageLarge($wpdb_row, $request, $controller) |
|
370 | + { |
|
371 | + return self::calculateImageData($wpdb_row, 'large'); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Gets the post-thumbnail image |
|
377 | + * |
|
378 | + * @param array $wpdb_row |
|
379 | + * @param WP_REST_Request $request |
|
380 | + * @param EventControllerBase $controller |
|
381 | + * @return array |
|
382 | + * @throws EE_Error |
|
383 | + */ |
|
384 | + public function imagePostThumbnail($wpdb_row, $request, $controller) |
|
385 | + { |
|
386 | + return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Gets the full size image |
|
392 | + * |
|
393 | + * @param array $wpdb_row |
|
394 | + * @param WP_REST_Request $request |
|
395 | + * @param EventControllerBase $controller |
|
396 | + * @return array |
|
397 | + * @throws EE_Error |
|
398 | + */ |
|
399 | + public function imageFull($wpdb_row, $request, $controller) |
|
400 | + { |
|
401 | + return self::calculateImageData($wpdb_row, 'full'); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Gets image specs and formats them for the display in the API, |
|
407 | + * according to the image size requested |
|
408 | + * |
|
409 | + * @param array $wpdb_row |
|
410 | + * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
411 | + * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + protected function calculateImageData($wpdb_row, $image_size) |
|
415 | + { |
|
416 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
417 | + throw new EE_Error( |
|
418 | + sprintf( |
|
419 | + esc_html__( |
|
420 | + // @codingStandardsIgnoreStart |
|
421 | + 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
422 | + // @codingStandardsIgnoreEnd |
|
423 | + 'event_espresso' |
|
424 | + ), |
|
425 | + print_r($wpdb_row, true) |
|
426 | + ) |
|
427 | + ); |
|
428 | + } |
|
429 | + $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
430 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
431 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
432 | + if (! $data) { |
|
433 | + return null; |
|
434 | + } |
|
435 | + $generated = true; |
|
436 | + if (isset($data[3])) { |
|
437 | + $generated = $data[3]; |
|
438 | + } |
|
439 | + return array( |
|
440 | + 'url' => $data[0], |
|
441 | + 'width' => $data[1], |
|
442 | + 'height' => $data[2], |
|
443 | + 'generated' => $generated, |
|
444 | + ); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
450 | + * |
|
451 | + * @param array $wpdb_row |
|
452 | + * @return bool |
|
453 | + */ |
|
454 | + protected function wpdbRowHasEventId($wpdb_row) |
|
455 | + { |
|
456 | + return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
462 | + * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
463 | + * |
|
464 | + * @since 4.9.68.p |
|
465 | + * @return array |
|
466 | + */ |
|
467 | + public function schemaForCalculations() |
|
468 | + { |
|
469 | + $image_object_properties = array( |
|
470 | + 'url' => array( |
|
471 | + 'type' => 'string', |
|
472 | + ), |
|
473 | + 'width' => array( |
|
474 | + 'type' => 'number', |
|
475 | + ), |
|
476 | + 'height' => array( |
|
477 | + 'type' => 'number', |
|
478 | + ), |
|
479 | + 'generated' => array( |
|
480 | + 'type' => 'boolean', |
|
481 | + ), |
|
482 | + ); |
|
483 | + return array( |
|
484 | + 'optimum_sales_at_start' => array( |
|
485 | + 'description' => esc_html__( |
|
486 | + 'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.', |
|
487 | + 'event_espresso' |
|
488 | + ), |
|
489 | + 'type' => 'number', |
|
490 | + 'protected' => true, |
|
491 | + ), |
|
492 | + 'optimum_sales_now' => array( |
|
493 | + 'description' => esc_html__( |
|
494 | + 'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.', |
|
495 | + 'event_espresso' |
|
496 | + ), |
|
497 | + 'type' => 'number', |
|
498 | + 'protected' => true, |
|
499 | + ), |
|
500 | + 'spaces_remaining' => array( |
|
501 | + 'description' => esc_html__( |
|
502 | + 'The optimum_sales_number result, minus total sales so far.', |
|
503 | + 'event_espresso' |
|
504 | + ), |
|
505 | + 'type' => 'number', |
|
506 | + 'protected' => true, |
|
507 | + ), |
|
508 | + 'spots_taken' => array( |
|
509 | + 'description' => esc_html__( |
|
510 | + 'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
511 | + 'event_espresso' |
|
512 | + ), |
|
513 | + 'type' => 'number', |
|
514 | + 'protected' => true, |
|
515 | + ), |
|
516 | + 'spots_taken_pending_payment' => array( |
|
517 | + 'description' => esc_html__( |
|
518 | + 'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
519 | + 'event_espresso' |
|
520 | + ), |
|
521 | + 'type' => 'number', |
|
522 | + 'protected' => true, |
|
523 | + ), |
|
524 | + 'registrations_checked_in_count' => array( |
|
525 | + 'description' => esc_html__( |
|
526 | + 'The count of all the registrations who have checked into one of this event\'s datetimes.', |
|
527 | + 'event_espresso' |
|
528 | + ), |
|
529 | + 'type' => 'number', |
|
530 | + 'protected' => true, |
|
531 | + ), |
|
532 | + 'registrations_checked_out_count' => array( |
|
533 | + 'description' => esc_html__( |
|
534 | + 'The count of all registrations who have checked out of one of this event\'s datetimes.', |
|
535 | + 'event_espresso' |
|
536 | + ), |
|
537 | + 'type' => 'number', |
|
538 | + 'protected' => true, |
|
539 | + ), |
|
540 | + 'image_thumbnail' => array( |
|
541 | + 'description' => esc_html__( |
|
542 | + 'The thumbnail image data.', |
|
543 | + 'event_espresso' |
|
544 | + ), |
|
545 | + 'type' => 'object', |
|
546 | + 'properties' => $image_object_properties, |
|
547 | + 'additionalProperties' => false, |
|
548 | + ), |
|
549 | + 'image_medium' => array( |
|
550 | + 'description' => esc_html__( |
|
551 | + 'The medium image data.', |
|
552 | + 'event_espresso' |
|
553 | + ), |
|
554 | + 'type' => 'object', |
|
555 | + 'properties' => $image_object_properties, |
|
556 | + 'additionalProperties' => false, |
|
557 | + ), |
|
558 | + 'image_medium_large' => array( |
|
559 | + 'description' => esc_html__( |
|
560 | + 'The medium-large image data.', |
|
561 | + 'event_espresso' |
|
562 | + ), |
|
563 | + 'type' => 'object', |
|
564 | + 'properties' => $image_object_properties, |
|
565 | + 'additionalProperties' => false, |
|
566 | + ), |
|
567 | + 'image_large' => array( |
|
568 | + 'description' => esc_html__( |
|
569 | + 'The large image data.', |
|
570 | + 'event_espresso' |
|
571 | + ), |
|
572 | + 'type' => 'object', |
|
573 | + 'properties' => $image_object_properties, |
|
574 | + 'additionalProperties' => false, |
|
575 | + ), |
|
576 | + 'image_post_thumbnail' => array( |
|
577 | + 'description' => esc_html__( |
|
578 | + 'The post-thumbnail image data.', |
|
579 | + 'event_espresso' |
|
580 | + ), |
|
581 | + 'type' => 'object', |
|
582 | + 'properties' => $image_object_properties, |
|
583 | + 'additionalProperties' => false, |
|
584 | + ), |
|
585 | + 'image_full' => array( |
|
586 | + 'description' => esc_html__( |
|
587 | + 'The full size image data', |
|
588 | + 'event_espresso' |
|
589 | + ), |
|
590 | + 'type' => 'object', |
|
591 | + 'properties' => $image_object_properties, |
|
592 | + 'additionalProperties' => false, |
|
593 | + ), |
|
594 | + ); |
|
595 | + } |
|
596 | 596 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function spotsTaken($wpdb_row, $request, $controller) |
177 | 177 | { |
178 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
178 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
179 | 179 | throw new EE_Error( |
180 | 180 | sprintf( |
181 | 181 | esc_html__( |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
219 | 219 | { |
220 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
220 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
221 | 221 | throw new EE_Error( |
222 | 222 | sprintf( |
223 | 223 | esc_html__( |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
262 | 262 | { |
263 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
263 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
264 | 264 | throw new EE_Error( |
265 | 265 | sprintf( |
266 | 266 | esc_html__( |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | */ |
295 | 295 | public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
296 | 296 | { |
297 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
297 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
298 | 298 | throw new EE_Error( |
299 | 299 | sprintf( |
300 | 300 | esc_html__( |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | */ |
414 | 414 | protected function calculateImageData($wpdb_row, $image_size) |
415 | 415 | { |
416 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
416 | + if ( ! Event::wpdbRowHasEventId($wpdb_row)) { |
|
417 | 417 | throw new EE_Error( |
418 | 418 | sprintf( |
419 | 419 | esc_html__( |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $EVT_ID = $wpdb_row['Event_CPT.ID']; |
430 | 430 | $attachment_id = get_post_thumbnail_id($EVT_ID); |
431 | 431 | $data = wp_get_attachment_image_src($attachment_id, $image_size); |
432 | - if (! $data) { |
|
432 | + if ( ! $data) { |
|
433 | 433 | return null; |
434 | 434 | } |
435 | 435 | $generated = true; |
@@ -15,88 +15,88 @@ |
||
15 | 15 | * ------------------------------------------------------------------------ |
16 | 16 | */ |
17 | 17 | /** |
18 | - * |
|
19 | - * Class EE_Receipt_Line_Item_Display_Strategy |
|
20 | - * |
|
21 | - * Description |
|
22 | - * |
|
23 | - * @package Event Espresso |
|
24 | - * @subpackage core |
|
25 | - * @author Brent Christensen |
|
26 | - * |
|
27 | - * |
|
28 | - */ |
|
18 | + * |
|
19 | + * Class EE_Receipt_Line_Item_Display_Strategy |
|
20 | + * |
|
21 | + * Description |
|
22 | + * |
|
23 | + * @package Event Espresso |
|
24 | + * @subpackage core |
|
25 | + * @author Brent Christensen |
|
26 | + * |
|
27 | + * |
|
28 | + */ |
|
29 | 29 | |
30 | 30 | class EE_Receipt_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * @param EE_Line_Item $line_item |
|
35 | - * @param array $options |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
39 | - { |
|
33 | + /** |
|
34 | + * @param EE_Line_Item $line_item |
|
35 | + * @param array $options |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
39 | + { |
|
40 | 40 | |
41 | - $html = ''; |
|
42 | - // set some default options and merge with incoming |
|
43 | - $default_options = array( |
|
44 | - 'show_desc' => true, |
|
45 | - 'odd' => false |
|
46 | - ); |
|
47 | - $options = array_merge($default_options, (array) $options); |
|
48 | - switch ($line_item->type()) { |
|
49 | - case EEM_Line_Item::type_total: |
|
50 | - // loop thru children |
|
51 | - foreach ($line_item->children() as $child_line_item) { |
|
52 | - // recursively feed children back into this method |
|
41 | + $html = ''; |
|
42 | + // set some default options and merge with incoming |
|
43 | + $default_options = array( |
|
44 | + 'show_desc' => true, |
|
45 | + 'odd' => false |
|
46 | + ); |
|
47 | + $options = array_merge($default_options, (array) $options); |
|
48 | + switch ($line_item->type()) { |
|
49 | + case EEM_Line_Item::type_total: |
|
50 | + // loop thru children |
|
51 | + foreach ($line_item->children() as $child_line_item) { |
|
52 | + // recursively feed children back into this method |
|
53 | 53 | // $html .= $this->display_line_item( $child_line_item, $options ); |
54 | - } |
|
54 | + } |
|
55 | 55 | // $html .= $this->_separator_row( $options ); |
56 | 56 | // $html .= $this->_total_row( $line_item, esc_html__('Total', 'event_espresso'), $options ); |
57 | - break; |
|
57 | + break; |
|
58 | 58 | |
59 | 59 | |
60 | - case EEM_Line_Item::type_sub_total: |
|
61 | - // loop thru children |
|
62 | - foreach ($line_item->children() as $child_line_item) { |
|
63 | - // recursively feed children back into this method |
|
60 | + case EEM_Line_Item::type_sub_total: |
|
61 | + // loop thru children |
|
62 | + foreach ($line_item->children() as $child_line_item) { |
|
63 | + // recursively feed children back into this method |
|
64 | 64 | // $html .= $this->display_line_item( $child_line_item, $options ); |
65 | - } |
|
65 | + } |
|
66 | 66 | // $html .= $this->_total_row( $line_item, esc_html__('Sub-Total', 'event_espresso'), $options ); |
67 | - break; |
|
67 | + break; |
|
68 | 68 | |
69 | 69 | |
70 | - case EEM_Line_Item::type_tax_sub_total: |
|
71 | - // loop thru children |
|
72 | - foreach ($line_item->children() as $child_line_item) { |
|
73 | - // recursively feed children back into this method |
|
70 | + case EEM_Line_Item::type_tax_sub_total: |
|
71 | + // loop thru children |
|
72 | + foreach ($line_item->children() as $child_line_item) { |
|
73 | + // recursively feed children back into this method |
|
74 | 74 | // $html .= $this->display_line_item( $child_line_item, $options ); |
75 | - } |
|
75 | + } |
|
76 | 76 | // $html .= $this->_total_row( $line_item, esc_html__('Tax Total', 'event_espresso'), $options ); |
77 | - break; |
|
77 | + break; |
|
78 | 78 | |
79 | 79 | |
80 | - case EEM_Line_Item::type_line_item: |
|
81 | - // item row |
|
80 | + case EEM_Line_Item::type_line_item: |
|
81 | + // item row |
|
82 | 82 | // $html .= $this->_item_row( $line_item, $options ); |
83 | - // got any kids? |
|
84 | - foreach ($line_item->children() as $child_line_item) { |
|
83 | + // got any kids? |
|
84 | + foreach ($line_item->children() as $child_line_item) { |
|
85 | 85 | // $this->display_line_item( $child_line_item, $options ); |
86 | - } |
|
87 | - break; |
|
86 | + } |
|
87 | + break; |
|
88 | 88 | |
89 | 89 | |
90 | - case EEM_Line_Item::type_sub_line_item: |
|
90 | + case EEM_Line_Item::type_sub_line_item: |
|
91 | 91 | // $html .= $this->_sub_item_row( $line_item, $options ); |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | 94 | |
95 | - case EEM_Line_Item::type_tax: |
|
95 | + case EEM_Line_Item::type_tax: |
|
96 | 96 | // $html .= $this->_tax_row( $line_item, $options ); |
97 | - break; |
|
98 | - } |
|
97 | + break; |
|
98 | + } |
|
99 | 99 | |
100 | - return $html; |
|
101 | - } |
|
100 | + return $html; |
|
101 | + } |
|
102 | 102 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $html .= $this->_taxes_html; |
119 | 119 | $html .= $this->_total_row($line_item, $options); |
120 | 120 | if ($options['use_table_wrapper']) { |
121 | - $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
121 | + $html = $this->_table_header($options).$html.$this->_table_footer($options); |
|
122 | 122 | } |
123 | 123 | break; |
124 | 124 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function _table_footer($options) |
159 | 159 | { |
160 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
160 | + return EEH_HTML::tbodyx().EEH_HTML::tablex(); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | |
189 | 189 | |
190 | 190 | $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
191 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
191 | + $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>' : $name_html; |
|
192 | 192 | $name_html .= $line_item->is_taxable() ? ' *' : ''; |
193 | 193 | // maybe preface with icon? |
194 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
195 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
196 | - $name_html .= sprintf( |
|
194 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon().$name_html : $name_html; |
|
195 | + $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>'; |
|
196 | + $name_html .= sprintf( |
|
197 | 197 | _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
198 | 198 | '<span class="ee-line-item-related-parent-object">', |
199 | 199 | $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : esc_html__('Item:', 'event_espresso'), |
200 | - $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
200 | + $parent_related_object_link ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>' : $parent_related_object_name, |
|
201 | 201 | '</span>' |
202 | 202 | ); |
203 | 203 | |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | $type_html .= $this->_get_cancellations($line_item); |
215 | 215 | $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
216 | 216 | $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
217 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
217 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(esc_html__('Code: %s', 'event_espresso'), $code).'</span>' : ''; |
|
218 | 218 | $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
219 | 219 | |
220 | 220 | |
221 | 221 | // Amount Column |
222 | 222 | if ($line_item->is_percent()) { |
223 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
223 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght'); |
|
224 | 224 | } else { |
225 | 225 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
226 | 226 | } |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | // start of row |
296 | 296 | $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
297 | 297 | // name th |
298 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
298 | + $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="4"'); |
|
299 | 299 | // total th |
300 | 300 | $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
301 | 301 | // end of row |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | // start of row |
335 | 335 | $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
336 | 336 | // Total th label |
337 | - $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
337 | + $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')'); |
|
338 | 338 | $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
339 | 339 | // total th |
340 | 340 |
@@ -13,332 +13,332 @@ |
||
13 | 13 | |
14 | 14 | class EE_Admin_Table_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
15 | 15 | { |
16 | - /** |
|
17 | - * whether to display the taxes row or not |
|
18 | - * @type bool $_show_taxes |
|
19 | - */ |
|
20 | - protected $_show_taxes = false; |
|
21 | - |
|
22 | - /** |
|
23 | - * html for any tax rows |
|
24 | - * @type string $_show_taxes |
|
25 | - */ |
|
26 | - protected $_taxes_html = ''; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * total amount including tax we can bill for at this time |
|
31 | - * @type float $_grand_total |
|
32 | - */ |
|
33 | - protected $_grand_total = 0.00; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return float |
|
39 | - */ |
|
40 | - public function grand_total() |
|
41 | - { |
|
42 | - return $this->_grand_total; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This is used to output a single |
|
49 | - * @param EE_Line_Item $line_item |
|
50 | - * @param array $options |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
54 | - { |
|
55 | - |
|
56 | - $html = ''; |
|
57 | - // set some default options and merge with incoming |
|
58 | - $default_options = array( |
|
59 | - 'odd' => true, |
|
60 | - 'use_table_wrapper' => true, |
|
61 | - 'table_css_class' => 'admin-primary-mbox-tbl', |
|
62 | - 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', |
|
63 | - 'total_tr_css_class' => 'admin-primary-mbox-total-tr' |
|
64 | - ); |
|
65 | - $options = array_merge($default_options, (array) $options); |
|
66 | - |
|
67 | - switch ($line_item->type()) { |
|
68 | - case EEM_Line_Item::type_line_item: |
|
69 | - // item row |
|
70 | - $html .= $this->_item_row($line_item, $options); |
|
71 | - break; |
|
72 | - |
|
73 | - case EEM_Line_Item::type_sub_line_item: |
|
74 | - $html .= $this->_sub_item_row($line_item, $options); |
|
75 | - break; |
|
76 | - |
|
77 | - case EEM_Line_Item::type_sub_total: |
|
78 | - if ($line_item->quantity() === 0) { |
|
79 | - return $html; |
|
80 | - } |
|
81 | - // loop through children |
|
82 | - $child_line_items = $line_item->children(); |
|
83 | - // loop through children |
|
84 | - foreach ($child_line_items as $child_line_item) { |
|
85 | - // recursively feed children back into this method |
|
86 | - $html .= $this->display_line_item($child_line_item, $options); |
|
87 | - } |
|
88 | - $html .= $this->_sub_total_row($line_item, $options); |
|
89 | - break; |
|
90 | - |
|
91 | - case EEM_Line_Item::type_tax: |
|
92 | - if ($this->_show_taxes) { |
|
93 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
94 | - } |
|
95 | - break; |
|
96 | - |
|
97 | - case EEM_Line_Item::type_tax_sub_total: |
|
98 | - foreach ($line_item->children() as $child_line_item) { |
|
99 | - if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
100 | - $this->display_line_item($child_line_item, $options); |
|
101 | - } |
|
102 | - } |
|
103 | - break; |
|
104 | - |
|
105 | - case EEM_Line_Item::type_total: |
|
106 | - // determine whether to display taxes or not |
|
107 | - $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; |
|
108 | - // get all child line items |
|
109 | - $children = $line_item->children(); |
|
110 | - |
|
111 | - // loop thru all non-tax child line items |
|
112 | - foreach ($children as $child_line_item) { |
|
113 | - $html .= $this->display_line_item($child_line_item, $options); |
|
114 | - } |
|
115 | - |
|
116 | - $html .= $this->_taxes_html; |
|
117 | - $html .= $this->_total_row($line_item, $options); |
|
118 | - if ($options['use_table_wrapper']) { |
|
119 | - $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
120 | - } |
|
121 | - break; |
|
122 | - } |
|
123 | - |
|
124 | - return $html; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Table header for display. |
|
131 | - * @since 4.8 |
|
132 | - * @param array $options |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - protected function _table_header($options) |
|
136 | - { |
|
137 | - $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
138 | - $html .= EEH_HTML::thead(); |
|
139 | - $html .= EEH_HTML::tr(); |
|
140 | - $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left'); |
|
141 | - $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left'); |
|
142 | - $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
143 | - $html .= EEH_HTML::th(esc_html__('Qty', 'event_espresso'), '', 'jst-cntr'); |
|
144 | - $html .= EEH_HTML::th(esc_html__('Line Total', 'event_espresso'), '', 'jst-cntr'); |
|
145 | - $html .= EEH_HTML::tbody(); |
|
146 | - return $html; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Table footer for display |
|
152 | - * @since 4.8 |
|
153 | - * @param array $options array of options for the table. |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - protected function _table_footer($options) |
|
157 | - { |
|
158 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * _item_row |
|
165 | - * |
|
166 | - * @param EE_Line_Item $line_item |
|
167 | - * @param array $options |
|
168 | - * @return mixed |
|
169 | - */ |
|
170 | - protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
171 | - { |
|
172 | - $line_item_related_object = $line_item->get_object(); |
|
173 | - $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null; |
|
174 | - // start of row |
|
175 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
176 | - $html = EEH_HTML::tr('', '', $row_class); |
|
177 | - |
|
178 | - |
|
179 | - // Name Column |
|
180 | - $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
181 | - |
|
182 | - // related object scope. |
|
183 | - $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : ''; |
|
184 | - $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name; |
|
185 | - $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : ''; |
|
186 | - |
|
187 | - |
|
188 | - $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
|
189 | - $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
190 | - $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
191 | - // maybe preface with icon? |
|
192 | - $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
193 | - $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
194 | - $name_html .= sprintf( |
|
195 | - _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
196 | - '<span class="ee-line-item-related-parent-object">', |
|
197 | - $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : esc_html__('Item:', 'event_espresso'), |
|
198 | - $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
199 | - '</span>' |
|
200 | - ); |
|
201 | - |
|
202 | - $name_html = apply_filters( |
|
203 | - 'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html', |
|
204 | - $name_html, |
|
205 | - $line_item, |
|
206 | - $options |
|
207 | - ); |
|
208 | - |
|
209 | - $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
210 | - // Type Column |
|
211 | - $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
212 | - $type_html .= $this->_get_cancellations($line_item); |
|
213 | - $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
214 | - $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
215 | - $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
216 | - $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
217 | - |
|
218 | - |
|
219 | - // Amount Column |
|
220 | - if ($line_item->is_percent()) { |
|
221 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
222 | - } else { |
|
223 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
224 | - } |
|
225 | - |
|
226 | - // QTY column |
|
227 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght'); |
|
228 | - |
|
229 | - // total column |
|
230 | - $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
231 | - |
|
232 | - // finish things off and return |
|
233 | - $html .= EEH_HTML::trx(); |
|
234 | - return $html; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * _get_cancellations |
|
241 | - * |
|
242 | - * @param EE_Line_Item $line_item |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function _get_cancellations(EE_Line_Item $line_item) |
|
246 | - { |
|
247 | - $html = ''; |
|
248 | - $cancellations = $line_item->get_cancellations(); |
|
249 | - $cancellation = reset($cancellations); |
|
250 | - // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ ); |
|
251 | - if ($cancellation instanceof EE_Line_Item) { |
|
252 | - $html .= ' <span class="ee-line-item-id">'; |
|
253 | - $html .= sprintf( |
|
254 | - _n( |
|
255 | - '(%1$s Cancellation)', |
|
256 | - '(%1$s Cancellations)', |
|
257 | - $cancellation->quantity(), |
|
258 | - 'event_espresso' |
|
259 | - ), |
|
260 | - $cancellation->quantity() |
|
261 | - ); |
|
262 | - $html .= '</span>'; |
|
263 | - } |
|
264 | - return $html; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * _sub_item_row |
|
271 | - * |
|
272 | - * @param EE_Line_Item $line_item |
|
273 | - * @param array $options |
|
274 | - * @return mixed |
|
275 | - */ |
|
276 | - protected function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
277 | - { |
|
278 | - // for now we're not showing sub-items |
|
279 | - return ''; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * _tax_row |
|
286 | - * |
|
287 | - * @param EE_Line_Item $line_item |
|
288 | - * @param array $options |
|
289 | - * @return mixed |
|
290 | - */ |
|
291 | - protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
292 | - { |
|
293 | - // start of row |
|
294 | - $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
295 | - // name th |
|
296 | - $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
297 | - // total th |
|
298 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
299 | - // end of row |
|
300 | - $html .= EEH_HTML::trx(); |
|
301 | - return $html; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * _total_row |
|
309 | - * |
|
310 | - * @param EE_Line_Item $line_item |
|
311 | - * @param string $text |
|
312 | - * @param array $options |
|
313 | - * @return mixed |
|
314 | - */ |
|
315 | - protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
316 | - { |
|
317 | - // currently not showing subtotal row |
|
318 | - return ''; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * _total_row |
|
325 | - * |
|
326 | - * @param EE_Line_Item $line_item |
|
327 | - * @param array $options |
|
328 | - * @return mixed |
|
329 | - */ |
|
330 | - protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
331 | - { |
|
332 | - // start of row |
|
333 | - $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
334 | - // Total th label |
|
335 | - $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
336 | - $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
|
337 | - // total th |
|
338 | - |
|
339 | - $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
340 | - // end of row |
|
341 | - $html .= EEH_HTML::trx(); |
|
342 | - return $html; |
|
343 | - } |
|
16 | + /** |
|
17 | + * whether to display the taxes row or not |
|
18 | + * @type bool $_show_taxes |
|
19 | + */ |
|
20 | + protected $_show_taxes = false; |
|
21 | + |
|
22 | + /** |
|
23 | + * html for any tax rows |
|
24 | + * @type string $_show_taxes |
|
25 | + */ |
|
26 | + protected $_taxes_html = ''; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * total amount including tax we can bill for at this time |
|
31 | + * @type float $_grand_total |
|
32 | + */ |
|
33 | + protected $_grand_total = 0.00; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return float |
|
39 | + */ |
|
40 | + public function grand_total() |
|
41 | + { |
|
42 | + return $this->_grand_total; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This is used to output a single |
|
49 | + * @param EE_Line_Item $line_item |
|
50 | + * @param array $options |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
54 | + { |
|
55 | + |
|
56 | + $html = ''; |
|
57 | + // set some default options and merge with incoming |
|
58 | + $default_options = array( |
|
59 | + 'odd' => true, |
|
60 | + 'use_table_wrapper' => true, |
|
61 | + 'table_css_class' => 'admin-primary-mbox-tbl', |
|
62 | + 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', |
|
63 | + 'total_tr_css_class' => 'admin-primary-mbox-total-tr' |
|
64 | + ); |
|
65 | + $options = array_merge($default_options, (array) $options); |
|
66 | + |
|
67 | + switch ($line_item->type()) { |
|
68 | + case EEM_Line_Item::type_line_item: |
|
69 | + // item row |
|
70 | + $html .= $this->_item_row($line_item, $options); |
|
71 | + break; |
|
72 | + |
|
73 | + case EEM_Line_Item::type_sub_line_item: |
|
74 | + $html .= $this->_sub_item_row($line_item, $options); |
|
75 | + break; |
|
76 | + |
|
77 | + case EEM_Line_Item::type_sub_total: |
|
78 | + if ($line_item->quantity() === 0) { |
|
79 | + return $html; |
|
80 | + } |
|
81 | + // loop through children |
|
82 | + $child_line_items = $line_item->children(); |
|
83 | + // loop through children |
|
84 | + foreach ($child_line_items as $child_line_item) { |
|
85 | + // recursively feed children back into this method |
|
86 | + $html .= $this->display_line_item($child_line_item, $options); |
|
87 | + } |
|
88 | + $html .= $this->_sub_total_row($line_item, $options); |
|
89 | + break; |
|
90 | + |
|
91 | + case EEM_Line_Item::type_tax: |
|
92 | + if ($this->_show_taxes) { |
|
93 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
94 | + } |
|
95 | + break; |
|
96 | + |
|
97 | + case EEM_Line_Item::type_tax_sub_total: |
|
98 | + foreach ($line_item->children() as $child_line_item) { |
|
99 | + if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
100 | + $this->display_line_item($child_line_item, $options); |
|
101 | + } |
|
102 | + } |
|
103 | + break; |
|
104 | + |
|
105 | + case EEM_Line_Item::type_total: |
|
106 | + // determine whether to display taxes or not |
|
107 | + $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; |
|
108 | + // get all child line items |
|
109 | + $children = $line_item->children(); |
|
110 | + |
|
111 | + // loop thru all non-tax child line items |
|
112 | + foreach ($children as $child_line_item) { |
|
113 | + $html .= $this->display_line_item($child_line_item, $options); |
|
114 | + } |
|
115 | + |
|
116 | + $html .= $this->_taxes_html; |
|
117 | + $html .= $this->_total_row($line_item, $options); |
|
118 | + if ($options['use_table_wrapper']) { |
|
119 | + $html = $this->_table_header($options) . $html . $this->_table_footer($options); |
|
120 | + } |
|
121 | + break; |
|
122 | + } |
|
123 | + |
|
124 | + return $html; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Table header for display. |
|
131 | + * @since 4.8 |
|
132 | + * @param array $options |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + protected function _table_header($options) |
|
136 | + { |
|
137 | + $html = EEH_HTML::table('', '', $options['table_css_class']); |
|
138 | + $html .= EEH_HTML::thead(); |
|
139 | + $html .= EEH_HTML::tr(); |
|
140 | + $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left'); |
|
141 | + $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left'); |
|
142 | + $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr'); |
|
143 | + $html .= EEH_HTML::th(esc_html__('Qty', 'event_espresso'), '', 'jst-cntr'); |
|
144 | + $html .= EEH_HTML::th(esc_html__('Line Total', 'event_espresso'), '', 'jst-cntr'); |
|
145 | + $html .= EEH_HTML::tbody(); |
|
146 | + return $html; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Table footer for display |
|
152 | + * @since 4.8 |
|
153 | + * @param array $options array of options for the table. |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + protected function _table_footer($options) |
|
157 | + { |
|
158 | + return EEH_HTML::tbodyx() . EEH_HTML::tablex(); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * _item_row |
|
165 | + * |
|
166 | + * @param EE_Line_Item $line_item |
|
167 | + * @param array $options |
|
168 | + * @return mixed |
|
169 | + */ |
|
170 | + protected function _item_row(EE_Line_Item $line_item, $options = array()) |
|
171 | + { |
|
172 | + $line_item_related_object = $line_item->get_object(); |
|
173 | + $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null; |
|
174 | + // start of row |
|
175 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
176 | + $html = EEH_HTML::tr('', '', $row_class); |
|
177 | + |
|
178 | + |
|
179 | + // Name Column |
|
180 | + $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : ''; |
|
181 | + |
|
182 | + // related object scope. |
|
183 | + $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : ''; |
|
184 | + $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name; |
|
185 | + $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : ''; |
|
186 | + |
|
187 | + |
|
188 | + $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name(); |
|
189 | + $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html; |
|
190 | + $name_html .= $line_item->is_taxable() ? ' *' : ''; |
|
191 | + // maybe preface with icon? |
|
192 | + $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html; |
|
193 | + $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>'; |
|
194 | + $name_html .= sprintf( |
|
195 | + _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), |
|
196 | + '<span class="ee-line-item-related-parent-object">', |
|
197 | + $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : esc_html__('Item:', 'event_espresso'), |
|
198 | + $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, |
|
199 | + '</span>' |
|
200 | + ); |
|
201 | + |
|
202 | + $name_html = apply_filters( |
|
203 | + 'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html', |
|
204 | + $name_html, |
|
205 | + $line_item, |
|
206 | + $options |
|
207 | + ); |
|
208 | + |
|
209 | + $html .= EEH_HTML::td($name_html, '', 'jst-left'); |
|
210 | + // Type Column |
|
211 | + $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : ''; |
|
212 | + $type_html .= $this->_get_cancellations($line_item); |
|
213 | + $type_html .= $line_item->OBJ_type() ? '<br />' : ''; |
|
214 | + $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : ''; |
|
215 | + $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : ''; |
|
216 | + $html .= EEH_HTML::td($type_html, '', 'jst-left'); |
|
217 | + |
|
218 | + |
|
219 | + // Amount Column |
|
220 | + if ($line_item->is_percent()) { |
|
221 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght'); |
|
222 | + } else { |
|
223 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght'); |
|
224 | + } |
|
225 | + |
|
226 | + // QTY column |
|
227 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght'); |
|
228 | + |
|
229 | + // total column |
|
230 | + $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
231 | + |
|
232 | + // finish things off and return |
|
233 | + $html .= EEH_HTML::trx(); |
|
234 | + return $html; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * _get_cancellations |
|
241 | + * |
|
242 | + * @param EE_Line_Item $line_item |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function _get_cancellations(EE_Line_Item $line_item) |
|
246 | + { |
|
247 | + $html = ''; |
|
248 | + $cancellations = $line_item->get_cancellations(); |
|
249 | + $cancellation = reset($cancellations); |
|
250 | + // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ ); |
|
251 | + if ($cancellation instanceof EE_Line_Item) { |
|
252 | + $html .= ' <span class="ee-line-item-id">'; |
|
253 | + $html .= sprintf( |
|
254 | + _n( |
|
255 | + '(%1$s Cancellation)', |
|
256 | + '(%1$s Cancellations)', |
|
257 | + $cancellation->quantity(), |
|
258 | + 'event_espresso' |
|
259 | + ), |
|
260 | + $cancellation->quantity() |
|
261 | + ); |
|
262 | + $html .= '</span>'; |
|
263 | + } |
|
264 | + return $html; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * _sub_item_row |
|
271 | + * |
|
272 | + * @param EE_Line_Item $line_item |
|
273 | + * @param array $options |
|
274 | + * @return mixed |
|
275 | + */ |
|
276 | + protected function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
277 | + { |
|
278 | + // for now we're not showing sub-items |
|
279 | + return ''; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * _tax_row |
|
286 | + * |
|
287 | + * @param EE_Line_Item $line_item |
|
288 | + * @param array $options |
|
289 | + * @return mixed |
|
290 | + */ |
|
291 | + protected function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
292 | + { |
|
293 | + // start of row |
|
294 | + $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr'); |
|
295 | + // name th |
|
296 | + $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"'); |
|
297 | + // total th |
|
298 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
299 | + // end of row |
|
300 | + $html .= EEH_HTML::trx(); |
|
301 | + return $html; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * _total_row |
|
309 | + * |
|
310 | + * @param EE_Line_Item $line_item |
|
311 | + * @param string $text |
|
312 | + * @param array $options |
|
313 | + * @return mixed |
|
314 | + */ |
|
315 | + protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
316 | + { |
|
317 | + // currently not showing subtotal row |
|
318 | + return ''; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * _total_row |
|
325 | + * |
|
326 | + * @param EE_Line_Item $line_item |
|
327 | + * @param array $options |
|
328 | + * @return mixed |
|
329 | + */ |
|
330 | + protected function _total_row(EE_Line_Item $line_item, $options = array()) |
|
331 | + { |
|
332 | + // start of row |
|
333 | + $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr'); |
|
334 | + // Total th label |
|
335 | + $total_label = sprintf(esc_html__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')'); |
|
336 | + $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"'); |
|
337 | + // total th |
|
338 | + |
|
339 | + $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght'); |
|
340 | + // end of row |
|
341 | + $html .= EEH_HTML::trx(); |
|
342 | + return $html; |
|
343 | + } |
|
344 | 344 | } |