@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $tax = 0; |
41 | 41 | $total_tax = 0; |
42 | 42 | // This first checks to see if the given ticket is taxable. |
43 | - if (! $ticket->get('TKT_taxable')) { |
|
43 | + if ( ! $ticket->get('TKT_taxable')) { |
|
44 | 44 | return $tax; |
45 | 45 | } |
46 | 46 | // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | public static function get_subtotal_for_admin(EE_Ticket $ticket) |
85 | 85 | { |
86 | 86 | $TKT_ID = $ticket->ID(); |
87 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
88 | - ? self::$_subtotal[ $TKT_ID ] |
|
87 | + return isset(self::$_subtotal[$TKT_ID]) |
|
88 | + ? self::$_subtotal[$TKT_ID] |
|
89 | 89 | : self::_get_subtotal_for_admin($ticket); |
90 | 90 | } |
91 | 91 |
@@ -9,145 +9,145 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Taxes extends EE_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * This is used for when EE_Taxes is used statically by the admin |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - private static $_subtotal = []; |
|
12 | + /** |
|
13 | + * This is used for when EE_Taxes is used statically by the admin |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + private static $_subtotal = []; |
|
18 | 18 | |
19 | - /** |
|
20 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
21 | - * |
|
22 | - * @var EE_Price[] |
|
23 | - */ |
|
24 | - private static $_default_taxes = []; |
|
19 | + /** |
|
20 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
21 | + * |
|
22 | + * @var EE_Price[] |
|
23 | + */ |
|
24 | + private static $_default_taxes = []; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
29 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
30 | - * calc of taxes for tickets listed in the event editor. |
|
31 | - * |
|
32 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
33 | - * @return float total taxes to apply to ticket. |
|
34 | - * @throws EE_Error |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | - { |
|
39 | - $tax = 0; |
|
40 | - $total_tax = 0; |
|
41 | - // This first checks to see if the given ticket is taxable. |
|
42 | - if (! $ticket->get('TKT_taxable')) { |
|
43 | - return $tax; |
|
44 | - } |
|
45 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | - $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | - // get taxes |
|
48 | - $taxes = self::get_taxes_for_admin(); |
|
49 | - // apply taxes to subtotal |
|
50 | - foreach ($taxes as $tax) { |
|
51 | - // assuming taxes are not cumulative |
|
52 | - $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | - } |
|
54 | - return $total_tax; |
|
55 | - } |
|
27 | + /** |
|
28 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
29 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
30 | + * calc of taxes for tickets listed in the event editor. |
|
31 | + * |
|
32 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
33 | + * @return float total taxes to apply to ticket. |
|
34 | + * @throws EE_Error |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | + { |
|
39 | + $tax = 0; |
|
40 | + $total_tax = 0; |
|
41 | + // This first checks to see if the given ticket is taxable. |
|
42 | + if (! $ticket->get('TKT_taxable')) { |
|
43 | + return $tax; |
|
44 | + } |
|
45 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | + $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | + // get taxes |
|
48 | + $taxes = self::get_taxes_for_admin(); |
|
49 | + // apply taxes to subtotal |
|
50 | + foreach ($taxes as $tax) { |
|
51 | + // assuming taxes are not cumulative |
|
52 | + $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | + } |
|
54 | + return $total_tax; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | - * |
|
61 | - * @return float the percentage of tax that should be added to taxable items |
|
62 | - * @throws EE_Error eg 20 for %20 tax (NOT 0.20, which |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public static function get_total_taxes_percentage() |
|
66 | - { |
|
67 | - $total_tax_percent = 0; |
|
68 | - foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | - if ($tax_price instanceof EE_Price) { |
|
70 | - $total_tax_percent += $tax_price->amount(); |
|
71 | - } |
|
72 | - } |
|
73 | - return $total_tax_percent; |
|
74 | - } |
|
58 | + /** |
|
59 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | + * |
|
61 | + * @return float the percentage of tax that should be added to taxable items |
|
62 | + * @throws EE_Error eg 20 for %20 tax (NOT 0.20, which |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public static function get_total_taxes_percentage() |
|
66 | + { |
|
67 | + $total_tax_percent = 0; |
|
68 | + foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | + if ($tax_price instanceof EE_Price) { |
|
70 | + $total_tax_percent += $tax_price->amount(); |
|
71 | + } |
|
72 | + } |
|
73 | + return $total_tax_percent; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @param EE_Ticket $ticket |
|
79 | - * @return float |
|
80 | - * @throws EE_Error |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
84 | - { |
|
85 | - $TKT_ID = $ticket->ID(); |
|
86 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
87 | - ? self::$_subtotal[ $TKT_ID ] |
|
88 | - : self::_get_subtotal_for_admin($ticket); |
|
89 | - } |
|
77 | + /** |
|
78 | + * @param EE_Ticket $ticket |
|
79 | + * @return float |
|
80 | + * @throws EE_Error |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
84 | + { |
|
85 | + $TKT_ID = $ticket->ID(); |
|
86 | + return isset(self::$_subtotal[ $TKT_ID ]) |
|
87 | + ? self::$_subtotal[ $TKT_ID ] |
|
88 | + : self::_get_subtotal_for_admin($ticket); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
94 | - * |
|
95 | - * @param EE_Ticket $ticket |
|
96 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
97 | - * @throws EE_Error |
|
98 | - * @throws ReflectionException |
|
99 | - */ |
|
100 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
101 | - { |
|
102 | - $subtotal = 0; |
|
103 | - // get all prices |
|
104 | - $prices = $ticket->get_many_related( |
|
105 | - 'Price', |
|
106 | - [ |
|
107 | - 'default_where_conditions' => 'none', |
|
108 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
109 | - ] |
|
110 | - ); |
|
111 | - // let's loop through them (base price is always the first item) |
|
112 | - foreach ($prices as $price) { |
|
113 | - if ($price instanceof EE_Price) { |
|
114 | - $price_type = $price->type_obj(); |
|
115 | - if ($price_type instanceof EE_Price_Type) { |
|
116 | - switch ($price->type_obj()->base_type()) { |
|
117 | - case 1: // base price |
|
118 | - case 3: // surcharges |
|
119 | - $subtotal += $price->is_percent() |
|
120 | - ? $subtotal * $price->amount() / 100 |
|
121 | - : $price->amount(); |
|
122 | - break; |
|
123 | - case 2: // discounts |
|
124 | - $subtotal -= $price->is_percent() |
|
125 | - ? $subtotal * $price->amount() / 100 |
|
126 | - : $price->amount(); |
|
127 | - break; |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - $TKT_ID = $ticket->ID(); |
|
133 | - self::$_subtotal = [$TKT_ID => $subtotal]; |
|
134 | - return $subtotal; |
|
135 | - } |
|
92 | + /** |
|
93 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
94 | + * |
|
95 | + * @param EE_Ticket $ticket |
|
96 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
97 | + * @throws EE_Error |
|
98 | + * @throws ReflectionException |
|
99 | + */ |
|
100 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
101 | + { |
|
102 | + $subtotal = 0; |
|
103 | + // get all prices |
|
104 | + $prices = $ticket->get_many_related( |
|
105 | + 'Price', |
|
106 | + [ |
|
107 | + 'default_where_conditions' => 'none', |
|
108 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
109 | + ] |
|
110 | + ); |
|
111 | + // let's loop through them (base price is always the first item) |
|
112 | + foreach ($prices as $price) { |
|
113 | + if ($price instanceof EE_Price) { |
|
114 | + $price_type = $price->type_obj(); |
|
115 | + if ($price_type instanceof EE_Price_Type) { |
|
116 | + switch ($price->type_obj()->base_type()) { |
|
117 | + case 1: // base price |
|
118 | + case 3: // surcharges |
|
119 | + $subtotal += $price->is_percent() |
|
120 | + ? $subtotal * $price->amount() / 100 |
|
121 | + : $price->amount(); |
|
122 | + break; |
|
123 | + case 2: // discounts |
|
124 | + $subtotal -= $price->is_percent() |
|
125 | + ? $subtotal * $price->amount() / 100 |
|
126 | + : $price->amount(); |
|
127 | + break; |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + $TKT_ID = $ticket->ID(); |
|
133 | + self::$_subtotal = [$TKT_ID => $subtotal]; |
|
134 | + return $subtotal; |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | - /** |
|
139 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
140 | - * |
|
141 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
142 | - * @throws EE_Error |
|
143 | - */ |
|
144 | - public static function get_taxes_for_admin() |
|
145 | - { |
|
146 | - if (empty(self::$_default_taxes)) { |
|
147 | - self::$_default_taxes = EEM_Price::instance()->get_all( |
|
148 | - [['Price_Type.PBT_ID' => 4]] |
|
149 | - ); |
|
150 | - } |
|
151 | - return self::$_default_taxes; |
|
152 | - } |
|
138 | + /** |
|
139 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
140 | + * |
|
141 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
142 | + * @throws EE_Error |
|
143 | + */ |
|
144 | + public static function get_taxes_for_admin() |
|
145 | + { |
|
146 | + if (empty(self::$_default_taxes)) { |
|
147 | + self::$_default_taxes = EEM_Price::instance()->get_all( |
|
148 | + [['Price_Type.PBT_ID' => 4]] |
|
149 | + ); |
|
150 | + } |
|
151 | + return self::$_default_taxes; |
|
152 | + } |
|
153 | 153 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
32 | 32 | { |
33 | 33 | $payment = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
34 | - if (! $payment instanceof EE_Payment) { |
|
34 | + if ( ! $payment instanceof EE_Payment) { |
|
35 | 35 | $payment = new EE_Payment($props_n_values, false, $timezone, $date_formats); |
36 | 36 | } |
37 | 37 | return $payment; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | { |
67 | 67 | parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
68 | 68 | // in a better world this would have been injected upon construction |
69 | - if (! $this->currency_formatter instanceof CurrencyFormatter) { |
|
69 | + if ( ! $this->currency_formatter instanceof CurrencyFormatter) { |
|
70 | 70 | $this->currency_formatter = LoaderFactory::getLoader()->getShared(CurrencyFormatter::class); |
71 | 71 | } |
72 | 72 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | public function timestamp($date_format = '', $time_format = '') |
332 | 332 | { |
333 | - return $this->get_i18n_datetime('PAY_timestamp', trim($date_format . ' ' . $time_format)); |
|
333 | + return $this->get_i18n_datetime('PAY_timestamp', trim($date_format.' '.$time_format)); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | : ''; |
526 | 526 | break; |
527 | 527 | } |
528 | - return $icon . $status[ $this->STS_ID() ]; |
|
528 | + return $icon.$status[$this->STS_ID()]; |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | |
@@ -704,13 +704,13 @@ discard block |
||
704 | 704 | $get_params = null; |
705 | 705 | parse_str($querystring, $get_params); |
706 | 706 | $inside_form_html .= $this->_args_as_inputs($get_params); |
707 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
707 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
708 | 708 | } |
709 | 709 | $form = EEH_HTML::nl(1) |
710 | - . '<form method="' . $method . '" name="gateway_form" action="' . $redirect_url . '">'; |
|
711 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
710 | + . '<form method="'.$method.'" name="gateway_form" action="'.$redirect_url.'">'; |
|
711 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
712 | 712 | $form .= $inside_form_html; |
713 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
713 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
714 | 714 | return $form; |
715 | 715 | } |
716 | 716 | |
@@ -765,8 +765,8 @@ discard block |
||
765 | 765 | return $html; |
766 | 766 | } |
767 | 767 | return EEH_HTML::nl() |
768 | - . '<input type="hidden" name="' . $name . '"' |
|
769 | - . ' value="' . esc_attr($value) . '"/>'; |
|
768 | + . '<input type="hidden" name="'.$name.'"' |
|
769 | + . ' value="'.esc_attr($value).'"/>'; |
|
770 | 770 | } |
771 | 771 | |
772 | 772 |
@@ -13,922 +13,922 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
15 | 15 | { |
16 | - /** |
|
17 | - * @var CurrencyFormatter |
|
18 | - * @since $VID:$ |
|
19 | - */ |
|
20 | - protected $currency_formatter; |
|
21 | - |
|
22 | - /** |
|
23 | - * @param array $props_n_values incoming values |
|
24 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
25 | - * used.) |
|
26 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
27 | - * date_format and the second value is the time format |
|
28 | - * @return EE_Payment |
|
29 | - * @throws EE_Error|ReflectionException |
|
30 | - */ |
|
31 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
32 | - { |
|
33 | - $payment = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
34 | - if (! $payment instanceof EE_Payment) { |
|
35 | - $payment = new EE_Payment($props_n_values, false, $timezone, $date_formats); |
|
36 | - } |
|
37 | - return $payment; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @param array $props_n_values incoming values from the database |
|
43 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
44 | - * the website will be used. |
|
45 | - * @return EE_Payment |
|
46 | - * @throws EE_Error|ReflectionException |
|
47 | - */ |
|
48 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
49 | - { |
|
50 | - return new EE_Payment($props_n_values, true, $timezone); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Adds some defaults if they're not specified |
|
56 | - * |
|
57 | - * @param array $props_n_values |
|
58 | - * @param bool $bydb |
|
59 | - * @param string $timezone |
|
60 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
61 | - * date_format and the second value is the time format |
|
62 | - * @throws EE_Error |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - protected function __construct($props_n_values = [], $bydb = false, $timezone = '', $date_formats = []) |
|
66 | - { |
|
67 | - parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
|
68 | - // in a better world this would have been injected upon construction |
|
69 | - if (! $this->currency_formatter instanceof CurrencyFormatter) { |
|
70 | - $this->currency_formatter = LoaderFactory::getLoader()->getShared(CurrencyFormatter::class); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Set Transaction ID |
|
77 | - * |
|
78 | - * @access public |
|
79 | - * @param int $TXN_ID |
|
80 | - * @throws EE_Error|ReflectionException |
|
81 | - */ |
|
82 | - public function set_transaction_id($TXN_ID = 0) |
|
83 | - { |
|
84 | - $this->set('TXN_ID', $TXN_ID); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the transaction related to this payment |
|
90 | - * |
|
91 | - * @return EE_Base_Class|EE_Transaction |
|
92 | - * @throws EE_Error|ReflectionException |
|
93 | - */ |
|
94 | - public function transaction() |
|
95 | - { |
|
96 | - return $this->get_first_related('Transaction'); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Set Status |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @param string $STS_ID |
|
105 | - * @throws EE_Error|ReflectionException |
|
106 | - */ |
|
107 | - public function set_status($STS_ID = '') |
|
108 | - { |
|
109 | - $this->set('STS_ID', $STS_ID); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Set Payment Timestamp |
|
115 | - * |
|
116 | - * @access public |
|
117 | - * @param int $timestamp |
|
118 | - * @throws EE_Error|ReflectionException |
|
119 | - */ |
|
120 | - public function set_timestamp($timestamp = 0) |
|
121 | - { |
|
122 | - $this->set('PAY_timestamp', $timestamp); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Set Payment Method |
|
128 | - * |
|
129 | - * @access public |
|
130 | - * @param string $PAY_source |
|
131 | - * @throws EE_Error|ReflectionException |
|
132 | - */ |
|
133 | - public function set_source($PAY_source = '') |
|
134 | - { |
|
135 | - $this->set('PAY_source', $PAY_source); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Set Payment Amount |
|
141 | - * |
|
142 | - * @access public |
|
143 | - * @param float $amount |
|
144 | - * @throws EE_Error|ReflectionException |
|
145 | - */ |
|
146 | - public function set_amount($amount = 0.00) |
|
147 | - { |
|
148 | - $this->set('PAY_amount', $amount); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Set Payment Gateway Response |
|
154 | - * |
|
155 | - * @access public |
|
156 | - * @param string $gateway_response |
|
157 | - * @throws EE_Error|ReflectionException |
|
158 | - */ |
|
159 | - public function set_gateway_response($gateway_response = '') |
|
160 | - { |
|
161 | - $this->set('PAY_gateway_response', $gateway_response); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
167 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
168 | - * used on it |
|
169 | - * |
|
170 | - * @return string |
|
171 | - * @throws EE_Error|ReflectionException |
|
172 | - *@deprecated |
|
173 | - */ |
|
174 | - public function gateway() |
|
175 | - { |
|
176 | - EE_Error::doing_it_wrong( |
|
177 | - 'EE_Payment::gateway', |
|
178 | - esc_html__( |
|
179 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
180 | - 'event_espresso' |
|
181 | - ), |
|
182 | - '4.6.0' |
|
183 | - ); |
|
184 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Set Gateway Transaction ID |
|
190 | - * |
|
191 | - * @access public |
|
192 | - * @param string $txn_id_chq_nmbr |
|
193 | - * @throws EE_Error|ReflectionException |
|
194 | - */ |
|
195 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
196 | - { |
|
197 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Set Purchase Order Number |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @param string $po_number |
|
206 | - * @throws EE_Error|ReflectionException |
|
207 | - */ |
|
208 | - public function set_po_number($po_number = '') |
|
209 | - { |
|
210 | - $this->set('PAY_po_number', $po_number); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Set Extra Accounting Field |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @param string $extra_accntng |
|
219 | - * @throws EE_Error|ReflectionException |
|
220 | - */ |
|
221 | - public function set_extra_accntng($extra_accntng = '') |
|
222 | - { |
|
223 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * Set Payment made via admin flag |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @param bool $via_admin |
|
232 | - * @throws EE_Error|ReflectionException |
|
233 | - */ |
|
234 | - public function set_payment_made_via_admin($via_admin = false) |
|
235 | - { |
|
236 | - if ($via_admin) { |
|
237 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
238 | - } else { |
|
239 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * Set Payment Details |
|
246 | - * |
|
247 | - * @access public |
|
248 | - * @param string|array $details |
|
249 | - * @throws EE_Error|ReflectionException |
|
250 | - */ |
|
251 | - public function set_details($details = '') |
|
252 | - { |
|
253 | - if (is_array($details)) { |
|
254 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
255 | - } else { |
|
256 | - $details = wp_strip_all_tags($details); |
|
257 | - } |
|
258 | - $this->set('PAY_details', $details); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Sets redirect_url |
|
264 | - * |
|
265 | - * @param string $redirect_url |
|
266 | - * @throws EE_Error|ReflectionException |
|
267 | - */ |
|
268 | - public function set_redirect_url($redirect_url) |
|
269 | - { |
|
270 | - $this->set('PAY_redirect_url', $redirect_url); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Sets redirect_args |
|
276 | - * |
|
277 | - * @param array $redirect_args |
|
278 | - * @throws EE_Error|ReflectionException |
|
279 | - */ |
|
280 | - public function set_redirect_args($redirect_args) |
|
281 | - { |
|
282 | - $this->set('PAY_redirect_args', $redirect_args); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * get Payment Transaction ID |
|
288 | - * |
|
289 | - * @access public |
|
290 | - * @throws EE_Error|ReflectionException |
|
291 | - */ |
|
292 | - public function TXN_ID() |
|
293 | - { |
|
294 | - return $this->get('TXN_ID'); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * get Payment Status |
|
300 | - * |
|
301 | - * @access public |
|
302 | - * @throws EE_Error|ReflectionException |
|
303 | - */ |
|
304 | - public function status() |
|
305 | - { |
|
306 | - return $this->get('STS_ID'); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * get Payment Status |
|
312 | - * |
|
313 | - * @access public |
|
314 | - * @throws EE_Error|ReflectionException |
|
315 | - */ |
|
316 | - public function STS_ID() |
|
317 | - { |
|
318 | - return $this->get('STS_ID'); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * get Payment Timestamp |
|
324 | - * |
|
325 | - * @access public |
|
326 | - * @param string $date_format |
|
327 | - * @param string $time_format |
|
328 | - * @return string |
|
329 | - * @throws EE_Error|ReflectionException |
|
330 | - */ |
|
331 | - public function timestamp($date_format = '', $time_format = '') |
|
332 | - { |
|
333 | - return $this->get_i18n_datetime('PAY_timestamp', trim($date_format . ' ' . $time_format)); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * get Payment Source |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @throws EE_Error|ReflectionException |
|
342 | - */ |
|
343 | - public function source() |
|
344 | - { |
|
345 | - return $this->get('PAY_source'); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * get Payment Amount |
|
351 | - * |
|
352 | - * @access public |
|
353 | - * @return float |
|
354 | - * @throws EE_Error|ReflectionException |
|
355 | - */ |
|
356 | - public function amount() |
|
357 | - { |
|
358 | - return (float) $this->get('PAY_amount'); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @return mixed |
|
364 | - * @throws EE_Error|ReflectionException |
|
365 | - */ |
|
366 | - public function amount_no_code() |
|
367 | - { |
|
368 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @return mixed |
|
374 | - * @throws EE_Error|ReflectionException |
|
375 | - */ |
|
376 | - public function prettyAmount() |
|
377 | - { |
|
378 | - return $this->get_pretty('PAY_amount', 'localized_currency'); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * get Payment Gateway Response |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @throws EE_Error|ReflectionException |
|
387 | - */ |
|
388 | - public function gateway_response() |
|
389 | - { |
|
390 | - return $this->get('PAY_gateway_response'); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * get Payment Gateway Transaction ID |
|
396 | - * |
|
397 | - * @access public |
|
398 | - * @throws EE_Error|ReflectionException |
|
399 | - */ |
|
400 | - public function txn_id_chq_nmbr() |
|
401 | - { |
|
402 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * get Purchase Order Number |
|
408 | - * |
|
409 | - * @access public |
|
410 | - * @throws EE_Error|ReflectionException |
|
411 | - */ |
|
412 | - public function po_number() |
|
413 | - { |
|
414 | - return $this->get('PAY_po_number'); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * get Extra Accounting Field |
|
420 | - * |
|
421 | - * @access public |
|
422 | - * @throws EE_Error|ReflectionException |
|
423 | - */ |
|
424 | - public function extra_accntng() |
|
425 | - { |
|
426 | - return $this->get('PAY_extra_accntng'); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * get Payment made via admin source |
|
432 | - * |
|
433 | - * @access public |
|
434 | - * @throws EE_Error|ReflectionException |
|
435 | - */ |
|
436 | - public function payment_made_via_admin() |
|
437 | - { |
|
438 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * get Payment Details |
|
444 | - * |
|
445 | - * @access public |
|
446 | - * @throws EE_Error|ReflectionException |
|
447 | - */ |
|
448 | - public function details() |
|
449 | - { |
|
450 | - return $this->get('PAY_details'); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * Gets redirect_url |
|
456 | - * |
|
457 | - * @return string |
|
458 | - * @throws EE_Error|ReflectionException |
|
459 | - */ |
|
460 | - public function redirect_url() |
|
461 | - { |
|
462 | - return $this->get('PAY_redirect_url'); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * Gets redirect_args |
|
468 | - * |
|
469 | - * @return array |
|
470 | - * @throws EE_Error|ReflectionException |
|
471 | - */ |
|
472 | - public function redirect_args() |
|
473 | - { |
|
474 | - return $this->get('PAY_redirect_args'); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * echoes $this->pretty_status() |
|
480 | - * |
|
481 | - * @param bool $show_icons |
|
482 | - * @return void |
|
483 | - * @throws EE_Error|ReflectionException |
|
484 | - */ |
|
485 | - public function e_pretty_status($show_icons = false) |
|
486 | - { |
|
487 | - echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * returns a pretty version of the status, good for displaying to users |
|
493 | - * |
|
494 | - * @param bool $show_icons |
|
495 | - * @return string |
|
496 | - * @throws EE_Error|ReflectionException |
|
497 | - */ |
|
498 | - public function pretty_status($show_icons = false) |
|
499 | - { |
|
500 | - $status = EEM_Status::instance()->localized_status( |
|
501 | - array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
502 | - false, |
|
503 | - 'sentence' |
|
504 | - ); |
|
505 | - $icon = ''; |
|
506 | - switch ($this->STS_ID()) { |
|
507 | - case EEM_Payment::status_id_approved: |
|
508 | - $icon = $show_icons |
|
509 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
510 | - : ''; |
|
511 | - break; |
|
512 | - case EEM_Payment::status_id_pending: |
|
513 | - $icon = $show_icons |
|
514 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
515 | - : ''; |
|
516 | - break; |
|
517 | - case EEM_Payment::status_id_cancelled: |
|
518 | - $icon = $show_icons |
|
519 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
520 | - : ''; |
|
521 | - break; |
|
522 | - case EEM_Payment::status_id_declined: |
|
523 | - $icon = $show_icons |
|
524 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
525 | - : ''; |
|
526 | - break; |
|
527 | - } |
|
528 | - return $icon . $status[ $this->STS_ID() ]; |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * For determining the status of the payment |
|
534 | - * |
|
535 | - * @return boolean whether the payment is approved or not |
|
536 | - * @throws EE_Error|ReflectionException |
|
537 | - */ |
|
538 | - public function is_approved() |
|
539 | - { |
|
540 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * Generally determines if the status of this payment equals |
|
546 | - * the $STS_ID string |
|
547 | - * |
|
548 | - * @param string $STS_ID an ID from the esp_status table/ |
|
549 | - * one of the status_id_* on the EEM_Payment model |
|
550 | - * @return boolean whether the status of this payment equals the status id |
|
551 | - * @throws EE_Error|ReflectionException |
|
552 | - */ |
|
553 | - protected function status_is($STS_ID) |
|
554 | - { |
|
555 | - return $STS_ID === $this->STS_ID(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * For determining the status of the payment |
|
561 | - * |
|
562 | - * @return boolean whether the payment is pending or not |
|
563 | - * @throws EE_Error|ReflectionException |
|
564 | - */ |
|
565 | - public function is_pending() |
|
566 | - { |
|
567 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * For determining the status of the payment |
|
573 | - * |
|
574 | - * @return boolean |
|
575 | - * @throws EE_Error|ReflectionException |
|
576 | - */ |
|
577 | - public function is_cancelled() |
|
578 | - { |
|
579 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * For determining the status of the payment |
|
585 | - * |
|
586 | - * @return boolean |
|
587 | - * @throws EE_Error|ReflectionException |
|
588 | - */ |
|
589 | - public function is_declined() |
|
590 | - { |
|
591 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * For determining the status of the payment |
|
597 | - * |
|
598 | - * @return boolean |
|
599 | - * @throws EE_Error|ReflectionException |
|
600 | - */ |
|
601 | - public function is_failed() |
|
602 | - { |
|
603 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
609 | - * |
|
610 | - * @return boolean |
|
611 | - * @throws EE_Error|ReflectionException |
|
612 | - */ |
|
613 | - public function is_a_refund() |
|
614 | - { |
|
615 | - return $this->amount() < 0; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Get the status object of this object |
|
621 | - * |
|
622 | - * @return EE_Base_Class|EE_Status |
|
623 | - * @throws EE_Error|ReflectionException |
|
624 | - */ |
|
625 | - public function status_obj() |
|
626 | - { |
|
627 | - return $this->get_first_related('Status'); |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * Gets all the extra meta info on this payment |
|
633 | - * |
|
634 | - * @param array $query_params |
|
635 | - * @return array[]|EE_Base_Class[]|EE_Extra_Meta |
|
636 | - * @throws EE_Error|ReflectionException |
|
637 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
638 | - */ |
|
639 | - public function extra_meta($query_params = array()) |
|
640 | - { |
|
641 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - /** |
|
646 | - * Gets the last-used payment method on this transaction |
|
647 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
648 | - * offline ones, dont' create payments) |
|
649 | - * |
|
650 | - * @return EE_Base_Class|EE_Payment_Method |
|
651 | - * @throws EE_Error|ReflectionException |
|
652 | - */ |
|
653 | - public function payment_method() |
|
654 | - { |
|
655 | - return $this->get_first_related('Payment_Method'); |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
661 | - * You can pass it special content to put inside the form, or use |
|
662 | - * the default inner content (or possibly generate this all yourself using |
|
663 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
664 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
665 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
666 | - * so browsers submit them properly) |
|
667 | - * |
|
668 | - * @param string $inside_form_html |
|
669 | - * @return string html |
|
670 | - * @throws EE_Error|ReflectionException |
|
671 | - */ |
|
672 | - public function redirect_form($inside_form_html = null) |
|
673 | - { |
|
674 | - $redirect_url = $this->redirect_url(); |
|
675 | - |
|
676 | - if (empty($redirect_url)) { |
|
677 | - return null; |
|
678 | - } |
|
679 | - |
|
680 | - // what ? no inner form content? |
|
681 | - if ($inside_form_html === null) { |
|
682 | - $inside_form_html = EEH_HTML::p( |
|
683 | - sprintf( |
|
684 | - esc_html__( |
|
685 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
686 | - 'event_espresso' |
|
687 | - ), |
|
688 | - EEH_HTML::br(2), |
|
689 | - '<input type="submit" value="', |
|
690 | - '">' |
|
691 | - ), |
|
692 | - '', |
|
693 | - '', |
|
694 | - 'text-align:center;' |
|
695 | - ); |
|
696 | - } |
|
697 | - |
|
698 | - $method = apply_filters( |
|
699 | - 'FHEE__EE_Payment__redirect_form__method', |
|
700 | - $this->redirect_args() ? 'POST' : 'GET', |
|
701 | - $this |
|
702 | - ); |
|
703 | - |
|
704 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
705 | - // and put them into the form instead |
|
706 | - if ($method === 'GET') { |
|
707 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
708 | - $get_params = null; |
|
709 | - parse_str($querystring, $get_params); |
|
710 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
711 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
712 | - } |
|
713 | - |
|
714 | - $form = EEH_HTML::nl(1) |
|
715 | - . '<form method="' . $method . '" name="gateway_form" action="' . $redirect_url . '">'; |
|
716 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
717 | - $form .= $inside_form_html; |
|
718 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
719 | - return $form; |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
725 | - * and returns the html as a string |
|
726 | - * |
|
727 | - * @return string |
|
728 | - * @throws EE_Error|ReflectionException |
|
729 | - */ |
|
730 | - public function redirect_args_as_inputs() |
|
731 | - { |
|
732 | - return $this->_args_as_inputs($this->redirect_args()); |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Converts a 2d array of key-value pairs into html hidden inputs |
|
738 | - * and returns the string of html |
|
739 | - * |
|
740 | - * @param array $args key-value pairs |
|
741 | - * @return string |
|
742 | - */ |
|
743 | - protected function _args_as_inputs($args) |
|
744 | - { |
|
745 | - $html = ''; |
|
746 | - if ($args !== null && is_array($args)) { |
|
747 | - foreach ($args as $name => $value) { |
|
748 | - $html .= $this->generateInput($name, $value); |
|
749 | - } |
|
750 | - } |
|
751 | - return $html; |
|
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Converts either a single name and value or array of values into html hidden inputs |
|
756 | - * and returns the string of html |
|
757 | - * |
|
758 | - * @param string $name |
|
759 | - * @param string|array $value |
|
760 | - * @return string |
|
761 | - */ |
|
762 | - private function generateInput($name, $value) |
|
763 | - { |
|
764 | - if (is_array($value)) { |
|
765 | - $html = ''; |
|
766 | - $name = "{$name}[]"; |
|
767 | - foreach ($value as $array_value) { |
|
768 | - $html .= $this->generateInput($name, $array_value); |
|
769 | - } |
|
770 | - return $html; |
|
771 | - } |
|
772 | - return EEH_HTML::nl() |
|
773 | - . '<input type="hidden" name="' . $name . '"' |
|
774 | - . ' value="' . esc_attr($value) . '"/>'; |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * Returns the currency of the payment. |
|
780 | - * (At the time of writing, this will always be the currency in the configuration; |
|
781 | - * however in the future it is anticipated that this will be stored on the payment |
|
782 | - * object itself) |
|
783 | - * |
|
784 | - * @return string for the currency code |
|
785 | - */ |
|
786 | - public function currency_code() |
|
787 | - { |
|
788 | - return $this->currency_formatter->getCurrencyIsoCodeForLocale(); |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * apply wp_strip_all_tags to all elements within an array |
|
794 | - * |
|
795 | - * @access private |
|
796 | - * @param mixed $item |
|
797 | - */ |
|
798 | - private function _strip_all_tags_within_array(&$item) |
|
799 | - { |
|
800 | - if (is_object($item)) { |
|
801 | - $item = (array) $item; |
|
802 | - } |
|
803 | - if (is_array($item)) { |
|
804 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
805 | - } else { |
|
806 | - $item = wp_strip_all_tags($item); |
|
807 | - } |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - /** |
|
812 | - * Returns TRUE is this payment was set to approved during this request (or |
|
813 | - * is approved and was created during this request). False otherwise. |
|
814 | - * |
|
815 | - * @return boolean |
|
816 | - * @throws EE_Error|ReflectionException |
|
817 | - */ |
|
818 | - public function just_approved() |
|
819 | - { |
|
820 | - $original_status = EEH_Array::is_set( |
|
821 | - $this->_props_n_values_provided_in_constructor, |
|
822 | - 'STS_ID', |
|
823 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
824 | - ); |
|
825 | - $current_status = $this->status(); |
|
826 | - if ( |
|
827 | - $original_status !== EEM_Payment::status_id_approved |
|
828 | - && $current_status === EEM_Payment::status_id_approved |
|
829 | - ) { |
|
830 | - return true; |
|
831 | - } |
|
832 | - return false; |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
838 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
839 | - * |
|
840 | - * @param string $field_name |
|
841 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
842 | - * (in cases where the same property may be used for different outputs |
|
843 | - * - i.e. datetime, money etc.) |
|
844 | - * @return mixed |
|
845 | - * @throws EE_Error|ReflectionException |
|
846 | - */ |
|
847 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
848 | - { |
|
849 | - if ($field_name === 'PAY_gateway') { |
|
850 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
851 | - } |
|
852 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
853 | - } |
|
854 | - |
|
855 | - |
|
856 | - /** |
|
857 | - * Gets details regarding which registrations this payment was applied to |
|
858 | - * |
|
859 | - * @param array $query_params |
|
860 | - * @return array[]|EE_Base_Class[]|EE_Registration_Payment[] |
|
861 | - * @throws EE_Error|ReflectionException |
|
862 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
863 | - */ |
|
864 | - public function registration_payments($query_params = array()) |
|
865 | - { |
|
866 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
872 | - * |
|
873 | - * @return EE_Event|null |
|
874 | - * @throws EE_Error |
|
875 | - * @throws ReflectionException |
|
876 | - */ |
|
877 | - public function get_first_event() |
|
878 | - { |
|
879 | - $transaction = $this->transaction(); |
|
880 | - if ($transaction instanceof EE_Transaction) { |
|
881 | - $primary_registrant = $transaction->primary_registration(); |
|
882 | - if ($primary_registrant instanceof EE_Registration) { |
|
883 | - return $primary_registrant->event_obj(); |
|
884 | - } |
|
885 | - } |
|
886 | - return null; |
|
887 | - } |
|
888 | - |
|
889 | - |
|
890 | - /** |
|
891 | - * Gets the name of the first event for which is being paid |
|
892 | - * |
|
893 | - * @return string |
|
894 | - * @throws EE_Error|ReflectionException |
|
895 | - */ |
|
896 | - public function get_first_event_name() |
|
897 | - { |
|
898 | - $event = $this->get_first_event(); |
|
899 | - return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
900 | - } |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * Returns the payment's transaction's primary registration |
|
905 | - * |
|
906 | - * @return EE_Registration|null |
|
907 | - * @throws EE_Error |
|
908 | - * @throws ReflectionException |
|
909 | - */ |
|
910 | - public function get_primary_registration() |
|
911 | - { |
|
912 | - if ($this->transaction() instanceof EE_Transaction) { |
|
913 | - return $this->transaction()->primary_registration(); |
|
914 | - } |
|
915 | - return null; |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
921 | - * |
|
922 | - * @return EE_Attendee|null |
|
923 | - * @throws EE_Error |
|
924 | - * @throws ReflectionException |
|
925 | - */ |
|
926 | - public function get_primary_attendee() |
|
927 | - { |
|
928 | - $primary_reg = $this->get_primary_registration(); |
|
929 | - if ($primary_reg instanceof EE_Registration) { |
|
930 | - return $primary_reg->attendee(); |
|
931 | - } |
|
932 | - return null; |
|
933 | - } |
|
16 | + /** |
|
17 | + * @var CurrencyFormatter |
|
18 | + * @since $VID:$ |
|
19 | + */ |
|
20 | + protected $currency_formatter; |
|
21 | + |
|
22 | + /** |
|
23 | + * @param array $props_n_values incoming values |
|
24 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
25 | + * used.) |
|
26 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
27 | + * date_format and the second value is the time format |
|
28 | + * @return EE_Payment |
|
29 | + * @throws EE_Error|ReflectionException |
|
30 | + */ |
|
31 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
32 | + { |
|
33 | + $payment = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
34 | + if (! $payment instanceof EE_Payment) { |
|
35 | + $payment = new EE_Payment($props_n_values, false, $timezone, $date_formats); |
|
36 | + } |
|
37 | + return $payment; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @param array $props_n_values incoming values from the database |
|
43 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
44 | + * the website will be used. |
|
45 | + * @return EE_Payment |
|
46 | + * @throws EE_Error|ReflectionException |
|
47 | + */ |
|
48 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
49 | + { |
|
50 | + return new EE_Payment($props_n_values, true, $timezone); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Adds some defaults if they're not specified |
|
56 | + * |
|
57 | + * @param array $props_n_values |
|
58 | + * @param bool $bydb |
|
59 | + * @param string $timezone |
|
60 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
61 | + * date_format and the second value is the time format |
|
62 | + * @throws EE_Error |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + protected function __construct($props_n_values = [], $bydb = false, $timezone = '', $date_formats = []) |
|
66 | + { |
|
67 | + parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
|
68 | + // in a better world this would have been injected upon construction |
|
69 | + if (! $this->currency_formatter instanceof CurrencyFormatter) { |
|
70 | + $this->currency_formatter = LoaderFactory::getLoader()->getShared(CurrencyFormatter::class); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Set Transaction ID |
|
77 | + * |
|
78 | + * @access public |
|
79 | + * @param int $TXN_ID |
|
80 | + * @throws EE_Error|ReflectionException |
|
81 | + */ |
|
82 | + public function set_transaction_id($TXN_ID = 0) |
|
83 | + { |
|
84 | + $this->set('TXN_ID', $TXN_ID); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the transaction related to this payment |
|
90 | + * |
|
91 | + * @return EE_Base_Class|EE_Transaction |
|
92 | + * @throws EE_Error|ReflectionException |
|
93 | + */ |
|
94 | + public function transaction() |
|
95 | + { |
|
96 | + return $this->get_first_related('Transaction'); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Set Status |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @param string $STS_ID |
|
105 | + * @throws EE_Error|ReflectionException |
|
106 | + */ |
|
107 | + public function set_status($STS_ID = '') |
|
108 | + { |
|
109 | + $this->set('STS_ID', $STS_ID); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Set Payment Timestamp |
|
115 | + * |
|
116 | + * @access public |
|
117 | + * @param int $timestamp |
|
118 | + * @throws EE_Error|ReflectionException |
|
119 | + */ |
|
120 | + public function set_timestamp($timestamp = 0) |
|
121 | + { |
|
122 | + $this->set('PAY_timestamp', $timestamp); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Set Payment Method |
|
128 | + * |
|
129 | + * @access public |
|
130 | + * @param string $PAY_source |
|
131 | + * @throws EE_Error|ReflectionException |
|
132 | + */ |
|
133 | + public function set_source($PAY_source = '') |
|
134 | + { |
|
135 | + $this->set('PAY_source', $PAY_source); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Set Payment Amount |
|
141 | + * |
|
142 | + * @access public |
|
143 | + * @param float $amount |
|
144 | + * @throws EE_Error|ReflectionException |
|
145 | + */ |
|
146 | + public function set_amount($amount = 0.00) |
|
147 | + { |
|
148 | + $this->set('PAY_amount', $amount); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Set Payment Gateway Response |
|
154 | + * |
|
155 | + * @access public |
|
156 | + * @param string $gateway_response |
|
157 | + * @throws EE_Error|ReflectionException |
|
158 | + */ |
|
159 | + public function set_gateway_response($gateway_response = '') |
|
160 | + { |
|
161 | + $this->set('PAY_gateway_response', $gateway_response); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
167 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
168 | + * used on it |
|
169 | + * |
|
170 | + * @return string |
|
171 | + * @throws EE_Error|ReflectionException |
|
172 | + *@deprecated |
|
173 | + */ |
|
174 | + public function gateway() |
|
175 | + { |
|
176 | + EE_Error::doing_it_wrong( |
|
177 | + 'EE_Payment::gateway', |
|
178 | + esc_html__( |
|
179 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
180 | + 'event_espresso' |
|
181 | + ), |
|
182 | + '4.6.0' |
|
183 | + ); |
|
184 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Set Gateway Transaction ID |
|
190 | + * |
|
191 | + * @access public |
|
192 | + * @param string $txn_id_chq_nmbr |
|
193 | + * @throws EE_Error|ReflectionException |
|
194 | + */ |
|
195 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
196 | + { |
|
197 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Set Purchase Order Number |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @param string $po_number |
|
206 | + * @throws EE_Error|ReflectionException |
|
207 | + */ |
|
208 | + public function set_po_number($po_number = '') |
|
209 | + { |
|
210 | + $this->set('PAY_po_number', $po_number); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Set Extra Accounting Field |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @param string $extra_accntng |
|
219 | + * @throws EE_Error|ReflectionException |
|
220 | + */ |
|
221 | + public function set_extra_accntng($extra_accntng = '') |
|
222 | + { |
|
223 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * Set Payment made via admin flag |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @param bool $via_admin |
|
232 | + * @throws EE_Error|ReflectionException |
|
233 | + */ |
|
234 | + public function set_payment_made_via_admin($via_admin = false) |
|
235 | + { |
|
236 | + if ($via_admin) { |
|
237 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
238 | + } else { |
|
239 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * Set Payment Details |
|
246 | + * |
|
247 | + * @access public |
|
248 | + * @param string|array $details |
|
249 | + * @throws EE_Error|ReflectionException |
|
250 | + */ |
|
251 | + public function set_details($details = '') |
|
252 | + { |
|
253 | + if (is_array($details)) { |
|
254 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
255 | + } else { |
|
256 | + $details = wp_strip_all_tags($details); |
|
257 | + } |
|
258 | + $this->set('PAY_details', $details); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Sets redirect_url |
|
264 | + * |
|
265 | + * @param string $redirect_url |
|
266 | + * @throws EE_Error|ReflectionException |
|
267 | + */ |
|
268 | + public function set_redirect_url($redirect_url) |
|
269 | + { |
|
270 | + $this->set('PAY_redirect_url', $redirect_url); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Sets redirect_args |
|
276 | + * |
|
277 | + * @param array $redirect_args |
|
278 | + * @throws EE_Error|ReflectionException |
|
279 | + */ |
|
280 | + public function set_redirect_args($redirect_args) |
|
281 | + { |
|
282 | + $this->set('PAY_redirect_args', $redirect_args); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * get Payment Transaction ID |
|
288 | + * |
|
289 | + * @access public |
|
290 | + * @throws EE_Error|ReflectionException |
|
291 | + */ |
|
292 | + public function TXN_ID() |
|
293 | + { |
|
294 | + return $this->get('TXN_ID'); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * get Payment Status |
|
300 | + * |
|
301 | + * @access public |
|
302 | + * @throws EE_Error|ReflectionException |
|
303 | + */ |
|
304 | + public function status() |
|
305 | + { |
|
306 | + return $this->get('STS_ID'); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * get Payment Status |
|
312 | + * |
|
313 | + * @access public |
|
314 | + * @throws EE_Error|ReflectionException |
|
315 | + */ |
|
316 | + public function STS_ID() |
|
317 | + { |
|
318 | + return $this->get('STS_ID'); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * get Payment Timestamp |
|
324 | + * |
|
325 | + * @access public |
|
326 | + * @param string $date_format |
|
327 | + * @param string $time_format |
|
328 | + * @return string |
|
329 | + * @throws EE_Error|ReflectionException |
|
330 | + */ |
|
331 | + public function timestamp($date_format = '', $time_format = '') |
|
332 | + { |
|
333 | + return $this->get_i18n_datetime('PAY_timestamp', trim($date_format . ' ' . $time_format)); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * get Payment Source |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @throws EE_Error|ReflectionException |
|
342 | + */ |
|
343 | + public function source() |
|
344 | + { |
|
345 | + return $this->get('PAY_source'); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * get Payment Amount |
|
351 | + * |
|
352 | + * @access public |
|
353 | + * @return float |
|
354 | + * @throws EE_Error|ReflectionException |
|
355 | + */ |
|
356 | + public function amount() |
|
357 | + { |
|
358 | + return (float) $this->get('PAY_amount'); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @return mixed |
|
364 | + * @throws EE_Error|ReflectionException |
|
365 | + */ |
|
366 | + public function amount_no_code() |
|
367 | + { |
|
368 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @return mixed |
|
374 | + * @throws EE_Error|ReflectionException |
|
375 | + */ |
|
376 | + public function prettyAmount() |
|
377 | + { |
|
378 | + return $this->get_pretty('PAY_amount', 'localized_currency'); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * get Payment Gateway Response |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @throws EE_Error|ReflectionException |
|
387 | + */ |
|
388 | + public function gateway_response() |
|
389 | + { |
|
390 | + return $this->get('PAY_gateway_response'); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * get Payment Gateway Transaction ID |
|
396 | + * |
|
397 | + * @access public |
|
398 | + * @throws EE_Error|ReflectionException |
|
399 | + */ |
|
400 | + public function txn_id_chq_nmbr() |
|
401 | + { |
|
402 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * get Purchase Order Number |
|
408 | + * |
|
409 | + * @access public |
|
410 | + * @throws EE_Error|ReflectionException |
|
411 | + */ |
|
412 | + public function po_number() |
|
413 | + { |
|
414 | + return $this->get('PAY_po_number'); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * get Extra Accounting Field |
|
420 | + * |
|
421 | + * @access public |
|
422 | + * @throws EE_Error|ReflectionException |
|
423 | + */ |
|
424 | + public function extra_accntng() |
|
425 | + { |
|
426 | + return $this->get('PAY_extra_accntng'); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * get Payment made via admin source |
|
432 | + * |
|
433 | + * @access public |
|
434 | + * @throws EE_Error|ReflectionException |
|
435 | + */ |
|
436 | + public function payment_made_via_admin() |
|
437 | + { |
|
438 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * get Payment Details |
|
444 | + * |
|
445 | + * @access public |
|
446 | + * @throws EE_Error|ReflectionException |
|
447 | + */ |
|
448 | + public function details() |
|
449 | + { |
|
450 | + return $this->get('PAY_details'); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * Gets redirect_url |
|
456 | + * |
|
457 | + * @return string |
|
458 | + * @throws EE_Error|ReflectionException |
|
459 | + */ |
|
460 | + public function redirect_url() |
|
461 | + { |
|
462 | + return $this->get('PAY_redirect_url'); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * Gets redirect_args |
|
468 | + * |
|
469 | + * @return array |
|
470 | + * @throws EE_Error|ReflectionException |
|
471 | + */ |
|
472 | + public function redirect_args() |
|
473 | + { |
|
474 | + return $this->get('PAY_redirect_args'); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * echoes $this->pretty_status() |
|
480 | + * |
|
481 | + * @param bool $show_icons |
|
482 | + * @return void |
|
483 | + * @throws EE_Error|ReflectionException |
|
484 | + */ |
|
485 | + public function e_pretty_status($show_icons = false) |
|
486 | + { |
|
487 | + echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * returns a pretty version of the status, good for displaying to users |
|
493 | + * |
|
494 | + * @param bool $show_icons |
|
495 | + * @return string |
|
496 | + * @throws EE_Error|ReflectionException |
|
497 | + */ |
|
498 | + public function pretty_status($show_icons = false) |
|
499 | + { |
|
500 | + $status = EEM_Status::instance()->localized_status( |
|
501 | + array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
502 | + false, |
|
503 | + 'sentence' |
|
504 | + ); |
|
505 | + $icon = ''; |
|
506 | + switch ($this->STS_ID()) { |
|
507 | + case EEM_Payment::status_id_approved: |
|
508 | + $icon = $show_icons |
|
509 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
510 | + : ''; |
|
511 | + break; |
|
512 | + case EEM_Payment::status_id_pending: |
|
513 | + $icon = $show_icons |
|
514 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
515 | + : ''; |
|
516 | + break; |
|
517 | + case EEM_Payment::status_id_cancelled: |
|
518 | + $icon = $show_icons |
|
519 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
520 | + : ''; |
|
521 | + break; |
|
522 | + case EEM_Payment::status_id_declined: |
|
523 | + $icon = $show_icons |
|
524 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
525 | + : ''; |
|
526 | + break; |
|
527 | + } |
|
528 | + return $icon . $status[ $this->STS_ID() ]; |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * For determining the status of the payment |
|
534 | + * |
|
535 | + * @return boolean whether the payment is approved or not |
|
536 | + * @throws EE_Error|ReflectionException |
|
537 | + */ |
|
538 | + public function is_approved() |
|
539 | + { |
|
540 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * Generally determines if the status of this payment equals |
|
546 | + * the $STS_ID string |
|
547 | + * |
|
548 | + * @param string $STS_ID an ID from the esp_status table/ |
|
549 | + * one of the status_id_* on the EEM_Payment model |
|
550 | + * @return boolean whether the status of this payment equals the status id |
|
551 | + * @throws EE_Error|ReflectionException |
|
552 | + */ |
|
553 | + protected function status_is($STS_ID) |
|
554 | + { |
|
555 | + return $STS_ID === $this->STS_ID(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * For determining the status of the payment |
|
561 | + * |
|
562 | + * @return boolean whether the payment is pending or not |
|
563 | + * @throws EE_Error|ReflectionException |
|
564 | + */ |
|
565 | + public function is_pending() |
|
566 | + { |
|
567 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * For determining the status of the payment |
|
573 | + * |
|
574 | + * @return boolean |
|
575 | + * @throws EE_Error|ReflectionException |
|
576 | + */ |
|
577 | + public function is_cancelled() |
|
578 | + { |
|
579 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * For determining the status of the payment |
|
585 | + * |
|
586 | + * @return boolean |
|
587 | + * @throws EE_Error|ReflectionException |
|
588 | + */ |
|
589 | + public function is_declined() |
|
590 | + { |
|
591 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * For determining the status of the payment |
|
597 | + * |
|
598 | + * @return boolean |
|
599 | + * @throws EE_Error|ReflectionException |
|
600 | + */ |
|
601 | + public function is_failed() |
|
602 | + { |
|
603 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
609 | + * |
|
610 | + * @return boolean |
|
611 | + * @throws EE_Error|ReflectionException |
|
612 | + */ |
|
613 | + public function is_a_refund() |
|
614 | + { |
|
615 | + return $this->amount() < 0; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Get the status object of this object |
|
621 | + * |
|
622 | + * @return EE_Base_Class|EE_Status |
|
623 | + * @throws EE_Error|ReflectionException |
|
624 | + */ |
|
625 | + public function status_obj() |
|
626 | + { |
|
627 | + return $this->get_first_related('Status'); |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * Gets all the extra meta info on this payment |
|
633 | + * |
|
634 | + * @param array $query_params |
|
635 | + * @return array[]|EE_Base_Class[]|EE_Extra_Meta |
|
636 | + * @throws EE_Error|ReflectionException |
|
637 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
638 | + */ |
|
639 | + public function extra_meta($query_params = array()) |
|
640 | + { |
|
641 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + /** |
|
646 | + * Gets the last-used payment method on this transaction |
|
647 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
648 | + * offline ones, dont' create payments) |
|
649 | + * |
|
650 | + * @return EE_Base_Class|EE_Payment_Method |
|
651 | + * @throws EE_Error|ReflectionException |
|
652 | + */ |
|
653 | + public function payment_method() |
|
654 | + { |
|
655 | + return $this->get_first_related('Payment_Method'); |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
661 | + * You can pass it special content to put inside the form, or use |
|
662 | + * the default inner content (or possibly generate this all yourself using |
|
663 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
664 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
665 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
666 | + * so browsers submit them properly) |
|
667 | + * |
|
668 | + * @param string $inside_form_html |
|
669 | + * @return string html |
|
670 | + * @throws EE_Error|ReflectionException |
|
671 | + */ |
|
672 | + public function redirect_form($inside_form_html = null) |
|
673 | + { |
|
674 | + $redirect_url = $this->redirect_url(); |
|
675 | + |
|
676 | + if (empty($redirect_url)) { |
|
677 | + return null; |
|
678 | + } |
|
679 | + |
|
680 | + // what ? no inner form content? |
|
681 | + if ($inside_form_html === null) { |
|
682 | + $inside_form_html = EEH_HTML::p( |
|
683 | + sprintf( |
|
684 | + esc_html__( |
|
685 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
686 | + 'event_espresso' |
|
687 | + ), |
|
688 | + EEH_HTML::br(2), |
|
689 | + '<input type="submit" value="', |
|
690 | + '">' |
|
691 | + ), |
|
692 | + '', |
|
693 | + '', |
|
694 | + 'text-align:center;' |
|
695 | + ); |
|
696 | + } |
|
697 | + |
|
698 | + $method = apply_filters( |
|
699 | + 'FHEE__EE_Payment__redirect_form__method', |
|
700 | + $this->redirect_args() ? 'POST' : 'GET', |
|
701 | + $this |
|
702 | + ); |
|
703 | + |
|
704 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
705 | + // and put them into the form instead |
|
706 | + if ($method === 'GET') { |
|
707 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
708 | + $get_params = null; |
|
709 | + parse_str($querystring, $get_params); |
|
710 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
711 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
712 | + } |
|
713 | + |
|
714 | + $form = EEH_HTML::nl(1) |
|
715 | + . '<form method="' . $method . '" name="gateway_form" action="' . $redirect_url . '">'; |
|
716 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
717 | + $form .= $inside_form_html; |
|
718 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
719 | + return $form; |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
725 | + * and returns the html as a string |
|
726 | + * |
|
727 | + * @return string |
|
728 | + * @throws EE_Error|ReflectionException |
|
729 | + */ |
|
730 | + public function redirect_args_as_inputs() |
|
731 | + { |
|
732 | + return $this->_args_as_inputs($this->redirect_args()); |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Converts a 2d array of key-value pairs into html hidden inputs |
|
738 | + * and returns the string of html |
|
739 | + * |
|
740 | + * @param array $args key-value pairs |
|
741 | + * @return string |
|
742 | + */ |
|
743 | + protected function _args_as_inputs($args) |
|
744 | + { |
|
745 | + $html = ''; |
|
746 | + if ($args !== null && is_array($args)) { |
|
747 | + foreach ($args as $name => $value) { |
|
748 | + $html .= $this->generateInput($name, $value); |
|
749 | + } |
|
750 | + } |
|
751 | + return $html; |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Converts either a single name and value or array of values into html hidden inputs |
|
756 | + * and returns the string of html |
|
757 | + * |
|
758 | + * @param string $name |
|
759 | + * @param string|array $value |
|
760 | + * @return string |
|
761 | + */ |
|
762 | + private function generateInput($name, $value) |
|
763 | + { |
|
764 | + if (is_array($value)) { |
|
765 | + $html = ''; |
|
766 | + $name = "{$name}[]"; |
|
767 | + foreach ($value as $array_value) { |
|
768 | + $html .= $this->generateInput($name, $array_value); |
|
769 | + } |
|
770 | + return $html; |
|
771 | + } |
|
772 | + return EEH_HTML::nl() |
|
773 | + . '<input type="hidden" name="' . $name . '"' |
|
774 | + . ' value="' . esc_attr($value) . '"/>'; |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * Returns the currency of the payment. |
|
780 | + * (At the time of writing, this will always be the currency in the configuration; |
|
781 | + * however in the future it is anticipated that this will be stored on the payment |
|
782 | + * object itself) |
|
783 | + * |
|
784 | + * @return string for the currency code |
|
785 | + */ |
|
786 | + public function currency_code() |
|
787 | + { |
|
788 | + return $this->currency_formatter->getCurrencyIsoCodeForLocale(); |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * apply wp_strip_all_tags to all elements within an array |
|
794 | + * |
|
795 | + * @access private |
|
796 | + * @param mixed $item |
|
797 | + */ |
|
798 | + private function _strip_all_tags_within_array(&$item) |
|
799 | + { |
|
800 | + if (is_object($item)) { |
|
801 | + $item = (array) $item; |
|
802 | + } |
|
803 | + if (is_array($item)) { |
|
804 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
805 | + } else { |
|
806 | + $item = wp_strip_all_tags($item); |
|
807 | + } |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + /** |
|
812 | + * Returns TRUE is this payment was set to approved during this request (or |
|
813 | + * is approved and was created during this request). False otherwise. |
|
814 | + * |
|
815 | + * @return boolean |
|
816 | + * @throws EE_Error|ReflectionException |
|
817 | + */ |
|
818 | + public function just_approved() |
|
819 | + { |
|
820 | + $original_status = EEH_Array::is_set( |
|
821 | + $this->_props_n_values_provided_in_constructor, |
|
822 | + 'STS_ID', |
|
823 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
824 | + ); |
|
825 | + $current_status = $this->status(); |
|
826 | + if ( |
|
827 | + $original_status !== EEM_Payment::status_id_approved |
|
828 | + && $current_status === EEM_Payment::status_id_approved |
|
829 | + ) { |
|
830 | + return true; |
|
831 | + } |
|
832 | + return false; |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
838 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
839 | + * |
|
840 | + * @param string $field_name |
|
841 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
842 | + * (in cases where the same property may be used for different outputs |
|
843 | + * - i.e. datetime, money etc.) |
|
844 | + * @return mixed |
|
845 | + * @throws EE_Error|ReflectionException |
|
846 | + */ |
|
847 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
848 | + { |
|
849 | + if ($field_name === 'PAY_gateway') { |
|
850 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
851 | + } |
|
852 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
853 | + } |
|
854 | + |
|
855 | + |
|
856 | + /** |
|
857 | + * Gets details regarding which registrations this payment was applied to |
|
858 | + * |
|
859 | + * @param array $query_params |
|
860 | + * @return array[]|EE_Base_Class[]|EE_Registration_Payment[] |
|
861 | + * @throws EE_Error|ReflectionException |
|
862 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
863 | + */ |
|
864 | + public function registration_payments($query_params = array()) |
|
865 | + { |
|
866 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
872 | + * |
|
873 | + * @return EE_Event|null |
|
874 | + * @throws EE_Error |
|
875 | + * @throws ReflectionException |
|
876 | + */ |
|
877 | + public function get_first_event() |
|
878 | + { |
|
879 | + $transaction = $this->transaction(); |
|
880 | + if ($transaction instanceof EE_Transaction) { |
|
881 | + $primary_registrant = $transaction->primary_registration(); |
|
882 | + if ($primary_registrant instanceof EE_Registration) { |
|
883 | + return $primary_registrant->event_obj(); |
|
884 | + } |
|
885 | + } |
|
886 | + return null; |
|
887 | + } |
|
888 | + |
|
889 | + |
|
890 | + /** |
|
891 | + * Gets the name of the first event for which is being paid |
|
892 | + * |
|
893 | + * @return string |
|
894 | + * @throws EE_Error|ReflectionException |
|
895 | + */ |
|
896 | + public function get_first_event_name() |
|
897 | + { |
|
898 | + $event = $this->get_first_event(); |
|
899 | + return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
900 | + } |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * Returns the payment's transaction's primary registration |
|
905 | + * |
|
906 | + * @return EE_Registration|null |
|
907 | + * @throws EE_Error |
|
908 | + * @throws ReflectionException |
|
909 | + */ |
|
910 | + public function get_primary_registration() |
|
911 | + { |
|
912 | + if ($this->transaction() instanceof EE_Transaction) { |
|
913 | + return $this->transaction()->primary_registration(); |
|
914 | + } |
|
915 | + return null; |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
921 | + * |
|
922 | + * @return EE_Attendee|null |
|
923 | + * @throws EE_Error |
|
924 | + * @throws ReflectionException |
|
925 | + */ |
|
926 | + public function get_primary_attendee() |
|
927 | + { |
|
928 | + $primary_reg = $this->get_primary_registration(); |
|
929 | + if ($primary_reg instanceof EE_Registration) { |
|
930 | + return $primary_reg->attendee(); |
|
931 | + } |
|
932 | + return null; |
|
933 | + } |
|
934 | 934 | } |
@@ -24,14 +24,14 @@ |
||
24 | 24 | */ |
25 | 25 | public function formatArray(array $input): array |
26 | 26 | { |
27 | - if (! is_array($input)) { |
|
27 | + if ( ! is_array($input)) { |
|
28 | 28 | throw new InvalidDataTypeException('input', $input, 'array'); |
29 | 29 | } |
30 | 30 | // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
31 | 31 | $formatter = $this; |
32 | 32 | array_walk_recursive( |
33 | 33 | $input, |
34 | - function (&$value) use ($formatter) { |
|
34 | + function(&$value) use ($formatter) { |
|
35 | 35 | $value = $formatter->format($value); |
36 | 36 | } |
37 | 37 | ); |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class FormatterBase implements FormatterInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
19 | - * |
|
20 | - * @param array $input |
|
21 | - * @return array |
|
22 | - * @throws InvalidDataTypeException if $input is not an array |
|
23 | - */ |
|
24 | - public function formatArray(array $input): array |
|
25 | - { |
|
26 | - if (! is_array($input)) { |
|
27 | - throw new InvalidDataTypeException('input', $input, 'array'); |
|
28 | - } |
|
29 | - // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
30 | - $formatter = $this; |
|
31 | - array_walk_recursive( |
|
32 | - $input, |
|
33 | - function (&$value) use ($formatter) { |
|
34 | - $value = $formatter->format($value); |
|
35 | - } |
|
36 | - ); |
|
37 | - return $input; |
|
38 | - } |
|
17 | + /** |
|
18 | + * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
19 | + * |
|
20 | + * @param array $input |
|
21 | + * @return array |
|
22 | + * @throws InvalidDataTypeException if $input is not an array |
|
23 | + */ |
|
24 | + public function formatArray(array $input): array |
|
25 | + { |
|
26 | + if (! is_array($input)) { |
|
27 | + throw new InvalidDataTypeException('input', $input, 'array'); |
|
28 | + } |
|
29 | + // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
30 | + $formatter = $this; |
|
31 | + array_walk_recursive( |
|
32 | + $input, |
|
33 | + function (&$value) use ($formatter) { |
|
34 | + $value = $formatter->format($value); |
|
35 | + } |
|
36 | + ); |
|
37 | + return $input; |
|
38 | + } |
|
39 | 39 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public function parseForLocale($number, $locale = ''): float |
90 | 90 | { |
91 | 91 | // just return the value if it's not a string |
92 | - if (! is_string($number)) { |
|
92 | + if ( ! is_string($number)) { |
|
93 | 93 | return (float) $number; |
94 | 94 | } |
95 | 95 | $locale = $this->locales->getLocale($locale); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $locale->decimalPoint(), |
101 | 101 | ], |
102 | 102 | [ |
103 | - '', // remove thousands separator |
|
103 | + '', // remove thousands separator |
|
104 | 104 | '.', // convert decimal mark to what PHP expects |
105 | 105 | ], |
106 | 106 | $number |
@@ -6,105 +6,105 @@ |
||
6 | 6 | |
7 | 7 | class NumberFormatter extends LocaleFloatFormatter |
8 | 8 | { |
9 | - /** |
|
10 | - * formats the provided number for the selected locale (defaults to site locale) and returns a string |
|
11 | - * |
|
12 | - * @param Locale $locale |
|
13 | - * @param float $number unformatted number value, ex: 1234.56789 |
|
14 | - * @param int|null $precision the number of decimal places to round to |
|
15 | - * @return string formatted value, ex: '1,234.57' |
|
16 | - */ |
|
17 | - protected function format(Locale $locale, float $number, ?int $precision = null) |
|
18 | - { |
|
19 | - $is_negative = $number < 0; |
|
20 | - $precision = $precision !== null |
|
21 | - ? absint($precision) |
|
22 | - : $locale->decimalPrecision(); |
|
23 | - return $this->formatSymbolAndSignPositions( |
|
24 | - $locale, |
|
25 | - $this->formatGroupings( |
|
26 | - $number, |
|
27 | - $precision, |
|
28 | - $locale->decimalPoint(), |
|
29 | - $locale->grouping(), |
|
30 | - $locale->thousandsSeparator() |
|
31 | - ), |
|
32 | - $is_negative |
|
33 | - ); |
|
34 | - } |
|
9 | + /** |
|
10 | + * formats the provided number for the selected locale (defaults to site locale) and returns a string |
|
11 | + * |
|
12 | + * @param Locale $locale |
|
13 | + * @param float $number unformatted number value, ex: 1234.56789 |
|
14 | + * @param int|null $precision the number of decimal places to round to |
|
15 | + * @return string formatted value, ex: '1,234.57' |
|
16 | + */ |
|
17 | + protected function format(Locale $locale, float $number, ?int $precision = null) |
|
18 | + { |
|
19 | + $is_negative = $number < 0; |
|
20 | + $precision = $precision !== null |
|
21 | + ? absint($precision) |
|
22 | + : $locale->decimalPrecision(); |
|
23 | + return $this->formatSymbolAndSignPositions( |
|
24 | + $locale, |
|
25 | + $this->formatGroupings( |
|
26 | + $number, |
|
27 | + $precision, |
|
28 | + $locale->decimalPoint(), |
|
29 | + $locale->grouping(), |
|
30 | + $locale->thousandsSeparator() |
|
31 | + ), |
|
32 | + $is_negative |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param Locale $locale |
|
39 | - * @param int|float|string $number |
|
40 | - * @param bool $is_negative |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - protected function formatSymbolAndSignPositions(Locale $locale, $number, bool $is_negative) |
|
44 | - { |
|
45 | - // format for positive or negative values |
|
46 | - if ($is_negative) { |
|
47 | - $sign = $locale->negativeSign(); |
|
48 | - $position = $locale->negativeSignPosition(); |
|
49 | - } else { |
|
50 | - $sign = $locale->positiveSign(); |
|
51 | - $position = $locale->positiveSignPosition(); |
|
52 | - } |
|
53 | - switch ($position) { |
|
54 | - case LocaleFloatFormatter::PARENTHESES: |
|
55 | - return "({$number})"; |
|
56 | - case LocaleFloatFormatter::SIGN_BEFORE_ALL: |
|
57 | - case LocaleFloatFormatter::SIGN_BEFORE_CURRENCY: |
|
58 | - case LocaleFloatFormatter::SIGN_AFTER_CURRENCY: |
|
59 | - return "{$sign}{$number}"; |
|
60 | - case LocaleFloatFormatter::SIGN_AFTER_ALL: |
|
61 | - return "{$number}{$sign}"; |
|
62 | - } |
|
63 | - return $number; |
|
64 | - } |
|
37 | + /** |
|
38 | + * @param Locale $locale |
|
39 | + * @param int|float|string $number |
|
40 | + * @param bool $is_negative |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + protected function formatSymbolAndSignPositions(Locale $locale, $number, bool $is_negative) |
|
44 | + { |
|
45 | + // format for positive or negative values |
|
46 | + if ($is_negative) { |
|
47 | + $sign = $locale->negativeSign(); |
|
48 | + $position = $locale->negativeSignPosition(); |
|
49 | + } else { |
|
50 | + $sign = $locale->positiveSign(); |
|
51 | + $position = $locale->positiveSignPosition(); |
|
52 | + } |
|
53 | + switch ($position) { |
|
54 | + case LocaleFloatFormatter::PARENTHESES: |
|
55 | + return "({$number})"; |
|
56 | + case LocaleFloatFormatter::SIGN_BEFORE_ALL: |
|
57 | + case LocaleFloatFormatter::SIGN_BEFORE_CURRENCY: |
|
58 | + case LocaleFloatFormatter::SIGN_AFTER_CURRENCY: |
|
59 | + return "{$sign}{$number}"; |
|
60 | + case LocaleFloatFormatter::SIGN_AFTER_ALL: |
|
61 | + return "{$number}{$sign}"; |
|
62 | + } |
|
63 | + return $number; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * formats the provided number for the selected locale (defaults to site locale) and returns a string |
|
69 | - * |
|
70 | - * @param float|int|string $number unformatted number value, ex: 1234.56789 |
|
71 | - * @param int|null $precision the number of decimal places to round to |
|
72 | - * @param string|Locale $locale ex: 'en_US' or Locale object |
|
73 | - * @return string formatted value, ex: '1,234.57' |
|
74 | - */ |
|
75 | - public function formatForLocale($number, ?int $precision = null, $locale = ''): string |
|
76 | - { |
|
77 | - $locale = $this->locales->getLocale($locale); |
|
78 | - return $this->format($locale, (float) $number, $precision); |
|
79 | - } |
|
67 | + /** |
|
68 | + * formats the provided number for the selected locale (defaults to site locale) and returns a string |
|
69 | + * |
|
70 | + * @param float|int|string $number unformatted number value, ex: 1234.56789 |
|
71 | + * @param int|null $precision the number of decimal places to round to |
|
72 | + * @param string|Locale $locale ex: 'en_US' or Locale object |
|
73 | + * @return string formatted value, ex: '1,234.57' |
|
74 | + */ |
|
75 | + public function formatForLocale($number, ?int $precision = null, $locale = ''): string |
|
76 | + { |
|
77 | + $locale = $this->locales->getLocale($locale); |
|
78 | + return $this->format($locale, (float) $number, $precision); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * This removes all localized formatting from the incoming value and returns a float |
|
84 | - * |
|
85 | - * @param float|int|string $number formatted numeric value as string, ex: '1,234,567.89' |
|
86 | - * @param string|Locale $locale ex: 'en_US' or Locale object |
|
87 | - * @return float unformatted number value, ex: 1234567.89 |
|
88 | - */ |
|
89 | - public function parseForLocale($number, $locale = ''): float |
|
90 | - { |
|
91 | - // just return the value if it's not a string |
|
92 | - if (! is_string($number)) { |
|
93 | - return (float) $number; |
|
94 | - } |
|
95 | - $locale = $this->locales->getLocale($locale); |
|
96 | - return $this->filterNumericValue( |
|
97 | - str_replace( |
|
98 | - [ |
|
99 | - $locale->thousandsSeparator(), |
|
100 | - $locale->decimalPoint(), |
|
101 | - ], |
|
102 | - [ |
|
103 | - '', // remove thousands separator |
|
104 | - '.', // convert decimal mark to what PHP expects |
|
105 | - ], |
|
106 | - $number |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
82 | + /** |
|
83 | + * This removes all localized formatting from the incoming value and returns a float |
|
84 | + * |
|
85 | + * @param float|int|string $number formatted numeric value as string, ex: '1,234,567.89' |
|
86 | + * @param string|Locale $locale ex: 'en_US' or Locale object |
|
87 | + * @return float unformatted number value, ex: 1234567.89 |
|
88 | + */ |
|
89 | + public function parseForLocale($number, $locale = ''): float |
|
90 | + { |
|
91 | + // just return the value if it's not a string |
|
92 | + if (! is_string($number)) { |
|
93 | + return (float) $number; |
|
94 | + } |
|
95 | + $locale = $this->locales->getLocale($locale); |
|
96 | + return $this->filterNumericValue( |
|
97 | + str_replace( |
|
98 | + [ |
|
99 | + $locale->thousandsSeparator(), |
|
100 | + $locale->decimalPoint(), |
|
101 | + ], |
|
102 | + [ |
|
103 | + '', // remove thousands separator |
|
104 | + '.', // convert decimal mark to what PHP expects |
|
105 | + ], |
|
106 | + $number |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | 110 | } |
@@ -36,29 +36,29 @@ |
||
36 | 36 | protected function convertAscii($string): string |
37 | 37 | { |
38 | 38 | // Replace Single Curly Quotes |
39 | - $search[] = chr(226) . chr(128) . chr(152); |
|
39 | + $search[] = chr(226).chr(128).chr(152); |
|
40 | 40 | $replace[] = "'"; |
41 | - $search[] = chr(226) . chr(128) . chr(153); |
|
41 | + $search[] = chr(226).chr(128).chr(153); |
|
42 | 42 | $replace[] = "'"; |
43 | 43 | // Replace Smart Double Curly Quotes |
44 | - $search[] = chr(226) . chr(128) . chr(156); |
|
44 | + $search[] = chr(226).chr(128).chr(156); |
|
45 | 45 | $replace[] = '"'; |
46 | - $search[] = chr(226) . chr(128) . chr(157); |
|
46 | + $search[] = chr(226).chr(128).chr(157); |
|
47 | 47 | $replace[] = '"'; |
48 | 48 | // Replace En Dash |
49 | - $search[] = chr(226) . chr(128) . chr(147); |
|
49 | + $search[] = chr(226).chr(128).chr(147); |
|
50 | 50 | $replace[] = '--'; |
51 | 51 | // Replace Em Dash |
52 | - $search[] = chr(226) . chr(128) . chr(148); |
|
52 | + $search[] = chr(226).chr(128).chr(148); |
|
53 | 53 | $replace[] = '---'; |
54 | 54 | // Replace Bullet |
55 | - $search[] = chr(226) . chr(128) . chr(162); |
|
55 | + $search[] = chr(226).chr(128).chr(162); |
|
56 | 56 | $replace[] = '*'; |
57 | 57 | // Replace Middle Dot |
58 | - $search[] = chr(194) . chr(183); |
|
58 | + $search[] = chr(194).chr(183); |
|
59 | 59 | $replace[] = '*'; |
60 | 60 | // Replace Ellipsis with three consecutive dots |
61 | - $search[] = chr(226) . chr(128) . chr(166); |
|
61 | + $search[] = chr(226).chr(128).chr(166); |
|
62 | 62 | $replace[] = '...'; |
63 | 63 | // Apply Replacements |
64 | 64 | $string = str_replace($search, $replace, $string); |
@@ -12,56 +12,56 @@ |
||
12 | 12 | */ |
13 | 13 | class AsciiOnly extends FormatterBase |
14 | 14 | { |
15 | - /** |
|
16 | - * Removes all non Ascii characters from string |
|
17 | - * |
|
18 | - * @param string|int|float $input anything easily cast into a string |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function format($input): string |
|
22 | - { |
|
23 | - // in case an int or float etc was passed in |
|
24 | - $input = (string) $input; |
|
25 | - return $this->convertAscii($input); |
|
26 | - } |
|
15 | + /** |
|
16 | + * Removes all non Ascii characters from string |
|
17 | + * |
|
18 | + * @param string|int|float $input anything easily cast into a string |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function format($input): string |
|
22 | + { |
|
23 | + // in case an int or float etc was passed in |
|
24 | + $input = (string) $input; |
|
25 | + return $this->convertAscii($input); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Taken from https://gist.github.com/jaywilliams/119517 |
|
31 | - * |
|
32 | - * @param $string |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - protected function convertAscii($string): string |
|
36 | - { |
|
37 | - // Replace Single Curly Quotes |
|
38 | - $search[] = chr(226) . chr(128) . chr(152); |
|
39 | - $replace[] = "'"; |
|
40 | - $search[] = chr(226) . chr(128) . chr(153); |
|
41 | - $replace[] = "'"; |
|
42 | - // Replace Smart Double Curly Quotes |
|
43 | - $search[] = chr(226) . chr(128) . chr(156); |
|
44 | - $replace[] = '"'; |
|
45 | - $search[] = chr(226) . chr(128) . chr(157); |
|
46 | - $replace[] = '"'; |
|
47 | - // Replace En Dash |
|
48 | - $search[] = chr(226) . chr(128) . chr(147); |
|
49 | - $replace[] = '--'; |
|
50 | - // Replace Em Dash |
|
51 | - $search[] = chr(226) . chr(128) . chr(148); |
|
52 | - $replace[] = '---'; |
|
53 | - // Replace Bullet |
|
54 | - $search[] = chr(226) . chr(128) . chr(162); |
|
55 | - $replace[] = '*'; |
|
56 | - // Replace Middle Dot |
|
57 | - $search[] = chr(194) . chr(183); |
|
58 | - $replace[] = '*'; |
|
59 | - // Replace Ellipsis with three consecutive dots |
|
60 | - $search[] = chr(226) . chr(128) . chr(166); |
|
61 | - $replace[] = '...'; |
|
62 | - // Apply Replacements |
|
63 | - $string = str_replace($search, $replace, $string); |
|
64 | - // Remove any non-ASCII Characters |
|
65 | - return preg_replace("/[^\x01-\x7F]/", "", $string); |
|
66 | - } |
|
29 | + /** |
|
30 | + * Taken from https://gist.github.com/jaywilliams/119517 |
|
31 | + * |
|
32 | + * @param $string |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + protected function convertAscii($string): string |
|
36 | + { |
|
37 | + // Replace Single Curly Quotes |
|
38 | + $search[] = chr(226) . chr(128) . chr(152); |
|
39 | + $replace[] = "'"; |
|
40 | + $search[] = chr(226) . chr(128) . chr(153); |
|
41 | + $replace[] = "'"; |
|
42 | + // Replace Smart Double Curly Quotes |
|
43 | + $search[] = chr(226) . chr(128) . chr(156); |
|
44 | + $replace[] = '"'; |
|
45 | + $search[] = chr(226) . chr(128) . chr(157); |
|
46 | + $replace[] = '"'; |
|
47 | + // Replace En Dash |
|
48 | + $search[] = chr(226) . chr(128) . chr(147); |
|
49 | + $replace[] = '--'; |
|
50 | + // Replace Em Dash |
|
51 | + $search[] = chr(226) . chr(128) . chr(148); |
|
52 | + $replace[] = '---'; |
|
53 | + // Replace Bullet |
|
54 | + $search[] = chr(226) . chr(128) . chr(162); |
|
55 | + $replace[] = '*'; |
|
56 | + // Replace Middle Dot |
|
57 | + $search[] = chr(194) . chr(183); |
|
58 | + $replace[] = '*'; |
|
59 | + // Replace Ellipsis with three consecutive dots |
|
60 | + $search[] = chr(226) . chr(128) . chr(166); |
|
61 | + $replace[] = '...'; |
|
62 | + // Apply Replacements |
|
63 | + $string = str_replace($search, $replace, $string); |
|
64 | + // Remove any non-ASCII Characters |
|
65 | + return preg_replace("/[^\x01-\x7F]/", "", $string); |
|
66 | + } |
|
67 | 67 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $block->initialize(); |
163 | 163 | $this->trackAssetManagersForBlocks($block); |
164 | 164 | $asset_manager = $block->assetManager(); |
165 | - if (! $this->block_asset_manager_collection->contains($asset_manager)) { |
|
165 | + if ( ! $this->block_asset_manager_collection->contains($asset_manager)) { |
|
166 | 166 | $this->block_asset_manager_collection->add($asset_manager, get_class($asset_manager)); |
167 | 167 | $block->assetManager()->setAssetHandles(); |
168 | 168 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $supported_routes = $block->supportedRoutes(); |
185 | 185 | foreach ($supported_routes as $supported_route) { |
186 | 186 | if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
187 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | + $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace(); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | } |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function matchesRoute(BlockInterface $block) |
202 | 202 | { |
203 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | + if (isset($this->block_asset_managers[$block->blockType()])) { |
|
204 | 204 | return true; |
205 | 205 | } |
206 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | + unset($this->block_asset_managers[$block->blockType()]); |
|
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | try { |
220 | 220 | // cycle thru block loader folders |
221 | 221 | foreach ($this->blocks as $block) { |
222 | - if (! $this->matchesRoute($block)) { |
|
222 | + if ( ! $this->matchesRoute($block)) { |
|
223 | 223 | continue; |
224 | 224 | } |
225 | 225 | // perform any setup required for the block |
226 | 226 | $block_type = $block->registerBlock(); |
227 | - if (! $block_type instanceof WP_Block_Type) { |
|
227 | + if ( ! $block_type instanceof WP_Block_Type) { |
|
228 | 228 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
229 | 229 | } |
230 | 230 | do_action( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $assets = array_flip($this->block_asset_managers); |
244 | 244 | foreach ($this->block_asset_manager_collection as $asset_manager) { |
245 | 245 | // if there are no longer any blocks that require these assets, |
246 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | + if ( ! isset($assets[$asset_manager->assetNamespace()])) { |
|
247 | 247 | // then unset asset enqueueing and bail |
248 | 248 | remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
249 | 249 | remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
@@ -31,224 +31,224 @@ |
||
31 | 31 | */ |
32 | 32 | class BlockRegistrationManager extends BlockManager |
33 | 33 | { |
34 | - /** |
|
35 | - * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
36 | - */ |
|
37 | - protected $block_asset_manager_collection; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var RouteMatchSpecificationManager $route_manager |
|
41 | - */ |
|
42 | - protected $route_manager; |
|
43 | - |
|
44 | - /** |
|
45 | - * array for tracking asset managers required by blocks for the current route |
|
46 | - * |
|
47 | - * @var array $block_asset_managers |
|
48 | - */ |
|
49 | - protected $block_asset_managers = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * BlockRegistrationManager constructor. |
|
54 | - * |
|
55 | - * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
56 | - * @param BlockCollection $blocks |
|
57 | - * @param RouteMatchSpecificationManager $route_manager |
|
58 | - * @param RequestInterface $request |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - BlockAssetManagerCollection $block_asset_manager_collection, |
|
62 | - BlockCollection $blocks, |
|
63 | - RouteMatchSpecificationManager $route_manager, |
|
64 | - RequestInterface $request |
|
65 | - ) { |
|
66 | - $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
67 | - $this->route_manager = $route_manager; |
|
68 | - parent::__construct($blocks, $request); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Returns the name of a hookpoint to be used to call initialize() |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function initHook() |
|
78 | - { |
|
79 | - return 'AHEE__EE_System__initialize'; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Perform any early setup required for block editors to functions |
|
85 | - * |
|
86 | - * @return void |
|
87 | - * @throws Exception |
|
88 | - */ |
|
89 | - public function initialize() |
|
90 | - { |
|
91 | - $this->initializeBlocks(); |
|
92 | - add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
93 | - add_action('wp_loaded', array($this, 'unloadAssets')); |
|
94 | - add_filter('block_categories_all', array($this, 'addEspressoBlockCategories')); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param array $categories |
|
100 | - * @since 4.9.71.p |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function addEspressoBlockCategories(array $categories) |
|
104 | - { |
|
105 | - return array_merge( |
|
106 | - $categories, |
|
107 | - array( |
|
108 | - array( |
|
109 | - 'slug' => 'event-espresso', |
|
110 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
111 | - ), |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return CollectionInterface|BlockInterface[] |
|
119 | - * @throws CollectionLoaderException |
|
120 | - * @throws CollectionDetailsException |
|
121 | - */ |
|
122 | - protected function populateBlockCollection() |
|
123 | - { |
|
124 | - $loader = new CollectionLoader( |
|
125 | - new CollectionDetails( |
|
126 | - // collection name |
|
127 | - 'editor_blocks', |
|
128 | - // collection interface |
|
129 | - 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
130 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
131 | - apply_filters( |
|
132 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
133 | - array('EventEspresso\core\domain\entities\editor\blocks') |
|
134 | - ), |
|
135 | - // filepaths to classes to add |
|
136 | - array(), |
|
137 | - // file mask to use if parsing folder for files to add |
|
138 | - '', |
|
139 | - // what to use as identifier for collection entities |
|
140 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
141 | - CollectionDetails::ID_CLASS_NAME |
|
142 | - ), |
|
143 | - $this->blocks |
|
144 | - ); |
|
145 | - return $loader->getCollection(); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * populates the BlockCollection and calls initialize() on all installed blocks |
|
151 | - * |
|
152 | - * @return void |
|
153 | - * @throws Exception |
|
154 | - */ |
|
155 | - public function initializeBlocks() |
|
156 | - { |
|
157 | - try { |
|
158 | - $this->populateBlockCollection(); |
|
159 | - // cycle thru block loaders and initialize each loader |
|
160 | - foreach ($this->blocks as $block) { |
|
161 | - $block->initialize(); |
|
162 | - $this->trackAssetManagersForBlocks($block); |
|
163 | - $asset_manager = $block->assetManager(); |
|
164 | - if (! $this->block_asset_manager_collection->contains($asset_manager)) { |
|
165 | - $this->block_asset_manager_collection->add($asset_manager, get_class($asset_manager)); |
|
166 | - $block->assetManager()->setAssetHandles(); |
|
167 | - } |
|
168 | - } |
|
169 | - } catch (Exception $exception) { |
|
170 | - new ExceptionStackTraceDisplay($exception); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * track blocks with routes that match the current request |
|
177 | - * |
|
178 | - * @param BlockInterface $block |
|
179 | - * @throws InvalidClassException |
|
180 | - */ |
|
181 | - private function trackAssetManagersForBlocks(BlockInterface $block) |
|
182 | - { |
|
183 | - $supported_routes = $block->supportedRoutes(); |
|
184 | - foreach ($supported_routes as $supported_route) { |
|
185 | - if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
186 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * returns true if the block should be registered for the current request |
|
194 | - * else removes block from block_routes array and returns false |
|
195 | - * |
|
196 | - * @param BlockInterface $block |
|
197 | - * @return boolean |
|
198 | - * @throws InvalidClassException |
|
199 | - */ |
|
200 | - public function matchesRoute(BlockInterface $block) |
|
201 | - { |
|
202 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | - return true; |
|
204 | - } |
|
205 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | - return false; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * calls registerBlock() and load assets for all installed blocks |
|
212 | - * |
|
213 | - * @return void |
|
214 | - * @throws Exception |
|
215 | - */ |
|
216 | - public function registerBlocks() |
|
217 | - { |
|
218 | - try { |
|
219 | - // cycle thru block loader folders |
|
220 | - foreach ($this->blocks as $block) { |
|
221 | - if (! $this->matchesRoute($block)) { |
|
222 | - continue; |
|
223 | - } |
|
224 | - // perform any setup required for the block |
|
225 | - $block_type = $block->registerBlock(); |
|
226 | - if (! $block_type instanceof WP_Block_Type) { |
|
227 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
228 | - } |
|
229 | - do_action( |
|
230 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
231 | - $block, |
|
232 | - $block_type |
|
233 | - ); |
|
234 | - } |
|
235 | - } catch (Exception $exception) { |
|
236 | - new ExceptionStackTraceDisplay($exception); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - public function unloadAssets() |
|
241 | - { |
|
242 | - $assets = array_flip($this->block_asset_managers); |
|
243 | - foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
244 | - // if there are no longer any blocks that require these assets, |
|
245 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | - // then unset asset enqueueing and bail |
|
247 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
249 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
34 | + /** |
|
35 | + * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
36 | + */ |
|
37 | + protected $block_asset_manager_collection; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var RouteMatchSpecificationManager $route_manager |
|
41 | + */ |
|
42 | + protected $route_manager; |
|
43 | + |
|
44 | + /** |
|
45 | + * array for tracking asset managers required by blocks for the current route |
|
46 | + * |
|
47 | + * @var array $block_asset_managers |
|
48 | + */ |
|
49 | + protected $block_asset_managers = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * BlockRegistrationManager constructor. |
|
54 | + * |
|
55 | + * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
56 | + * @param BlockCollection $blocks |
|
57 | + * @param RouteMatchSpecificationManager $route_manager |
|
58 | + * @param RequestInterface $request |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + BlockAssetManagerCollection $block_asset_manager_collection, |
|
62 | + BlockCollection $blocks, |
|
63 | + RouteMatchSpecificationManager $route_manager, |
|
64 | + RequestInterface $request |
|
65 | + ) { |
|
66 | + $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
67 | + $this->route_manager = $route_manager; |
|
68 | + parent::__construct($blocks, $request); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Returns the name of a hookpoint to be used to call initialize() |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function initHook() |
|
78 | + { |
|
79 | + return 'AHEE__EE_System__initialize'; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Perform any early setup required for block editors to functions |
|
85 | + * |
|
86 | + * @return void |
|
87 | + * @throws Exception |
|
88 | + */ |
|
89 | + public function initialize() |
|
90 | + { |
|
91 | + $this->initializeBlocks(); |
|
92 | + add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
93 | + add_action('wp_loaded', array($this, 'unloadAssets')); |
|
94 | + add_filter('block_categories_all', array($this, 'addEspressoBlockCategories')); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param array $categories |
|
100 | + * @since 4.9.71.p |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function addEspressoBlockCategories(array $categories) |
|
104 | + { |
|
105 | + return array_merge( |
|
106 | + $categories, |
|
107 | + array( |
|
108 | + array( |
|
109 | + 'slug' => 'event-espresso', |
|
110 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
111 | + ), |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return CollectionInterface|BlockInterface[] |
|
119 | + * @throws CollectionLoaderException |
|
120 | + * @throws CollectionDetailsException |
|
121 | + */ |
|
122 | + protected function populateBlockCollection() |
|
123 | + { |
|
124 | + $loader = new CollectionLoader( |
|
125 | + new CollectionDetails( |
|
126 | + // collection name |
|
127 | + 'editor_blocks', |
|
128 | + // collection interface |
|
129 | + 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
130 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
131 | + apply_filters( |
|
132 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
133 | + array('EventEspresso\core\domain\entities\editor\blocks') |
|
134 | + ), |
|
135 | + // filepaths to classes to add |
|
136 | + array(), |
|
137 | + // file mask to use if parsing folder for files to add |
|
138 | + '', |
|
139 | + // what to use as identifier for collection entities |
|
140 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
141 | + CollectionDetails::ID_CLASS_NAME |
|
142 | + ), |
|
143 | + $this->blocks |
|
144 | + ); |
|
145 | + return $loader->getCollection(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * populates the BlockCollection and calls initialize() on all installed blocks |
|
151 | + * |
|
152 | + * @return void |
|
153 | + * @throws Exception |
|
154 | + */ |
|
155 | + public function initializeBlocks() |
|
156 | + { |
|
157 | + try { |
|
158 | + $this->populateBlockCollection(); |
|
159 | + // cycle thru block loaders and initialize each loader |
|
160 | + foreach ($this->blocks as $block) { |
|
161 | + $block->initialize(); |
|
162 | + $this->trackAssetManagersForBlocks($block); |
|
163 | + $asset_manager = $block->assetManager(); |
|
164 | + if (! $this->block_asset_manager_collection->contains($asset_manager)) { |
|
165 | + $this->block_asset_manager_collection->add($asset_manager, get_class($asset_manager)); |
|
166 | + $block->assetManager()->setAssetHandles(); |
|
167 | + } |
|
168 | + } |
|
169 | + } catch (Exception $exception) { |
|
170 | + new ExceptionStackTraceDisplay($exception); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * track blocks with routes that match the current request |
|
177 | + * |
|
178 | + * @param BlockInterface $block |
|
179 | + * @throws InvalidClassException |
|
180 | + */ |
|
181 | + private function trackAssetManagersForBlocks(BlockInterface $block) |
|
182 | + { |
|
183 | + $supported_routes = $block->supportedRoutes(); |
|
184 | + foreach ($supported_routes as $supported_route) { |
|
185 | + if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
186 | + $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * returns true if the block should be registered for the current request |
|
194 | + * else removes block from block_routes array and returns false |
|
195 | + * |
|
196 | + * @param BlockInterface $block |
|
197 | + * @return boolean |
|
198 | + * @throws InvalidClassException |
|
199 | + */ |
|
200 | + public function matchesRoute(BlockInterface $block) |
|
201 | + { |
|
202 | + if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | + return true; |
|
204 | + } |
|
205 | + unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | + return false; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * calls registerBlock() and load assets for all installed blocks |
|
212 | + * |
|
213 | + * @return void |
|
214 | + * @throws Exception |
|
215 | + */ |
|
216 | + public function registerBlocks() |
|
217 | + { |
|
218 | + try { |
|
219 | + // cycle thru block loader folders |
|
220 | + foreach ($this->blocks as $block) { |
|
221 | + if (! $this->matchesRoute($block)) { |
|
222 | + continue; |
|
223 | + } |
|
224 | + // perform any setup required for the block |
|
225 | + $block_type = $block->registerBlock(); |
|
226 | + if (! $block_type instanceof WP_Block_Type) { |
|
227 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
228 | + } |
|
229 | + do_action( |
|
230 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
231 | + $block, |
|
232 | + $block_type |
|
233 | + ); |
|
234 | + } |
|
235 | + } catch (Exception $exception) { |
|
236 | + new ExceptionStackTraceDisplay($exception); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + public function unloadAssets() |
|
241 | + { |
|
242 | + $assets = array_flip($this->block_asset_managers); |
|
243 | + foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
244 | + // if there are no longer any blocks that require these assets, |
|
245 | + if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | + // then unset asset enqueueing and bail |
|
247 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
249 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | if ($locale_changed !== false) { |
37 | 37 | $locale = localeconv(); |
38 | 38 | $locale['locale_name'] = $locale_name; |
39 | - $this->locales[ $locale_name ] = $locale; |
|
39 | + $this->locales[$locale_name] = $locale; |
|
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | return false; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getLocale(string $locale_name, int $allow_recurse = 2): array |
110 | 110 | { |
111 | - if (! isset($this->locales[ $locale_name ])) { |
|
111 | + if ( ! isset($this->locales[$locale_name])) { |
|
112 | 112 | $this->stashCurrentSystemLocales(); |
113 | 113 | $charsets = $this->getLocaleCharsets(); |
114 | 114 | // some systems use dashes and some use underscores for the locale names, ie: "en_US" vs "en-US" |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | } |
125 | 125 | $this->resetSystemLocales(); |
126 | 126 | } |
127 | - if (isset($this->locales[ $locale_name ])) { |
|
128 | - return $this->locales[ $locale_name ]; |
|
127 | + if (isset($this->locales[$locale_name])) { |
|
128 | + return $this->locales[$locale_name]; |
|
129 | 129 | } |
130 | 130 | // if our second attempt to get a locale failed, then try one more time using the site locale |
131 | 131 | if ($allow_recurse === 2) { |
@@ -16,127 +16,127 @@ |
||
16 | 16 | */ |
17 | 17 | class LocaleSwitcher implements InterminableInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $current_system_locales = []; |
|
19 | + /** |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $current_system_locales = []; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $locales = []; |
|
24 | + /** |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $locales = []; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param string $locale_name |
|
32 | - * @param string $charset |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - private function changeLocale(string $locale_name, string $charset): bool |
|
36 | - { |
|
37 | - $locale_changed = setlocale(LC_ALL, "{$locale_name}.{$charset}"); |
|
38 | - if ($locale_changed !== false) { |
|
39 | - $locale = localeconv(); |
|
40 | - $locale['locale_name'] = $locale_name; |
|
41 | - $this->locales[ $locale_name ] = $locale; |
|
42 | - return true; |
|
43 | - } |
|
44 | - return false; |
|
45 | - } |
|
30 | + /** |
|
31 | + * @param string $locale_name |
|
32 | + * @param string $charset |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + private function changeLocale(string $locale_name, string $charset): bool |
|
36 | + { |
|
37 | + $locale_changed = setlocale(LC_ALL, "{$locale_name}.{$charset}"); |
|
38 | + if ($locale_changed !== false) { |
|
39 | + $locale = localeconv(); |
|
40 | + $locale['locale_name'] = $locale_name; |
|
41 | + $this->locales[ $locale_name ] = $locale; |
|
42 | + return true; |
|
43 | + } |
|
44 | + return false; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - private function getLocaleCharsets(): array |
|
52 | - { |
|
53 | - return (array) apply_filters( |
|
54 | - 'FHEE_EventEspresso_core_services_formatters_Locale__getLocaleCharsets__charsets', |
|
55 | - [ |
|
56 | - 'UTF-8', |
|
57 | - 'UTF8', |
|
58 | - 'utf-8', |
|
59 | - 'utf8', |
|
60 | - 'iso88591', |
|
61 | - ] |
|
62 | - ); |
|
63 | - } |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + private function getLocaleCharsets(): array |
|
52 | + { |
|
53 | + return (array) apply_filters( |
|
54 | + 'FHEE_EventEspresso_core_services_formatters_Locale__getLocaleCharsets__charsets', |
|
55 | + [ |
|
56 | + 'UTF-8', |
|
57 | + 'UTF8', |
|
58 | + 'utf-8', |
|
59 | + 'utf8', |
|
60 | + 'iso88591', |
|
61 | + ] |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * returns the locale settings to their previous value |
|
68 | - * |
|
69 | - * @link https://www.php.net/manual/en/function.setlocale.php#106811 |
|
70 | - */ |
|
71 | - private function resetSystemLocales() |
|
72 | - { |
|
73 | - foreach ($this->current_system_locales as $locale_setting) { |
|
74 | - if (strpos($locale_setting, '=') !== false) { |
|
75 | - [$category, $locale] = explode('=', $locale_setting); |
|
76 | - } else { |
|
77 | - $category = LC_ALL; |
|
78 | - $locale = $locale_setting; |
|
79 | - } |
|
80 | - setlocale(absint($category), $locale); |
|
81 | - } |
|
82 | - } |
|
66 | + /** |
|
67 | + * returns the locale settings to their previous value |
|
68 | + * |
|
69 | + * @link https://www.php.net/manual/en/function.setlocale.php#106811 |
|
70 | + */ |
|
71 | + private function resetSystemLocales() |
|
72 | + { |
|
73 | + foreach ($this->current_system_locales as $locale_setting) { |
|
74 | + if (strpos($locale_setting, '=') !== false) { |
|
75 | + [$category, $locale] = explode('=', $locale_setting); |
|
76 | + } else { |
|
77 | + $category = LC_ALL; |
|
78 | + $locale = $locale_setting; |
|
79 | + } |
|
80 | + setlocale(absint($category), $locale); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * stashes the current locale settings so that they can be reset later |
|
87 | - * |
|
88 | - * @link https://www.php.net/manual/en/function.setlocale.php#106811 |
|
89 | - */ |
|
90 | - private function stashCurrentSystemLocales() |
|
91 | - { |
|
92 | - // passing "0" for second parameter of setlocale() |
|
93 | - // returns the current settings as opposed to setting anything ¯\_(ツ)_/¯ |
|
94 | - $current_system_locales = setlocale(LC_ALL, 0); |
|
95 | - $this->current_system_locales = explode(';', $current_system_locales); |
|
96 | - } |
|
85 | + /** |
|
86 | + * stashes the current locale settings so that they can be reset later |
|
87 | + * |
|
88 | + * @link https://www.php.net/manual/en/function.setlocale.php#106811 |
|
89 | + */ |
|
90 | + private function stashCurrentSystemLocales() |
|
91 | + { |
|
92 | + // passing "0" for second parameter of setlocale() |
|
93 | + // returns the current settings as opposed to setting anything ¯\_(ツ)_/¯ |
|
94 | + $current_system_locales = setlocale(LC_ALL, 0); |
|
95 | + $this->current_system_locales = explode(';', $current_system_locales); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * stashes the current locale settings |
|
101 | - * switches to the provided locale |
|
102 | - * retrieves ALL details for the provided locale |
|
103 | - * caches the retrieved data using the provided locale value as the key |
|
104 | - * resets the locale to its original value |
|
105 | - * returns the requested locale data |
|
106 | - * |
|
107 | - * @param string $locale_name |
|
108 | - * @param int $allow_recurse |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function getLocale(string $locale_name, int $allow_recurse = 2): array |
|
112 | - { |
|
113 | - if (! isset($this->locales[ $locale_name ])) { |
|
114 | - $this->stashCurrentSystemLocales(); |
|
115 | - $charsets = $this->getLocaleCharsets(); |
|
116 | - // some systems use dashes and some use underscores for the locale names, ie: "en_US" vs "en-US" |
|
117 | - $alternate_locale = strpos($locale_name, '_') |
|
118 | - ? str_replace('_', '-', $locale_name) |
|
119 | - : str_replace('-', '_', $locale_name); |
|
120 | - foreach ($charsets as $charset) { |
|
121 | - // if the first locale gets set, then the conditional will short-circuit and break the loop |
|
122 | - // otherwise we'll try again with the alternate locale name |
|
123 | - if ($this->changeLocale($locale_name, $charset) || $this->changeLocale($alternate_locale, $charset)) { |
|
124 | - break; |
|
125 | - } |
|
126 | - } |
|
127 | - $this->resetSystemLocales(); |
|
128 | - } |
|
129 | - if (isset($this->locales[ $locale_name ])) { |
|
130 | - return $this->locales[ $locale_name ]; |
|
131 | - } |
|
132 | - // if our second attempt to get a locale failed, then try one more time using the site locale |
|
133 | - if ($allow_recurse === 2) { |
|
134 | - return $this->getLocale(get_locale(), 1); |
|
135 | - } |
|
136 | - // if the above doesn't work then the locale likely isn't installed on the server. |
|
137 | - // we'll try "en_US" and if that doesn't work then the server is definitely not configured properly, |
|
138 | - // or the customer is trying to use a language on a server in a country that doesn't speak that language... |
|
139 | - // like trying to use English on a server in Australia! :drop-bear-emoji: |
|
140 | - return $allow_recurse ? $this->getLocale('en_US', 0) : []; |
|
141 | - } |
|
99 | + /** |
|
100 | + * stashes the current locale settings |
|
101 | + * switches to the provided locale |
|
102 | + * retrieves ALL details for the provided locale |
|
103 | + * caches the retrieved data using the provided locale value as the key |
|
104 | + * resets the locale to its original value |
|
105 | + * returns the requested locale data |
|
106 | + * |
|
107 | + * @param string $locale_name |
|
108 | + * @param int $allow_recurse |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function getLocale(string $locale_name, int $allow_recurse = 2): array |
|
112 | + { |
|
113 | + if (! isset($this->locales[ $locale_name ])) { |
|
114 | + $this->stashCurrentSystemLocales(); |
|
115 | + $charsets = $this->getLocaleCharsets(); |
|
116 | + // some systems use dashes and some use underscores for the locale names, ie: "en_US" vs "en-US" |
|
117 | + $alternate_locale = strpos($locale_name, '_') |
|
118 | + ? str_replace('_', '-', $locale_name) |
|
119 | + : str_replace('-', '_', $locale_name); |
|
120 | + foreach ($charsets as $charset) { |
|
121 | + // if the first locale gets set, then the conditional will short-circuit and break the loop |
|
122 | + // otherwise we'll try again with the alternate locale name |
|
123 | + if ($this->changeLocale($locale_name, $charset) || $this->changeLocale($alternate_locale, $charset)) { |
|
124 | + break; |
|
125 | + } |
|
126 | + } |
|
127 | + $this->resetSystemLocales(); |
|
128 | + } |
|
129 | + if (isset($this->locales[ $locale_name ])) { |
|
130 | + return $this->locales[ $locale_name ]; |
|
131 | + } |
|
132 | + // if our second attempt to get a locale failed, then try one more time using the site locale |
|
133 | + if ($allow_recurse === 2) { |
|
134 | + return $this->getLocale(get_locale(), 1); |
|
135 | + } |
|
136 | + // if the above doesn't work then the locale likely isn't installed on the server. |
|
137 | + // we'll try "en_US" and if that doesn't work then the server is definitely not configured properly, |
|
138 | + // or the customer is trying to use a language on a server in a country that doesn't speak that language... |
|
139 | + // like trying to use English on a server in Australia! :drop-bear-emoji: |
|
140 | + return $allow_recurse ? $this->getLocale('en_US', 0) : []; |
|
141 | + } |
|
142 | 142 | } |
@@ -14,462 +14,462 @@ |
||
14 | 14 | */ |
15 | 15 | class Locale |
16 | 16 | { |
17 | - /** |
|
18 | - * Monetary decimal point character |
|
19 | - */ |
|
20 | - const CURRENCY_DECIMAL_POINT = 'mon_decimal_point'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Array containing monetary groupings |
|
24 | - */ |
|
25 | - const CURRENCY_GROUPING = 'mon_grouping'; |
|
26 | - |
|
27 | - /** |
|
28 | - * International currency code (ex: USD) |
|
29 | - */ |
|
30 | - const CURRENCY_ISO_CODE = 'int_curr_symbol'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Local currency symbol (ex: $) |
|
34 | - */ |
|
35 | - const CURRENCY_SYMBOL = 'currency_symbol'; |
|
36 | - |
|
37 | - /** |
|
38 | - * true if currency_symbol precedes a positive value, false if it succeeds one |
|
39 | - */ |
|
40 | - const CURRENCY_SYMBOL_B4_POSITIVE = 'p_cs_precedes'; |
|
41 | - |
|
42 | - /** |
|
43 | - * true if a space separates currency_symbol from a positive value, false otherwise |
|
44 | - */ |
|
45 | - const CURRENCY_SYMBOL_SPACE_B4_POSITIVE = 'p_sep_by_space'; |
|
46 | - |
|
47 | - /** |
|
48 | - * true if currency_symbol precedes a negative value, false if it succeeds one |
|
49 | - */ |
|
50 | - const CURRENCY_SYMBOL_B4_NEGATIVE = 'n_cs_precedes'; |
|
51 | - |
|
52 | - /** |
|
53 | - * true if a space separates currency_symbol from a negative value, false otherwise |
|
54 | - */ |
|
55 | - const CURRENCY_SYMBOL_SPACE_B4_NEGATIVE = 'n_sep_by_space'; |
|
56 | - |
|
57 | - /** |
|
58 | - * Monetary thousands separator |
|
59 | - */ |
|
60 | - const CURRENCY_THOUSANDS_SEP = 'mon_thousands_sep'; |
|
61 | - |
|
62 | - /** |
|
63 | - * International fractional digits (number of decimal places) |
|
64 | - */ |
|
65 | - const INTL_DECIMAL_PRECISION = 'int_frac_digits'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Local fractional digits (number of decimal places) |
|
69 | - */ |
|
70 | - const LOCAL_DECIMAL_PRECISION = 'frac_digits'; |
|
71 | - |
|
72 | - /** |
|
73 | - * Sign for negative values |
|
74 | - */ |
|
75 | - const NEGATIVE_SIGN = 'negative_sign'; |
|
76 | - |
|
77 | - /** |
|
78 | - * 0 - Parentheses surround the quantity and currency_symbol |
|
79 | - * 1 - The sign string precedes the quantity and currency_symbol |
|
80 | - * 2 - The sign string succeeds the quantity and currency_symbol |
|
81 | - * 3 - The sign string immediately precedes the currency_symbol |
|
82 | - * 4 - The sign string immediately succeeds the currency_symbol |
|
83 | - */ |
|
84 | - const NEGATIVE_SIGN_POSITION = 'n_sign_posn'; |
|
85 | - |
|
86 | - /** |
|
87 | - * Decimal point character |
|
88 | - */ |
|
89 | - const NUMBER_DECIMAL_POINT = 'decimal_point'; |
|
90 | - |
|
91 | - /** |
|
92 | - * Array containing numeric groupings |
|
93 | - */ |
|
94 | - const NUMBER_GROUPING = 'grouping'; |
|
95 | - |
|
96 | - /** |
|
97 | - * Thousands separator |
|
98 | - */ |
|
99 | - const NUMBER_THOUSANDS_SEP = 'thousands_sep'; |
|
100 | - |
|
101 | - /** |
|
102 | - * Sign for positive values |
|
103 | - */ |
|
104 | - const POSITIVE_SIGN = 'positive_sign'; |
|
105 | - |
|
106 | - /** |
|
107 | - * 0 - Parentheses surround the quantity and currency_symbol |
|
108 | - * 1 - The sign string precedes the quantity and currency_symbol |
|
109 | - * 2 - The sign string succeeds the quantity and currency_symbol |
|
110 | - * 3 - The sign string immediately precedes the currency_symbol |
|
111 | - * 4 - The sign string immediately succeeds the currency_symbol |
|
112 | - */ |
|
113 | - const POSITIVE_SIGN_POSITION = 'p_sign_posn'; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var array |
|
117 | - */ |
|
118 | - protected $locale_info; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var string |
|
122 | - */ |
|
123 | - protected $locale_name; |
|
124 | - |
|
125 | - /** |
|
126 | - * @var string |
|
127 | - */ |
|
128 | - protected $currency_decimal_point; |
|
129 | - |
|
130 | - /** |
|
131 | - * @var int |
|
132 | - */ |
|
133 | - protected $currency_grouping; |
|
134 | - |
|
135 | - /** |
|
136 | - * @var string |
|
137 | - */ |
|
138 | - protected $currency_iso_code; |
|
139 | - |
|
140 | - /** |
|
141 | - * @var string |
|
142 | - */ |
|
143 | - protected $currency_symbol; |
|
144 | - |
|
145 | - /** |
|
146 | - * @var bool |
|
147 | - */ |
|
148 | - protected $currency_symbol_b4_negative; |
|
149 | - |
|
150 | - /** |
|
151 | - * @var bool |
|
152 | - */ |
|
153 | - protected $currency_symbol_b4_positive; |
|
154 | - |
|
155 | - /** |
|
156 | - * @var bool |
|
157 | - */ |
|
158 | - protected $currency_symbol_space_b4_negative; |
|
159 | - |
|
160 | - /** |
|
161 | - * @var bool |
|
162 | - */ |
|
163 | - protected $currency_symbol_space_b4_positive; |
|
164 | - |
|
165 | - /** |
|
166 | - * @var string |
|
167 | - */ |
|
168 | - protected $currency_thousands_separator; |
|
169 | - |
|
170 | - /** |
|
171 | - * @var int |
|
172 | - */ |
|
173 | - protected $intl_decimal_precision; |
|
174 | - |
|
175 | - /** |
|
176 | - * @var int |
|
177 | - */ |
|
178 | - protected $local_decimal_precision; |
|
179 | - |
|
180 | - /** |
|
181 | - * @var string |
|
182 | - */ |
|
183 | - protected $negative_sign; |
|
184 | - |
|
185 | - /** |
|
186 | - * @var int |
|
187 | - */ |
|
188 | - protected $negative_sign_position; |
|
189 | - |
|
190 | - /** |
|
191 | - * @var string |
|
192 | - */ |
|
193 | - protected $number_decimal_point; |
|
194 | - |
|
195 | - /** |
|
196 | - * @var int |
|
197 | - */ |
|
198 | - protected $number_grouping; |
|
199 | - |
|
200 | - /** |
|
201 | - * @var string |
|
202 | - */ |
|
203 | - protected $number_thousands_separator; |
|
204 | - |
|
205 | - /** |
|
206 | - * @var string |
|
207 | - */ |
|
208 | - protected $positive_sign; |
|
209 | - |
|
210 | - /** |
|
211 | - * @var int |
|
212 | - */ |
|
213 | - protected $positive_sign_position; |
|
214 | - |
|
215 | - |
|
216 | - protected static $property_key_map = [ |
|
217 | - Locale::CURRENCY_DECIMAL_POINT => 'currency_decimal_point', |
|
218 | - Locale::CURRENCY_GROUPING => 'currency_grouping', |
|
219 | - Locale::CURRENCY_ISO_CODE => 'currency_iso_code', |
|
220 | - Locale::CURRENCY_SYMBOL => 'currency_symbol', |
|
221 | - Locale::CURRENCY_SYMBOL_B4_NEGATIVE => 'currency_symbol_b4_negative', |
|
222 | - Locale::CURRENCY_SYMBOL_B4_POSITIVE => 'currency_symbol_b4_positive', |
|
223 | - Locale::CURRENCY_SYMBOL_SPACE_B4_NEGATIVE => 'currency_symbol_space_b4_negative', |
|
224 | - Locale::CURRENCY_SYMBOL_SPACE_B4_POSITIVE => 'currency_symbol_space_b4_positive', |
|
225 | - Locale::CURRENCY_THOUSANDS_SEP => 'currency_thousands_separator', |
|
226 | - Locale::INTL_DECIMAL_PRECISION => 'intl_decimal_precision', |
|
227 | - Locale::LOCAL_DECIMAL_PRECISION => 'local_decimal_precision', |
|
228 | - Locale::NUMBER_DECIMAL_POINT => 'number_decimal_point', |
|
229 | - Locale::NUMBER_GROUPING => 'number_grouping', |
|
230 | - Locale::NUMBER_THOUSANDS_SEP => 'number_thousands_separator', |
|
231 | - Locale::NEGATIVE_SIGN => 'negative_sign', |
|
232 | - Locale::NEGATIVE_SIGN_POSITION => 'negative_sign_position', |
|
233 | - Locale::POSITIVE_SIGN => 'positive_sign', |
|
234 | - Locale::POSITIVE_SIGN_POSITION => 'positive_sign_position', |
|
235 | - ]; |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Locale constructor. |
|
240 | - * |
|
241 | - * @param string $locale_name |
|
242 | - * @param array $locale_info |
|
243 | - * @param array $defaults |
|
244 | - */ |
|
245 | - public function __construct(string $locale_name, array $locale_info, array $defaults) |
|
246 | - { |
|
247 | - $this->locale_info = $locale_info; |
|
248 | - $this->locale_name = $this->locale_info['locale_name'] ?? $locale_name; |
|
249 | - |
|
250 | - foreach (Locale::$property_key_map as $key => $property) { |
|
251 | - $value = ''; |
|
252 | - if (isset($key, $this->locale_info)) { |
|
253 | - $value = $this->locale_info[ $key ]; |
|
254 | - } elseif (isset($key, $defaults)) { |
|
255 | - $value = $defaults[ $key ]; |
|
256 | - } |
|
257 | - $value = is_array($value) ? reset($value) : $value; |
|
258 | - // replace any space characters (nbsp, NNBSP, etc) with regular spaces |
|
259 | - $value = preg_replace('/[\s]+/mu', " ", $value); |
|
260 | - $this->{$property} = trim($value); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return string[] |
|
267 | - */ |
|
268 | - private function validLocaleInfoKeys(): array |
|
269 | - { |
|
270 | - return array_keys(Locale::$property_key_map); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param string $info_key |
|
276 | - * @throws DomainException |
|
277 | - */ |
|
278 | - private function validateLocaleInfoKeys(string $info_key) |
|
279 | - { |
|
280 | - if (! in_array($info_key, $this->validLocaleInfoKeys())) { |
|
281 | - throw new DomainException( |
|
282 | - sprintf( |
|
283 | - esc_html__( |
|
284 | - '"%1$s" is not a valid key for retrieving locale information. Please use one of the "Locale::*" constants.', |
|
285 | - 'event_espresso' |
|
286 | - ), |
|
287 | - $info_key |
|
288 | - ) |
|
289 | - ); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $key |
|
296 | - * @param int|float|string $default |
|
297 | - * @return string |
|
298 | - */ |
|
299 | - public function getLocaleInfo(string $key = '', $default = '') |
|
300 | - { |
|
301 | - $this->validateLocaleInfoKeys($key); |
|
302 | - return array_key_exists($key, $this->locale_info) ? $this->locale_info[ $key ] : $default; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * @return string |
|
308 | - */ |
|
309 | - public function currencyDecimalPoint(): string |
|
310 | - { |
|
311 | - return $this->currency_decimal_point; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * @return int |
|
317 | - */ |
|
318 | - public function currencyGrouping(): int |
|
319 | - { |
|
320 | - return $this->currency_grouping; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function currencyIsoCode(): string |
|
328 | - { |
|
329 | - return $this->currency_iso_code; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * @return string |
|
335 | - */ |
|
336 | - public function currencySymbol(): string |
|
337 | - { |
|
338 | - return $this->currency_symbol; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @return bool |
|
344 | - */ |
|
345 | - public function currencySymbolB4Negative(): bool |
|
346 | - { |
|
347 | - return $this->currency_symbol_b4_negative; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * @return bool |
|
353 | - */ |
|
354 | - public function currencySymbolB4Positive(): bool |
|
355 | - { |
|
356 | - return $this->currency_symbol_b4_positive; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * @return bool |
|
362 | - */ |
|
363 | - public function currencySymbolSpaceB4Negative(): bool |
|
364 | - { |
|
365 | - return $this->currency_symbol_space_b4_negative; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @return bool |
|
371 | - */ |
|
372 | - public function currencySymbolSpaceB4Positive(): bool |
|
373 | - { |
|
374 | - return $this->currency_symbol_space_b4_positive; |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function currencyThousandsSeparator(): string |
|
382 | - { |
|
383 | - return $this->currency_thousands_separator; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function decimalPoint(): string |
|
391 | - { |
|
392 | - return $this->number_decimal_point; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @return int |
|
398 | - */ |
|
399 | - public function decimalPrecision(): int |
|
400 | - { |
|
401 | - return $this->local_decimal_precision; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @return int |
|
407 | - */ |
|
408 | - public function internationalDecimalPrecision(): int |
|
409 | - { |
|
410 | - return $this->intl_decimal_precision; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @return int |
|
416 | - */ |
|
417 | - public function grouping(): int |
|
418 | - { |
|
419 | - return $this->number_grouping; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function name(): string |
|
427 | - { |
|
428 | - return $this->locale_name; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function negativeSign(): string |
|
436 | - { |
|
437 | - return $this->negative_sign; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * @return int |
|
443 | - */ |
|
444 | - public function negativeSignPosition(): int |
|
445 | - { |
|
446 | - return $this->negative_sign_position; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @return string |
|
452 | - */ |
|
453 | - public function positiveSign(): string |
|
454 | - { |
|
455 | - return $this->positive_sign; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @return int |
|
461 | - */ |
|
462 | - public function positiveSignPosition(): int |
|
463 | - { |
|
464 | - return $this->positive_sign_position; |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @return string |
|
470 | - */ |
|
471 | - public function thousandsSeparator(): string |
|
472 | - { |
|
473 | - return $this->number_thousands_separator; |
|
474 | - } |
|
17 | + /** |
|
18 | + * Monetary decimal point character |
|
19 | + */ |
|
20 | + const CURRENCY_DECIMAL_POINT = 'mon_decimal_point'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Array containing monetary groupings |
|
24 | + */ |
|
25 | + const CURRENCY_GROUPING = 'mon_grouping'; |
|
26 | + |
|
27 | + /** |
|
28 | + * International currency code (ex: USD) |
|
29 | + */ |
|
30 | + const CURRENCY_ISO_CODE = 'int_curr_symbol'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Local currency symbol (ex: $) |
|
34 | + */ |
|
35 | + const CURRENCY_SYMBOL = 'currency_symbol'; |
|
36 | + |
|
37 | + /** |
|
38 | + * true if currency_symbol precedes a positive value, false if it succeeds one |
|
39 | + */ |
|
40 | + const CURRENCY_SYMBOL_B4_POSITIVE = 'p_cs_precedes'; |
|
41 | + |
|
42 | + /** |
|
43 | + * true if a space separates currency_symbol from a positive value, false otherwise |
|
44 | + */ |
|
45 | + const CURRENCY_SYMBOL_SPACE_B4_POSITIVE = 'p_sep_by_space'; |
|
46 | + |
|
47 | + /** |
|
48 | + * true if currency_symbol precedes a negative value, false if it succeeds one |
|
49 | + */ |
|
50 | + const CURRENCY_SYMBOL_B4_NEGATIVE = 'n_cs_precedes'; |
|
51 | + |
|
52 | + /** |
|
53 | + * true if a space separates currency_symbol from a negative value, false otherwise |
|
54 | + */ |
|
55 | + const CURRENCY_SYMBOL_SPACE_B4_NEGATIVE = 'n_sep_by_space'; |
|
56 | + |
|
57 | + /** |
|
58 | + * Monetary thousands separator |
|
59 | + */ |
|
60 | + const CURRENCY_THOUSANDS_SEP = 'mon_thousands_sep'; |
|
61 | + |
|
62 | + /** |
|
63 | + * International fractional digits (number of decimal places) |
|
64 | + */ |
|
65 | + const INTL_DECIMAL_PRECISION = 'int_frac_digits'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Local fractional digits (number of decimal places) |
|
69 | + */ |
|
70 | + const LOCAL_DECIMAL_PRECISION = 'frac_digits'; |
|
71 | + |
|
72 | + /** |
|
73 | + * Sign for negative values |
|
74 | + */ |
|
75 | + const NEGATIVE_SIGN = 'negative_sign'; |
|
76 | + |
|
77 | + /** |
|
78 | + * 0 - Parentheses surround the quantity and currency_symbol |
|
79 | + * 1 - The sign string precedes the quantity and currency_symbol |
|
80 | + * 2 - The sign string succeeds the quantity and currency_symbol |
|
81 | + * 3 - The sign string immediately precedes the currency_symbol |
|
82 | + * 4 - The sign string immediately succeeds the currency_symbol |
|
83 | + */ |
|
84 | + const NEGATIVE_SIGN_POSITION = 'n_sign_posn'; |
|
85 | + |
|
86 | + /** |
|
87 | + * Decimal point character |
|
88 | + */ |
|
89 | + const NUMBER_DECIMAL_POINT = 'decimal_point'; |
|
90 | + |
|
91 | + /** |
|
92 | + * Array containing numeric groupings |
|
93 | + */ |
|
94 | + const NUMBER_GROUPING = 'grouping'; |
|
95 | + |
|
96 | + /** |
|
97 | + * Thousands separator |
|
98 | + */ |
|
99 | + const NUMBER_THOUSANDS_SEP = 'thousands_sep'; |
|
100 | + |
|
101 | + /** |
|
102 | + * Sign for positive values |
|
103 | + */ |
|
104 | + const POSITIVE_SIGN = 'positive_sign'; |
|
105 | + |
|
106 | + /** |
|
107 | + * 0 - Parentheses surround the quantity and currency_symbol |
|
108 | + * 1 - The sign string precedes the quantity and currency_symbol |
|
109 | + * 2 - The sign string succeeds the quantity and currency_symbol |
|
110 | + * 3 - The sign string immediately precedes the currency_symbol |
|
111 | + * 4 - The sign string immediately succeeds the currency_symbol |
|
112 | + */ |
|
113 | + const POSITIVE_SIGN_POSITION = 'p_sign_posn'; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var array |
|
117 | + */ |
|
118 | + protected $locale_info; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var string |
|
122 | + */ |
|
123 | + protected $locale_name; |
|
124 | + |
|
125 | + /** |
|
126 | + * @var string |
|
127 | + */ |
|
128 | + protected $currency_decimal_point; |
|
129 | + |
|
130 | + /** |
|
131 | + * @var int |
|
132 | + */ |
|
133 | + protected $currency_grouping; |
|
134 | + |
|
135 | + /** |
|
136 | + * @var string |
|
137 | + */ |
|
138 | + protected $currency_iso_code; |
|
139 | + |
|
140 | + /** |
|
141 | + * @var string |
|
142 | + */ |
|
143 | + protected $currency_symbol; |
|
144 | + |
|
145 | + /** |
|
146 | + * @var bool |
|
147 | + */ |
|
148 | + protected $currency_symbol_b4_negative; |
|
149 | + |
|
150 | + /** |
|
151 | + * @var bool |
|
152 | + */ |
|
153 | + protected $currency_symbol_b4_positive; |
|
154 | + |
|
155 | + /** |
|
156 | + * @var bool |
|
157 | + */ |
|
158 | + protected $currency_symbol_space_b4_negative; |
|
159 | + |
|
160 | + /** |
|
161 | + * @var bool |
|
162 | + */ |
|
163 | + protected $currency_symbol_space_b4_positive; |
|
164 | + |
|
165 | + /** |
|
166 | + * @var string |
|
167 | + */ |
|
168 | + protected $currency_thousands_separator; |
|
169 | + |
|
170 | + /** |
|
171 | + * @var int |
|
172 | + */ |
|
173 | + protected $intl_decimal_precision; |
|
174 | + |
|
175 | + /** |
|
176 | + * @var int |
|
177 | + */ |
|
178 | + protected $local_decimal_precision; |
|
179 | + |
|
180 | + /** |
|
181 | + * @var string |
|
182 | + */ |
|
183 | + protected $negative_sign; |
|
184 | + |
|
185 | + /** |
|
186 | + * @var int |
|
187 | + */ |
|
188 | + protected $negative_sign_position; |
|
189 | + |
|
190 | + /** |
|
191 | + * @var string |
|
192 | + */ |
|
193 | + protected $number_decimal_point; |
|
194 | + |
|
195 | + /** |
|
196 | + * @var int |
|
197 | + */ |
|
198 | + protected $number_grouping; |
|
199 | + |
|
200 | + /** |
|
201 | + * @var string |
|
202 | + */ |
|
203 | + protected $number_thousands_separator; |
|
204 | + |
|
205 | + /** |
|
206 | + * @var string |
|
207 | + */ |
|
208 | + protected $positive_sign; |
|
209 | + |
|
210 | + /** |
|
211 | + * @var int |
|
212 | + */ |
|
213 | + protected $positive_sign_position; |
|
214 | + |
|
215 | + |
|
216 | + protected static $property_key_map = [ |
|
217 | + Locale::CURRENCY_DECIMAL_POINT => 'currency_decimal_point', |
|
218 | + Locale::CURRENCY_GROUPING => 'currency_grouping', |
|
219 | + Locale::CURRENCY_ISO_CODE => 'currency_iso_code', |
|
220 | + Locale::CURRENCY_SYMBOL => 'currency_symbol', |
|
221 | + Locale::CURRENCY_SYMBOL_B4_NEGATIVE => 'currency_symbol_b4_negative', |
|
222 | + Locale::CURRENCY_SYMBOL_B4_POSITIVE => 'currency_symbol_b4_positive', |
|
223 | + Locale::CURRENCY_SYMBOL_SPACE_B4_NEGATIVE => 'currency_symbol_space_b4_negative', |
|
224 | + Locale::CURRENCY_SYMBOL_SPACE_B4_POSITIVE => 'currency_symbol_space_b4_positive', |
|
225 | + Locale::CURRENCY_THOUSANDS_SEP => 'currency_thousands_separator', |
|
226 | + Locale::INTL_DECIMAL_PRECISION => 'intl_decimal_precision', |
|
227 | + Locale::LOCAL_DECIMAL_PRECISION => 'local_decimal_precision', |
|
228 | + Locale::NUMBER_DECIMAL_POINT => 'number_decimal_point', |
|
229 | + Locale::NUMBER_GROUPING => 'number_grouping', |
|
230 | + Locale::NUMBER_THOUSANDS_SEP => 'number_thousands_separator', |
|
231 | + Locale::NEGATIVE_SIGN => 'negative_sign', |
|
232 | + Locale::NEGATIVE_SIGN_POSITION => 'negative_sign_position', |
|
233 | + Locale::POSITIVE_SIGN => 'positive_sign', |
|
234 | + Locale::POSITIVE_SIGN_POSITION => 'positive_sign_position', |
|
235 | + ]; |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Locale constructor. |
|
240 | + * |
|
241 | + * @param string $locale_name |
|
242 | + * @param array $locale_info |
|
243 | + * @param array $defaults |
|
244 | + */ |
|
245 | + public function __construct(string $locale_name, array $locale_info, array $defaults) |
|
246 | + { |
|
247 | + $this->locale_info = $locale_info; |
|
248 | + $this->locale_name = $this->locale_info['locale_name'] ?? $locale_name; |
|
249 | + |
|
250 | + foreach (Locale::$property_key_map as $key => $property) { |
|
251 | + $value = ''; |
|
252 | + if (isset($key, $this->locale_info)) { |
|
253 | + $value = $this->locale_info[ $key ]; |
|
254 | + } elseif (isset($key, $defaults)) { |
|
255 | + $value = $defaults[ $key ]; |
|
256 | + } |
|
257 | + $value = is_array($value) ? reset($value) : $value; |
|
258 | + // replace any space characters (nbsp, NNBSP, etc) with regular spaces |
|
259 | + $value = preg_replace('/[\s]+/mu', " ", $value); |
|
260 | + $this->{$property} = trim($value); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return string[] |
|
267 | + */ |
|
268 | + private function validLocaleInfoKeys(): array |
|
269 | + { |
|
270 | + return array_keys(Locale::$property_key_map); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param string $info_key |
|
276 | + * @throws DomainException |
|
277 | + */ |
|
278 | + private function validateLocaleInfoKeys(string $info_key) |
|
279 | + { |
|
280 | + if (! in_array($info_key, $this->validLocaleInfoKeys())) { |
|
281 | + throw new DomainException( |
|
282 | + sprintf( |
|
283 | + esc_html__( |
|
284 | + '"%1$s" is not a valid key for retrieving locale information. Please use one of the "Locale::*" constants.', |
|
285 | + 'event_espresso' |
|
286 | + ), |
|
287 | + $info_key |
|
288 | + ) |
|
289 | + ); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $key |
|
296 | + * @param int|float|string $default |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public function getLocaleInfo(string $key = '', $default = '') |
|
300 | + { |
|
301 | + $this->validateLocaleInfoKeys($key); |
|
302 | + return array_key_exists($key, $this->locale_info) ? $this->locale_info[ $key ] : $default; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * @return string |
|
308 | + */ |
|
309 | + public function currencyDecimalPoint(): string |
|
310 | + { |
|
311 | + return $this->currency_decimal_point; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * @return int |
|
317 | + */ |
|
318 | + public function currencyGrouping(): int |
|
319 | + { |
|
320 | + return $this->currency_grouping; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function currencyIsoCode(): string |
|
328 | + { |
|
329 | + return $this->currency_iso_code; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * @return string |
|
335 | + */ |
|
336 | + public function currencySymbol(): string |
|
337 | + { |
|
338 | + return $this->currency_symbol; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @return bool |
|
344 | + */ |
|
345 | + public function currencySymbolB4Negative(): bool |
|
346 | + { |
|
347 | + return $this->currency_symbol_b4_negative; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * @return bool |
|
353 | + */ |
|
354 | + public function currencySymbolB4Positive(): bool |
|
355 | + { |
|
356 | + return $this->currency_symbol_b4_positive; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * @return bool |
|
362 | + */ |
|
363 | + public function currencySymbolSpaceB4Negative(): bool |
|
364 | + { |
|
365 | + return $this->currency_symbol_space_b4_negative; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @return bool |
|
371 | + */ |
|
372 | + public function currencySymbolSpaceB4Positive(): bool |
|
373 | + { |
|
374 | + return $this->currency_symbol_space_b4_positive; |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function currencyThousandsSeparator(): string |
|
382 | + { |
|
383 | + return $this->currency_thousands_separator; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function decimalPoint(): string |
|
391 | + { |
|
392 | + return $this->number_decimal_point; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @return int |
|
398 | + */ |
|
399 | + public function decimalPrecision(): int |
|
400 | + { |
|
401 | + return $this->local_decimal_precision; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @return int |
|
407 | + */ |
|
408 | + public function internationalDecimalPrecision(): int |
|
409 | + { |
|
410 | + return $this->intl_decimal_precision; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @return int |
|
416 | + */ |
|
417 | + public function grouping(): int |
|
418 | + { |
|
419 | + return $this->number_grouping; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function name(): string |
|
427 | + { |
|
428 | + return $this->locale_name; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function negativeSign(): string |
|
436 | + { |
|
437 | + return $this->negative_sign; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * @return int |
|
443 | + */ |
|
444 | + public function negativeSignPosition(): int |
|
445 | + { |
|
446 | + return $this->negative_sign_position; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @return string |
|
452 | + */ |
|
453 | + public function positiveSign(): string |
|
454 | + { |
|
455 | + return $this->positive_sign; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @return int |
|
461 | + */ |
|
462 | + public function positiveSignPosition(): int |
|
463 | + { |
|
464 | + return $this->positive_sign_position; |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @return string |
|
470 | + */ |
|
471 | + public function thousandsSeparator(): string |
|
472 | + { |
|
473 | + return $this->number_thousands_separator; |
|
474 | + } |
|
475 | 475 | } |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | foreach (Locale::$property_key_map as $key => $property) { |
251 | 251 | $value = ''; |
252 | 252 | if (isset($key, $this->locale_info)) { |
253 | - $value = $this->locale_info[ $key ]; |
|
253 | + $value = $this->locale_info[$key]; |
|
254 | 254 | } elseif (isset($key, $defaults)) { |
255 | - $value = $defaults[ $key ]; |
|
255 | + $value = $defaults[$key]; |
|
256 | 256 | } |
257 | 257 | $value = is_array($value) ? reset($value) : $value; |
258 | 258 | // replace any space characters (nbsp, NNBSP, etc) with regular spaces |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | */ |
278 | 278 | private function validateLocaleInfoKeys(string $info_key) |
279 | 279 | { |
280 | - if (! in_array($info_key, $this->validLocaleInfoKeys())) { |
|
280 | + if ( ! in_array($info_key, $this->validLocaleInfoKeys())) { |
|
281 | 281 | throw new DomainException( |
282 | 282 | sprintf( |
283 | 283 | esc_html__( |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | public function getLocaleInfo(string $key = '', $default = '') |
300 | 300 | { |
301 | 301 | $this->validateLocaleInfoKeys($key); |
302 | - return array_key_exists($key, $this->locale_info) ? $this->locale_info[ $key ] : $default; |
|
302 | + return array_key_exists($key, $this->locale_info) ? $this->locale_info[$key] : $default; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 |
@@ -14,57 +14,57 @@ |
||
14 | 14 | */ |
15 | 15 | class DefaultLocaleData |
16 | 16 | { |
17 | - /** |
|
18 | - * @var EE_Currency_Config |
|
19 | - */ |
|
20 | - private $currency_config; |
|
17 | + /** |
|
18 | + * @var EE_Currency_Config |
|
19 | + */ |
|
20 | + private $currency_config; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * DefaultLocaleData constructor. |
|
25 | - * |
|
26 | - * @param EE_Currency_Config $currency_config |
|
27 | - */ |
|
28 | - public function __construct(EE_Currency_Config $currency_config) |
|
29 | - { |
|
30 | - $this->currency_config = $currency_config; |
|
31 | - } |
|
23 | + /** |
|
24 | + * DefaultLocaleData constructor. |
|
25 | + * |
|
26 | + * @param EE_Currency_Config $currency_config |
|
27 | + */ |
|
28 | + public function __construct(EE_Currency_Config $currency_config) |
|
29 | + { |
|
30 | + $this->currency_config = $currency_config; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function getDefaultLocale(): string |
|
38 | - { |
|
39 | - return $this->currency_config->locale(); |
|
40 | - } |
|
34 | + /** |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function getDefaultLocale(): string |
|
38 | + { |
|
39 | + return $this->currency_config->locale(); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function getDefaults(): array |
|
47 | - { |
|
48 | - // if locale info is missing, then fall back to legacy money formatting details |
|
49 | - return [ |
|
50 | - Locale::CURRENCY_DECIMAL_POINT => $this->currency_config->dec_plc, |
|
51 | - Locale::CURRENCY_GROUPING => 3, |
|
52 | - Locale::CURRENCY_ISO_CODE => $this->currency_config->code, |
|
53 | - Locale::CURRENCY_SYMBOL => $this->currency_config->sign, |
|
54 | - Locale::CURRENCY_SYMBOL_B4_NEGATIVE => $this->currency_config->sign_b4, |
|
55 | - Locale::CURRENCY_SYMBOL_B4_POSITIVE => $this->currency_config->sign_b4, |
|
56 | - Locale::CURRENCY_SYMBOL_SPACE_B4_NEGATIVE => true, |
|
57 | - Locale::CURRENCY_SYMBOL_SPACE_B4_POSITIVE => true, |
|
58 | - Locale::CURRENCY_THOUSANDS_SEP => $this->currency_config->thsnds, |
|
59 | - Locale::INTL_DECIMAL_PRECISION => $this->currency_config->dec_plc, |
|
60 | - Locale::LOCAL_DECIMAL_PRECISION => $this->currency_config->dec_plc, |
|
61 | - Locale::NUMBER_DECIMAL_POINT => $this->currency_config->dec_mrk, |
|
62 | - Locale::NUMBER_GROUPING => 3, |
|
63 | - Locale::NUMBER_THOUSANDS_SEP => $this->currency_config->thsnds, |
|
64 | - Locale::NEGATIVE_SIGN => '-', |
|
65 | - Locale::NEGATIVE_SIGN_POSITION => 1, |
|
66 | - Locale::POSITIVE_SIGN => '', |
|
67 | - Locale::POSITIVE_SIGN_POSITION => 1, |
|
68 | - ]; |
|
69 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function getDefaults(): array |
|
47 | + { |
|
48 | + // if locale info is missing, then fall back to legacy money formatting details |
|
49 | + return [ |
|
50 | + Locale::CURRENCY_DECIMAL_POINT => $this->currency_config->dec_plc, |
|
51 | + Locale::CURRENCY_GROUPING => 3, |
|
52 | + Locale::CURRENCY_ISO_CODE => $this->currency_config->code, |
|
53 | + Locale::CURRENCY_SYMBOL => $this->currency_config->sign, |
|
54 | + Locale::CURRENCY_SYMBOL_B4_NEGATIVE => $this->currency_config->sign_b4, |
|
55 | + Locale::CURRENCY_SYMBOL_B4_POSITIVE => $this->currency_config->sign_b4, |
|
56 | + Locale::CURRENCY_SYMBOL_SPACE_B4_NEGATIVE => true, |
|
57 | + Locale::CURRENCY_SYMBOL_SPACE_B4_POSITIVE => true, |
|
58 | + Locale::CURRENCY_THOUSANDS_SEP => $this->currency_config->thsnds, |
|
59 | + Locale::INTL_DECIMAL_PRECISION => $this->currency_config->dec_plc, |
|
60 | + Locale::LOCAL_DECIMAL_PRECISION => $this->currency_config->dec_plc, |
|
61 | + Locale::NUMBER_DECIMAL_POINT => $this->currency_config->dec_mrk, |
|
62 | + Locale::NUMBER_GROUPING => 3, |
|
63 | + Locale::NUMBER_THOUSANDS_SEP => $this->currency_config->thsnds, |
|
64 | + Locale::NEGATIVE_SIGN => '-', |
|
65 | + Locale::NEGATIVE_SIGN_POSITION => 1, |
|
66 | + Locale::POSITIVE_SIGN => '', |
|
67 | + Locale::POSITIVE_SIGN_POSITION => 1, |
|
68 | + ]; |
|
69 | + } |
|
70 | 70 | } |