Completed
Branch BUG-10381-asset-loading (361215)
by
unknown
158:58 queued 146:07
created
modules/ticket_selector/TicketSelectorRowStandard.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -232,7 +232,7 @@
 block discarded – undo
232 232
      * setTicketMinAndMax
233 233
      *
234 234
      * @param int $remaining
235
-     * @return array
235
+     * @return integer[]
236 236
      * @throws EE_Error
237 237
      */
238 238
     protected function setTicketMinAndMax($remaining)
Please login to merge, or discard this patch.
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -19,399 +19,399 @@
 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) {
199
-            return $ticket_selector_row_html
200
-                   . $new_row_cells_content
201
-                   . $this->ticketQtyAndIdHiddenInputs()
202
-                   . \EEH_HTML::trx();
203
-        }
204
-        $this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
205
-
206
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
207
-        $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
208
-        $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
209
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
210
-        if (empty($this->ticket_status_display)) {
211
-            if ($this->max_atndz === 1) {
212
-                // only ONE attendee is allowed to register at a time
213
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
214
-            } else if ($max > 0) {
215
-                $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
216
-            }
217
-        }
218
-        $ticket_selector_row_html .= $this->ticket_status_display;
219
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
220
-        $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
221
-        $ticket_selector_row_html .= \EEH_HTML::tdx();
222
-        $ticket_selector_row_html .= \EEH_HTML::trx();
223
-
224
-
225
-        $this->row++;
226
-        return $ticket_selector_row_html;
227
-    }
228
-
229
-
230
-
231
-    /**
232
-     * setTicketMinAndMax
233
-     *
234
-     * @param int $remaining
235
-     * @return array
236
-     * @throws EE_Error
237
-     */
238
-    protected function setTicketMinAndMax($remaining)
239
-    {
240
-        // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
241
-        $max = min($remaining, $this->max_atndz);
242
-        // but... we also want to restrict the number of tickets by the ticket max setting,
243
-        // however, the max still can't be higher than what was just set above
244
-        $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
245
-        // and we also want to restrict the minimum number of tickets by the ticket min setting
246
-        $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
247
-        // and if the ticket is required, then make sure that min qty is at least 1
248
-        $min = $this->ticket->required() ? max($min, 1) : $min;
249
-        return array($min, $max);
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * getTicketPriceDetails
256
-     *
257
-     * @return array
258
-     * @throws EE_Error
259
-     */
260
-    protected function getTicketPriceDetails()
261
-    {
262
-        $ticket_price = $this->tax_settings->prices_displayed_including_taxes
263
-            ? $this->ticket->get_ticket_total_with_taxes()
264
-            : $this->ticket->get_ticket_subtotal();
265
-        $ticket_bundle = false;
266
-        $ticket_min = $this->ticket->min();
267
-        // for ticket bundles, set min and max qty the same
268
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
269
-            $ticket_price *= $ticket_min;
270
-            $ticket_bundle = true;
271
-        }
272
-        $ticket_price = apply_filters(
273
-            'FHEE__ticket_selector_chart_template__ticket_price',
274
-            $ticket_price,
275
-            $this->ticket
276
-        );
277
-        return array($ticket_price, $ticket_bundle);
278
-    }
279
-
280
-
281
-
282
-
283
-    /**
284
-     * ticketNameTableCell
285
-     *
286
-     * @return string
287
-     * @throws EE_Error
288
-     */
289
-    protected function ticketNameTableCell()
290
-    {
291
-        $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
292
-        $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
293
-        $html .= $this->ticket_details->getShowHideLinks();
294
-        if ($this->ticket->required()) {
295
-            $html .= \EEH_HTML::p(
296
-                    apply_filters(
297
-                            'FHEE__ticket_selector_chart_template__ticket_required_message',
298
-                            esc_html__('This ticket is required and must be purchased.', 'event_espresso')
299
-                    ),
300
-                    '', 'ticket-required-pg'
301
-            );
302
-        }
303
-        $html .= \EEH_HTML::tdx();
304
-        return $html;
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * ticketPriceTableCell
311
-     *
312
-     * @param float $ticket_price
313
-     * @param bool  $ticket_bundle
314
-     * @return string
315
-     * @throws EE_Error
316
-     */
317
-    protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
318
-    {
319
-        $html = '';
320
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
321
-            $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
322
-            $html .= \EEH_Template::format_currency($ticket_price);
323
-            $html .= $this->ticket->taxable()
324
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
325
-                : '';
326
-            $html .= ' ';
327
-            $html .= \EEH_HTML::span(
328
-                $ticket_bundle
329
-                    ? apply_filters(
330
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
331
-                        __(' / bundle', 'event_espresso')
332
-                    )
333
-                    : apply_filters(
334
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
335
-                        __('', 'event_espresso')
336
-                    ),
337
-                '', 'smaller-text no-bold'
338
-            );
339
-            $html .= ' ';
340
-            $html .= \EEH_HTML::tdx();
341
-            $this->cols++;
342
-        }
343
-        return $html;
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * onlyOneAttendeeCanRegister
350
-     *
351
-     * @return string
352
-     */
353
-    protected function onlyOneAttendeeCanRegister()
354
-    {
355
-        // display submit button since we have tickets available
356
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
357
-        $this->hidden_input_qty = false;
358
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
359
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
360
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
361
-        $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
362
-        $html .= ' title=""/>';
363
-        return $html;
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * ticketQuantitySelector
370
-     *
371
-     * @param int $min
372
-     * @param int $max
373
-     * @return string
374
-     * @throws EE_Error
375
-     */
376
-    protected function ticketQuantitySelector($min = 0, $max = 0)
377
-    {
378
-        // display submit button since we have tickets available
379
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
380
-        $this->hidden_input_qty = false;
381
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
382
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
383
-        $html .= ' class="ticket-selector-tbl-qty-slct">';
384
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
385
-        if ($min !== 0 && ! $this->ticket->required()) {
386
-            $html .= '<option value="0">&nbsp;0&nbsp;</option>';
387
-        }
388
-        // offer ticket quantities from the min to the max
389
-        for ($i = $min; $i <= $max; $i++) {
390
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
391
-        }
392
-        $html .= '</select>';
393
-        return $html;
394
-    }
395
-
396
-
397
-
398
-    /**
399
-     * getHiddenInputs
400
-     *
401
-     * @return string
402
-     * @throws EE_Error
403
-     */
404
-    protected function ticketQtyAndIdHiddenInputs()
405
-    {
406
-        $html = '';
407
-        // depending on group reg we need to change the format for qty
408
-        if ($this->hidden_input_qty) {
409
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
410
-        }
411
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
412
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
413
-        return $html;
414
-    }
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) {
199
+			return $ticket_selector_row_html
200
+				   . $new_row_cells_content
201
+				   . $this->ticketQtyAndIdHiddenInputs()
202
+				   . \EEH_HTML::trx();
203
+		}
204
+		$this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
205
+
206
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
207
+		$ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
208
+		$ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
209
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
210
+		if (empty($this->ticket_status_display)) {
211
+			if ($this->max_atndz === 1) {
212
+				// only ONE attendee is allowed to register at a time
213
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
214
+			} else if ($max > 0) {
215
+				$ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
216
+			}
217
+		}
218
+		$ticket_selector_row_html .= $this->ticket_status_display;
219
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
220
+		$ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
221
+		$ticket_selector_row_html .= \EEH_HTML::tdx();
222
+		$ticket_selector_row_html .= \EEH_HTML::trx();
223
+
224
+
225
+		$this->row++;
226
+		return $ticket_selector_row_html;
227
+	}
228
+
229
+
230
+
231
+	/**
232
+	 * setTicketMinAndMax
233
+	 *
234
+	 * @param int $remaining
235
+	 * @return array
236
+	 * @throws EE_Error
237
+	 */
238
+	protected function setTicketMinAndMax($remaining)
239
+	{
240
+		// offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
241
+		$max = min($remaining, $this->max_atndz);
242
+		// but... we also want to restrict the number of tickets by the ticket max setting,
243
+		// however, the max still can't be higher than what was just set above
244
+		$max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
245
+		// and we also want to restrict the minimum number of tickets by the ticket min setting
246
+		$min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
247
+		// and if the ticket is required, then make sure that min qty is at least 1
248
+		$min = $this->ticket->required() ? max($min, 1) : $min;
249
+		return array($min, $max);
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * getTicketPriceDetails
256
+	 *
257
+	 * @return array
258
+	 * @throws EE_Error
259
+	 */
260
+	protected function getTicketPriceDetails()
261
+	{
262
+		$ticket_price = $this->tax_settings->prices_displayed_including_taxes
263
+			? $this->ticket->get_ticket_total_with_taxes()
264
+			: $this->ticket->get_ticket_subtotal();
265
+		$ticket_bundle = false;
266
+		$ticket_min = $this->ticket->min();
267
+		// for ticket bundles, set min and max qty the same
268
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
269
+			$ticket_price *= $ticket_min;
270
+			$ticket_bundle = true;
271
+		}
272
+		$ticket_price = apply_filters(
273
+			'FHEE__ticket_selector_chart_template__ticket_price',
274
+			$ticket_price,
275
+			$this->ticket
276
+		);
277
+		return array($ticket_price, $ticket_bundle);
278
+	}
279
+
280
+
281
+
282
+
283
+	/**
284
+	 * ticketNameTableCell
285
+	 *
286
+	 * @return string
287
+	 * @throws EE_Error
288
+	 */
289
+	protected function ticketNameTableCell()
290
+	{
291
+		$html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
292
+		$html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
293
+		$html .= $this->ticket_details->getShowHideLinks();
294
+		if ($this->ticket->required()) {
295
+			$html .= \EEH_HTML::p(
296
+					apply_filters(
297
+							'FHEE__ticket_selector_chart_template__ticket_required_message',
298
+							esc_html__('This ticket is required and must be purchased.', 'event_espresso')
299
+					),
300
+					'', 'ticket-required-pg'
301
+			);
302
+		}
303
+		$html .= \EEH_HTML::tdx();
304
+		return $html;
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * ticketPriceTableCell
311
+	 *
312
+	 * @param float $ticket_price
313
+	 * @param bool  $ticket_bundle
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 */
317
+	protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
318
+	{
319
+		$html = '';
320
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
321
+			$html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
322
+			$html .= \EEH_Template::format_currency($ticket_price);
323
+			$html .= $this->ticket->taxable()
324
+				? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
325
+				: '';
326
+			$html .= '&nbsp;';
327
+			$html .= \EEH_HTML::span(
328
+				$ticket_bundle
329
+					? apply_filters(
330
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
331
+						__(' / bundle', 'event_espresso')
332
+					)
333
+					: apply_filters(
334
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
335
+						__('', 'event_espresso')
336
+					),
337
+				'', 'smaller-text no-bold'
338
+			);
339
+			$html .= '&nbsp;';
340
+			$html .= \EEH_HTML::tdx();
341
+			$this->cols++;
342
+		}
343
+		return $html;
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * onlyOneAttendeeCanRegister
350
+	 *
351
+	 * @return string
352
+	 */
353
+	protected function onlyOneAttendeeCanRegister()
354
+	{
355
+		// display submit button since we have tickets available
356
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
357
+		$this->hidden_input_qty = false;
358
+		$html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
359
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
360
+		$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
361
+		$html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
362
+		$html .= ' title=""/>';
363
+		return $html;
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * ticketQuantitySelector
370
+	 *
371
+	 * @param int $min
372
+	 * @param int $max
373
+	 * @return string
374
+	 * @throws EE_Error
375
+	 */
376
+	protected function ticketQuantitySelector($min = 0, $max = 0)
377
+	{
378
+		// display submit button since we have tickets available
379
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
380
+		$this->hidden_input_qty = false;
381
+		$html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
382
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
383
+		$html .= ' class="ticket-selector-tbl-qty-slct">';
384
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
385
+		if ($min !== 0 && ! $this->ticket->required()) {
386
+			$html .= '<option value="0">&nbsp;0&nbsp;</option>';
387
+		}
388
+		// offer ticket quantities from the min to the max
389
+		for ($i = $min; $i <= $max; $i++) {
390
+			$html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
391
+		}
392
+		$html .= '</select>';
393
+		return $html;
394
+	}
395
+
396
+
397
+
398
+	/**
399
+	 * getHiddenInputs
400
+	 *
401
+	 * @return string
402
+	 * @throws EE_Error
403
+	 */
404
+	protected function ticketQtyAndIdHiddenInputs()
405
+	{
406
+		$html = '';
407
+		// depending on group reg we need to change the format for qty
408
+		if ($this->hidden_input_qty) {
409
+			$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
410
+		}
411
+		$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
412
+		$html .= ' value="' . $this->ticket->ID() . '"/>';
413
+		return $html;
414
+	}
415 415
 
416 416
 }
417 417
 // End of file TicketSelectorRowStandard.php
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorSimple.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,54 +18,54 @@
 block discarded – undo
18 18
 class TicketSelectorSimple extends TicketSelector
19 19
 {
20 20
 
21
-    /**
22
-     * @var \EE_Ticket $ticket
23
-     */
24
-    protected $ticket;
21
+	/**
22
+	 * @var \EE_Ticket $ticket
23
+	 */
24
+	protected $ticket;
25 25
 
26 26
 
27 27
 
28
-    /**
29
-     * TicketSelectorSimple constructor.
30
-     *
31
-     * @param \EE_Event  $event
32
-     * @param \EE_Ticket $ticket
33
-     * @param int        $max_attendees
34
-     * @param array      $template_args
35
-     */
36
-    public function __construct(\EE_Event $event, \EE_Ticket $ticket, $max_attendees, array $template_args)
37
-    {
38
-        $this->ticket = $ticket;
39
-        parent::__construct($event, array($this->ticket), $max_attendees, $template_args);
40
-    }
28
+	/**
29
+	 * TicketSelectorSimple constructor.
30
+	 *
31
+	 * @param \EE_Event  $event
32
+	 * @param \EE_Ticket $ticket
33
+	 * @param int        $max_attendees
34
+	 * @param array      $template_args
35
+	 */
36
+	public function __construct(\EE_Event $event, \EE_Ticket $ticket, $max_attendees, array $template_args)
37
+	{
38
+		$this->ticket = $ticket;
39
+		parent::__construct($event, array($this->ticket), $max_attendees, $template_args);
40
+	}
41 41
 
42 42
 
43 43
 
44
-    /**
45
-     * sets any and all template args that are required for this Ticket Selector
46
-     *
47
-     * @return void
48
-     * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
49
-     * @throws \EE_Error
50
-     */
51
-    protected function addTemplateArgs()
52
-    {
53
-        unset($this->template_args['tickets']);
54
-        $this->template_args['ticket'] = $this->ticket;
55
-        $ticket_selector_row = new TicketSelectorRowSimple(
56
-            $this->ticket,
57
-            $this->max_attendees,
58
-            $this->template_args['date_format'],
59
-            $this->template_args['event_status']
60
-        );
61
-        $this->template_args['TKT_ID'] = $this->ticket->ID();
62
-        $ticket_selector_row->setupTicketStatusDisplay();
63
-        $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay();
64
-        if (empty($this->template_args['ticket_status_display'])) {
65
-            add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
66
-        }
67
-        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
68
-    }
44
+	/**
45
+	 * sets any and all template args that are required for this Ticket Selector
46
+	 *
47
+	 * @return void
48
+	 * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
49
+	 * @throws \EE_Error
50
+	 */
51
+	protected function addTemplateArgs()
52
+	{
53
+		unset($this->template_args['tickets']);
54
+		$this->template_args['ticket'] = $this->ticket;
55
+		$ticket_selector_row = new TicketSelectorRowSimple(
56
+			$this->ticket,
57
+			$this->max_attendees,
58
+			$this->template_args['date_format'],
59
+			$this->template_args['event_status']
60
+		);
61
+		$this->template_args['TKT_ID'] = $this->ticket->ID();
62
+		$ticket_selector_row->setupTicketStatusDisplay();
63
+		$this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay();
64
+		if (empty($this->template_args['ticket_status_display'])) {
65
+			add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
66
+		}
67
+		$this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
68
+	}
69 69
 
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
         if (empty($this->template_args['ticket_status_display'])) {
65 65
             add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
66 66
         }
67
-        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
67
+        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH.'simple_ticket_selector.template.php';
68 68
     }
69 69
 
70 70
 
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowSimple.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@
 block discarded – undo
18 18
 class TicketSelectorRowSimple extends TicketSelectorRow
19 19
 {
20 20
 
21
-    /**
22
-     * @throws EE_Error
23
-     */
24
-    public function setupTicketStatusDisplay()
25
-    {
26
-        $remaining = $this->ticket->remaining();
27
-        list($tkt_status, $ticket_status) = $this->getTicketStatusClasses($remaining);
28
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
29
-    }
21
+	/**
22
+	 * @throws EE_Error
23
+	 */
24
+	public function setupTicketStatusDisplay()
25
+	{
26
+		$remaining = $this->ticket->remaining();
27
+		list($tkt_status, $ticket_status) = $this->getTicketStatusClasses($remaining);
28
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
29
+	}
30 30
 
31 31
 
32 32
 
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRow.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -19,249 +19,249 @@
 block discarded – undo
19 19
 abstract class TicketSelectorRow
20 20
 {
21 21
 
22
-    /**
23
-     * @var \EE_Ticket $ticket
24
-     */
25
-    protected $ticket;
26
-
27
-    /**
28
-     * @var int $total_tickets
29
-     */
30
-    protected $total_tickets;
31
-
32
-    /**
33
-     * @var int $max_atndz
34
-     */
35
-    protected $max_atndz;
36
-
37
-    /**
38
-     * @var string $date_format
39
-     */
40
-    protected $date_format;
41
-
42
-    /**
43
-     * @var int $EVT_ID
44
-     */
45
-    protected $EVT_ID;
46
-
47
-    /**
48
-     * @var string $event_status
49
-     */
50
-    protected $event_status;
51
-
52
-    /**
53
-     * @var boolean $required_ticket_sold_out
54
-     */
55
-    protected $required_ticket_sold_out;
56
-
57
-    /**
58
-     * @var string $ticket_status_display
59
-     */
60
-    protected $ticket_status_display;
61
-
62
-
63
-
64
-    /**
65
-     * @param \EE_Ticket $ticket
66
-     * @param int        $max_atndz
67
-     * @param string     $date_format
68
-     * @param string     $event_status
69
-     * @param bool       $required_ticket_sold_out
70
-     * @throws EE_Error
71
-     * @throws UnexpectedEntityException
72
-     */
73
-    public function __construct(
74
-        \EE_Ticket $ticket,
75
-        $max_atndz,
76
-        $date_format,
77
-        $event_status,
78
-        $required_ticket_sold_out = false
79
-    ) {
80
-        $this->ticket = $ticket;
81
-        $this->max_atndz = $max_atndz;
82
-        $this->date_format = $date_format;
83
-        $this->EVT_ID = $this->ticket->get_event_ID();
84
-        $this->event_status = $event_status;
85
-        $this->required_ticket_sold_out = $required_ticket_sold_out;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * getTicketStatusClasses
92
-     *
93
-     * @param int $remaining
94
-     * @return array
95
-     * @throws EE_Error
96
-     */
97
-    protected function getTicketStatusClasses($remaining = 0)
98
-    {
99
-        // if a previous required ticket with the same sale start date is sold out,
100
-        // then mark this ticket as sold out as well.
101
-        // tickets that go on sale at a later date than the required ticket  will NOT be affected
102
-        $tkt_status = $this->required_ticket_sold_out !== false
103
-                      && $this->required_ticket_sold_out === $this->ticket->start_date()
104
-            ? \EE_Ticket::sold_out
105
-            : $this->ticket->ticket_status();
106
-        $tkt_status = $this->event_status === \EE_Datetime::sold_out
107
-            ? \EE_Ticket::sold_out
108
-            : $tkt_status;
109
-        // check ticket status
110
-        switch ($tkt_status) {
111
-            // sold_out
112
-            case \EE_Ticket::sold_out :
113
-                $ticket_status = 'ticket-sales-sold-out';
114
-                $status_class = 'ticket-sales-sold-out lt-grey-text';
115
-                break;
116
-            // expired
117
-            case \EE_Ticket::expired :
118
-                $ticket_status = 'ticket-sales-expired';
119
-                $status_class = 'ticket-sales-expired lt-grey-text';
120
-                break;
121
-            // archived
122
-            case \EE_Ticket::archived :
123
-                $ticket_status = 'archived-ticket';
124
-                $status_class = 'archived-ticket hidden';
125
-                break;
126
-            // pending
127
-            case \EE_Ticket::pending :
128
-                $ticket_status = 'ticket-pending';
129
-                $status_class = 'ticket-pending';
130
-                break;
131
-            // onsale
132
-            case \EE_Ticket::onsale :
133
-            default :
134
-                $ticket_status = 'ticket-on-sale';
135
-                $status_class = 'ticket-on-sale';
136
-                break;
137
-        }
138
-        $ticket_status = \EEH_HTML::span($this->ticket->ticket_status(true, ($remaining > 0)), '', $ticket_status);
139
-        return array($tkt_status, $ticket_status, $status_class);
140
-    }
141
-
142
-
143
-    /**
144
-     * @return string
145
-     */
146
-    public function getTicketStatusDisplay()
147
-    {
148
-        return $this->ticket_status_display;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * setTicketStatusDisplay
155
-     *
156
-     * @param string $tkt_status
157
-     * @param string $ticket_status
158
-     * @param int    $remaining
159
-     * @throws EE_Error
160
-     */
161
-    protected function setTicketStatusDisplay($tkt_status, $ticket_status, $remaining) {
162
-        $this->ticket_status_display = '';
163
-        // now depending on the ticket and other circumstances...
164
-        if ($this->max_atndz === 0) {
165
-            // registration is CLOSED because admin set max attendees to ZERO
166
-            $this->ticket_status_display = $this->registrationClosed();
167
-        } else if ($tkt_status === \EE_Ticket::sold_out || $remaining === 0) {
168
-            // SOLD OUT - no tickets remaining
169
-            $this->ticket_status_display = $this->ticketsSoldOut();
170
-        } else if ($tkt_status === \EE_Ticket::expired || $tkt_status === \EE_Ticket::archived) {
171
-            // expired or archived ticket
172
-            $this->ticket_status_display = $ticket_status;
173
-        } else if ($tkt_status === \EE_Ticket::pending) {
174
-            // ticket not on sale yet
175
-            $this->ticket_status_display = $this->ticketsSalesPending();
176
-        } else if ($this->ticket->min() > $remaining) {
177
-            // min qty purchasable is less than tickets available
178
-            $this->ticket_status_display = $this->notEnoughTicketsAvailable();
179
-        }
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * registrationClosed
186
-     */
187
-    protected function registrationClosed()
188
-    {
189
-        return \EEH_HTML::span(
190
-            apply_filters(
191
-                'FHEE__ticket_selector_chart_template__ticket_closed_msg',
192
-                __('Closed', 'event_espresso')
193
-            ),
194
-            '', 'sold-out'
195
-        );
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * ticketsSoldOut
202
-     */
203
-    protected function ticketsSoldOut()
204
-    {
205
-        return \EEH_HTML::span(
206
-            apply_filters(
207
-                'FHEE__ticket_selector_chart_template__ticket_sold_out_msg',
208
-                __('Sold&nbsp;Out', 'event_espresso')
209
-            ),
210
-            '', 'sold-out'
211
-        );
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * ticketsSalesPending
218
-     *
219
-     * @throws EE_Error
220
-     */
221
-    protected function ticketsSalesPending()
222
-    {
223
-        return \EEH_HTML::span(
224
-            \EEH_HTML::span(
225
-                apply_filters(
226
-                    'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg',
227
-                    __('Goes&nbsp;On&nbsp;Sale', 'event_espresso')
228
-                ),
229
-                '', 'ticket-pending'
230
-            )
231
-            . \EEH_HTML::br()
232
-            . \EEH_HTML::span(
233
-                $this->ticket->get_i18n_datetime(
234
-                    'TKT_start_date',
235
-                    apply_filters(
236
-                        'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',
237
-                        $this->date_format
238
-                    )
239
-                ),
240
-                '', 'small-text'
241
-            ),
242
-            '', 'ticket-pending-pg'
243
-        );
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * notEnoughTicketsAvailable
250
-     */
251
-    protected function notEnoughTicketsAvailable()
252
-    {
253
-        return \EEH_HTML::div(
254
-            \EEH_HTML::span(
255
-                apply_filters(
256
-                    'FHEE__ticket_selector_chart_template__ticket_not_available_msg',
257
-                    __('Not Available', 'event_espresso')
258
-                ),
259
-                '', 'archived-ticket small-text'
260
-            )
261
-            . \EEH_HTML::br(),
262
-            '', 'archived-ticket-pg'
263
-        );
264
-    }
22
+	/**
23
+	 * @var \EE_Ticket $ticket
24
+	 */
25
+	protected $ticket;
26
+
27
+	/**
28
+	 * @var int $total_tickets
29
+	 */
30
+	protected $total_tickets;
31
+
32
+	/**
33
+	 * @var int $max_atndz
34
+	 */
35
+	protected $max_atndz;
36
+
37
+	/**
38
+	 * @var string $date_format
39
+	 */
40
+	protected $date_format;
41
+
42
+	/**
43
+	 * @var int $EVT_ID
44
+	 */
45
+	protected $EVT_ID;
46
+
47
+	/**
48
+	 * @var string $event_status
49
+	 */
50
+	protected $event_status;
51
+
52
+	/**
53
+	 * @var boolean $required_ticket_sold_out
54
+	 */
55
+	protected $required_ticket_sold_out;
56
+
57
+	/**
58
+	 * @var string $ticket_status_display
59
+	 */
60
+	protected $ticket_status_display;
61
+
62
+
63
+
64
+	/**
65
+	 * @param \EE_Ticket $ticket
66
+	 * @param int        $max_atndz
67
+	 * @param string     $date_format
68
+	 * @param string     $event_status
69
+	 * @param bool       $required_ticket_sold_out
70
+	 * @throws EE_Error
71
+	 * @throws UnexpectedEntityException
72
+	 */
73
+	public function __construct(
74
+		\EE_Ticket $ticket,
75
+		$max_atndz,
76
+		$date_format,
77
+		$event_status,
78
+		$required_ticket_sold_out = false
79
+	) {
80
+		$this->ticket = $ticket;
81
+		$this->max_atndz = $max_atndz;
82
+		$this->date_format = $date_format;
83
+		$this->EVT_ID = $this->ticket->get_event_ID();
84
+		$this->event_status = $event_status;
85
+		$this->required_ticket_sold_out = $required_ticket_sold_out;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * getTicketStatusClasses
92
+	 *
93
+	 * @param int $remaining
94
+	 * @return array
95
+	 * @throws EE_Error
96
+	 */
97
+	protected function getTicketStatusClasses($remaining = 0)
98
+	{
99
+		// if a previous required ticket with the same sale start date is sold out,
100
+		// then mark this ticket as sold out as well.
101
+		// tickets that go on sale at a later date than the required ticket  will NOT be affected
102
+		$tkt_status = $this->required_ticket_sold_out !== false
103
+					  && $this->required_ticket_sold_out === $this->ticket->start_date()
104
+			? \EE_Ticket::sold_out
105
+			: $this->ticket->ticket_status();
106
+		$tkt_status = $this->event_status === \EE_Datetime::sold_out
107
+			? \EE_Ticket::sold_out
108
+			: $tkt_status;
109
+		// check ticket status
110
+		switch ($tkt_status) {
111
+			// sold_out
112
+			case \EE_Ticket::sold_out :
113
+				$ticket_status = 'ticket-sales-sold-out';
114
+				$status_class = 'ticket-sales-sold-out lt-grey-text';
115
+				break;
116
+			// expired
117
+			case \EE_Ticket::expired :
118
+				$ticket_status = 'ticket-sales-expired';
119
+				$status_class = 'ticket-sales-expired lt-grey-text';
120
+				break;
121
+			// archived
122
+			case \EE_Ticket::archived :
123
+				$ticket_status = 'archived-ticket';
124
+				$status_class = 'archived-ticket hidden';
125
+				break;
126
+			// pending
127
+			case \EE_Ticket::pending :
128
+				$ticket_status = 'ticket-pending';
129
+				$status_class = 'ticket-pending';
130
+				break;
131
+			// onsale
132
+			case \EE_Ticket::onsale :
133
+			default :
134
+				$ticket_status = 'ticket-on-sale';
135
+				$status_class = 'ticket-on-sale';
136
+				break;
137
+		}
138
+		$ticket_status = \EEH_HTML::span($this->ticket->ticket_status(true, ($remaining > 0)), '', $ticket_status);
139
+		return array($tkt_status, $ticket_status, $status_class);
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return string
145
+	 */
146
+	public function getTicketStatusDisplay()
147
+	{
148
+		return $this->ticket_status_display;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * setTicketStatusDisplay
155
+	 *
156
+	 * @param string $tkt_status
157
+	 * @param string $ticket_status
158
+	 * @param int    $remaining
159
+	 * @throws EE_Error
160
+	 */
161
+	protected function setTicketStatusDisplay($tkt_status, $ticket_status, $remaining) {
162
+		$this->ticket_status_display = '';
163
+		// now depending on the ticket and other circumstances...
164
+		if ($this->max_atndz === 0) {
165
+			// registration is CLOSED because admin set max attendees to ZERO
166
+			$this->ticket_status_display = $this->registrationClosed();
167
+		} else if ($tkt_status === \EE_Ticket::sold_out || $remaining === 0) {
168
+			// SOLD OUT - no tickets remaining
169
+			$this->ticket_status_display = $this->ticketsSoldOut();
170
+		} else if ($tkt_status === \EE_Ticket::expired || $tkt_status === \EE_Ticket::archived) {
171
+			// expired or archived ticket
172
+			$this->ticket_status_display = $ticket_status;
173
+		} else if ($tkt_status === \EE_Ticket::pending) {
174
+			// ticket not on sale yet
175
+			$this->ticket_status_display = $this->ticketsSalesPending();
176
+		} else if ($this->ticket->min() > $remaining) {
177
+			// min qty purchasable is less than tickets available
178
+			$this->ticket_status_display = $this->notEnoughTicketsAvailable();
179
+		}
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * registrationClosed
186
+	 */
187
+	protected function registrationClosed()
188
+	{
189
+		return \EEH_HTML::span(
190
+			apply_filters(
191
+				'FHEE__ticket_selector_chart_template__ticket_closed_msg',
192
+				__('Closed', 'event_espresso')
193
+			),
194
+			'', 'sold-out'
195
+		);
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * ticketsSoldOut
202
+	 */
203
+	protected function ticketsSoldOut()
204
+	{
205
+		return \EEH_HTML::span(
206
+			apply_filters(
207
+				'FHEE__ticket_selector_chart_template__ticket_sold_out_msg',
208
+				__('Sold&nbsp;Out', 'event_espresso')
209
+			),
210
+			'', 'sold-out'
211
+		);
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * ticketsSalesPending
218
+	 *
219
+	 * @throws EE_Error
220
+	 */
221
+	protected function ticketsSalesPending()
222
+	{
223
+		return \EEH_HTML::span(
224
+			\EEH_HTML::span(
225
+				apply_filters(
226
+					'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg',
227
+					__('Goes&nbsp;On&nbsp;Sale', 'event_espresso')
228
+				),
229
+				'', 'ticket-pending'
230
+			)
231
+			. \EEH_HTML::br()
232
+			. \EEH_HTML::span(
233
+				$this->ticket->get_i18n_datetime(
234
+					'TKT_start_date',
235
+					apply_filters(
236
+						'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',
237
+						$this->date_format
238
+					)
239
+				),
240
+				'', 'small-text'
241
+			),
242
+			'', 'ticket-pending-pg'
243
+		);
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * notEnoughTicketsAvailable
250
+	 */
251
+	protected function notEnoughTicketsAvailable()
252
+	{
253
+		return \EEH_HTML::div(
254
+			\EEH_HTML::span(
255
+				apply_filters(
256
+					'FHEE__ticket_selector_chart_template__ticket_not_available_msg',
257
+					__('Not Available', 'event_espresso')
258
+				),
259
+				'', 'archived-ticket small-text'
260
+			)
261
+			. \EEH_HTML::br(),
262
+			'', 'archived-ticket-pg'
263
+		);
264
+	}
265 265
 
266 266
 
267 267
 
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_system_stati_page.template.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 function ee_resurse_into_array($data) {
9 9
 	if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {//is_object($incomplete_class) actually returns false, hence why we check for it
10
-		$data = (array)$data;
10
+		$data = (array) $data;
11 11
 	}
12 12
 	if (is_array($data)) {
13 13
 		if (EEH_Array::is_associative_array($data)) {
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
 						?>
20 20
 						<tr>
21 21
 							<td>
22
-								<?php echo $data_key;?>
22
+								<?php echo $data_key; ?>
23 23
 							</td>
24 24
 							<td>
25
-								<?php ee_resurse_into_array($data_values);?>
25
+								<?php ee_resurse_into_array($data_values); ?>
26 26
 							</td>
27 27
 						</tr>
28 28
 						<?php
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
 			<ul>
37 37
 				<?php
38 38
 				foreach ($data as $datum) {
39
-					echo "<li>";ee_resurse_into_array($datum);echo "</li>";
39
+					echo "<li>"; ee_resurse_into_array($datum); echo "</li>";
40 40
 				}?>
41 41
 			</ul>
42 42
 			<?php
43 43
 		}
44
-	}else {
44
+	} else {
45 45
 		//simple value
46 46
 		echo $data;
47 47
 	}
48 48
 }
49 49
 ?>
50 50
 <h1>
51
-	<?php _e("System Information", "event_espresso");?> <a href="<?php echo $download_system_status_url;?>" class="button-secondary"><?php esc_html_e( 'Download to File', 'event_espresso' );?></a>
51
+	<?php _e("System Information", "event_espresso"); ?> <a href="<?php echo $download_system_status_url; ?>" class="button-secondary"><?php esc_html_e('Download to File', 'event_espresso'); ?></a>
52 52
 </h1>
53 53
 <div class="padding">
54 54
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		<?php
57 57
 		foreach ($system_stati as $status_category_slug => $data) {
58 58
 			if (is_object($data)) {
59
-				$data = (array)$data;
59
+				$data = (array) $data;
60 60
 			}
61 61
 			?>
62 62
 			<thead>
Please login to merge, or discard this patch.
core/db_classes/EE_Import.class.php 3 patches
Doc Comments   +4 added lines, -10 removed lines patch added patch discarded remove patch
@@ -79,10 +79,6 @@  discard block
 block discarded – undo
79 79
 	 *	@ access 	public
80 80
 	 * 	@param 	string 		$title - heading for the form
81 81
 	 * 	@param 	string 		$intro - additional text explaing what to do
82
-	 * 	@param 	string 		$page - EE Admin page to direct form to - in the form "espresso_{pageslug}"
83
-	 * 	@param 	string 		$action - EE Admin page route array "action" that form will direct to
84
-	 * 	@param 	string 		$type - type of file to import
85
-	 *	@ return 	string
86 82
 	 */
87 83
 	public function upload_form ( $title, $intro, $form_url, $action, $type  ) {
88 84
 
@@ -121,7 +117,7 @@  discard block
 block discarded – undo
121 117
 	/**
122 118
 	 *	@Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
123 119
 	 *	@access public
124
-	 *	@return boolean success
120
+	 *	@return boolean|null success
125 121
 	 */
126 122
 	public function import() {
127 123
 
@@ -272,8 +268,7 @@  discard block
 block discarded – undo
272 268
       *
273 269
       * @access public
274 270
       * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array()
275
-      * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
276
-      * @return TRUE on success, FALSE on fail
271
+      * @return boolean on success, FALSE on fail
277 272
       * @throws \EE_Error
278 273
       */
279 274
 	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
@@ -370,7 +365,7 @@  discard block
 block discarded – undo
370 365
 	 * we need to insert a new row for that ID, and then map from the non-existent ID
371 366
 	 * to the newly-inserted real ID.
372 367
 	 * @param type $csv_data_array
373
-	 * @param type $export_from_site_a_to_b
368
+	 * @param boolean $export_from_site_a_to_b
374 369
 	 * @param type $old_db_to_new_db_mapping
375 370
 	 * @return array updated $old_db_to_new_db_mapping
376 371
 	 */
@@ -487,7 +482,6 @@  discard block
 block discarded – undo
487 482
 	 * @param type $id_in_csv
488 483
 	 * @param type $model_object_data
489 484
 	 * @param EEM_Base $model
490
-	 * @param type $old_db_to_new_db_mapping
491 485
 	 * @return
492 486
 	 */
493 487
 	protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) {
@@ -597,7 +591,7 @@  discard block
 block discarded – undo
597 591
 	 * @param type $object_id
598 592
 	 * @param string $model_name
599 593
 	 * @param array $old_db_to_new_db_mapping
600
-	 * @param type $export_from_site_a_to_b
594
+	 * @param boolean $export_from_site_a_to_b
601 595
 	 * @return int
602 596
 	 */
603 597
 	protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
Please login to merge, or discard this patch.
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -131,43 +131,43 @@  discard block
 block discarded – undo
131 131
 		if ( isset( $_REQUEST['import'] )) {
132 132
 			if( isset( $_POST['csv_submitted'] )) {
133 133
 
134
-			    switch ( $_FILES['file']['error'][0] ) {
135
-			        case UPLOAD_ERR_OK:
136
-			            $error_msg = FALSE;
137
-			            break;
138
-			        case UPLOAD_ERR_INI_SIZE:
139
-			            $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
140
-			            break;
141
-			        case UPLOAD_ERR_FORM_SIZE:
142
-			            $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
143
-			            break;
144
-			        case UPLOAD_ERR_PARTIAL:
145
-			            $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
146
-			            break;
147
-			        case UPLOAD_ERR_NO_FILE:
148
-			            $error_msg = __('No file was uploaded.', "event_espresso");
149
-			            break;
150
-			        case UPLOAD_ERR_NO_TMP_DIR:
151
-			            $error_msg = __('Missing a temporary folder.', "event_espresso");
152
-			            break;
153
-			        case UPLOAD_ERR_CANT_WRITE:
154
-			            $error_msg = __('Failed to write file to disk.', "event_espresso");
155
-			            break;
156
-			        case UPLOAD_ERR_EXTENSION:
157
-			            $error_msg = __('File upload stopped by extension.', "event_espresso");
158
-			            break;
159
-			        default:
160
-			            $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
161
-			            break;
162
-			    }
134
+				switch ( $_FILES['file']['error'][0] ) {
135
+					case UPLOAD_ERR_OK:
136
+						$error_msg = FALSE;
137
+						break;
138
+					case UPLOAD_ERR_INI_SIZE:
139
+						$error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
140
+						break;
141
+					case UPLOAD_ERR_FORM_SIZE:
142
+						$error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
143
+						break;
144
+					case UPLOAD_ERR_PARTIAL:
145
+						$error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
146
+						break;
147
+					case UPLOAD_ERR_NO_FILE:
148
+						$error_msg = __('No file was uploaded.', "event_espresso");
149
+						break;
150
+					case UPLOAD_ERR_NO_TMP_DIR:
151
+						$error_msg = __('Missing a temporary folder.', "event_espresso");
152
+						break;
153
+					case UPLOAD_ERR_CANT_WRITE:
154
+						$error_msg = __('Failed to write file to disk.', "event_espresso");
155
+						break;
156
+					case UPLOAD_ERR_EXTENSION:
157
+						$error_msg = __('File upload stopped by extension.', "event_espresso");
158
+						break;
159
+					default:
160
+						$error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
161
+						break;
162
+				}
163 163
 
164 164
 				if ( ! $error_msg ) {
165 165
 
166
-				    $filename	= $_FILES['file']['name'][0];
166
+					$filename	= $_FILES['file']['name'][0];
167 167
 					$file_ext 		= substr( strrchr( $filename, '.' ), 1 );
168
-				    $file_type 	= $_FILES['file']['type'][0];
169
-				    $temp_file	= $_FILES['file']['tmp_name'][0];
170
-				    $filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
168
+					$file_type 	= $_FILES['file']['type'][0];
169
+					$temp_file	= $_FILES['file']['tmp_name'][0];
170
+					$filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
171 171
 
172 172
 					if ( $file_ext=='csv' ) {
173 173
 
@@ -242,40 +242,40 @@  discard block
 block discarded – undo
242 242
 
243 243
 
244 244
 
245
-     /**
246
-      *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
247
-      *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
248
-      *    next level being numeric indexes adn each value representing a model object, and the last layer down
249
-      *    being keys of model fields and their proposed values.
250
-      *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
251
-      *    If the CSV data says (in the metadata row) that it's from the SAME database,
252
-      *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
253
-      *    IDs DON'T exist in the database, they're treated as temporary IDs,
254
-      *    which can used elsewhere to refer to the same object. Once an item
255
-      *    with a temporary ID gets inserted, we record its mapping from temporary
256
-      *    ID to real ID, and use the real ID in place of the temporary ID
257
-      *    when that temporary ID was used as a foreign key.
258
-      *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
259
-      *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
260
-      *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
261
-      *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
262
-      *    An important exception are non-auto-increment primary keys. If one entry in the
263
-      *    CSV file has the same ID as one in the DB, we assume they are meant to be
264
-      *    the same item, and instead update the item in the DB with that same ID.
265
-      *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
266
-      *    time you import a CSV from a different site, we remember their mappings, and
267
-      * will try to update the item in the DB instead of inserting another item (eg
268
-      * if we previously imported an event with temporary ID 1, and then it got a
269
-      * real ID of 123, we remember that. So the next time we import an event with
270
-      * temporary ID, from the same site, we know that it's real ID is 123, and will
271
-      * update that event, instead of adding a new event).
272
-      *
273
-      * @access public
274
-      * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array()
275
-      * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
276
-      * @return TRUE on success, FALSE on fail
277
-      * @throws \EE_Error
278
-      */
245
+	 /**
246
+	  *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
247
+	  *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
248
+	  *    next level being numeric indexes adn each value representing a model object, and the last layer down
249
+	  *    being keys of model fields and their proposed values.
250
+	  *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
251
+	  *    If the CSV data says (in the metadata row) that it's from the SAME database,
252
+	  *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
253
+	  *    IDs DON'T exist in the database, they're treated as temporary IDs,
254
+	  *    which can used elsewhere to refer to the same object. Once an item
255
+	  *    with a temporary ID gets inserted, we record its mapping from temporary
256
+	  *    ID to real ID, and use the real ID in place of the temporary ID
257
+	  *    when that temporary ID was used as a foreign key.
258
+	  *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
259
+	  *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
260
+	  *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
261
+	  *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
262
+	  *    An important exception are non-auto-increment primary keys. If one entry in the
263
+	  *    CSV file has the same ID as one in the DB, we assume they are meant to be
264
+	  *    the same item, and instead update the item in the DB with that same ID.
265
+	  *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
266
+	  *    time you import a CSV from a different site, we remember their mappings, and
267
+	  * will try to update the item in the DB instead of inserting another item (eg
268
+	  * if we previously imported an event with temporary ID 1, and then it got a
269
+	  * real ID of 123, we remember that. So the next time we import an event with
270
+	  * temporary ID, from the same site, we know that it's real ID is 123, and will
271
+	  * update that event, instead of adding a new event).
272
+	  *
273
+	  * @access public
274
+	  * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array()
275
+	  * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
276
+	  * @return TRUE on success, FALSE on fail
277
+	  * @throws \EE_Error
278
+	  */
279 279
 	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
280 280
 
281 281
 
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 			unset($csv_data_array[EE_CSV::metadata_header]);
307 307
 		}
308 308
 		/**
309
-		* @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
310
-		* the value will be the newly-inserted ID.
311
-		* If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
312
-		*/
309
+		 * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
310
+		 * the value will be the newly-inserted ID.
311
+		 * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
312
+		 */
313 313
 	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array());
314 314
 	   if( $old_db_to_new_db_mapping){
315 315
 		   EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url()));
Please login to merge, or discard this patch.
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
+do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3 3
 /**
4 4
  * EE_Import class
5 5
  *
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public static function instance() {
58 58
 		// check if class object is instantiated
59
-		if ( self::$_instance === NULL  or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) {
59
+		if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
60 60
 			self::$_instance = new self();
61 61
 		}
62 62
 		return self::$_instance;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * Resets the importer
67 67
 	 * @return EE_Import
68 68
 	 */
69
-	public static function reset(){
69
+	public static function reset() {
70 70
 		self::$_instance = null;
71 71
 		return self::instance();
72 72
 	}
@@ -84,27 +84,27 @@  discard block
 block discarded – undo
84 84
 	 * 	@param 	string 		$type - type of file to import
85 85
 	 *	@ return 	string
86 86
 	 */
87
-	public function upload_form ( $title, $intro, $form_url, $action, $type  ) {
87
+	public function upload_form($title, $intro, $form_url, $action, $type) {
88 88
 
89
-		$form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url );
89
+		$form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
90 90
 
91 91
 		ob_start();
92 92
 ?>
93 93
 	<div class="ee-upload-form-dv">
94
-		<h3><?php echo $title;?></h3>
95
-		<p><?php echo $intro;?></p>
94
+		<h3><?php echo $title; ?></h3>
95
+		<p><?php echo $intro; ?></p>
96 96
 
97 97
 		<form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data">
98
-			<input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>">
99
-			<input name="import" type="hidden" value="<?php echo $type;?>" />
98
+			<input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>">
99
+			<input name="import" type="hidden" value="<?php echo $type; ?>" />
100 100
 			<input type="file" name="file[]" size="90" >
101
-			<input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>">
101
+			<input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>">
102 102
 		</form>
103 103
 
104 104
 		<p class="ee-attention">
105
-			<b><?php _e( 'Attention', 'event_espresso' );?></b><br/>
106
-			<?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?>
107
-			<?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?>
105
+			<b><?php _e('Attention', 'event_espresso'); ?></b><br/>
106
+			<?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?>
107
+			<?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?>
108 108
 		</p>
109 109
 
110 110
 	</div>
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function import() {
127 127
 
128
-		require_once( EE_CLASSES . 'EE_CSV.class.php' );
128
+		require_once(EE_CLASSES.'EE_CSV.class.php');
129 129
 		$this->EE_CSV = EE_CSV::instance();
130 130
 
131
-		if ( isset( $_REQUEST['import'] )) {
132
-			if( isset( $_POST['csv_submitted'] )) {
131
+		if (isset($_REQUEST['import'])) {
132
+			if (isset($_POST['csv_submitted'])) {
133 133
 
134
-			    switch ( $_FILES['file']['error'][0] ) {
134
+			    switch ($_FILES['file']['error'][0]) {
135 135
 			        case UPLOAD_ERR_OK:
136 136
 			            $error_msg = FALSE;
137 137
 			            break;
@@ -161,32 +161,32 @@  discard block
 block discarded – undo
161 161
 			            break;
162 162
 			    }
163 163
 
164
-				if ( ! $error_msg ) {
164
+				if ( ! $error_msg) {
165 165
 
166
-				    $filename	= $_FILES['file']['name'][0];
167
-					$file_ext 		= substr( strrchr( $filename, '.' ), 1 );
168
-				    $file_type 	= $_FILES['file']['type'][0];
169
-				    $temp_file	= $_FILES['file']['tmp_name'][0];
170
-				    $filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
166
+				    $filename = $_FILES['file']['name'][0];
167
+					$file_ext = substr(strrchr($filename, '.'), 1);
168
+				    $file_type = $_FILES['file']['type'][0];
169
+				    $temp_file = $_FILES['file']['tmp_name'][0];
170
+				    $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB
171 171
 
172
-					if ( $file_ext=='csv' ) {
172
+					if ($file_ext == 'csv') {
173 173
 
174
-						$max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB
175
-						if ( $filesize < $max_upload || true) {
174
+						$max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB
175
+						if ($filesize < $max_upload || true) {
176 176
 
177
-							$wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir());
178
-							$path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename;
177
+							$wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir());
178
+							$path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename;
179 179
 
180
-							if( move_uploaded_file( $temp_file, $path_to_file )) {
180
+							if (move_uploaded_file($temp_file, $path_to_file)) {
181 181
 
182 182
 								// convert csv to array
183
-								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file );
183
+								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
184 184
 
185 185
 								// was data successfully stored in an array?
186
-								if ( is_array( $this->csv_array ) ) {
186
+								if (is_array($this->csv_array)) {
187 187
 
188
-									$import_what = str_replace( 'csv_import_', '', $_REQUEST['action'] );
189
-									$import_what = str_replace( '_', ' ', ucwords( $import_what ));
188
+									$import_what = str_replace('csv_import_', '', $_REQUEST['action']);
189
+									$import_what = str_replace('_', ' ', ucwords($import_what));
190 190
 									$processed_data = $this->csv_array;
191 191
 									$this->columns_to_save = FALSE;
192 192
 
@@ -205,33 +205,33 @@  discard block
 block discarded – undo
205 205
 
206 206
 									}
207 207
 									// save processed codes to db
208
-									if ( $this->save_csv_data_array_to_db( $processed_data, $this->columns_to_save ) ) {
208
+									if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) {
209 209
 										return TRUE;
210 210
 
211 211
 									}
212 212
 								} else {
213 213
 									// no array? must be an error
214
-									EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ );
214
+									EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__);
215 215
 									return FALSE;
216 216
 								}
217 217
 
218 218
 							} else {
219
-								EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ );
219
+								EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__);
220 220
 								return FALSE;
221 221
 							}
222 222
 
223 223
 						} else {
224
-							EE_Error::add_error( sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"),$filename,$max_upload), __FILE__, __FUNCTION__, __LINE__ );
224
+							EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__);
225 225
 							return FALSE;
226 226
 						}
227 227
 
228 228
 					} else {
229
-						EE_Error::add_error( sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ );
229
+						EE_Error::add_error(sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__);
230 230
 						return FALSE;
231 231
 					}
232 232
 
233 233
 				} else {
234
-					EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
234
+					EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
235 235
 					return FALSE;
236 236
 				}
237 237
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
       * @return TRUE on success, FALSE on fail
277 277
       * @throws \EE_Error
278 278
       */
279
-	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
279
+	public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) {
280 280
 
281 281
 
282 282
 		$success = FALSE;
@@ -286,22 +286,22 @@  discard block
 block discarded – undo
286 286
 		$export_from_site_a_to_b = true;
287 287
 		// first level of array is not table information but a table name was passed to the function
288 288
 		// array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
289
-		if($model_name){
289
+		if ($model_name) {
290 290
 			$csv_data_array = array($csv_data_array);
291 291
 		}
292 292
 		// begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
293 293
 		$old_site_url = 'none-specified';
294 294
 
295 295
 		//hanlde metadata
296
-		if(isset($csv_data_array[EE_CSV::metadata_header]) ){
296
+		if (isset($csv_data_array[EE_CSV::metadata_header])) {
297 297
 			$csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]);
298 298
 			//ok so its metadata, dont try to save it to ehte db obviously...
299
-			if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){
299
+			if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
300 300
 				EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso")));
301 301
 				$export_from_site_a_to_b = false;
302
-			}else{
303
-				$old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
304
-				EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url()));
302
+			} else {
303
+				$old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
304
+				EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"), $old_site_url, site_url()));
305 305
 			};
306 306
 			unset($csv_data_array[EE_CSV::metadata_header]);
307 307
 		}
@@ -310,30 +310,30 @@  discard block
 block discarded – undo
310 310
 		* the value will be the newly-inserted ID.
311 311
 		* If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
312 312
 		*/
313
-	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array());
314
-	   if( $old_db_to_new_db_mapping){
315
-		   EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url()));
313
+	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array());
314
+	   if ($old_db_to_new_db_mapping) {
315
+		   EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"), $old_site_url, site_url()));
316 316
 	   }
317 317
 	   $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping);
318 318
 
319 319
 		//save the mapping from old db to new db in case they try re-importing the same data from the same website again
320
-		update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping);
320
+		update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping);
321 321
 
322
-		if ( $this->_total_updates > 0 ) {
323
-			EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->_total_updates));
322
+		if ($this->_total_updates > 0) {
323
+			EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->_total_updates));
324 324
 			$success = true;
325 325
 		}
326
-		if ( $this->_total_inserts > 0 ) {
327
-			EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->_total_inserts));
326
+		if ($this->_total_inserts > 0) {
327
+			EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts));
328 328
 			$success = true;
329 329
 		}
330 330
 
331
-		if ( $this->_total_update_errors > 0 ) {
332
-			EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"),$this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__ );
331
+		if ($this->_total_update_errors > 0) {
332
+			EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"), $this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__);
333 333
 			$error = true;
334 334
 		}
335
-		if ( $this->_total_insert_errors > 0 ) {
336
-			EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"),$this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__ );
335
+		if ($this->_total_insert_errors > 0) {
336
+			EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"), $this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__);
337 337
 			$error = true;
338 338
 		}
339 339
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
343 343
 
344 344
 		// if there was at least one success and absolutely no errors
345
-		if ( $success && ! $error ) {
345
+		if ($success && ! $error) {
346 346
 			return TRUE;
347 347
 		} else {
348 348
 			return FALSE;
@@ -374,81 +374,81 @@  discard block
 block discarded – undo
374 374
 	 * @param type $old_db_to_new_db_mapping
375 375
 	 * @return array updated $old_db_to_new_db_mapping
376 376
 	 */
377
-	public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping ) {
378
-		foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) {
377
+	public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) {
378
+		foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
379 379
 			//now check that assumption was correct. If
380
-			if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
380
+			if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
381 381
 				$model_name = $model_name_in_csv_data;
382
-			}else {
382
+			} else {
383 383
 				// no table info in the array and no table name passed to the function?? FAIL
384
-				EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
384
+				EE_Error::add_error(__('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
385 385
 				return FALSE;
386 386
 			}
387 387
 			/* @var $model EEM_Base */
388 388
 			$model = EE_Registry::instance()->load_model($model_name);
389 389
 
390 390
 			//so without further ado, scanning all the data provided for primary keys and their inital values
391
-			foreach ( $model_data_from_import as $model_object_data ) {
391
+			foreach ($model_data_from_import as $model_object_data) {
392 392
 				//before we do ANYTHING, make sure the csv row wasn't just completely blank
393 393
 				$row_is_completely_empty = true;
394
-				foreach($model_object_data as $field){
395
-					if($field){
394
+				foreach ($model_object_data as $field) {
395
+					if ($field) {
396 396
 						$row_is_completely_empty = false;
397 397
 					}
398 398
 				}
399
-				if($row_is_completely_empty){
399
+				if ($row_is_completely_empty) {
400 400
 					continue;
401 401
 				}
402 402
 				//find the PK in the row of data (or a combined key if
403 403
 				//there is no primary key)
404
-				if($model->has_primary_key_field()){
405
-					$id_in_csv =  $model_object_data[$model->primary_key_name()];
406
-				}else{
404
+				if ($model->has_primary_key_field()) {
405
+					$id_in_csv = $model_object_data[$model->primary_key_name()];
406
+				} else {
407 407
 					$id_in_csv = $model->get_index_primary_key_string($model_object_data);
408 408
 				}
409 409
 
410 410
 
411
-				$model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b );
411
+				$model_object_data = $this->_replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b);
412 412
 				//now we need to decide if we're going to add a new model object given the $model_object_data,
413 413
 				//or just update.
414
-				if($export_from_site_a_to_b){
415
-					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
416
-				}else{//this is just a re-import
417
-					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
414
+				if ($export_from_site_a_to_b) {
415
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
416
+				} else {//this is just a re-import
417
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
418 418
 				}
419
-				if( $what_to_do == self::do_nothing ) {
419
+				if ($what_to_do == self::do_nothing) {
420 420
 					continue;
421 421
 				}
422 422
 
423 423
 				//double-check we actually want to insert, if that's what we're planning
424 424
 				//based on whether this item would be unique in the DB or not
425
-				if( $what_to_do == self::do_insert ) {
425
+				if ($what_to_do == self::do_insert) {
426 426
 					//we're supposed to be inserting. But wait, will this thing
427 427
 					//be acceptable if inserted?
428
-					$conflicting = $model->get_one_conflicting( $model_object_data, false );
429
-					if($conflicting){
428
+					$conflicting = $model->get_one_conflicting($model_object_data, false);
429
+					if ($conflicting) {
430 430
 						//ok, this item would conflict if inserted. Just update the item that it conflicts with.
431 431
 						$what_to_do = self::do_update;
432 432
 						//and if this model has a primary key, remember its mapping
433
-						if($model->has_primary_key_field()){
433
+						if ($model->has_primary_key_field()) {
434 434
 							$old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID();
435 435
 							$model_object_data[$model->primary_key_name()] = $conflicting->ID();
436
-						}else{
436
+						} else {
437 437
 							//we want to update this conflicting item, instead of inserting a conflicting item
438 438
 							//so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
439 439
 							//for the WHERE conditions in the update). At the time of this comment, there were no models like this
440
-							foreach($model->get_combined_primary_key_fields() as $key_field){
440
+							foreach ($model->get_combined_primary_key_fields() as $key_field) {
441 441
 								$model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name());
442 442
 							}
443 443
 						}
444 444
 					}
445 445
 				}
446
-				if( $what_to_do == self::do_insert ) {
447
-					$old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
448
-				}elseif( $what_to_do == self::do_update ) {
449
-					$old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
450
-				}else{
451
-					throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) );
446
+				if ($what_to_do == self::do_insert) {
447
+					$old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
448
+				}elseif ($what_to_do == self::do_update) {
449
+					$old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
450
+				} else {
451
+					throw new EE_Error(sprintf(__('Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso'), $what_to_do));
452 452
 				}
453 453
 			}
454 454
 		}
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 	 * @param array $old_db_to_new_db_mapping by reference so it can be modified
470 470
 	 * @return string one of the consts on this class that starts with do_*
471 471
 	 */
472
-	protected function _decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) {
472
+	protected function _decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
473 473
 		$model_name = $model->get_this_model_name();
474 474
 		//if it's a site-to-site export-and-import, see if this modelobject's id
475 475
 		//in the old data that we know of
476
-		if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){
476
+		if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) {
477 477
 			return self::do_update;
478
-		}else{
478
+		} else {
479 479
 			return self::do_insert;
480 480
 		}
481 481
 	}
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
 	 * @param type $old_db_to_new_db_mapping
491 491
 	 * @return
492 492
 	 */
493
-	protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) {
493
+	protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) {
494 494
 		//in this case, check if this thing ACTUALLY exists in the database
495
-		if( $model->get_one_conflicting( $model_object_data ) ){
495
+		if ($model->get_one_conflicting($model_object_data)) {
496 496
 			return self::do_update;
497
-		}else{
497
+		} else {
498 498
 			return self::do_insert;
499 499
 		}
500 500
 	}
@@ -513,55 +513,55 @@  discard block
 block discarded – undo
513 513
 	 * @param boolean $export_from_site_a_to_b
514 514
 	 * @return array updated model object data with temp IDs removed
515 515
 	 */
516
-	protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) {
516
+	protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
517 517
 		//if this model object's primary key is in the mapping, replace it
518
-		if( $model->has_primary_key_field() &&
518
+		if ($model->has_primary_key_field() &&
519 519
 				$model->get_primary_key_field()->is_auto_increment() &&
520
-				isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) &&
521
-				isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) {
522
-			$model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ];
520
+				isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) &&
521
+				isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) {
522
+			$model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]];
523 523
 		}
524 524
 
525
-		try{
525
+		try {
526 526
 			$model_name_field = $model->get_field_containing_related_model_name();
527 527
 			$models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
528
-		}catch( EE_Error $e ){
528
+		} catch (EE_Error $e) {
529 529
 			$model_name_field = NULL;
530 530
 			$models_pointed_to_by_model_name_field = array();
531 531
 		}
532
-		foreach( $model->field_settings( true )  as $field_obj ){
533
-			if( $field_obj instanceof EE_Foreign_Key_Int_Field ) {
532
+		foreach ($model->field_settings(true)  as $field_obj) {
533
+			if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
534 534
 				$models_pointed_to = $field_obj->get_model_names_pointed_to();
535 535
 				$found_a_mapping = false;
536
-				foreach( $models_pointed_to as $model_pointed_to_by_fk ) {
536
+				foreach ($models_pointed_to as $model_pointed_to_by_fk) {
537 537
 
538
-					if( $model_name_field ){
539
-						$value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
540
-						if( $value_of_model_name_field == $model_pointed_to_by_fk ) {
541
-							$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
542
-									$model_object_data[ $field_obj->get_name() ],
538
+					if ($model_name_field) {
539
+						$value_of_model_name_field = $model_object_data[$model_name_field->get_name()];
540
+						if ($value_of_model_name_field == $model_pointed_to_by_fk) {
541
+							$model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
542
+									$model_object_data[$field_obj->get_name()],
543 543
 									$model_pointed_to_by_fk,
544 544
 									$old_db_to_new_db_mapping,
545 545
 									$export_from_site_a_to_b );
546 546
 								$found_a_mapping = true;
547 547
 								break;
548 548
 						}
549
-					}else{
550
-						$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
551
-								$model_object_data[ $field_obj->get_name() ],
549
+					} else {
550
+						$model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
551
+								$model_object_data[$field_obj->get_name()],
552 552
 								$model_pointed_to_by_fk,
553 553
 								$old_db_to_new_db_mapping,
554 554
 								$export_from_site_a_to_b );
555 555
 						$found_a_mapping = true;
556 556
 					}
557 557
 					//once we've found a mapping for this field no need to continue
558
-					if( $found_a_mapping ) {
558
+					if ($found_a_mapping) {
559 559
 						break;
560 560
 					}
561 561
 
562 562
 
563 563
 				}
564
-			}else{
564
+			} else {
565 565
 				//it's a string foreign key (which we leave alone, because those are things
566 566
 				//like country names, which we'd really rather not make 2 USAs etc (we'd actually
567 567
 				//prefer to just update one)
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 			}
570 570
 		}
571 571
 		//
572
-		if( $model instanceof EEM_Term_Taxonomy ){
573
-			$model_object_data = $this->_handle_split_term_ids( $model_object_data );
572
+		if ($model instanceof EEM_Term_Taxonomy) {
573
+			$model_object_data = $this->_handle_split_term_ids($model_object_data);
574 574
 		}
575 575
 		return $model_object_data;
576 576
 	}
@@ -582,11 +582,11 @@  discard block
 block discarded – undo
582 582
 	 * @param type $model_object_data
583 583
 	 * @return array new model object data
584 584
 	 */
585
-	protected function _handle_split_term_ids( $model_object_data ){
586
-		if( isset( $model_object_data['term_id'] ) && isset( $model_object_data[ 'taxonomy' ]) && apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) {
587
-			$new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] );
588
-			if( $new_term_id ){
589
-				$model_object_data[ 'term_id' ] = $new_term_id;
585
+	protected function _handle_split_term_ids($model_object_data) {
586
+		if (isset($model_object_data['term_id']) && isset($model_object_data['taxonomy']) && apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) {
587
+			$new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
588
+			if ($new_term_id) {
589
+				$model_object_data['term_id'] = $new_term_id;
590 590
 			}
591 591
 		}
592 592
 		return $model_object_data;
@@ -600,18 +600,18 @@  discard block
 block discarded – undo
600 600
 	 * @param type $export_from_site_a_to_b
601 601
 	 * @return int
602 602
 	 */
603
-	protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
604
-		if(	isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){
603
+	protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
604
+		if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) {
605 605
 
606
-				return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
607
-			}elseif( $object_id == '0' || $object_id == '' ) {
606
+				return $old_db_to_new_db_mapping[$model_name][$object_id];
607
+			}elseif ($object_id == '0' || $object_id == '') {
608 608
 				//leave as-is
609 609
 				return $object_id;
610
-			}elseif( $export_from_site_a_to_b ){
610
+			}elseif ($export_from_site_a_to_b) {
611 611
 				//we couldn't find a mapping for this, and it's from a different site,
612 612
 				//so blank it out
613 613
 				return NULL;
614
-			}elseif( ! $export_from_site_a_to_b ) {
614
+			}elseif ( ! $export_from_site_a_to_b) {
615 615
 				//we coudln't find a mapping for this, but it's from thsi DB anyway
616 616
 				//so let's just leave it as-is
617 617
 				return $object_id;
@@ -626,36 +626,36 @@  discard block
 block discarded – undo
626 626
 	 * @param type $old_db_to_new_db_mapping
627 627
 	 * @return array updated $old_db_to_new_db_mapping
628 628
 	 */
629
-	protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) {
629
+	protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
630 630
 		//remove the primary key, if there is one (we don't want it for inserts OR updates)
631 631
 		//we'll put it back in if we need it
632
-		if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){
632
+		if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
633 633
 			$effective_id = $model_object_data[$model->primary_key_name()];
634 634
 			unset($model_object_data[$model->primary_key_name()]);
635
-		}else{
636
-			$effective_id = $model->get_index_primary_key_string( $model_object_data );
635
+		} else {
636
+			$effective_id = $model->get_index_primary_key_string($model_object_data);
637 637
 		}
638 638
 		//the model takes care of validating the CSV's input
639
-		try{
639
+		try {
640 640
 			$new_id = $model->insert($model_object_data);
641
-			if( $new_id ){
641
+			if ($new_id) {
642 642
 				$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id;
643 643
 				$this->_total_inserts++;
644
-				EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data)));
645
-			}else{
644
+				EE_Error::add_success(sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), $model->get_this_model_name(), $new_id, implode(",", $model_object_data)));
645
+			} else {
646 646
 				$this->_total_insert_errors++;
647 647
 				//put the ID used back in there for the error message
648
-				if($model->has_primary_key_field()){
648
+				if ($model->has_primary_key_field()) {
649 649
 					$model_object_data[$model->primary_key_name()] = $effective_id;
650 650
 				}
651
-				EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ );
651
+				EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__);
652 652
 			}
653
-		}catch(EE_Error $e){
653
+		} catch (EE_Error $e) {
654 654
 			$this->_total_insert_errors++;
655
-			if($model->has_primary_key_field()){
655
+			if ($model->has_primary_key_field()) {
656 656
 				$model_object_data[$model->primary_key_name()] = $effective_id;
657 657
 			}
658
-			EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()), __FILE__, __FUNCTION__, __LINE__ );
658
+			EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__);
659 659
 		}
660 660
 		return $old_db_to_new_db_mapping;
661 661
 	}
@@ -668,55 +668,55 @@  discard block
 block discarded – undo
668 668
 	 * @param array $old_db_to_new_db_mapping
669 669
 	 * @return array updated $old_db_to_new_db_mapping
670 670
 	 */
671
-	protected function _update_from_data_array( $id_in_csv,  $model_object_data, $model, $old_db_to_new_db_mapping ) {
672
-		try{
671
+	protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
672
+		try {
673 673
 			//let's keep two copies of the model object data:
674 674
 			//one for performing an update, one for everthing else
675 675
 			$model_object_data_for_update = $model_object_data;
676
-			if($model->has_primary_key_field()){
676
+			if ($model->has_primary_key_field()) {
677 677
 				$conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]);
678 678
 				//remove the primary key because we shouldn't use it for updating
679 679
 				unset($model_object_data_for_update[$model->primary_key_name()]);
680
-			}elseif($model->get_combined_primary_key_fields() > 1 ){
680
+			}elseif ($model->get_combined_primary_key_fields() > 1) {
681 681
 				$conditions = array();
682
-				foreach($model->get_combined_primary_key_fields() as $key_field){
682
+				foreach ($model->get_combined_primary_key_fields() as $key_field) {
683 683
 					$conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()];
684 684
 				}
685
-			}else{
686
-				$model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
685
+			} else {
686
+				$model->primary_key_name(); //this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
687 687
 			}
688 688
 
689
-			$success = $model->update($model_object_data_for_update,array($conditions));
690
-			if($success){
689
+			$success = $model->update($model_object_data_for_update, array($conditions));
690
+			if ($success) {
691 691
 				$this->_total_updates++;
692
-				EE_Error::add_success( sprintf(__("Successfully updated %s with csv data %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data_for_update)));
692
+				EE_Error::add_success(sprintf(__("Successfully updated %s with csv data %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data_for_update)));
693 693
 				//we should still record the mapping even though it was an update
694 694
 				//because if we were going to insert somethign but it was going to conflict
695 695
 				//we would have last-minute decided to update. So we'd like to know what we updated
696 696
 				//and so we record what record ended up being updated using the mapping
697
-				if( $model->has_primary_key_field() ){
698
-					$new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
699
-				}else{
697
+				if ($model->has_primary_key_field()) {
698
+					$new_key_for_mapping = $model_object_data[$model->primary_key_name()];
699
+				} else {
700 700
 					//no primary key just a combined key
701
-					$new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data );
701
+					$new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
702 702
 				}
703
-				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
704
-			}else{
703
+				$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping;
704
+			} else {
705 705
 				$matched_items = $model->get_all(array($conditions));
706
-				if( ! $matched_items){
706
+				if ( ! $matched_items) {
707 707
 					//no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
708 708
 					$this->_total_update_errors++;
709
-					EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ );
710
-				}else{
709
+					EE_Error::add_error(sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data), http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__);
710
+				} else {
711 711
 					$this->_total_updates++;
712
-					EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data)));
712
+					EE_Error::add_success(sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data)));
713 713
 				}
714 714
 			}
715
-		}catch(EE_Error $e){
715
+		} catch (EE_Error $e) {
716 716
 			$this->_total_update_errors++;
717
-			$basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage());
718
-			$debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
719
-			EE_Error::add_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ );
717
+			$basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage());
718
+			$debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString();
719
+			EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
720 720
 		}
721 721
 		return $old_db_to_new_db_mapping;
722 722
 	}
@@ -725,28 +725,28 @@  discard block
 block discarded – undo
725 725
 	 * Gets the number of inserts performed since importer was instantiated or reset
726 726
 	 * @return int
727 727
 	 */
728
-	public function get_total_inserts(){
728
+	public function get_total_inserts() {
729 729
 		return $this->_total_inserts;
730 730
 	}
731 731
 	/**
732 732
 	 *  Gets the number of insert errors since importer was instantiated or reset
733 733
 	 * @return int
734 734
 	 */
735
-	public function get_total_insert_errors(){
735
+	public function get_total_insert_errors() {
736 736
 		return $this->_total_insert_errors;
737 737
 	}
738 738
 	/**
739 739
 	 *  Gets the number of updates performed since importer was instantiated or reset
740 740
 	 * @return int
741 741
 	 */
742
-	public function get_total_updates(){
742
+	public function get_total_updates() {
743 743
 		return $this->_total_updates;
744 744
 	}
745 745
 	/**
746 746
 	 *  Gets the number of update errors since importer was instantiated or reset
747 747
 	 * @return int
748 748
 	 */
749
-	public function get_total_update_errors(){
749
+	public function get_total_update_errors() {
750 750
 		return $this->_total_update_errors;
751 751
 	}
752 752
 
Please login to merge, or discard this patch.
modules/ticket_sales_monitor/EED_Ticket_Sales_Monitor.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      * @access    protected
249 249
      * @param    \EE_Ticket $ticket
250 250
      * @param int           $quantity
251
-     * @return bool
251
+     * @return integer
252 252
      * @throws EE_Error
253 253
      */
254 254
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @access protected
269 269
      * @param  EE_Ticket $ticket
270 270
      * @param  int       $quantity
271
-     * @return bool
271
+     * @return integer
272 272
      * @throws EE_Error
273 273
      */
274 274
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 class EED_Ticket_Sales_Monitor extends EED_Module
22 22
 {
23 23
 
24
-    const debug = false;    //	true false
24
+    const debug = false; //	true false
25 25
 
26 26
     /**
27 27
      * an array of raw ticket data from EED_Ticket_Selector
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
             $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
181 181
         }
182 182
         if (self::debug) {
183
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
184
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
183
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()';
184
+            echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>';
185 185
         }
186 186
         return $qty;
187 187
     }
@@ -202,36 +202,36 @@  discard block
 block discarded – undo
202 202
     protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
203 203
     {
204 204
         if (self::debug) {
205
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
205
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
206 206
         }
207 207
         if ( ! $ticket instanceof EE_Ticket) {
208 208
             return 0;
209 209
         }
210 210
         if (self::debug) {
211
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
212
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
211
+            echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>';
212
+            echo '<br /> . original ticket->reserved: '.$ticket->reserved();
213 213
         }
214 214
         $ticket->refresh_from_db();
215 215
         // first let's determine the ticket availability based on sales
216 216
         $available = $ticket->qty('saleable');
217 217
         if (self::debug) {
218
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
219
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
220
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
221
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
222
-            echo '<br /> . . . available: ' . $available;
218
+            echo '<br /> . . . ticket->qty: '.$ticket->qty();
219
+            echo '<br /> . . . ticket->sold: '.$ticket->sold();
220
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
221
+            echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable');
222
+            echo '<br /> . . . available: '.$available;
223 223
         }
224 224
         if ($available < 1) {
225 225
             $this->_ticket_sold_out($ticket);
226 226
             return 0;
227 227
         }
228 228
         if (self::debug) {
229
-            echo '<br /> . . . qty: ' . $qty;
229
+            echo '<br /> . . . qty: '.$qty;
230 230
         }
231 231
         if ($available < $qty) {
232 232
             $qty = $available;
233 233
             if (self::debug) {
234
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
234
+                echo '<br /> . . . QTY ADJUSTED: '.$qty;
235 235
             }
236 236
             $this->_ticket_quantity_decremented($ticket);
237 237
         }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
255 255
     {
256 256
         if (self::debug) {
257
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
257
+            echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity;
258 258
         }
259 259
         $ticket->increase_reserved($quantity);
260 260
         return $ticket->save();
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
275 275
     {
276 276
         if (self::debug) {
277
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
278
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
277
+            echo '<br /> . . . ticket->ID: '.$ticket->ID();
278
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
279 279
         }
280 280
         $ticket->decrease_reserved($quantity);
281 281
         if (self::debug) {
282
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
282
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
283 283
         }
284 284
         return $ticket->save() ? 1 : 0;
285 285
     }
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
     protected function _ticket_sold_out(EE_Ticket $ticket)
300 300
     {
301 301
         if (self::debug) {
302
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
303
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
302
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
303
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
304 304
         }
305 305
         $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
306 306
     }
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
     protected function _ticket_quantity_decremented(EE_Ticket $ticket)
321 321
     {
322 322
         if (self::debug) {
323
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
324
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
323
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
324
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
325 325
         }
326 326
         $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
327 327
     }
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
     protected function _post_notices()
429 429
     {
430 430
         if (self::debug) {
431
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
431
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
432 432
         }
433 433
         $refresh_msg = '';
434 434
         $none_added_msg = '';
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
     protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
496 496
     {
497 497
         if (self::debug) {
498
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
499
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
498
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
499
+            echo '<br /> . transaction->ID: '.$transaction->ID();
500 500
         }
501 501
         // check if 'finalize_registration' step has been completed...
502 502
         $finalized = $transaction->reg_step_completed('finalize_registration');
@@ -505,13 +505,13 @@  discard block
 block discarded – undo
505 505
             EEH_Debug_Tools::log(
506 506
                 __CLASS__, __FUNCTION__, __LINE__,
507 507
                 array('finalized' => $finalized),
508
-                false, 'EE_Transaction: ' . $transaction->ID()
508
+                false, 'EE_Transaction: '.$transaction->ID()
509 509
             );
510 510
         }
511 511
         // how many tickets were released
512 512
         $count = 0;
513 513
         if (self::debug) {
514
-            echo '<br /> . . . finalized: ' . $finalized;
514
+            echo '<br /> . . . finalized: '.$finalized;
515 515
         }
516 516
         $release_tickets_with_TXN_status = array(
517 517
             EEM_Transaction::failed_status_code,
@@ -552,10 +552,10 @@  discard block
 block discarded – undo
552 552
     ) {
553 553
         $STS_ID = $transaction->status_ID();
554 554
         if (self::debug) {
555
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
556
-            echo '<br /> . . registration->ID: ' . $registration->ID();
557
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
558
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
555
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
556
+            echo '<br /> . . registration->ID: '.$registration->ID();
557
+            echo '<br /> . . registration->status_ID: '.$registration->status_ID();
558
+            echo '<br /> . . transaction->status_ID(): '.$STS_ID;
559 559
         }
560 560
         if (
561 561
             // release Tickets for Failed Transactions and Abandoned Transactions
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
     public static function session_cart_reset(EE_Session $session)
594 594
     {
595 595
         if (self::debug) {
596
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
596
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
597 597
         }
598 598
         $cart = $session->cart();
599 599
         if ($cart instanceof EE_Cart) {
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
     protected function _session_cart_reset(EE_Cart $cart)
624 624
     {
625 625
         if (self::debug) {
626
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
626
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
627 627
         }
628 628
         EE_Registry::instance()->load_helper('Line_Item');
629 629
         $ticket_line_items = $cart->get_tickets();
@@ -632,17 +632,17 @@  discard block
 block discarded – undo
632 632
         }
633 633
         foreach ($ticket_line_items as $ticket_line_item) {
634 634
             if (self::debug) {
635
-                echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
635
+                echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID();
636 636
             }
637 637
             if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
638 638
                 if (self::debug) {
639
-                    echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
639
+                    echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID();
640 640
                 }
641 641
                 $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
642 642
                 if ($ticket instanceof EE_Ticket) {
643 643
                     if (self::debug) {
644
-                        echo '<br /> . . ticket->ID(): ' . $ticket->ID();
645
-                        echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
644
+                        echo '<br /> . . ticket->ID(): '.$ticket->ID();
645
+                        echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity();
646 646
                     }
647 647
                     $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
648 648
                 }
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     protected function _session_checkout_reset(EE_Checkout $checkout)
691 691
     {
692 692
         if (self::debug) {
693
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
693
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
694 694
         }
695 695
         // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
696 696
         if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
                 EEH_Debug_Tools::log(
742 742
                     __CLASS__, __FUNCTION__, __LINE__,
743 743
                     array($transaction),
744
-                    false, 'EE_Transaction: ' . $transaction->ID()
744
+                    false, 'EE_Transaction: '.$transaction->ID()
745 745
                 );
746 746
             }
747 747
             return;
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
                     EEH_Debug_Tools::log(
756 756
                         __CLASS__, __FUNCTION__, __LINE__,
757 757
                         array($payment),
758
-                        false, 'EE_Transaction: ' . $transaction->ID()
758
+                        false, 'EE_Transaction: '.$transaction->ID()
759 759
                     );
760 760
                 }
761 761
                 return;
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
             /** @var EE_Transaction $transaction_in_progress */
814 814
             $total_line_item = $transaction_in_progress->total_line_item();
815 815
             // $transaction_in_progress->line
816
-            if (! $total_line_item instanceof EE_Line_Item) {
816
+            if ( ! $total_line_item instanceof EE_Line_Item) {
817 817
                 throw new DomainException(
818 818
                     esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso')
819 819
                 );
@@ -827,12 +827,12 @@  discard block
 block discarded – undo
827 827
         }
828 828
         $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
829 829
         foreach ($tickets_with_reservations as $ticket_with_reservations) {
830
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
830
+            if ( ! $ticket_with_reservations instanceof EE_Ticket) {
831 831
                 continue;
832 832
             }
833 833
             $reserved_qty = $ticket_with_reservations->reserved();
834 834
             foreach ($valid_reserved_tickets as $valid_reserved_ticket) {
835
-                if(
835
+                if (
836 836
                     $valid_reserved_ticket instanceof EE_Line_Item
837 837
                     && $valid_reserved_ticket->OBJ_ID() === $ticket_with_reservations->ID()
838 838
                 ) {
Please login to merge, or discard this patch.
Indentation   +841 added lines, -841 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\UnexpectedEntityException;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -21,846 +21,846 @@  discard block
 block discarded – undo
21 21
 class EED_Ticket_Sales_Monitor extends EED_Module
22 22
 {
23 23
 
24
-    const debug = false;    //	true false
25
-
26
-    /**
27
-     * an array of raw ticket data from EED_Ticket_Selector
28
-     *
29
-     * @var array $ticket_selections
30
-     */
31
-    protected $ticket_selections = array();
32
-
33
-    /**
34
-     * the raw ticket data from EED_Ticket_Selector is organized in rows
35
-     * according to how they are displayed in the actual Ticket_Selector
36
-     * this tracks the current row being processed
37
-     *
38
-     * @var int $current_row
39
-     */
40
-    protected $current_row = 0;
41
-
42
-    /**
43
-     * an array for tracking names of tickets that have sold out
44
-     *
45
-     * @var array $sold_out_tickets
46
-     */
47
-    protected $sold_out_tickets = array();
48
-
49
-    /**
50
-     * an array for tracking names of tickets that have had their quantities reduced
51
-     *
52
-     * @var array $decremented_tickets
53
-     */
54
-    protected $decremented_tickets = array();
55
-
56
-
57
-
58
-    /**
59
-     *    set_hooks - for hooking into EE Core, other modules, etc
60
-     *
61
-     * @access    public
62
-     * @return    void
63
-     */
64
-    public static function set_hooks()
65
-    {
66
-        // check ticket reserves AFTER MER does it's check (hence priority 20)
67
-        add_filter('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
68
-            array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
69
-            20, 3
70
-        );
71
-        // add notices for sold out tickets
72
-        add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
73
-            array('EED_Ticket_Sales_Monitor', 'post_notices'),
74
-            10
75
-        );
76
-        // handle ticket quantities adjusted in cart
77
-        //add_action(
78
-        //	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
79
-        //	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
80
-        //	10, 2
81
-        //);
82
-        // handle tickets deleted from cart
83
-        add_action(
84
-            'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
85
-            array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
86
-            10, 2
87
-        );
88
-        // handle emptied carts
89
-        add_action(
90
-            'AHEE__EE_Session__reset_cart__before_reset',
91
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
92
-            10, 1
93
-        );
94
-        add_action(
95
-            'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
96
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
97
-            10, 1
98
-        );
99
-        // handle cancelled registrations
100
-        add_action(
101
-            'AHEE__EE_Session__reset_checkout__before_reset',
102
-            array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
103
-            10, 1
104
-        );
105
-        // cron tasks
106
-        add_action(
107
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction',
108
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
109
-            10, 1
110
-        );
111
-        add_action(
112
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
113
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
114
-            10, 1
115
-        );
116
-        add_action(
117
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
118
-            array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
119
-            10, 1
120
-        );
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
127
-     *
128
-     * @access    public
129
-     * @return    void
130
-     */
131
-    public static function set_hooks_admin()
132
-    {
133
-        EED_Ticket_Sales_Monitor::set_hooks();
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * @return EED_Ticket_Sales_Monitor|EED_Module
140
-     */
141
-    public static function instance()
142
-    {
143
-        return parent::get_instance(__CLASS__);
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     *    run
150
-     *
151
-     * @access    public
152
-     * @param WP_Query $WP_Query
153
-     * @return    void
154
-     */
155
-    public function run($WP_Query)
156
-    {
157
-    }
158
-
159
-
160
-
161
-    /********************************** VALIDATE_TICKET_SALE  **********************************/
162
-
163
-
164
-
165
-    /**
166
-     *    validate_ticket_sales
167
-     *    callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
168
-     *
169
-     * @access    public
170
-     * @param int $qty
171
-     * @param \EE_Ticket $ticket
172
-     * @return bool
173
-     * @throws UnexpectedEntityException
174
-     * @throws EE_Error
175
-     */
176
-    public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
177
-    {
178
-        $qty = absint($qty);
179
-        if ($qty > 0) {
180
-            $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
181
-        }
182
-        if (self::debug) {
183
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
184
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
185
-        }
186
-        return $qty;
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     *    _validate_ticket_sale
193
-     * checks whether an individual ticket is available for purchase based on datetime, and ticket details
194
-     *
195
-     * @access    protected
196
-     * @param   \EE_Ticket $ticket
197
-     * @param int          $qty
198
-     * @return int
199
-     * @throws UnexpectedEntityException
200
-     * @throws EE_Error
201
-     */
202
-    protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
203
-    {
204
-        if (self::debug) {
205
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
206
-        }
207
-        if ( ! $ticket instanceof EE_Ticket) {
208
-            return 0;
209
-        }
210
-        if (self::debug) {
211
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
212
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
213
-        }
214
-        $ticket->refresh_from_db();
215
-        // first let's determine the ticket availability based on sales
216
-        $available = $ticket->qty('saleable');
217
-        if (self::debug) {
218
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
219
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
220
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
221
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
222
-            echo '<br /> . . . available: ' . $available;
223
-        }
224
-        if ($available < 1) {
225
-            $this->_ticket_sold_out($ticket);
226
-            return 0;
227
-        }
228
-        if (self::debug) {
229
-            echo '<br /> . . . qty: ' . $qty;
230
-        }
231
-        if ($available < $qty) {
232
-            $qty = $available;
233
-            if (self::debug) {
234
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
235
-            }
236
-            $this->_ticket_quantity_decremented($ticket);
237
-        }
238
-        $this->_reserve_ticket($ticket, $qty);
239
-        return $qty;
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     *  _reserve_ticket
246
-     *    increments ticket reserved based on quantity passed
247
-     *
248
-     * @access    protected
249
-     * @param    \EE_Ticket $ticket
250
-     * @param int           $quantity
251
-     * @return bool
252
-     * @throws EE_Error
253
-     */
254
-    protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
255
-    {
256
-        if (self::debug) {
257
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
258
-        }
259
-        $ticket->increase_reserved($quantity);
260
-        return $ticket->save();
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * _release_reserved_ticket
267
-     *
268
-     * @access protected
269
-     * @param  EE_Ticket $ticket
270
-     * @param  int       $quantity
271
-     * @return bool
272
-     * @throws EE_Error
273
-     */
274
-    protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
275
-    {
276
-        if (self::debug) {
277
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
278
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
279
-        }
280
-        $ticket->decrease_reserved($quantity);
281
-        if (self::debug) {
282
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
283
-        }
284
-        return $ticket->save() ? 1 : 0;
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     *    _ticket_sold_out
291
-     *    removes quantities within the ticket selector based on zero ticket availability
292
-     *
293
-     * @access    protected
294
-     * @param    \EE_Ticket $ticket
295
-     * @return    void
296
-     * @throws UnexpectedEntityException
297
-     * @throws EE_Error
298
-     */
299
-    protected function _ticket_sold_out(EE_Ticket $ticket)
300
-    {
301
-        if (self::debug) {
302
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
303
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
304
-        }
305
-        $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     *    _ticket_quantity_decremented
312
-     *    adjusts quantities within the ticket selector based on decreased ticket availability
313
-     *
314
-     * @access    protected
315
-     * @param    \EE_Ticket $ticket
316
-     * @return void
317
-     * @throws UnexpectedEntityException
318
-     * @throws EE_Error
319
-     */
320
-    protected function _ticket_quantity_decremented(EE_Ticket $ticket)
321
-    {
322
-        if (self::debug) {
323
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
324
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
325
-        }
326
-        $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     *    _get_ticket_and_event_name
333
-     *    builds string out of ticket and event name
334
-     *
335
-     * @access    protected
336
-     * @param    \EE_Ticket $ticket
337
-     * @return string
338
-     * @throws UnexpectedEntityException
339
-     * @throws EE_Error
340
-     */
341
-    protected function _get_ticket_and_event_name(EE_Ticket $ticket)
342
-    {
343
-        $event = $ticket->get_related_event();
344
-        if ($event instanceof EE_Event) {
345
-            $ticket_name = sprintf(
346
-                _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
347
-                $ticket->name(),
348
-                $event->name()
349
-            );
350
-        } else {
351
-            $ticket_name = $ticket->name();
352
-        }
353
-        return $ticket_name;
354
-    }
355
-
356
-
357
-
358
-    /********************************** EVENT CART  **********************************/
359
-
360
-
361
-
362
-    /**
363
-     * ticket_quantity_updated
364
-     * releases or reserves ticket(s) based on quantity passed
365
-     *
366
-     * @access public
367
-     * @param  EE_Line_Item $line_item
368
-     * @param  int          $quantity
369
-     * @return void
370
-     * @throws EE_Error
371
-     */
372
-    public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
373
-    {
374
-        $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
375
-        if ($ticket instanceof EE_Ticket) {
376
-            if ($quantity > 0) {
377
-                EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
378
-            } else {
379
-                EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
380
-            }
381
-        }
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     * ticket_removed_from_cart
388
-     * releases reserved ticket(s) based on quantity passed
389
-     *
390
-     * @access public
391
-     * @param  EE_Ticket $ticket
392
-     * @param  int       $quantity
393
-     * @return void
394
-     * @throws EE_Error
395
-     */
396
-    public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
397
-    {
398
-        EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
399
-    }
400
-
401
-
402
-
403
-    /********************************** POST_NOTICES  **********************************/
404
-
405
-
406
-
407
-    /**
408
-     *    post_notices
409
-     *
410
-     * @access    public
411
-     * @return    void
412
-     * @throws EE_Error
413
-     */
414
-    public static function post_notices()
415
-    {
416
-        EED_Ticket_Sales_Monitor::instance()->_post_notices();
417
-    }
418
-
419
-
420
-
421
-    /**
422
-     *    _post_notices
423
-     *
424
-     * @access    protected
425
-     * @return    void
426
-     * @throws EE_Error
427
-     */
428
-    protected function _post_notices()
429
-    {
430
-        if (self::debug) {
431
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
432
-        }
433
-        $refresh_msg = '';
434
-        $none_added_msg = '';
435
-        if (defined('DOING_AJAX') && DOING_AJAX) {
436
-            $refresh_msg = __('Please refresh the page to view updated ticket quantities.',
437
-                'event_espresso');
438
-            $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
439
-        }
440
-        if ( ! empty($this->sold_out_tickets)) {
441
-            EE_Error::add_attention(
442
-                sprintf(
443
-                    apply_filters(
444
-                        'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
445
-                        __('We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
446
-                            'event_espresso')
447
-                    ),
448
-                    '<br />',
449
-                    implode('<br />', $this->sold_out_tickets),
450
-                    $none_added_msg,
451
-                    $refresh_msg
452
-                )
453
-            );
454
-            // alter code flow in the Ticket Selector for better UX
455
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
456
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
457
-            $this->sold_out_tickets = array();
458
-            // and reset the cart
459
-            EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
460
-        }
461
-        if ( ! empty($this->decremented_tickets)) {
462
-            EE_Error::add_attention(
463
-                sprintf(
464
-                    apply_filters(
465
-                        'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
466
-                        __('We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
467
-                            'event_espresso')
468
-                    ),
469
-                    '<br />',
470
-                    implode('<br />', $this->decremented_tickets),
471
-                    $none_added_msg,
472
-                    $refresh_msg
473
-                )
474
-            );
475
-            $this->decremented_tickets = array();
476
-        }
477
-    }
478
-
479
-
480
-
481
-    /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
482
-
483
-
484
-
485
-    /**
486
-     *    _release_all_reserved_tickets_for_transaction
487
-     *    releases reserved tickets for all registrations of an EE_Transaction
488
-     *    by default, will NOT release tickets for finalized transactions
489
-     *
490
-     * @access    protected
491
-     * @param    EE_Transaction $transaction
492
-     * @return int
493
-     * @throws EE_Error
494
-     */
495
-    protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
496
-    {
497
-        if (self::debug) {
498
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
499
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
500
-        }
501
-        // check if 'finalize_registration' step has been completed...
502
-        $finalized = $transaction->reg_step_completed('finalize_registration');
503
-        if (self::debug) {
504
-            // DEBUG LOG
505
-            EEH_Debug_Tools::log(
506
-                __CLASS__, __FUNCTION__, __LINE__,
507
-                array('finalized' => $finalized),
508
-                false, 'EE_Transaction: ' . $transaction->ID()
509
-            );
510
-        }
511
-        // how many tickets were released
512
-        $count = 0;
513
-        if (self::debug) {
514
-            echo '<br /> . . . finalized: ' . $finalized;
515
-        }
516
-        $release_tickets_with_TXN_status = array(
517
-            EEM_Transaction::failed_status_code,
518
-            EEM_Transaction::abandoned_status_code,
519
-            EEM_Transaction::incomplete_status_code,
520
-        );
521
-        // if the session is getting cleared BEFORE the TXN has been finalized
522
-        if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
523
-            // let's cancel any reserved tickets
524
-            $registrations = $transaction->registrations();
525
-            if ( ! empty($registrations)) {
526
-                foreach ($registrations as $registration) {
527
-                    if ($registration instanceof EE_Registration) {
528
-                        $count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
529
-                    }
530
-                }
531
-            }
532
-        }
533
-        return $count;
534
-    }
535
-
536
-
537
-
538
-    /**
539
-     *    _release_reserved_ticket_for_registration
540
-     *    releases reserved tickets for an EE_Registration
541
-     *    by default, will NOT release tickets for APPROVED registrations
542
-     *
543
-     * @access    protected
544
-     * @param    EE_Registration $registration
545
-     * @param    EE_Transaction  $transaction
546
-     * @return    int
547
-     * @throws    EE_Error
548
-     */
549
-    protected function _release_reserved_ticket_for_registration(
550
-        EE_Registration $registration,
551
-        EE_Transaction $transaction
552
-    ) {
553
-        $STS_ID = $transaction->status_ID();
554
-        if (self::debug) {
555
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
556
-            echo '<br /> . . registration->ID: ' . $registration->ID();
557
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
558
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
559
-        }
560
-        if (
561
-            // release Tickets for Failed Transactions and Abandoned Transactions
562
-            $STS_ID === EEM_Transaction::failed_status_code
563
-            || $STS_ID === EEM_Transaction::abandoned_status_code
564
-            || (
565
-                // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
566
-                $STS_ID === EEM_Transaction::incomplete_status_code
567
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
568
-            )
569
-        ) {
570
-            $ticket = $registration->ticket();
571
-            if ($ticket instanceof EE_Ticket) {
572
-                return $this->_release_reserved_ticket($ticket);
573
-            }
574
-        }
575
-        return 0;
576
-    }
577
-
578
-
579
-
580
-    /********************************** SESSION_CART_RESET  **********************************/
581
-
582
-
583
-
584
-    /**
585
-     *    session_cart_reset
586
-     * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
587
-     *
588
-     * @access    public
589
-     * @param    EE_Session $session
590
-     * @return    void
591
-     * @throws EE_Error
592
-     */
593
-    public static function session_cart_reset(EE_Session $session)
594
-    {
595
-        if (self::debug) {
596
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
597
-        }
598
-        $cart = $session->cart();
599
-        if ($cart instanceof EE_Cart) {
600
-            if (self::debug) {
601
-                echo '<br /><br /> cart instance of EE_Cart: ';
602
-            }
603
-            EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart);
604
-        } else {
605
-            if (self::debug) {
606
-                echo '<br /><br /> invalid EE_Cart: ';
607
-                var_dump($cart);
608
-            }
609
-        }
610
-    }
611
-
612
-
613
-
614
-    /**
615
-     *    _session_cart_reset
616
-     * releases reserved tickets in the EE_Cart
617
-     *
618
-     * @access    protected
619
-     * @param    EE_Cart $cart
620
-     * @return    void
621
-     * @throws EE_Error
622
-     */
623
-    protected function _session_cart_reset(EE_Cart $cart)
624
-    {
625
-        if (self::debug) {
626
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
627
-        }
628
-        EE_Registry::instance()->load_helper('Line_Item');
629
-        $ticket_line_items = $cart->get_tickets();
630
-        if (empty($ticket_line_items)) {
631
-            return;
632
-        }
633
-        foreach ($ticket_line_items as $ticket_line_item) {
634
-            if (self::debug) {
635
-                echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
636
-            }
637
-            if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
638
-                if (self::debug) {
639
-                    echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
640
-                }
641
-                $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
642
-                if ($ticket instanceof EE_Ticket) {
643
-                    if (self::debug) {
644
-                        echo '<br /> . . ticket->ID(): ' . $ticket->ID();
645
-                        echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
646
-                    }
647
-                    $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
648
-                }
649
-            }
650
-        }
651
-        if (self::debug) {
652
-            echo '<br /><br /> RESET COMPLETED ';
653
-        }
654
-    }
655
-
656
-
657
-
658
-    /********************************** SESSION_CHECKOUT_RESET  **********************************/
659
-
660
-
661
-
662
-    /**
663
-     *    session_checkout_reset
664
-     * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
665
-     *
666
-     * @access    public
667
-     * @param    EE_Session $session
668
-     * @return    void
669
-     * @throws EE_Error
670
-     */
671
-    public static function session_checkout_reset(EE_Session $session)
672
-    {
673
-        $checkout = $session->checkout();
674
-        if ($checkout instanceof EE_Checkout) {
675
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
676
-        }
677
-    }
678
-
679
-
680
-
681
-    /**
682
-     *    _session_checkout_reset
683
-     * releases reserved tickets for the EE_Checkout->transaction
684
-     *
685
-     * @access    protected
686
-     * @param    EE_Checkout $checkout
687
-     * @return    void
688
-     * @throws EE_Error
689
-     */
690
-    protected function _session_checkout_reset(EE_Checkout $checkout)
691
-    {
692
-        if (self::debug) {
693
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
694
-        }
695
-        // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
696
-        if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
697
-            return;
698
-        }
699
-        $this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
700
-    }
701
-
702
-
703
-
704
-    /********************************** SESSION_EXPIRED_RESET  **********************************/
705
-
706
-
707
-
708
-    /**
709
-     *    session_expired_reset
710
-     *
711
-     * @access    public
712
-     * @param    EE_Session $session
713
-     * @return    void
714
-     */
715
-    public static function session_expired_reset(EE_Session $session)
716
-    {
717
-    }
718
-
719
-
720
-
721
-    /********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
722
-
723
-
724
-
725
-    /**
726
-     *    process_abandoned_transactions
727
-     *    releases reserved tickets for all registrations of an ABANDONED EE_Transaction
728
-     *    by default, will NOT release tickets for free transactions, or any that have received a payment
729
-     *
730
-     * @access    public
731
-     * @param    EE_Transaction $transaction
732
-     * @return    void
733
-     * @throws EE_Error
734
-     */
735
-    public static function process_abandoned_transactions(EE_Transaction $transaction)
736
-    {
737
-        // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
738
-        if ($transaction->is_free() || $transaction->paid() > 0) {
739
-            if (self::debug) {
740
-                // DEBUG LOG
741
-                EEH_Debug_Tools::log(
742
-                    __CLASS__, __FUNCTION__, __LINE__,
743
-                    array($transaction),
744
-                    false, 'EE_Transaction: ' . $transaction->ID()
745
-                );
746
-            }
747
-            return;
748
-        }
749
-        // have their been any successful payments made ?
750
-        $payments = $transaction->payments();
751
-        foreach ($payments as $payment) {
752
-            if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
753
-                if (self::debug) {
754
-                    // DEBUG LOG
755
-                    EEH_Debug_Tools::log(
756
-                        __CLASS__, __FUNCTION__, __LINE__,
757
-                        array($payment),
758
-                        false, 'EE_Transaction: ' . $transaction->ID()
759
-                    );
760
-                }
761
-                return;
762
-            }
763
-        }
764
-        // since you haven't even attempted to pay for your ticket...
765
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
766
-    }
767
-
768
-
769
-
770
-    /********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
771
-
772
-
773
-
774
-    /**
775
-     *    process_abandoned_transactions
776
-     *    releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
777
-     *
778
-     * @access    public
779
-     * @param    EE_Transaction $transaction
780
-     * @return    void
781
-     * @throws EE_Error
782
-     */
783
-    public static function process_failed_transactions(EE_Transaction $transaction)
784
-    {
785
-        // since you haven't even attempted to pay for your ticket...
786
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
787
-    }
788
-
789
-
790
-
791
-    /********************************** RESET RESERVATION COUNTS  *********************************/
792
-
793
-
794
-
795
-    /**
796
-     * Resets all ticket and datetime reserved counts to zero
797
-     * Tickets that are currently associated with a Transaction that is in progress
798
-     *
799
-     * @throws \EE_Error
800
-     * @throws \DomainException
801
-     */
802
-    public static function reset_reservation_counts()
803
-    {
804
-        $total_tickets_released = 0;
805
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
806
-        $valid_reserved_tickets = array();
807
-        $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress();
808
-        foreach ($transactions_in_progress as $transaction_in_progress) {
809
-            // if this TXN has been fully completed, then skip it
810
-            if ($transaction_in_progress->reg_step_completed('finalize_registration')) {
811
-                continue;
812
-            }
813
-            /** @var EE_Transaction $transaction_in_progress */
814
-            $total_line_item = $transaction_in_progress->total_line_item();
815
-            // $transaction_in_progress->line
816
-            if (! $total_line_item instanceof EE_Line_Item) {
817
-                throw new DomainException(
818
-                    esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso')
819
-                );
820
-            }
821
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item);
822
-        }
823
-        $total_line_items = EEM_Line_Item::instance()->get_total_line_items_just_added_to_cart();
824
-        foreach ($total_line_items as $total_line_item) {
825
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item);
826
-        }
827
-        $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
828
-        foreach ($tickets_with_reservations as $ticket_with_reservations) {
829
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
830
-                continue;
831
-            }
832
-            $reserved_qty = $ticket_with_reservations->reserved();
833
-            foreach ($valid_reserved_tickets as $valid_reserved_ticket) {
834
-                if(
835
-                    $valid_reserved_ticket instanceof EE_Line_Item
836
-                    && $valid_reserved_ticket->OBJ_ID() === $ticket_with_reservations->ID()
837
-                ) {
838
-                    $reserved_qty -= $valid_reserved_ticket->quantity();
839
-                }
840
-            }
841
-            if ($reserved_qty > 0) {
842
-                $ticket_with_reservations->decrease_reserved($reserved_qty);
843
-                $ticket_with_reservations->save();
844
-                $total_tickets_released += $reserved_qty;
845
-            }
846
-        }
847
-        return $total_tickets_released;
848
-    }
849
-
850
-
851
-
852
-    private static function get_reserved_tickets_for_line_item(EE_Line_Item $total_line_item)
853
-    {
854
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
855
-        $valid_reserved_tickets = array();
856
-        $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
857
-        foreach ($ticket_line_items as $ticket_line_item) {
858
-            if ($ticket_line_item instanceof EE_Line_Item) {
859
-                $valid_reserved_tickets[] = $ticket_line_item;
860
-            }
861
-        }
862
-        return $valid_reserved_tickets;
863
-    }
24
+	const debug = false;    //	true false
25
+
26
+	/**
27
+	 * an array of raw ticket data from EED_Ticket_Selector
28
+	 *
29
+	 * @var array $ticket_selections
30
+	 */
31
+	protected $ticket_selections = array();
32
+
33
+	/**
34
+	 * the raw ticket data from EED_Ticket_Selector is organized in rows
35
+	 * according to how they are displayed in the actual Ticket_Selector
36
+	 * this tracks the current row being processed
37
+	 *
38
+	 * @var int $current_row
39
+	 */
40
+	protected $current_row = 0;
41
+
42
+	/**
43
+	 * an array for tracking names of tickets that have sold out
44
+	 *
45
+	 * @var array $sold_out_tickets
46
+	 */
47
+	protected $sold_out_tickets = array();
48
+
49
+	/**
50
+	 * an array for tracking names of tickets that have had their quantities reduced
51
+	 *
52
+	 * @var array $decremented_tickets
53
+	 */
54
+	protected $decremented_tickets = array();
55
+
56
+
57
+
58
+	/**
59
+	 *    set_hooks - for hooking into EE Core, other modules, etc
60
+	 *
61
+	 * @access    public
62
+	 * @return    void
63
+	 */
64
+	public static function set_hooks()
65
+	{
66
+		// check ticket reserves AFTER MER does it's check (hence priority 20)
67
+		add_filter('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
68
+			array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
69
+			20, 3
70
+		);
71
+		// add notices for sold out tickets
72
+		add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
73
+			array('EED_Ticket_Sales_Monitor', 'post_notices'),
74
+			10
75
+		);
76
+		// handle ticket quantities adjusted in cart
77
+		//add_action(
78
+		//	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
79
+		//	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
80
+		//	10, 2
81
+		//);
82
+		// handle tickets deleted from cart
83
+		add_action(
84
+			'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
85
+			array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
86
+			10, 2
87
+		);
88
+		// handle emptied carts
89
+		add_action(
90
+			'AHEE__EE_Session__reset_cart__before_reset',
91
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
92
+			10, 1
93
+		);
94
+		add_action(
95
+			'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
96
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
97
+			10, 1
98
+		);
99
+		// handle cancelled registrations
100
+		add_action(
101
+			'AHEE__EE_Session__reset_checkout__before_reset',
102
+			array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
103
+			10, 1
104
+		);
105
+		// cron tasks
106
+		add_action(
107
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction',
108
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
109
+			10, 1
110
+		);
111
+		add_action(
112
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
113
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
114
+			10, 1
115
+		);
116
+		add_action(
117
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
118
+			array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
119
+			10, 1
120
+		);
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
127
+	 *
128
+	 * @access    public
129
+	 * @return    void
130
+	 */
131
+	public static function set_hooks_admin()
132
+	{
133
+		EED_Ticket_Sales_Monitor::set_hooks();
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * @return EED_Ticket_Sales_Monitor|EED_Module
140
+	 */
141
+	public static function instance()
142
+	{
143
+		return parent::get_instance(__CLASS__);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 *    run
150
+	 *
151
+	 * @access    public
152
+	 * @param WP_Query $WP_Query
153
+	 * @return    void
154
+	 */
155
+	public function run($WP_Query)
156
+	{
157
+	}
158
+
159
+
160
+
161
+	/********************************** VALIDATE_TICKET_SALE  **********************************/
162
+
163
+
164
+
165
+	/**
166
+	 *    validate_ticket_sales
167
+	 *    callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
168
+	 *
169
+	 * @access    public
170
+	 * @param int $qty
171
+	 * @param \EE_Ticket $ticket
172
+	 * @return bool
173
+	 * @throws UnexpectedEntityException
174
+	 * @throws EE_Error
175
+	 */
176
+	public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
177
+	{
178
+		$qty = absint($qty);
179
+		if ($qty > 0) {
180
+			$qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
181
+		}
182
+		if (self::debug) {
183
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
184
+			echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
185
+		}
186
+		return $qty;
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 *    _validate_ticket_sale
193
+	 * checks whether an individual ticket is available for purchase based on datetime, and ticket details
194
+	 *
195
+	 * @access    protected
196
+	 * @param   \EE_Ticket $ticket
197
+	 * @param int          $qty
198
+	 * @return int
199
+	 * @throws UnexpectedEntityException
200
+	 * @throws EE_Error
201
+	 */
202
+	protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
203
+	{
204
+		if (self::debug) {
205
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
206
+		}
207
+		if ( ! $ticket instanceof EE_Ticket) {
208
+			return 0;
209
+		}
210
+		if (self::debug) {
211
+			echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
212
+			echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
213
+		}
214
+		$ticket->refresh_from_db();
215
+		// first let's determine the ticket availability based on sales
216
+		$available = $ticket->qty('saleable');
217
+		if (self::debug) {
218
+			echo '<br /> . . . ticket->qty: ' . $ticket->qty();
219
+			echo '<br /> . . . ticket->sold: ' . $ticket->sold();
220
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
221
+			echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
222
+			echo '<br /> . . . available: ' . $available;
223
+		}
224
+		if ($available < 1) {
225
+			$this->_ticket_sold_out($ticket);
226
+			return 0;
227
+		}
228
+		if (self::debug) {
229
+			echo '<br /> . . . qty: ' . $qty;
230
+		}
231
+		if ($available < $qty) {
232
+			$qty = $available;
233
+			if (self::debug) {
234
+				echo '<br /> . . . QTY ADJUSTED: ' . $qty;
235
+			}
236
+			$this->_ticket_quantity_decremented($ticket);
237
+		}
238
+		$this->_reserve_ticket($ticket, $qty);
239
+		return $qty;
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 *  _reserve_ticket
246
+	 *    increments ticket reserved based on quantity passed
247
+	 *
248
+	 * @access    protected
249
+	 * @param    \EE_Ticket $ticket
250
+	 * @param int           $quantity
251
+	 * @return bool
252
+	 * @throws EE_Error
253
+	 */
254
+	protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
255
+	{
256
+		if (self::debug) {
257
+			echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
258
+		}
259
+		$ticket->increase_reserved($quantity);
260
+		return $ticket->save();
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * _release_reserved_ticket
267
+	 *
268
+	 * @access protected
269
+	 * @param  EE_Ticket $ticket
270
+	 * @param  int       $quantity
271
+	 * @return bool
272
+	 * @throws EE_Error
273
+	 */
274
+	protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
275
+	{
276
+		if (self::debug) {
277
+			echo '<br /> . . . ticket->ID: ' . $ticket->ID();
278
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
279
+		}
280
+		$ticket->decrease_reserved($quantity);
281
+		if (self::debug) {
282
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
283
+		}
284
+		return $ticket->save() ? 1 : 0;
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 *    _ticket_sold_out
291
+	 *    removes quantities within the ticket selector based on zero ticket availability
292
+	 *
293
+	 * @access    protected
294
+	 * @param    \EE_Ticket $ticket
295
+	 * @return    void
296
+	 * @throws UnexpectedEntityException
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function _ticket_sold_out(EE_Ticket $ticket)
300
+	{
301
+		if (self::debug) {
302
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
303
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
304
+		}
305
+		$this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 *    _ticket_quantity_decremented
312
+	 *    adjusts quantities within the ticket selector based on decreased ticket availability
313
+	 *
314
+	 * @access    protected
315
+	 * @param    \EE_Ticket $ticket
316
+	 * @return void
317
+	 * @throws UnexpectedEntityException
318
+	 * @throws EE_Error
319
+	 */
320
+	protected function _ticket_quantity_decremented(EE_Ticket $ticket)
321
+	{
322
+		if (self::debug) {
323
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
324
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
325
+		}
326
+		$this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 *    _get_ticket_and_event_name
333
+	 *    builds string out of ticket and event name
334
+	 *
335
+	 * @access    protected
336
+	 * @param    \EE_Ticket $ticket
337
+	 * @return string
338
+	 * @throws UnexpectedEntityException
339
+	 * @throws EE_Error
340
+	 */
341
+	protected function _get_ticket_and_event_name(EE_Ticket $ticket)
342
+	{
343
+		$event = $ticket->get_related_event();
344
+		if ($event instanceof EE_Event) {
345
+			$ticket_name = sprintf(
346
+				_x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
347
+				$ticket->name(),
348
+				$event->name()
349
+			);
350
+		} else {
351
+			$ticket_name = $ticket->name();
352
+		}
353
+		return $ticket_name;
354
+	}
355
+
356
+
357
+
358
+	/********************************** EVENT CART  **********************************/
359
+
360
+
361
+
362
+	/**
363
+	 * ticket_quantity_updated
364
+	 * releases or reserves ticket(s) based on quantity passed
365
+	 *
366
+	 * @access public
367
+	 * @param  EE_Line_Item $line_item
368
+	 * @param  int          $quantity
369
+	 * @return void
370
+	 * @throws EE_Error
371
+	 */
372
+	public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
373
+	{
374
+		$ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
375
+		if ($ticket instanceof EE_Ticket) {
376
+			if ($quantity > 0) {
377
+				EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
378
+			} else {
379
+				EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
380
+			}
381
+		}
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 * ticket_removed_from_cart
388
+	 * releases reserved ticket(s) based on quantity passed
389
+	 *
390
+	 * @access public
391
+	 * @param  EE_Ticket $ticket
392
+	 * @param  int       $quantity
393
+	 * @return void
394
+	 * @throws EE_Error
395
+	 */
396
+	public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
397
+	{
398
+		EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
399
+	}
400
+
401
+
402
+
403
+	/********************************** POST_NOTICES  **********************************/
404
+
405
+
406
+
407
+	/**
408
+	 *    post_notices
409
+	 *
410
+	 * @access    public
411
+	 * @return    void
412
+	 * @throws EE_Error
413
+	 */
414
+	public static function post_notices()
415
+	{
416
+		EED_Ticket_Sales_Monitor::instance()->_post_notices();
417
+	}
418
+
419
+
420
+
421
+	/**
422
+	 *    _post_notices
423
+	 *
424
+	 * @access    protected
425
+	 * @return    void
426
+	 * @throws EE_Error
427
+	 */
428
+	protected function _post_notices()
429
+	{
430
+		if (self::debug) {
431
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
432
+		}
433
+		$refresh_msg = '';
434
+		$none_added_msg = '';
435
+		if (defined('DOING_AJAX') && DOING_AJAX) {
436
+			$refresh_msg = __('Please refresh the page to view updated ticket quantities.',
437
+				'event_espresso');
438
+			$none_added_msg = __('No tickets were added for the event.', 'event_espresso');
439
+		}
440
+		if ( ! empty($this->sold_out_tickets)) {
441
+			EE_Error::add_attention(
442
+				sprintf(
443
+					apply_filters(
444
+						'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
445
+						__('We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
446
+							'event_espresso')
447
+					),
448
+					'<br />',
449
+					implode('<br />', $this->sold_out_tickets),
450
+					$none_added_msg,
451
+					$refresh_msg
452
+				)
453
+			);
454
+			// alter code flow in the Ticket Selector for better UX
455
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
456
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
457
+			$this->sold_out_tickets = array();
458
+			// and reset the cart
459
+			EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
460
+		}
461
+		if ( ! empty($this->decremented_tickets)) {
462
+			EE_Error::add_attention(
463
+				sprintf(
464
+					apply_filters(
465
+						'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
466
+						__('We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
467
+							'event_espresso')
468
+					),
469
+					'<br />',
470
+					implode('<br />', $this->decremented_tickets),
471
+					$none_added_msg,
472
+					$refresh_msg
473
+				)
474
+			);
475
+			$this->decremented_tickets = array();
476
+		}
477
+	}
478
+
479
+
480
+
481
+	/********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
482
+
483
+
484
+
485
+	/**
486
+	 *    _release_all_reserved_tickets_for_transaction
487
+	 *    releases reserved tickets for all registrations of an EE_Transaction
488
+	 *    by default, will NOT release tickets for finalized transactions
489
+	 *
490
+	 * @access    protected
491
+	 * @param    EE_Transaction $transaction
492
+	 * @return int
493
+	 * @throws EE_Error
494
+	 */
495
+	protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
496
+	{
497
+		if (self::debug) {
498
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
499
+			echo '<br /> . transaction->ID: ' . $transaction->ID();
500
+		}
501
+		// check if 'finalize_registration' step has been completed...
502
+		$finalized = $transaction->reg_step_completed('finalize_registration');
503
+		if (self::debug) {
504
+			// DEBUG LOG
505
+			EEH_Debug_Tools::log(
506
+				__CLASS__, __FUNCTION__, __LINE__,
507
+				array('finalized' => $finalized),
508
+				false, 'EE_Transaction: ' . $transaction->ID()
509
+			);
510
+		}
511
+		// how many tickets were released
512
+		$count = 0;
513
+		if (self::debug) {
514
+			echo '<br /> . . . finalized: ' . $finalized;
515
+		}
516
+		$release_tickets_with_TXN_status = array(
517
+			EEM_Transaction::failed_status_code,
518
+			EEM_Transaction::abandoned_status_code,
519
+			EEM_Transaction::incomplete_status_code,
520
+		);
521
+		// if the session is getting cleared BEFORE the TXN has been finalized
522
+		if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
523
+			// let's cancel any reserved tickets
524
+			$registrations = $transaction->registrations();
525
+			if ( ! empty($registrations)) {
526
+				foreach ($registrations as $registration) {
527
+					if ($registration instanceof EE_Registration) {
528
+						$count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
529
+					}
530
+				}
531
+			}
532
+		}
533
+		return $count;
534
+	}
535
+
536
+
537
+
538
+	/**
539
+	 *    _release_reserved_ticket_for_registration
540
+	 *    releases reserved tickets for an EE_Registration
541
+	 *    by default, will NOT release tickets for APPROVED registrations
542
+	 *
543
+	 * @access    protected
544
+	 * @param    EE_Registration $registration
545
+	 * @param    EE_Transaction  $transaction
546
+	 * @return    int
547
+	 * @throws    EE_Error
548
+	 */
549
+	protected function _release_reserved_ticket_for_registration(
550
+		EE_Registration $registration,
551
+		EE_Transaction $transaction
552
+	) {
553
+		$STS_ID = $transaction->status_ID();
554
+		if (self::debug) {
555
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
556
+			echo '<br /> . . registration->ID: ' . $registration->ID();
557
+			echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
558
+			echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
559
+		}
560
+		if (
561
+			// release Tickets for Failed Transactions and Abandoned Transactions
562
+			$STS_ID === EEM_Transaction::failed_status_code
563
+			|| $STS_ID === EEM_Transaction::abandoned_status_code
564
+			|| (
565
+				// also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
566
+				$STS_ID === EEM_Transaction::incomplete_status_code
567
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
568
+			)
569
+		) {
570
+			$ticket = $registration->ticket();
571
+			if ($ticket instanceof EE_Ticket) {
572
+				return $this->_release_reserved_ticket($ticket);
573
+			}
574
+		}
575
+		return 0;
576
+	}
577
+
578
+
579
+
580
+	/********************************** SESSION_CART_RESET  **********************************/
581
+
582
+
583
+
584
+	/**
585
+	 *    session_cart_reset
586
+	 * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
587
+	 *
588
+	 * @access    public
589
+	 * @param    EE_Session $session
590
+	 * @return    void
591
+	 * @throws EE_Error
592
+	 */
593
+	public static function session_cart_reset(EE_Session $session)
594
+	{
595
+		if (self::debug) {
596
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
597
+		}
598
+		$cart = $session->cart();
599
+		if ($cart instanceof EE_Cart) {
600
+			if (self::debug) {
601
+				echo '<br /><br /> cart instance of EE_Cart: ';
602
+			}
603
+			EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart);
604
+		} else {
605
+			if (self::debug) {
606
+				echo '<br /><br /> invalid EE_Cart: ';
607
+				var_dump($cart);
608
+			}
609
+		}
610
+	}
611
+
612
+
613
+
614
+	/**
615
+	 *    _session_cart_reset
616
+	 * releases reserved tickets in the EE_Cart
617
+	 *
618
+	 * @access    protected
619
+	 * @param    EE_Cart $cart
620
+	 * @return    void
621
+	 * @throws EE_Error
622
+	 */
623
+	protected function _session_cart_reset(EE_Cart $cart)
624
+	{
625
+		if (self::debug) {
626
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
627
+		}
628
+		EE_Registry::instance()->load_helper('Line_Item');
629
+		$ticket_line_items = $cart->get_tickets();
630
+		if (empty($ticket_line_items)) {
631
+			return;
632
+		}
633
+		foreach ($ticket_line_items as $ticket_line_item) {
634
+			if (self::debug) {
635
+				echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
636
+			}
637
+			if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
638
+				if (self::debug) {
639
+					echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
640
+				}
641
+				$ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
642
+				if ($ticket instanceof EE_Ticket) {
643
+					if (self::debug) {
644
+						echo '<br /> . . ticket->ID(): ' . $ticket->ID();
645
+						echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
646
+					}
647
+					$this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
648
+				}
649
+			}
650
+		}
651
+		if (self::debug) {
652
+			echo '<br /><br /> RESET COMPLETED ';
653
+		}
654
+	}
655
+
656
+
657
+
658
+	/********************************** SESSION_CHECKOUT_RESET  **********************************/
659
+
660
+
661
+
662
+	/**
663
+	 *    session_checkout_reset
664
+	 * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
665
+	 *
666
+	 * @access    public
667
+	 * @param    EE_Session $session
668
+	 * @return    void
669
+	 * @throws EE_Error
670
+	 */
671
+	public static function session_checkout_reset(EE_Session $session)
672
+	{
673
+		$checkout = $session->checkout();
674
+		if ($checkout instanceof EE_Checkout) {
675
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
676
+		}
677
+	}
678
+
679
+
680
+
681
+	/**
682
+	 *    _session_checkout_reset
683
+	 * releases reserved tickets for the EE_Checkout->transaction
684
+	 *
685
+	 * @access    protected
686
+	 * @param    EE_Checkout $checkout
687
+	 * @return    void
688
+	 * @throws EE_Error
689
+	 */
690
+	protected function _session_checkout_reset(EE_Checkout $checkout)
691
+	{
692
+		if (self::debug) {
693
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
694
+		}
695
+		// we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
696
+		if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
697
+			return;
698
+		}
699
+		$this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
700
+	}
701
+
702
+
703
+
704
+	/********************************** SESSION_EXPIRED_RESET  **********************************/
705
+
706
+
707
+
708
+	/**
709
+	 *    session_expired_reset
710
+	 *
711
+	 * @access    public
712
+	 * @param    EE_Session $session
713
+	 * @return    void
714
+	 */
715
+	public static function session_expired_reset(EE_Session $session)
716
+	{
717
+	}
718
+
719
+
720
+
721
+	/********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
722
+
723
+
724
+
725
+	/**
726
+	 *    process_abandoned_transactions
727
+	 *    releases reserved tickets for all registrations of an ABANDONED EE_Transaction
728
+	 *    by default, will NOT release tickets for free transactions, or any that have received a payment
729
+	 *
730
+	 * @access    public
731
+	 * @param    EE_Transaction $transaction
732
+	 * @return    void
733
+	 * @throws EE_Error
734
+	 */
735
+	public static function process_abandoned_transactions(EE_Transaction $transaction)
736
+	{
737
+		// is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
738
+		if ($transaction->is_free() || $transaction->paid() > 0) {
739
+			if (self::debug) {
740
+				// DEBUG LOG
741
+				EEH_Debug_Tools::log(
742
+					__CLASS__, __FUNCTION__, __LINE__,
743
+					array($transaction),
744
+					false, 'EE_Transaction: ' . $transaction->ID()
745
+				);
746
+			}
747
+			return;
748
+		}
749
+		// have their been any successful payments made ?
750
+		$payments = $transaction->payments();
751
+		foreach ($payments as $payment) {
752
+			if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
753
+				if (self::debug) {
754
+					// DEBUG LOG
755
+					EEH_Debug_Tools::log(
756
+						__CLASS__, __FUNCTION__, __LINE__,
757
+						array($payment),
758
+						false, 'EE_Transaction: ' . $transaction->ID()
759
+					);
760
+				}
761
+				return;
762
+			}
763
+		}
764
+		// since you haven't even attempted to pay for your ticket...
765
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
766
+	}
767
+
768
+
769
+
770
+	/********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
771
+
772
+
773
+
774
+	/**
775
+	 *    process_abandoned_transactions
776
+	 *    releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
777
+	 *
778
+	 * @access    public
779
+	 * @param    EE_Transaction $transaction
780
+	 * @return    void
781
+	 * @throws EE_Error
782
+	 */
783
+	public static function process_failed_transactions(EE_Transaction $transaction)
784
+	{
785
+		// since you haven't even attempted to pay for your ticket...
786
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
787
+	}
788
+
789
+
790
+
791
+	/********************************** RESET RESERVATION COUNTS  *********************************/
792
+
793
+
794
+
795
+	/**
796
+	 * Resets all ticket and datetime reserved counts to zero
797
+	 * Tickets that are currently associated with a Transaction that is in progress
798
+	 *
799
+	 * @throws \EE_Error
800
+	 * @throws \DomainException
801
+	 */
802
+	public static function reset_reservation_counts()
803
+	{
804
+		$total_tickets_released = 0;
805
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
806
+		$valid_reserved_tickets = array();
807
+		$transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress();
808
+		foreach ($transactions_in_progress as $transaction_in_progress) {
809
+			// if this TXN has been fully completed, then skip it
810
+			if ($transaction_in_progress->reg_step_completed('finalize_registration')) {
811
+				continue;
812
+			}
813
+			/** @var EE_Transaction $transaction_in_progress */
814
+			$total_line_item = $transaction_in_progress->total_line_item();
815
+			// $transaction_in_progress->line
816
+			if (! $total_line_item instanceof EE_Line_Item) {
817
+				throw new DomainException(
818
+					esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso')
819
+				);
820
+			}
821
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item);
822
+		}
823
+		$total_line_items = EEM_Line_Item::instance()->get_total_line_items_just_added_to_cart();
824
+		foreach ($total_line_items as $total_line_item) {
825
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item);
826
+		}
827
+		$tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
828
+		foreach ($tickets_with_reservations as $ticket_with_reservations) {
829
+			if (! $ticket_with_reservations instanceof EE_Ticket) {
830
+				continue;
831
+			}
832
+			$reserved_qty = $ticket_with_reservations->reserved();
833
+			foreach ($valid_reserved_tickets as $valid_reserved_ticket) {
834
+				if(
835
+					$valid_reserved_ticket instanceof EE_Line_Item
836
+					&& $valid_reserved_ticket->OBJ_ID() === $ticket_with_reservations->ID()
837
+				) {
838
+					$reserved_qty -= $valid_reserved_ticket->quantity();
839
+				}
840
+			}
841
+			if ($reserved_qty > 0) {
842
+				$ticket_with_reservations->decrease_reserved($reserved_qty);
843
+				$ticket_with_reservations->save();
844
+				$total_tickets_released += $reserved_qty;
845
+			}
846
+		}
847
+		return $total_tickets_released;
848
+	}
849
+
850
+
851
+
852
+	private static function get_reserved_tickets_for_line_item(EE_Line_Item $total_line_item)
853
+	{
854
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
855
+		$valid_reserved_tickets = array();
856
+		$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
857
+		foreach ($ticket_line_items as $ticket_line_item) {
858
+			if ($ticket_line_item instanceof EE_Line_Item) {
859
+				$valid_reserved_tickets[] = $ticket_line_item;
860
+			}
861
+		}
862
+		return $valid_reserved_tickets;
863
+	}
864 864
 
865 865
 }
866 866
 // End of file EED_Ticket_Sales_Monitor.module.php
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_data_reset_and_delete.template.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 /** @var string $delete_db_url */
8 8
 ?>
9 9
 <h2>
10
-	<?php esc_html_e( 'Reset/Delete Data for Event Espresso', 'event_espresso' );?>
10
+	<?php esc_html_e('Reset/Delete Data for Event Espresso', 'event_espresso'); ?>
11 11
 </h2>
12 12
 <br />
13 13
 
14 14
 <div class="padding">
15
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso');?></h4>
16
-	<p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso');?></p>
15
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso'); ?></h4>
16
+	<p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso'); ?></p>
17 17
 	<div class="float-right"><?php echo $reset_reservations_button; ?></div>
18 18
 	<div class="clear"></div>
19 19
 </div>
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 
23 23
 <!-- reset DB url is here. Just need to make it look pretty and unhide it-->
24 24
 <div class="padding">
25
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso');?></h4>
26
-	<p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities.  Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso');?></p>
25
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso'); ?></h4>
26
+	<p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities.  Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso'); ?></p>
27 27
 	<div class="float-right"><?php echo $reset_capabilities_button; ?></div>
28 28
 	<div class="clear"></div>
29 29
 </div>
@@ -31,24 +31,24 @@  discard block
 block discarded – undo
31 31
 <br />
32 32
 
33 33
 <div class="padding">
34
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso');?></h4>
35
-	<p><?php esc_html_e('Use this to reset Event Espresso Data and return your site to how it was just after first activating Event Espresso.', 'event_espresso');?></p>
36
-	<div class="float-right"><a class="button button-primary" href="<?php echo $reset_db_url;?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso');?></a></div>
34
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso'); ?></h4>
35
+	<p><?php esc_html_e('Use this to reset Event Espresso Data and return your site to how it was just after first activating Event Espresso.', 'event_espresso'); ?></p>
36
+	<div class="float-right"><a class="button button-primary" href="<?php echo $reset_db_url; ?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso'); ?></a></div>
37 37
 	<div class="clear"></div>
38 38
 </div>
39 39
 <br />
40 40
 <br />
41 41
 
42 42
 <div class="padding">
43
-	<h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Tables and Data', 'event_espresso');?></h4>
44
-	<p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso');?></p>
45
-	<p class="important-notice"><?php printf( esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<strong>', '</strong>' ); ?><br/></p>
43
+	<h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Tables and Data', 'event_espresso'); ?></h4>
44
+	<p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso'); ?></p>
45
+	<p class="important-notice"><?php printf(esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<strong>', '</strong>'); ?><br/></p>
46 46
 	<ol>
47
-		<li><?php  printf( esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>' );?></li>
48
-		<li><?php printf( esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li>
49
-        <li><?php printf( esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li>
47
+		<li><?php  printf(esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>'); ?></li>
48
+		<li><?php printf(esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>'); ?></li>
49
+        <li><?php printf(esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>'); ?></li>
50 50
 	</ol>
51
-	<div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso');?></a></div>
51
+	<div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso'); ?></a></div>
52 52
 	<div class="clear"></div>
53 53
 </div>
54 54
 <br/>
Please login to merge, or discard this patch.
core/db_models/EEM_Transaction.model.php 1 patch
Indentation   +362 added lines, -362 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_Base.model.php');
5 5
 
@@ -15,192 +15,192 @@  discard block
 block discarded – undo
15 15
 class EEM_Transaction extends EEM_Base
16 16
 {
17 17
 
18
-    // private instance of the Transaction object
19
-    protected static $_instance;
20
-
21
-    /**
22
-     * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
23
-     * but payment is pending. This is the state for transactions where payment is promised
24
-     * from an offline gateway.
25
-     */
26
-    //	const open_status_code = 'TPN';
27
-
28
-    /**
29
-     * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
30
-     * either due to a technical reason (server or computer crash during registration),
31
-     *  or some other reason that prevent the collection of any useful contact information from any of the registrants
32
-     */
33
-    const failed_status_code = 'TFL';
34
-
35
-    /**
36
-     * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
37
-     * either due to a technical reason (server or computer crash during registration),
38
-     * or due to an abandoned cart after registrant chose not to complete the registration process
39
-     * HOWEVER...
40
-     * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
41
-     * registrant
42
-     */
43
-    const abandoned_status_code = 'TAB';
44
-
45
-    /**
46
-     * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
47
-     * meaning that monies are still owing: TXN_paid < TXN_total
48
-     */
49
-    const incomplete_status_code = 'TIN';
50
-
51
-    /**
52
-     * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
53
-     * meaning that NO monies are owing: TXN_paid == TXN_total
54
-     */
55
-    const complete_status_code = 'TCM';
56
-
57
-    /**
58
-     *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
59
-     *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
60
-     */
61
-    const overpaid_status_code = 'TOP';
62
-
63
-
64
-    /**
65
-     *    private constructor to prevent direct creation
66
-     *
67
-     * @Constructor
68
-     * @access protected
69
-     *
70
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
71
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
72
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
73
-     *                         timezone in the 'timezone_string' wp option)
74
-     *
75
-     * @return EEM_Transaction
76
-     * @throws \EE_Error
77
-     */
78
-    protected function __construct($timezone)
79
-    {
80
-        $this->singular_item = __('Transaction', 'event_espresso');
81
-        $this->plural_item   = __('Transactions', 'event_espresso');
82
-
83
-        $this->_tables                 = array(
84
-            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
85
-        );
86
-        $this->_fields                 = array(
87
-            'TransactionTable' => array(
88
-                'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
89
-                'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
90
-                    __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
91
-                    $timezone),
92
-                'TXN_total'        => new EE_Money_Field('TXN_total',
93
-                    __('Total value of Transaction', 'event_espresso'), false, 0),
94
-                'TXN_paid'         => new EE_Money_Field('TXN_paid',
95
-                    __('Amount paid towards transaction to date', 'event_espresso'), false, 0),
96
-                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
97
-                    false, EEM_Transaction::failed_status_code, 'Status'),
98
-                'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
99
-                    __('Serialized session data', 'event_espresso'), true, ''),
100
-                'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
101
-                    __('Transaction Hash Salt', 'event_espresso'), true, ''),
102
-                'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
103
-                    __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
104
-                'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
105
-                    __('Registration Steps', 'event_espresso'), false, array()),
106
-            )
107
-        );
108
-        $this->_model_relations        = array(
109
-            'Registration'   => new EE_Has_Many_Relation(),
110
-            'Payment'        => new EE_Has_Many_Relation(),
111
-            'Status'         => new EE_Belongs_To_Relation(),
112
-            'Line_Item'      => new EE_Has_Many_Relation(false),
113
-            //you can delete a transaction without needing to delete its line items
114
-            'Payment_Method' => new EE_Belongs_To_Relation(),
115
-            'Message'        => new EE_Has_Many_Relation()
116
-        );
117
-        $this->_model_chain_to_wp_user = 'Registration.Event';
118
-        parent::__construct($timezone);
119
-
120
-    }
121
-
122
-
123
-    /**
124
-     *    txn_status_array
125
-     * get list of transaction statuses
126
-     *
127
-     * @access public
128
-     * @return array
129
-     */
130
-    public static function txn_status_array()
131
-    {
132
-        return apply_filters(
133
-            'FHEE__EEM_Transaction__txn_status_array',
134
-            array(
135
-                EEM_Transaction::overpaid_status_code,
136
-                EEM_Transaction::complete_status_code,
137
-                EEM_Transaction::incomplete_status_code,
138
-                EEM_Transaction::abandoned_status_code,
139
-                EEM_Transaction::failed_status_code,
140
-            )
141
-        );
142
-    }
143
-
144
-    /**
145
-     *        get the revenue per day  for the Transaction Admin page Reports Tab
146
-     *
147
-     * @access        public
148
-     *
149
-     * @param string $period
150
-     *
151
-     * @return \stdClass[]
152
-     */
153
-    public function get_revenue_per_day_report($period = '-1 month')
154
-    {
155
-        $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
156
-            'Y-m-d H:i:s', 'UTC');
157
-
158
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
159
-
160
-        return $this->_get_all_wpdb_results(
161
-            array(
162
-                array(
163
-                    'TXN_timestamp' => array('>=', $sql_date)
164
-                ),
165
-                'group_by' => 'txnDate',
166
-                'order_by' => array('TXN_timestamp' => 'ASC')
167
-            ),
168
-            OBJECT,
169
-            array(
170
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
171
-                'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
172
-            )
173
-        );
174
-    }
175
-
176
-
177
-    /**
178
-     *        get the revenue per event  for the Transaction Admin page Reports Tab
179
-     *
180
-     * @access        public
181
-     *
182
-     * @param string $period
183
-     *
184
-     * @throws \EE_Error
185
-     * @return mixed
186
-     */
187
-    public function get_revenue_per_event_report($period = '-1 month')
188
-    {
189
-        global $wpdb;
190
-        $transaction_table       = $wpdb->prefix . 'esp_transaction';
191
-        $registration_table      = $wpdb->prefix . 'esp_registration';
192
-        $event_table             = $wpdb->posts;
193
-        $payment_table           = $wpdb->prefix . 'esp_payment';
194
-        $sql_date                = date('Y-m-d H:i:s', strtotime($period));
195
-        $approved_payment_status = EEM_Payment::status_id_approved;
196
-        $extra_event_on_join     = '';
197
-        //exclude events not authored by user if permissions in effect
198
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
199
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
200
-        }
201
-
202
-        return $wpdb->get_results(
203
-            "SELECT
18
+	// private instance of the Transaction object
19
+	protected static $_instance;
20
+
21
+	/**
22
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
23
+	 * but payment is pending. This is the state for transactions where payment is promised
24
+	 * from an offline gateway.
25
+	 */
26
+	//	const open_status_code = 'TPN';
27
+
28
+	/**
29
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
30
+	 * either due to a technical reason (server or computer crash during registration),
31
+	 *  or some other reason that prevent the collection of any useful contact information from any of the registrants
32
+	 */
33
+	const failed_status_code = 'TFL';
34
+
35
+	/**
36
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
37
+	 * either due to a technical reason (server or computer crash during registration),
38
+	 * or due to an abandoned cart after registrant chose not to complete the registration process
39
+	 * HOWEVER...
40
+	 * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
41
+	 * registrant
42
+	 */
43
+	const abandoned_status_code = 'TAB';
44
+
45
+	/**
46
+	 * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
47
+	 * meaning that monies are still owing: TXN_paid < TXN_total
48
+	 */
49
+	const incomplete_status_code = 'TIN';
50
+
51
+	/**
52
+	 * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
53
+	 * meaning that NO monies are owing: TXN_paid == TXN_total
54
+	 */
55
+	const complete_status_code = 'TCM';
56
+
57
+	/**
58
+	 *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
59
+	 *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
60
+	 */
61
+	const overpaid_status_code = 'TOP';
62
+
63
+
64
+	/**
65
+	 *    private constructor to prevent direct creation
66
+	 *
67
+	 * @Constructor
68
+	 * @access protected
69
+	 *
70
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
71
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
72
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
73
+	 *                         timezone in the 'timezone_string' wp option)
74
+	 *
75
+	 * @return EEM_Transaction
76
+	 * @throws \EE_Error
77
+	 */
78
+	protected function __construct($timezone)
79
+	{
80
+		$this->singular_item = __('Transaction', 'event_espresso');
81
+		$this->plural_item   = __('Transactions', 'event_espresso');
82
+
83
+		$this->_tables                 = array(
84
+			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
85
+		);
86
+		$this->_fields                 = array(
87
+			'TransactionTable' => array(
88
+				'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
89
+				'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
90
+					__('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
91
+					$timezone),
92
+				'TXN_total'        => new EE_Money_Field('TXN_total',
93
+					__('Total value of Transaction', 'event_espresso'), false, 0),
94
+				'TXN_paid'         => new EE_Money_Field('TXN_paid',
95
+					__('Amount paid towards transaction to date', 'event_espresso'), false, 0),
96
+				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
97
+					false, EEM_Transaction::failed_status_code, 'Status'),
98
+				'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
99
+					__('Serialized session data', 'event_espresso'), true, ''),
100
+				'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
101
+					__('Transaction Hash Salt', 'event_espresso'), true, ''),
102
+				'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
103
+					__("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
104
+				'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
105
+					__('Registration Steps', 'event_espresso'), false, array()),
106
+			)
107
+		);
108
+		$this->_model_relations        = array(
109
+			'Registration'   => new EE_Has_Many_Relation(),
110
+			'Payment'        => new EE_Has_Many_Relation(),
111
+			'Status'         => new EE_Belongs_To_Relation(),
112
+			'Line_Item'      => new EE_Has_Many_Relation(false),
113
+			//you can delete a transaction without needing to delete its line items
114
+			'Payment_Method' => new EE_Belongs_To_Relation(),
115
+			'Message'        => new EE_Has_Many_Relation()
116
+		);
117
+		$this->_model_chain_to_wp_user = 'Registration.Event';
118
+		parent::__construct($timezone);
119
+
120
+	}
121
+
122
+
123
+	/**
124
+	 *    txn_status_array
125
+	 * get list of transaction statuses
126
+	 *
127
+	 * @access public
128
+	 * @return array
129
+	 */
130
+	public static function txn_status_array()
131
+	{
132
+		return apply_filters(
133
+			'FHEE__EEM_Transaction__txn_status_array',
134
+			array(
135
+				EEM_Transaction::overpaid_status_code,
136
+				EEM_Transaction::complete_status_code,
137
+				EEM_Transaction::incomplete_status_code,
138
+				EEM_Transaction::abandoned_status_code,
139
+				EEM_Transaction::failed_status_code,
140
+			)
141
+		);
142
+	}
143
+
144
+	/**
145
+	 *        get the revenue per day  for the Transaction Admin page Reports Tab
146
+	 *
147
+	 * @access        public
148
+	 *
149
+	 * @param string $period
150
+	 *
151
+	 * @return \stdClass[]
152
+	 */
153
+	public function get_revenue_per_day_report($period = '-1 month')
154
+	{
155
+		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
156
+			'Y-m-d H:i:s', 'UTC');
157
+
158
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
159
+
160
+		return $this->_get_all_wpdb_results(
161
+			array(
162
+				array(
163
+					'TXN_timestamp' => array('>=', $sql_date)
164
+				),
165
+				'group_by' => 'txnDate',
166
+				'order_by' => array('TXN_timestamp' => 'ASC')
167
+			),
168
+			OBJECT,
169
+			array(
170
+				'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
171
+				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
172
+			)
173
+		);
174
+	}
175
+
176
+
177
+	/**
178
+	 *        get the revenue per event  for the Transaction Admin page Reports Tab
179
+	 *
180
+	 * @access        public
181
+	 *
182
+	 * @param string $period
183
+	 *
184
+	 * @throws \EE_Error
185
+	 * @return mixed
186
+	 */
187
+	public function get_revenue_per_event_report($period = '-1 month')
188
+	{
189
+		global $wpdb;
190
+		$transaction_table       = $wpdb->prefix . 'esp_transaction';
191
+		$registration_table      = $wpdb->prefix . 'esp_registration';
192
+		$event_table             = $wpdb->posts;
193
+		$payment_table           = $wpdb->prefix . 'esp_payment';
194
+		$sql_date                = date('Y-m-d H:i:s', strtotime($period));
195
+		$approved_payment_status = EEM_Payment::status_id_approved;
196
+		$extra_event_on_join     = '';
197
+		//exclude events not authored by user if permissions in effect
198
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
199
+			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
200
+		}
201
+
202
+		return $wpdb->get_results(
203
+			"SELECT
204 204
 			Transaction_Event.event_name AS event_name,
205 205
 			SUM(Transaction_Event.paid) AS revenue
206 206
 			FROM
@@ -220,185 +220,185 @@  discard block
 block discarded – undo
220 220
 							$extra_event_on_join
221 221
 				) AS Transaction_Event
222 222
 			GROUP BY event_name",
223
-            OBJECT
224
-        );
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
230
-     * $_REQUEST global variable. Either way, tries to find the current transaction (through
231
-     * the registration pointed to by reg_url_link), if not returns null
232
-     *
233
-     * @param string $reg_url_link
234
-     *
235
-     * @return EE_Transaction
236
-     */
237
-    public function get_transaction_from_reg_url_link($reg_url_link = '')
238
-    {
239
-        return $this->get_one(array(
240
-            array(
241
-                'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
242
-                    '')
243
-            )
244
-        ));
245
-    }
246
-
247
-
248
-    /**
249
-     * Updates the provided EE_Transaction with all the applicable payments
250
-     * (or fetch the EE_Transaction from its ID)
251
-     *
252
-     * @deprecated
253
-     *
254
-     * @param EE_Transaction|int $transaction_obj_or_id
255
-     * @param boolean            $save_txn whether or not to save the transaction during this function call
256
-     *
257
-     * @return boolean
258
-     * @throws \EE_Error
259
-     */
260
-    public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
261
-    {
262
-        EE_Error::doing_it_wrong(
263
-            __CLASS__ . '::' . __FUNCTION__,
264
-            sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
265
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
266
-            '4.6.0'
267
-        );
268
-        /** @type EE_Transaction_Processor $transaction_processor */
269
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
270
-
271
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
272
-            $this->ensure_is_obj($transaction_obj_or_id)
273
-        );
274
-    }
275
-
276
-    /**
277
-     * Deletes "junk" transactions that were probably added by bots. There might be TONS
278
-     * of these, so we are very careful to NOT select (which the models do even when deleting),
279
-     * and so we only use wpdb directly and only do minimal joins.
280
-     * Transactions are considered "junk" if they're failed for longer than a week.
281
-     * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
282
-     * it, it's probably not junk (regardless of what status it has).
283
-     * The downside to this approach is that is addons are listening for object deletions
284
-     * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
285
-     * to catch these types of deletions.
286
-     *
287
-     * @global WPDB $wpdb
288
-     * @return mixed
289
-     */
290
-    public function delete_junk_transactions()
291
-    {
292
-        /** @type WPDB $wpdb */
293
-        global $wpdb;
294
-        $deleted             = false;
295
-        $time_to_leave_alone = apply_filters(
296
-            'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
297
-            , WEEK_IN_SECONDS
298
-        );
299
-
300
-
301
-        /**
302
-         * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
303
-         * Useful for plugins that want to exclude transactions matching certain query parameters.
304
-         * The query parameters should be in the format accepted by the EEM_Base model queries.
305
-         */
306
-        $ids_query = apply_filters(
307
-            'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
308
-            array(
309
-                0 => array(
310
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
311
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
312
-                    'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
313
-                )
314
-            ),
315
-            $time_to_leave_alone
316
-        );
317
-
318
-
319
-        /**
320
-         * This filter is for when code needs to filter the list of transaction ids that represent transactions
321
-         * about to be deleted based on some other criteria that isn't easily done via the query args filter.
322
-         */
323
-        $txn_ids = apply_filters(
324
-            'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
325
-            EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
326
-            $time_to_leave_alone
327
-        );
328
-        //now that we have the ids to delete
329
-        if (! empty($txn_ids) && is_array($txn_ids)) {
330
-            // first, make sure these TXN's are removed the "ee_locked_transactions" array
331
-            EEM_Transaction::unset_locked_transactions($txn_ids);
332
-            // let's get deletin'...
333
-            // Why no wpdb->prepare?  Because the data is trusted.
334
-            // We got the ids from the original query to get them FROM
335
-            // the db (which is sanitized) so no need to prepare them again.
336
-            $query   = '
223
+			OBJECT
224
+		);
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
230
+	 * $_REQUEST global variable. Either way, tries to find the current transaction (through
231
+	 * the registration pointed to by reg_url_link), if not returns null
232
+	 *
233
+	 * @param string $reg_url_link
234
+	 *
235
+	 * @return EE_Transaction
236
+	 */
237
+	public function get_transaction_from_reg_url_link($reg_url_link = '')
238
+	{
239
+		return $this->get_one(array(
240
+			array(
241
+				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
242
+					'')
243
+			)
244
+		));
245
+	}
246
+
247
+
248
+	/**
249
+	 * Updates the provided EE_Transaction with all the applicable payments
250
+	 * (or fetch the EE_Transaction from its ID)
251
+	 *
252
+	 * @deprecated
253
+	 *
254
+	 * @param EE_Transaction|int $transaction_obj_or_id
255
+	 * @param boolean            $save_txn whether or not to save the transaction during this function call
256
+	 *
257
+	 * @return boolean
258
+	 * @throws \EE_Error
259
+	 */
260
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
261
+	{
262
+		EE_Error::doing_it_wrong(
263
+			__CLASS__ . '::' . __FUNCTION__,
264
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
265
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
266
+			'4.6.0'
267
+		);
268
+		/** @type EE_Transaction_Processor $transaction_processor */
269
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
270
+
271
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
272
+			$this->ensure_is_obj($transaction_obj_or_id)
273
+		);
274
+	}
275
+
276
+	/**
277
+	 * Deletes "junk" transactions that were probably added by bots. There might be TONS
278
+	 * of these, so we are very careful to NOT select (which the models do even when deleting),
279
+	 * and so we only use wpdb directly and only do minimal joins.
280
+	 * Transactions are considered "junk" if they're failed for longer than a week.
281
+	 * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
282
+	 * it, it's probably not junk (regardless of what status it has).
283
+	 * The downside to this approach is that is addons are listening for object deletions
284
+	 * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
285
+	 * to catch these types of deletions.
286
+	 *
287
+	 * @global WPDB $wpdb
288
+	 * @return mixed
289
+	 */
290
+	public function delete_junk_transactions()
291
+	{
292
+		/** @type WPDB $wpdb */
293
+		global $wpdb;
294
+		$deleted             = false;
295
+		$time_to_leave_alone = apply_filters(
296
+			'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
297
+			, WEEK_IN_SECONDS
298
+		);
299
+
300
+
301
+		/**
302
+		 * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
303
+		 * Useful for plugins that want to exclude transactions matching certain query parameters.
304
+		 * The query parameters should be in the format accepted by the EEM_Base model queries.
305
+		 */
306
+		$ids_query = apply_filters(
307
+			'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
308
+			array(
309
+				0 => array(
310
+					'STS_ID'        => EEM_Transaction::failed_status_code,
311
+					'Payment.PAY_ID' => array( 'IS NULL' ),
312
+					'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
313
+				)
314
+			),
315
+			$time_to_leave_alone
316
+		);
317
+
318
+
319
+		/**
320
+		 * This filter is for when code needs to filter the list of transaction ids that represent transactions
321
+		 * about to be deleted based on some other criteria that isn't easily done via the query args filter.
322
+		 */
323
+		$txn_ids = apply_filters(
324
+			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
325
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
326
+			$time_to_leave_alone
327
+		);
328
+		//now that we have the ids to delete
329
+		if (! empty($txn_ids) && is_array($txn_ids)) {
330
+			// first, make sure these TXN's are removed the "ee_locked_transactions" array
331
+			EEM_Transaction::unset_locked_transactions($txn_ids);
332
+			// let's get deletin'...
333
+			// Why no wpdb->prepare?  Because the data is trusted.
334
+			// We got the ids from the original query to get them FROM
335
+			// the db (which is sanitized) so no need to prepare them again.
336
+			$query   = '
337 337
 				DELETE
338 338
 				FROM ' . $this->table() . '
339 339
 				WHERE
340 340
 					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
341
-            $deleted = $wpdb->query($query);
342
-        }
343
-        if ($deleted) {
344
-            /**
345
-             * Allows code to do something after the transactions have been deleted.
346
-             */
347
-            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
348
-        }
349
-
350
-        return $deleted;
351
-    }
352
-
353
-
354
-    /**
355
-     * @param array $transaction_IDs
356
-     *
357
-     * @return bool
358
-     */
359
-    public static function unset_locked_transactions(array $transaction_IDs)
360
-    {
361
-        $locked_transactions = get_option('ee_locked_transactions', array());
362
-        $update              = false;
363
-        foreach ($transaction_IDs as $TXN_ID) {
364
-            if (isset($locked_transactions[$TXN_ID])) {
365
-                unset($locked_transactions[$TXN_ID]);
366
-                $update = true;
367
-            }
368
-        }
369
-        if ($update) {
370
-            update_option('ee_locked_transactions', $locked_transactions);
371
-        }
372
-
373
-        return $update;
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * returns an array of EE_Transaction objects whose timestamp is less than
380
-     * the current time minus the session lifespan, which defaults to 60 minutes
381
-     *
382
-     * @return EE_Base_Class[]|EE_Transaction[]
383
-     * @throws \EE_Error
384
-     */
385
-    public function get_transactions_in_progress()
386
-    {
387
-        return $this->get_all(
388
-            array(
389
-                array(
390
-                    'TXN_timestamp' => array(
391
-                        '>',
392
-                        time() - EE_Registry::instance()->SSN->lifespan()
393
-                    ),
394
-                    'STS_ID' => array(
395
-                        '!=',
396
-                        EEM_Transaction::complete_status_code
397
-                    ),
398
-                )
399
-            )
400
-        );
401
-    }
341
+			$deleted = $wpdb->query($query);
342
+		}
343
+		if ($deleted) {
344
+			/**
345
+			 * Allows code to do something after the transactions have been deleted.
346
+			 */
347
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
348
+		}
349
+
350
+		return $deleted;
351
+	}
352
+
353
+
354
+	/**
355
+	 * @param array $transaction_IDs
356
+	 *
357
+	 * @return bool
358
+	 */
359
+	public static function unset_locked_transactions(array $transaction_IDs)
360
+	{
361
+		$locked_transactions = get_option('ee_locked_transactions', array());
362
+		$update              = false;
363
+		foreach ($transaction_IDs as $TXN_ID) {
364
+			if (isset($locked_transactions[$TXN_ID])) {
365
+				unset($locked_transactions[$TXN_ID]);
366
+				$update = true;
367
+			}
368
+		}
369
+		if ($update) {
370
+			update_option('ee_locked_transactions', $locked_transactions);
371
+		}
372
+
373
+		return $update;
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * returns an array of EE_Transaction objects whose timestamp is less than
380
+	 * the current time minus the session lifespan, which defaults to 60 minutes
381
+	 *
382
+	 * @return EE_Base_Class[]|EE_Transaction[]
383
+	 * @throws \EE_Error
384
+	 */
385
+	public function get_transactions_in_progress()
386
+	{
387
+		return $this->get_all(
388
+			array(
389
+				array(
390
+					'TXN_timestamp' => array(
391
+						'>',
392
+						time() - EE_Registry::instance()->SSN->lifespan()
393
+					),
394
+					'STS_ID' => array(
395
+						'!=',
396
+						EEM_Transaction::complete_status_code
397
+					),
398
+				)
399
+			)
400
+		);
401
+	}
402 402
 
403 403
 
404 404
 }
Please login to merge, or discard this patch.