Completed
Branch FET-10619-money-entity (c56734)
by
unknown
157:04 queued 143:03
created
modules/ticket_selector/TicketSelectorRowStandard.php 1 patch
Indentation   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -19,404 +19,404 @@
 block discarded – undo
19 19
 class TicketSelectorRowStandard extends TicketSelectorRow
20 20
 {
21 21
 
22
-    /**
23
-     * @var TicketDetails $ticket_details
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var \EE_Ticket_Selector_Config $template_settings
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var \EE_Tax_Config $tax_settings
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var boolean $prices_displayed_including_taxes
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int $row
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int $cols
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean $hidden_input_qty
54
-     */
55
-    protected $hidden_input_qty;
56
-
57
-    /**
58
-     * @var string $ticket_datetime_classes
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-
64
-    /**
65
-     * TicketDetails constructor.
66
-     *
67
-     * @param TicketDetails  $ticket_details
68
-     * @param \EE_Tax_Config $tax_settings
69
-     * @param int            $total_tickets
70
-     * @param int            $max_atndz
71
-     * @param int            $row
72
-     * @param int            $cols
73
-     * @param boolean        $required_ticket_sold_out
74
-     * @param string         $event_status
75
-     * @param string         $ticket_datetime_classes
76
-     * @throws EE_Error
77
-     * @throws UnexpectedEntityException
78
-     */
79
-    public function __construct(
80
-        TicketDetails $ticket_details,
81
-        \EE_Tax_Config $tax_settings,
82
-        $total_tickets,
83
-        $max_atndz,
84
-        $row,
85
-        $cols,
86
-        $required_ticket_sold_out,
87
-        $event_status,
88
-        $ticket_datetime_classes
89
-    ) {
90
-        $this->ticket = $ticket_details->getTicket();
91
-        $this->ticket_details = $ticket_details;
92
-        $this->template_settings = $ticket_details->getTemplateSettings();
93
-        $this->tax_settings = $tax_settings;
94
-        $this->total_tickets = $total_tickets;
95
-        $this->max_atndz = $max_atndz;
96
-        $this->row = $row;
97
-        $this->cols = $cols;
98
-        $this->date_format = $ticket_details->getDateFormat();
99
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
100
-        parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * other ticket rows will need to know if a required ticket is sold out,
107
-     * so that they are not offered for sale
108
-     *
109
-     * @return boolean
110
-     */
111
-    public function getRequiredTicketSoldOut()
112
-    {
113
-        return $this->required_ticket_sold_out;
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * getHtml
130
-     *
131
-     * @return string
132
-     * @throws EE_Error
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $min = 0;
137
-        $max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
-            list($min, $max) = $this->setTicketMinAndMax($remaining);
141
-        } else {
142
-            // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
-            $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
-                ? $this->ticket->start_date()
145
-                : $this->required_ticket_sold_out;
146
-        }
147
-        list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
-        list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
-        /**
150
-         * Allow plugins to hook in and abort the generation and display of this row to do
151
-         * something else if they want.
152
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
153
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
-         * current row.
155
-         *
156
-         * @var string|bool
157
-         */
158
-        $ticket_selector_row_html = apply_filters(
159
-            'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
-            false,
161
-            $this->ticket,
162
-            $max,
163
-            $min,
164
-            $this->required_ticket_sold_out,
165
-            $ticket_price,
166
-            $ticket_bundle,
167
-            $ticket_status,
168
-            $status_class
169
-        );
170
-        if ($ticket_selector_row_html !== false) {
171
-            return $ticket_selector_row_html;
172
-        }
173
-        $ticket_selector_row_html = \EEH_HTML::tr(
174
-            '', '',
175
-            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
-        );
177
-        /**
178
-         * Allow plugins to hook in and abort the generation and display of the contents of this
179
-         * row to do something else if they want.
180
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
181
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
-         * current row.
183
-         *
184
-         * @var string|bool
185
-         */
186
-        $new_row_cells_content = apply_filters(
187
-            'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
-            false,
189
-            $this->ticket,
190
-            $max,
191
-            $min,
192
-            $this->required_ticket_sold_out,
193
-            $ticket_price,
194
-            $ticket_bundle,
195
-            $ticket_status,
196
-            $status_class
197
-        );
198
-        if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
-            return $ticket_selector_row_html
200
-                   . $new_row_cells_content
201
-                   . $this->ticketQtyAndIdHiddenInputs()
202
-                   . \EEH_HTML::trx();
203
-        }
204
-        if ($new_row_cells_content !== false) {
205
-            return $ticket_selector_row_html
206
-                   . $new_row_cells_content
207
-                   . \EEH_HTML::trx();
208
-        }
209
-        $this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
-
211
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
212
-        $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
-        $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
-        if (empty($this->ticket_status_display)) {
216
-            if ($this->max_atndz === 1) {
217
-                // only ONE attendee is allowed to register at a time
218
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
-            } else if ($max > 0) {
220
-                $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
-            }
222
-        }
223
-        $ticket_selector_row_html .= $this->ticket_status_display;
224
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
-        $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
-        $ticket_selector_row_html .= \EEH_HTML::tdx();
227
-        $ticket_selector_row_html .= \EEH_HTML::trx();
228
-
229
-
230
-        $this->row++;
231
-        return $ticket_selector_row_html;
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * setTicketMinAndMax
238
-     *
239
-     * @param int $remaining
240
-     * @return array
241
-     * @throws EE_Error
242
-     */
243
-    protected function setTicketMinAndMax($remaining)
244
-    {
245
-        // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
-        $max = min($remaining, $this->max_atndz);
247
-        // but... we also want to restrict the number of tickets by the ticket max setting,
248
-        // however, the max still can't be higher than what was just set above
249
-        $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
-        // and we also want to restrict the minimum number of tickets by the ticket min setting
251
-        $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
-        // and if the ticket is required, then make sure that min qty is at least 1
253
-        $min = $this->ticket->required() ? max($min, 1) : $min;
254
-        return array($min, $max);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * getTicketPriceDetails
261
-     *
262
-     * @return array
263
-     * @throws EE_Error
264
-     */
265
-    protected function getTicketPriceDetails()
266
-    {
267
-        $ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
-            ? $this->ticket->get_ticket_total_with_taxes()
269
-            : $this->ticket->get_ticket_subtotal();
270
-        $ticket_bundle = false;
271
-        $ticket_min = $this->ticket->min();
272
-        // for ticket bundles, set min and max qty the same
273
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
-            $ticket_price *= $ticket_min;
275
-            $ticket_bundle = true;
276
-        }
277
-        $ticket_price = apply_filters(
278
-            'FHEE__ticket_selector_chart_template__ticket_price',
279
-            $ticket_price,
280
-            $this->ticket
281
-        );
282
-        return array($ticket_price, $ticket_bundle);
283
-    }
284
-
285
-
286
-
287
-
288
-    /**
289
-     * ticketNameTableCell
290
-     *
291
-     * @return string
292
-     * @throws EE_Error
293
-     */
294
-    protected function ticketNameTableCell()
295
-    {
296
-        $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
-        $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
-        $html .= $this->ticket_details->getShowHideLinks();
299
-        if ($this->ticket->required()) {
300
-            $html .= \EEH_HTML::p(
301
-                    apply_filters(
302
-                            'FHEE__ticket_selector_chart_template__ticket_required_message',
303
-                            esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
-                    ),
305
-                    '', 'ticket-required-pg'
306
-            );
307
-        }
308
-        $html .= \EEH_HTML::tdx();
309
-        return $html;
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * ticketPriceTableCell
316
-     *
317
-     * @param float $ticket_price
318
-     * @param bool  $ticket_bundle
319
-     * @return string
320
-     * @throws EE_Error
321
-     */
322
-    protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
-    {
324
-        $html = '';
325
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
-            $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
-            $html .= \EEH_Template::format_currency($ticket_price);
328
-            $html .= $this->ticket->taxable()
329
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
-                : '';
331
-            $html .= ' ';
332
-            $html .= \EEH_HTML::span(
333
-                $ticket_bundle
334
-                    ? apply_filters(
335
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
-                        __(' / bundle', 'event_espresso')
337
-                    )
338
-                    : apply_filters(
339
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
340
-                        __('', 'event_espresso')
341
-                    ),
342
-                '', 'smaller-text no-bold'
343
-            );
344
-            $html .= ' ';
345
-            $html .= \EEH_HTML::tdx();
346
-            $this->cols++;
347
-        }
348
-        return $html;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * onlyOneAttendeeCanRegister
355
-     *
356
-     * @return string
357
-     */
358
-    protected function onlyOneAttendeeCanRegister()
359
-    {
360
-        // display submit button since we have tickets available
361
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
-        $this->hidden_input_qty = false;
363
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
-        $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
-        $html .= ' title=""/>';
368
-        return $html;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * ticketQuantitySelector
375
-     *
376
-     * @param int $min
377
-     * @param int $max
378
-     * @return string
379
-     * @throws EE_Error
380
-     */
381
-    protected function ticketQuantitySelector($min = 0, $max = 0)
382
-    {
383
-        // display submit button since we have tickets available
384
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
-        $this->hidden_input_qty = false;
386
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
-        $html .= ' class="ticket-selector-tbl-qty-slct">';
389
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
-        if ($min !== 0 && ! $this->ticket->required()) {
391
-            $html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
-        }
393
-        // offer ticket quantities from the min to the max
394
-        for ($i = $min; $i <= $max; $i++) {
395
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
-        }
397
-        $html .= '</select>';
398
-        return $html;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * getHiddenInputs
405
-     *
406
-     * @return string
407
-     * @throws EE_Error
408
-     */
409
-    protected function ticketQtyAndIdHiddenInputs()
410
-    {
411
-        $html = '';
412
-        // depending on group reg we need to change the format for qty
413
-        if ($this->hidden_input_qty) {
414
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
-        }
416
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
418
-        return $html;
419
-    }
22
+	/**
23
+	 * @var TicketDetails $ticket_details
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var \EE_Ticket_Selector_Config $template_settings
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var \EE_Tax_Config $tax_settings
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var boolean $prices_displayed_including_taxes
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int $row
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int $cols
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean $hidden_input_qty
54
+	 */
55
+	protected $hidden_input_qty;
56
+
57
+	/**
58
+	 * @var string $ticket_datetime_classes
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+
64
+	/**
65
+	 * TicketDetails constructor.
66
+	 *
67
+	 * @param TicketDetails  $ticket_details
68
+	 * @param \EE_Tax_Config $tax_settings
69
+	 * @param int            $total_tickets
70
+	 * @param int            $max_atndz
71
+	 * @param int            $row
72
+	 * @param int            $cols
73
+	 * @param boolean        $required_ticket_sold_out
74
+	 * @param string         $event_status
75
+	 * @param string         $ticket_datetime_classes
76
+	 * @throws EE_Error
77
+	 * @throws UnexpectedEntityException
78
+	 */
79
+	public function __construct(
80
+		TicketDetails $ticket_details,
81
+		\EE_Tax_Config $tax_settings,
82
+		$total_tickets,
83
+		$max_atndz,
84
+		$row,
85
+		$cols,
86
+		$required_ticket_sold_out,
87
+		$event_status,
88
+		$ticket_datetime_classes
89
+	) {
90
+		$this->ticket = $ticket_details->getTicket();
91
+		$this->ticket_details = $ticket_details;
92
+		$this->template_settings = $ticket_details->getTemplateSettings();
93
+		$this->tax_settings = $tax_settings;
94
+		$this->total_tickets = $total_tickets;
95
+		$this->max_atndz = $max_atndz;
96
+		$this->row = $row;
97
+		$this->cols = $cols;
98
+		$this->date_format = $ticket_details->getDateFormat();
99
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
100
+		parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * other ticket rows will need to know if a required ticket is sold out,
107
+	 * so that they are not offered for sale
108
+	 *
109
+	 * @return boolean
110
+	 */
111
+	public function getRequiredTicketSoldOut()
112
+	{
113
+		return $this->required_ticket_sold_out;
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * getHtml
130
+	 *
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$min = 0;
137
+		$max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
+			list($min, $max) = $this->setTicketMinAndMax($remaining);
141
+		} else {
142
+			// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
+			$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
+				? $this->ticket->start_date()
145
+				: $this->required_ticket_sold_out;
146
+		}
147
+		list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
+		list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
+		/**
150
+		 * Allow plugins to hook in and abort the generation and display of this row to do
151
+		 * something else if they want.
152
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
153
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
+		 * current row.
155
+		 *
156
+		 * @var string|bool
157
+		 */
158
+		$ticket_selector_row_html = apply_filters(
159
+			'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
+			false,
161
+			$this->ticket,
162
+			$max,
163
+			$min,
164
+			$this->required_ticket_sold_out,
165
+			$ticket_price,
166
+			$ticket_bundle,
167
+			$ticket_status,
168
+			$status_class
169
+		);
170
+		if ($ticket_selector_row_html !== false) {
171
+			return $ticket_selector_row_html;
172
+		}
173
+		$ticket_selector_row_html = \EEH_HTML::tr(
174
+			'', '',
175
+			"tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
+		);
177
+		/**
178
+		 * Allow plugins to hook in and abort the generation and display of the contents of this
179
+		 * row to do something else if they want.
180
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
181
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
+		 * current row.
183
+		 *
184
+		 * @var string|bool
185
+		 */
186
+		$new_row_cells_content = apply_filters(
187
+			'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
+			false,
189
+			$this->ticket,
190
+			$max,
191
+			$min,
192
+			$this->required_ticket_sold_out,
193
+			$ticket_price,
194
+			$ticket_bundle,
195
+			$ticket_status,
196
+			$status_class
197
+		);
198
+		if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
+			return $ticket_selector_row_html
200
+				   . $new_row_cells_content
201
+				   . $this->ticketQtyAndIdHiddenInputs()
202
+				   . \EEH_HTML::trx();
203
+		}
204
+		if ($new_row_cells_content !== false) {
205
+			return $ticket_selector_row_html
206
+				   . $new_row_cells_content
207
+				   . \EEH_HTML::trx();
208
+		}
209
+		$this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
+
211
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
212
+		$ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
+		$ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
+		if (empty($this->ticket_status_display)) {
216
+			if ($this->max_atndz === 1) {
217
+				// only ONE attendee is allowed to register at a time
218
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
+			} else if ($max > 0) {
220
+				$ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
+			}
222
+		}
223
+		$ticket_selector_row_html .= $this->ticket_status_display;
224
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
+		$ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
+		$ticket_selector_row_html .= \EEH_HTML::tdx();
227
+		$ticket_selector_row_html .= \EEH_HTML::trx();
228
+
229
+
230
+		$this->row++;
231
+		return $ticket_selector_row_html;
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * setTicketMinAndMax
238
+	 *
239
+	 * @param int $remaining
240
+	 * @return array
241
+	 * @throws EE_Error
242
+	 */
243
+	protected function setTicketMinAndMax($remaining)
244
+	{
245
+		// offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
+		$max = min($remaining, $this->max_atndz);
247
+		// but... we also want to restrict the number of tickets by the ticket max setting,
248
+		// however, the max still can't be higher than what was just set above
249
+		$max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
+		// and we also want to restrict the minimum number of tickets by the ticket min setting
251
+		$min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
+		// and if the ticket is required, then make sure that min qty is at least 1
253
+		$min = $this->ticket->required() ? max($min, 1) : $min;
254
+		return array($min, $max);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * getTicketPriceDetails
261
+	 *
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 */
265
+	protected function getTicketPriceDetails()
266
+	{
267
+		$ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
+			? $this->ticket->get_ticket_total_with_taxes()
269
+			: $this->ticket->get_ticket_subtotal();
270
+		$ticket_bundle = false;
271
+		$ticket_min = $this->ticket->min();
272
+		// for ticket bundles, set min and max qty the same
273
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
+			$ticket_price *= $ticket_min;
275
+			$ticket_bundle = true;
276
+		}
277
+		$ticket_price = apply_filters(
278
+			'FHEE__ticket_selector_chart_template__ticket_price',
279
+			$ticket_price,
280
+			$this->ticket
281
+		);
282
+		return array($ticket_price, $ticket_bundle);
283
+	}
284
+
285
+
286
+
287
+
288
+	/**
289
+	 * ticketNameTableCell
290
+	 *
291
+	 * @return string
292
+	 * @throws EE_Error
293
+	 */
294
+	protected function ticketNameTableCell()
295
+	{
296
+		$html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
+		$html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
+		$html .= $this->ticket_details->getShowHideLinks();
299
+		if ($this->ticket->required()) {
300
+			$html .= \EEH_HTML::p(
301
+					apply_filters(
302
+							'FHEE__ticket_selector_chart_template__ticket_required_message',
303
+							esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
+					),
305
+					'', 'ticket-required-pg'
306
+			);
307
+		}
308
+		$html .= \EEH_HTML::tdx();
309
+		return $html;
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * ticketPriceTableCell
316
+	 *
317
+	 * @param float $ticket_price
318
+	 * @param bool  $ticket_bundle
319
+	 * @return string
320
+	 * @throws EE_Error
321
+	 */
322
+	protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
+	{
324
+		$html = '';
325
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
+			$html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
+			$html .= \EEH_Template::format_currency($ticket_price);
328
+			$html .= $this->ticket->taxable()
329
+				? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
+				: '';
331
+			$html .= '&nbsp;';
332
+			$html .= \EEH_HTML::span(
333
+				$ticket_bundle
334
+					? apply_filters(
335
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
+						__(' / bundle', 'event_espresso')
337
+					)
338
+					: apply_filters(
339
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
340
+						__('', 'event_espresso')
341
+					),
342
+				'', 'smaller-text no-bold'
343
+			);
344
+			$html .= '&nbsp;';
345
+			$html .= \EEH_HTML::tdx();
346
+			$this->cols++;
347
+		}
348
+		return $html;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * onlyOneAttendeeCanRegister
355
+	 *
356
+	 * @return string
357
+	 */
358
+	protected function onlyOneAttendeeCanRegister()
359
+	{
360
+		// display submit button since we have tickets available
361
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
+		$this->hidden_input_qty = false;
363
+		$html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
+		$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
+		$html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
+		$html .= ' title=""/>';
368
+		return $html;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * ticketQuantitySelector
375
+	 *
376
+	 * @param int $min
377
+	 * @param int $max
378
+	 * @return string
379
+	 * @throws EE_Error
380
+	 */
381
+	protected function ticketQuantitySelector($min = 0, $max = 0)
382
+	{
383
+		// display submit button since we have tickets available
384
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
+		$this->hidden_input_qty = false;
386
+		$html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
+		$html .= ' class="ticket-selector-tbl-qty-slct">';
389
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
+		if ($min !== 0 && ! $this->ticket->required()) {
391
+			$html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
+		}
393
+		// offer ticket quantities from the min to the max
394
+		for ($i = $min; $i <= $max; $i++) {
395
+			$html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
+		}
397
+		$html .= '</select>';
398
+		return $html;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * getHiddenInputs
405
+	 *
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 */
409
+	protected function ticketQtyAndIdHiddenInputs()
410
+	{
411
+		$html = '';
412
+		// depending on group reg we need to change the format for qty
413
+		if ($this->hidden_input_qty) {
414
+			$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
+		}
416
+		$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
+		$html .= ' value="' . $this->ticket->ID() . '"/>';
418
+		return $html;
419
+	}
420 420
 
421 421
 }
422 422
 // End of file TicketSelectorRowStandard.php
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/rpc/Checkin.php 2 patches
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 use EventEspresso\core\libraries\rest_api\controllers\model\Read;
15 15
 
16 16
 if (! defined('EVENT_ESPRESSO_VERSION')) {
17
-    exit('No direct script access allowed');
17
+	exit('No direct script access allowed');
18 18
 }
19 19
 
20 20
 
@@ -31,116 +31,116 @@  discard block
 block discarded – undo
31 31
 class Checkin extends Base
32 32
 {
33 33
 
34
-    /**
35
-     * @param WP_REST_Request $request
36
-     * @return WP_Error|WP_REST_Response
37
-     */
38
-    public static function handle_request_toggle_checkin(WP_REST_Request $request)
39
-    {
40
-        $controller = new Checkin();
41
-        return $controller->_create_checkin_checkout_object($request);
42
-    }
34
+	/**
35
+	 * @param WP_REST_Request $request
36
+	 * @return WP_Error|WP_REST_Response
37
+	 */
38
+	public static function handle_request_toggle_checkin(WP_REST_Request $request)
39
+	{
40
+		$controller = new Checkin();
41
+		return $controller->_create_checkin_checkout_object($request);
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * Toggles whether the user is checked in or not.
48
-     *
49
-     * @param WP_REST_Request $request
50
-     * @return WP_Error|WP_REST_Response
51
-     */
52
-    protected function _create_checkin_checkout_object(WP_REST_Request $request)
53
-    {
54
-        $reg_id = $request->get_param('REG_ID');
55
-        $dtt_id = $request->get_param('DTT_ID');
56
-        $force = $request->get_param('force');
57
-        if ($force == 'true') {
58
-            $force = true;
59
-        } else {
60
-            $force = false;
61
-        }
62
-        $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
63
-        if (! $reg instanceof EE_Registration) {
64
-            return $this->send_response(
65
-                new WP_Error(
66
-                    'rest_registration_toggle_checkin_invalid_id',
67
-                    sprintf(
68
-                        __('You cannot checkin registration with ID %1$s because it doesn\'t exist.',
69
-                            'event_espresso'),
70
-                        $reg_id
71
-                    ),
72
-                    array('status' => 422)
73
-                )
74
-            );
75
-        }
76
-        if (! EE_Capabilities::instance()
77
-                             ->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)
78
-        ) {
79
-            return $this->send_response(
80
-                new WP_Error(
81
-                    'rest_user_cannot_toggle_checkin',
82
-                    sprintf(
83
-                        __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
84
-                        $reg_id
85
-                    ),
86
-                    array('status' => 403)
87
-                )
88
-            );
89
-        }
90
-        $success = $reg->toggle_checkin_status($dtt_id, ! $force);
91
-        if ($success === false) {
92
-            //check if we know they can't check in because they're not approved and we aren't forcing
93
-            if (! $reg->is_approved() && ! $force) {
94
-                //rely on EE_Error::add_error messages to have been added to give more data about why it failed
95
-                return $this->send_response(
96
-                    new WP_Error(
97
-                        'rest_toggle_checkin_failed',
98
-                        __('Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
99
-                            'event_espresso')
100
-                    )
101
-                );
102
-            }
103
-            return $this->send_response(
104
-                new WP_Error(
105
-                    'rest_toggle_checkin_failed_not_forceable',
106
-                    __('Registration checkin failed. Please see additional error data.', 'event_espresso')
107
-                )
108
-            );
109
-        }
110
-        $checkin = EEM_Checkin::instance()->get_one(
111
-            array(
112
-                array(
113
-                    'REG_ID' => $reg_id,
114
-                    'DTT_ID' => $dtt_id,
115
-                ),
116
-                'order_by' => array(
117
-                    'CHK_timestamp' => 'DESC',
118
-                ),
119
-            )
120
-        );
121
-        if (! $checkin instanceof EE_Checkin) {
122
-            return $this->send_response(
123
-                new WP_Error(
124
-                    'rest_toggle_checkin_error',
125
-                    sprintf(
126
-                        __('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
127
-                            'event_espresso'),
128
-                        $reg_id,
129
-                        $dtt_id
130
-                    )
131
-                )
132
-            );
133
-        }
134
-        $requested_version = $this->get_requested_version($request->get_route());
135
-        $get_request = new WP_REST_Request(
136
-            'GET',
137
-            EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID()
138
-        );
139
-        $get_request->set_url_params(
140
-            array(
141
-                'id' => $checkin->ID(),
142
-            )
143
-        );
144
-        return Read::handle_request_get_one($get_request);
145
-    }
46
+	/**
47
+	 * Toggles whether the user is checked in or not.
48
+	 *
49
+	 * @param WP_REST_Request $request
50
+	 * @return WP_Error|WP_REST_Response
51
+	 */
52
+	protected function _create_checkin_checkout_object(WP_REST_Request $request)
53
+	{
54
+		$reg_id = $request->get_param('REG_ID');
55
+		$dtt_id = $request->get_param('DTT_ID');
56
+		$force = $request->get_param('force');
57
+		if ($force == 'true') {
58
+			$force = true;
59
+		} else {
60
+			$force = false;
61
+		}
62
+		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
63
+		if (! $reg instanceof EE_Registration) {
64
+			return $this->send_response(
65
+				new WP_Error(
66
+					'rest_registration_toggle_checkin_invalid_id',
67
+					sprintf(
68
+						__('You cannot checkin registration with ID %1$s because it doesn\'t exist.',
69
+							'event_espresso'),
70
+						$reg_id
71
+					),
72
+					array('status' => 422)
73
+				)
74
+			);
75
+		}
76
+		if (! EE_Capabilities::instance()
77
+							 ->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)
78
+		) {
79
+			return $this->send_response(
80
+				new WP_Error(
81
+					'rest_user_cannot_toggle_checkin',
82
+					sprintf(
83
+						__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
84
+						$reg_id
85
+					),
86
+					array('status' => 403)
87
+				)
88
+			);
89
+		}
90
+		$success = $reg->toggle_checkin_status($dtt_id, ! $force);
91
+		if ($success === false) {
92
+			//check if we know they can't check in because they're not approved and we aren't forcing
93
+			if (! $reg->is_approved() && ! $force) {
94
+				//rely on EE_Error::add_error messages to have been added to give more data about why it failed
95
+				return $this->send_response(
96
+					new WP_Error(
97
+						'rest_toggle_checkin_failed',
98
+						__('Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
99
+							'event_espresso')
100
+					)
101
+				);
102
+			}
103
+			return $this->send_response(
104
+				new WP_Error(
105
+					'rest_toggle_checkin_failed_not_forceable',
106
+					__('Registration checkin failed. Please see additional error data.', 'event_espresso')
107
+				)
108
+			);
109
+		}
110
+		$checkin = EEM_Checkin::instance()->get_one(
111
+			array(
112
+				array(
113
+					'REG_ID' => $reg_id,
114
+					'DTT_ID' => $dtt_id,
115
+				),
116
+				'order_by' => array(
117
+					'CHK_timestamp' => 'DESC',
118
+				),
119
+			)
120
+		);
121
+		if (! $checkin instanceof EE_Checkin) {
122
+			return $this->send_response(
123
+				new WP_Error(
124
+					'rest_toggle_checkin_error',
125
+					sprintf(
126
+						__('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
127
+							'event_espresso'),
128
+						$reg_id,
129
+						$dtt_id
130
+					)
131
+				)
132
+			);
133
+		}
134
+		$requested_version = $this->get_requested_version($request->get_route());
135
+		$get_request = new WP_REST_Request(
136
+			'GET',
137
+			EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID()
138
+		);
139
+		$get_request->set_url_params(
140
+			array(
141
+				'id' => $checkin->ID(),
142
+			)
143
+		);
144
+		return Read::handle_request_get_one($get_request);
145
+	}
146 146
 }
147 147
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use EventEspresso\core\libraries\rest_api\controllers\Base as Base;
14 14
 use EventEspresso\core\libraries\rest_api\controllers\model\Read;
15 15
 
16
-if (! defined('EVENT_ESPRESSO_VERSION')) {
16
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
17 17
     exit('No direct script access allowed');
18 18
 }
19 19
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $force = false;
61 61
         }
62 62
         $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
63
-        if (! $reg instanceof EE_Registration) {
63
+        if ( ! $reg instanceof EE_Registration) {
64 64
             return $this->send_response(
65 65
                 new WP_Error(
66 66
                     'rest_registration_toggle_checkin_invalid_id',
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
                 )
74 74
             );
75 75
         }
76
-        if (! EE_Capabilities::instance()
76
+        if ( ! EE_Capabilities::instance()
77 77
                              ->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)
78 78
         ) {
79 79
             return $this->send_response(
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         $success = $reg->toggle_checkin_status($dtt_id, ! $force);
91 91
         if ($success === false) {
92 92
             //check if we know they can't check in because they're not approved and we aren't forcing
93
-            if (! $reg->is_approved() && ! $force) {
93
+            if ( ! $reg->is_approved() && ! $force) {
94 94
                 //rely on EE_Error::add_error messages to have been added to give more data about why it failed
95 95
                 return $this->send_response(
96 96
                     new WP_Error(
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                 ),
119 119
             )
120 120
         );
121
-        if (! $checkin instanceof EE_Checkin) {
121
+        if ( ! $checkin instanceof EE_Checkin) {
122 122
             return $this->send_response(
123 123
                 new WP_Error(
124 124
                     'rest_toggle_checkin_error',
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $requested_version = $this->get_requested_version($request->get_route());
135 135
         $get_request = new WP_REST_Request(
136 136
             'GET',
137
-            EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID()
137
+            EED_Core_Rest_Api::ee_api_namespace.$requested_version.'/checkins/'.$checkin->ID()
138 138
         );
139 139
         $get_request->set_url_params(
140 140
             array(
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.35.rc.007');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.35.rc.007');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
core/entities/money/Money.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@
 block discarded – undo
200 200
      * Returns the money amount as an unformatted string
201 201
      * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
202 202
      *
203
-     * @return string
203
+     * @return double
204 204
      */
205 205
     public function amount()
206 206
     {
Please login to merge, or discard this patch.
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -29,418 +29,418 @@
 block discarded – undo
29 29
 class Money
30 30
 {
31 31
 
32
-    /**
33
-     * number of decimal places to be added to currencies for internal computations,
34
-     * but removed before any output or formatting is applied.
35
-     * This allows us to avoid rounding errors during calculations.
36
-     */
37
-    const EXTRA_PRECISION = 3;
38
-
39
-    /**
40
-     * @var int $amount
41
-     */
42
-    private $amount;
43
-
44
-    /**
45
-     * @var Currency $currency
46
-     */
47
-    private $currency;
48
-
49
-    /**
50
-     * @var Calculator $calculator
51
-     */
52
-    protected static $calculator;
53
-
54
-    /**
55
-     * @var MoneyFormatter[] $formatters
56
-     */
57
-    protected static $formatters;
58
-
59
-
60
-
61
-    /**
62
-     * Money constructor.
63
-     *
64
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
65
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
66
-     * @param Currency         $currency
67
-     * @throws InvalidDataTypeException
68
-     */
69
-    public function __construct($amount, Currency $currency)
70
-    {
71
-        $this->currency = $currency;
72
-        $this->amount = (string)$this->parseAmount($amount);
73
-    }
74
-
75
-
76
-
77
-    /**
78
-     * factory method that returns a Money object using the currency corresponding to the site's country
79
-     * example: Money::forSite(12.5)
80
-     *
81
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
82
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
83
-     * @return Money
84
-     * @throws InvalidArgumentException
85
-     */
86
-    public static function forSite($amount)
87
-    {
88
-        $CNT_ISO = isset(EE_Registry::instance()->CFG->organization)
89
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
90
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
91
-            : 'US';
92
-        return new self($amount, Currency::createFromCountryCode($CNT_ISO));
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * factory method that returns a Money object using the currency as specified by the supplied ISO country code
99
-     * example: Money::forCountry(12.5,'US')
100
-     *
101
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
102
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
103
-     * @param string           $CNT_ISO
104
-     * @return Money
105
-     * @throws InvalidArgumentException
106
-     */
107
-    public static function forCountry($amount, $CNT_ISO)
108
-    {
109
-        return new self($amount, Currency::createFromCountryCode($CNT_ISO));
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * factory method that returns a Money object using the currency as specified by the supplied currency code
116
-     * example: Money::forCurrency(12.5, 'USD')
117
-     *
118
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
119
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
120
-     * @param string           $currency_code
121
-     * @return Money
122
-     * @throws InvalidDataTypeException
123
-     * @throws EE_Error
124
-     * @throws InvalidArgumentException
125
-     */
126
-    public static function forCurrency($amount, $currency_code)
127
-    {
128
-        return new self($amount, Currency::createFromCode($currency_code));
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * factory method that returns a Money object for the currency specified as if it were a class method
135
-     * example: Money::USD(12.5);
136
-     * money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
137
-     * example: $12.5 USD would equate to a value amount of 12.50
138
-     *
139
-     * @param string $currency_code
140
-     * @param array  $arguments
141
-     * @return Money
142
-     * @throws InvalidDataTypeException
143
-     * @throws EE_Error
144
-     * @throws InvalidArgumentException
145
-     */
146
-    public static function __callStatic($currency_code, $arguments)
147
-    {
148
-        return new self($arguments[0], Currency::createFromCode($currency_code));
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
155
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
156
-     * @return float|int|number|string
157
-     * @throws InvalidDataTypeException
158
-     */
159
-    private function parseAmount($amount)
160
-    {
161
-        $type = gettype($amount);
162
-        switch ($type) {
163
-            case 'integer' :
164
-            case 'double' :
165
-            case 'string' :
166
-                // shift the decimal position by the number of decimal places used internally
167
-                // ex: 12.5 for a currency using 2 decimal places, would become 1250
168
-                // then if our extra internal precision was 3, it would become 1250000
169
-                $amount *= pow(10, $this->precision());
170
-                // then round up the remaining value if there is still a fractional amount left
171
-                $amount = round($amount, 0, PHP_ROUND_HALF_UP);
172
-            break;
173
-            default  :
174
-                throw new InvalidDataTypeException(
175
-                    '$amount',
176
-                    $amount,
177
-                    'integer (or float or string)'
178
-                );
179
-        }
180
-        return $amount;
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant
187
-     *
188
-     * @param bool $positive
189
-     * @return int
190
-     */
191
-    private function precision($positive = true)
192
-    {
193
-        $sign = $positive ? 1 : -1;
194
-        return ((int)$this->currency->decimalPlaces() + Money::EXTRA_PRECISION) * $sign;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * Returns the money amount as an unformatted string
201
-     * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
202
-     *
203
-     * @return string
204
-     */
205
-    public function amount()
206
-    {
207
-        // shift the decimal position BACK by the number of decimal places used internally
208
-        // ex: 1250 for a currency using 2 decimal places, would become 12.5
209
-        $amount = (string)$this->amount * pow(10, $this->precision(false));
210
-        // then shave off our extra internal precision using the number of decimal places for the currency
211
-        $amount = round($amount, $this->currency->decimalPlaces());
212
-        return $amount;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * applies formatting based on the specified formatting level
219
-     * corresponding to one of the constants on \EventEspresso\core\services\currency\MoneyFormatter
220
-     *
221
-     * @param int $formatting_level
222
-     * @return string
223
-     */
224
-    public function format($formatting_level = MoneyFormatter::ADD_THOUSANDS)
225
-    {
226
-        $formatted_amount = $this->amount();
227
-        $formatters = $this->formatters();
228
-        // if we are applying thousands formatting...
229
-        if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) {
230
-            // then let's remove decimal formatting since it's included in thousands formatting
231
-            unset($formatters[MoneyFormatter::DECIMAL_ONLY]);
232
-        }
233
-        for ($x = 1; $x <= $formatting_level; $x++) {
234
-            if (isset($formatters[$x]) && $formatters[$x] instanceof MoneyFormatter) {
235
-                $formatted_amount = $formatters[$x]->format($formatted_amount, $this->currency);
236
-            }
237
-        }
238
-        return $formatted_amount;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Returns the Currency object for this money
245
-     *
246
-     * @return Currency
247
-     */
248
-    public function currency()
249
-    {
250
-        return $this->currency;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * adds the supplied Money amount to this Money amount
257
-     * and returns a new Money object
258
-     *
259
-     * @param Money $other
260
-     * @return Money
261
-     * @throws InvalidArgumentException
262
-     */
263
-    public function add(Money $other)
264
-    {
265
-        $this->verifySameCurrency($other->currency());
266
-        return new Money(
267
-            $this->calculator()->add(
268
-                $this->amount(),
269
-                $other->amount()
270
-            ),
271
-            $this->currency()
272
-        );
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * subtracts the supplied Money amount from this Money amount
279
-     * and returns a new Money object
280
-     *
281
-     * @param Money $other
282
-     * @return Money
283
-     * @throws InvalidArgumentException
284
-     */
285
-    public function subtract(Money $other)
286
-    {
287
-        $this->verifySameCurrency($other->currency());
288
-        return new Money(
289
-            $this->calculator()->subtract(
290
-                $this->amount(),
291
-                $other->amount()
292
-            ),
293
-            $this->currency()
294
-        );
295
-    }
296
-
297
-
298
-
299
-    /**
300
-     * multiplies this Money amount by the supplied $multiplier
301
-     * and returns a new Money object
302
-     *
303
-     * @param float|int|string $multiplier
304
-     * @param int              $rounding_mode
305
-     * @return Money
306
-     * @throws InvalidDataTypeException
307
-     */
308
-    public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP)
309
-    {
310
-        return new Money(
311
-            $this->calculator()->multiply(
312
-                $this->amount(),
313
-                $multiplier,
314
-                $this->precision(),
315
-                $rounding_mode
316
-            ),
317
-            $this->currency()
318
-        );
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * divides this Money amount by the supplied $divisor
325
-     * and returns a new Money object
326
-     *
327
-     * @param float|int|string $divisor
328
-     * @param int              $rounding_mode
329
-     * @return Money
330
-     * @throws InvalidDataTypeException
331
-     */
332
-    public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP)
333
-    {
334
-        return new Money(
335
-            $this->calculator()->divide(
336
-                $this->amount(),
337
-                $divisor,
338
-                $this->precision(),
339
-                $rounding_mode
340
-            ),
341
-            $this->currency()
342
-        );
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * @param Currency $other_currency
349
-     * @throws InvalidArgumentException
350
-     */
351
-    public function verifySameCurrency(Currency $other_currency)
352
-    {
353
-        if ($this->currency()->equals($other_currency) !== true) {
354
-            throw new InvalidArgumentException(
355
-                esc_html__(
356
-                    'Currencies must be the same in order to add or subtract their values.',
357
-                    'event_espresso'
358
-                )
359
-            );
360
-        }
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * @return Calculator
367
-     */
368
-    protected function calculator()
369
-    {
370
-        $this->initializeCalculators();
371
-        return self::$calculator;
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * loops through a filterable array of Calculator services
378
-     * and selects the first one that is supported by the current server
379
-     */
380
-    protected function initializeCalculators()
381
-    {
382
-        if (self::$calculator instanceof Calculator) {
383
-            return;
384
-        }
385
-        $calculators = apply_filters(
386
-            'FHEE__EventEspresso\core\entities\money\Money__initializeCalculators__Calculator_array',
387
-            array(
388
-                '\EventEspresso\core\services\currency\DefaultCalculator',
389
-            )
390
-        );
391
-        foreach ($calculators as $calculator) {
392
-            if (! class_exists($calculator)) {
393
-                continue;
394
-            }
395
-            $calculator = new $calculator();
396
-            if ($calculator instanceof Calculator && $calculator->isSupported()) {
397
-                self::$calculator = $calculator;
398
-                break;
399
-            }
400
-        }
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * @return MoneyFormatter[]
407
-     */
408
-    protected function formatters()
409
-    {
410
-        $this->initializeFormatters();
411
-        return self::$formatters;
412
-    }
413
-
414
-
415
-
416
-    /**
417
-     * initializes a filterable array of MoneyFormatter services
418
-     */
419
-    protected function initializeFormatters()
420
-    {
421
-        if (! empty(self::$formatters)) {
422
-            return;
423
-        }
424
-        self::$formatters = apply_filters(
425
-            'FHEE__EventEspresso\core\entities\money\Money__initializeFormatters__MoneyFormatters_array',
426
-            array(
427
-                1 => new DecimalMoneyFormatter(),
428
-                2 => new ThousandsMoneyFormatter(),
429
-                3 => new CurrencySignMoneyFormatter(),
430
-                4 => new InternationalMoneyFormatter(),
431
-            )
432
-        );
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * @return string
439
-     */
440
-    public function __toString()
441
-    {
442
-        return $this->format(MoneyFormatter::DECIMAL_ONLY);
443
-    }
32
+	/**
33
+	 * number of decimal places to be added to currencies for internal computations,
34
+	 * but removed before any output or formatting is applied.
35
+	 * This allows us to avoid rounding errors during calculations.
36
+	 */
37
+	const EXTRA_PRECISION = 3;
38
+
39
+	/**
40
+	 * @var int $amount
41
+	 */
42
+	private $amount;
43
+
44
+	/**
45
+	 * @var Currency $currency
46
+	 */
47
+	private $currency;
48
+
49
+	/**
50
+	 * @var Calculator $calculator
51
+	 */
52
+	protected static $calculator;
53
+
54
+	/**
55
+	 * @var MoneyFormatter[] $formatters
56
+	 */
57
+	protected static $formatters;
58
+
59
+
60
+
61
+	/**
62
+	 * Money constructor.
63
+	 *
64
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
65
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
66
+	 * @param Currency         $currency
67
+	 * @throws InvalidDataTypeException
68
+	 */
69
+	public function __construct($amount, Currency $currency)
70
+	{
71
+		$this->currency = $currency;
72
+		$this->amount = (string)$this->parseAmount($amount);
73
+	}
74
+
75
+
76
+
77
+	/**
78
+	 * factory method that returns a Money object using the currency corresponding to the site's country
79
+	 * example: Money::forSite(12.5)
80
+	 *
81
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
82
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
83
+	 * @return Money
84
+	 * @throws InvalidArgumentException
85
+	 */
86
+	public static function forSite($amount)
87
+	{
88
+		$CNT_ISO = isset(EE_Registry::instance()->CFG->organization)
89
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
90
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
91
+			: 'US';
92
+		return new self($amount, Currency::createFromCountryCode($CNT_ISO));
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * factory method that returns a Money object using the currency as specified by the supplied ISO country code
99
+	 * example: Money::forCountry(12.5,'US')
100
+	 *
101
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
102
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
103
+	 * @param string           $CNT_ISO
104
+	 * @return Money
105
+	 * @throws InvalidArgumentException
106
+	 */
107
+	public static function forCountry($amount, $CNT_ISO)
108
+	{
109
+		return new self($amount, Currency::createFromCountryCode($CNT_ISO));
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * factory method that returns a Money object using the currency as specified by the supplied currency code
116
+	 * example: Money::forCurrency(12.5, 'USD')
117
+	 *
118
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
119
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
120
+	 * @param string           $currency_code
121
+	 * @return Money
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws EE_Error
124
+	 * @throws InvalidArgumentException
125
+	 */
126
+	public static function forCurrency($amount, $currency_code)
127
+	{
128
+		return new self($amount, Currency::createFromCode($currency_code));
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * factory method that returns a Money object for the currency specified as if it were a class method
135
+	 * example: Money::USD(12.5);
136
+	 * money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
137
+	 * example: $12.5 USD would equate to a value amount of 12.50
138
+	 *
139
+	 * @param string $currency_code
140
+	 * @param array  $arguments
141
+	 * @return Money
142
+	 * @throws InvalidDataTypeException
143
+	 * @throws EE_Error
144
+	 * @throws InvalidArgumentException
145
+	 */
146
+	public static function __callStatic($currency_code, $arguments)
147
+	{
148
+		return new self($arguments[0], Currency::createFromCode($currency_code));
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
155
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
156
+	 * @return float|int|number|string
157
+	 * @throws InvalidDataTypeException
158
+	 */
159
+	private function parseAmount($amount)
160
+	{
161
+		$type = gettype($amount);
162
+		switch ($type) {
163
+			case 'integer' :
164
+			case 'double' :
165
+			case 'string' :
166
+				// shift the decimal position by the number of decimal places used internally
167
+				// ex: 12.5 for a currency using 2 decimal places, would become 1250
168
+				// then if our extra internal precision was 3, it would become 1250000
169
+				$amount *= pow(10, $this->precision());
170
+				// then round up the remaining value if there is still a fractional amount left
171
+				$amount = round($amount, 0, PHP_ROUND_HALF_UP);
172
+			break;
173
+			default  :
174
+				throw new InvalidDataTypeException(
175
+					'$amount',
176
+					$amount,
177
+					'integer (or float or string)'
178
+				);
179
+		}
180
+		return $amount;
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant
187
+	 *
188
+	 * @param bool $positive
189
+	 * @return int
190
+	 */
191
+	private function precision($positive = true)
192
+	{
193
+		$sign = $positive ? 1 : -1;
194
+		return ((int)$this->currency->decimalPlaces() + Money::EXTRA_PRECISION) * $sign;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * Returns the money amount as an unformatted string
201
+	 * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
202
+	 *
203
+	 * @return string
204
+	 */
205
+	public function amount()
206
+	{
207
+		// shift the decimal position BACK by the number of decimal places used internally
208
+		// ex: 1250 for a currency using 2 decimal places, would become 12.5
209
+		$amount = (string)$this->amount * pow(10, $this->precision(false));
210
+		// then shave off our extra internal precision using the number of decimal places for the currency
211
+		$amount = round($amount, $this->currency->decimalPlaces());
212
+		return $amount;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * applies formatting based on the specified formatting level
219
+	 * corresponding to one of the constants on \EventEspresso\core\services\currency\MoneyFormatter
220
+	 *
221
+	 * @param int $formatting_level
222
+	 * @return string
223
+	 */
224
+	public function format($formatting_level = MoneyFormatter::ADD_THOUSANDS)
225
+	{
226
+		$formatted_amount = $this->amount();
227
+		$formatters = $this->formatters();
228
+		// if we are applying thousands formatting...
229
+		if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) {
230
+			// then let's remove decimal formatting since it's included in thousands formatting
231
+			unset($formatters[MoneyFormatter::DECIMAL_ONLY]);
232
+		}
233
+		for ($x = 1; $x <= $formatting_level; $x++) {
234
+			if (isset($formatters[$x]) && $formatters[$x] instanceof MoneyFormatter) {
235
+				$formatted_amount = $formatters[$x]->format($formatted_amount, $this->currency);
236
+			}
237
+		}
238
+		return $formatted_amount;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Returns the Currency object for this money
245
+	 *
246
+	 * @return Currency
247
+	 */
248
+	public function currency()
249
+	{
250
+		return $this->currency;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * adds the supplied Money amount to this Money amount
257
+	 * and returns a new Money object
258
+	 *
259
+	 * @param Money $other
260
+	 * @return Money
261
+	 * @throws InvalidArgumentException
262
+	 */
263
+	public function add(Money $other)
264
+	{
265
+		$this->verifySameCurrency($other->currency());
266
+		return new Money(
267
+			$this->calculator()->add(
268
+				$this->amount(),
269
+				$other->amount()
270
+			),
271
+			$this->currency()
272
+		);
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * subtracts the supplied Money amount from this Money amount
279
+	 * and returns a new Money object
280
+	 *
281
+	 * @param Money $other
282
+	 * @return Money
283
+	 * @throws InvalidArgumentException
284
+	 */
285
+	public function subtract(Money $other)
286
+	{
287
+		$this->verifySameCurrency($other->currency());
288
+		return new Money(
289
+			$this->calculator()->subtract(
290
+				$this->amount(),
291
+				$other->amount()
292
+			),
293
+			$this->currency()
294
+		);
295
+	}
296
+
297
+
298
+
299
+	/**
300
+	 * multiplies this Money amount by the supplied $multiplier
301
+	 * and returns a new Money object
302
+	 *
303
+	 * @param float|int|string $multiplier
304
+	 * @param int              $rounding_mode
305
+	 * @return Money
306
+	 * @throws InvalidDataTypeException
307
+	 */
308
+	public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP)
309
+	{
310
+		return new Money(
311
+			$this->calculator()->multiply(
312
+				$this->amount(),
313
+				$multiplier,
314
+				$this->precision(),
315
+				$rounding_mode
316
+			),
317
+			$this->currency()
318
+		);
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * divides this Money amount by the supplied $divisor
325
+	 * and returns a new Money object
326
+	 *
327
+	 * @param float|int|string $divisor
328
+	 * @param int              $rounding_mode
329
+	 * @return Money
330
+	 * @throws InvalidDataTypeException
331
+	 */
332
+	public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP)
333
+	{
334
+		return new Money(
335
+			$this->calculator()->divide(
336
+				$this->amount(),
337
+				$divisor,
338
+				$this->precision(),
339
+				$rounding_mode
340
+			),
341
+			$this->currency()
342
+		);
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * @param Currency $other_currency
349
+	 * @throws InvalidArgumentException
350
+	 */
351
+	public function verifySameCurrency(Currency $other_currency)
352
+	{
353
+		if ($this->currency()->equals($other_currency) !== true) {
354
+			throw new InvalidArgumentException(
355
+				esc_html__(
356
+					'Currencies must be the same in order to add or subtract their values.',
357
+					'event_espresso'
358
+				)
359
+			);
360
+		}
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * @return Calculator
367
+	 */
368
+	protected function calculator()
369
+	{
370
+		$this->initializeCalculators();
371
+		return self::$calculator;
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * loops through a filterable array of Calculator services
378
+	 * and selects the first one that is supported by the current server
379
+	 */
380
+	protected function initializeCalculators()
381
+	{
382
+		if (self::$calculator instanceof Calculator) {
383
+			return;
384
+		}
385
+		$calculators = apply_filters(
386
+			'FHEE__EventEspresso\core\entities\money\Money__initializeCalculators__Calculator_array',
387
+			array(
388
+				'\EventEspresso\core\services\currency\DefaultCalculator',
389
+			)
390
+		);
391
+		foreach ($calculators as $calculator) {
392
+			if (! class_exists($calculator)) {
393
+				continue;
394
+			}
395
+			$calculator = new $calculator();
396
+			if ($calculator instanceof Calculator && $calculator->isSupported()) {
397
+				self::$calculator = $calculator;
398
+				break;
399
+			}
400
+		}
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * @return MoneyFormatter[]
407
+	 */
408
+	protected function formatters()
409
+	{
410
+		$this->initializeFormatters();
411
+		return self::$formatters;
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 * initializes a filterable array of MoneyFormatter services
418
+	 */
419
+	protected function initializeFormatters()
420
+	{
421
+		if (! empty(self::$formatters)) {
422
+			return;
423
+		}
424
+		self::$formatters = apply_filters(
425
+			'FHEE__EventEspresso\core\entities\money\Money__initializeFormatters__MoneyFormatters_array',
426
+			array(
427
+				1 => new DecimalMoneyFormatter(),
428
+				2 => new ThousandsMoneyFormatter(),
429
+				3 => new CurrencySignMoneyFormatter(),
430
+				4 => new InternationalMoneyFormatter(),
431
+			)
432
+		);
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * @return string
439
+	 */
440
+	public function __toString()
441
+	{
442
+		return $this->format(MoneyFormatter::DECIMAL_ONLY);
443
+	}
444 444
 
445 445
 
446 446
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     public function __construct($amount, Currency $currency)
70 70
     {
71 71
         $this->currency = $currency;
72
-        $this->amount = (string)$this->parseAmount($amount);
72
+        $this->amount = (string) $this->parseAmount($amount);
73 73
     }
74 74
 
75 75
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     private function precision($positive = true)
192 192
     {
193 193
         $sign = $positive ? 1 : -1;
194
-        return ((int)$this->currency->decimalPlaces() + Money::EXTRA_PRECISION) * $sign;
194
+        return ((int) $this->currency->decimalPlaces() + Money::EXTRA_PRECISION) * $sign;
195 195
     }
196 196
 
197 197
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     {
207 207
         // shift the decimal position BACK by the number of decimal places used internally
208 208
         // ex: 1250 for a currency using 2 decimal places, would become 12.5
209
-        $amount = (string)$this->amount * pow(10, $this->precision(false));
209
+        $amount = (string) $this->amount * pow(10, $this->precision(false));
210 210
         // then shave off our extra internal precision using the number of decimal places for the currency
211 211
         $amount = round($amount, $this->currency->decimalPlaces());
212 212
         return $amount;
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
             )
390 390
         );
391 391
         foreach ($calculators as $calculator) {
392
-            if (! class_exists($calculator)) {
392
+            if ( ! class_exists($calculator)) {
393 393
                 continue;
394 394
             }
395 395
             $calculator = new $calculator();
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
      */
419 419
     protected function initializeFormatters()
420 420
     {
421
-        if (! empty(self::$formatters)) {
421
+        if ( ! empty(self::$formatters)) {
422 422
             return;
423 423
         }
424 424
         self::$formatters = apply_filters(
Please login to merge, or discard this patch.
core/services/currency/Calculator.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -9,110 +9,110 @@
 block discarded – undo
9 9
 interface Calculator
10 10
 {
11 11
 
12
-    /**
13
-     * Round val up to precision decimal places AWAY from zero,
14
-     * when it is half way there. Making 1.5 into 2 and -1.5 into -2.
15
-     */
16
-    const ROUND_HALF_UP   = PHP_ROUND_HALF_UP;
17
-
18
-    /**
19
-     * Round val down to precision decimal places TOWARDS zero,
20
-     * when it is half way there. Making 1.5 into 1 and -1.5 into -1.
21
-     */
22
-    const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN;
23
-
24
-    /**
25
-     * Round val to precision decimal places towards the next even value.
26
-     */
27
-    const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN;
28
-
29
-    /**
30
-     * Round val to precision decimal places towards the next odd value.
31
-     */
32
-    const ROUND_HALF_ODD  = PHP_ROUND_HALF_ODD;
33
-
34
-    /**
35
-     * Round val up to the next highest integer
36
-     */
37
-    const ROUND_UP = 5;
38
-
39
-    /**
40
-     * Round val down to the next lowest integer
41
-     */
42
-    const ROUND_DOWN = 6;
43
-
44
-
45
-
46
-    /**
47
-     * returns true if a calculator is supported as determined by loaded server extensions
48
-     *
49
-     * @return bool
50
-     */
51
-    public function isSupported();
52
-
53
-
54
-
55
-    /**
56
-     * adds the supplied Money amount to this Money amount
57
-     * and returns a new Money object
58
-     *
59
-     * @param string           $amount
60
-     * @param float|int|string $amount_to_add
61
-     * @return string
62
-     */
63
-    public function add($amount, $amount_to_add);
64
-
65
-
66
-
67
-    /**
68
-     * subtracts the supplied Money amount from this Money amount
69
-     * and returns a new Money object
70
-     *
71
-     * @param string           $amount
72
-     * @param float|int|string $amount_to_subtract
73
-     * @return string
74
-     */
75
-    public function subtract($amount, $amount_to_subtract);
76
-
77
-
78
-
79
-    /**
80
-     * multiplies this Money amount by the supplied $multiplier
81
-     * and returns a new Money object
82
-     *
83
-     * @param string           $amount
84
-     * @param float|int|string $multiplier
85
-     * @param int              $precision
86
-     * @param int              $rounding_mode
87
-     * @return string
88
-     */
89
-    public function multiply($amount, $multiplier, $precision, $rounding_mode);
90
-
91
-
92
-
93
-    /**
94
-     * divides this Money amount by the supplied $divisor
95
-     * and returns a new Money object
96
-     *
97
-     * @param string           $amount
98
-     * @param float|int|string $divisor
99
-     * @param int              $precision
100
-     * @param int              $rounding_mode
101
-     * @return string
102
-     */
103
-    public function divide($amount, $divisor, $precision, $rounding_mode);
104
-
105
-
106
-
107
-    /**
108
-     * adjust amount according to precision and rounding mode
109
-     *
110
-     * @param int|float $amount
111
-     * @param int       $precision
112
-     * @param int       $rounding_mode
113
-     * @return string
114
-     */
115
-    public function round($amount, $precision, $rounding_mode);
12
+	/**
13
+	 * Round val up to precision decimal places AWAY from zero,
14
+	 * when it is half way there. Making 1.5 into 2 and -1.5 into -2.
15
+	 */
16
+	const ROUND_HALF_UP   = PHP_ROUND_HALF_UP;
17
+
18
+	/**
19
+	 * Round val down to precision decimal places TOWARDS zero,
20
+	 * when it is half way there. Making 1.5 into 1 and -1.5 into -1.
21
+	 */
22
+	const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN;
23
+
24
+	/**
25
+	 * Round val to precision decimal places towards the next even value.
26
+	 */
27
+	const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN;
28
+
29
+	/**
30
+	 * Round val to precision decimal places towards the next odd value.
31
+	 */
32
+	const ROUND_HALF_ODD  = PHP_ROUND_HALF_ODD;
33
+
34
+	/**
35
+	 * Round val up to the next highest integer
36
+	 */
37
+	const ROUND_UP = 5;
38
+
39
+	/**
40
+	 * Round val down to the next lowest integer
41
+	 */
42
+	const ROUND_DOWN = 6;
43
+
44
+
45
+
46
+	/**
47
+	 * returns true if a calculator is supported as determined by loaded server extensions
48
+	 *
49
+	 * @return bool
50
+	 */
51
+	public function isSupported();
52
+
53
+
54
+
55
+	/**
56
+	 * adds the supplied Money amount to this Money amount
57
+	 * and returns a new Money object
58
+	 *
59
+	 * @param string           $amount
60
+	 * @param float|int|string $amount_to_add
61
+	 * @return string
62
+	 */
63
+	public function add($amount, $amount_to_add);
64
+
65
+
66
+
67
+	/**
68
+	 * subtracts the supplied Money amount from this Money amount
69
+	 * and returns a new Money object
70
+	 *
71
+	 * @param string           $amount
72
+	 * @param float|int|string $amount_to_subtract
73
+	 * @return string
74
+	 */
75
+	public function subtract($amount, $amount_to_subtract);
76
+
77
+
78
+
79
+	/**
80
+	 * multiplies this Money amount by the supplied $multiplier
81
+	 * and returns a new Money object
82
+	 *
83
+	 * @param string           $amount
84
+	 * @param float|int|string $multiplier
85
+	 * @param int              $precision
86
+	 * @param int              $rounding_mode
87
+	 * @return string
88
+	 */
89
+	public function multiply($amount, $multiplier, $precision, $rounding_mode);
90
+
91
+
92
+
93
+	/**
94
+	 * divides this Money amount by the supplied $divisor
95
+	 * and returns a new Money object
96
+	 *
97
+	 * @param string           $amount
98
+	 * @param float|int|string $divisor
99
+	 * @param int              $precision
100
+	 * @param int              $rounding_mode
101
+	 * @return string
102
+	 */
103
+	public function divide($amount, $divisor, $precision, $rounding_mode);
104
+
105
+
106
+
107
+	/**
108
+	 * adjust amount according to precision and rounding mode
109
+	 *
110
+	 * @param int|float $amount
111
+	 * @param int       $precision
112
+	 * @param int       $rounding_mode
113
+	 * @return string
114
+	 */
115
+	public function round($amount, $precision, $rounding_mode);
116 116
 
117 117
 
118 118
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Round val up to precision decimal places AWAY from zero,
14 14
      * when it is half way there. Making 1.5 into 2 and -1.5 into -2.
15 15
      */
16
-    const ROUND_HALF_UP   = PHP_ROUND_HALF_UP;
16
+    const ROUND_HALF_UP = PHP_ROUND_HALF_UP;
17 17
 
18 18
     /**
19 19
      * Round val down to precision decimal places TOWARDS zero,
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * Round val to precision decimal places towards the next odd value.
31 31
      */
32
-    const ROUND_HALF_ODD  = PHP_ROUND_HALF_ODD;
32
+    const ROUND_HALF_ODD = PHP_ROUND_HALF_ODD;
33 33
 
34 34
     /**
35 35
      * Round val up to the next highest integer
Please login to merge, or discard this patch.
core/services/currency/CalculatorBase.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -19,72 +19,72 @@
 block discarded – undo
19 19
 abstract class CalculatorBase implements Calculator
20 20
 {
21 21
 
22
-    /**
23
-     * @param int|float $amount
24
-     * @param int       $precision
25
-     * @param int       $rounding_mode
26
-     * @return string
27
-     * @throws InvalidArgumentException
28
-     */
29
-    public function round($amount, $precision, $rounding_mode)
30
-    {
31
-        $this->verifyRoundingMode($rounding_mode);
32
-        if ($rounding_mode === Calculator::ROUND_UP) {
33
-            return (string) ceil($amount);
34
-        }
35
-        if ($rounding_mode === Calculator::ROUND_DOWN) {
36
-            return (string) floor($amount);
37
-        }
38
-        return (string) round($amount, $precision, $rounding_mode);
39
-    }
40
-
41
-
42
-
43
-    /**
44
-     * Asserts that rounding mode is a valid integer value.
45
-     *
46
-     * @param int $rounding_mode
47
-     * @throws InvalidArgumentException If $roundingMode is not valid
48
-     */
49
-    private function verifyRoundingMode($rounding_mode)
50
-    {
51
-        if (
52
-        ! in_array(
53
-            $rounding_mode,
54
-            array(
55
-                Calculator::ROUND_UP,
56
-                Calculator::ROUND_DOWN,
57
-                Calculator::ROUND_HALF_DOWN,
58
-                Calculator::ROUND_HALF_EVEN,
59
-                Calculator::ROUND_HALF_ODD,
60
-                Calculator::ROUND_HALF_UP,
61
-            ),
62
-            true
63
-        )
64
-        ) {
65
-            throw new InvalidArgumentException(
66
-                esc_html__(
67
-                    'Rounding mode should be one of the following: Calculator::ROUND_UP, Calculator::ROUND_DOWN, Calculator::ROUND_HALF_DOWN, Calculator::ROUND_HALF_EVEN, Calculator::ROUND_HALF_ODD, or Calculator::ROUND_HALF_UP.',
68
-                    'event_espresso'
69
-                )
70
-            );
71
-        }
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param $divisor
78
-     * @throws InvalidArgumentException
79
-     */
80
-    protected function validateDivisor($divisor)
81
-    {
82
-        if ((int)$divisor === 0) {
83
-            throw new InvalidArgumentException(
84
-                esc_html__('Division by zero.', 'event_espresso')
85
-            );
86
-        }
87
-    }
22
+	/**
23
+	 * @param int|float $amount
24
+	 * @param int       $precision
25
+	 * @param int       $rounding_mode
26
+	 * @return string
27
+	 * @throws InvalidArgumentException
28
+	 */
29
+	public function round($amount, $precision, $rounding_mode)
30
+	{
31
+		$this->verifyRoundingMode($rounding_mode);
32
+		if ($rounding_mode === Calculator::ROUND_UP) {
33
+			return (string) ceil($amount);
34
+		}
35
+		if ($rounding_mode === Calculator::ROUND_DOWN) {
36
+			return (string) floor($amount);
37
+		}
38
+		return (string) round($amount, $precision, $rounding_mode);
39
+	}
40
+
41
+
42
+
43
+	/**
44
+	 * Asserts that rounding mode is a valid integer value.
45
+	 *
46
+	 * @param int $rounding_mode
47
+	 * @throws InvalidArgumentException If $roundingMode is not valid
48
+	 */
49
+	private function verifyRoundingMode($rounding_mode)
50
+	{
51
+		if (
52
+		! in_array(
53
+			$rounding_mode,
54
+			array(
55
+				Calculator::ROUND_UP,
56
+				Calculator::ROUND_DOWN,
57
+				Calculator::ROUND_HALF_DOWN,
58
+				Calculator::ROUND_HALF_EVEN,
59
+				Calculator::ROUND_HALF_ODD,
60
+				Calculator::ROUND_HALF_UP,
61
+			),
62
+			true
63
+		)
64
+		) {
65
+			throw new InvalidArgumentException(
66
+				esc_html__(
67
+					'Rounding mode should be one of the following: Calculator::ROUND_UP, Calculator::ROUND_DOWN, Calculator::ROUND_HALF_DOWN, Calculator::ROUND_HALF_EVEN, Calculator::ROUND_HALF_ODD, or Calculator::ROUND_HALF_UP.',
68
+					'event_espresso'
69
+				)
70
+			);
71
+		}
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param $divisor
78
+	 * @throws InvalidArgumentException
79
+	 */
80
+	protected function validateDivisor($divisor)
81
+	{
82
+		if ((int)$divisor === 0) {
83
+			throw new InvalidArgumentException(
84
+				esc_html__('Division by zero.', 'event_espresso')
85
+			);
86
+		}
87
+	}
88 88
 
89 89
 
90 90
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
      */
80 80
     protected function validateDivisor($divisor)
81 81
     {
82
-        if ((int)$divisor === 0) {
82
+        if ((int) $divisor === 0) {
83 83
             throw new InvalidArgumentException(
84 84
                 esc_html__('Division by zero.', 'event_espresso')
85 85
             );
Please login to merge, or discard this patch.
core/services/currency/MoneyFormatter.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -19,44 +19,44 @@
 block discarded – undo
19 19
 interface MoneyFormatter
20 20
 {
21 21
 
22
-    /**
23
-     * do NOT apply any formatting
24
-     * eg: 123456
25
-     */
26
-    const RAW = 0;
27
-
28
-    /**
29
-     * only format money amount by adding the decimal mark
30
-     * eg: 1234.56
31
-     */
32
-    const DECIMAL_ONLY = 1;
33
-
34
-    /**
35
-     * format money amount by adding decimal mark and thousands separator
36
-     * eg: 1,234.56
37
-     */
38
-    const ADD_THOUSANDS = 2;
39
-
40
-    /**
41
-     * format money amount by adding decimal mark, thousands separator, and currency sign
42
-     * eg: $1,234.56
43
-     */
44
-    const ADD_CURRENCY_SIGN = 3;
45
-
46
-    /**
47
-     * format money amount by adding decimal mark, thousands separator, currency sign, and currency code
48
-     * eg: USD $1,234.56
49
-     */
50
-    const INTERNATIONAL = 4;
51
-
52
-
53
-
54
-    /**
55
-     * @param string   $money_amount
56
-     * @param Currency $currency
57
-     * @return string
58
-     */
59
-    public function format($money_amount, Currency $currency);
22
+	/**
23
+	 * do NOT apply any formatting
24
+	 * eg: 123456
25
+	 */
26
+	const RAW = 0;
27
+
28
+	/**
29
+	 * only format money amount by adding the decimal mark
30
+	 * eg: 1234.56
31
+	 */
32
+	const DECIMAL_ONLY = 1;
33
+
34
+	/**
35
+	 * format money amount by adding decimal mark and thousands separator
36
+	 * eg: 1,234.56
37
+	 */
38
+	const ADD_THOUSANDS = 2;
39
+
40
+	/**
41
+	 * format money amount by adding decimal mark, thousands separator, and currency sign
42
+	 * eg: $1,234.56
43
+	 */
44
+	const ADD_CURRENCY_SIGN = 3;
45
+
46
+	/**
47
+	 * format money amount by adding decimal mark, thousands separator, currency sign, and currency code
48
+	 * eg: USD $1,234.56
49
+	 */
50
+	const INTERNATIONAL = 4;
51
+
52
+
53
+
54
+	/**
55
+	 * @param string   $money_amount
56
+	 * @param Currency $currency
57
+	 * @return string
58
+	 */
59
+	public function format($money_amount, Currency $currency);
60 60
 
61 61
 
62 62
 }
Please login to merge, or discard this patch.
core/services/currency/DecimalMoneyFormatter.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * @param string   $money_amount
26
-     * @param Currency $currency
27
-     * @return string
28
-     */
29
-    public function format($money_amount, Currency $currency)
30
-    {
31
-        return (string)round($money_amount, $currency->decimalPlaces());
32
-    }
24
+	/**
25
+	 * @param string   $money_amount
26
+	 * @param Currency $currency
27
+	 * @return string
28
+	 */
29
+	public function format($money_amount, Currency $currency)
30
+	{
31
+		return (string)round($money_amount, $currency->decimalPlaces());
32
+	}
33 33
 
34 34
 
35 35
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
      */
29 29
     public function format($money_amount, Currency $currency)
30 30
     {
31
-        return (string)round($money_amount, $currency->decimalPlaces());
31
+        return (string) round($money_amount, $currency->decimalPlaces());
32 32
     }
33 33
 
34 34
 
Please login to merge, or discard this patch.
core/services/currency/ThousandsMoneyFormatter.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -21,20 +21,20 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * @param string   $money_amount
26
-     * @param Currency $currency
27
-     * @return string
28
-     */
29
-    public function format($money_amount, Currency $currency)
30
-    {
31
-        return number_format(
32
-            $money_amount,
33
-            $currency->decimalPlaces(),
34
-            $currency->decimalMark(),
35
-            $currency->thousands()
36
-        );
37
-    }
24
+	/**
25
+	 * @param string   $money_amount
26
+	 * @param Currency $currency
27
+	 * @return string
28
+	 */
29
+	public function format($money_amount, Currency $currency)
30
+	{
31
+		return number_format(
32
+			$money_amount,
33
+			$currency->decimalPlaces(),
34
+			$currency->decimalMark(),
35
+			$currency->thousands()
36
+		);
37
+	}
38 38
 
39 39
 
40 40
 }
Please login to merge, or discard this patch.