Completed
Branch BUG-10532-replace-hooks-for-ts (65130e)
by
unknown
28:48 queued 15:20
created
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 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 On 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 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 On Sale', 'event_espresso')
228
+				),
229
+				'', 'ticket-pending'
230
+			)
231
+			. \EEH_HTML::br()
232
+			. \EEH_HTML::span(
233
+				$this->ticket->get_i18n_datetime(
234
+					'TKT_start_date',
235
+					apply_filters(
236
+						'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',
237
+						$this->date_format
238
+					)
239
+				),
240
+				'', 'small-text'
241
+			),
242
+			'', 'ticket-pending-pg'
243
+		);
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * notEnoughTicketsAvailable
250
+	 */
251
+	protected function notEnoughTicketsAvailable()
252
+	{
253
+		return \EEH_HTML::div(
254
+			\EEH_HTML::span(
255
+				apply_filters(
256
+					'FHEE__ticket_selector_chart_template__ticket_not_available_msg',
257
+					__('Not Available', 'event_espresso')
258
+				),
259
+				'', 'archived-ticket small-text'
260
+			)
261
+			. \EEH_HTML::br(),
262
+			'', 'archived-ticket-pg'
263
+		);
264
+	}
265 265
 
266 266
 
267 267
 
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_system_stati_page.template.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 function ee_resurse_into_array($data) {
9 9
 	if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {//is_object($incomplete_class) actually returns false, hence why we check for it
10
-		$data = (array)$data;
10
+		$data = (array) $data;
11 11
 	}
12 12
 	if (is_array($data)) {
13 13
 		if (EEH_Array::is_associative_array($data)) {
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
 						?>
20 20
 						<tr>
21 21
 							<td>
22
-								<?php echo $data_key;?>
22
+								<?php echo $data_key; ?>
23 23
 							</td>
24 24
 							<td>
25
-								<?php ee_resurse_into_array($data_values);?>
25
+								<?php ee_resurse_into_array($data_values); ?>
26 26
 							</td>
27 27
 						</tr>
28 28
 						<?php
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
 			<ul>
37 37
 				<?php
38 38
 				foreach ($data as $datum) {
39
-					echo "<li>";ee_resurse_into_array($datum);echo "</li>";
39
+					echo "<li>"; ee_resurse_into_array($datum); echo "</li>";
40 40
 				}?>
41 41
 			</ul>
42 42
 			<?php
43 43
 		}
44
-	}else {
44
+	} else {
45 45
 		//simple value
46 46
 		echo $data;
47 47
 	}
48 48
 }
49 49
 ?>
50 50
 <h1>
51
-	<?php _e("System Information", "event_espresso");?> <a href="<?php echo $download_system_status_url;?>" class="button-secondary"><?php esc_html_e( 'Download to File', 'event_espresso' );?></a>
51
+	<?php _e("System Information", "event_espresso"); ?> <a href="<?php echo $download_system_status_url; ?>" class="button-secondary"><?php esc_html_e('Download to File', 'event_espresso'); ?></a>
52 52
 </h1>
53 53
 <div class="padding">
54 54
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		<?php
57 57
 		foreach ($system_stati as $status_category_slug => $data) {
58 58
 			if (is_object($data)) {
59
-				$data = (array)$data;
59
+				$data = (array) $data;
60 60
 			}
61 61
 			?>
62 62
 			<thead>
Please login to merge, or discard this patch.
core/db_classes/EE_Import.class.php 3 patches
Doc Comments   +4 added lines, -10 removed lines patch added patch discarded remove patch
@@ -79,10 +79,6 @@  discard block
 block discarded – undo
79 79
 	 *	@ access 	public
80 80
 	 * 	@param 	string 		$title - heading for the form
81 81
 	 * 	@param 	string 		$intro - additional text explaing what to do
82
-	 * 	@param 	string 		$page - EE Admin page to direct form to - in the form "espresso_{pageslug}"
83
-	 * 	@param 	string 		$action - EE Admin page route array "action" that form will direct to
84
-	 * 	@param 	string 		$type - type of file to import
85
-	 *	@ return 	string
86 82
 	 */
87 83
 	public function upload_form ( $title, $intro, $form_url, $action, $type  ) {
88 84
 
@@ -121,7 +117,7 @@  discard block
 block discarded – undo
121 117
 	/**
122 118
 	 *	@Import Event Espresso data - some code "borrowed" from event espresso csv_import.php
123 119
 	 *	@access public
124
-	 *	@return boolean success
120
+	 *	@return boolean|null success
125 121
 	 */
126 122
 	public function import() {
127 123
 
@@ -272,8 +268,7 @@  discard block
 block discarded – undo
272 268
       *
273 269
       * @access public
274 270
       * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array()
275
-      * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
276
-      * @return TRUE on success, FALSE on fail
271
+      * @return boolean on success, FALSE on fail
277 272
       * @throws \EE_Error
278 273
       */
279 274
 	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
@@ -370,7 +365,7 @@  discard block
 block discarded – undo
370 365
 	 * we need to insert a new row for that ID, and then map from the non-existent ID
371 366
 	 * to the newly-inserted real ID.
372 367
 	 * @param type $csv_data_array
373
-	 * @param type $export_from_site_a_to_b
368
+	 * @param boolean $export_from_site_a_to_b
374 369
 	 * @param type $old_db_to_new_db_mapping
375 370
 	 * @return array updated $old_db_to_new_db_mapping
376 371
 	 */
@@ -487,7 +482,6 @@  discard block
 block discarded – undo
487 482
 	 * @param type $id_in_csv
488 483
 	 * @param type $model_object_data
489 484
 	 * @param EEM_Base $model
490
-	 * @param type $old_db_to_new_db_mapping
491 485
 	 * @return
492 486
 	 */
493 487
 	protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) {
@@ -597,7 +591,7 @@  discard block
 block discarded – undo
597 591
 	 * @param type $object_id
598 592
 	 * @param string $model_name
599 593
 	 * @param array $old_db_to_new_db_mapping
600
-	 * @param type $export_from_site_a_to_b
594
+	 * @param boolean $export_from_site_a_to_b
601 595
 	 * @return int
602 596
 	 */
603 597
 	protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
Please login to merge, or discard this patch.
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -131,43 +131,43 @@  discard block
 block discarded – undo
131 131
 		if ( isset( $_REQUEST['import'] )) {
132 132
 			if( isset( $_POST['csv_submitted'] )) {
133 133
 
134
-			    switch ( $_FILES['file']['error'][0] ) {
135
-			        case UPLOAD_ERR_OK:
136
-			            $error_msg = FALSE;
137
-			            break;
138
-			        case UPLOAD_ERR_INI_SIZE:
139
-			            $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
140
-			            break;
141
-			        case UPLOAD_ERR_FORM_SIZE:
142
-			            $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
143
-			            break;
144
-			        case UPLOAD_ERR_PARTIAL:
145
-			            $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
146
-			            break;
147
-			        case UPLOAD_ERR_NO_FILE:
148
-			            $error_msg = __('No file was uploaded.', "event_espresso");
149
-			            break;
150
-			        case UPLOAD_ERR_NO_TMP_DIR:
151
-			            $error_msg = __('Missing a temporary folder.', "event_espresso");
152
-			            break;
153
-			        case UPLOAD_ERR_CANT_WRITE:
154
-			            $error_msg = __('Failed to write file to disk.', "event_espresso");
155
-			            break;
156
-			        case UPLOAD_ERR_EXTENSION:
157
-			            $error_msg = __('File upload stopped by extension.', "event_espresso");
158
-			            break;
159
-			        default:
160
-			            $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
161
-			            break;
162
-			    }
134
+				switch ( $_FILES['file']['error'][0] ) {
135
+					case UPLOAD_ERR_OK:
136
+						$error_msg = FALSE;
137
+						break;
138
+					case UPLOAD_ERR_INI_SIZE:
139
+						$error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
140
+						break;
141
+					case UPLOAD_ERR_FORM_SIZE:
142
+						$error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
143
+						break;
144
+					case UPLOAD_ERR_PARTIAL:
145
+						$error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
146
+						break;
147
+					case UPLOAD_ERR_NO_FILE:
148
+						$error_msg = __('No file was uploaded.', "event_espresso");
149
+						break;
150
+					case UPLOAD_ERR_NO_TMP_DIR:
151
+						$error_msg = __('Missing a temporary folder.', "event_espresso");
152
+						break;
153
+					case UPLOAD_ERR_CANT_WRITE:
154
+						$error_msg = __('Failed to write file to disk.', "event_espresso");
155
+						break;
156
+					case UPLOAD_ERR_EXTENSION:
157
+						$error_msg = __('File upload stopped by extension.', "event_espresso");
158
+						break;
159
+					default:
160
+						$error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
161
+						break;
162
+				}
163 163
 
164 164
 				if ( ! $error_msg ) {
165 165
 
166
-				    $filename	= $_FILES['file']['name'][0];
166
+					$filename	= $_FILES['file']['name'][0];
167 167
 					$file_ext 		= substr( strrchr( $filename, '.' ), 1 );
168
-				    $file_type 	= $_FILES['file']['type'][0];
169
-				    $temp_file	= $_FILES['file']['tmp_name'][0];
170
-				    $filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
168
+					$file_type 	= $_FILES['file']['type'][0];
169
+					$temp_file	= $_FILES['file']['tmp_name'][0];
170
+					$filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
171 171
 
172 172
 					if ( $file_ext=='csv' ) {
173 173
 
@@ -242,40 +242,40 @@  discard block
 block discarded – undo
242 242
 
243 243
 
244 244
 
245
-     /**
246
-      *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
247
-      *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
248
-      *    next level being numeric indexes adn each value representing a model object, and the last layer down
249
-      *    being keys of model fields and their proposed values.
250
-      *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
251
-      *    If the CSV data says (in the metadata row) that it's from the SAME database,
252
-      *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
253
-      *    IDs DON'T exist in the database, they're treated as temporary IDs,
254
-      *    which can used elsewhere to refer to the same object. Once an item
255
-      *    with a temporary ID gets inserted, we record its mapping from temporary
256
-      *    ID to real ID, and use the real ID in place of the temporary ID
257
-      *    when that temporary ID was used as a foreign key.
258
-      *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
259
-      *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
260
-      *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
261
-      *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
262
-      *    An important exception are non-auto-increment primary keys. If one entry in the
263
-      *    CSV file has the same ID as one in the DB, we assume they are meant to be
264
-      *    the same item, and instead update the item in the DB with that same ID.
265
-      *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
266
-      *    time you import a CSV from a different site, we remember their mappings, and
267
-      * will try to update the item in the DB instead of inserting another item (eg
268
-      * if we previously imported an event with temporary ID 1, and then it got a
269
-      * real ID of 123, we remember that. So the next time we import an event with
270
-      * temporary ID, from the same site, we know that it's real ID is 123, and will
271
-      * update that event, instead of adding a new event).
272
-      *
273
-      * @access public
274
-      * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array()
275
-      * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
276
-      * @return TRUE on success, FALSE on fail
277
-      * @throws \EE_Error
278
-      */
245
+	 /**
246
+	  *    Given an array of data (usually from a CSV import) attempts to save that data to the db.
247
+	  *    If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names,
248
+	  *    next level being numeric indexes adn each value representing a model object, and the last layer down
249
+	  *    being keys of model fields and their proposed values.
250
+	  *    If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned.
251
+	  *    If the CSV data says (in the metadata row) that it's from the SAME database,
252
+	  *    we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those
253
+	  *    IDs DON'T exist in the database, they're treated as temporary IDs,
254
+	  *    which can used elsewhere to refer to the same object. Once an item
255
+	  *    with a temporary ID gets inserted, we record its mapping from temporary
256
+	  *    ID to real ID, and use the real ID in place of the temporary ID
257
+	  *    when that temporary ID was used as a foreign key.
258
+	  *    If the CSV data says (in the metadata again) that it's from a DIFFERENT database,
259
+	  *    we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with
260
+	  *    ID 1, and the database already has an event with ID 1, we assume that's just a coincidence,
261
+	  *    and insert a new event, and map it's temporary ID of 1 over to its new real ID.
262
+	  *    An important exception are non-auto-increment primary keys. If one entry in the
263
+	  *    CSV file has the same ID as one in the DB, we assume they are meant to be
264
+	  *    the same item, and instead update the item in the DB with that same ID.
265
+	  *    Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th
266
+	  *    time you import a CSV from a different site, we remember their mappings, and
267
+	  * will try to update the item in the DB instead of inserting another item (eg
268
+	  * if we previously imported an event with temporary ID 1, and then it got a
269
+	  * real ID of 123, we remember that. So the next time we import an event with
270
+	  * temporary ID, from the same site, we know that it's real ID is 123, and will
271
+	  * update that event, instead of adding a new event).
272
+	  *
273
+	  * @access public
274
+	  * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array()
275
+	  * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
276
+	  * @return TRUE on success, FALSE on fail
277
+	  * @throws \EE_Error
278
+	  */
279 279
 	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
280 280
 
281 281
 
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 			unset($csv_data_array[EE_CSV::metadata_header]);
307 307
 		}
308 308
 		/**
309
-		* @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
310
-		* the value will be the newly-inserted ID.
311
-		* If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
312
-		*/
309
+		 * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and
310
+		 * the value will be the newly-inserted ID.
311
+		 * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
312
+		 */
313 313
 	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array());
314 314
 	   if( $old_db_to_new_db_mapping){
315 315
 		   EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url()));
Please login to merge, or discard this patch.
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
+do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3 3
 /**
4 4
  * EE_Import class
5 5
  *
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public static function instance() {
58 58
 		// check if class object is instantiated
59
-		if ( self::$_instance === NULL  or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) {
59
+		if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
60 60
 			self::$_instance = new self();
61 61
 		}
62 62
 		return self::$_instance;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * Resets the importer
67 67
 	 * @return EE_Import
68 68
 	 */
69
-	public static function reset(){
69
+	public static function reset() {
70 70
 		self::$_instance = null;
71 71
 		return self::instance();
72 72
 	}
@@ -84,27 +84,27 @@  discard block
 block discarded – undo
84 84
 	 * 	@param 	string 		$type - type of file to import
85 85
 	 *	@ return 	string
86 86
 	 */
87
-	public function upload_form ( $title, $intro, $form_url, $action, $type  ) {
87
+	public function upload_form($title, $intro, $form_url, $action, $type) {
88 88
 
89
-		$form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url );
89
+		$form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
90 90
 
91 91
 		ob_start();
92 92
 ?>
93 93
 	<div class="ee-upload-form-dv">
94
-		<h3><?php echo $title;?></h3>
95
-		<p><?php echo $intro;?></p>
94
+		<h3><?php echo $title; ?></h3>
95
+		<p><?php echo $intro; ?></p>
96 96
 
97 97
 		<form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data">
98
-			<input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>">
99
-			<input name="import" type="hidden" value="<?php echo $type;?>" />
98
+			<input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>">
99
+			<input name="import" type="hidden" value="<?php echo $type; ?>" />
100 100
 			<input type="file" name="file[]" size="90" >
101
-			<input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>">
101
+			<input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>">
102 102
 		</form>
103 103
 
104 104
 		<p class="ee-attention">
105
-			<b><?php _e( 'Attention', 'event_espresso' );?></b><br/>
106
-			<?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?>
107
-			<?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?>
105
+			<b><?php _e('Attention', 'event_espresso'); ?></b><br/>
106
+			<?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?>
107
+			<?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?>
108 108
 		</p>
109 109
 
110 110
 	</div>
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function import() {
127 127
 
128
-		require_once( EE_CLASSES . 'EE_CSV.class.php' );
128
+		require_once(EE_CLASSES.'EE_CSV.class.php');
129 129
 		$this->EE_CSV = EE_CSV::instance();
130 130
 
131
-		if ( isset( $_REQUEST['import'] )) {
132
-			if( isset( $_POST['csv_submitted'] )) {
131
+		if (isset($_REQUEST['import'])) {
132
+			if (isset($_POST['csv_submitted'])) {
133 133
 
134
-			    switch ( $_FILES['file']['error'][0] ) {
134
+			    switch ($_FILES['file']['error'][0]) {
135 135
 			        case UPLOAD_ERR_OK:
136 136
 			            $error_msg = FALSE;
137 137
 			            break;
@@ -161,32 +161,32 @@  discard block
 block discarded – undo
161 161
 			            break;
162 162
 			    }
163 163
 
164
-				if ( ! $error_msg ) {
164
+				if ( ! $error_msg) {
165 165
 
166
-				    $filename	= $_FILES['file']['name'][0];
167
-					$file_ext 		= substr( strrchr( $filename, '.' ), 1 );
168
-				    $file_type 	= $_FILES['file']['type'][0];
169
-				    $temp_file	= $_FILES['file']['tmp_name'][0];
170
-				    $filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
166
+				    $filename = $_FILES['file']['name'][0];
167
+					$file_ext = substr(strrchr($filename, '.'), 1);
168
+				    $file_type = $_FILES['file']['type'][0];
169
+				    $temp_file = $_FILES['file']['tmp_name'][0];
170
+				    $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB
171 171
 
172
-					if ( $file_ext=='csv' ) {
172
+					if ($file_ext == 'csv') {
173 173
 
174
-						$max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB
175
-						if ( $filesize < $max_upload || true) {
174
+						$max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB
175
+						if ($filesize < $max_upload || true) {
176 176
 
177
-							$wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir());
178
-							$path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename;
177
+							$wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir());
178
+							$path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename;
179 179
 
180
-							if( move_uploaded_file( $temp_file, $path_to_file )) {
180
+							if (move_uploaded_file($temp_file, $path_to_file)) {
181 181
 
182 182
 								// convert csv to array
183
-								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file );
183
+								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
184 184
 
185 185
 								// was data successfully stored in an array?
186
-								if ( is_array( $this->csv_array ) ) {
186
+								if (is_array($this->csv_array)) {
187 187
 
188
-									$import_what = str_replace( 'csv_import_', '', $_REQUEST['action'] );
189
-									$import_what = str_replace( '_', ' ', ucwords( $import_what ));
188
+									$import_what = str_replace('csv_import_', '', $_REQUEST['action']);
189
+									$import_what = str_replace('_', ' ', ucwords($import_what));
190 190
 									$processed_data = $this->csv_array;
191 191
 									$this->columns_to_save = FALSE;
192 192
 
@@ -205,33 +205,33 @@  discard block
 block discarded – undo
205 205
 
206 206
 									}
207 207
 									// save processed codes to db
208
-									if ( $this->save_csv_data_array_to_db( $processed_data, $this->columns_to_save ) ) {
208
+									if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) {
209 209
 										return TRUE;
210 210
 
211 211
 									}
212 212
 								} else {
213 213
 									// no array? must be an error
214
-									EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ );
214
+									EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__);
215 215
 									return FALSE;
216 216
 								}
217 217
 
218 218
 							} else {
219
-								EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ );
219
+								EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__);
220 220
 								return FALSE;
221 221
 							}
222 222
 
223 223
 						} else {
224
-							EE_Error::add_error( sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"),$filename,$max_upload), __FILE__, __FUNCTION__, __LINE__ );
224
+							EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__);
225 225
 							return FALSE;
226 226
 						}
227 227
 
228 228
 					} else {
229
-						EE_Error::add_error( sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ );
229
+						EE_Error::add_error(sprintf(__("%s  had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__);
230 230
 						return FALSE;
231 231
 					}
232 232
 
233 233
 				} else {
234
-					EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
234
+					EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
235 235
 					return FALSE;
236 236
 				}
237 237
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
       * @return TRUE on success, FALSE on fail
277 277
       * @throws \EE_Error
278 278
       */
279
-	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
279
+	public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) {
280 280
 
281 281
 
282 282
 		$success = FALSE;
@@ -286,22 +286,22 @@  discard block
 block discarded – undo
286 286
 		$export_from_site_a_to_b = true;
287 287
 		// first level of array is not table information but a table name was passed to the function
288 288
 		// array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
289
-		if($model_name){
289
+		if ($model_name) {
290 290
 			$csv_data_array = array($csv_data_array);
291 291
 		}
292 292
 		// begin looking through the $csv_data_array, expecting the toplevel key to be the model's name...
293 293
 		$old_site_url = 'none-specified';
294 294
 
295 295
 		//hanlde metadata
296
-		if(isset($csv_data_array[EE_CSV::metadata_header]) ){
296
+		if (isset($csv_data_array[EE_CSV::metadata_header])) {
297 297
 			$csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]);
298 298
 			//ok so its metadata, dont try to save it to ehte db obviously...
299
-			if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){
299
+			if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) {
300 300
 				EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso")));
301 301
 				$export_from_site_a_to_b = false;
302
-			}else{
303
-				$old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
304
-				EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url()));
302
+			} else {
303
+				$old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url;
304
+				EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"), $old_site_url, site_url()));
305 305
 			};
306 306
 			unset($csv_data_array[EE_CSV::metadata_header]);
307 307
 		}
@@ -310,30 +310,30 @@  discard block
 block discarded – undo
310 310
 		* the value will be the newly-inserted ID.
311 311
 		* If we have already imported data from the same website via CSV, it shoudl be kept in this wp option
312 312
 		*/
313
-	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array());
314
-	   if( $old_db_to_new_db_mapping){
315
-		   EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url()));
313
+	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array());
314
+	   if ($old_db_to_new_db_mapping) {
315
+		   EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"), $old_site_url, site_url()));
316 316
 	   }
317 317
 	   $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping);
318 318
 
319 319
 		//save the mapping from old db to new db in case they try re-importing the same data from the same website again
320
-		update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping);
320
+		update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping);
321 321
 
322
-		if ( $this->_total_updates > 0 ) {
323
-			EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->_total_updates));
322
+		if ($this->_total_updates > 0) {
323
+			EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->_total_updates));
324 324
 			$success = true;
325 325
 		}
326
-		if ( $this->_total_inserts > 0 ) {
327
-			EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->_total_inserts));
326
+		if ($this->_total_inserts > 0) {
327
+			EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts));
328 328
 			$success = true;
329 329
 		}
330 330
 
331
-		if ( $this->_total_update_errors > 0 ) {
332
-			EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"),$this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__ );
331
+		if ($this->_total_update_errors > 0) {
332
+			EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"), $this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__);
333 333
 			$error = true;
334 334
 		}
335
-		if ( $this->_total_insert_errors > 0 ) {
336
-			EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"),$this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__ );
335
+		if ($this->_total_insert_errors > 0) {
336
+			EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"), $this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__);
337 337
 			$error = true;
338 338
 		}
339 339
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
343 343
 
344 344
 		// if there was at least one success and absolutely no errors
345
-		if ( $success && ! $error ) {
345
+		if ($success && ! $error) {
346 346
 			return TRUE;
347 347
 		} else {
348 348
 			return FALSE;
@@ -374,81 +374,81 @@  discard block
 block discarded – undo
374 374
 	 * @param type $old_db_to_new_db_mapping
375 375
 	 * @return array updated $old_db_to_new_db_mapping
376 376
 	 */
377
-	public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping ) {
378
-		foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) {
377
+	public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) {
378
+		foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
379 379
 			//now check that assumption was correct. If
380
-			if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
380
+			if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
381 381
 				$model_name = $model_name_in_csv_data;
382
-			}else {
382
+			} else {
383 383
 				// no table info in the array and no table name passed to the function?? FAIL
384
-				EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
384
+				EE_Error::add_error(__('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
385 385
 				return FALSE;
386 386
 			}
387 387
 			/* @var $model EEM_Base */
388 388
 			$model = EE_Registry::instance()->load_model($model_name);
389 389
 
390 390
 			//so without further ado, scanning all the data provided for primary keys and their inital values
391
-			foreach ( $model_data_from_import as $model_object_data ) {
391
+			foreach ($model_data_from_import as $model_object_data) {
392 392
 				//before we do ANYTHING, make sure the csv row wasn't just completely blank
393 393
 				$row_is_completely_empty = true;
394
-				foreach($model_object_data as $field){
395
-					if($field){
394
+				foreach ($model_object_data as $field) {
395
+					if ($field) {
396 396
 						$row_is_completely_empty = false;
397 397
 					}
398 398
 				}
399
-				if($row_is_completely_empty){
399
+				if ($row_is_completely_empty) {
400 400
 					continue;
401 401
 				}
402 402
 				//find the PK in the row of data (or a combined key if
403 403
 				//there is no primary key)
404
-				if($model->has_primary_key_field()){
405
-					$id_in_csv =  $model_object_data[$model->primary_key_name()];
406
-				}else{
404
+				if ($model->has_primary_key_field()) {
405
+					$id_in_csv = $model_object_data[$model->primary_key_name()];
406
+				} else {
407 407
 					$id_in_csv = $model->get_index_primary_key_string($model_object_data);
408 408
 				}
409 409
 
410 410
 
411
-				$model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b );
411
+				$model_object_data = $this->_replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b);
412 412
 				//now we need to decide if we're going to add a new model object given the $model_object_data,
413 413
 				//or just update.
414
-				if($export_from_site_a_to_b){
415
-					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
416
-				}else{//this is just a re-import
417
-					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
414
+				if ($export_from_site_a_to_b) {
415
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
416
+				} else {//this is just a re-import
417
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
418 418
 				}
419
-				if( $what_to_do == self::do_nothing ) {
419
+				if ($what_to_do == self::do_nothing) {
420 420
 					continue;
421 421
 				}
422 422
 
423 423
 				//double-check we actually want to insert, if that's what we're planning
424 424
 				//based on whether this item would be unique in the DB or not
425
-				if( $what_to_do == self::do_insert ) {
425
+				if ($what_to_do == self::do_insert) {
426 426
 					//we're supposed to be inserting. But wait, will this thing
427 427
 					//be acceptable if inserted?
428
-					$conflicting = $model->get_one_conflicting( $model_object_data, false );
429
-					if($conflicting){
428
+					$conflicting = $model->get_one_conflicting($model_object_data, false);
429
+					if ($conflicting) {
430 430
 						//ok, this item would conflict if inserted. Just update the item that it conflicts with.
431 431
 						$what_to_do = self::do_update;
432 432
 						//and if this model has a primary key, remember its mapping
433
-						if($model->has_primary_key_field()){
433
+						if ($model->has_primary_key_field()) {
434 434
 							$old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID();
435 435
 							$model_object_data[$model->primary_key_name()] = $conflicting->ID();
436
-						}else{
436
+						} else {
437 437
 							//we want to update this conflicting item, instead of inserting a conflicting item
438 438
 							//so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
439 439
 							//for the WHERE conditions in the update). At the time of this comment, there were no models like this
440
-							foreach($model->get_combined_primary_key_fields() as $key_field){
440
+							foreach ($model->get_combined_primary_key_fields() as $key_field) {
441 441
 								$model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name());
442 442
 							}
443 443
 						}
444 444
 					}
445 445
 				}
446
-				if( $what_to_do == self::do_insert ) {
447
-					$old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
448
-				}elseif( $what_to_do == self::do_update ) {
449
-					$old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
450
-				}else{
451
-					throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) );
446
+				if ($what_to_do == self::do_insert) {
447
+					$old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
448
+				}elseif ($what_to_do == self::do_update) {
449
+					$old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
450
+				} else {
451
+					throw new EE_Error(sprintf(__('Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso'), $what_to_do));
452 452
 				}
453 453
 			}
454 454
 		}
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 	 * @param array $old_db_to_new_db_mapping by reference so it can be modified
470 470
 	 * @return string one of the consts on this class that starts with do_*
471 471
 	 */
472
-	protected function _decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) {
472
+	protected function _decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
473 473
 		$model_name = $model->get_this_model_name();
474 474
 		//if it's a site-to-site export-and-import, see if this modelobject's id
475 475
 		//in the old data that we know of
476
-		if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){
476
+		if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) {
477 477
 			return self::do_update;
478
-		}else{
478
+		} else {
479 479
 			return self::do_insert;
480 480
 		}
481 481
 	}
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
 	 * @param type $old_db_to_new_db_mapping
491 491
 	 * @return
492 492
 	 */
493
-	protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) {
493
+	protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) {
494 494
 		//in this case, check if this thing ACTUALLY exists in the database
495
-		if( $model->get_one_conflicting( $model_object_data ) ){
495
+		if ($model->get_one_conflicting($model_object_data)) {
496 496
 			return self::do_update;
497
-		}else{
497
+		} else {
498 498
 			return self::do_insert;
499 499
 		}
500 500
 	}
@@ -513,55 +513,55 @@  discard block
 block discarded – undo
513 513
 	 * @param boolean $export_from_site_a_to_b
514 514
 	 * @return array updated model object data with temp IDs removed
515 515
 	 */
516
-	protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) {
516
+	protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
517 517
 		//if this model object's primary key is in the mapping, replace it
518
-		if( $model->has_primary_key_field() &&
518
+		if ($model->has_primary_key_field() &&
519 519
 				$model->get_primary_key_field()->is_auto_increment() &&
520
-				isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) &&
521
-				isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) {
522
-			$model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ];
520
+				isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) &&
521
+				isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) {
522
+			$model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]];
523 523
 		}
524 524
 
525
-		try{
525
+		try {
526 526
 			$model_name_field = $model->get_field_containing_related_model_name();
527 527
 			$models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
528
-		}catch( EE_Error $e ){
528
+		} catch (EE_Error $e) {
529 529
 			$model_name_field = NULL;
530 530
 			$models_pointed_to_by_model_name_field = array();
531 531
 		}
532
-		foreach( $model->field_settings( true )  as $field_obj ){
533
-			if( $field_obj instanceof EE_Foreign_Key_Int_Field ) {
532
+		foreach ($model->field_settings(true)  as $field_obj) {
533
+			if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
534 534
 				$models_pointed_to = $field_obj->get_model_names_pointed_to();
535 535
 				$found_a_mapping = false;
536
-				foreach( $models_pointed_to as $model_pointed_to_by_fk ) {
536
+				foreach ($models_pointed_to as $model_pointed_to_by_fk) {
537 537
 
538
-					if( $model_name_field ){
539
-						$value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
540
-						if( $value_of_model_name_field == $model_pointed_to_by_fk ) {
541
-							$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
542
-									$model_object_data[ $field_obj->get_name() ],
538
+					if ($model_name_field) {
539
+						$value_of_model_name_field = $model_object_data[$model_name_field->get_name()];
540
+						if ($value_of_model_name_field == $model_pointed_to_by_fk) {
541
+							$model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
542
+									$model_object_data[$field_obj->get_name()],
543 543
 									$model_pointed_to_by_fk,
544 544
 									$old_db_to_new_db_mapping,
545 545
 									$export_from_site_a_to_b );
546 546
 								$found_a_mapping = true;
547 547
 								break;
548 548
 						}
549
-					}else{
550
-						$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
551
-								$model_object_data[ $field_obj->get_name() ],
549
+					} else {
550
+						$model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
551
+								$model_object_data[$field_obj->get_name()],
552 552
 								$model_pointed_to_by_fk,
553 553
 								$old_db_to_new_db_mapping,
554 554
 								$export_from_site_a_to_b );
555 555
 						$found_a_mapping = true;
556 556
 					}
557 557
 					//once we've found a mapping for this field no need to continue
558
-					if( $found_a_mapping ) {
558
+					if ($found_a_mapping) {
559 559
 						break;
560 560
 					}
561 561
 
562 562
 
563 563
 				}
564
-			}else{
564
+			} else {
565 565
 				//it's a string foreign key (which we leave alone, because those are things
566 566
 				//like country names, which we'd really rather not make 2 USAs etc (we'd actually
567 567
 				//prefer to just update one)
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 			}
570 570
 		}
571 571
 		//
572
-		if( $model instanceof EEM_Term_Taxonomy ){
573
-			$model_object_data = $this->_handle_split_term_ids( $model_object_data );
572
+		if ($model instanceof EEM_Term_Taxonomy) {
573
+			$model_object_data = $this->_handle_split_term_ids($model_object_data);
574 574
 		}
575 575
 		return $model_object_data;
576 576
 	}
@@ -582,11 +582,11 @@  discard block
 block discarded – undo
582 582
 	 * @param type $model_object_data
583 583
 	 * @return array new model object data
584 584
 	 */
585
-	protected function _handle_split_term_ids( $model_object_data ){
586
-		if( isset( $model_object_data['term_id'] ) && isset( $model_object_data[ 'taxonomy' ]) && apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) {
587
-			$new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] );
588
-			if( $new_term_id ){
589
-				$model_object_data[ 'term_id' ] = $new_term_id;
585
+	protected function _handle_split_term_ids($model_object_data) {
586
+		if (isset($model_object_data['term_id']) && isset($model_object_data['taxonomy']) && apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) {
587
+			$new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
588
+			if ($new_term_id) {
589
+				$model_object_data['term_id'] = $new_term_id;
590 590
 			}
591 591
 		}
592 592
 		return $model_object_data;
@@ -600,18 +600,18 @@  discard block
 block discarded – undo
600 600
 	 * @param type $export_from_site_a_to_b
601 601
 	 * @return int
602 602
 	 */
603
-	protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
604
-		if(	isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){
603
+	protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
604
+		if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) {
605 605
 
606
-				return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
607
-			}elseif( $object_id == '0' || $object_id == '' ) {
606
+				return $old_db_to_new_db_mapping[$model_name][$object_id];
607
+			}elseif ($object_id == '0' || $object_id == '') {
608 608
 				//leave as-is
609 609
 				return $object_id;
610
-			}elseif( $export_from_site_a_to_b ){
610
+			}elseif ($export_from_site_a_to_b) {
611 611
 				//we couldn't find a mapping for this, and it's from a different site,
612 612
 				//so blank it out
613 613
 				return NULL;
614
-			}elseif( ! $export_from_site_a_to_b ) {
614
+			}elseif ( ! $export_from_site_a_to_b) {
615 615
 				//we coudln't find a mapping for this, but it's from thsi DB anyway
616 616
 				//so let's just leave it as-is
617 617
 				return $object_id;
@@ -626,36 +626,36 @@  discard block
 block discarded – undo
626 626
 	 * @param type $old_db_to_new_db_mapping
627 627
 	 * @return array updated $old_db_to_new_db_mapping
628 628
 	 */
629
-	protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) {
629
+	protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
630 630
 		//remove the primary key, if there is one (we don't want it for inserts OR updates)
631 631
 		//we'll put it back in if we need it
632
-		if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){
632
+		if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
633 633
 			$effective_id = $model_object_data[$model->primary_key_name()];
634 634
 			unset($model_object_data[$model->primary_key_name()]);
635
-		}else{
636
-			$effective_id = $model->get_index_primary_key_string( $model_object_data );
635
+		} else {
636
+			$effective_id = $model->get_index_primary_key_string($model_object_data);
637 637
 		}
638 638
 		//the model takes care of validating the CSV's input
639
-		try{
639
+		try {
640 640
 			$new_id = $model->insert($model_object_data);
641
-			if( $new_id ){
641
+			if ($new_id) {
642 642
 				$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id;
643 643
 				$this->_total_inserts++;
644
-				EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data)));
645
-			}else{
644
+				EE_Error::add_success(sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), $model->get_this_model_name(), $new_id, implode(",", $model_object_data)));
645
+			} else {
646 646
 				$this->_total_insert_errors++;
647 647
 				//put the ID used back in there for the error message
648
-				if($model->has_primary_key_field()){
648
+				if ($model->has_primary_key_field()) {
649 649
 					$model_object_data[$model->primary_key_name()] = $effective_id;
650 650
 				}
651
-				EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ );
651
+				EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__);
652 652
 			}
653
-		}catch(EE_Error $e){
653
+		} catch (EE_Error $e) {
654 654
 			$this->_total_insert_errors++;
655
-			if($model->has_primary_key_field()){
655
+			if ($model->has_primary_key_field()) {
656 656
 				$model_object_data[$model->primary_key_name()] = $effective_id;
657 657
 			}
658
-			EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()), __FILE__, __FUNCTION__, __LINE__ );
658
+			EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__);
659 659
 		}
660 660
 		return $old_db_to_new_db_mapping;
661 661
 	}
@@ -668,55 +668,55 @@  discard block
 block discarded – undo
668 668
 	 * @param array $old_db_to_new_db_mapping
669 669
 	 * @return array updated $old_db_to_new_db_mapping
670 670
 	 */
671
-	protected function _update_from_data_array( $id_in_csv,  $model_object_data, $model, $old_db_to_new_db_mapping ) {
672
-		try{
671
+	protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
672
+		try {
673 673
 			//let's keep two copies of the model object data:
674 674
 			//one for performing an update, one for everthing else
675 675
 			$model_object_data_for_update = $model_object_data;
676
-			if($model->has_primary_key_field()){
676
+			if ($model->has_primary_key_field()) {
677 677
 				$conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]);
678 678
 				//remove the primary key because we shouldn't use it for updating
679 679
 				unset($model_object_data_for_update[$model->primary_key_name()]);
680
-			}elseif($model->get_combined_primary_key_fields() > 1 ){
680
+			}elseif ($model->get_combined_primary_key_fields() > 1) {
681 681
 				$conditions = array();
682
-				foreach($model->get_combined_primary_key_fields() as $key_field){
682
+				foreach ($model->get_combined_primary_key_fields() as $key_field) {
683 683
 					$conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()];
684 684
 				}
685
-			}else{
686
-				$model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
685
+			} else {
686
+				$model->primary_key_name(); //this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
687 687
 			}
688 688
 
689
-			$success = $model->update($model_object_data_for_update,array($conditions));
690
-			if($success){
689
+			$success = $model->update($model_object_data_for_update, array($conditions));
690
+			if ($success) {
691 691
 				$this->_total_updates++;
692
-				EE_Error::add_success( sprintf(__("Successfully updated %s with csv data %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data_for_update)));
692
+				EE_Error::add_success(sprintf(__("Successfully updated %s with csv data %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data_for_update)));
693 693
 				//we should still record the mapping even though it was an update
694 694
 				//because if we were going to insert somethign but it was going to conflict
695 695
 				//we would have last-minute decided to update. So we'd like to know what we updated
696 696
 				//and so we record what record ended up being updated using the mapping
697
-				if( $model->has_primary_key_field() ){
698
-					$new_key_for_mapping = $model_object_data[ $model->primary_key_name() ];
699
-				}else{
697
+				if ($model->has_primary_key_field()) {
698
+					$new_key_for_mapping = $model_object_data[$model->primary_key_name()];
699
+				} else {
700 700
 					//no primary key just a combined key
701
-					$new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data );
701
+					$new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
702 702
 				}
703
-				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping;
704
-			}else{
703
+				$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping;
704
+			} else {
705 705
 				$matched_items = $model->get_all(array($conditions));
706
-				if( ! $matched_items){
706
+				if ( ! $matched_items) {
707 707
 					//no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
708 708
 					$this->_total_update_errors++;
709
-					EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ );
710
-				}else{
709
+					EE_Error::add_error(sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data), http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__);
710
+				} else {
711 711
 					$this->_total_updates++;
712
-					EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data)));
712
+					EE_Error::add_success(sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data)));
713 713
 				}
714 714
 			}
715
-		}catch(EE_Error $e){
715
+		} catch (EE_Error $e) {
716 716
 			$this->_total_update_errors++;
717
-			$basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage());
718
-			$debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
719
-			EE_Error::add_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ );
717
+			$basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage());
718
+			$debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString();
719
+			EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
720 720
 		}
721 721
 		return $old_db_to_new_db_mapping;
722 722
 	}
@@ -725,28 +725,28 @@  discard block
 block discarded – undo
725 725
 	 * Gets the number of inserts performed since importer was instantiated or reset
726 726
 	 * @return int
727 727
 	 */
728
-	public function get_total_inserts(){
728
+	public function get_total_inserts() {
729 729
 		return $this->_total_inserts;
730 730
 	}
731 731
 	/**
732 732
 	 *  Gets the number of insert errors since importer was instantiated or reset
733 733
 	 * @return int
734 734
 	 */
735
-	public function get_total_insert_errors(){
735
+	public function get_total_insert_errors() {
736 736
 		return $this->_total_insert_errors;
737 737
 	}
738 738
 	/**
739 739
 	 *  Gets the number of updates performed since importer was instantiated or reset
740 740
 	 * @return int
741 741
 	 */
742
-	public function get_total_updates(){
742
+	public function get_total_updates() {
743 743
 		return $this->_total_updates;
744 744
 	}
745 745
 	/**
746 746
 	 *  Gets the number of update errors since importer was instantiated or reset
747 747
 	 * @return int
748 748
 	 */
749
-	public function get_total_update_errors(){
749
+	public function get_total_update_errors() {
750 750
 		return $this->_total_update_errors;
751 751
 	}
752 752
 
Please login to merge, or discard this patch.
modules/ticket_sales_monitor/EED_Ticket_Sales_Monitor.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      * @access    protected
249 249
      * @param    \EE_Ticket $ticket
250 250
      * @param int           $quantity
251
-     * @return bool
251
+     * @return integer
252 252
      * @throws EE_Error
253 253
      */
254 254
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @access protected
269 269
      * @param  EE_Ticket $ticket
270 270
      * @param  int       $quantity
271
-     * @return bool
271
+     * @return integer
272 272
      * @throws EE_Error
273 273
      */
274 274
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
Please login to merge, or discard this patch.
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.
core/db_models/EEM_Transaction.model.php 1 patch
Indentation   +362 added lines, -362 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_Base.model.php');
5 5
 
@@ -15,192 +15,192 @@  discard block
 block discarded – undo
15 15
 class EEM_Transaction extends EEM_Base
16 16
 {
17 17
 
18
-    // private instance of the Transaction object
19
-    protected static $_instance;
20
-
21
-    /**
22
-     * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
23
-     * but payment is pending. This is the state for transactions where payment is promised
24
-     * from an offline gateway.
25
-     */
26
-    //	const open_status_code = 'TPN';
27
-
28
-    /**
29
-     * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
30
-     * either due to a technical reason (server or computer crash during registration),
31
-     *  or some other reason that prevent the collection of any useful contact information from any of the registrants
32
-     */
33
-    const failed_status_code = 'TFL';
34
-
35
-    /**
36
-     * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
37
-     * either due to a technical reason (server or computer crash during registration),
38
-     * or due to an abandoned cart after registrant chose not to complete the registration process
39
-     * HOWEVER...
40
-     * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
41
-     * registrant
42
-     */
43
-    const abandoned_status_code = 'TAB';
44
-
45
-    /**
46
-     * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
47
-     * meaning that monies are still owing: TXN_paid < TXN_total
48
-     */
49
-    const incomplete_status_code = 'TIN';
50
-
51
-    /**
52
-     * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
53
-     * meaning that NO monies are owing: TXN_paid == TXN_total
54
-     */
55
-    const complete_status_code = 'TCM';
56
-
57
-    /**
58
-     *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
59
-     *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
60
-     */
61
-    const overpaid_status_code = 'TOP';
62
-
63
-
64
-    /**
65
-     *    private constructor to prevent direct creation
66
-     *
67
-     * @Constructor
68
-     * @access protected
69
-     *
70
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
71
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
72
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
73
-     *                         timezone in the 'timezone_string' wp option)
74
-     *
75
-     * @return EEM_Transaction
76
-     * @throws \EE_Error
77
-     */
78
-    protected function __construct($timezone)
79
-    {
80
-        $this->singular_item = __('Transaction', 'event_espresso');
81
-        $this->plural_item   = __('Transactions', 'event_espresso');
82
-
83
-        $this->_tables                 = array(
84
-            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
85
-        );
86
-        $this->_fields                 = array(
87
-            'TransactionTable' => array(
88
-                'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
89
-                'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
90
-                    __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
91
-                    $timezone),
92
-                'TXN_total'        => new EE_Money_Field('TXN_total',
93
-                    __('Total value of Transaction', 'event_espresso'), false, 0),
94
-                'TXN_paid'         => new EE_Money_Field('TXN_paid',
95
-                    __('Amount paid towards transaction to date', 'event_espresso'), false, 0),
96
-                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
97
-                    false, EEM_Transaction::failed_status_code, 'Status'),
98
-                'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
99
-                    __('Serialized session data', 'event_espresso'), true, ''),
100
-                'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
101
-                    __('Transaction Hash Salt', 'event_espresso'), true, ''),
102
-                'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
103
-                    __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
104
-                'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
105
-                    __('Registration Steps', 'event_espresso'), false, array()),
106
-            )
107
-        );
108
-        $this->_model_relations        = array(
109
-            'Registration'   => new EE_Has_Many_Relation(),
110
-            'Payment'        => new EE_Has_Many_Relation(),
111
-            'Status'         => new EE_Belongs_To_Relation(),
112
-            'Line_Item'      => new EE_Has_Many_Relation(false),
113
-            //you can delete a transaction without needing to delete its line items
114
-            'Payment_Method' => new EE_Belongs_To_Relation(),
115
-            'Message'        => new EE_Has_Many_Relation()
116
-        );
117
-        $this->_model_chain_to_wp_user = 'Registration.Event';
118
-        parent::__construct($timezone);
119
-
120
-    }
121
-
122
-
123
-    /**
124
-     *    txn_status_array
125
-     * get list of transaction statuses
126
-     *
127
-     * @access public
128
-     * @return array
129
-     */
130
-    public static function txn_status_array()
131
-    {
132
-        return apply_filters(
133
-            'FHEE__EEM_Transaction__txn_status_array',
134
-            array(
135
-                EEM_Transaction::overpaid_status_code,
136
-                EEM_Transaction::complete_status_code,
137
-                EEM_Transaction::incomplete_status_code,
138
-                EEM_Transaction::abandoned_status_code,
139
-                EEM_Transaction::failed_status_code,
140
-            )
141
-        );
142
-    }
143
-
144
-    /**
145
-     *        get the revenue per day  for the Transaction Admin page Reports Tab
146
-     *
147
-     * @access        public
148
-     *
149
-     * @param string $period
150
-     *
151
-     * @return \stdClass[]
152
-     */
153
-    public function get_revenue_per_day_report($period = '-1 month')
154
-    {
155
-        $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
156
-            'Y-m-d H:i:s', 'UTC');
157
-
158
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
159
-
160
-        return $this->_get_all_wpdb_results(
161
-            array(
162
-                array(
163
-                    'TXN_timestamp' => array('>=', $sql_date)
164
-                ),
165
-                'group_by' => 'txnDate',
166
-                'order_by' => array('TXN_timestamp' => 'ASC')
167
-            ),
168
-            OBJECT,
169
-            array(
170
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
171
-                'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
172
-            )
173
-        );
174
-    }
175
-
176
-
177
-    /**
178
-     *        get the revenue per event  for the Transaction Admin page Reports Tab
179
-     *
180
-     * @access        public
181
-     *
182
-     * @param string $period
183
-     *
184
-     * @throws \EE_Error
185
-     * @return mixed
186
-     */
187
-    public function get_revenue_per_event_report($period = '-1 month')
188
-    {
189
-        global $wpdb;
190
-        $transaction_table       = $wpdb->prefix . 'esp_transaction';
191
-        $registration_table      = $wpdb->prefix . 'esp_registration';
192
-        $event_table             = $wpdb->posts;
193
-        $payment_table           = $wpdb->prefix . 'esp_payment';
194
-        $sql_date                = date('Y-m-d H:i:s', strtotime($period));
195
-        $approved_payment_status = EEM_Payment::status_id_approved;
196
-        $extra_event_on_join     = '';
197
-        //exclude events not authored by user if permissions in effect
198
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
199
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
200
-        }
201
-
202
-        return $wpdb->get_results(
203
-            "SELECT
18
+	// private instance of the Transaction object
19
+	protected static $_instance;
20
+
21
+	/**
22
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
23
+	 * but payment is pending. This is the state for transactions where payment is promised
24
+	 * from an offline gateway.
25
+	 */
26
+	//	const open_status_code = 'TPN';
27
+
28
+	/**
29
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
30
+	 * either due to a technical reason (server or computer crash during registration),
31
+	 *  or some other reason that prevent the collection of any useful contact information from any of the registrants
32
+	 */
33
+	const failed_status_code = 'TFL';
34
+
35
+	/**
36
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
37
+	 * either due to a technical reason (server or computer crash during registration),
38
+	 * or due to an abandoned cart after registrant chose not to complete the registration process
39
+	 * HOWEVER...
40
+	 * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
41
+	 * registrant
42
+	 */
43
+	const abandoned_status_code = 'TAB';
44
+
45
+	/**
46
+	 * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
47
+	 * meaning that monies are still owing: TXN_paid < TXN_total
48
+	 */
49
+	const incomplete_status_code = 'TIN';
50
+
51
+	/**
52
+	 * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
53
+	 * meaning that NO monies are owing: TXN_paid == TXN_total
54
+	 */
55
+	const complete_status_code = 'TCM';
56
+
57
+	/**
58
+	 *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
59
+	 *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
60
+	 */
61
+	const overpaid_status_code = 'TOP';
62
+
63
+
64
+	/**
65
+	 *    private constructor to prevent direct creation
66
+	 *
67
+	 * @Constructor
68
+	 * @access protected
69
+	 *
70
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
71
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
72
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
73
+	 *                         timezone in the 'timezone_string' wp option)
74
+	 *
75
+	 * @return EEM_Transaction
76
+	 * @throws \EE_Error
77
+	 */
78
+	protected function __construct($timezone)
79
+	{
80
+		$this->singular_item = __('Transaction', 'event_espresso');
81
+		$this->plural_item   = __('Transactions', 'event_espresso');
82
+
83
+		$this->_tables                 = array(
84
+			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
85
+		);
86
+		$this->_fields                 = array(
87
+			'TransactionTable' => array(
88
+				'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
89
+				'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
90
+					__('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
91
+					$timezone),
92
+				'TXN_total'        => new EE_Money_Field('TXN_total',
93
+					__('Total value of Transaction', 'event_espresso'), false, 0),
94
+				'TXN_paid'         => new EE_Money_Field('TXN_paid',
95
+					__('Amount paid towards transaction to date', 'event_espresso'), false, 0),
96
+				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
97
+					false, EEM_Transaction::failed_status_code, 'Status'),
98
+				'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
99
+					__('Serialized session data', 'event_espresso'), true, ''),
100
+				'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
101
+					__('Transaction Hash Salt', 'event_espresso'), true, ''),
102
+				'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
103
+					__("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
104
+				'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
105
+					__('Registration Steps', 'event_espresso'), false, array()),
106
+			)
107
+		);
108
+		$this->_model_relations        = array(
109
+			'Registration'   => new EE_Has_Many_Relation(),
110
+			'Payment'        => new EE_Has_Many_Relation(),
111
+			'Status'         => new EE_Belongs_To_Relation(),
112
+			'Line_Item'      => new EE_Has_Many_Relation(false),
113
+			//you can delete a transaction without needing to delete its line items
114
+			'Payment_Method' => new EE_Belongs_To_Relation(),
115
+			'Message'        => new EE_Has_Many_Relation()
116
+		);
117
+		$this->_model_chain_to_wp_user = 'Registration.Event';
118
+		parent::__construct($timezone);
119
+
120
+	}
121
+
122
+
123
+	/**
124
+	 *    txn_status_array
125
+	 * get list of transaction statuses
126
+	 *
127
+	 * @access public
128
+	 * @return array
129
+	 */
130
+	public static function txn_status_array()
131
+	{
132
+		return apply_filters(
133
+			'FHEE__EEM_Transaction__txn_status_array',
134
+			array(
135
+				EEM_Transaction::overpaid_status_code,
136
+				EEM_Transaction::complete_status_code,
137
+				EEM_Transaction::incomplete_status_code,
138
+				EEM_Transaction::abandoned_status_code,
139
+				EEM_Transaction::failed_status_code,
140
+			)
141
+		);
142
+	}
143
+
144
+	/**
145
+	 *        get the revenue per day  for the Transaction Admin page Reports Tab
146
+	 *
147
+	 * @access        public
148
+	 *
149
+	 * @param string $period
150
+	 *
151
+	 * @return \stdClass[]
152
+	 */
153
+	public function get_revenue_per_day_report($period = '-1 month')
154
+	{
155
+		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
156
+			'Y-m-d H:i:s', 'UTC');
157
+
158
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
159
+
160
+		return $this->_get_all_wpdb_results(
161
+			array(
162
+				array(
163
+					'TXN_timestamp' => array('>=', $sql_date)
164
+				),
165
+				'group_by' => 'txnDate',
166
+				'order_by' => array('TXN_timestamp' => 'ASC')
167
+			),
168
+			OBJECT,
169
+			array(
170
+				'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
171
+				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
172
+			)
173
+		);
174
+	}
175
+
176
+
177
+	/**
178
+	 *        get the revenue per event  for the Transaction Admin page Reports Tab
179
+	 *
180
+	 * @access        public
181
+	 *
182
+	 * @param string $period
183
+	 *
184
+	 * @throws \EE_Error
185
+	 * @return mixed
186
+	 */
187
+	public function get_revenue_per_event_report($period = '-1 month')
188
+	{
189
+		global $wpdb;
190
+		$transaction_table       = $wpdb->prefix . 'esp_transaction';
191
+		$registration_table      = $wpdb->prefix . 'esp_registration';
192
+		$event_table             = $wpdb->posts;
193
+		$payment_table           = $wpdb->prefix . 'esp_payment';
194
+		$sql_date                = date('Y-m-d H:i:s', strtotime($period));
195
+		$approved_payment_status = EEM_Payment::status_id_approved;
196
+		$extra_event_on_join     = '';
197
+		//exclude events not authored by user if permissions in effect
198
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
199
+			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
200
+		}
201
+
202
+		return $wpdb->get_results(
203
+			"SELECT
204 204
 			Transaction_Event.event_name AS event_name,
205 205
 			SUM(Transaction_Event.paid) AS revenue
206 206
 			FROM
@@ -220,185 +220,185 @@  discard block
 block discarded – undo
220 220
 							$extra_event_on_join
221 221
 				) AS Transaction_Event
222 222
 			GROUP BY event_name",
223
-            OBJECT
224
-        );
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
230
-     * $_REQUEST global variable. Either way, tries to find the current transaction (through
231
-     * the registration pointed to by reg_url_link), if not returns null
232
-     *
233
-     * @param string $reg_url_link
234
-     *
235
-     * @return EE_Transaction
236
-     */
237
-    public function get_transaction_from_reg_url_link($reg_url_link = '')
238
-    {
239
-        return $this->get_one(array(
240
-            array(
241
-                'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
242
-                    '')
243
-            )
244
-        ));
245
-    }
246
-
247
-
248
-    /**
249
-     * Updates the provided EE_Transaction with all the applicable payments
250
-     * (or fetch the EE_Transaction from its ID)
251
-     *
252
-     * @deprecated
253
-     *
254
-     * @param EE_Transaction|int $transaction_obj_or_id
255
-     * @param boolean            $save_txn whether or not to save the transaction during this function call
256
-     *
257
-     * @return boolean
258
-     * @throws \EE_Error
259
-     */
260
-    public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
261
-    {
262
-        EE_Error::doing_it_wrong(
263
-            __CLASS__ . '::' . __FUNCTION__,
264
-            sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
265
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
266
-            '4.6.0'
267
-        );
268
-        /** @type EE_Transaction_Processor $transaction_processor */
269
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
270
-
271
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
272
-            $this->ensure_is_obj($transaction_obj_or_id)
273
-        );
274
-    }
275
-
276
-    /**
277
-     * Deletes "junk" transactions that were probably added by bots. There might be TONS
278
-     * of these, so we are very careful to NOT select (which the models do even when deleting),
279
-     * and so we only use wpdb directly and only do minimal joins.
280
-     * Transactions are considered "junk" if they're failed for longer than a week.
281
-     * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
282
-     * it, it's probably not junk (regardless of what status it has).
283
-     * The downside to this approach is that is addons are listening for object deletions
284
-     * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
285
-     * to catch these types of deletions.
286
-     *
287
-     * @global WPDB $wpdb
288
-     * @return mixed
289
-     */
290
-    public function delete_junk_transactions()
291
-    {
292
-        /** @type WPDB $wpdb */
293
-        global $wpdb;
294
-        $deleted             = false;
295
-        $time_to_leave_alone = apply_filters(
296
-            'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
297
-            , WEEK_IN_SECONDS
298
-        );
299
-
300
-
301
-        /**
302
-         * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
303
-         * Useful for plugins that want to exclude transactions matching certain query parameters.
304
-         * The query parameters should be in the format accepted by the EEM_Base model queries.
305
-         */
306
-        $ids_query = apply_filters(
307
-            'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
308
-            array(
309
-                0 => array(
310
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
311
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
312
-                    'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
313
-                )
314
-            ),
315
-            $time_to_leave_alone
316
-        );
317
-
318
-
319
-        /**
320
-         * This filter is for when code needs to filter the list of transaction ids that represent transactions
321
-         * about to be deleted based on some other criteria that isn't easily done via the query args filter.
322
-         */
323
-        $txn_ids = apply_filters(
324
-            'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
325
-            EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
326
-            $time_to_leave_alone
327
-        );
328
-        //now that we have the ids to delete
329
-        if (! empty($txn_ids) && is_array($txn_ids)) {
330
-            // first, make sure these TXN's are removed the "ee_locked_transactions" array
331
-            EEM_Transaction::unset_locked_transactions($txn_ids);
332
-            // let's get deletin'...
333
-            // Why no wpdb->prepare?  Because the data is trusted.
334
-            // We got the ids from the original query to get them FROM
335
-            // the db (which is sanitized) so no need to prepare them again.
336
-            $query   = '
223
+			OBJECT
224
+		);
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
230
+	 * $_REQUEST global variable. Either way, tries to find the current transaction (through
231
+	 * the registration pointed to by reg_url_link), if not returns null
232
+	 *
233
+	 * @param string $reg_url_link
234
+	 *
235
+	 * @return EE_Transaction
236
+	 */
237
+	public function get_transaction_from_reg_url_link($reg_url_link = '')
238
+	{
239
+		return $this->get_one(array(
240
+			array(
241
+				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
242
+					'')
243
+			)
244
+		));
245
+	}
246
+
247
+
248
+	/**
249
+	 * Updates the provided EE_Transaction with all the applicable payments
250
+	 * (or fetch the EE_Transaction from its ID)
251
+	 *
252
+	 * @deprecated
253
+	 *
254
+	 * @param EE_Transaction|int $transaction_obj_or_id
255
+	 * @param boolean            $save_txn whether or not to save the transaction during this function call
256
+	 *
257
+	 * @return boolean
258
+	 * @throws \EE_Error
259
+	 */
260
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
261
+	{
262
+		EE_Error::doing_it_wrong(
263
+			__CLASS__ . '::' . __FUNCTION__,
264
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
265
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
266
+			'4.6.0'
267
+		);
268
+		/** @type EE_Transaction_Processor $transaction_processor */
269
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
270
+
271
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
272
+			$this->ensure_is_obj($transaction_obj_or_id)
273
+		);
274
+	}
275
+
276
+	/**
277
+	 * Deletes "junk" transactions that were probably added by bots. There might be TONS
278
+	 * of these, so we are very careful to NOT select (which the models do even when deleting),
279
+	 * and so we only use wpdb directly and only do minimal joins.
280
+	 * Transactions are considered "junk" if they're failed for longer than a week.
281
+	 * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
282
+	 * it, it's probably not junk (regardless of what status it has).
283
+	 * The downside to this approach is that is addons are listening for object deletions
284
+	 * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
285
+	 * to catch these types of deletions.
286
+	 *
287
+	 * @global WPDB $wpdb
288
+	 * @return mixed
289
+	 */
290
+	public function delete_junk_transactions()
291
+	{
292
+		/** @type WPDB $wpdb */
293
+		global $wpdb;
294
+		$deleted             = false;
295
+		$time_to_leave_alone = apply_filters(
296
+			'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
297
+			, WEEK_IN_SECONDS
298
+		);
299
+
300
+
301
+		/**
302
+		 * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
303
+		 * Useful for plugins that want to exclude transactions matching certain query parameters.
304
+		 * The query parameters should be in the format accepted by the EEM_Base model queries.
305
+		 */
306
+		$ids_query = apply_filters(
307
+			'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
308
+			array(
309
+				0 => array(
310
+					'STS_ID'        => EEM_Transaction::failed_status_code,
311
+					'Payment.PAY_ID' => array( 'IS NULL' ),
312
+					'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
313
+				)
314
+			),
315
+			$time_to_leave_alone
316
+		);
317
+
318
+
319
+		/**
320
+		 * This filter is for when code needs to filter the list of transaction ids that represent transactions
321
+		 * about to be deleted based on some other criteria that isn't easily done via the query args filter.
322
+		 */
323
+		$txn_ids = apply_filters(
324
+			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
325
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
326
+			$time_to_leave_alone
327
+		);
328
+		//now that we have the ids to delete
329
+		if (! empty($txn_ids) && is_array($txn_ids)) {
330
+			// first, make sure these TXN's are removed the "ee_locked_transactions" array
331
+			EEM_Transaction::unset_locked_transactions($txn_ids);
332
+			// let's get deletin'...
333
+			// Why no wpdb->prepare?  Because the data is trusted.
334
+			// We got the ids from the original query to get them FROM
335
+			// the db (which is sanitized) so no need to prepare them again.
336
+			$query   = '
337 337
 				DELETE
338 338
 				FROM ' . $this->table() . '
339 339
 				WHERE
340 340
 					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
341
-            $deleted = $wpdb->query($query);
342
-        }
343
-        if ($deleted) {
344
-            /**
345
-             * Allows code to do something after the transactions have been deleted.
346
-             */
347
-            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
348
-        }
349
-
350
-        return $deleted;
351
-    }
352
-
353
-
354
-    /**
355
-     * @param array $transaction_IDs
356
-     *
357
-     * @return bool
358
-     */
359
-    public static function unset_locked_transactions(array $transaction_IDs)
360
-    {
361
-        $locked_transactions = get_option('ee_locked_transactions', array());
362
-        $update              = false;
363
-        foreach ($transaction_IDs as $TXN_ID) {
364
-            if (isset($locked_transactions[$TXN_ID])) {
365
-                unset($locked_transactions[$TXN_ID]);
366
-                $update = true;
367
-            }
368
-        }
369
-        if ($update) {
370
-            update_option('ee_locked_transactions', $locked_transactions);
371
-        }
372
-
373
-        return $update;
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * returns an array of EE_Transaction objects whose timestamp is less than
380
-     * the current time minus the session lifespan, which defaults to 60 minutes
381
-     *
382
-     * @return EE_Base_Class[]|EE_Transaction[]
383
-     * @throws \EE_Error
384
-     */
385
-    public function get_transactions_in_progress()
386
-    {
387
-        return $this->get_all(
388
-            array(
389
-                array(
390
-                    'TXN_timestamp' => array(
391
-                        '>',
392
-                        time() - EE_Registry::instance()->SSN->lifespan()
393
-                    ),
394
-                    'STS_ID' => array(
395
-                        '!=',
396
-                        EEM_Transaction::complete_status_code
397
-                    ),
398
-                )
399
-            )
400
-        );
401
-    }
341
+			$deleted = $wpdb->query($query);
342
+		}
343
+		if ($deleted) {
344
+			/**
345
+			 * Allows code to do something after the transactions have been deleted.
346
+			 */
347
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
348
+		}
349
+
350
+		return $deleted;
351
+	}
352
+
353
+
354
+	/**
355
+	 * @param array $transaction_IDs
356
+	 *
357
+	 * @return bool
358
+	 */
359
+	public static function unset_locked_transactions(array $transaction_IDs)
360
+	{
361
+		$locked_transactions = get_option('ee_locked_transactions', array());
362
+		$update              = false;
363
+		foreach ($transaction_IDs as $TXN_ID) {
364
+			if (isset($locked_transactions[$TXN_ID])) {
365
+				unset($locked_transactions[$TXN_ID]);
366
+				$update = true;
367
+			}
368
+		}
369
+		if ($update) {
370
+			update_option('ee_locked_transactions', $locked_transactions);
371
+		}
372
+
373
+		return $update;
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * returns an array of EE_Transaction objects whose timestamp is less than
380
+	 * the current time minus the session lifespan, which defaults to 60 minutes
381
+	 *
382
+	 * @return EE_Base_Class[]|EE_Transaction[]
383
+	 * @throws \EE_Error
384
+	 */
385
+	public function get_transactions_in_progress()
386
+	{
387
+		return $this->get_all(
388
+			array(
389
+				array(
390
+					'TXN_timestamp' => array(
391
+						'>',
392
+						time() - EE_Registry::instance()->SSN->lifespan()
393
+					),
394
+					'STS_ID' => array(
395
+						'!=',
396
+						EEM_Transaction::complete_status_code
397
+					),
398
+				)
399
+			)
400
+		);
401
+	}
402 402
 
403 403
 
404 404
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 1 patch
Indentation   +590 added lines, -590 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Class Datetime Model
@@ -11,595 +11,595 @@  discard block
 block discarded – undo
11 11
 class EEM_Datetime extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var EEM_Datetime $_instance
16
-     */
17
-    protected static $_instance;
18
-
19
-
20
-
21
-    /**
22
-     *        private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
-     *                         timezone in the 'timezone_string' wp option)
30
-     * @throws \EE_Error
31
-     */
32
-    protected function __construct($timezone)
33
-    {
34
-        $this->singular_item = __('Datetime', 'event_espresso');
35
-        $this->plural_item = __('Datetimes', 'event_espresso');
36
-        $this->_tables = array(
37
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
-        );
39
-        $this->_fields = array(
40
-            'Datetime' => array(
41
-                'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
-                    'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
-                ),
45
-                'DTT_name'        => new EE_Plain_Text_Field(
46
-                    'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
-                ),
48
-                'DTT_description' => new EE_Post_Content_Field(
49
-                    'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
-                ),
51
-                'DTT_EVT_start'   => new EE_Datetime_Field(
52
-                    'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
-                    $timezone
54
-                ),
55
-                'DTT_EVT_end'     => new EE_Datetime_Field(
56
-                    'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
-                    $timezone
58
-                ),
59
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
-                    'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
-                'DTT_sold'        => new EE_Integer_Field(
62
-                    'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
-                ),
64
-                'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
-                    __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
-                ),
67
-                'DTT_is_primary'  => new EE_Boolean_Field(
68
-                    'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
-                    false, false
70
-                ),
71
-                'DTT_order'       => new EE_Integer_Field(
72
-                    'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
-                ),
74
-                'DTT_parent'      => new EE_Integer_Field(
75
-                    'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
-                ),
77
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
-                    'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
-                ),
80
-            ),
81
-        );
82
-        $this->_model_relations = array(
83
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
-            'Event'   => new EE_Belongs_To_Relation(),
85
-            'Checkin' => new EE_Has_Many_Relation(),
86
-        );
87
-        $this->_model_chain_to_wp_user = 'Event';
88
-        //this model is generally available for reading
89
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
-            EEM_Base::caps_edit);
94
-        parent::__construct($timezone);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * create new blank datetime
101
-     *
102
-     * @access public
103
-     * @return EE_Datetime[] array on success, FALSE on fail
104
-     * @throws \EE_Error
105
-     */
106
-    public function create_new_blank_datetime()
107
-    {
108
-        //makes sure timezone is always set.
109
-        $timezone_string = $this->get_timezone();
110
-        $blank_datetime = EE_Datetime::new_instance(
111
-            array(
112
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
-                'DTT_order'     => 1,
115
-                'DTT_reg_limit' => EE_INF,
116
-            ),
117
-            $timezone_string
118
-        );
119
-        $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
-            $timezone_string));
121
-        $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
-        return array($blank_datetime);
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * get event start date from db
129
-     *
130
-     * @access public
131
-     * @param  int $EVT_ID
132
-     * @return EE_Datetime[] array on success, FALSE on fail
133
-     * @throws \EE_Error
134
-     */
135
-    public function get_all_event_dates($EVT_ID = 0)
136
-    {
137
-        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
-            return $this->create_new_blank_datetime();
139
-        }
140
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
-        if (empty($results)) {
142
-            return $this->create_new_blank_datetime();
143
-        }
144
-        return $results;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * get all datetimes attached to an event ordered by the DTT_order field
151
-     *
152
-     * @public
153
-     * @param  int    $EVT_ID     event id
154
-     * @param boolean $include_expired
155
-     * @param boolean $include_deleted
156
-     * @param  int    $limit      If included then limit the count of results by
157
-     *                            the given number
158
-     * @return EE_Datetime[]
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_datetimes_for_event_ordered_by_DTT_order(
162
-        $EVT_ID,
163
-        $include_expired = true,
164
-        $include_deleted = true,
165
-        $limit = null
166
-    ) {
167
-        //sanitize EVT_ID
168
-        $EVT_ID = absint($EVT_ID);
169
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
172
-        $query_params = ! empty($limit)
173
-            ? array(
174
-                $where_params,
175
-                'limit'                    => $limit,
176
-                'order_by'                 => array('DTT_order' => 'ASC'),
177
-                'default_where_conditions' => 'none',
178
-            )
179
-            : array(
180
-                $where_params,
181
-                'order_by'                 => array('DTT_order' => 'ASC'),
182
-                'default_where_conditions' => 'none',
183
-            );
184
-        if ( ! $include_expired) {
185
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
-        }
187
-        if ($include_deleted) {
188
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
-        }
190
-        /** @var EE_Datetime[] $result */
191
-        $result = $this->get_all($query_params);
192
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
193
-        return $result;
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
-     * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
-     * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
-     *
203
-     * @param int $EVT_ID
204
-     * @param int $limit
205
-     * @return EE_Datetime[]|EE_Base_Class[]
206
-     * @throws \EE_Error
207
-     */
208
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
-    {
210
-        return $this->get_all(
211
-            array(
212
-                array('Event.EVT_ID' => $EVT_ID),
213
-                'limit'                    => $limit,
214
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
-                'default_where_conditions' => 'none',
216
-            )
217
-        );
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * @param int     $EVT_ID
224
-     * @param boolean $include_expired
225
-     * @param boolean $include_deleted
226
-     * @return EE_Datetime
227
-     * @throws \EE_Error
228
-     */
229
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
-    {
231
-        $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
-        if ($results) {
233
-            return array_shift($results);
234
-        } else {
235
-            return null;
236
-        }
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * Gets the 'primary' datetime for an event.
243
-     *
244
-     * @param int  $EVT_ID
245
-     * @param bool $try_to_exclude_expired
246
-     * @param bool $try_to_exclude_deleted
247
-     * @return \EE_Datetime
248
-     * @throws \EE_Error
249
-     */
250
-    public function get_primary_datetime_for_event(
251
-        $EVT_ID,
252
-        $try_to_exclude_expired = true,
253
-        $try_to_exclude_deleted = true
254
-    ) {
255
-        if ($try_to_exclude_expired) {
256
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
-            if ($non_expired) {
258
-                return $non_expired;
259
-            }
260
-        }
261
-        if ($try_to_exclude_deleted) {
262
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
-            if ($expired_even) {
264
-                return $expired_even;
265
-            }
266
-        }
267
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
-     * only by start date
275
-     *
276
-     * @param int     $EVT_ID
277
-     * @param boolean $include_expired
278
-     * @param boolean $include_deleted
279
-     * @param int     $limit
280
-     * @return EE_Datetime[]
281
-     * @throws \EE_Error
282
-     */
283
-    public function get_datetimes_for_event_ordered_by_start_time(
284
-        $EVT_ID,
285
-        $include_expired = true,
286
-        $include_deleted = true,
287
-        $limit = null
288
-    ) {
289
-        //sanitize EVT_ID
290
-        $EVT_ID = absint($EVT_ID);
291
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
-        if ( ! $include_expired) {
295
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
-        }
297
-        if ($include_deleted) {
298
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
-        }
300
-        if ($limit) {
301
-            $query_params['limit'] = $limit;
302
-        }
303
-        /** @var EE_Datetime[] $result */
304
-        $result = $this->get_all($query_params);
305
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
306
-        return $result;
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
-     * only by start date
314
-     *
315
-     * @param int     $TKT_ID
316
-     * @param boolean $include_expired
317
-     * @param boolean $include_deleted
318
-     * @param int     $limit
319
-     * @return EE_Datetime[]
320
-     * @throws \EE_Error
321
-     */
322
-    public function get_datetimes_for_ticket_ordered_by_start_time(
323
-        $TKT_ID,
324
-        $include_expired = true,
325
-        $include_deleted = true,
326
-        $limit = null
327
-    ) {
328
-        //sanitize TKT_ID
329
-        $TKT_ID = absint($TKT_ID);
330
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
-        if ( ! $include_expired) {
334
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
-        }
336
-        if ($include_deleted) {
337
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
-        }
339
-        if ($limit) {
340
-            $query_params['limit'] = $limit;
341
-        }
342
-        /** @var EE_Datetime[] $result */
343
-        $result = $this->get_all($query_params);
344
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
345
-        return $result;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
-     * datetimes.
353
-     *
354
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
-     * @param  boolean  $include_expired whether to include expired datetimes or not
356
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
-     * @param  int|null $limit           if null, no limit, if int then limit results by
358
-     *                                   that number
359
-     * @return EE_Datetime[]
360
-     * @throws \EE_Error
361
-     */
362
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
-        $TKT_ID,
364
-        $include_expired = true,
365
-        $include_deleted = true,
366
-        $limit = null
367
-    ) {
368
-        //sanitize id.
369
-        $TKT_ID = absint($TKT_ID);
370
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
-        if ( ! $include_expired) {
375
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
-        }
377
-        if ($include_deleted) {
378
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
-        }
380
-        if ($limit) {
381
-            $query_params['limit'] = $limit;
382
-        }
383
-        /** @var EE_Datetime[] $result */
384
-        $result = $this->get_all($query_params);
385
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
386
-        return $result;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
-     * reason it doesn't exist, we consider the earliest event the most important)
394
-     *
395
-     * @param int $EVT_ID
396
-     * @return EE_Datetime
397
-     * @throws \EE_Error
398
-     */
399
-    public function get_most_important_datetime_for_event($EVT_ID)
400
-    {
401
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
-        if ($results) {
403
-            return array_shift($results);
404
-        } else {
405
-            return null;
406
-        }
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
-     * grouped by month and year.
414
-     *
415
-     * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
-     *                                   Can be:
418
-     *                                   - '' = no filter
419
-     *                                   - upcoming = Published events with at least one upcoming datetime.
420
-     *                                   - expired = Events with all datetimes expired.
421
-     *                                   - active = Events that are published and have at least one datetime that
422
-     *                                   starts before now and ends after now.
423
-     *                                   - inactive = Events that are either not published.
424
-     * @return EE_Base_Class[]
425
-     * @throws \EE_Error
426
-     */
427
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
-    {
429
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
-        $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
-        switch ($evt_active_status) {
432
-            case 'upcoming' :
433
-                $where_params['Event.status'] = 'publish';
434
-                //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
-                if (isset($where_params['DTT_EVT_start'])) {
436
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
-                }
438
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
-                break;
440
-            case 'expired' :
441
-                if (isset($where_params['Event.status'])) {
442
-                    unset($where_params['Event.status']);
443
-                }
444
-                //get events to exclude
445
-                $exclude_query[0] = array_merge($where_params,
446
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
-                //first get all events that have datetimes where its not expired.
448
-                $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
-                $event_ids = array_keys($event_ids);
450
-                if (isset($where_params['DTT_EVT_end'])) {
451
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
-                }
453
-                $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
-                break;
456
-            case 'active' :
457
-                $where_params['Event.status'] = 'publish';
458
-                if (isset($where_params['DTT_EVT_start'])) {
459
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
-                }
461
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
-                }
464
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
-                $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
-                break;
467
-            case 'inactive' :
468
-                if (isset($where_params['Event.status'])) {
469
-                    unset($where_params['Event.status']);
470
-                }
471
-                if (isset($where_params['OR'])) {
472
-                    $where_params['AND']['OR'] = $where_params['OR'];
473
-                }
474
-                if (isset($where_params['DTT_EVT_end'])) {
475
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
-                    unset($where_params['DTT_EVT_end']);
477
-                }
478
-                if (isset($where_params['DTT_EVT_start'])) {
479
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
-                    unset($where_params['DTT_EVT_start']);
481
-                }
482
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
483
-                break;
484
-        }
485
-        $query_params[0] = $where_params;
486
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
487
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
-        $columns_to_select = array(
490
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
-        );
494
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
501
-     * for the tickets for each datetime)
502
-     *
503
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
504
-     * @throws \EE_Error
505
-     */
506
-    public function update_sold($datetimes)
507
-    {
508
-        EE_Error::doing_it_wrong(
509
-            __FUNCTION__,
510
-            esc_html__(
511
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
512
-                'event_espresso'
513
-            ),
514
-            '4.9.32.rc.005'
515
-        );
516
-        foreach ($datetimes as $datetime) {
517
-            $datetime->update_sold();
518
-        }
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     *    Gets the total number of tickets available at a particular datetime
525
-     *    (does NOT take into account the datetime's spaces available)
526
-     *
527
-     * @param int   $DTT_ID
528
-     * @param array $query_params
529
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
530
-     *             tickets attached to datetime then FALSE is returned.
531
-     */
532
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
533
-    {
534
-        $datetime = $this->get_one_by_ID($DTT_ID);
535
-        if ($datetime instanceof EE_Datetime) {
536
-            return $datetime->tickets_remaining($query_params);
537
-        }
538
-        return 0;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
545
-     *
546
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
547
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
548
-     *                                 for all valid stati.
549
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
550
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
551
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
552
-     * @throws \EE_Error
553
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
554
-     */
555
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
556
-    {
557
-        //only accept where conditions for this query.
558
-        $_where = isset($query_params[0]) ? $query_params[0] : array();
559
-        $status_query_args = array(
560
-            EE_Datetime::active   => array_merge(
561
-                $_where,
562
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
563
-            ),
564
-            EE_Datetime::upcoming => array_merge(
565
-                $_where,
566
-                array('DTT_EVT_start' => array('>', time()))
567
-            ),
568
-            EE_Datetime::expired  => array_merge(
569
-                $_where,
570
-                array('DTT_EVT_end' => array('<', time()))
571
-            ),
572
-        );
573
-        if ( ! empty($stati_to_include)) {
574
-            foreach (array_keys($status_query_args) as $status) {
575
-                if ( ! in_array($status, $stati_to_include, true)) {
576
-                    unset($status_query_args[$status]);
577
-                }
578
-            }
579
-        }
580
-        //loop through and query counts for each stati.
581
-        $status_query_results = array();
582
-        foreach ($status_query_args as $status => $status_where_conditions) {
583
-            $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
584
-        }
585
-        return $status_query_results;
586
-    }
587
-
588
-
589
-
590
-    /**
591
-     * Returns the specific count for a given Datetime status matching any given query_params.
592
-     *
593
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
594
-     * @param array  $query_params
595
-     * @return int
596
-     * @throws \EE_Error
597
-     */
598
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
599
-    {
600
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
601
-        return ! empty($count[$status]) ? $count[$status] : 0;
602
-    }
14
+	/**
15
+	 * @var EEM_Datetime $_instance
16
+	 */
17
+	protected static $_instance;
18
+
19
+
20
+
21
+	/**
22
+	 *        private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
+	 *                         timezone in the 'timezone_string' wp option)
30
+	 * @throws \EE_Error
31
+	 */
32
+	protected function __construct($timezone)
33
+	{
34
+		$this->singular_item = __('Datetime', 'event_espresso');
35
+		$this->plural_item = __('Datetimes', 'event_espresso');
36
+		$this->_tables = array(
37
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
+		);
39
+		$this->_fields = array(
40
+			'Datetime' => array(
41
+				'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
+					'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
+				),
45
+				'DTT_name'        => new EE_Plain_Text_Field(
46
+					'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
+				),
48
+				'DTT_description' => new EE_Post_Content_Field(
49
+					'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
+				),
51
+				'DTT_EVT_start'   => new EE_Datetime_Field(
52
+					'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
+					$timezone
54
+				),
55
+				'DTT_EVT_end'     => new EE_Datetime_Field(
56
+					'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
+					$timezone
58
+				),
59
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
+					'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
+				'DTT_sold'        => new EE_Integer_Field(
62
+					'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
+				),
64
+				'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
+					__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
+				),
67
+				'DTT_is_primary'  => new EE_Boolean_Field(
68
+					'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
+					false, false
70
+				),
71
+				'DTT_order'       => new EE_Integer_Field(
72
+					'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
+				),
74
+				'DTT_parent'      => new EE_Integer_Field(
75
+					'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
+				),
77
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
+					'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
+				),
80
+			),
81
+		);
82
+		$this->_model_relations = array(
83
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
+			'Event'   => new EE_Belongs_To_Relation(),
85
+			'Checkin' => new EE_Has_Many_Relation(),
86
+		);
87
+		$this->_model_chain_to_wp_user = 'Event';
88
+		//this model is generally available for reading
89
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
+			EEM_Base::caps_edit);
94
+		parent::__construct($timezone);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * create new blank datetime
101
+	 *
102
+	 * @access public
103
+	 * @return EE_Datetime[] array on success, FALSE on fail
104
+	 * @throws \EE_Error
105
+	 */
106
+	public function create_new_blank_datetime()
107
+	{
108
+		//makes sure timezone is always set.
109
+		$timezone_string = $this->get_timezone();
110
+		$blank_datetime = EE_Datetime::new_instance(
111
+			array(
112
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
+				'DTT_order'     => 1,
115
+				'DTT_reg_limit' => EE_INF,
116
+			),
117
+			$timezone_string
118
+		);
119
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
+			$timezone_string));
121
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
+		return array($blank_datetime);
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * get event start date from db
129
+	 *
130
+	 * @access public
131
+	 * @param  int $EVT_ID
132
+	 * @return EE_Datetime[] array on success, FALSE on fail
133
+	 * @throws \EE_Error
134
+	 */
135
+	public function get_all_event_dates($EVT_ID = 0)
136
+	{
137
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
+			return $this->create_new_blank_datetime();
139
+		}
140
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
+		if (empty($results)) {
142
+			return $this->create_new_blank_datetime();
143
+		}
144
+		return $results;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * get all datetimes attached to an event ordered by the DTT_order field
151
+	 *
152
+	 * @public
153
+	 * @param  int    $EVT_ID     event id
154
+	 * @param boolean $include_expired
155
+	 * @param boolean $include_deleted
156
+	 * @param  int    $limit      If included then limit the count of results by
157
+	 *                            the given number
158
+	 * @return EE_Datetime[]
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_datetimes_for_event_ordered_by_DTT_order(
162
+		$EVT_ID,
163
+		$include_expired = true,
164
+		$include_deleted = true,
165
+		$limit = null
166
+	) {
167
+		//sanitize EVT_ID
168
+		$EVT_ID = absint($EVT_ID);
169
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
172
+		$query_params = ! empty($limit)
173
+			? array(
174
+				$where_params,
175
+				'limit'                    => $limit,
176
+				'order_by'                 => array('DTT_order' => 'ASC'),
177
+				'default_where_conditions' => 'none',
178
+			)
179
+			: array(
180
+				$where_params,
181
+				'order_by'                 => array('DTT_order' => 'ASC'),
182
+				'default_where_conditions' => 'none',
183
+			);
184
+		if ( ! $include_expired) {
185
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
+		}
187
+		if ($include_deleted) {
188
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
+		}
190
+		/** @var EE_Datetime[] $result */
191
+		$result = $this->get_all($query_params);
192
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
193
+		return $result;
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
+	 * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
+	 * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
+	 *
203
+	 * @param int $EVT_ID
204
+	 * @param int $limit
205
+	 * @return EE_Datetime[]|EE_Base_Class[]
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
+	{
210
+		return $this->get_all(
211
+			array(
212
+				array('Event.EVT_ID' => $EVT_ID),
213
+				'limit'                    => $limit,
214
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
+				'default_where_conditions' => 'none',
216
+			)
217
+		);
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * @param int     $EVT_ID
224
+	 * @param boolean $include_expired
225
+	 * @param boolean $include_deleted
226
+	 * @return EE_Datetime
227
+	 * @throws \EE_Error
228
+	 */
229
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
+	{
231
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
+		if ($results) {
233
+			return array_shift($results);
234
+		} else {
235
+			return null;
236
+		}
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * Gets the 'primary' datetime for an event.
243
+	 *
244
+	 * @param int  $EVT_ID
245
+	 * @param bool $try_to_exclude_expired
246
+	 * @param bool $try_to_exclude_deleted
247
+	 * @return \EE_Datetime
248
+	 * @throws \EE_Error
249
+	 */
250
+	public function get_primary_datetime_for_event(
251
+		$EVT_ID,
252
+		$try_to_exclude_expired = true,
253
+		$try_to_exclude_deleted = true
254
+	) {
255
+		if ($try_to_exclude_expired) {
256
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
+			if ($non_expired) {
258
+				return $non_expired;
259
+			}
260
+		}
261
+		if ($try_to_exclude_deleted) {
262
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
+			if ($expired_even) {
264
+				return $expired_even;
265
+			}
266
+		}
267
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
+	 * only by start date
275
+	 *
276
+	 * @param int     $EVT_ID
277
+	 * @param boolean $include_expired
278
+	 * @param boolean $include_deleted
279
+	 * @param int     $limit
280
+	 * @return EE_Datetime[]
281
+	 * @throws \EE_Error
282
+	 */
283
+	public function get_datetimes_for_event_ordered_by_start_time(
284
+		$EVT_ID,
285
+		$include_expired = true,
286
+		$include_deleted = true,
287
+		$limit = null
288
+	) {
289
+		//sanitize EVT_ID
290
+		$EVT_ID = absint($EVT_ID);
291
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
+		if ( ! $include_expired) {
295
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
+		}
297
+		if ($include_deleted) {
298
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
+		}
300
+		if ($limit) {
301
+			$query_params['limit'] = $limit;
302
+		}
303
+		/** @var EE_Datetime[] $result */
304
+		$result = $this->get_all($query_params);
305
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
306
+		return $result;
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
+	 * only by start date
314
+	 *
315
+	 * @param int     $TKT_ID
316
+	 * @param boolean $include_expired
317
+	 * @param boolean $include_deleted
318
+	 * @param int     $limit
319
+	 * @return EE_Datetime[]
320
+	 * @throws \EE_Error
321
+	 */
322
+	public function get_datetimes_for_ticket_ordered_by_start_time(
323
+		$TKT_ID,
324
+		$include_expired = true,
325
+		$include_deleted = true,
326
+		$limit = null
327
+	) {
328
+		//sanitize TKT_ID
329
+		$TKT_ID = absint($TKT_ID);
330
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
+		if ( ! $include_expired) {
334
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
+		}
336
+		if ($include_deleted) {
337
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
+		}
339
+		if ($limit) {
340
+			$query_params['limit'] = $limit;
341
+		}
342
+		/** @var EE_Datetime[] $result */
343
+		$result = $this->get_all($query_params);
344
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
345
+		return $result;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
+	 * datetimes.
353
+	 *
354
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
356
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
358
+	 *                                   that number
359
+	 * @return EE_Datetime[]
360
+	 * @throws \EE_Error
361
+	 */
362
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
+		$TKT_ID,
364
+		$include_expired = true,
365
+		$include_deleted = true,
366
+		$limit = null
367
+	) {
368
+		//sanitize id.
369
+		$TKT_ID = absint($TKT_ID);
370
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
+		if ( ! $include_expired) {
375
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
+		}
377
+		if ($include_deleted) {
378
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
+		}
380
+		if ($limit) {
381
+			$query_params['limit'] = $limit;
382
+		}
383
+		/** @var EE_Datetime[] $result */
384
+		$result = $this->get_all($query_params);
385
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
386
+		return $result;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
+	 * reason it doesn't exist, we consider the earliest event the most important)
394
+	 *
395
+	 * @param int $EVT_ID
396
+	 * @return EE_Datetime
397
+	 * @throws \EE_Error
398
+	 */
399
+	public function get_most_important_datetime_for_event($EVT_ID)
400
+	{
401
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
+		if ($results) {
403
+			return array_shift($results);
404
+		} else {
405
+			return null;
406
+		}
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
+	 * grouped by month and year.
414
+	 *
415
+	 * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
+	 *                                   Can be:
418
+	 *                                   - '' = no filter
419
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
420
+	 *                                   - expired = Events with all datetimes expired.
421
+	 *                                   - active = Events that are published and have at least one datetime that
422
+	 *                                   starts before now and ends after now.
423
+	 *                                   - inactive = Events that are either not published.
424
+	 * @return EE_Base_Class[]
425
+	 * @throws \EE_Error
426
+	 */
427
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
+	{
429
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
+		switch ($evt_active_status) {
432
+			case 'upcoming' :
433
+				$where_params['Event.status'] = 'publish';
434
+				//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
+				if (isset($where_params['DTT_EVT_start'])) {
436
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
+				}
438
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
+				break;
440
+			case 'expired' :
441
+				if (isset($where_params['Event.status'])) {
442
+					unset($where_params['Event.status']);
443
+				}
444
+				//get events to exclude
445
+				$exclude_query[0] = array_merge($where_params,
446
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
+				//first get all events that have datetimes where its not expired.
448
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
+				$event_ids = array_keys($event_ids);
450
+				if (isset($where_params['DTT_EVT_end'])) {
451
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
+				}
453
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
+				break;
456
+			case 'active' :
457
+				$where_params['Event.status'] = 'publish';
458
+				if (isset($where_params['DTT_EVT_start'])) {
459
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
+				}
461
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
+				}
464
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
+				break;
467
+			case 'inactive' :
468
+				if (isset($where_params['Event.status'])) {
469
+					unset($where_params['Event.status']);
470
+				}
471
+				if (isset($where_params['OR'])) {
472
+					$where_params['AND']['OR'] = $where_params['OR'];
473
+				}
474
+				if (isset($where_params['DTT_EVT_end'])) {
475
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
+					unset($where_params['DTT_EVT_end']);
477
+				}
478
+				if (isset($where_params['DTT_EVT_start'])) {
479
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
+					unset($where_params['DTT_EVT_start']);
481
+				}
482
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
483
+				break;
484
+		}
485
+		$query_params[0] = $where_params;
486
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
487
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
+		$columns_to_select = array(
490
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
+		);
494
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
501
+	 * for the tickets for each datetime)
502
+	 *
503
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
504
+	 * @throws \EE_Error
505
+	 */
506
+	public function update_sold($datetimes)
507
+	{
508
+		EE_Error::doing_it_wrong(
509
+			__FUNCTION__,
510
+			esc_html__(
511
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
512
+				'event_espresso'
513
+			),
514
+			'4.9.32.rc.005'
515
+		);
516
+		foreach ($datetimes as $datetime) {
517
+			$datetime->update_sold();
518
+		}
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 *    Gets the total number of tickets available at a particular datetime
525
+	 *    (does NOT take into account the datetime's spaces available)
526
+	 *
527
+	 * @param int   $DTT_ID
528
+	 * @param array $query_params
529
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
530
+	 *             tickets attached to datetime then FALSE is returned.
531
+	 */
532
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
533
+	{
534
+		$datetime = $this->get_one_by_ID($DTT_ID);
535
+		if ($datetime instanceof EE_Datetime) {
536
+			return $datetime->tickets_remaining($query_params);
537
+		}
538
+		return 0;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
545
+	 *
546
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
547
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
548
+	 *                                 for all valid stati.
549
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
550
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
551
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
552
+	 * @throws \EE_Error
553
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
554
+	 */
555
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
556
+	{
557
+		//only accept where conditions for this query.
558
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
559
+		$status_query_args = array(
560
+			EE_Datetime::active   => array_merge(
561
+				$_where,
562
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
563
+			),
564
+			EE_Datetime::upcoming => array_merge(
565
+				$_where,
566
+				array('DTT_EVT_start' => array('>', time()))
567
+			),
568
+			EE_Datetime::expired  => array_merge(
569
+				$_where,
570
+				array('DTT_EVT_end' => array('<', time()))
571
+			),
572
+		);
573
+		if ( ! empty($stati_to_include)) {
574
+			foreach (array_keys($status_query_args) as $status) {
575
+				if ( ! in_array($status, $stati_to_include, true)) {
576
+					unset($status_query_args[$status]);
577
+				}
578
+			}
579
+		}
580
+		//loop through and query counts for each stati.
581
+		$status_query_results = array();
582
+		foreach ($status_query_args as $status => $status_where_conditions) {
583
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
584
+		}
585
+		return $status_query_results;
586
+	}
587
+
588
+
589
+
590
+	/**
591
+	 * Returns the specific count for a given Datetime status matching any given query_params.
592
+	 *
593
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
594
+	 * @param array  $query_params
595
+	 * @return int
596
+	 * @throws \EE_Error
597
+	 */
598
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
599
+	{
600
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
601
+		return ! empty($count[$status]) ? $count[$status] : 0;
602
+	}
603 603
 
604 604
 
605 605
 
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 2 patches
Indentation   +582 added lines, -582 removed lines patch added patch discarded remove patch
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * @param array  $props_n_values          incoming values
66
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
-     *                                        used.)
68
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
-     *                                        date_format and the second value is the time format
70
-     * @return EE_Ticket
71
-     * @throws \EE_Error
72
-     */
64
+	/**
65
+	 * @param array  $props_n_values          incoming values
66
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
+	 *                                        used.)
68
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
+	 *                                        date_format and the second value is the time format
70
+	 * @return EE_Ticket
71
+	 * @throws \EE_Error
72
+	 */
73 73
 	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74 74
 		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75 75
 		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
@@ -77,36 +77,36 @@  discard block
 block discarded – undo
77 77
 
78 78
 
79 79
 
80
-    /**
81
-     * @param array  $props_n_values  incoming values from the database
82
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
-     *                                the website will be used.
84
-     * @return EE_Ticket
85
-     * @throws \EE_Error
86
-     */
80
+	/**
81
+	 * @param array  $props_n_values  incoming values from the database
82
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
+	 *                                the website will be used.
84
+	 * @return EE_Ticket
85
+	 * @throws \EE_Error
86
+	 */
87 87
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88 88
 		return new self( $props_n_values, TRUE, $timezone );
89 89
 	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     * @throws \EE_Error
96
-     */
93
+	/**
94
+	 * @return bool
95
+	 * @throws \EE_Error
96
+	 */
97 97
 	public function parent() {
98 98
 		return $this->get( 'TKT_parent' );
99 99
 	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * return if a ticket has quantities available for purchase
105
-     *
106
-     * @param  int $DTT_ID the primary key for a particular datetime
107
-     * @return boolean
108
-     * @throws \EE_Error
109
-     */
103
+	/**
104
+	 * return if a ticket has quantities available for purchase
105
+	 *
106
+	 * @param  int $DTT_ID the primary key for a particular datetime
107
+	 * @return boolean
108
+	 * @throws \EE_Error
109
+	 */
110 110
 	public function available( $DTT_ID = 0 ) {
111 111
 		// are we checking availability for a particular datetime ?
112 112
 		if ( $DTT_ID ) {
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
-     *
129
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
-     * @return mixed status int if the display string isn't requested
132
-     * @throws \EE_Error
133
-     */
126
+	/**
127
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
+	 *
129
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
+	 * @return mixed status int if the display string isn't requested
132
+	 * @throws \EE_Error
133
+	 */
134 134
 	public function ticket_status( $display = FALSE, $remaining = null ) {
135 135
 		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136 136
 		if ( ! $remaining ) {
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
-     *
159
-     * @access public
160
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
-     * @return boolean         true = tickets remaining, false not.
162
-     * @throws \EE_Error
163
-     */
156
+	/**
157
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
+	 *
159
+	 * @access public
160
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
+	 * @return boolean         true = tickets remaining, false not.
162
+	 * @throws \EE_Error
163
+	 */
164 164
 	public function is_remaining( $DTT_ID = 0 ) {
165 165
 		$num_remaining = $this->remaining( $DTT_ID );
166 166
 		if ( $num_remaining === 0 ) {
@@ -174,76 +174,76 @@  discard block
 block discarded – undo
174 174
 
175 175
 
176 176
 
177
-    /**
178
-     * return the total number of tickets available for purchase
179
-     *
180
-     * @param  int $DTT_ID the primary key for a particular datetime.
181
-     *                     set to 0 for all related datetimes
182
-     * @return int
183
-     * @throws \EE_Error
184
-     */
177
+	/**
178
+	 * return the total number of tickets available for purchase
179
+	 *
180
+	 * @param  int $DTT_ID the primary key for a particular datetime.
181
+	 *                     set to 0 for all related datetimes
182
+	 * @return int
183
+	 * @throws \EE_Error
184
+	 */
185 185
 	public function remaining( $DTT_ID = 0 ) {
186 186
 		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
187 187
 	}
188 188
 
189 189
 
190 190
 
191
-    /**
192
-     * Gets min
193
-     *
194
-     * @return int
195
-     * @throws \EE_Error
196
-     */
191
+	/**
192
+	 * Gets min
193
+	 *
194
+	 * @return int
195
+	 * @throws \EE_Error
196
+	 */
197 197
 	public function min() {
198 198
 		return $this->get( 'TKT_min' );
199 199
 	}
200 200
 
201 201
 
202 202
 
203
-    /**
204
-     * return if a ticket is no longer available cause its available dates have expired.
205
-     *
206
-     * @return boolean
207
-     * @throws \EE_Error
208
-     */
203
+	/**
204
+	 * return if a ticket is no longer available cause its available dates have expired.
205
+	 *
206
+	 * @return boolean
207
+	 * @throws \EE_Error
208
+	 */
209 209
 	public function is_expired() {
210 210
 		return ( $this->get_raw( 'TKT_end_date' ) < time() );
211 211
 	}
212 212
 
213 213
 
214 214
 
215
-    /**
216
-     * Return if a ticket is yet to go on sale or not
217
-     *
218
-     * @return boolean
219
-     * @throws \EE_Error
220
-     */
215
+	/**
216
+	 * Return if a ticket is yet to go on sale or not
217
+	 *
218
+	 * @return boolean
219
+	 * @throws \EE_Error
220
+	 */
221 221
 	public function is_pending() {
222 222
 		return ( $this->get_raw( 'TKT_start_date' ) > time() );
223 223
 	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Return if a ticket is on sale or not
229
-     *
230
-     * @return boolean
231
-     * @throws \EE_Error
232
-     */
227
+	/**
228
+	 * Return if a ticket is on sale or not
229
+	 *
230
+	 * @return boolean
231
+	 * @throws \EE_Error
232
+	 */
233 233
 	public function is_on_sale() {
234 234
 		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
235 235
 	}
236 236
 
237 237
 
238 238
 
239
-    /**
240
-     * This returns the chronologically last datetime that this ticket is associated with
241
-     *
242
-     * @param string $dt_frmt
243
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
-     * @return string
245
-     * @throws \EE_Error
246
-     */
239
+	/**
240
+	 * This returns the chronologically last datetime that this ticket is associated with
241
+	 *
242
+	 * @param string $dt_frmt
243
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
+	 * @return string
245
+	 * @throws \EE_Error
246
+	 */
247 247
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248 248
 		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249 249
 		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     * This returns the chronologically first datetime that this ticket is associated with
258
-     *
259
-     * @return EE_Datetime
260
-     * @throws \EE_Error
261
-     */
256
+	/**
257
+	 * This returns the chronologically first datetime that this ticket is associated with
258
+	 *
259
+	 * @return EE_Datetime
260
+	 * @throws \EE_Error
261
+	 */
262 262
 	public function first_datetime() {
263 263
 		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264 264
 		return reset( $datetimes );
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 
267 267
 
268 268
 
269
-    /**
270
-     * Gets all the datetimes this ticket can be used for attending.
271
-     * Unless otherwise specified, orders datetimes by start date.
272
-     *
273
-     * @param array $query_params see EEM_Base::get_all()
274
-     * @return EE_Datetime[]|EE_Base_Class[]
275
-     * @throws \EE_Error
276
-     */
269
+	/**
270
+	 * Gets all the datetimes this ticket can be used for attending.
271
+	 * Unless otherwise specified, orders datetimes by start date.
272
+	 *
273
+	 * @param array $query_params see EEM_Base::get_all()
274
+	 * @return EE_Datetime[]|EE_Base_Class[]
275
+	 * @throws \EE_Error
276
+	 */
277 277
 	public function datetimes( $query_params = array() ) {
278 278
 		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279 279
 			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
 
284 284
 
285 285
 
286
-    /**
287
-     * This returns the chronologically last datetime that this ticket is associated with
288
-     *
289
-     * @return EE_Datetime
290
-     * @throws \EE_Error
291
-     */
286
+	/**
287
+	 * This returns the chronologically last datetime that this ticket is associated with
288
+	 *
289
+	 * @return EE_Datetime
290
+	 * @throws \EE_Error
291
+	 */
292 292
 	public function last_datetime() {
293 293
 		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294 294
 		return end( $datetimes );
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
 
297 297
 
298 298
 
299
-    /**
300
-     * This returns the total tickets sold depending on the given parameters.
301
-     *
302
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
306
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
-     * @return mixed (array|int)          how many tickets have sold
310
-     * @throws \EE_Error
311
-     */
299
+	/**
300
+	 * This returns the total tickets sold depending on the given parameters.
301
+	 *
302
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
306
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
+	 * @return mixed (array|int)          how many tickets have sold
310
+	 * @throws \EE_Error
311
+	 */
312 312
 	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 
334 334
 
335 335
 
336
-    /**
337
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
-     *
339
-     * @return EE_Ticket[]
340
-     * @throws \EE_Error
341
-     */
336
+	/**
337
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
+	 *
339
+	 * @return EE_Ticket[]
340
+	 * @throws \EE_Error
341
+	 */
342 342
 	protected function _all_tickets_sold() {
343 343
 		$datetimes = $this->get_many_related( 'Datetime' );
344 344
 		$tickets_sold = array();
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
 
356 356
 
357
-    /**
358
-     * This returns the base price object for the ticket.
359
-     *
360
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
-     * @throws \EE_Error
363
-     */
357
+	/**
358
+	 * This returns the base price object for the ticket.
359
+	 *
360
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
+	 * @throws \EE_Error
363
+	 */
364 364
 	public function base_price( $return_array = FALSE ) {
365 365
 		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+			? $this->get_many_related( 'Price', array( $_where ) )
368
+			: $this->get_first_related( 'Price', array( $_where ) );
369 369
 	}
370 370
 
371 371
 
372 372
 
373
-    /**
374
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
-     *
376
-     * @access public
377
-     * @return EE_Price[]
378
-     * @throws \EE_Error
379
-     */
373
+	/**
374
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
+	 *
376
+	 * @access public
377
+	 * @return EE_Price[]
378
+	 * @throws \EE_Error
379
+	 */
380 380
 	public function price_modifiers() {
381 381
 		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382 382
 		return $this->prices( $query_params );
@@ -384,132 +384,132 @@  discard block
 block discarded – undo
384 384
 
385 385
 
386 386
 
387
-    /**
388
-     * Gets all the prices that combine to form the final price of this ticket
389
-     *
390
-     * @param array $query_params like EEM_Base::get_all
391
-     * @return EE_Price[]|EE_Base_Class[]
392
-     * @throws \EE_Error
393
-     */
387
+	/**
388
+	 * Gets all the prices that combine to form the final price of this ticket
389
+	 *
390
+	 * @param array $query_params like EEM_Base::get_all
391
+	 * @return EE_Price[]|EE_Base_Class[]
392
+	 * @throws \EE_Error
393
+	 */
394 394
 	public function prices( $query_params = array() ) {
395 395
 		return $this->get_many_related( 'Price', $query_params );
396 396
 	}
397 397
 
398 398
 
399 399
 
400
-    /**
401
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
-     *
403
-     * @param array $query_params see EEM_Base::get_all()
404
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
405
-     * @throws \EE_Error
406
-     */
400
+	/**
401
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
+	 *
403
+	 * @param array $query_params see EEM_Base::get_all()
404
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
405
+	 * @throws \EE_Error
406
+	 */
407 407
 	public function datetime_tickets( $query_params = array() ) {
408 408
 		return $this->get_many_related( 'Datetime_Ticket', $query_params );
409 409
 	}
410 410
 
411 411
 
412 412
 
413
-    /**
414
-     * Gets all the datetimes from the db ordered by DTT_order
415
-     *
416
-     * @param boolean $show_expired
417
-     * @param boolean $show_deleted
418
-     * @return EE_Datetime[]
419
-     * @throws \EE_Error
420
-     */
413
+	/**
414
+	 * Gets all the datetimes from the db ordered by DTT_order
415
+	 *
416
+	 * @param boolean $show_expired
417
+	 * @param boolean $show_deleted
418
+	 * @return EE_Datetime[]
419
+	 * @throws \EE_Error
420
+	 */
421 421
 	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422 422
 		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
423 423
 	}
424 424
 
425 425
 
426 426
 
427
-    /**
428
-     * Gets ID
429
-     *
430
-     * @return string
431
-     * @throws \EE_Error
432
-     */
427
+	/**
428
+	 * Gets ID
429
+	 *
430
+	 * @return string
431
+	 * @throws \EE_Error
432
+	 */
433 433
 	public function ID() {
434 434
 		return $this->get( 'TKT_ID' );
435 435
 	}
436 436
 
437 437
 
438 438
 
439
-    /**
440
-     * get the author of the ticket.
441
-     *
442
-     * @since 4.5.0
443
-     * @return int
444
-     * @throws \EE_Error
445
-     */
439
+	/**
440
+	 * get the author of the ticket.
441
+	 *
442
+	 * @since 4.5.0
443
+	 * @return int
444
+	 * @throws \EE_Error
445
+	 */
446 446
 	public function wp_user() {
447 447
 		return $this->get('TKT_wp_user');
448 448
 	}
449 449
 
450 450
 
451 451
 
452
-    /**
453
-     * Gets the template for the ticket
454
-     *
455
-     * @return EE_Ticket_Template|EE_Base_Class
456
-     * @throws \EE_Error
457
-     */
452
+	/**
453
+	 * Gets the template for the ticket
454
+	 *
455
+	 * @return EE_Ticket_Template|EE_Base_Class
456
+	 * @throws \EE_Error
457
+	 */
458 458
 	public function template() {
459 459
 		return $this->get_first_related( 'Ticket_Template' );
460 460
 	}
461 461
 
462 462
 
463 463
 
464
-    /**
465
-     * Simply returns an array of EE_Price objects that are taxes.
466
-     *
467
-     * @return EE_Price[]
468
-     * @throws \EE_Error
469
-     */
464
+	/**
465
+	 * Simply returns an array of EE_Price objects that are taxes.
466
+	 *
467
+	 * @return EE_Price[]
468
+	 * @throws \EE_Error
469
+	 */
470 470
 	public function get_ticket_taxes_for_admin() {
471 471
 		return EE_Taxes::get_taxes_for_admin();
472 472
 	}
473 473
 
474 474
 
475 475
 
476
-    /**
477
-     * @return float
478
-     * @throws \EE_Error
479
-     */
476
+	/**
477
+	 * @return float
478
+	 * @throws \EE_Error
479
+	 */
480 480
 	public function ticket_price() {
481 481
 		return $this->get( 'TKT_price' );
482 482
 	}
483 483
 
484 484
 
485 485
 
486
-    /**
487
-     * @return mixed
488
-     * @throws \EE_Error
489
-     */
486
+	/**
487
+	 * @return mixed
488
+	 * @throws \EE_Error
489
+	 */
490 490
 	public function pretty_price() {
491 491
 		return $this->get_pretty( 'TKT_price' );
492 492
 	}
493 493
 
494 494
 
495 495
 
496
-    /**
497
-     * @return bool
498
-     * @throws \EE_Error
499
-     */
496
+	/**
497
+	 * @return bool
498
+	 * @throws \EE_Error
499
+	 */
500 500
 	public function is_free() {
501 501
 		return $this->get_ticket_total_with_taxes() === (float) 0;
502 502
 	}
503 503
 
504 504
 
505 505
 
506
-    /**
507
-     * get_ticket_total_with_taxes
508
-     *
509
-     * @param bool $no_cache
510
-     * @return float
511
-     * @throws \EE_Error
512
-     */
506
+	/**
507
+	 * get_ticket_total_with_taxes
508
+	 *
509
+	 * @param bool $no_cache
510
+	 * @return float
511
+	 * @throws \EE_Error
512
+	 */
513 513
 	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514 514
 		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
@@ -526,201 +526,201 @@  discard block
 block discarded – undo
526 526
 
527 527
 
528 528
 
529
-    /**
530
-     * @return float
531
-     * @throws \EE_Error
532
-     */
529
+	/**
530
+	 * @return float
531
+	 * @throws \EE_Error
532
+	 */
533 533
 	public function get_ticket_subtotal() {
534 534
 		return EE_Taxes::get_subtotal_for_admin( $this );
535 535
 	}
536 536
 
537 537
 
538 538
 
539
-    /**
540
-     * Returns the total taxes applied to this ticket
541
-     *
542
-     * @return float
543
-     * @throws \EE_Error
544
-     */
539
+	/**
540
+	 * Returns the total taxes applied to this ticket
541
+	 *
542
+	 * @return float
543
+	 * @throws \EE_Error
544
+	 */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546 546
 		return EE_Taxes::get_total_taxes_for_admin( $this );
547 547
 	}
548 548
 
549 549
 
550 550
 
551
-    /**
552
-     * Sets name
553
-     *
554
-     * @param string $name
555
-     * @throws \EE_Error
556
-     */
551
+	/**
552
+	 * Sets name
553
+	 *
554
+	 * @param string $name
555
+	 * @throws \EE_Error
556
+	 */
557 557
 	public function set_name( $name ) {
558 558
 		$this->set( 'TKT_name', $name );
559 559
 	}
560 560
 
561 561
 
562 562
 
563
-    /**
564
-     * Gets description
565
-     *
566
-     * @return string
567
-     * @throws \EE_Error
568
-     */
563
+	/**
564
+	 * Gets description
565
+	 *
566
+	 * @return string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public function description() {
570 570
 		return $this->get( 'TKT_description' );
571 571
 	}
572 572
 
573 573
 
574 574
 
575
-    /**
576
-     * Sets description
577
-     *
578
-     * @param string $description
579
-     * @throws \EE_Error
580
-     */
575
+	/**
576
+	 * Sets description
577
+	 *
578
+	 * @param string $description
579
+	 * @throws \EE_Error
580
+	 */
581 581
 	public function set_description( $description ) {
582 582
 		$this->set( 'TKT_description', $description );
583 583
 	}
584 584
 
585 585
 
586 586
 
587
-    /**
588
-     * Gets start_date
589
-     *
590
-     * @param string $dt_frmt
591
-     * @param string $tm_frmt
592
-     * @return string
593
-     * @throws \EE_Error
594
-     */
587
+	/**
588
+	 * Gets start_date
589
+	 *
590
+	 * @param string $dt_frmt
591
+	 * @param string $tm_frmt
592
+	 * @return string
593
+	 * @throws \EE_Error
594
+	 */
595 595
 	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596 596
 		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
597 597
 	}
598 598
 
599 599
 
600 600
 
601
-    /**
602
-     * Sets start_date
603
-     *
604
-     * @param string $start_date
605
-     * @return void
606
-     * @throws \EE_Error
607
-     */
601
+	/**
602
+	 * Sets start_date
603
+	 *
604
+	 * @param string $start_date
605
+	 * @return void
606
+	 * @throws \EE_Error
607
+	 */
608 608
 	public function set_start_date( $start_date ) {
609 609
 		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
610 610
 	}
611 611
 
612 612
 
613 613
 
614
-    /**
615
-     * Gets end_date
616
-     *
617
-     * @param string $dt_frmt
618
-     * @param string $tm_frmt
619
-     * @return string
620
-     * @throws \EE_Error
621
-     */
614
+	/**
615
+	 * Gets end_date
616
+	 *
617
+	 * @param string $dt_frmt
618
+	 * @param string $tm_frmt
619
+	 * @return string
620
+	 * @throws \EE_Error
621
+	 */
622 622
 	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623 623
 		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
624 624
 	}
625 625
 
626 626
 
627 627
 
628
-    /**
629
-     * Sets end_date
630
-     *
631
-     * @param string $end_date
632
-     * @return void
633
-     * @throws \EE_Error
634
-     */
628
+	/**
629
+	 * Sets end_date
630
+	 *
631
+	 * @param string $end_date
632
+	 * @return void
633
+	 * @throws \EE_Error
634
+	 */
635 635
 	public function set_end_date( $end_date ) {
636 636
 		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
637 637
 	}
638 638
 
639 639
 
640 640
 
641
-    /**
642
-     * Sets sell until time
643
-     *
644
-     * @since 4.5.0
645
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
-     * @throws \EE_Error
647
-     */
641
+	/**
642
+	 * Sets sell until time
643
+	 *
644
+	 * @since 4.5.0
645
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
+	 * @throws \EE_Error
647
+	 */
648 648
 	public function set_end_time( $time ) {
649 649
 		$this->_set_time_for( $time, 'TKT_end_date' );
650 650
 	}
651 651
 
652 652
 
653 653
 
654
-    /**
655
-     * Sets min
656
-     *
657
-     * @param int $min
658
-     * @return void
659
-     * @throws \EE_Error
660
-     */
654
+	/**
655
+	 * Sets min
656
+	 *
657
+	 * @param int $min
658
+	 * @return void
659
+	 * @throws \EE_Error
660
+	 */
661 661
 	public function set_min( $min ) {
662 662
 		$this->set( 'TKT_min', $min );
663 663
 	}
664 664
 
665 665
 
666 666
 
667
-    /**
668
-     * Gets max
669
-     *
670
-     * @return int
671
-     * @throws \EE_Error
672
-     */
667
+	/**
668
+	 * Gets max
669
+	 *
670
+	 * @return int
671
+	 * @throws \EE_Error
672
+	 */
673 673
 	public function max() {
674 674
 		return $this->get( 'TKT_max' );
675 675
 	}
676 676
 
677 677
 
678 678
 
679
-    /**
680
-     * Sets max
681
-     *
682
-     * @param int $max
683
-     * @return void
684
-     * @throws \EE_Error
685
-     */
679
+	/**
680
+	 * Sets max
681
+	 *
682
+	 * @param int $max
683
+	 * @return void
684
+	 * @throws \EE_Error
685
+	 */
686 686
 	public function set_max( $max ) {
687 687
 		$this->set( 'TKT_max', $max );
688 688
 	}
689 689
 
690 690
 
691 691
 
692
-    /**
693
-     * Sets price
694
-     *
695
-     * @param float $price
696
-     * @return void
697
-     * @throws \EE_Error
698
-     */
692
+	/**
693
+	 * Sets price
694
+	 *
695
+	 * @param float $price
696
+	 * @return void
697
+	 * @throws \EE_Error
698
+	 */
699 699
 	public function set_price( $price ) {
700 700
 		$this->set( 'TKT_price', $price );
701 701
 	}
702 702
 
703 703
 
704 704
 
705
-    /**
706
-     * Gets sold
707
-     *
708
-     * @return int
709
-     * @throws \EE_Error
710
-     */
705
+	/**
706
+	 * Gets sold
707
+	 *
708
+	 * @return int
709
+	 * @throws \EE_Error
710
+	 */
711 711
 	public function sold() {
712 712
 		return $this->get_raw( 'TKT_sold' );
713 713
 	}
714 714
 
715 715
 
716 716
 
717
-    /**
718
-     * Sets sold
719
-     *
720
-     * @param int $sold
721
-     * @return void
722
-     * @throws \EE_Error
723
-     */
717
+	/**
718
+	 * Sets sold
719
+	 *
720
+	 * @param int $sold
721
+	 * @return void
722
+	 * @throws \EE_Error
723
+	 */
724 724
 	public function set_sold( $sold ) {
725 725
 		// sold can not go below zero
726 726
 		$sold = max( 0, $sold );
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
 
730 730
 
731 731
 
732
-    /**
733
-     * increments sold by amount passed by $qty
734
-     *
735
-     * @param int $qty
736
-     * @return void
737
-     * @throws \EE_Error
738
-     */
732
+	/**
733
+	 * increments sold by amount passed by $qty
734
+	 *
735
+	 * @param int $qty
736
+	 * @return void
737
+	 * @throws \EE_Error
738
+	 */
739 739
 	public function increase_sold( $qty = 1 ) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 
748 748
 
749 749
 
750
-    /**
751
-     * Increases sold on related datetimes
752
-     *
753
-     * @param int $qty
754
-     * @return void
755
-     * @throws \EE_Error
756
-     */
750
+	/**
751
+	 * Increases sold on related datetimes
752
+	 *
753
+	 * @param int $qty
754
+	 * @return void
755
+	 * @throws \EE_Error
756
+	 */
757 757
 	protected function _increase_sold_for_datetimes( $qty = 1 ) {
758 758
 		$datetimes = $this->datetimes();
759 759
 		if ( is_array( $datetimes ) ) {
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
 
769 769
 
770 770
 
771
-    /**
772
-     * decrements (subtracts) sold by amount passed by $qty
773
-     *
774
-     * @param int $qty
775
-     * @return void
776
-     * @throws \EE_Error
777
-     */
771
+	/**
772
+	 * decrements (subtracts) sold by amount passed by $qty
773
+	 *
774
+	 * @param int $qty
775
+	 * @return void
776
+	 * @throws \EE_Error
777
+	 */
778 778
 	public function decrease_sold( $qty = 1 ) {
779 779
 		$sold = $this->sold() - $qty;
780 780
 		$this->_decrease_sold_for_datetimes( $qty );
@@ -783,13 +783,13 @@  discard block
 block discarded – undo
783 783
 
784 784
 
785 785
 
786
-    /**
787
-     * Decreases sold on related datetimes
788
-     *
789
-     * @param int $qty
790
-     * @return void
791
-     * @throws \EE_Error
792
-     */
786
+	/**
787
+	 * Decreases sold on related datetimes
788
+	 *
789
+	 * @param int $qty
790
+	 * @return void
791
+	 * @throws \EE_Error
792
+	 */
793 793
 	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
794 794
 		$datetimes = $this->datetimes();
795 795
 		if ( is_array( $datetimes ) ) {
@@ -804,25 +804,25 @@  discard block
 block discarded – undo
804 804
 
805 805
 
806 806
 
807
-    /**
808
-     * Gets qty of reserved tickets
809
-     *
810
-     * @return int
811
-     * @throws \EE_Error
812
-     */
807
+	/**
808
+	 * Gets qty of reserved tickets
809
+	 *
810
+	 * @return int
811
+	 * @throws \EE_Error
812
+	 */
813 813
 	public function reserved() {
814 814
 		return $this->get_raw( 'TKT_reserved' );
815 815
 	}
816 816
 
817 817
 
818 818
 
819
-    /**
820
-     * Sets reserved
821
-     *
822
-     * @param int $reserved
823
-     * @return void
824
-     * @throws \EE_Error
825
-     */
819
+	/**
820
+	 * Sets reserved
821
+	 *
822
+	 * @param int $reserved
823
+	 * @return void
824
+	 * @throws \EE_Error
825
+	 */
826 826
 	public function set_reserved( $reserved ) {
827 827
 		// reserved can not go below zero
828 828
 		$reserved = max( 0, (int) $reserved );
@@ -831,13 +831,13 @@  discard block
 block discarded – undo
831 831
 
832 832
 
833 833
 
834
-    /**
835
-     * increments reserved by amount passed by $qty
836
-     *
837
-     * @param int $qty
838
-     * @return void
839
-     * @throws \EE_Error
840
-     */
834
+	/**
835
+	 * increments reserved by amount passed by $qty
836
+	 *
837
+	 * @param int $qty
838
+	 * @return void
839
+	 * @throws \EE_Error
840
+	 */
841 841
 	public function increase_reserved( $qty = 1 ) {
842 842
 		$qty = absint( $qty );
843 843
 		$reserved = $this->reserved() + $qty;
@@ -847,13 +847,13 @@  discard block
 block discarded – undo
847 847
 
848 848
 
849 849
 
850
-    /**
851
-     * Increases sold on related datetimes
852
-     *
853
-     * @param int $qty
854
-     * @return void
855
-     * @throws \EE_Error
856
-     */
850
+	/**
851
+	 * Increases sold on related datetimes
852
+	 *
853
+	 * @param int $qty
854
+	 * @return void
855
+	 * @throws \EE_Error
856
+	 */
857 857
 	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
858 858
 		$datetimes = $this->datetimes();
859 859
 		if ( is_array( $datetimes ) ) {
@@ -868,14 +868,14 @@  discard block
 block discarded – undo
868 868
 
869 869
 
870 870
 
871
-    /**
872
-     * decrements (subtracts) reserved by amount passed by $qty
873
-     *
874
-     * @param int  $qty
875
-     * @param bool $adjust_datetimes
876
-     * @return void
877
-     * @throws \EE_Error
878
-     */
871
+	/**
872
+	 * decrements (subtracts) reserved by amount passed by $qty
873
+	 *
874
+	 * @param int  $qty
875
+	 * @param bool $adjust_datetimes
876
+	 * @return void
877
+	 * @throws \EE_Error
878
+	 */
879 879
 	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880 880
 		$reserved = $this->reserved() - absint( $qty );
881 881
 		if ( $adjust_datetimes ) {
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
 
887 887
 
888 888
 
889
-    /**
890
-     * Increases sold on related datetimes
891
-     *
892
-     * @param int $qty
893
-     * @return void
894
-     * @throws \EE_Error
895
-     */
889
+	/**
890
+	 * Increases sold on related datetimes
891
+	 *
892
+	 * @param int $qty
893
+	 * @return void
894
+	 * @throws \EE_Error
895
+	 */
896 896
 	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
897 897
 		$datetimes = $this->datetimes();
898 898
 		if ( is_array( $datetimes ) ) {
@@ -907,18 +907,18 @@  discard block
 block discarded – undo
907 907
 
908 908
 
909 909
 
910
-    /**
911
-     * Gets ticket quantity
912
-     *
913
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
919
-     * @return int
920
-     * @throws \EE_Error
921
-     */
910
+	/**
911
+	 * Gets ticket quantity
912
+	 *
913
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
919
+	 * @return int
920
+	 * @throws \EE_Error
921
+	 */
922 922
 	public function qty( $context = '' ) {
923 923
 		switch ( $context ) {
924 924
 			case 'reg_limit' :
@@ -932,19 +932,19 @@  discard block
 block discarded – undo
932 932
 
933 933
 
934 934
 
935
-    /**
936
-     * Gets ticket quantity
937
-     *
938
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
943
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
944
-     *                            set to 0 for all related datetimes
945
-     * @return int
946
-     * @throws \EE_Error
947
-     */
935
+	/**
936
+	 * Gets ticket quantity
937
+	 *
938
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
943
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
944
+	 *                            set to 0 for all related datetimes
945
+	 * @return int
946
+	 * @throws \EE_Error
947
+	 */
948 948
 	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949 949
 		$raw = $this->get_raw( 'TKT_qty' );
950 950
 		// return immediately if it's zero
@@ -1027,212 +1027,212 @@  discard block
 block discarded – undo
1027 1027
 
1028 1028
 
1029 1029
 
1030
-    /**
1031
-     * Gets uses
1032
-     *
1033
-     * @return int
1034
-     * @throws \EE_Error
1035
-     */
1030
+	/**
1031
+	 * Gets uses
1032
+	 *
1033
+	 * @return int
1034
+	 * @throws \EE_Error
1035
+	 */
1036 1036
 	public function uses() {
1037 1037
 		return $this->get( 'TKT_uses' );
1038 1038
 	}
1039 1039
 
1040 1040
 
1041 1041
 
1042
-    /**
1043
-     * Sets uses
1044
-     *
1045
-     * @param int $uses
1046
-     * @return void
1047
-     * @throws \EE_Error
1048
-     */
1042
+	/**
1043
+	 * Sets uses
1044
+	 *
1045
+	 * @param int $uses
1046
+	 * @return void
1047
+	 * @throws \EE_Error
1048
+	 */
1049 1049
 	public function set_uses( $uses ) {
1050 1050
 		$this->set( 'TKT_uses', $uses );
1051 1051
 	}
1052 1052
 
1053 1053
 
1054 1054
 
1055
-    /**
1056
-     * returns whether ticket is required or not.
1057
-     *
1058
-     * @return boolean
1059
-     * @throws \EE_Error
1060
-     */
1055
+	/**
1056
+	 * returns whether ticket is required or not.
1057
+	 *
1058
+	 * @return boolean
1059
+	 * @throws \EE_Error
1060
+	 */
1061 1061
 	public function required() {
1062 1062
 		return $this->get( 'TKT_required' );
1063 1063
 	}
1064 1064
 
1065 1065
 
1066 1066
 
1067
-    /**
1068
-     * sets the TKT_required property
1069
-     *
1070
-     * @param boolean $required
1071
-     * @return void
1072
-     * @throws \EE_Error
1073
-     */
1067
+	/**
1068
+	 * sets the TKT_required property
1069
+	 *
1070
+	 * @param boolean $required
1071
+	 * @return void
1072
+	 * @throws \EE_Error
1073
+	 */
1074 1074
 	public function set_required( $required ) {
1075 1075
 		$this->set( 'TKT_required', $required );
1076 1076
 	}
1077 1077
 
1078 1078
 
1079 1079
 
1080
-    /**
1081
-     * Gets taxable
1082
-     *
1083
-     * @return boolean
1084
-     * @throws \EE_Error
1085
-     */
1080
+	/**
1081
+	 * Gets taxable
1082
+	 *
1083
+	 * @return boolean
1084
+	 * @throws \EE_Error
1085
+	 */
1086 1086
 	public function taxable() {
1087 1087
 		return $this->get( 'TKT_taxable' );
1088 1088
 	}
1089 1089
 
1090 1090
 
1091 1091
 
1092
-    /**
1093
-     * Sets taxable
1094
-     *
1095
-     * @param boolean $taxable
1096
-     * @return void
1097
-     * @throws \EE_Error
1098
-     */
1092
+	/**
1093
+	 * Sets taxable
1094
+	 *
1095
+	 * @param boolean $taxable
1096
+	 * @return void
1097
+	 * @throws \EE_Error
1098
+	 */
1099 1099
 	public function set_taxable( $taxable ) {
1100 1100
 		$this->set( 'TKT_taxable', $taxable );
1101 1101
 	}
1102 1102
 
1103 1103
 
1104 1104
 
1105
-    /**
1106
-     * Gets is_default
1107
-     *
1108
-     * @return boolean
1109
-     * @throws \EE_Error
1110
-     */
1105
+	/**
1106
+	 * Gets is_default
1107
+	 *
1108
+	 * @return boolean
1109
+	 * @throws \EE_Error
1110
+	 */
1111 1111
 	public function is_default() {
1112 1112
 		return $this->get( 'TKT_is_default' );
1113 1113
 	}
1114 1114
 
1115 1115
 
1116 1116
 
1117
-    /**
1118
-     * Sets is_default
1119
-     *
1120
-     * @param boolean $is_default
1121
-     * @return void
1122
-     * @throws \EE_Error
1123
-     */
1117
+	/**
1118
+	 * Sets is_default
1119
+	 *
1120
+	 * @param boolean $is_default
1121
+	 * @return void
1122
+	 * @throws \EE_Error
1123
+	 */
1124 1124
 	public function set_is_default( $is_default ) {
1125 1125
 		$this->set( 'TKT_is_default', $is_default );
1126 1126
 	}
1127 1127
 
1128 1128
 
1129 1129
 
1130
-    /**
1131
-     * Gets order
1132
-     *
1133
-     * @return int
1134
-     * @throws \EE_Error
1135
-     */
1130
+	/**
1131
+	 * Gets order
1132
+	 *
1133
+	 * @return int
1134
+	 * @throws \EE_Error
1135
+	 */
1136 1136
 	public function order() {
1137 1137
 		return $this->get( 'TKT_order' );
1138 1138
 	}
1139 1139
 
1140 1140
 
1141 1141
 
1142
-    /**
1143
-     * Sets order
1144
-     *
1145
-     * @param int $order
1146
-     * @return void
1147
-     * @throws \EE_Error
1148
-     */
1142
+	/**
1143
+	 * Sets order
1144
+	 *
1145
+	 * @param int $order
1146
+	 * @return void
1147
+	 * @throws \EE_Error
1148
+	 */
1149 1149
 	public function set_order( $order ) {
1150 1150
 		$this->set( 'TKT_order', $order );
1151 1151
 	}
1152 1152
 
1153 1153
 
1154 1154
 
1155
-    /**
1156
-     * Gets row
1157
-     *
1158
-     * @return int
1159
-     * @throws \EE_Error
1160
-     */
1155
+	/**
1156
+	 * Gets row
1157
+	 *
1158
+	 * @return int
1159
+	 * @throws \EE_Error
1160
+	 */
1161 1161
 	public function row() {
1162 1162
 		return $this->get( 'TKT_row' );
1163 1163
 	}
1164 1164
 
1165 1165
 
1166 1166
 
1167
-    /**
1168
-     * Sets row
1169
-     *
1170
-     * @param int $row
1171
-     * @return void
1172
-     * @throws \EE_Error
1173
-     */
1167
+	/**
1168
+	 * Sets row
1169
+	 *
1170
+	 * @param int $row
1171
+	 * @return void
1172
+	 * @throws \EE_Error
1173
+	 */
1174 1174
 	public function set_row( $row ) {
1175 1175
 		$this->set( 'TKT_row', $row );
1176 1176
 	}
1177 1177
 
1178 1178
 
1179 1179
 
1180
-    /**
1181
-     * Gets deleted
1182
-     *
1183
-     * @return boolean
1184
-     * @throws \EE_Error
1185
-     */
1180
+	/**
1181
+	 * Gets deleted
1182
+	 *
1183
+	 * @return boolean
1184
+	 * @throws \EE_Error
1185
+	 */
1186 1186
 	public function deleted() {
1187 1187
 		return $this->get( 'TKT_deleted' );
1188 1188
 	}
1189 1189
 
1190 1190
 
1191 1191
 
1192
-    /**
1193
-     * Sets deleted
1194
-     *
1195
-     * @param boolean $deleted
1196
-     * @return void
1197
-     * @throws \EE_Error
1198
-     */
1192
+	/**
1193
+	 * Sets deleted
1194
+	 *
1195
+	 * @param boolean $deleted
1196
+	 * @return void
1197
+	 * @throws \EE_Error
1198
+	 */
1199 1199
 	public function set_deleted( $deleted ) {
1200 1200
 		$this->set( 'TKT_deleted', $deleted );
1201 1201
 	}
1202 1202
 
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Gets parent
1207
-     *
1208
-     * @return int
1209
-     * @throws \EE_Error
1210
-     */
1205
+	/**
1206
+	 * Gets parent
1207
+	 *
1208
+	 * @return int
1209
+	 * @throws \EE_Error
1210
+	 */
1211 1211
 	public function parent_ID() {
1212 1212
 		return $this->get( 'TKT_parent' );
1213 1213
 	}
1214 1214
 
1215 1215
 
1216 1216
 
1217
-    /**
1218
-     * Sets parent
1219
-     *
1220
-     * @param int $parent
1221
-     * @return void
1222
-     * @throws \EE_Error
1223
-     */
1217
+	/**
1218
+	 * Sets parent
1219
+	 *
1220
+	 * @param int $parent
1221
+	 * @return void
1222
+	 * @throws \EE_Error
1223
+	 */
1224 1224
 	public function set_parent_ID( $parent ) {
1225 1225
 		$this->set( 'TKT_parent', $parent );
1226 1226
 	}
1227 1227
 
1228 1228
 
1229 1229
 
1230
-    /**
1231
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
-     *
1233
-     * @return string
1234
-     * @throws \EE_Error
1235
-     */
1230
+	/**
1231
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
+	 *
1233
+	 * @return string
1234
+	 * @throws \EE_Error
1235
+	 */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238 1238
 		foreach ( $this->datetimes() as $datetime ) {
@@ -1243,67 +1243,67 @@  discard block
 block discarded – undo
1243 1243
 
1244 1244
 
1245 1245
 
1246
-    /**
1247
-     * Gets name
1248
-     *
1249
-     * @return string
1250
-     * @throws \EE_Error
1251
-     */
1246
+	/**
1247
+	 * Gets name
1248
+	 *
1249
+	 * @return string
1250
+	 * @throws \EE_Error
1251
+	 */
1252 1252
 	public function name() {
1253 1253
 		return $this->get( 'TKT_name' );
1254 1254
 	}
1255 1255
 
1256 1256
 
1257 1257
 
1258
-    /**
1259
-     * Gets price
1260
-     *
1261
-     * @return float
1262
-     * @throws \EE_Error
1263
-     */
1258
+	/**
1259
+	 * Gets price
1260
+	 *
1261
+	 * @return float
1262
+	 * @throws \EE_Error
1263
+	 */
1264 1264
 	public function price() {
1265 1265
 		return $this->get( 'TKT_price' );
1266 1266
 	}
1267 1267
 
1268 1268
 
1269 1269
 
1270
-    /**
1271
-     * Gets all the registrations for this ticket
1272
-     *
1273
-     * @param array $query_params like EEM_Base::get_all's
1274
-     * @return EE_Registration[]|EE_Base_Class[]
1275
-     * @throws \EE_Error
1276
-     */
1270
+	/**
1271
+	 * Gets all the registrations for this ticket
1272
+	 *
1273
+	 * @param array $query_params like EEM_Base::get_all's
1274
+	 * @return EE_Registration[]|EE_Base_Class[]
1275
+	 * @throws \EE_Error
1276
+	 */
1277 1277
 	public function registrations( $query_params = array() ) {
1278 1278
 		return $this->get_many_related( 'Registration', $query_params );
1279 1279
 	}
1280 1280
 
1281 1281
 
1282 1282
 
1283
-    /**
1284
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
-     * into account
1286
-     *
1287
-     * @return int
1288
-     * @throws \EE_Error
1289
-     */
1283
+	/**
1284
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
+	 * into account
1286
+	 *
1287
+	 * @return int
1288
+	 * @throws \EE_Error
1289
+	 */
1290 1290
 	public function update_tickets_sold() {
1291
-        $count_regs_for_this_ticket = $this->count_registrations(
1292
-            array(
1293
-                array(
1294
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1295
-                    'REG_deleted' => 0,
1296
-                ),
1297
-            )
1298
-        );
1299
-        $sold = $this->sold();
1300
-        if ($count_regs_for_this_ticket > $sold) {
1301
-            $this->increase_sold($count_regs_for_this_ticket - $sold);
1302
-            $this->save();
1303
-        } else if ($count_regs_for_this_ticket < $sold) {
1304
-            $this->decrease_sold($count_regs_for_this_ticket - $sold);
1305
-            $this->save();
1306
-        }
1291
+		$count_regs_for_this_ticket = $this->count_registrations(
1292
+			array(
1293
+				array(
1294
+					'STS_ID'      => EEM_Registration::status_id_approved,
1295
+					'REG_deleted' => 0,
1296
+				),
1297
+			)
1298
+		);
1299
+		$sold = $this->sold();
1300
+		if ($count_regs_for_this_ticket > $sold) {
1301
+			$this->increase_sold($count_regs_for_this_ticket - $sold);
1302
+			$this->save();
1303
+		} else if ($count_regs_for_this_ticket < $sold) {
1304
+			$this->decrease_sold($count_regs_for_this_ticket - $sold);
1305
+			$this->save();
1306
+		}
1307 1307
 		return $count_regs_for_this_ticket;
1308 1308
 	}
1309 1309
 
@@ -1331,21 +1331,21 @@  discard block
 block discarded – undo
1331 1331
 
1332 1332
 
1333 1333
 
1334
-    /**
1335
-     * Implementation of the EEI_Event_Relation interface method
1336
-     *
1337
-     * @see EEI_Event_Relation for comments
1338
-     * @return EE_Event
1339
-     * @throws \EE_Error
1340
-     * @throws UnexpectedEntityException
1341
-     */
1334
+	/**
1335
+	 * Implementation of the EEI_Event_Relation interface method
1336
+	 *
1337
+	 * @see EEI_Event_Relation for comments
1338
+	 * @return EE_Event
1339
+	 * @throws \EE_Error
1340
+	 * @throws UnexpectedEntityException
1341
+	 */
1342 1342
 	public function get_related_event() {
1343 1343
 		//get one datetime to use for getting the event
1344 1344
 		$datetime = $this->first_datetime();
1345 1345
 		if ( ! $datetime instanceof \EE_Datetime ) {
1346 1346
 			throw new UnexpectedEntityException(
1347 1347
 				$datetime,
1348
-                'EE_Datetime',
1348
+				'EE_Datetime',
1349 1349
 				sprintf(
1350 1350
 					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1351 1351
 					$this->name()
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
 		if ( ! $event instanceof \EE_Event ) {
1357 1357
 			throw new UnexpectedEntityException(
1358 1358
 				$event,
1359
-                'EE_Event',
1359
+				'EE_Event',
1360 1360
 				sprintf(
1361 1361
 					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1362 1362
 					$this->name()
@@ -1368,14 +1368,14 @@  discard block
 block discarded – undo
1368 1368
 
1369 1369
 
1370 1370
 
1371
-    /**
1372
-     * Implementation of the EEI_Event_Relation interface method
1373
-     *
1374
-     * @see EEI_Event_Relation for comments
1375
-     * @return string
1376
-     * @throws UnexpectedEntityException
1377
-     * @throws \EE_Error
1378
-     */
1371
+	/**
1372
+	 * Implementation of the EEI_Event_Relation interface method
1373
+	 *
1374
+	 * @see EEI_Event_Relation for comments
1375
+	 * @return string
1376
+	 * @throws UnexpectedEntityException
1377
+	 * @throws \EE_Error
1378
+	 */
1379 1379
 	public function get_event_name() {
1380 1380
 		$event = $this->get_related_event();
1381 1381
 		return $event instanceof EE_Event ? $event->name() : '';
@@ -1383,14 +1383,14 @@  discard block
 block discarded – undo
1383 1383
 
1384 1384
 
1385 1385
 
1386
-    /**
1387
-     * Implementation of the EEI_Event_Relation interface method
1388
-     *
1389
-     * @see EEI_Event_Relation for comments
1390
-     * @return int
1391
-     * @throws UnexpectedEntityException
1392
-     * @throws \EE_Error
1393
-     */
1386
+	/**
1387
+	 * Implementation of the EEI_Event_Relation interface method
1388
+	 *
1389
+	 * @see EEI_Event_Relation for comments
1390
+	 * @return int
1391
+	 * @throws UnexpectedEntityException
1392
+	 * @throws \EE_Error
1393
+	 */
1394 1394
 	public function get_event_ID() {
1395 1395
 		$event = $this->get_related_event();
1396 1396
 		return $event instanceof EE_Event ? $event->ID() : 0;
Please login to merge, or discard this patch.
Spacing   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\UnexpectedEntityException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
      * @return EE_Ticket
71 71
      * @throws \EE_Error
72 72
      */
73
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
73
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
74
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
75
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
76 76
 	}
77 77
 
78 78
 
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
      * @return EE_Ticket
85 85
      * @throws \EE_Error
86 86
      */
87
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88
-		return new self( $props_n_values, TRUE, $timezone );
87
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
88
+		return new self($props_n_values, TRUE, $timezone);
89 89
 	}
90 90
 
91 91
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @throws \EE_Error
96 96
      */
97 97
 	public function parent() {
98
-		return $this->get( 'TKT_parent' );
98
+		return $this->get('TKT_parent');
99 99
 	}
100 100
 
101 101
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
      * @return boolean
108 108
      * @throws \EE_Error
109 109
      */
110
-	public function available( $DTT_ID = 0 ) {
110
+	public function available($DTT_ID = 0) {
111 111
 		// are we checking availability for a particular datetime ?
112
-		if ( $DTT_ID ) {
112
+		if ($DTT_ID) {
113 113
 			// get that datetime object
114
-			$datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) );
114
+			$datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
115 115
 			// if  ticket sales for this datetime have exceeded the reg limit...
116
-			if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) {
116
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
117 117
 				return FALSE;
118 118
 			}
119 119
 		}
@@ -131,22 +131,22 @@  discard block
 block discarded – undo
131 131
      * @return mixed status int if the display string isn't requested
132 132
      * @throws \EE_Error
133 133
      */
134
-	public function ticket_status( $display = FALSE, $remaining = null ) {
135
-		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136
-		if ( ! $remaining ) {
137
-			return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out;
134
+	public function ticket_status($display = FALSE, $remaining = null) {
135
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
136
+		if ( ! $remaining) {
137
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out;
138 138
 		}
139
-		if ( $this->get( 'TKT_deleted' ) ) {
140
-			return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived;
139
+		if ($this->get('TKT_deleted')) {
140
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived;
141 141
 		}
142
-		if ( $this->is_expired() ) {
143
-			return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired;
142
+		if ($this->is_expired()) {
143
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired;
144 144
 		}
145
-		if ( $this->is_pending() ) {
146
-			return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending;
145
+		if ($this->is_pending()) {
146
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending;
147 147
 		}
148
-		if ( $this->is_on_sale() ) {
149
-			return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale;
148
+		if ($this->is_on_sale()) {
149
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale;
150 150
 		}
151 151
 		return '';
152 152
 	}
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
      * @return boolean         true = tickets remaining, false not.
162 162
      * @throws \EE_Error
163 163
      */
164
-	public function is_remaining( $DTT_ID = 0 ) {
165
-		$num_remaining = $this->remaining( $DTT_ID );
166
-		if ( $num_remaining === 0 ) {
164
+	public function is_remaining($DTT_ID = 0) {
165
+		$num_remaining = $this->remaining($DTT_ID);
166
+		if ($num_remaining === 0) {
167 167
 			return FALSE;
168 168
 		}
169
-		if ( $num_remaining > 0 && $num_remaining < $this->min() ) {
169
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
170 170
 			return FALSE;
171 171
 		}
172 172
 		return TRUE;
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      * @return int
183 183
      * @throws \EE_Error
184 184
      */
185
-	public function remaining( $DTT_ID = 0 ) {
186
-		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
185
+	public function remaining($DTT_ID = 0) {
186
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
187 187
 	}
188 188
 
189 189
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @throws \EE_Error
196 196
      */
197 197
 	public function min() {
198
-		return $this->get( 'TKT_min' );
198
+		return $this->get('TKT_min');
199 199
 	}
200 200
 
201 201
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * @throws \EE_Error
208 208
      */
209 209
 	public function is_expired() {
210
-		return ( $this->get_raw( 'TKT_end_date' ) < time() );
210
+		return ($this->get_raw('TKT_end_date') < time());
211 211
 	}
212 212
 
213 213
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @throws \EE_Error
220 220
      */
221 221
 	public function is_pending() {
222
-		return ( $this->get_raw( 'TKT_start_date' ) > time() );
222
+		return ($this->get_raw('TKT_start_date') > time());
223 223
 	}
224 224
 
225 225
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @throws \EE_Error
232 232
      */
233 233
 	public function is_on_sale() {
234
-		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
234
+		return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
235 235
 	}
236 236
 
237 237
 
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
      * @return string
245 245
      * @throws \EE_Error
246 246
      */
247
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248
-		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249
-		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
247
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
248
+		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : '';
249
+		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
250 250
 
251
-		return $first_date && $last_date ? $first_date . $conjunction  . $last_date : '';
251
+		return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
252 252
 	}
253 253
 
254 254
 
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
      * @throws \EE_Error
261 261
      */
262 262
 	public function first_datetime() {
263
-		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264
-		return reset( $datetimes );
263
+		$datetimes = $this->datetimes(array('limit' => 1));
264
+		return reset($datetimes);
265 265
 	}
266 266
 
267 267
 
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
      * @return EE_Datetime[]|EE_Base_Class[]
275 275
      * @throws \EE_Error
276 276
      */
277
-	public function datetimes( $query_params = array() ) {
278
-		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279
-			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
277
+	public function datetimes($query_params = array()) {
278
+		if ( ! isset($query_params['order_by'])) {
279
+			$query_params['order_by']['DTT_order'] = 'ASC';
280 280
 		}
281
-		return $this->get_many_related( 'Datetime', $query_params );
281
+		return $this->get_many_related('Datetime', $query_params);
282 282
 	}
283 283
 
284 284
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
      * @throws \EE_Error
291 291
      */
292 292
 	public function last_datetime() {
293
-		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294
-		return end( $datetimes );
293
+		$datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
294
+		return end($datetimes);
295 295
 	}
296 296
 
297 297
 
@@ -309,22 +309,22 @@  discard block
 block discarded – undo
309 309
      * @return mixed (array|int)          how many tickets have sold
310 310
      * @throws \EE_Error
311 311
      */
312
-	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
312
+	public function tickets_sold($what = 'ticket', $dtt_id = NULL) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
315
-		switch ( $what ) {
315
+		switch ($what) {
316 316
 			case 'ticket' :
317
-				return $tickets_sold[ 'ticket' ];
317
+				return $tickets_sold['ticket'];
318 318
 				break;
319 319
 			case 'datetime' :
320
-				if ( empty( $tickets_sold[ 'datetime' ] ) ) {
320
+				if (empty($tickets_sold['datetime'])) {
321 321
 					return $total;
322 322
 				}
323
-				if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) {
324
-					EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
323
+				if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
324
+					EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
325 325
 					return $total;
326 326
 				}
327
-				return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ];
327
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
328 328
 				break;
329 329
 			default:
330 330
 				return $total;
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
      * @throws \EE_Error
341 341
      */
342 342
 	protected function _all_tickets_sold() {
343
-		$datetimes = $this->get_many_related( 'Datetime' );
343
+		$datetimes = $this->get_many_related('Datetime');
344 344
 		$tickets_sold = array();
345
-		if ( ! empty( $datetimes ) ) {
346
-			foreach ( $datetimes as $datetime ) {
347
-				$tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' );
345
+		if ( ! empty($datetimes)) {
346
+			foreach ($datetimes as $datetime) {
347
+				$tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
348 348
 			}
349 349
 		}
350 350
 		//Tickets sold
351
-		$tickets_sold[ 'ticket' ] = $this->sold();
351
+		$tickets_sold['ticket'] = $this->sold();
352 352
 		return $tickets_sold;
353 353
 	}
354 354
 
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
      * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362 362
      * @throws \EE_Error
363 363
      */
364
-	public function base_price( $return_array = FALSE ) {
365
-		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
364
+	public function base_price($return_array = FALSE) {
365
+		$_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+            ? $this->get_many_related('Price', array($_where))
368
+            : $this->get_first_related('Price', array($_where));
369 369
 	}
370 370
 
371 371
 
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
      * @throws \EE_Error
379 379
      */
380 380
 	public function price_modifiers() {
381
-		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382
-		return $this->prices( $query_params );
381
+		$query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax))));
382
+		return $this->prices($query_params);
383 383
 	}
384 384
 
385 385
 
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
      * @return EE_Price[]|EE_Base_Class[]
392 392
      * @throws \EE_Error
393 393
      */
394
-	public function prices( $query_params = array() ) {
395
-		return $this->get_many_related( 'Price', $query_params );
394
+	public function prices($query_params = array()) {
395
+		return $this->get_many_related('Price', $query_params);
396 396
 	}
397 397
 
398 398
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
      * @return EE_Datetime_Ticket|EE_Base_Class[]
405 405
      * @throws \EE_Error
406 406
      */
407
-	public function datetime_tickets( $query_params = array() ) {
408
-		return $this->get_many_related( 'Datetime_Ticket', $query_params );
407
+	public function datetime_tickets($query_params = array()) {
408
+		return $this->get_many_related('Datetime_Ticket', $query_params);
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
      * @return EE_Datetime[]
419 419
      * @throws \EE_Error
420 420
      */
421
-	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422
-		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
421
+	public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) {
422
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted);
423 423
 	}
424 424
 
425 425
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @throws \EE_Error
432 432
      */
433 433
 	public function ID() {
434
-		return $this->get( 'TKT_ID' );
434
+		return $this->get('TKT_ID');
435 435
 	}
436 436
 
437 437
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
      * @throws \EE_Error
457 457
      */
458 458
 	public function template() {
459
-		return $this->get_first_related( 'Ticket_Template' );
459
+		return $this->get_first_related('Ticket_Template');
460 460
 	}
461 461
 
462 462
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      * @throws \EE_Error
479 479
      */
480 480
 	public function ticket_price() {
481
-		return $this->get( 'TKT_price' );
481
+		return $this->get('TKT_price');
482 482
 	}
483 483
 
484 484
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      * @throws \EE_Error
489 489
      */
490 490
 	public function pretty_price() {
491
-		return $this->get_pretty( 'TKT_price' );
491
+		return $this->get_pretty('TKT_price');
492 492
 	}
493 493
 
494 494
 
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
      * @return float
511 511
      * @throws \EE_Error
512 512
      */
513
-	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514
-		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
513
+	public function get_ticket_total_with_taxes($no_cache = FALSE) {
514
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
516 516
 		}
517 517
 		return (float) $this->_ticket_total_with_taxes;
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 
521 521
 
522 522
 	public function ensure_TKT_Price_correct() {
523
-		$this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) );
523
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
524 524
 		$this->save();
525 525
 	}
526 526
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      * @throws \EE_Error
532 532
      */
533 533
 	public function get_ticket_subtotal() {
534
-		return EE_Taxes::get_subtotal_for_admin( $this );
534
+		return EE_Taxes::get_subtotal_for_admin($this);
535 535
 	}
536 536
 
537 537
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
      * @throws \EE_Error
544 544
      */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546
-		return EE_Taxes::get_total_taxes_for_admin( $this );
546
+		return EE_Taxes::get_total_taxes_for_admin($this);
547 547
 	}
548 548
 
549 549
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
      * @param string $name
555 555
      * @throws \EE_Error
556 556
      */
557
-	public function set_name( $name ) {
558
-		$this->set( 'TKT_name', $name );
557
+	public function set_name($name) {
558
+		$this->set('TKT_name', $name);
559 559
 	}
560 560
 
561 561
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * @throws \EE_Error
568 568
      */
569 569
 	public function description() {
570
-		return $this->get( 'TKT_description' );
570
+		return $this->get('TKT_description');
571 571
 	}
572 572
 
573 573
 
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
      * @param string $description
579 579
      * @throws \EE_Error
580 580
      */
581
-	public function set_description( $description ) {
582
-		$this->set( 'TKT_description', $description );
581
+	public function set_description($description) {
582
+		$this->set('TKT_description', $description);
583 583
 	}
584 584
 
585 585
 
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
      * @return string
593 593
      * @throws \EE_Error
594 594
      */
595
-	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596
-		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
595
+	public function start_date($dt_frmt = '', $tm_frmt = '') {
596
+		return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
597 597
 	}
598 598
 
599 599
 
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
      * @return void
606 606
      * @throws \EE_Error
607 607
      */
608
-	public function set_start_date( $start_date ) {
609
-		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
608
+	public function set_start_date($start_date) {
609
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
610 610
 	}
611 611
 
612 612
 
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
      * @return string
620 620
      * @throws \EE_Error
621 621
      */
622
-	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623
-		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
622
+	public function end_date($dt_frmt = '', $tm_frmt = '') {
623
+		return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
624 624
 	}
625 625
 
626 626
 
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
      * @return void
633 633
      * @throws \EE_Error
634 634
      */
635
-	public function set_end_date( $end_date ) {
636
-		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
635
+	public function set_end_date($end_date) {
636
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
637 637
 	}
638 638
 
639 639
 
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
      * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646 646
      * @throws \EE_Error
647 647
      */
648
-	public function set_end_time( $time ) {
649
-		$this->_set_time_for( $time, 'TKT_end_date' );
648
+	public function set_end_time($time) {
649
+		$this->_set_time_for($time, 'TKT_end_date');
650 650
 	}
651 651
 
652 652
 
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
      * @return void
659 659
      * @throws \EE_Error
660 660
      */
661
-	public function set_min( $min ) {
662
-		$this->set( 'TKT_min', $min );
661
+	public function set_min($min) {
662
+		$this->set('TKT_min', $min);
663 663
 	}
664 664
 
665 665
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      * @throws \EE_Error
672 672
      */
673 673
 	public function max() {
674
-		return $this->get( 'TKT_max' );
674
+		return $this->get('TKT_max');
675 675
 	}
676 676
 
677 677
 
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
      * @return void
684 684
      * @throws \EE_Error
685 685
      */
686
-	public function set_max( $max ) {
687
-		$this->set( 'TKT_max', $max );
686
+	public function set_max($max) {
687
+		$this->set('TKT_max', $max);
688 688
 	}
689 689
 
690 690
 
@@ -696,8 +696,8 @@  discard block
 block discarded – undo
696 696
      * @return void
697 697
      * @throws \EE_Error
698 698
      */
699
-	public function set_price( $price ) {
700
-		$this->set( 'TKT_price', $price );
699
+	public function set_price($price) {
700
+		$this->set('TKT_price', $price);
701 701
 	}
702 702
 
703 703
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
      * @throws \EE_Error
710 710
      */
711 711
 	public function sold() {
712
-		return $this->get_raw( 'TKT_sold' );
712
+		return $this->get_raw('TKT_sold');
713 713
 	}
714 714
 
715 715
 
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
      * @return void
722 722
      * @throws \EE_Error
723 723
      */
724
-	public function set_sold( $sold ) {
724
+	public function set_sold($sold) {
725 725
 		// sold can not go below zero
726
-		$sold = max( 0, $sold );
727
-		$this->set( 'TKT_sold', $sold );
726
+		$sold = max(0, $sold);
727
+		$this->set('TKT_sold', $sold);
728 728
 	}
729 729
 
730 730
 
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
      * @return void
737 737
      * @throws \EE_Error
738 738
      */
739
-	public function increase_sold( $qty = 1 ) {
739
+	public function increase_sold($qty = 1) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
742 742
 		// via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
743
-		$this->decrease_reserved( $qty, false );
744
-		$this->_increase_sold_for_datetimes( $qty );
745
-		$this->set_sold( $sold );
743
+		$this->decrease_reserved($qty, false);
744
+		$this->_increase_sold_for_datetimes($qty);
745
+		$this->set_sold($sold);
746 746
 	}
747 747
 
748 748
 
@@ -754,12 +754,12 @@  discard block
 block discarded – undo
754 754
      * @return void
755 755
      * @throws \EE_Error
756 756
      */
757
-	protected function _increase_sold_for_datetimes( $qty = 1 ) {
757
+	protected function _increase_sold_for_datetimes($qty = 1) {
758 758
 		$datetimes = $this->datetimes();
759
-		if ( is_array( $datetimes ) ) {
760
-			foreach ( $datetimes as $datetime ) {
761
-				if ( $datetime instanceof EE_Datetime ) {
762
-					$datetime->increase_sold( $qty );
759
+		if (is_array($datetimes)) {
760
+			foreach ($datetimes as $datetime) {
761
+				if ($datetime instanceof EE_Datetime) {
762
+					$datetime->increase_sold($qty);
763 763
 					$datetime->save();
764 764
 				}
765 765
 			}
@@ -775,10 +775,10 @@  discard block
 block discarded – undo
775 775
      * @return void
776 776
      * @throws \EE_Error
777 777
      */
778
-	public function decrease_sold( $qty = 1 ) {
778
+	public function decrease_sold($qty = 1) {
779 779
 		$sold = $this->sold() - $qty;
780
-		$this->_decrease_sold_for_datetimes( $qty );
781
-		$this->set_sold( $sold );
780
+		$this->_decrease_sold_for_datetimes($qty);
781
+		$this->set_sold($sold);
782 782
 	}
783 783
 
784 784
 
@@ -790,12 +790,12 @@  discard block
 block discarded – undo
790 790
      * @return void
791 791
      * @throws \EE_Error
792 792
      */
793
-	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
793
+	protected function _decrease_sold_for_datetimes($qty = 1) {
794 794
 		$datetimes = $this->datetimes();
795
-		if ( is_array( $datetimes ) ) {
796
-			foreach ( $datetimes as $datetime ) {
797
-				if ( $datetime instanceof EE_Datetime ) {
798
-					$datetime->decrease_sold( $qty );
795
+		if (is_array($datetimes)) {
796
+			foreach ($datetimes as $datetime) {
797
+				if ($datetime instanceof EE_Datetime) {
798
+					$datetime->decrease_sold($qty);
799 799
 					$datetime->save();
800 800
 				}
801 801
 			}
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
      * @throws \EE_Error
812 812
      */
813 813
 	public function reserved() {
814
-		return $this->get_raw( 'TKT_reserved' );
814
+		return $this->get_raw('TKT_reserved');
815 815
 	}
816 816
 
817 817
 
@@ -823,10 +823,10 @@  discard block
 block discarded – undo
823 823
      * @return void
824 824
      * @throws \EE_Error
825 825
      */
826
-	public function set_reserved( $reserved ) {
826
+	public function set_reserved($reserved) {
827 827
 		// reserved can not go below zero
828
-		$reserved = max( 0, (int) $reserved );
829
-		$this->set( 'TKT_reserved', $reserved );
828
+		$reserved = max(0, (int) $reserved);
829
+		$this->set('TKT_reserved', $reserved);
830 830
 	}
831 831
 
832 832
 
@@ -838,11 +838,11 @@  discard block
 block discarded – undo
838 838
      * @return void
839 839
      * @throws \EE_Error
840 840
      */
841
-	public function increase_reserved( $qty = 1 ) {
842
-		$qty = absint( $qty );
841
+	public function increase_reserved($qty = 1) {
842
+		$qty = absint($qty);
843 843
 		$reserved = $this->reserved() + $qty;
844
-		$this->_increase_reserved_for_datetimes( $qty );
845
-		$this->set_reserved( $reserved );
844
+		$this->_increase_reserved_for_datetimes($qty);
845
+		$this->set_reserved($reserved);
846 846
 	}
847 847
 
848 848
 
@@ -854,12 +854,12 @@  discard block
 block discarded – undo
854 854
      * @return void
855 855
      * @throws \EE_Error
856 856
      */
857
-	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
857
+	protected function _increase_reserved_for_datetimes($qty = 1) {
858 858
 		$datetimes = $this->datetimes();
859
-		if ( is_array( $datetimes ) ) {
860
-			foreach ( $datetimes as $datetime ) {
861
-				if ( $datetime instanceof EE_Datetime ) {
862
-					$datetime->increase_reserved( $qty );
859
+		if (is_array($datetimes)) {
860
+			foreach ($datetimes as $datetime) {
861
+				if ($datetime instanceof EE_Datetime) {
862
+					$datetime->increase_reserved($qty);
863 863
 					$datetime->save();
864 864
 				}
865 865
 			}
@@ -876,12 +876,12 @@  discard block
 block discarded – undo
876 876
      * @return void
877 877
      * @throws \EE_Error
878 878
      */
879
-	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880
-		$reserved = $this->reserved() - absint( $qty );
881
-		if ( $adjust_datetimes ) {
882
-			$this->_decrease_reserved_for_datetimes( $qty );
879
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true) {
880
+		$reserved = $this->reserved() - absint($qty);
881
+		if ($adjust_datetimes) {
882
+			$this->_decrease_reserved_for_datetimes($qty);
883 883
 		}
884
-		$this->set_reserved( $reserved );
884
+		$this->set_reserved($reserved);
885 885
 	}
886 886
 
887 887
 
@@ -893,12 +893,12 @@  discard block
 block discarded – undo
893 893
      * @return void
894 894
      * @throws \EE_Error
895 895
      */
896
-	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
896
+	protected function _decrease_reserved_for_datetimes($qty = 1) {
897 897
 		$datetimes = $this->datetimes();
898
-		if ( is_array( $datetimes ) ) {
899
-			foreach ( $datetimes as $datetime ) {
900
-				if ( $datetime instanceof EE_Datetime ) {
901
-					$datetime->decrease_reserved( $qty );
898
+		if (is_array($datetimes)) {
899
+			foreach ($datetimes as $datetime) {
900
+				if ($datetime instanceof EE_Datetime) {
901
+					$datetime->decrease_reserved($qty);
902 902
 					$datetime->save();
903 903
 				}
904 904
 			}
@@ -919,14 +919,14 @@  discard block
 block discarded – undo
919 919
      * @return int
920 920
      * @throws \EE_Error
921 921
      */
922
-	public function qty( $context = '' ) {
923
-		switch ( $context ) {
922
+	public function qty($context = '') {
923
+		switch ($context) {
924 924
 			case 'reg_limit' :
925 925
 				return $this->real_quantity_on_ticket();
926 926
 			case 'saleable' :
927
-				return $this->real_quantity_on_ticket( 'saleable' );
927
+				return $this->real_quantity_on_ticket('saleable');
928 928
 			default:
929
-				return $this->get_raw( 'TKT_qty' );
929
+				return $this->get_raw('TKT_qty');
930 930
 		}
931 931
 	}
932 932
 
@@ -945,15 +945,15 @@  discard block
 block discarded – undo
945 945
      * @return int
946 946
      * @throws \EE_Error
947 947
      */
948
-	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949
-		$raw = $this->get_raw( 'TKT_qty' );
948
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) {
949
+		$raw = $this->get_raw('TKT_qty');
950 950
 		// return immediately if it's zero
951
-		if ( $raw === 0 ) {
951
+		if ($raw === 0) {
952 952
 			return $raw;
953 953
 		}
954 954
 		//echo "\n\n<br />Ticket: " . $this->name() . '<br />';
955 955
 		// ensure qty doesn't exceed raw value for THIS ticket
956
-		$qty = min( EE_INF, $raw );
956
+		$qty = min(EE_INF, $raw);
957 957
 		//echo "\n . qty: " . $qty . '<br />';
958 958
 		// calculate this ticket's total sales and reservations
959 959
 		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
@@ -962,23 +962,23 @@  discard block
 block discarded – undo
962 962
 		//echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
963 963
 		// first we need to calculate the maximum number of tickets available for the datetime
964 964
 		// do we want data for one datetime or all of them ?
965
-		$query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array();
966
-		$datetimes = $this->datetimes( $query_params );
967
-		if ( is_array( $datetimes ) && ! empty( $datetimes ) ) {
968
-			foreach ( $datetimes as $datetime ) {
969
-				if ( $datetime instanceof EE_Datetime ) {
965
+		$query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
966
+		$datetimes = $this->datetimes($query_params);
967
+		if (is_array($datetimes) && ! empty($datetimes)) {
968
+			foreach ($datetimes as $datetime) {
969
+				if ($datetime instanceof EE_Datetime) {
970 970
 					$datetime->refresh_from_db();
971 971
 					//echo "\n . . datetime name: " . $datetime->name() . '<br />';
972 972
 					//echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
973 973
 					// initialize with no restrictions for each datetime
974 974
 					// but adjust datetime qty based on datetime reg limit
975
-					$datetime_qty = min( EE_INF, $datetime->reg_limit() );
975
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
976 976
 					//echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
977 977
 					//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
978 978
 					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
979 979
 					// and reservations for this datetime, that do NOT include sales and reservations
980 980
 					// for this ticket (so we add $this->sold() and $this->reserved() back in)
981
-					if ( $context === 'saleable' ) {
981
+					if ($context === 'saleable') {
982 982
 						$datetime_qty = max(
983 983
 							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
984 984
 							0
@@ -990,16 +990,16 @@  discard block
 block discarded – undo
990 990
 						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
991 991
 						//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
992 992
 					}
993
-					$qty = min( $datetime_qty, $qty );
993
+					$qty = min($datetime_qty, $qty);
994 994
 					//echo "\n . . qty: " . $qty . '<br />';
995 995
 				}
996 996
 			}
997 997
 		}
998 998
 		// NOW that we know the  maximum number of tickets available for the datetime
999 999
 		// we can finally factor in the details for this specific ticket
1000
-		if ( $qty > 0 && $context === 'saleable' ) {
1000
+		if ($qty > 0 && $context === 'saleable') {
1001 1001
 			// and subtract the sales for THIS ticket
1002
-			$qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 );
1002
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1003 1003
 			//echo "\n . qty: " . $qty . '<br />';
1004 1004
 		}
1005 1005
 		//echo "\nFINAL QTY: " . $qty . "<br /><br />";
@@ -1015,14 +1015,14 @@  discard block
 block discarded – undo
1015 1015
 	 * @return void
1016 1016
 	 * @throws \EE_Error
1017 1017
 	 */
1018
-	public function set_qty( $qty ) {
1018
+	public function set_qty($qty) {
1019 1019
 		$datetimes = $this->datetimes();
1020
-		foreach ( $datetimes as $datetime ) {
1021
-			if ( $datetime instanceof EE_Datetime ) {
1022
-				$qty = min( $qty, $datetime->reg_limit() );
1020
+		foreach ($datetimes as $datetime) {
1021
+			if ($datetime instanceof EE_Datetime) {
1022
+				$qty = min($qty, $datetime->reg_limit());
1023 1023
 			}
1024 1024
 		}
1025
-		$this->set( 'TKT_qty', $qty );
1025
+		$this->set('TKT_qty', $qty);
1026 1026
 	}
1027 1027
 
1028 1028
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
      * @throws \EE_Error
1035 1035
      */
1036 1036
 	public function uses() {
1037
-		return $this->get( 'TKT_uses' );
1037
+		return $this->get('TKT_uses');
1038 1038
 	}
1039 1039
 
1040 1040
 
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
      * @return void
1047 1047
      * @throws \EE_Error
1048 1048
      */
1049
-	public function set_uses( $uses ) {
1050
-		$this->set( 'TKT_uses', $uses );
1049
+	public function set_uses($uses) {
1050
+		$this->set('TKT_uses', $uses);
1051 1051
 	}
1052 1052
 
1053 1053
 
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
      * @throws \EE_Error
1060 1060
      */
1061 1061
 	public function required() {
1062
-		return $this->get( 'TKT_required' );
1062
+		return $this->get('TKT_required');
1063 1063
 	}
1064 1064
 
1065 1065
 
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
      * @return void
1072 1072
      * @throws \EE_Error
1073 1073
      */
1074
-	public function set_required( $required ) {
1075
-		$this->set( 'TKT_required', $required );
1074
+	public function set_required($required) {
1075
+		$this->set('TKT_required', $required);
1076 1076
 	}
1077 1077
 
1078 1078
 
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
      * @throws \EE_Error
1085 1085
      */
1086 1086
 	public function taxable() {
1087
-		return $this->get( 'TKT_taxable' );
1087
+		return $this->get('TKT_taxable');
1088 1088
 	}
1089 1089
 
1090 1090
 
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
      * @return void
1097 1097
      * @throws \EE_Error
1098 1098
      */
1099
-	public function set_taxable( $taxable ) {
1100
-		$this->set( 'TKT_taxable', $taxable );
1099
+	public function set_taxable($taxable) {
1100
+		$this->set('TKT_taxable', $taxable);
1101 1101
 	}
1102 1102
 
1103 1103
 
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
      * @throws \EE_Error
1110 1110
      */
1111 1111
 	public function is_default() {
1112
-		return $this->get( 'TKT_is_default' );
1112
+		return $this->get('TKT_is_default');
1113 1113
 	}
1114 1114
 
1115 1115
 
@@ -1121,8 +1121,8 @@  discard block
 block discarded – undo
1121 1121
      * @return void
1122 1122
      * @throws \EE_Error
1123 1123
      */
1124
-	public function set_is_default( $is_default ) {
1125
-		$this->set( 'TKT_is_default', $is_default );
1124
+	public function set_is_default($is_default) {
1125
+		$this->set('TKT_is_default', $is_default);
1126 1126
 	}
1127 1127
 
1128 1128
 
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
      * @throws \EE_Error
1135 1135
      */
1136 1136
 	public function order() {
1137
-		return $this->get( 'TKT_order' );
1137
+		return $this->get('TKT_order');
1138 1138
 	}
1139 1139
 
1140 1140
 
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
      * @return void
1147 1147
      * @throws \EE_Error
1148 1148
      */
1149
-	public function set_order( $order ) {
1150
-		$this->set( 'TKT_order', $order );
1149
+	public function set_order($order) {
1150
+		$this->set('TKT_order', $order);
1151 1151
 	}
1152 1152
 
1153 1153
 
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
      * @throws \EE_Error
1160 1160
      */
1161 1161
 	public function row() {
1162
-		return $this->get( 'TKT_row' );
1162
+		return $this->get('TKT_row');
1163 1163
 	}
1164 1164
 
1165 1165
 
@@ -1171,8 +1171,8 @@  discard block
 block discarded – undo
1171 1171
      * @return void
1172 1172
      * @throws \EE_Error
1173 1173
      */
1174
-	public function set_row( $row ) {
1175
-		$this->set( 'TKT_row', $row );
1174
+	public function set_row($row) {
1175
+		$this->set('TKT_row', $row);
1176 1176
 	}
1177 1177
 
1178 1178
 
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
      * @throws \EE_Error
1185 1185
      */
1186 1186
 	public function deleted() {
1187
-		return $this->get( 'TKT_deleted' );
1187
+		return $this->get('TKT_deleted');
1188 1188
 	}
1189 1189
 
1190 1190
 
@@ -1196,8 +1196,8 @@  discard block
 block discarded – undo
1196 1196
      * @return void
1197 1197
      * @throws \EE_Error
1198 1198
      */
1199
-	public function set_deleted( $deleted ) {
1200
-		$this->set( 'TKT_deleted', $deleted );
1199
+	public function set_deleted($deleted) {
1200
+		$this->set('TKT_deleted', $deleted);
1201 1201
 	}
1202 1202
 
1203 1203
 
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
      * @throws \EE_Error
1210 1210
      */
1211 1211
 	public function parent_ID() {
1212
-		return $this->get( 'TKT_parent' );
1212
+		return $this->get('TKT_parent');
1213 1213
 	}
1214 1214
 
1215 1215
 
@@ -1221,8 +1221,8 @@  discard block
 block discarded – undo
1221 1221
      * @return void
1222 1222
      * @throws \EE_Error
1223 1223
      */
1224
-	public function set_parent_ID( $parent ) {
1225
-		$this->set( 'TKT_parent', $parent );
1224
+	public function set_parent_ID($parent) {
1225
+		$this->set('TKT_parent', $parent);
1226 1226
 	}
1227 1227
 
1228 1228
 
@@ -1235,10 +1235,10 @@  discard block
 block discarded – undo
1235 1235
      */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238
-		foreach ( $this->datetimes() as $datetime ) {
1238
+		foreach ($this->datetimes() as $datetime) {
1239 1239
 			$times[] = $datetime->start_date_and_time();
1240 1240
 		}
1241
-		return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price();
1241
+		return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1242 1242
 	}
1243 1243
 
1244 1244
 
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
      * @throws \EE_Error
1251 1251
      */
1252 1252
 	public function name() {
1253
-		return $this->get( 'TKT_name' );
1253
+		return $this->get('TKT_name');
1254 1254
 	}
1255 1255
 
1256 1256
 
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
      * @throws \EE_Error
1263 1263
      */
1264 1264
 	public function price() {
1265
-		return $this->get( 'TKT_price' );
1265
+		return $this->get('TKT_price');
1266 1266
 	}
1267 1267
 
1268 1268
 
@@ -1274,8 +1274,8 @@  discard block
 block discarded – undo
1274 1274
      * @return EE_Registration[]|EE_Base_Class[]
1275 1275
      * @throws \EE_Error
1276 1276
      */
1277
-	public function registrations( $query_params = array() ) {
1278
-		return $this->get_many_related( 'Registration', $query_params );
1277
+	public function registrations($query_params = array()) {
1278
+		return $this->get_many_related('Registration', $query_params);
1279 1279
 	}
1280 1280
 
1281 1281
 
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
 	 * @param array $query_params like EEM_Base::get_all's
1315 1315
 	 * @return int
1316 1316
 	 */
1317
-	public function count_registrations( $query_params = array() ) {
1317
+	public function count_registrations($query_params = array()) {
1318 1318
 		return $this->count_related('Registration', $query_params);
1319 1319
 	}
1320 1320
 
@@ -1342,23 +1342,23 @@  discard block
 block discarded – undo
1342 1342
 	public function get_related_event() {
1343 1343
 		//get one datetime to use for getting the event
1344 1344
 		$datetime = $this->first_datetime();
1345
-		if ( ! $datetime instanceof \EE_Datetime ) {
1345
+		if ( ! $datetime instanceof \EE_Datetime) {
1346 1346
 			throw new UnexpectedEntityException(
1347 1347
 				$datetime,
1348 1348
                 'EE_Datetime',
1349 1349
 				sprintf(
1350
-					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1350
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1351 1351
 					$this->name()
1352 1352
 				)
1353 1353
 			);
1354 1354
 		}
1355 1355
 		$event = $datetime->event();
1356
-		if ( ! $event instanceof \EE_Event ) {
1356
+		if ( ! $event instanceof \EE_Event) {
1357 1357
 			throw new UnexpectedEntityException(
1358 1358
 				$event,
1359 1359
                 'EE_Event',
1360 1360
 				sprintf(
1361
-					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1361
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1362 1362
 					$this->name()
1363 1363
 				)
1364 1364
 			);
Please login to merge, or discard this patch.
core/db_classes/EE_Datetime.class.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -358,13 +358,13 @@  discard block
 block discarded – undo
358 358
 
359 359
 
360 360
 
361
-    /**
362
-     * get event start date.  Provide either the date format, or NULL to re-use the
363
-     * last-used format, or '' to use the default date format
364
-     *
365
-     * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
366
-     * @return        mixed        string on success, FALSE on fail
367
-     */
361
+	/**
362
+	 * get event start date.  Provide either the date format, or NULL to re-use the
363
+	 * last-used format, or '' to use the default date format
364
+	 *
365
+	 * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
366
+	 * @return        mixed        string on success, FALSE on fail
367
+	 */
368 368
 	public function start_date( $dt_frmt = '' ) {
369 369
 		return $this->_show_datetime( 'D', 'start', $dt_frmt );
370 370
 	}
@@ -381,13 +381,13 @@  discard block
 block discarded – undo
381 381
 
382 382
 
383 383
 
384
-    /**
385
-     * get end date. Provide either the date format, or NULL to re-use the
386
-     * last-used format, or '' to use the default date format
387
-     *
388
-     * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
389
-     * @return        mixed        string on success, FALSE on fail
390
-     */
384
+	/**
385
+	 * get end date. Provide either the date format, or NULL to re-use the
386
+	 * last-used format, or '' to use the default date format
387
+	 *
388
+	 * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
389
+	 * @return        mixed        string on success, FALSE on fail
390
+	 */
391 391
 	public function end_date( $dt_frmt = '' ) {
392 392
 		return $this->_show_datetime( 'D', 'end', $dt_frmt );
393 393
 	}
@@ -509,23 +509,23 @@  discard block
 block discarded – undo
509 509
 	/**
510 510
 	 * This returns a range representation of the date and times.
511 511
 	 * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end.
512
-     * Also, the return value is localized.
513
-     *
514
-     * @param string $dt_format
512
+	 * Also, the return value is localized.
513
+	 *
514
+	 * @param string $dt_format
515 515
 	 * @param string $tm_format
516 516
 	 * @param string $conjunction used between two different dates or times.
517
-     *                            ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm
518
-     * @param string $separator   used between the date and time formats.
519
-     *                            ex: Dec 1, 2016{$separator}2pm
517
+	 *                            ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm
518
+	 * @param string $separator   used between the date and time formats.
519
+	 *                            ex: Dec 1, 2016{$separator}2pm
520 520
 	 * @return string
521 521
 	 * @throws \EE_Error
522 522
 	 */
523 523
 	public function date_and_time_range(
524
-	    $dt_format = '',
525
-        $tm_format = '',
526
-        $conjunction = ' - ' ,
527
-        $separator = ' '
528
-    ) {
524
+		$dt_format = '',
525
+		$tm_format = '',
526
+		$conjunction = ' - ' ,
527
+		$separator = ' '
528
+	) {
529 529
 		$dt_format = ! empty( $dt_format ) ? $dt_format : $this->_dt_frmt;
530 530
 		$tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt;
531 531
 		$full_format = $dt_format . $separator . $tm_format;
@@ -539,14 +539,14 @@  discard block
 block discarded – undo
539 539
 			//start and end date are the same but times are different
540 540
 			case ( $this->start_date() === $this->end_date() ) :
541 541
 				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
542
-				          . $conjunction
543
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format );
542
+						  . $conjunction
543
+						  . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format );
544 544
 				break;
545 545
 			//all other conditions
546 546
 			default :
547 547
 				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
548
-				          . $conjunction
549
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format );
548
+						  . $conjunction
549
+						  . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format );
550 550
 				break;
551 551
 		}
552 552
 		return $output;
@@ -630,13 +630,13 @@  discard block
 block discarded – undo
630 630
 
631 631
 
632 632
 	/**
633
-     *        get end date and time
634
-     *
635
-     * @param string $dt_frmt   - string representation of date format defaults to 'F j, Y'
636
-     * @param string $tm_format - string representation of time format defaults to 'g:i a'
637
-     * @return    mixed                string on success, FALSE on fail
638
-     */
639
-    public function end_date_and_time($dt_frmt = '', $tm_format = '') {
633
+	 *        get end date and time
634
+	 *
635
+	 * @param string $dt_frmt   - string representation of date format defaults to 'F j, Y'
636
+	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
637
+	 * @return    mixed                string on success, FALSE on fail
638
+	 */
639
+	public function end_date_and_time($dt_frmt = '', $tm_format = '') {
640 640
 		return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format );
641 641
 	}
642 642
 
@@ -905,13 +905,13 @@  discard block
 block discarded – undo
905 905
 
906 906
 
907 907
 
908
-    /**
909
-     * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime (via the tickets).
910
-     * into account
911
-     *
912
-     * @return int
913
-     * @throws \EE_Error
914
-     */
908
+	/**
909
+	 * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime (via the tickets).
910
+	 * into account
911
+	 *
912
+	 * @return int
913
+	 * @throws \EE_Error
914
+	 */
915 915
 	public function update_sold() {
916 916
 		$count_regs_for_this_datetime = EEM_Registration::instance()->count(
917 917
 			array( array(
@@ -920,14 +920,14 @@  discard block
 block discarded – undo
920 920
 				'Ticket.Datetime.DTT_ID' 	=> $this->ID(),
921 921
 			) )
922 922
 		);
923
-        $sold = $this->sold();
924
-        if ($count_regs_for_this_datetime > $sold) {
925
-            $this->increase_sold($count_regs_for_this_datetime - $sold);
926
-            $this->save();
927
-        } else if ($count_regs_for_this_datetime < $sold) {
928
-            $this->decrease_sold($count_regs_for_this_datetime - $sold);
929
-            $this->save();
930
-        }
923
+		$sold = $this->sold();
924
+		if ($count_regs_for_this_datetime > $sold) {
925
+			$this->increase_sold($count_regs_for_this_datetime - $sold);
926
+			$this->save();
927
+		} else if ($count_regs_for_this_datetime < $sold) {
928
+			$this->decrease_sold($count_regs_for_this_datetime - $sold);
929
+			$this->save();
930
+		}
931 931
 		return $count_regs_for_this_datetime;
932 932
 	}
933 933
 }
Please login to merge, or discard this patch.
Spacing   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
 	 *                             		    date_format and the second value is the time format
75 75
 	 * @return EE_Datetime
76 76
 	 */
77
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
78
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
79
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
77
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
78
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
79
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
80 80
 	}
81 81
 
82 82
 
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	 *                          		the website will be used.
88 88
 	 * @return EE_Datetime
89 89
 	 */
90
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
91
-		return new self( $props_n_values, TRUE, $timezone );
90
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
91
+		return new self($props_n_values, TRUE, $timezone);
92 92
 	}
93 93
 
94 94
 
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	/**
97 97
 	 * @param $name
98 98
 	 */
99
-	public function set_name( $name ) {
100
-		$this->set( 'DTT_name', $name );
99
+	public function set_name($name) {
100
+		$this->set('DTT_name', $name);
101 101
 	}
102 102
 
103 103
 
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	/**
106 106
 	 * @param $description
107 107
 	 */
108
-	public function set_description( $description ) {
109
-		$this->set( 'DTT_description', $description );
108
+	public function set_description($description) {
109
+		$this->set('DTT_description', $description);
110 110
 	}
111 111
 
112 112
 
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param        string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
120 120
 	 */
121
-	public function set_start_date( $date ) {
122
-		$this->_set_date_for( $date, 'DTT_EVT_start' );
121
+	public function set_start_date($date) {
122
+		$this->_set_date_for($date, 'DTT_EVT_start');
123 123
 	}
124 124
 
125 125
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @param        string $time a string representation of the event time ex:  9am  or  7:30 PM
133 133
 	 */
134
-	public function set_start_time( $time ) {
135
-		$this->_set_time_for( $time, 'DTT_EVT_start' );
134
+	public function set_start_time($time) {
135
+		$this->_set_time_for($time, 'DTT_EVT_start');
136 136
 	}
137 137
 
138 138
 
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @param        string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
146 146
 	 */
147
-	public function set_end_date( $date ) {
148
-		$this->_set_date_for( $date, 'DTT_EVT_end' );
147
+	public function set_end_date($date) {
148
+		$this->_set_date_for($date, 'DTT_EVT_end');
149 149
 	}
150 150
 
151 151
 
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param        string $time a string representation of the event time ex:  9am  or  7:30 PM
159 159
 	 */
160
-	public function set_end_time( $time ) {
161
-		$this->_set_time_for( $time, 'DTT_EVT_end' );
160
+	public function set_end_time($time) {
161
+		$this->_set_time_for($time, 'DTT_EVT_end');
162 162
 	}
163 163
 
164 164
 
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @param        int $reg_limit
172 172
 	 */
173
-	public function set_reg_limit( $reg_limit ) {
174
-		$this->set( 'DTT_reg_limit', $reg_limit );
173
+	public function set_reg_limit($reg_limit) {
174
+		$this->set('DTT_reg_limit', $reg_limit);
175 175
 	}
176 176
 
177 177
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @return        mixed        int on success, FALSE on fail
184 184
 	 */
185 185
 	public function sold() {
186
-		return $this->get_raw( 'DTT_sold' );
186
+		return $this->get_raw('DTT_sold');
187 187
 	}
188 188
 
189 189
 
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @param        int $sold
195 195
 	 */
196
-	public function set_sold( $sold ) {
196
+	public function set_sold($sold) {
197 197
 		// sold can not go below zero
198
-		$sold = max( 0, $sold );
199
-		$this->set( 'DTT_sold', $sold );
198
+		$sold = max(0, $sold);
199
+		$this->set('DTT_sold', $sold);
200 200
 	}
201 201
 
202 202
 
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
 	 * increments sold by amount passed by $qty
206 206
 	 * @param int $qty
207 207
 	 */
208
-	public function increase_sold( $qty = 1 ) {
208
+	public function increase_sold($qty = 1) {
209 209
 		$sold = $this->sold() + $qty;
210 210
 		// remove ticket reservation
211
-		$this->decrease_reserved( $qty );
212
-		$this->set_sold( $sold );
211
+		$this->decrease_reserved($qty);
212
+		$this->set_sold($sold);
213 213
 	}
214 214
 
215 215
 
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 	 * decrements (subtracts) sold amount passed by $qty
219 219
 	 * @param int $qty
220 220
 	 */
221
-	public function decrease_sold( $qty = 1 ) {
221
+	public function decrease_sold($qty = 1) {
222 222
 		$sold = $this->sold() - $qty;
223
-		$this->set_sold( $sold );
223
+		$this->set_sold($sold);
224 224
 	}
225 225
 
226 226
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	 * @return int
232 232
 	 */
233 233
 	public function reserved() {
234
-		return $this->get_raw( 'DTT_reserved' );
234
+		return $this->get_raw('DTT_reserved');
235 235
 	}
236 236
 
237 237
 
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @param int $reserved
243 243
 	 */
244
-	public function set_reserved( $reserved ) {
244
+	public function set_reserved($reserved) {
245 245
 		// reserved can not go below zero
246
-		$reserved = max( 0, (int) $reserved );
247
-		$this->set( 'DTT_reserved', $reserved );
246
+		$reserved = max(0, (int) $reserved);
247
+		$this->set('DTT_reserved', $reserved);
248 248
 	}
249 249
 
250 250
 
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 * @param int $qty
256 256
 	 * @return boolean
257 257
 	 */
258
-	public function increase_reserved( $qty = 1 ) {
259
-		$reserved = $this->reserved() + absint( $qty );
260
-		return $this->set_reserved( $reserved );
258
+	public function increase_reserved($qty = 1) {
259
+		$reserved = $this->reserved() + absint($qty);
260
+		return $this->set_reserved($reserved);
261 261
 	}
262 262
 
263 263
 
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
 	 * @param int $qty
269 269
 	 * @return boolean
270 270
 	 */
271
-	public function decrease_reserved( $qty = 1 ) {
272
-		$reserved = $this->reserved() - absint( $qty );
273
-		return $this->set_reserved( $reserved );
271
+	public function decrease_reserved($qty = 1) {
272
+		$reserved = $this->reserved() - absint($qty);
273
+		return $this->set_reserved($reserved);
274 274
 	}
275 275
 
276 276
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @return string
292 292
 	 */
293 293
 	public function name() {
294
-		return $this->get( 'DTT_name' );
294
+		return $this->get('DTT_name');
295 295
 	}
296 296
 
297 297
 
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	 * @return string
302 302
 	 */
303 303
 	public function description() {
304
-		return $this->get( 'DTT_description' );
304
+		return $this->get('DTT_description');
305 305
 	}
306 306
 
307 307
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @return boolean          TRUE if is primary, FALSE if not.
312 312
 	 */
313 313
 	public function is_primary() {
314
-		return $this->get( 'DTT_is_primary' );
314
+		return $this->get('DTT_is_primary');
315 315
 	}
316 316
 
317 317
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 * @return int         The order of the datetime for this event.
322 322
 	 */
323 323
 	public function order() {
324
-		return $this->get( 'DTT_order' );
324
+		return $this->get('DTT_order');
325 325
 	}
326 326
 
327 327
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 * @return int
332 332
 	 */
333 333
 	public function parent() {
334
-		return $this->get( 'DTT_parent' );
334
+		return $this->get('DTT_parent');
335 335
 	}
336 336
 
337 337
 
@@ -347,10 +347,10 @@  discard block
 block discarded – undo
347 347
 	 * @param    bool   $echo         - whether we echo or return (note echoing uses "pretty" formats, otherwise we use the standard formats)
348 348
 	 * @return    string|bool  string on success, FALSE on fail
349 349
 	 */
350
-	private function _show_datetime( $date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE ) {
350
+	private function _show_datetime($date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE) {
351 351
 		$field_name = "DTT_EVT_{$start_or_end}";
352
-		$dtt = $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo );
353
-		if ( ! $echo ) {
352
+		$dtt = $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo);
353
+		if ( ! $echo) {
354 354
 			return $dtt;
355 355
 		}
356 356
 		return '';
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
      * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
366 366
      * @return        mixed        string on success, FALSE on fail
367 367
      */
368
-	public function start_date( $dt_frmt = '' ) {
369
-		return $this->_show_datetime( 'D', 'start', $dt_frmt );
368
+	public function start_date($dt_frmt = '') {
369
+		return $this->_show_datetime('D', 'start', $dt_frmt);
370 370
 	}
371 371
 
372 372
 
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * Echoes start_date()
376 376
 	 * @param string $dt_frmt
377 377
 	 */
378
-	public function e_start_date( $dt_frmt = '' ) {
379
-		$this->_show_datetime( 'D', 'start', $dt_frmt, NULL, TRUE );
378
+	public function e_start_date($dt_frmt = '') {
379
+		$this->_show_datetime('D', 'start', $dt_frmt, NULL, TRUE);
380 380
 	}
381 381
 
382 382
 
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
      * @param string $dt_frmt - string representation of date format defaults to 'F j, Y'
389 389
      * @return        mixed        string on success, FALSE on fail
390 390
      */
391
-	public function end_date( $dt_frmt = '' ) {
392
-		return $this->_show_datetime( 'D', 'end', $dt_frmt );
391
+	public function end_date($dt_frmt = '') {
392
+		return $this->_show_datetime('D', 'end', $dt_frmt);
393 393
 	}
394 394
 
395 395
 
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * Echoes the end date. See end_date()
399 399
 	 * @param string $dt_frmt
400 400
 	 */
401
-	public function e_end_date( $dt_frmt = '' ) {
402
-		$this->_show_datetime( 'D', 'end', $dt_frmt, NULL, TRUE );
401
+	public function e_end_date($dt_frmt = '') {
402
+		$this->_show_datetime('D', 'end', $dt_frmt, NULL, TRUE);
403 403
 	}
404 404
 
405 405
 
@@ -414,11 +414,11 @@  discard block
 block discarded – undo
414 414
 	 * @return mixed        string on success, FALSE on fail
415 415
 	 * @throws \EE_Error
416 416
 	 */
417
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
418
-		$dt_frmt = ! empty( $dt_frmt ) ? $dt_frmt : $this->_dt_frmt;
419
-		$start = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_start', $dt_frmt ) );
420
-		$end = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_end', $dt_frmt ) );
421
-		return $start !== $end ? $start . $conjunction . $end : $start;
417
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
418
+		$dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt;
419
+		$start = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt));
420
+		$end = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt));
421
+		return $start !== $end ? $start.$conjunction.$end : $start;
422 422
 	}
423 423
 
424 424
 
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 	 * @param string $conjunction
429 429
 	 * @throws \EE_Error
430 430
 	 */
431
-	public function e_date_range( $dt_frmt = '', $conjunction = ' - ' ) {
432
-		echo $this->date_range( $dt_frmt, $conjunction );
431
+	public function e_date_range($dt_frmt = '', $conjunction = ' - ') {
432
+		echo $this->date_range($dt_frmt, $conjunction);
433 433
 	}
434 434
 
435 435
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
441 441
 	 * @return mixed        string on success, FALSE on fail
442 442
 	 */
443
-	public function start_time( $tm_format = '' ) {
444
-		return $this->_show_datetime( 'T', 'start', NULL, $tm_format );
443
+	public function start_time($tm_format = '') {
444
+		return $this->_show_datetime('T', 'start', NULL, $tm_format);
445 445
 	}
446 446
 
447 447
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	/**
450 450
 	 * @param string $tm_format
451 451
 	 */
452
-	public function e_start_time( $tm_format = '' ) {
453
-		$this->_show_datetime( 'T', 'start', NULL, $tm_format, TRUE );
452
+	public function e_start_time($tm_format = '') {
453
+		$this->_show_datetime('T', 'start', NULL, $tm_format, TRUE);
454 454
 	}
455 455
 
456 456
 
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
 	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
462 462
 	 * @return mixed        string on success, FALSE on fail
463 463
 	 */
464
-	public function end_time( $tm_format = '' ) {
465
-		return $this->_show_datetime( 'T', 'end', NULL, $tm_format );
464
+	public function end_time($tm_format = '') {
465
+		return $this->_show_datetime('T', 'end', NULL, $tm_format);
466 466
 	}
467 467
 
468 468
 
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
 	/**
471 471
 	 * @param string $tm_format
472 472
 	 */
473
-	public function e_end_time( $tm_format = '' ) {
474
-		$this->_show_datetime( 'T', 'end', NULL, $tm_format, TRUE );
473
+	public function e_end_time($tm_format = '') {
474
+		$this->_show_datetime('T', 'end', NULL, $tm_format, TRUE);
475 475
 	}
476 476
 
477 477
 
@@ -486,11 +486,11 @@  discard block
 block discarded – undo
486 486
 	 * @return mixed              string on success, FALSE on fail
487 487
 	 * @throws \EE_Error
488 488
 	 */
489
-	public function time_range( $tm_format = '', $conjunction = ' - ' ) {
490
-		$tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt;
491
-		$start = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_start', $tm_format ) );
492
-		$end = str_replace( ' ', '&nbsp;', $this->get_i18n_datetime( 'DTT_EVT_end',  $tm_format ) );
493
-		return $start !== $end ? $start . $conjunction . $end : $start;
489
+	public function time_range($tm_format = '', $conjunction = ' - ') {
490
+		$tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
491
+		$start = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_start', $tm_format));
492
+		$end = str_replace(' ', '&nbsp;', $this->get_i18n_datetime('DTT_EVT_end', $tm_format));
493
+		return $start !== $end ? $start.$conjunction.$end : $start;
494 494
 	}
495 495
 
496 496
 
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
 	 * @param string $conjunction
501 501
 	 * @throws \EE_Error
502 502
 	 */
503
-	public function e_time_range( $tm_format = '', $conjunction = ' - ' ) {
504
-		echo $this->time_range( $tm_format, $conjunction );
503
+	public function e_time_range($tm_format = '', $conjunction = ' - ') {
504
+		echo $this->time_range($tm_format, $conjunction);
505 505
 	}
506 506
 
507 507
 
@@ -523,30 +523,30 @@  discard block
 block discarded – undo
523 523
 	public function date_and_time_range(
524 524
 	    $dt_format = '',
525 525
         $tm_format = '',
526
-        $conjunction = ' - ' ,
526
+        $conjunction = ' - ',
527 527
         $separator = ' '
528 528
     ) {
529
-		$dt_format = ! empty( $dt_format ) ? $dt_format : $this->_dt_frmt;
530
-		$tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt;
531
-		$full_format = $dt_format . $separator . $tm_format;
529
+		$dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt;
530
+		$tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
531
+		$full_format = $dt_format.$separator.$tm_format;
532 532
 
533 533
 		//the range output depends on various conditions
534
-		switch ( true ) {
534
+		switch (true) {
535 535
 			//start date timestamp and end date timestamp are the same.
536
-			case ( $this->get_raw( 'DTT_EVT_start' ) === $this->get_raw( 'DTT_EVT_end' ) ) :
537
-				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format );
536
+			case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')) :
537
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format);
538 538
 				break;
539 539
 			//start and end date are the same but times are different
540
-			case ( $this->start_date() === $this->end_date() ) :
541
-				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
540
+			case ($this->start_date() === $this->end_date()) :
541
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
542 542
 				          . $conjunction
543
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format );
543
+				          . $this->get_i18n_datetime('DTT_EVT_end', $tm_format);
544 544
 				break;
545 545
 			//all other conditions
546 546
 			default :
547
-				$output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format )
547
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
548 548
 				          . $conjunction
549
-				          . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format );
549
+				          . $this->get_i18n_datetime('DTT_EVT_end', $full_format);
550 550
 				break;
551 551
 		}
552 552
 		return $output;
@@ -564,8 +564,8 @@  discard block
 block discarded – undo
564 564
 	 * @return void
565 565
 	 * @throws \EE_Error
566 566
 	 */
567
-	public function e_date_and_time_range( $dt_format = '', $tm_format = '', $conjunction = ' - ' ) {
568
-		echo $this->date_and_time_range( $dt_format, $tm_format, $conjunction );
567
+	public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') {
568
+		echo $this->date_and_time_range($dt_format, $tm_format, $conjunction);
569 569
 	}
570 570
 
571 571
 
@@ -577,8 +577,8 @@  discard block
 block discarded – undo
577 577
 	 * @param 	string 	$tm_format - string representation of time format defaults to 'g:i a'
578 578
 	 * @return 	mixed 	string on success, FALSE on fail
579 579
 	 */
580
-	public function start_date_and_time( $dt_format = '', $tm_format = '' ) {
581
-		return $this->_show_datetime( '', 'start', $dt_format, $tm_format );
580
+	public function start_date_and_time($dt_format = '', $tm_format = '') {
581
+		return $this->_show_datetime('', 'start', $dt_format, $tm_format);
582 582
 	}
583 583
 
584 584
 
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
 	 * @param string $dt_frmt
588 588
 	 * @param string $tm_format
589 589
 	 */
590
-	public function e_start_date_and_time( $dt_frmt = '', $tm_format = '' ) {
591
-		$this->_show_datetime( '', 'start', $dt_frmt, $tm_format, TRUE );
590
+	public function e_start_date_and_time($dt_frmt = '', $tm_format = '') {
591
+		$this->_show_datetime('', 'start', $dt_frmt, $tm_format, TRUE);
592 592
 	}
593 593
 
594 594
 
@@ -602,11 +602,11 @@  discard block
 block discarded – undo
602 602
 	 * @param bool   $round_up
603 603
 	 * @return float|int|mixed
604 604
 	 */
605
-	public function length( $units = 'seconds', $round_up = FALSE ) {
606
-		$start = $this->get_raw( 'DTT_EVT_start' );
607
-		$end = $this->get_raw( 'DTT_EVT_end' );
605
+	public function length($units = 'seconds', $round_up = FALSE) {
606
+		$start = $this->get_raw('DTT_EVT_start');
607
+		$end = $this->get_raw('DTT_EVT_end');
608 608
 		$length_in_units = $end - $start;
609
-		switch ( $units ) {
609
+		switch ($units) {
610 610
 			//NOTE: We purposefully don't use "break;" in order to chain the divisions
611 611
 			/** @noinspection PhpMissingBreakStatementInspection */
612 612
 			case 'days':
@@ -619,10 +619,10 @@  discard block
 block discarded – undo
619 619
 				$length_in_units /= 60;
620 620
 			case 'seconds':
621 621
 			default:
622
-				$length_in_units = ceil( $length_in_units );
622
+				$length_in_units = ceil($length_in_units);
623 623
 		}
624
-		if ( $round_up ) {
625
-			$length_in_units = max( $length_in_units, 1 );
624
+		if ($round_up) {
625
+			$length_in_units = max($length_in_units, 1);
626 626
 		}
627 627
 		return $length_in_units;
628 628
 	}
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
      * @return    mixed                string on success, FALSE on fail
638 638
      */
639 639
     public function end_date_and_time($dt_frmt = '', $tm_format = '') {
640
-		return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format );
640
+		return $this->_show_datetime('', 'end', $dt_frmt, $tm_format);
641 641
 	}
642 642
 
643 643
 
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 	 * @param string $dt_frmt
647 647
 	 * @param string $tm_format
648 648
 	 */
649
-	public function e_end_date_and_time( $dt_frmt = '', $tm_format = '' ) {
650
-		$this->_show_datetime( '', 'end', $dt_frmt, $tm_format, TRUE );
649
+	public function e_end_date_and_time($dt_frmt = '', $tm_format = '') {
650
+		$this->_show_datetime('', 'end', $dt_frmt, $tm_format, TRUE);
651 651
 	}
652 652
 
653 653
 
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 	 * @return        int
659 659
 	 */
660 660
 	public function start() {
661
-		return $this->get_raw( 'DTT_EVT_start' );
661
+		return $this->get_raw('DTT_EVT_start');
662 662
 	}
663 663
 
664 664
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 	 * @return        int
670 670
 	 */
671 671
 	public function end() {
672
-		return $this->get_raw( 'DTT_EVT_end' );
672
+		return $this->get_raw('DTT_EVT_end');
673 673
 	}
674 674
 
675 675
 
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
 	 * @return        mixed        int on success, FALSE on fail
681 681
 	 */
682 682
 	public function reg_limit() {
683
-		return $this->get_raw( 'DTT_reg_limit' );
683
+		return $this->get_raw('DTT_reg_limit');
684 684
 	}
685 685
 
686 686
 
@@ -708,15 +708,15 @@  discard block
 block discarded – undo
708 708
 	 * 																	the spaces remaining for this particular datetime, hence the flag.
709 709
 	 * @return 	int
710 710
 	 */
711
-	public function spaces_remaining( $consider_tickets = FALSE ) {
711
+	public function spaces_remaining($consider_tickets = FALSE) {
712 712
 		// tickets remaining available for purchase
713 713
 		//no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF
714 714
 		$dtt_remaining = $this->reg_limit() - $this->sold_and_reserved();
715
-		if ( ! $consider_tickets ) {
715
+		if ( ! $consider_tickets) {
716 716
 			return $dtt_remaining;
717 717
 		}
718 718
 		$tickets_remaining = $this->tickets_remaining();
719
-		return min( $dtt_remaining, $tickets_remaining );
719
+		return min($dtt_remaining, $tickets_remaining);
720 720
 	}
721 721
 
722 722
 
@@ -727,19 +727,19 @@  discard block
 block discarded – undo
727 727
 	 * @param array $query_params like EEM_Base::get_all's
728 728
 	 * @return int
729 729
 	 */
730
-	public function tickets_remaining( $query_params = array() ) {
730
+	public function tickets_remaining($query_params = array()) {
731 731
 		$sum = 0;
732
-		$tickets = $this->tickets( $query_params );
733
-		if ( ! empty( $tickets ) ) {
734
-			foreach ( $tickets as $ticket ) {
735
-				if ( $ticket instanceof EE_Ticket ) {
732
+		$tickets = $this->tickets($query_params);
733
+		if ( ! empty($tickets)) {
734
+			foreach ($tickets as $ticket) {
735
+				if ($ticket instanceof EE_Ticket) {
736 736
 					// get the actual amount of tickets that can be sold
737
-					$qty = $ticket->qty( 'saleable' );
738
-					if ( $qty === EE_INF ) {
737
+					$qty = $ticket->qty('saleable');
738
+					if ($qty === EE_INF) {
739 739
 						return EE_INF;
740 740
 					}
741 741
 					// no negative ticket quantities plz
742
-					if ( $qty > 0 ) {
742
+					if ($qty > 0) {
743 743
 						$sum += $qty;
744 744
 					}
745 745
 				}
@@ -756,8 +756,8 @@  discard block
 block discarded – undo
756 756
 	 * @param array $query_params like EEM_Base::get_all's
757 757
 	 * @return int
758 758
 	 */
759
-	public function sum_tickets_initially_available( $query_params = array() ) {
760
-		return $this->sum_related( 'Ticket', $query_params, 'TKT_qty' );
759
+	public function sum_tickets_initially_available($query_params = array()) {
760
+		return $this->sum_related('Ticket', $query_params, 'TKT_qty');
761 761
 	}
762 762
 
763 763
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	 * @return int
770 770
 	 */
771 771
 	public function total_tickets_available_at_this_datetime() {
772
-		return $this->spaces_remaining( true );
772
+		return $this->spaces_remaining(true);
773 773
 	}
774 774
 
775 775
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 	 * @return boolean
781 781
 	 */
782 782
 	public function is_upcoming() {
783
-		return ( $this->get_raw( 'DTT_EVT_start' ) > time() );
783
+		return ($this->get_raw('DTT_EVT_start') > time());
784 784
 	}
785 785
 
786 786
 
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 	 * @return boolean
791 791
 	 */
792 792
 	public function is_active() {
793
-		return ( $this->get_raw( 'DTT_EVT_start' ) < time() && $this->get_raw( 'DTT_EVT_end' ) > time() );
793
+		return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time());
794 794
 	}
795 795
 
796 796
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 	 * @return boolean
801 801
 	 */
802 802
 	public function is_expired() {
803
-		return ( $this->get_raw( 'DTT_EVT_end' ) < time() );
803
+		return ($this->get_raw('DTT_EVT_end') < time());
804 804
 	}
805 805
 
806 806
 
@@ -811,16 +811,16 @@  discard block
 block discarded – undo
811 811
 	 */
812 812
 	public function get_active_status() {
813 813
 		$total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime();
814
-		if ( $total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1 ) {
814
+		if ($total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1) {
815 815
 			return EE_Datetime::sold_out;
816 816
 		}
817
-		if ( $this->is_expired() ) {
817
+		if ($this->is_expired()) {
818 818
 			return EE_Datetime::expired;
819 819
 		}
820
-		if ( $this->is_upcoming() ) {
820
+		if ($this->is_upcoming()) {
821 821
 			return EE_Datetime::upcoming;
822 822
 		}
823
-		if ( $this->is_active() ) {
823
+		if ($this->is_active()) {
824 824
 			return EE_Datetime::active;
825 825
 		}
826 826
 		return NULL;
@@ -834,24 +834,24 @@  discard block
 block discarded – undo
834 834
 	 * @param  boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty.
835 835
 	 * @return string
836 836
 	 */
837
-	public function get_dtt_display_name( $use_dtt_name = FALSE ) {
838
-		if ( $use_dtt_name ) {
837
+	public function get_dtt_display_name($use_dtt_name = FALSE) {
838
+		if ($use_dtt_name) {
839 839
 			$dtt_name = $this->name();
840
-			if ( !empty( $dtt_name ) ) {
840
+			if ( ! empty($dtt_name)) {
841 841
 				return $dtt_name;
842 842
 			}
843 843
 		}
844 844
 		//first condition is to see if the months are different
845
-		if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) ) {
846
-			$display_date = $this->start_date( 'M j\, Y g:i a' ) . ' - ' . $this->end_date( 'M j\, Y g:i a' );
845
+		if (date('m', $this->get_raw('DTT_EVT_start')) != date('m', $this->get_raw('DTT_EVT_end'))) {
846
+			$display_date = $this->start_date('M j\, Y g:i a').' - '.$this->end_date('M j\, Y g:i a');
847 847
 			//next condition is if its the same month but different day
848 848
 		}
849 849
 		else {
850
-			if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) == date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) && date( 'd', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'd', $this->get_raw( 'DTT_EVT_end' ) ) ) {
851
-				$display_date = $this->start_date( 'M j\, g:i a' ) . ' - ' . $this->end_date( 'M j\, g:i a Y' );
850
+			if (date('m', $this->get_raw('DTT_EVT_start')) == date('m', $this->get_raw('DTT_EVT_end')) && date('d', $this->get_raw('DTT_EVT_start')) != date('d', $this->get_raw('DTT_EVT_end'))) {
851
+				$display_date = $this->start_date('M j\, g:i a').' - '.$this->end_date('M j\, g:i a Y');
852 852
 			}
853 853
 			else {
854
-				$display_date = $this->start_date( 'F j\, Y' ) . ' @ ' . $this->start_date( 'g:i a' ) . ' - ' . $this->end_date( 'g:i a' );
854
+				$display_date = $this->start_date('F j\, Y').' @ '.$this->start_date('g:i a').' - '.$this->end_date('g:i a');
855 855
 			}
856 856
 		}
857 857
 		return $display_date;
@@ -865,8 +865,8 @@  discard block
 block discarded – undo
865 865
 *@param array $query_params see EEM_Base::get_all()
866 866
 	 * @return EE_Ticket[]
867 867
 	 */
868
-	public function tickets( $query_params = array() ) {
869
-		return $this->get_many_related( 'Ticket', $query_params );
868
+	public function tickets($query_params = array()) {
869
+		return $this->get_many_related('Ticket', $query_params);
870 870
 	}
871 871
 
872 872
 
@@ -876,21 +876,21 @@  discard block
 block discarded – undo
876 876
 	 * @param array $query_params like EEM_Base::get_all's
877 877
 	 * @return EE_Ticket[]
878 878
 	 */
879
-	public function ticket_types_available_for_purchase( $query_params = array() ) {
879
+	public function ticket_types_available_for_purchase($query_params = array()) {
880 880
 		// first check if datetime is valid
881
-		if ( ! ( $this->is_upcoming() || $this->is_active() ) || $this->sold_out() ) {
881
+		if ( ! ($this->is_upcoming() || $this->is_active()) || $this->sold_out()) {
882 882
 			return array();
883 883
 		}
884
-		if ( empty( $query_params ) ) {
884
+		if (empty($query_params)) {
885 885
 			$query_params = array(
886 886
 				array(
887
-					'TKT_start_date' => array( '<=', EEM_Ticket::instance()->current_time_for_query( 'TKT_start_date' ) ),
888
-					'TKT_end_date'   => array( '>=', EEM_Ticket::instance()->current_time_for_query( 'TKT_end_date' ) ),
887
+					'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')),
888
+					'TKT_end_date'   => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
889 889
 					'TKT_deleted'    => false
890 890
 				)
891 891
 			);
892 892
 		}
893
-		return $this->tickets( $query_params );
893
+		return $this->tickets($query_params);
894 894
 	}
895 895
 
896 896
 
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 	 * @return EE_Event
901 901
 	 */
902 902
 	public function event() {
903
-		return $this->get_first_related( 'Event' );
903
+		return $this->get_first_related('Event');
904 904
 	}
905 905
 
906 906
 
@@ -914,11 +914,11 @@  discard block
 block discarded – undo
914 914
      */
915 915
 	public function update_sold() {
916 916
 		$count_regs_for_this_datetime = EEM_Registration::instance()->count(
917
-			array( array(
917
+			array(array(
918 918
 				'STS_ID' 					=> EEM_Registration::status_id_approved,
919 919
 				'REG_deleted' 				=> 0,
920 920
 				'Ticket.Datetime.DTT_ID' 	=> $this->ID(),
921
-			) )
921
+			))
922 922
 		);
923 923
         $sold = $this->sold();
924 924
         if ($count_regs_for_this_datetime > $sold) {
Please login to merge, or discard this patch.