Completed
Branch BUG-9951-10331-8793-pue-fixes (40e696)
by
unknown
27:52 queued 13:57
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   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -19,404 +19,404 @@
 block discarded – undo
19 19
 class TicketSelectorRowStandard extends TicketSelectorRow
20 20
 {
21 21
 
22
-    /**
23
-     * @var TicketDetails $ticket_details
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var \EE_Ticket_Selector_Config $template_settings
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var \EE_Tax_Config $tax_settings
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var boolean $prices_displayed_including_taxes
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int $row
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int $cols
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean $hidden_input_qty
54
-     */
55
-    protected $hidden_input_qty;
56
-
57
-    /**
58
-     * @var string $ticket_datetime_classes
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-
64
-    /**
65
-     * TicketDetails constructor.
66
-     *
67
-     * @param TicketDetails  $ticket_details
68
-     * @param \EE_Tax_Config $tax_settings
69
-     * @param int            $total_tickets
70
-     * @param int            $max_atndz
71
-     * @param int            $row
72
-     * @param int            $cols
73
-     * @param boolean        $required_ticket_sold_out
74
-     * @param string         $event_status
75
-     * @param string         $ticket_datetime_classes
76
-     * @throws EE_Error
77
-     * @throws UnexpectedEntityException
78
-     */
79
-    public function __construct(
80
-        TicketDetails $ticket_details,
81
-        \EE_Tax_Config $tax_settings,
82
-        $total_tickets,
83
-        $max_atndz,
84
-        $row,
85
-        $cols,
86
-        $required_ticket_sold_out,
87
-        $event_status,
88
-        $ticket_datetime_classes
89
-    ) {
90
-        $this->ticket = $ticket_details->getTicket();
91
-        $this->ticket_details = $ticket_details;
92
-        $this->template_settings = $ticket_details->getTemplateSettings();
93
-        $this->tax_settings = $tax_settings;
94
-        $this->total_tickets = $total_tickets;
95
-        $this->max_atndz = $max_atndz;
96
-        $this->row = $row;
97
-        $this->cols = $cols;
98
-        $this->date_format = $ticket_details->getDateFormat();
99
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
100
-        parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * other ticket rows will need to know if a required ticket is sold out,
107
-     * so that they are not offered for sale
108
-     *
109
-     * @return boolean
110
-     */
111
-    public function getRequiredTicketSoldOut()
112
-    {
113
-        return $this->required_ticket_sold_out;
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * getHtml
130
-     *
131
-     * @return string
132
-     * @throws EE_Error
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $min = 0;
137
-        $max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
-            list($min, $max) = $this->setTicketMinAndMax($remaining);
141
-        } else {
142
-            // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
-            $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
-                ? $this->ticket->start_date()
145
-                : $this->required_ticket_sold_out;
146
-        }
147
-        list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
-        list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
-        /**
150
-         * Allow plugins to hook in and abort the generation and display of this row to do
151
-         * something else if they want.
152
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
153
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
-         * current row.
155
-         *
156
-         * @var string|bool
157
-         */
158
-        $ticket_selector_row_html = apply_filters(
159
-            'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
-            false,
161
-            $this->ticket,
162
-            $max,
163
-            $min,
164
-            $this->required_ticket_sold_out,
165
-            $ticket_price,
166
-            $ticket_bundle,
167
-            $ticket_status,
168
-            $status_class
169
-        );
170
-        if ($ticket_selector_row_html !== false) {
171
-            return $ticket_selector_row_html;
172
-        }
173
-        $ticket_selector_row_html = \EEH_HTML::tr(
174
-            '', '',
175
-            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
-        );
177
-        /**
178
-         * Allow plugins to hook in and abort the generation and display of the contents of this
179
-         * row to do something else if they want.
180
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
181
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
-         * current row.
183
-         *
184
-         * @var string|bool
185
-         */
186
-        $new_row_cells_content = apply_filters(
187
-            'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
-            false,
189
-            $this->ticket,
190
-            $max,
191
-            $min,
192
-            $this->required_ticket_sold_out,
193
-            $ticket_price,
194
-            $ticket_bundle,
195
-            $ticket_status,
196
-            $status_class
197
-        );
198
-        if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
-            return $ticket_selector_row_html
200
-                   . $new_row_cells_content
201
-                   . $this->ticketQtyAndIdHiddenInputs()
202
-                   . \EEH_HTML::trx();
203
-        }
204
-        if ($new_row_cells_content !== false) {
205
-            return $ticket_selector_row_html
206
-                   . $new_row_cells_content
207
-                   . \EEH_HTML::trx();
208
-        }
209
-        $this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
-
211
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
212
-        $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
-        $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
-        if (empty($this->ticket_status_display)) {
216
-            if ($this->max_atndz === 1) {
217
-                // only ONE attendee is allowed to register at a time
218
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
-            } else if ($max > 0) {
220
-                $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
-            }
222
-        }
223
-        $ticket_selector_row_html .= $this->ticket_status_display;
224
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
-        $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
-        $ticket_selector_row_html .= \EEH_HTML::tdx();
227
-        $ticket_selector_row_html .= \EEH_HTML::trx();
228
-
229
-
230
-        $this->row++;
231
-        return $ticket_selector_row_html;
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * setTicketMinAndMax
238
-     *
239
-     * @param int $remaining
240
-     * @return array
241
-     * @throws EE_Error
242
-     */
243
-    protected function setTicketMinAndMax($remaining)
244
-    {
245
-        // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
-        $max = min($remaining, $this->max_atndz);
247
-        // but... we also want to restrict the number of tickets by the ticket max setting,
248
-        // however, the max still can't be higher than what was just set above
249
-        $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
-        // and we also want to restrict the minimum number of tickets by the ticket min setting
251
-        $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
-        // and if the ticket is required, then make sure that min qty is at least 1
253
-        $min = $this->ticket->required() ? max($min, 1) : $min;
254
-        return array($min, $max);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * getTicketPriceDetails
261
-     *
262
-     * @return array
263
-     * @throws EE_Error
264
-     */
265
-    protected function getTicketPriceDetails()
266
-    {
267
-        $ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
-            ? $this->ticket->get_ticket_total_with_taxes()
269
-            : $this->ticket->get_ticket_subtotal();
270
-        $ticket_bundle = false;
271
-        $ticket_min = $this->ticket->min();
272
-        // for ticket bundles, set min and max qty the same
273
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
-            $ticket_price *= $ticket_min;
275
-            $ticket_bundle = true;
276
-        }
277
-        $ticket_price = apply_filters(
278
-            'FHEE__ticket_selector_chart_template__ticket_price',
279
-            $ticket_price,
280
-            $this->ticket
281
-        );
282
-        return array($ticket_price, $ticket_bundle);
283
-    }
284
-
285
-
286
-
287
-
288
-    /**
289
-     * ticketNameTableCell
290
-     *
291
-     * @return string
292
-     * @throws EE_Error
293
-     */
294
-    protected function ticketNameTableCell()
295
-    {
296
-        $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
-        $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
-        $html .= $this->ticket_details->getShowHideLinks();
299
-        if ($this->ticket->required()) {
300
-            $html .= \EEH_HTML::p(
301
-                    apply_filters(
302
-                            'FHEE__ticket_selector_chart_template__ticket_required_message',
303
-                            esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
-                    ),
305
-                    '', 'ticket-required-pg'
306
-            );
307
-        }
308
-        $html .= \EEH_HTML::tdx();
309
-        return $html;
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * ticketPriceTableCell
316
-     *
317
-     * @param float $ticket_price
318
-     * @param bool  $ticket_bundle
319
-     * @return string
320
-     * @throws EE_Error
321
-     */
322
-    protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
-    {
324
-        $html = '';
325
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
-            $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
-            $html .= \EEH_Template::format_currency($ticket_price);
328
-            $html .= $this->ticket->taxable()
329
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
-                : '';
331
-            $html .= ' ';
332
-            $html .= \EEH_HTML::span(
333
-                $ticket_bundle
334
-                    ? apply_filters(
335
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
-                        __(' / bundle', 'event_espresso')
337
-                    )
338
-                    : apply_filters(
339
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
340
-                        __('', 'event_espresso')
341
-                    ),
342
-                '', 'smaller-text no-bold'
343
-            );
344
-            $html .= ' ';
345
-            $html .= \EEH_HTML::tdx();
346
-            $this->cols++;
347
-        }
348
-        return $html;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * onlyOneAttendeeCanRegister
355
-     *
356
-     * @return string
357
-     */
358
-    protected function onlyOneAttendeeCanRegister()
359
-    {
360
-        // display submit button since we have tickets available
361
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
-        $this->hidden_input_qty = false;
363
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
-        $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
-        $html .= ' title=""/>';
368
-        return $html;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * ticketQuantitySelector
375
-     *
376
-     * @param int $min
377
-     * @param int $max
378
-     * @return string
379
-     * @throws EE_Error
380
-     */
381
-    protected function ticketQuantitySelector($min = 0, $max = 0)
382
-    {
383
-        // display submit button since we have tickets available
384
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
-        $this->hidden_input_qty = false;
386
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
-        $html .= ' class="ticket-selector-tbl-qty-slct">';
389
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
-        if ($min !== 0 && ! $this->ticket->required()) {
391
-            $html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
-        }
393
-        // offer ticket quantities from the min to the max
394
-        for ($i = $min; $i <= $max; $i++) {
395
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
-        }
397
-        $html .= '</select>';
398
-        return $html;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * getHiddenInputs
405
-     *
406
-     * @return string
407
-     * @throws EE_Error
408
-     */
409
-    protected function ticketQtyAndIdHiddenInputs()
410
-    {
411
-        $html = '';
412
-        // depending on group reg we need to change the format for qty
413
-        if ($this->hidden_input_qty) {
414
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
-        }
416
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
418
-        return $html;
419
-    }
22
+	/**
23
+	 * @var TicketDetails $ticket_details
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var \EE_Ticket_Selector_Config $template_settings
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var \EE_Tax_Config $tax_settings
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var boolean $prices_displayed_including_taxes
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int $row
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int $cols
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean $hidden_input_qty
54
+	 */
55
+	protected $hidden_input_qty;
56
+
57
+	/**
58
+	 * @var string $ticket_datetime_classes
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+
64
+	/**
65
+	 * TicketDetails constructor.
66
+	 *
67
+	 * @param TicketDetails  $ticket_details
68
+	 * @param \EE_Tax_Config $tax_settings
69
+	 * @param int            $total_tickets
70
+	 * @param int            $max_atndz
71
+	 * @param int            $row
72
+	 * @param int            $cols
73
+	 * @param boolean        $required_ticket_sold_out
74
+	 * @param string         $event_status
75
+	 * @param string         $ticket_datetime_classes
76
+	 * @throws EE_Error
77
+	 * @throws UnexpectedEntityException
78
+	 */
79
+	public function __construct(
80
+		TicketDetails $ticket_details,
81
+		\EE_Tax_Config $tax_settings,
82
+		$total_tickets,
83
+		$max_atndz,
84
+		$row,
85
+		$cols,
86
+		$required_ticket_sold_out,
87
+		$event_status,
88
+		$ticket_datetime_classes
89
+	) {
90
+		$this->ticket = $ticket_details->getTicket();
91
+		$this->ticket_details = $ticket_details;
92
+		$this->template_settings = $ticket_details->getTemplateSettings();
93
+		$this->tax_settings = $tax_settings;
94
+		$this->total_tickets = $total_tickets;
95
+		$this->max_atndz = $max_atndz;
96
+		$this->row = $row;
97
+		$this->cols = $cols;
98
+		$this->date_format = $ticket_details->getDateFormat();
99
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
100
+		parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * other ticket rows will need to know if a required ticket is sold out,
107
+	 * so that they are not offered for sale
108
+	 *
109
+	 * @return boolean
110
+	 */
111
+	public function getRequiredTicketSoldOut()
112
+	{
113
+		return $this->required_ticket_sold_out;
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * getHtml
130
+	 *
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$min = 0;
137
+		$max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
+			list($min, $max) = $this->setTicketMinAndMax($remaining);
141
+		} else {
142
+			// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
+			$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
+				? $this->ticket->start_date()
145
+				: $this->required_ticket_sold_out;
146
+		}
147
+		list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
+		list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
+		/**
150
+		 * Allow plugins to hook in and abort the generation and display of this row to do
151
+		 * something else if they want.
152
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
153
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
+		 * current row.
155
+		 *
156
+		 * @var string|bool
157
+		 */
158
+		$ticket_selector_row_html = apply_filters(
159
+			'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
+			false,
161
+			$this->ticket,
162
+			$max,
163
+			$min,
164
+			$this->required_ticket_sold_out,
165
+			$ticket_price,
166
+			$ticket_bundle,
167
+			$ticket_status,
168
+			$status_class
169
+		);
170
+		if ($ticket_selector_row_html !== false) {
171
+			return $ticket_selector_row_html;
172
+		}
173
+		$ticket_selector_row_html = \EEH_HTML::tr(
174
+			'', '',
175
+			"tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
+		);
177
+		/**
178
+		 * Allow plugins to hook in and abort the generation and display of the contents of this
179
+		 * row to do something else if they want.
180
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
181
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
+		 * current row.
183
+		 *
184
+		 * @var string|bool
185
+		 */
186
+		$new_row_cells_content = apply_filters(
187
+			'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
+			false,
189
+			$this->ticket,
190
+			$max,
191
+			$min,
192
+			$this->required_ticket_sold_out,
193
+			$ticket_price,
194
+			$ticket_bundle,
195
+			$ticket_status,
196
+			$status_class
197
+		);
198
+		if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
+			return $ticket_selector_row_html
200
+				   . $new_row_cells_content
201
+				   . $this->ticketQtyAndIdHiddenInputs()
202
+				   . \EEH_HTML::trx();
203
+		}
204
+		if ($new_row_cells_content !== false) {
205
+			return $ticket_selector_row_html
206
+				   . $new_row_cells_content
207
+				   . \EEH_HTML::trx();
208
+		}
209
+		$this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
+
211
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
212
+		$ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
+		$ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
+		if (empty($this->ticket_status_display)) {
216
+			if ($this->max_atndz === 1) {
217
+				// only ONE attendee is allowed to register at a time
218
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
+			} else if ($max > 0) {
220
+				$ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
+			}
222
+		}
223
+		$ticket_selector_row_html .= $this->ticket_status_display;
224
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
+		$ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
+		$ticket_selector_row_html .= \EEH_HTML::tdx();
227
+		$ticket_selector_row_html .= \EEH_HTML::trx();
228
+
229
+
230
+		$this->row++;
231
+		return $ticket_selector_row_html;
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * setTicketMinAndMax
238
+	 *
239
+	 * @param int $remaining
240
+	 * @return array
241
+	 * @throws EE_Error
242
+	 */
243
+	protected function setTicketMinAndMax($remaining)
244
+	{
245
+		// offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
+		$max = min($remaining, $this->max_atndz);
247
+		// but... we also want to restrict the number of tickets by the ticket max setting,
248
+		// however, the max still can't be higher than what was just set above
249
+		$max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
+		// and we also want to restrict the minimum number of tickets by the ticket min setting
251
+		$min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
+		// and if the ticket is required, then make sure that min qty is at least 1
253
+		$min = $this->ticket->required() ? max($min, 1) : $min;
254
+		return array($min, $max);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * getTicketPriceDetails
261
+	 *
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 */
265
+	protected function getTicketPriceDetails()
266
+	{
267
+		$ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
+			? $this->ticket->get_ticket_total_with_taxes()
269
+			: $this->ticket->get_ticket_subtotal();
270
+		$ticket_bundle = false;
271
+		$ticket_min = $this->ticket->min();
272
+		// for ticket bundles, set min and max qty the same
273
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
+			$ticket_price *= $ticket_min;
275
+			$ticket_bundle = true;
276
+		}
277
+		$ticket_price = apply_filters(
278
+			'FHEE__ticket_selector_chart_template__ticket_price',
279
+			$ticket_price,
280
+			$this->ticket
281
+		);
282
+		return array($ticket_price, $ticket_bundle);
283
+	}
284
+
285
+
286
+
287
+
288
+	/**
289
+	 * ticketNameTableCell
290
+	 *
291
+	 * @return string
292
+	 * @throws EE_Error
293
+	 */
294
+	protected function ticketNameTableCell()
295
+	{
296
+		$html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
+		$html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
+		$html .= $this->ticket_details->getShowHideLinks();
299
+		if ($this->ticket->required()) {
300
+			$html .= \EEH_HTML::p(
301
+					apply_filters(
302
+							'FHEE__ticket_selector_chart_template__ticket_required_message',
303
+							esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
+					),
305
+					'', 'ticket-required-pg'
306
+			);
307
+		}
308
+		$html .= \EEH_HTML::tdx();
309
+		return $html;
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * ticketPriceTableCell
316
+	 *
317
+	 * @param float $ticket_price
318
+	 * @param bool  $ticket_bundle
319
+	 * @return string
320
+	 * @throws EE_Error
321
+	 */
322
+	protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
+	{
324
+		$html = '';
325
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
+			$html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
+			$html .= \EEH_Template::format_currency($ticket_price);
328
+			$html .= $this->ticket->taxable()
329
+				? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
+				: '';
331
+			$html .= '&nbsp;';
332
+			$html .= \EEH_HTML::span(
333
+				$ticket_bundle
334
+					? apply_filters(
335
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
+						__(' / bundle', 'event_espresso')
337
+					)
338
+					: apply_filters(
339
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
340
+						__('', 'event_espresso')
341
+					),
342
+				'', 'smaller-text no-bold'
343
+			);
344
+			$html .= '&nbsp;';
345
+			$html .= \EEH_HTML::tdx();
346
+			$this->cols++;
347
+		}
348
+		return $html;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * onlyOneAttendeeCanRegister
355
+	 *
356
+	 * @return string
357
+	 */
358
+	protected function onlyOneAttendeeCanRegister()
359
+	{
360
+		// display submit button since we have tickets available
361
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
+		$this->hidden_input_qty = false;
363
+		$html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
+		$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
+		$html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
+		$html .= ' title=""/>';
368
+		return $html;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * ticketQuantitySelector
375
+	 *
376
+	 * @param int $min
377
+	 * @param int $max
378
+	 * @return string
379
+	 * @throws EE_Error
380
+	 */
381
+	protected function ticketQuantitySelector($min = 0, $max = 0)
382
+	{
383
+		// display submit button since we have tickets available
384
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
+		$this->hidden_input_qty = false;
386
+		$html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
+		$html .= ' class="ticket-selector-tbl-qty-slct">';
389
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
+		if ($min !== 0 && ! $this->ticket->required()) {
391
+			$html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
+		}
393
+		// offer ticket quantities from the min to the max
394
+		for ($i = $min; $i <= $max; $i++) {
395
+			$html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
+		}
397
+		$html .= '</select>';
398
+		return $html;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * getHiddenInputs
405
+	 *
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 */
409
+	protected function ticketQtyAndIdHiddenInputs()
410
+	{
411
+		$html = '';
412
+		// depending on group reg we need to change the format for qty
413
+		if ($this->hidden_input_qty) {
414
+			$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
+		}
416
+		$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
+		$html .= ' value="' . $this->ticket->ID() . '"/>';
418
+		return $html;
419
+	}
420 420
 
421 421
 }
422 422
 // End of file TicketSelectorRowStandard.php
Please login to merge, or discard this patch.
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.
espresso_ticket_selector/EES_Espresso_Ticket_Selector.shortcode.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 * @access    public
51 51
 	 * @param \WP $WP
52 52
 	 */
53
-	public function run( WP $WP ) {
54
-		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
53
+	public function run(WP $WP) {
54
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
55 55
 	}
56 56
 
57 57
 
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
 	 *  @param		array 	$attributes
63 63
 	 *  @return 	string
64 64
 	 */
65
-	public function process_shortcode( $attributes = array() ) {
66
-		extract( $attributes );
67
-		$event_id = isset( $event_id ) ? $event_id : 0;
68
-		$event = EE_Registry::instance()->load_model( 'Event' )->get_one_by_ID( $event_id );
65
+	public function process_shortcode($attributes = array()) {
66
+		extract($attributes);
67
+		$event_id = isset($event_id) ? $event_id : 0;
68
+		$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
69 69
 		ob_start();
70
-		do_action( 'AHEE__EES_Espresso_Ticket_Selector__process_shortcode__begin', $event_id );
71
-		espresso_ticket_selector( $event );
72
-		do_action( 'AHEE__EES_Espresso_Ticket_Selector__process_shortcode__end', $event_id );
70
+		do_action('AHEE__EES_Espresso_Ticket_Selector__process_shortcode__begin', $event_id);
71
+		espresso_ticket_selector($event);
72
+		do_action('AHEE__EES_Espresso_Ticket_Selector__process_shortcode__end', $event_id);
73 73
 		return ob_get_clean();
74 74
 	}
75 75
 
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.
Indentation   +946 added lines, -946 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,952 +21,952 @@  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
-        // release tickets for expired carts
67
-        add_action('EED_Ticket_Selector__process_ticket_selections__before',
68
-            array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
69
-            1
70
-        );
71
-        // check ticket reserves AFTER MER does it's check (hence priority 20)
72
-        add_filter('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
73
-            array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
74
-            20, 3
75
-        );
76
-        // add notices for sold out tickets
77
-        add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
78
-            array('EED_Ticket_Sales_Monitor', 'post_notices'),
79
-            10
80
-        );
81
-        // handle ticket quantities adjusted in cart
82
-        //add_action(
83
-        //	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
84
-        //	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
85
-        //	10, 2
86
-        //);
87
-        // handle tickets deleted from cart
88
-        add_action(
89
-            'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
90
-            array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
91
-            10, 2
92
-        );
93
-        // handle emptied carts
94
-        add_action(
95
-            'AHEE__EE_Session__reset_cart__before_reset',
96
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
97
-            10, 1
98
-        );
99
-        add_action(
100
-            'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
101
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
102
-            10, 1
103
-        );
104
-        // handle cancelled registrations
105
-        add_action(
106
-            'AHEE__EE_Session__reset_checkout__before_reset',
107
-            array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
108
-            10, 1
109
-        );
110
-        // cron tasks
111
-        add_action(
112
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_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__incomplete_transaction',
118
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
119
-            10, 1
120
-        );
121
-        add_action(
122
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
123
-            array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
124
-            10, 1
125
-        );
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
132
-     *
133
-     * @access    public
134
-     * @return    void
135
-     */
136
-    public static function set_hooks_admin()
137
-    {
138
-        EED_Ticket_Sales_Monitor::set_hooks();
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * @return EED_Ticket_Sales_Monitor|EED_Module
145
-     */
146
-    public static function instance()
147
-    {
148
-        return parent::get_instance(__CLASS__);
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     *    run
155
-     *
156
-     * @access    public
157
-     * @param WP_Query $WP_Query
158
-     * @return    void
159
-     */
160
-    public function run($WP_Query)
161
-    {
162
-    }
163
-
164
-
165
-
166
-    /********************************** PRE_TICKET_SALES  **********************************/
167
-
168
-
169
-
170
-    /**
171
-     * Retrieves grand totals from the line items that have no TXN ID
172
-     * and timestamps less than the current time minus the session lifespan.
173
-     * These are carts that have been abandoned before the "registrant" even attempted to checkout.
174
-     * We're going to release the tickets for these line items before attempting to add more to the cart.
175
-     *
176
-     * @return void
177
-     * @throws \EE_Error
178
-     */
179
-    public static function release_tickets_for_expired_carts()
180
-    {
181
-        $expired_ticket_IDs = array();
182
-        $valid_ticket_line_items = array();
183
-        $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
184
-        if(empty($total_line_items)){
185
-            return;
186
-        }
187
-        $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
188
-        foreach ($total_line_items as $total_line_item) {
189
-            /** @var EE_Line_Item $total_line_item */
190
-            $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
191
-            foreach ($ticket_line_items as $ticket_line_item) {
192
-                if(! $ticket_line_item instanceof EE_Line_Item) {
193
-                    continue;
194
-                }
195
-                if ($total_line_item->timestamp(true) <= $expired ) {
196
-                    $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID();
197
-                } else {
198
-                    $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item;
199
-                }
200
-            }
201
-        }
202
-        if (! empty($expired_ticket_IDs)) {
203
-            EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
204
-                \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
205
-                $valid_ticket_line_items
206
-            );
207
-            // let's get rid of expired line items so that they can't interfere with tracking
208
-            add_action(
209
-                'shutdown',
210
-                array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'),
211
-                999
212
-            );
213
-        }
214
-    }
215
-
216
-
217
-
218
-    /********************************** VALIDATE_TICKET_SALE  **********************************/
219
-
220
-
221
-
222
-    /**
223
-     *    validate_ticket_sales
224
-     *    callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
225
-     *
226
-     * @access    public
227
-     * @param int $qty
228
-     * @param \EE_Ticket $ticket
229
-     * @return bool
230
-     * @throws UnexpectedEntityException
231
-     * @throws EE_Error
232
-     */
233
-    public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
234
-    {
235
-        $qty = absint($qty);
236
-        if ($qty > 0) {
237
-            $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
238
-        }
239
-        if (self::debug) {
240
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
241
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
242
-        }
243
-        return $qty;
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     *    _validate_ticket_sale
250
-     * checks whether an individual ticket is available for purchase based on datetime, and ticket details
251
-     *
252
-     * @access    protected
253
-     * @param   \EE_Ticket $ticket
254
-     * @param int          $qty
255
-     * @return int
256
-     * @throws UnexpectedEntityException
257
-     * @throws EE_Error
258
-     */
259
-    protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
260
-    {
261
-        if (self::debug) {
262
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
263
-        }
264
-        if ( ! $ticket instanceof EE_Ticket) {
265
-            return 0;
266
-        }
267
-        if (self::debug) {
268
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
269
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
270
-        }
271
-        $ticket->refresh_from_db();
272
-        // first let's determine the ticket availability based on sales
273
-        $available = $ticket->qty('saleable');
274
-        if (self::debug) {
275
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
276
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
277
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
278
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
279
-            echo '<br /> . . . available: ' . $available;
280
-        }
281
-        if ($available < 1) {
282
-            $this->_ticket_sold_out($ticket);
283
-            return 0;
284
-        }
285
-        if (self::debug) {
286
-            echo '<br /> . . . qty: ' . $qty;
287
-        }
288
-        if ($available < $qty) {
289
-            $qty = $available;
290
-            if (self::debug) {
291
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
292
-            }
293
-            $this->_ticket_quantity_decremented($ticket);
294
-        }
295
-        $this->_reserve_ticket($ticket, $qty);
296
-        return $qty;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     *  _reserve_ticket
303
-     *    increments ticket reserved based on quantity passed
304
-     *
305
-     * @access    protected
306
-     * @param    \EE_Ticket $ticket
307
-     * @param int           $quantity
308
-     * @return bool
309
-     * @throws EE_Error
310
-     */
311
-    protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
312
-    {
313
-        if (self::debug) {
314
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
315
-        }
316
-        $ticket->increase_reserved($quantity);
317
-        return $ticket->save();
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * _release_reserved_ticket
324
-     *
325
-     * @access protected
326
-     * @param  EE_Ticket $ticket
327
-     * @param  int       $quantity
328
-     * @return bool
329
-     * @throws EE_Error
330
-     */
331
-    protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
332
-    {
333
-        if (self::debug) {
334
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
335
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
336
-        }
337
-        $ticket->decrease_reserved($quantity);
338
-        if (self::debug) {
339
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
340
-        }
341
-        return $ticket->save() ? 1 : 0;
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     *    _ticket_sold_out
348
-     *    removes quantities within the ticket selector based on zero ticket availability
349
-     *
350
-     * @access    protected
351
-     * @param    \EE_Ticket $ticket
352
-     * @return    void
353
-     * @throws UnexpectedEntityException
354
-     * @throws EE_Error
355
-     */
356
-    protected function _ticket_sold_out(EE_Ticket $ticket)
357
-    {
358
-        if (self::debug) {
359
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
360
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
361
-        }
362
-        $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     *    _ticket_quantity_decremented
369
-     *    adjusts quantities within the ticket selector based on decreased ticket availability
370
-     *
371
-     * @access    protected
372
-     * @param    \EE_Ticket $ticket
373
-     * @return void
374
-     * @throws UnexpectedEntityException
375
-     * @throws EE_Error
376
-     */
377
-    protected function _ticket_quantity_decremented(EE_Ticket $ticket)
378
-    {
379
-        if (self::debug) {
380
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
381
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
382
-        }
383
-        $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     *    _get_ticket_and_event_name
390
-     *    builds string out of ticket and event name
391
-     *
392
-     * @access    protected
393
-     * @param    \EE_Ticket $ticket
394
-     * @return string
395
-     * @throws UnexpectedEntityException
396
-     * @throws EE_Error
397
-     */
398
-    protected function _get_ticket_and_event_name(EE_Ticket $ticket)
399
-    {
400
-        $event = $ticket->get_related_event();
401
-        if ($event instanceof EE_Event) {
402
-            $ticket_name = sprintf(
403
-                _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
404
-                $ticket->name(),
405
-                $event->name()
406
-            );
407
-        } else {
408
-            $ticket_name = $ticket->name();
409
-        }
410
-        return $ticket_name;
411
-    }
412
-
413
-
414
-
415
-    /********************************** EVENT CART  **********************************/
416
-
417
-
418
-
419
-    /**
420
-     * ticket_quantity_updated
421
-     * releases or reserves ticket(s) based on quantity passed
422
-     *
423
-     * @access public
424
-     * @param  EE_Line_Item $line_item
425
-     * @param  int          $quantity
426
-     * @return void
427
-     * @throws EE_Error
428
-     */
429
-    public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
430
-    {
431
-        $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
432
-        if ($ticket instanceof EE_Ticket) {
433
-            if ($quantity > 0) {
434
-                EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
435
-            } else {
436
-                EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
437
-            }
438
-        }
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * ticket_removed_from_cart
445
-     * releases reserved ticket(s) based on quantity passed
446
-     *
447
-     * @access public
448
-     * @param  EE_Ticket $ticket
449
-     * @param  int       $quantity
450
-     * @return void
451
-     * @throws EE_Error
452
-     */
453
-    public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
454
-    {
455
-        EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
456
-    }
457
-
458
-
459
-
460
-    /********************************** POST_NOTICES  **********************************/
461
-
462
-
463
-
464
-    /**
465
-     *    post_notices
466
-     *
467
-     * @access    public
468
-     * @return    void
469
-     * @throws EE_Error
470
-     */
471
-    public static function post_notices()
472
-    {
473
-        EED_Ticket_Sales_Monitor::instance()->_post_notices();
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     *    _post_notices
480
-     *
481
-     * @access    protected
482
-     * @return    void
483
-     * @throws EE_Error
484
-     */
485
-    protected function _post_notices()
486
-    {
487
-        if (self::debug) {
488
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
489
-        }
490
-        $refresh_msg = '';
491
-        $none_added_msg = '';
492
-        if (defined('DOING_AJAX') && DOING_AJAX) {
493
-            $refresh_msg = __('Please refresh the page to view updated ticket quantities.',
494
-                'event_espresso');
495
-            $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
496
-        }
497
-        if ( ! empty($this->sold_out_tickets)) {
498
-            EE_Error::add_attention(
499
-                sprintf(
500
-                    apply_filters(
501
-                        'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
502
-                        __('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',
503
-                            'event_espresso')
504
-                    ),
505
-                    '<br />',
506
-                    implode('<br />', $this->sold_out_tickets),
507
-                    $none_added_msg,
508
-                    $refresh_msg
509
-                )
510
-            );
511
-            // alter code flow in the Ticket Selector for better UX
512
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
513
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
514
-            $this->sold_out_tickets = array();
515
-            // and reset the cart
516
-            EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
517
-        }
518
-        if ( ! empty($this->decremented_tickets)) {
519
-            EE_Error::add_attention(
520
-                sprintf(
521
-                    apply_filters(
522
-                        'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
523
-                        __('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',
524
-                            'event_espresso')
525
-                    ),
526
-                    '<br />',
527
-                    implode('<br />', $this->decremented_tickets),
528
-                    $none_added_msg,
529
-                    $refresh_msg
530
-                )
531
-            );
532
-            $this->decremented_tickets = array();
533
-        }
534
-    }
535
-
536
-
537
-
538
-    /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
539
-
540
-
541
-
542
-    /**
543
-     *    _release_all_reserved_tickets_for_transaction
544
-     *    releases reserved tickets for all registrations of an EE_Transaction
545
-     *    by default, will NOT release tickets for finalized transactions
546
-     *
547
-     * @access    protected
548
-     * @param    EE_Transaction $transaction
549
-     * @return int
550
-     * @throws EE_Error
551
-     */
552
-    protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
553
-    {
554
-        if (self::debug) {
555
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
556
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
557
-        }
558
-        // check if 'finalize_registration' step has been completed...
559
-        $finalized = $transaction->reg_step_completed('finalize_registration');
560
-        if (self::debug) {
561
-            // DEBUG LOG
562
-            EEH_Debug_Tools::log(
563
-                __CLASS__, __FUNCTION__, __LINE__,
564
-                array('finalized' => $finalized),
565
-                false, 'EE_Transaction: ' . $transaction->ID()
566
-            );
567
-        }
568
-        // how many tickets were released
569
-        $count = 0;
570
-        if (self::debug) {
571
-            echo '<br /> . . . finalized: ' . $finalized;
572
-        }
573
-        $release_tickets_with_TXN_status = array(
574
-            EEM_Transaction::failed_status_code,
575
-            EEM_Transaction::abandoned_status_code,
576
-            EEM_Transaction::incomplete_status_code,
577
-        );
578
-        // if the session is getting cleared BEFORE the TXN has been finalized
579
-        if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
580
-            // let's cancel any reserved tickets
581
-            $registrations = $transaction->registrations();
582
-            if ( ! empty($registrations)) {
583
-                foreach ($registrations as $registration) {
584
-                    if ($registration instanceof EE_Registration) {
585
-                        $count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
586
-                    }
587
-                }
588
-            }
589
-        }
590
-        return $count;
591
-    }
592
-
593
-
594
-
595
-    /**
596
-     *    _release_reserved_ticket_for_registration
597
-     *    releases reserved tickets for an EE_Registration
598
-     *    by default, will NOT release tickets for APPROVED registrations
599
-     *
600
-     * @access    protected
601
-     * @param    EE_Registration $registration
602
-     * @param    EE_Transaction  $transaction
603
-     * @return    int
604
-     * @throws    EE_Error
605
-     */
606
-    protected function _release_reserved_ticket_for_registration(
607
-        EE_Registration $registration,
608
-        EE_Transaction $transaction
609
-    ) {
610
-        $STS_ID = $transaction->status_ID();
611
-        if (self::debug) {
612
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
613
-            echo '<br /> . . registration->ID: ' . $registration->ID();
614
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
615
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
616
-        }
617
-        if (
618
-            // release Tickets for Failed Transactions and Abandoned Transactions
619
-            $STS_ID === EEM_Transaction::failed_status_code
620
-            || $STS_ID === EEM_Transaction::abandoned_status_code
621
-            || (
622
-                // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
623
-                $STS_ID === EEM_Transaction::incomplete_status_code
624
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
625
-            )
626
-        ) {
627
-            $ticket = $registration->ticket();
628
-            if ($ticket instanceof EE_Ticket) {
629
-                return $this->_release_reserved_ticket($ticket);
630
-            }
631
-        }
632
-        return 0;
633
-    }
634
-
635
-
636
-
637
-    /********************************** SESSION_CART_RESET  **********************************/
638
-
639
-
640
-
641
-    /**
642
-     *    session_cart_reset
643
-     * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
644
-     *
645
-     * @access    public
646
-     * @param    EE_Session $session
647
-     * @return    void
648
-     * @throws EE_Error
649
-     */
650
-    public static function session_cart_reset(EE_Session $session)
651
-    {
652
-        if (self::debug) {
653
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
654
-        }
655
-        $cart = $session->cart();
656
-        if ($cart instanceof EE_Cart) {
657
-            if (self::debug) {
658
-                echo '<br /><br /> cart instance of EE_Cart: ';
659
-            }
660
-            EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart);
661
-        } else {
662
-            if (self::debug) {
663
-                echo '<br /><br /> invalid EE_Cart: ';
664
-                var_dump($cart);
665
-            }
666
-        }
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     *    _session_cart_reset
673
-     * releases reserved tickets in the EE_Cart
674
-     *
675
-     * @access    protected
676
-     * @param    EE_Cart $cart
677
-     * @return    void
678
-     * @throws EE_Error
679
-     */
680
-    protected function _session_cart_reset(EE_Cart $cart)
681
-    {
682
-        if (self::debug) {
683
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
684
-        }
685
-        EE_Registry::instance()->load_helper('Line_Item');
686
-        $ticket_line_items = $cart->get_tickets();
687
-        if (empty($ticket_line_items)) {
688
-            return;
689
-        }
690
-        foreach ($ticket_line_items as $ticket_line_item) {
691
-            if (self::debug) {
692
-                echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
693
-            }
694
-            if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
695
-                if (self::debug) {
696
-                    echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
697
-                }
698
-                $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
699
-                if ($ticket instanceof EE_Ticket) {
700
-                    if (self::debug) {
701
-                        echo '<br /> . . ticket->ID(): ' . $ticket->ID();
702
-                        echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
703
-                    }
704
-                    $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
705
-                }
706
-            }
707
-        }
708
-        if (self::debug) {
709
-            echo '<br /><br /> RESET COMPLETED ';
710
-        }
711
-    }
712
-
713
-
714
-
715
-    /********************************** SESSION_CHECKOUT_RESET  **********************************/
716
-
717
-
718
-
719
-    /**
720
-     *    session_checkout_reset
721
-     * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
722
-     *
723
-     * @access    public
724
-     * @param    EE_Session $session
725
-     * @return    void
726
-     * @throws EE_Error
727
-     */
728
-    public static function session_checkout_reset(EE_Session $session)
729
-    {
730
-        $checkout = $session->checkout();
731
-        if ($checkout instanceof EE_Checkout) {
732
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
733
-        }
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     *    _session_checkout_reset
740
-     * releases reserved tickets for the EE_Checkout->transaction
741
-     *
742
-     * @access    protected
743
-     * @param    EE_Checkout $checkout
744
-     * @return    void
745
-     * @throws EE_Error
746
-     */
747
-    protected function _session_checkout_reset(EE_Checkout $checkout)
748
-    {
749
-        if (self::debug) {
750
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
751
-        }
752
-        // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
753
-        if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
754
-            return;
755
-        }
756
-        $this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
757
-    }
758
-
759
-
760
-
761
-    /********************************** SESSION_EXPIRED_RESET  **********************************/
762
-
763
-
764
-
765
-    /**
766
-     *    session_expired_reset
767
-     *
768
-     * @access    public
769
-     * @param    EE_Session $session
770
-     * @return    void
771
-     */
772
-    public static function session_expired_reset(EE_Session $session)
773
-    {
774
-    }
775
-
776
-
777
-
778
-    /********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
779
-
780
-
781
-
782
-    /**
783
-     *    process_abandoned_transactions
784
-     *    releases reserved tickets for all registrations of an ABANDONED EE_Transaction
785
-     *    by default, will NOT release tickets for free transactions, or any that have received a payment
786
-     *
787
-     * @access    public
788
-     * @param    EE_Transaction $transaction
789
-     * @return    void
790
-     * @throws EE_Error
791
-     */
792
-    public static function process_abandoned_transactions(EE_Transaction $transaction)
793
-    {
794
-        // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
795
-        if ($transaction->is_free() || $transaction->paid() > 0) {
796
-            if (self::debug) {
797
-                // DEBUG LOG
798
-                EEH_Debug_Tools::log(
799
-                    __CLASS__, __FUNCTION__, __LINE__,
800
-                    array($transaction),
801
-                    false, 'EE_Transaction: ' . $transaction->ID()
802
-                );
803
-            }
804
-            return;
805
-        }
806
-        // have their been any successful payments made ?
807
-        $payments = $transaction->payments();
808
-        foreach ($payments as $payment) {
809
-            if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
810
-                if (self::debug) {
811
-                    // DEBUG LOG
812
-                    EEH_Debug_Tools::log(
813
-                        __CLASS__, __FUNCTION__, __LINE__,
814
-                        array($payment),
815
-                        false, 'EE_Transaction: ' . $transaction->ID()
816
-                    );
817
-                }
818
-                return;
819
-            }
820
-        }
821
-        // since you haven't even attempted to pay for your ticket...
822
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
823
-    }
824
-
825
-
826
-
827
-    /********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
828
-
829
-
830
-
831
-    /**
832
-     *    process_abandoned_transactions
833
-     *    releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
834
-     *
835
-     * @access    public
836
-     * @param    EE_Transaction $transaction
837
-     * @return    void
838
-     * @throws EE_Error
839
-     */
840
-    public static function process_failed_transactions(EE_Transaction $transaction)
841
-    {
842
-        // since you haven't even attempted to pay for your ticket...
843
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
844
-    }
845
-
846
-
847
-
848
-    /********************************** RESET RESERVATION COUNTS  *********************************/
849
-
850
-
851
-
852
-    /**
853
-     * Resets all ticket and datetime reserved counts to zero
854
-     * Tickets that are currently associated with a Transaction that is in progress
855
-     *
856
-     * @throws \EE_Error
857
-     * @throws \DomainException
858
-     */
859
-    public static function reset_reservation_counts()
860
-    {
861
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
862
-        $valid_reserved_tickets = array();
863
-        $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress();
864
-        foreach ($transactions_in_progress as $transaction_in_progress) {
865
-            // if this TXN has been fully completed, then skip it
866
-            if ($transaction_in_progress->reg_step_completed('finalize_registration')) {
867
-                continue;
868
-            }
869
-            /** @var EE_Transaction $transaction_in_progress */
870
-            $total_line_item = $transaction_in_progress->total_line_item();
871
-            // $transaction_in_progress->line
872
-            if (! $total_line_item instanceof EE_Line_Item) {
873
-                throw new DomainException(
874
-                    esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso')
875
-                );
876
-            }
877
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
878
-                $total_line_item
879
-            );
880
-        }
881
-        $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
882
-        foreach ($total_line_items as $total_line_item) {
883
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
884
-                $total_line_item
885
-            );
886
-        }
887
-        return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
888
-            EEM_Ticket::instance()->get_tickets_with_reservations(),
889
-            $valid_reserved_tickets
890
-        );
891
-    }
892
-
893
-
894
-
895
-    /**
896
-     * @param EE_Line_Item $total_line_item
897
-     * @return EE_Line_Item[]
898
-     */
899
-    private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
900
-    {
901
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
902
-        $valid_reserved_tickets = array();
903
-        $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
904
-        foreach ($ticket_line_items as $ticket_line_item) {
905
-            if ($ticket_line_item instanceof EE_Line_Item) {
906
-                $valid_reserved_tickets[] = $ticket_line_item;
907
-            }
908
-        }
909
-        return $valid_reserved_tickets;
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * @param EE_Ticket[] $tickets_with_reservations
916
-     * @param EE_Line_Item[] $valid_reserved_ticket_line_items
917
-     * @return int
918
-     * @throws \EE_Error
919
-     */
920
-    private static function release_reservations_for_tickets(
921
-        array $tickets_with_reservations,
922
-        $valid_reserved_ticket_line_items = array()
923
-    ) {
924
-        $total_tickets_released = 0;
925
-        foreach ($tickets_with_reservations as $ticket_with_reservations) {
926
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
927
-                continue;
928
-            }
929
-            $reserved_qty = $ticket_with_reservations->reserved();
930
-            foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
931
-                if (
932
-                    $valid_reserved_ticket_line_item instanceof EE_Line_Item
933
-                    && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
934
-                ) {
935
-                    $reserved_qty -= $valid_reserved_ticket_line_item->quantity();
936
-                }
937
-            }
938
-            if ($reserved_qty > 0) {
939
-                $ticket_with_reservations->decrease_reserved($reserved_qty);
940
-                $ticket_with_reservations->save();
941
-                $total_tickets_released += $reserved_qty;
942
-            }
943
-        }
944
-        return $total_tickets_released;
945
-    }
946
-
947
-
948
-
949
-    /********************************** SHUTDOWN  **********************************/
950
-
951
-
952
-
953
-    /**
954
-     * @return false|int
955
-     * @throws \EE_Error
956
-     */
957
-    public static function clear_expired_line_items_with_no_transaction()
958
-    {
959
-        /** @type WPDB $wpdb */
960
-        global $wpdb;
961
-        return $wpdb->query(
962
-            $wpdb->prepare(
963
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
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
+		// release tickets for expired carts
67
+		add_action('EED_Ticket_Selector__process_ticket_selections__before',
68
+			array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
69
+			1
70
+		);
71
+		// check ticket reserves AFTER MER does it's check (hence priority 20)
72
+		add_filter('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
73
+			array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
74
+			20, 3
75
+		);
76
+		// add notices for sold out tickets
77
+		add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
78
+			array('EED_Ticket_Sales_Monitor', 'post_notices'),
79
+			10
80
+		);
81
+		// handle ticket quantities adjusted in cart
82
+		//add_action(
83
+		//	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
84
+		//	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
85
+		//	10, 2
86
+		//);
87
+		// handle tickets deleted from cart
88
+		add_action(
89
+			'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
90
+			array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
91
+			10, 2
92
+		);
93
+		// handle emptied carts
94
+		add_action(
95
+			'AHEE__EE_Session__reset_cart__before_reset',
96
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
97
+			10, 1
98
+		);
99
+		add_action(
100
+			'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
101
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
102
+			10, 1
103
+		);
104
+		// handle cancelled registrations
105
+		add_action(
106
+			'AHEE__EE_Session__reset_checkout__before_reset',
107
+			array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
108
+			10, 1
109
+		);
110
+		// cron tasks
111
+		add_action(
112
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_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__incomplete_transaction',
118
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
119
+			10, 1
120
+		);
121
+		add_action(
122
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
123
+			array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
124
+			10, 1
125
+		);
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
132
+	 *
133
+	 * @access    public
134
+	 * @return    void
135
+	 */
136
+	public static function set_hooks_admin()
137
+	{
138
+		EED_Ticket_Sales_Monitor::set_hooks();
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * @return EED_Ticket_Sales_Monitor|EED_Module
145
+	 */
146
+	public static function instance()
147
+	{
148
+		return parent::get_instance(__CLASS__);
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 *    run
155
+	 *
156
+	 * @access    public
157
+	 * @param WP_Query $WP_Query
158
+	 * @return    void
159
+	 */
160
+	public function run($WP_Query)
161
+	{
162
+	}
163
+
164
+
165
+
166
+	/********************************** PRE_TICKET_SALES  **********************************/
167
+
168
+
169
+
170
+	/**
171
+	 * Retrieves grand totals from the line items that have no TXN ID
172
+	 * and timestamps less than the current time minus the session lifespan.
173
+	 * These are carts that have been abandoned before the "registrant" even attempted to checkout.
174
+	 * We're going to release the tickets for these line items before attempting to add more to the cart.
175
+	 *
176
+	 * @return void
177
+	 * @throws \EE_Error
178
+	 */
179
+	public static function release_tickets_for_expired_carts()
180
+	{
181
+		$expired_ticket_IDs = array();
182
+		$valid_ticket_line_items = array();
183
+		$total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
184
+		if(empty($total_line_items)){
185
+			return;
186
+		}
187
+		$expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
188
+		foreach ($total_line_items as $total_line_item) {
189
+			/** @var EE_Line_Item $total_line_item */
190
+			$ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
191
+			foreach ($ticket_line_items as $ticket_line_item) {
192
+				if(! $ticket_line_item instanceof EE_Line_Item) {
193
+					continue;
194
+				}
195
+				if ($total_line_item->timestamp(true) <= $expired ) {
196
+					$expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID();
197
+				} else {
198
+					$valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item;
199
+				}
200
+			}
201
+		}
202
+		if (! empty($expired_ticket_IDs)) {
203
+			EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
204
+				\EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
205
+				$valid_ticket_line_items
206
+			);
207
+			// let's get rid of expired line items so that they can't interfere with tracking
208
+			add_action(
209
+				'shutdown',
210
+				array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'),
211
+				999
212
+			);
213
+		}
214
+	}
215
+
216
+
217
+
218
+	/********************************** VALIDATE_TICKET_SALE  **********************************/
219
+
220
+
221
+
222
+	/**
223
+	 *    validate_ticket_sales
224
+	 *    callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
225
+	 *
226
+	 * @access    public
227
+	 * @param int $qty
228
+	 * @param \EE_Ticket $ticket
229
+	 * @return bool
230
+	 * @throws UnexpectedEntityException
231
+	 * @throws EE_Error
232
+	 */
233
+	public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
234
+	{
235
+		$qty = absint($qty);
236
+		if ($qty > 0) {
237
+			$qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
238
+		}
239
+		if (self::debug) {
240
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
241
+			echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
242
+		}
243
+		return $qty;
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 *    _validate_ticket_sale
250
+	 * checks whether an individual ticket is available for purchase based on datetime, and ticket details
251
+	 *
252
+	 * @access    protected
253
+	 * @param   \EE_Ticket $ticket
254
+	 * @param int          $qty
255
+	 * @return int
256
+	 * @throws UnexpectedEntityException
257
+	 * @throws EE_Error
258
+	 */
259
+	protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
260
+	{
261
+		if (self::debug) {
262
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
263
+		}
264
+		if ( ! $ticket instanceof EE_Ticket) {
265
+			return 0;
266
+		}
267
+		if (self::debug) {
268
+			echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
269
+			echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
270
+		}
271
+		$ticket->refresh_from_db();
272
+		// first let's determine the ticket availability based on sales
273
+		$available = $ticket->qty('saleable');
274
+		if (self::debug) {
275
+			echo '<br /> . . . ticket->qty: ' . $ticket->qty();
276
+			echo '<br /> . . . ticket->sold: ' . $ticket->sold();
277
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
278
+			echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
279
+			echo '<br /> . . . available: ' . $available;
280
+		}
281
+		if ($available < 1) {
282
+			$this->_ticket_sold_out($ticket);
283
+			return 0;
284
+		}
285
+		if (self::debug) {
286
+			echo '<br /> . . . qty: ' . $qty;
287
+		}
288
+		if ($available < $qty) {
289
+			$qty = $available;
290
+			if (self::debug) {
291
+				echo '<br /> . . . QTY ADJUSTED: ' . $qty;
292
+			}
293
+			$this->_ticket_quantity_decremented($ticket);
294
+		}
295
+		$this->_reserve_ticket($ticket, $qty);
296
+		return $qty;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 *  _reserve_ticket
303
+	 *    increments ticket reserved based on quantity passed
304
+	 *
305
+	 * @access    protected
306
+	 * @param    \EE_Ticket $ticket
307
+	 * @param int           $quantity
308
+	 * @return bool
309
+	 * @throws EE_Error
310
+	 */
311
+	protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
312
+	{
313
+		if (self::debug) {
314
+			echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
315
+		}
316
+		$ticket->increase_reserved($quantity);
317
+		return $ticket->save();
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * _release_reserved_ticket
324
+	 *
325
+	 * @access protected
326
+	 * @param  EE_Ticket $ticket
327
+	 * @param  int       $quantity
328
+	 * @return bool
329
+	 * @throws EE_Error
330
+	 */
331
+	protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
332
+	{
333
+		if (self::debug) {
334
+			echo '<br /> . . . ticket->ID: ' . $ticket->ID();
335
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
336
+		}
337
+		$ticket->decrease_reserved($quantity);
338
+		if (self::debug) {
339
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
340
+		}
341
+		return $ticket->save() ? 1 : 0;
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 *    _ticket_sold_out
348
+	 *    removes quantities within the ticket selector based on zero ticket availability
349
+	 *
350
+	 * @access    protected
351
+	 * @param    \EE_Ticket $ticket
352
+	 * @return    void
353
+	 * @throws UnexpectedEntityException
354
+	 * @throws EE_Error
355
+	 */
356
+	protected function _ticket_sold_out(EE_Ticket $ticket)
357
+	{
358
+		if (self::debug) {
359
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
360
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
361
+		}
362
+		$this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 *    _ticket_quantity_decremented
369
+	 *    adjusts quantities within the ticket selector based on decreased ticket availability
370
+	 *
371
+	 * @access    protected
372
+	 * @param    \EE_Ticket $ticket
373
+	 * @return void
374
+	 * @throws UnexpectedEntityException
375
+	 * @throws EE_Error
376
+	 */
377
+	protected function _ticket_quantity_decremented(EE_Ticket $ticket)
378
+	{
379
+		if (self::debug) {
380
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
381
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
382
+		}
383
+		$this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 *    _get_ticket_and_event_name
390
+	 *    builds string out of ticket and event name
391
+	 *
392
+	 * @access    protected
393
+	 * @param    \EE_Ticket $ticket
394
+	 * @return string
395
+	 * @throws UnexpectedEntityException
396
+	 * @throws EE_Error
397
+	 */
398
+	protected function _get_ticket_and_event_name(EE_Ticket $ticket)
399
+	{
400
+		$event = $ticket->get_related_event();
401
+		if ($event instanceof EE_Event) {
402
+			$ticket_name = sprintf(
403
+				_x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
404
+				$ticket->name(),
405
+				$event->name()
406
+			);
407
+		} else {
408
+			$ticket_name = $ticket->name();
409
+		}
410
+		return $ticket_name;
411
+	}
412
+
413
+
414
+
415
+	/********************************** EVENT CART  **********************************/
416
+
417
+
418
+
419
+	/**
420
+	 * ticket_quantity_updated
421
+	 * releases or reserves ticket(s) based on quantity passed
422
+	 *
423
+	 * @access public
424
+	 * @param  EE_Line_Item $line_item
425
+	 * @param  int          $quantity
426
+	 * @return void
427
+	 * @throws EE_Error
428
+	 */
429
+	public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
430
+	{
431
+		$ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
432
+		if ($ticket instanceof EE_Ticket) {
433
+			if ($quantity > 0) {
434
+				EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
435
+			} else {
436
+				EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
437
+			}
438
+		}
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * ticket_removed_from_cart
445
+	 * releases reserved ticket(s) based on quantity passed
446
+	 *
447
+	 * @access public
448
+	 * @param  EE_Ticket $ticket
449
+	 * @param  int       $quantity
450
+	 * @return void
451
+	 * @throws EE_Error
452
+	 */
453
+	public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
454
+	{
455
+		EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
456
+	}
457
+
458
+
459
+
460
+	/********************************** POST_NOTICES  **********************************/
461
+
462
+
463
+
464
+	/**
465
+	 *    post_notices
466
+	 *
467
+	 * @access    public
468
+	 * @return    void
469
+	 * @throws EE_Error
470
+	 */
471
+	public static function post_notices()
472
+	{
473
+		EED_Ticket_Sales_Monitor::instance()->_post_notices();
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 *    _post_notices
480
+	 *
481
+	 * @access    protected
482
+	 * @return    void
483
+	 * @throws EE_Error
484
+	 */
485
+	protected function _post_notices()
486
+	{
487
+		if (self::debug) {
488
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
489
+		}
490
+		$refresh_msg = '';
491
+		$none_added_msg = '';
492
+		if (defined('DOING_AJAX') && DOING_AJAX) {
493
+			$refresh_msg = __('Please refresh the page to view updated ticket quantities.',
494
+				'event_espresso');
495
+			$none_added_msg = __('No tickets were added for the event.', 'event_espresso');
496
+		}
497
+		if ( ! empty($this->sold_out_tickets)) {
498
+			EE_Error::add_attention(
499
+				sprintf(
500
+					apply_filters(
501
+						'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
502
+						__('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',
503
+							'event_espresso')
504
+					),
505
+					'<br />',
506
+					implode('<br />', $this->sold_out_tickets),
507
+					$none_added_msg,
508
+					$refresh_msg
509
+				)
510
+			);
511
+			// alter code flow in the Ticket Selector for better UX
512
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
513
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
514
+			$this->sold_out_tickets = array();
515
+			// and reset the cart
516
+			EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
517
+		}
518
+		if ( ! empty($this->decremented_tickets)) {
519
+			EE_Error::add_attention(
520
+				sprintf(
521
+					apply_filters(
522
+						'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
523
+						__('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',
524
+							'event_espresso')
525
+					),
526
+					'<br />',
527
+					implode('<br />', $this->decremented_tickets),
528
+					$none_added_msg,
529
+					$refresh_msg
530
+				)
531
+			);
532
+			$this->decremented_tickets = array();
533
+		}
534
+	}
535
+
536
+
537
+
538
+	/********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
539
+
540
+
541
+
542
+	/**
543
+	 *    _release_all_reserved_tickets_for_transaction
544
+	 *    releases reserved tickets for all registrations of an EE_Transaction
545
+	 *    by default, will NOT release tickets for finalized transactions
546
+	 *
547
+	 * @access    protected
548
+	 * @param    EE_Transaction $transaction
549
+	 * @return int
550
+	 * @throws EE_Error
551
+	 */
552
+	protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
553
+	{
554
+		if (self::debug) {
555
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
556
+			echo '<br /> . transaction->ID: ' . $transaction->ID();
557
+		}
558
+		// check if 'finalize_registration' step has been completed...
559
+		$finalized = $transaction->reg_step_completed('finalize_registration');
560
+		if (self::debug) {
561
+			// DEBUG LOG
562
+			EEH_Debug_Tools::log(
563
+				__CLASS__, __FUNCTION__, __LINE__,
564
+				array('finalized' => $finalized),
565
+				false, 'EE_Transaction: ' . $transaction->ID()
566
+			);
567
+		}
568
+		// how many tickets were released
569
+		$count = 0;
570
+		if (self::debug) {
571
+			echo '<br /> . . . finalized: ' . $finalized;
572
+		}
573
+		$release_tickets_with_TXN_status = array(
574
+			EEM_Transaction::failed_status_code,
575
+			EEM_Transaction::abandoned_status_code,
576
+			EEM_Transaction::incomplete_status_code,
577
+		);
578
+		// if the session is getting cleared BEFORE the TXN has been finalized
579
+		if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
580
+			// let's cancel any reserved tickets
581
+			$registrations = $transaction->registrations();
582
+			if ( ! empty($registrations)) {
583
+				foreach ($registrations as $registration) {
584
+					if ($registration instanceof EE_Registration) {
585
+						$count += $this->_release_reserved_ticket_for_registration($registration, $transaction);
586
+					}
587
+				}
588
+			}
589
+		}
590
+		return $count;
591
+	}
592
+
593
+
594
+
595
+	/**
596
+	 *    _release_reserved_ticket_for_registration
597
+	 *    releases reserved tickets for an EE_Registration
598
+	 *    by default, will NOT release tickets for APPROVED registrations
599
+	 *
600
+	 * @access    protected
601
+	 * @param    EE_Registration $registration
602
+	 * @param    EE_Transaction  $transaction
603
+	 * @return    int
604
+	 * @throws    EE_Error
605
+	 */
606
+	protected function _release_reserved_ticket_for_registration(
607
+		EE_Registration $registration,
608
+		EE_Transaction $transaction
609
+	) {
610
+		$STS_ID = $transaction->status_ID();
611
+		if (self::debug) {
612
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
613
+			echo '<br /> . . registration->ID: ' . $registration->ID();
614
+			echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
615
+			echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
616
+		}
617
+		if (
618
+			// release Tickets for Failed Transactions and Abandoned Transactions
619
+			$STS_ID === EEM_Transaction::failed_status_code
620
+			|| $STS_ID === EEM_Transaction::abandoned_status_code
621
+			|| (
622
+				// also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
623
+				$STS_ID === EEM_Transaction::incomplete_status_code
624
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
625
+			)
626
+		) {
627
+			$ticket = $registration->ticket();
628
+			if ($ticket instanceof EE_Ticket) {
629
+				return $this->_release_reserved_ticket($ticket);
630
+			}
631
+		}
632
+		return 0;
633
+	}
634
+
635
+
636
+
637
+	/********************************** SESSION_CART_RESET  **********************************/
638
+
639
+
640
+
641
+	/**
642
+	 *    session_cart_reset
643
+	 * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
644
+	 *
645
+	 * @access    public
646
+	 * @param    EE_Session $session
647
+	 * @return    void
648
+	 * @throws EE_Error
649
+	 */
650
+	public static function session_cart_reset(EE_Session $session)
651
+	{
652
+		if (self::debug) {
653
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
654
+		}
655
+		$cart = $session->cart();
656
+		if ($cart instanceof EE_Cart) {
657
+			if (self::debug) {
658
+				echo '<br /><br /> cart instance of EE_Cart: ';
659
+			}
660
+			EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart);
661
+		} else {
662
+			if (self::debug) {
663
+				echo '<br /><br /> invalid EE_Cart: ';
664
+				var_dump($cart);
665
+			}
666
+		}
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 *    _session_cart_reset
673
+	 * releases reserved tickets in the EE_Cart
674
+	 *
675
+	 * @access    protected
676
+	 * @param    EE_Cart $cart
677
+	 * @return    void
678
+	 * @throws EE_Error
679
+	 */
680
+	protected function _session_cart_reset(EE_Cart $cart)
681
+	{
682
+		if (self::debug) {
683
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
684
+		}
685
+		EE_Registry::instance()->load_helper('Line_Item');
686
+		$ticket_line_items = $cart->get_tickets();
687
+		if (empty($ticket_line_items)) {
688
+			return;
689
+		}
690
+		foreach ($ticket_line_items as $ticket_line_item) {
691
+			if (self::debug) {
692
+				echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
693
+			}
694
+			if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
695
+				if (self::debug) {
696
+					echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
697
+				}
698
+				$ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
699
+				if ($ticket instanceof EE_Ticket) {
700
+					if (self::debug) {
701
+						echo '<br /> . . ticket->ID(): ' . $ticket->ID();
702
+						echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
703
+					}
704
+					$this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
705
+				}
706
+			}
707
+		}
708
+		if (self::debug) {
709
+			echo '<br /><br /> RESET COMPLETED ';
710
+		}
711
+	}
712
+
713
+
714
+
715
+	/********************************** SESSION_CHECKOUT_RESET  **********************************/
716
+
717
+
718
+
719
+	/**
720
+	 *    session_checkout_reset
721
+	 * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
722
+	 *
723
+	 * @access    public
724
+	 * @param    EE_Session $session
725
+	 * @return    void
726
+	 * @throws EE_Error
727
+	 */
728
+	public static function session_checkout_reset(EE_Session $session)
729
+	{
730
+		$checkout = $session->checkout();
731
+		if ($checkout instanceof EE_Checkout) {
732
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
733
+		}
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 *    _session_checkout_reset
740
+	 * releases reserved tickets for the EE_Checkout->transaction
741
+	 *
742
+	 * @access    protected
743
+	 * @param    EE_Checkout $checkout
744
+	 * @return    void
745
+	 * @throws EE_Error
746
+	 */
747
+	protected function _session_checkout_reset(EE_Checkout $checkout)
748
+	{
749
+		if (self::debug) {
750
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
751
+		}
752
+		// we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
753
+		if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
754
+			return;
755
+		}
756
+		$this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
757
+	}
758
+
759
+
760
+
761
+	/********************************** SESSION_EXPIRED_RESET  **********************************/
762
+
763
+
764
+
765
+	/**
766
+	 *    session_expired_reset
767
+	 *
768
+	 * @access    public
769
+	 * @param    EE_Session $session
770
+	 * @return    void
771
+	 */
772
+	public static function session_expired_reset(EE_Session $session)
773
+	{
774
+	}
775
+
776
+
777
+
778
+	/********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
779
+
780
+
781
+
782
+	/**
783
+	 *    process_abandoned_transactions
784
+	 *    releases reserved tickets for all registrations of an ABANDONED EE_Transaction
785
+	 *    by default, will NOT release tickets for free transactions, or any that have received a payment
786
+	 *
787
+	 * @access    public
788
+	 * @param    EE_Transaction $transaction
789
+	 * @return    void
790
+	 * @throws EE_Error
791
+	 */
792
+	public static function process_abandoned_transactions(EE_Transaction $transaction)
793
+	{
794
+		// is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
795
+		if ($transaction->is_free() || $transaction->paid() > 0) {
796
+			if (self::debug) {
797
+				// DEBUG LOG
798
+				EEH_Debug_Tools::log(
799
+					__CLASS__, __FUNCTION__, __LINE__,
800
+					array($transaction),
801
+					false, 'EE_Transaction: ' . $transaction->ID()
802
+				);
803
+			}
804
+			return;
805
+		}
806
+		// have their been any successful payments made ?
807
+		$payments = $transaction->payments();
808
+		foreach ($payments as $payment) {
809
+			if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
810
+				if (self::debug) {
811
+					// DEBUG LOG
812
+					EEH_Debug_Tools::log(
813
+						__CLASS__, __FUNCTION__, __LINE__,
814
+						array($payment),
815
+						false, 'EE_Transaction: ' . $transaction->ID()
816
+					);
817
+				}
818
+				return;
819
+			}
820
+		}
821
+		// since you haven't even attempted to pay for your ticket...
822
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
823
+	}
824
+
825
+
826
+
827
+	/********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
828
+
829
+
830
+
831
+	/**
832
+	 *    process_abandoned_transactions
833
+	 *    releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
834
+	 *
835
+	 * @access    public
836
+	 * @param    EE_Transaction $transaction
837
+	 * @return    void
838
+	 * @throws EE_Error
839
+	 */
840
+	public static function process_failed_transactions(EE_Transaction $transaction)
841
+	{
842
+		// since you haven't even attempted to pay for your ticket...
843
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
844
+	}
845
+
846
+
847
+
848
+	/********************************** RESET RESERVATION COUNTS  *********************************/
849
+
850
+
851
+
852
+	/**
853
+	 * Resets all ticket and datetime reserved counts to zero
854
+	 * Tickets that are currently associated with a Transaction that is in progress
855
+	 *
856
+	 * @throws \EE_Error
857
+	 * @throws \DomainException
858
+	 */
859
+	public static function reset_reservation_counts()
860
+	{
861
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
862
+		$valid_reserved_tickets = array();
863
+		$transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress();
864
+		foreach ($transactions_in_progress as $transaction_in_progress) {
865
+			// if this TXN has been fully completed, then skip it
866
+			if ($transaction_in_progress->reg_step_completed('finalize_registration')) {
867
+				continue;
868
+			}
869
+			/** @var EE_Transaction $transaction_in_progress */
870
+			$total_line_item = $transaction_in_progress->total_line_item();
871
+			// $transaction_in_progress->line
872
+			if (! $total_line_item instanceof EE_Line_Item) {
873
+				throw new DomainException(
874
+					esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso')
875
+				);
876
+			}
877
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
878
+				$total_line_item
879
+			);
880
+		}
881
+		$total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
882
+		foreach ($total_line_items as $total_line_item) {
883
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
884
+				$total_line_item
885
+			);
886
+		}
887
+		return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
888
+			EEM_Ticket::instance()->get_tickets_with_reservations(),
889
+			$valid_reserved_tickets
890
+		);
891
+	}
892
+
893
+
894
+
895
+	/**
896
+	 * @param EE_Line_Item $total_line_item
897
+	 * @return EE_Line_Item[]
898
+	 */
899
+	private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
900
+	{
901
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
902
+		$valid_reserved_tickets = array();
903
+		$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
904
+		foreach ($ticket_line_items as $ticket_line_item) {
905
+			if ($ticket_line_item instanceof EE_Line_Item) {
906
+				$valid_reserved_tickets[] = $ticket_line_item;
907
+			}
908
+		}
909
+		return $valid_reserved_tickets;
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * @param EE_Ticket[] $tickets_with_reservations
916
+	 * @param EE_Line_Item[] $valid_reserved_ticket_line_items
917
+	 * @return int
918
+	 * @throws \EE_Error
919
+	 */
920
+	private static function release_reservations_for_tickets(
921
+		array $tickets_with_reservations,
922
+		$valid_reserved_ticket_line_items = array()
923
+	) {
924
+		$total_tickets_released = 0;
925
+		foreach ($tickets_with_reservations as $ticket_with_reservations) {
926
+			if (! $ticket_with_reservations instanceof EE_Ticket) {
927
+				continue;
928
+			}
929
+			$reserved_qty = $ticket_with_reservations->reserved();
930
+			foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
931
+				if (
932
+					$valid_reserved_ticket_line_item instanceof EE_Line_Item
933
+					&& $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
934
+				) {
935
+					$reserved_qty -= $valid_reserved_ticket_line_item->quantity();
936
+				}
937
+			}
938
+			if ($reserved_qty > 0) {
939
+				$ticket_with_reservations->decrease_reserved($reserved_qty);
940
+				$ticket_with_reservations->save();
941
+				$total_tickets_released += $reserved_qty;
942
+			}
943
+		}
944
+		return $total_tickets_released;
945
+	}
946
+
947
+
948
+
949
+	/********************************** SHUTDOWN  **********************************/
950
+
951
+
952
+
953
+	/**
954
+	 * @return false|int
955
+	 * @throws \EE_Error
956
+	 */
957
+	public static function clear_expired_line_items_with_no_transaction()
958
+	{
959
+		/** @type WPDB $wpdb */
960
+		global $wpdb;
961
+		return $wpdb->query(
962
+			$wpdb->prepare(
963
+				'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
964 964
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
965
-                // use GMT time because that's what LIN_timestamps are in
966
-                date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
967
-            )
968
-        );
969
-    }
965
+				// use GMT time because that's what LIN_timestamps are in
966
+				date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
967
+			)
968
+		);
969
+	}
970 970
 
971 971
 }
972 972
 // End of file EED_Ticket_Sales_Monitor.module.php
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 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
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         $expired_ticket_IDs = array();
182 182
         $valid_ticket_line_items = array();
183 183
         $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
184
-        if(empty($total_line_items)){
184
+        if (empty($total_line_items)) {
185 185
             return;
186 186
         }
187 187
         $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
             /** @var EE_Line_Item $total_line_item */
190 190
             $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
191 191
             foreach ($ticket_line_items as $ticket_line_item) {
192
-                if(! $ticket_line_item instanceof EE_Line_Item) {
192
+                if ( ! $ticket_line_item instanceof EE_Line_Item) {
193 193
                     continue;
194 194
                 }
195
-                if ($total_line_item->timestamp(true) <= $expired ) {
195
+                if ($total_line_item->timestamp(true) <= $expired) {
196 196
                     $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID();
197 197
                 } else {
198 198
                     $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item;
199 199
                 }
200 200
             }
201 201
         }
202
-        if (! empty($expired_ticket_IDs)) {
202
+        if ( ! empty($expired_ticket_IDs)) {
203 203
             EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
204 204
                 \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
205 205
                 $valid_ticket_line_items
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
             $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
238 238
         }
239 239
         if (self::debug) {
240
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
241
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
240
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()';
241
+            echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>';
242 242
         }
243 243
         return $qty;
244 244
     }
@@ -259,36 +259,36 @@  discard block
 block discarded – undo
259 259
     protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
260 260
     {
261 261
         if (self::debug) {
262
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
262
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
263 263
         }
264 264
         if ( ! $ticket instanceof EE_Ticket) {
265 265
             return 0;
266 266
         }
267 267
         if (self::debug) {
268
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
269
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
268
+            echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>';
269
+            echo '<br /> . original ticket->reserved: '.$ticket->reserved();
270 270
         }
271 271
         $ticket->refresh_from_db();
272 272
         // first let's determine the ticket availability based on sales
273 273
         $available = $ticket->qty('saleable');
274 274
         if (self::debug) {
275
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
276
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
277
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
278
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
279
-            echo '<br /> . . . available: ' . $available;
275
+            echo '<br /> . . . ticket->qty: '.$ticket->qty();
276
+            echo '<br /> . . . ticket->sold: '.$ticket->sold();
277
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
278
+            echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable');
279
+            echo '<br /> . . . available: '.$available;
280 280
         }
281 281
         if ($available < 1) {
282 282
             $this->_ticket_sold_out($ticket);
283 283
             return 0;
284 284
         }
285 285
         if (self::debug) {
286
-            echo '<br /> . . . qty: ' . $qty;
286
+            echo '<br /> . . . qty: '.$qty;
287 287
         }
288 288
         if ($available < $qty) {
289 289
             $qty = $available;
290 290
             if (self::debug) {
291
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
291
+                echo '<br /> . . . QTY ADJUSTED: '.$qty;
292 292
             }
293 293
             $this->_ticket_quantity_decremented($ticket);
294 294
         }
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
312 312
     {
313 313
         if (self::debug) {
314
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
314
+            echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity;
315 315
         }
316 316
         $ticket->increase_reserved($quantity);
317 317
         return $ticket->save();
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
332 332
     {
333 333
         if (self::debug) {
334
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
335
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
334
+            echo '<br /> . . . ticket->ID: '.$ticket->ID();
335
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
336 336
         }
337 337
         $ticket->decrease_reserved($quantity);
338 338
         if (self::debug) {
339
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
339
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
340 340
         }
341 341
         return $ticket->save() ? 1 : 0;
342 342
     }
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
     protected function _ticket_sold_out(EE_Ticket $ticket)
357 357
     {
358 358
         if (self::debug) {
359
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
360
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
359
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
360
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
361 361
         }
362 362
         $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
363 363
     }
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
     protected function _ticket_quantity_decremented(EE_Ticket $ticket)
378 378
     {
379 379
         if (self::debug) {
380
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
381
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
380
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
381
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
382 382
         }
383 383
         $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
384 384
     }
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
     protected function _post_notices()
486 486
     {
487 487
         if (self::debug) {
488
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
488
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
489 489
         }
490 490
         $refresh_msg = '';
491 491
         $none_added_msg = '';
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
     protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
553 553
     {
554 554
         if (self::debug) {
555
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
556
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
555
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
556
+            echo '<br /> . transaction->ID: '.$transaction->ID();
557 557
         }
558 558
         // check if 'finalize_registration' step has been completed...
559 559
         $finalized = $transaction->reg_step_completed('finalize_registration');
@@ -562,13 +562,13 @@  discard block
 block discarded – undo
562 562
             EEH_Debug_Tools::log(
563 563
                 __CLASS__, __FUNCTION__, __LINE__,
564 564
                 array('finalized' => $finalized),
565
-                false, 'EE_Transaction: ' . $transaction->ID()
565
+                false, 'EE_Transaction: '.$transaction->ID()
566 566
             );
567 567
         }
568 568
         // how many tickets were released
569 569
         $count = 0;
570 570
         if (self::debug) {
571
-            echo '<br /> . . . finalized: ' . $finalized;
571
+            echo '<br /> . . . finalized: '.$finalized;
572 572
         }
573 573
         $release_tickets_with_TXN_status = array(
574 574
             EEM_Transaction::failed_status_code,
@@ -609,10 +609,10 @@  discard block
 block discarded – undo
609 609
     ) {
610 610
         $STS_ID = $transaction->status_ID();
611 611
         if (self::debug) {
612
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
613
-            echo '<br /> . . registration->ID: ' . $registration->ID();
614
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
615
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
612
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
613
+            echo '<br /> . . registration->ID: '.$registration->ID();
614
+            echo '<br /> . . registration->status_ID: '.$registration->status_ID();
615
+            echo '<br /> . . transaction->status_ID(): '.$STS_ID;
616 616
         }
617 617
         if (
618 618
             // release Tickets for Failed Transactions and Abandoned Transactions
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
     public static function session_cart_reset(EE_Session $session)
651 651
     {
652 652
         if (self::debug) {
653
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
653
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
654 654
         }
655 655
         $cart = $session->cart();
656 656
         if ($cart instanceof EE_Cart) {
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
     protected function _session_cart_reset(EE_Cart $cart)
681 681
     {
682 682
         if (self::debug) {
683
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
683
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
684 684
         }
685 685
         EE_Registry::instance()->load_helper('Line_Item');
686 686
         $ticket_line_items = $cart->get_tickets();
@@ -689,17 +689,17 @@  discard block
 block discarded – undo
689 689
         }
690 690
         foreach ($ticket_line_items as $ticket_line_item) {
691 691
             if (self::debug) {
692
-                echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
692
+                echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID();
693 693
             }
694 694
             if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
695 695
                 if (self::debug) {
696
-                    echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
696
+                    echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID();
697 697
                 }
698 698
                 $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
699 699
                 if ($ticket instanceof EE_Ticket) {
700 700
                     if (self::debug) {
701
-                        echo '<br /> . . ticket->ID(): ' . $ticket->ID();
702
-                        echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
701
+                        echo '<br /> . . ticket->ID(): '.$ticket->ID();
702
+                        echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity();
703 703
                     }
704 704
                     $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
705 705
                 }
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
     protected function _session_checkout_reset(EE_Checkout $checkout)
748 748
     {
749 749
         if (self::debug) {
750
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
750
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
751 751
         }
752 752
         // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
753 753
         if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
                 EEH_Debug_Tools::log(
799 799
                     __CLASS__, __FUNCTION__, __LINE__,
800 800
                     array($transaction),
801
-                    false, 'EE_Transaction: ' . $transaction->ID()
801
+                    false, 'EE_Transaction: '.$transaction->ID()
802 802
                 );
803 803
             }
804 804
             return;
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
                     EEH_Debug_Tools::log(
813 813
                         __CLASS__, __FUNCTION__, __LINE__,
814 814
                         array($payment),
815
-                        false, 'EE_Transaction: ' . $transaction->ID()
815
+                        false, 'EE_Transaction: '.$transaction->ID()
816 816
                     );
817 817
                 }
818 818
                 return;
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
             /** @var EE_Transaction $transaction_in_progress */
870 870
             $total_line_item = $transaction_in_progress->total_line_item();
871 871
             // $transaction_in_progress->line
872
-            if (! $total_line_item instanceof EE_Line_Item) {
872
+            if ( ! $total_line_item instanceof EE_Line_Item) {
873 873
                 throw new DomainException(
874 874
                     esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso')
875 875
                 );
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
     ) {
924 924
         $total_tickets_released = 0;
925 925
         foreach ($tickets_with_reservations as $ticket_with_reservations) {
926
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
926
+            if ( ! $ticket_with_reservations instanceof EE_Ticket) {
927 927
                 continue;
928 928
             }
929 929
             $reserved_qty = $ticket_with_reservations->reserved();
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
         global $wpdb;
961 961
         return $wpdb->query(
962 962
             $wpdb->prepare(
963
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
963
+                'DELETE FROM '.EEM_Line_Item::instance()->table().'
964 964
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
965 965
                 // use GMT time because that's what LIN_timestamps are in
966 966
                 date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
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.