Completed
Branch FET-8385-datetime-ticket-selec... (36e0c9)
by
unknown
56:21 queued 45:48
created
core/libraries/shortcodes/EE_Transaction_Shortcodes.lib.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
  */
32 32
 class EE_Transaction_Shortcodes extends EE_Shortcodes {
33 33
 
34
-    /**
35
-     * @var EE_Payment_Method $_invoice_pm the invoiec payment method for use in invoices etc
36
-     */
37
-    protected $_invoice_pm;
34
+	/**
35
+	 * @var EE_Payment_Method $_invoice_pm the invoiec payment method for use in invoices etc
36
+	 */
37
+	protected $_invoice_pm;
38 38
 
39 39
 	/**
40 40
 	 * EE_Transaction_Shortcodes constructor.
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
 	 * @return \EE_Payment_Method|null
379 379
 	 */
380 380
 	private function _get_invoice_payment_method(){
381
-	    if( ! $this->_invoice_pm instanceof EE_Payment_Method ) {
382
-            $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
383
-            $transaction = ! $transaction instanceof EE_Transaction
384
-                           && is_array($this->_extra_data)
385
-                           && isset($this->_extra_data['data'])
386
-                           && $this->_extra_data['data'] instanceof EE_Messages_Addressee
387
-                ? $this->_extra_data['data']->txn : $transaction;
388
-            //get the invoice payment method, and remember it for the next call too
389
-            $this->_invoice_pm = apply_filters( 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', EEM_Payment_Method::instance()->get_one_of_type( 'Invoice' ), $transaction );
390
-        }
391
-        return $this->_invoice_pm;
381
+		if( ! $this->_invoice_pm instanceof EE_Payment_Method ) {
382
+			$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
383
+			$transaction = ! $transaction instanceof EE_Transaction
384
+						   && is_array($this->_extra_data)
385
+						   && isset($this->_extra_data['data'])
386
+						   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
387
+				? $this->_extra_data['data']->txn : $transaction;
388
+			//get the invoice payment method, and remember it for the next call too
389
+			$this->_invoice_pm = apply_filters( 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', EEM_Payment_Method::instance()->get_one_of_type( 'Invoice' ), $transaction );
390
+		}
391
+		return $this->_invoice_pm;
392 392
 	}
393 393
 
394 394
 
Please login to merge, or discard this patch.
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION') )
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('NO direct script access allowed');
5 5
 
6 6
 /**
@@ -45,50 +45,50 @@  discard block
 block discarded – undo
45 45
 
46 46
 
47 47
 	protected function _init_props() {
48
-		$this->label = esc_html__( 'Transaction Shortcodes', 'event_espresso' );
49
-		$this->description = esc_html__( 'All shortcodes specific to transaction related data', 'event_espresso' );
48
+		$this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
49
+		$this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
50 50
 		$this->_shortcodes = array(
51
-			'[TXN_ID]' => esc_html__( 'The transaction id for the purchase.', 'event_espresso' ),
52
-			'[PAYMENT_URL]' => esc_html__( 'This is a link to make a payment for the event', 'event_espresso' ),
53
-			'[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', 'event_espresso' ) . '<ul>'
54
-				. '<li>' . sprintf( esc_html__( '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', 'event_espresso' ), '<strong>', '</strong>' ) . '</li>'
55
-				. '<li>' . sprintf( esc_html__( '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', 'event_espresso' ), '<strong>', '</strong>' ) . '</li>'
56
-				. '<li>' . sprintf( esc_html__( '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', 'event_espresso' ), '<strong>', '</strong>' ) . '</li>'
51
+			'[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'),
52
+			'[PAYMENT_URL]' => esc_html__('This is a link to make a payment for the event', 'event_espresso'),
53
+			'[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__('This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', 'event_espresso').'<ul>'
54
+				. '<li>'.sprintf(esc_html__('%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', 'event_espresso'), '<strong>', '</strong>').'</li>'
55
+				. '<li>'.sprintf(esc_html__('%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', 'event_espresso'), '<strong>', '</strong>').'</li>'
56
+				. '<li>'.sprintf(esc_html__('%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', 'event_espresso'), '<strong>', '</strong>').'</li>'
57 57
 				. '</ul>',
58
-			'[PAYMENT_DUE_DATE_*]' => esc_html__( 'This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:', 'event_espresso' )
58
+			'[PAYMENT_DUE_DATE_*]' => esc_html__('This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:', 'event_espresso')
59 59
 				. '<ul>'
60
-				. '<li>' . sprintf( esc_html__( '%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.', 'event_espresso' ), '<strong>', '</strong>' ) . '</li>'
61
-				. '<li>' . sprintf( esc_html__( '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.', 'event_espresso' ), '<strong>', '</strong>' ) . '</li>'
62
-				. '<li>' . sprintf( esc_html__( '%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"', 'event_espresso' ), '<strong>', '</strong>' ) . '</li>',
63
-			'[INVOICE_LINK]' => esc_html__( 'This is a full html link to the invoice', 'event_espresso' ),
64
-			'[INVOICE_URL]' => esc_html__( 'This is just the url for the invoice', 'event_espresso' ),
65
-			'[INVOICE_LOGO_URL]' => esc_html__( 'This returns the url for the logo uploaded via the invoice settings page.', 'event_espresso' ),
66
-			'[INVOICE_LOGO]' => esc_html__( 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', 'event_espresso' ),
67
-			'[INVOICE_PAYEE_NAME]' => esc_html__( 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', 'event_espresso' ),
68
-			'[INVOICE_PAYEE_ADDRESS]' => esc_html__( 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', 'event_espresso' ),
69
-			'[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', 'event_espresso' ),
70
-			'[INVOICE_PAYEE_EMAIL]' => esc_html__( 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', 'event_espresso' ),
71
-			'[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( esc_html__( 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.', 'event_espresso' ), '<code>', '</code>' ),
72
-			'[TOTAL_COST]' => esc_html__( 'The total cost for the transaction', 'event_espresso' ),
73
-			'[TXN_STATUS]' => esc_html__( 'The transaction status for the transaction.', 'event_espresso' ),
74
-			'[TXN_STATUS_ID]' => esc_html__( 'The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.', 'event_espresso' ),
75
-			'[PAYMENT_STATUS]' => esc_html__( 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', 'event_espresso' ),
76
-			'[PAYMENT_GATEWAY]' => esc_html__( 'The payment gateway used for the transaction', 'event_espresso' ),
77
-			'[AMOUNT_PAID]' => esc_html__( 'The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.', 'event_espresso' ),
78
-			'[LAST_AMOUNT_PAID]' => esc_html__( 'This is the last payment or refund made on the transaction related to the message being generated.', 'event_espresso' ),
79
-			'[TOTAL_AMOUNT_PAID]' => esc_html__( 'This parses to the total amount paid over all payments', 'event_espresso' ),
80
-			'[TOTAL_OWING]' => esc_html__( 'The total owing on a transaction with no attributes.', 'event_espresso' ),
81
-			'[TXN_SUBTOTAL]' => esc_html__( 'The subtotal for all txn line items.', 'event_espresso' ),
82
-			'[TXN_TAX_SUBTOTAL]' => esc_html__( 'The subtotal for all tax line items.', 'event_espresso' ),
83
-			'[OWING_STATUS_MESSAGE_*]' => esc_html__( 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', 'event_espresso' ) . '<p></ul>' .
84
-				'<li><strong>still_owing</strong>:' . esc_html__( 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', 'event_espresso' ) . sprintf( esc_html__( '%sPlease make a payment.%s', 'event_espresso' ),  '<a href="[PAYMENT_URL]" class="noPrint">', '</a>' ) . '</li>' .
85
-				'<li><strong>none_owing</strong>:' . esc_html__( 'If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.', 'event_espresso' ) . '</li></ul></p>',
86
-			'[TXN_TOTAL_TICKETS]' => esc_html__( 'The total number of all tickets purchased in a transaction', 'event_espresso' ),
87
-			'[TKT_QTY_PURCHASED]' => sprintf( esc_html__( 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', 'event_espresso' ), '<strong>', '</strong>' ),
88
-			'[TRANSACTION_ADMIN_URL]' => esc_html__( 'The url to the admin page for this transaction', 'event_espresso' ),
89
-			'[RECEIPT_URL]' => esc_html__( 'This parses to the generated url for retrieving the receipt for the transaction', 'event_espresso' ),
90
-			'[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.', 'event_espresso' ),
91
-			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( esc_html__( 'The same as %1$s[INVOICE_RECEIPT_SWITCHER_URL]%2$s except this returns the html for a button linked to the invoice or receipt.', 'event_espresso' ), '<code>', '</code>' )
60
+				. '<li>'.sprintf(esc_html__('%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.', 'event_espresso'), '<strong>', '</strong>').'</li>'
61
+				. '<li>'.sprintf(esc_html__('%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.', 'event_espresso'), '<strong>', '</strong>').'</li>'
62
+				. '<li>'.sprintf(esc_html__('%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"', 'event_espresso'), '<strong>', '</strong>').'</li>',
63
+			'[INVOICE_LINK]' => esc_html__('This is a full html link to the invoice', 'event_espresso'),
64
+			'[INVOICE_URL]' => esc_html__('This is just the url for the invoice', 'event_espresso'),
65
+			'[INVOICE_LOGO_URL]' => esc_html__('This returns the url for the logo uploaded via the invoice settings page.', 'event_espresso'),
66
+			'[INVOICE_LOGO]' => esc_html__('This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', 'event_espresso'),
67
+			'[INVOICE_PAYEE_NAME]' => esc_html__('This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', 'event_espresso'),
68
+			'[INVOICE_PAYEE_ADDRESS]' => esc_html__('This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', 'event_espresso'),
69
+			'[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__('This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', 'event_espresso'),
70
+			'[INVOICE_PAYEE_EMAIL]' => esc_html__('This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', 'event_espresso'),
71
+			'[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf(esc_html__('This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.', 'event_espresso'), '<code>', '</code>'),
72
+			'[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'),
73
+			'[TXN_STATUS]' => esc_html__('The transaction status for the transaction.', 'event_espresso'),
74
+			'[TXN_STATUS_ID]' => esc_html__('The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.', 'event_espresso'),
75
+			'[PAYMENT_STATUS]' => esc_html__('The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', 'event_espresso'),
76
+			'[PAYMENT_GATEWAY]' => esc_html__('The payment gateway used for the transaction', 'event_espresso'),
77
+			'[AMOUNT_PAID]' => esc_html__('The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.', 'event_espresso'),
78
+			'[LAST_AMOUNT_PAID]' => esc_html__('This is the last payment or refund made on the transaction related to the message being generated.', 'event_espresso'),
79
+			'[TOTAL_AMOUNT_PAID]' => esc_html__('This parses to the total amount paid over all payments', 'event_espresso'),
80
+			'[TOTAL_OWING]' => esc_html__('The total owing on a transaction with no attributes.', 'event_espresso'),
81
+			'[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
82
+			'[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
83
+			'[OWING_STATUS_MESSAGE_*]' => esc_html__('A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', 'event_espresso').'<p></ul>'.
84
+				'<li><strong>still_owing</strong>:'.esc_html__('If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', 'event_espresso').sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'), '<a href="[PAYMENT_URL]" class="noPrint">', '</a>').'</li>'.
85
+				'<li><strong>none_owing</strong>:'.esc_html__('If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.', 'event_espresso').'</li></ul></p>',
86
+			'[TXN_TOTAL_TICKETS]' => esc_html__('The total number of all tickets purchased in a transaction', 'event_espresso'),
87
+			'[TKT_QTY_PURCHASED]' => sprintf(esc_html__('The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', 'event_espresso'), '<strong>', '</strong>'),
88
+			'[TRANSACTION_ADMIN_URL]' => esc_html__('The url to the admin page for this transaction', 'event_espresso'),
89
+			'[RECEIPT_URL]' => esc_html__('This parses to the generated url for retrieving the receipt for the transaction', 'event_espresso'),
90
+			'[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__('This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.', 'event_espresso'),
91
+			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(esc_html__('The same as %1$s[INVOICE_RECEIPT_SWITCHER_URL]%2$s except this returns the html for a button linked to the invoice or receipt.', 'event_espresso'), '<code>', '</code>')
92 92
 			);
93 93
 	}
94 94
 
@@ -99,40 +99,40 @@  discard block
 block discarded – undo
99 99
 	 * @param  string $shortcode the shortcode to be parsed.
100 100
 	 * @return string parsed shortcode
101 101
 	 */
102
-	protected function _parser( $shortcode ) {
102
+	protected function _parser($shortcode) {
103 103
 
104 104
 		//attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the _extra_data for the transaction.
105 105
 		$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
106
-		$transaction = ! $transaction instanceof EE_Transaction && is_array( $this->_extra_data ) &&  isset( $this->_extra_data['data'] ) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->txn: $transaction;
106
+		$transaction = ! $transaction instanceof EE_Transaction && is_array($this->_extra_data) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->txn : $transaction;
107 107
 
108 108
 		//payment
109 109
 		$payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
110
-		$payment = ! $payment instanceof EE_Payment && is_array( $this->_extra_data ) &&  isset( $this->_extra_data['data'] ) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment: $payment;
110
+		$payment = ! $payment instanceof EE_Payment && is_array($this->_extra_data) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment : $payment;
111 111
 
112 112
 
113
-		if ( ! $transaction instanceof EE_Transaction ) {
113
+		if ( ! $transaction instanceof EE_Transaction) {
114 114
 			return '';
115 115
 		}
116 116
 
117
-		switch ( $shortcode ) {
117
+		switch ($shortcode) {
118 118
 			case '[TXN_ID]' :
119 119
 				return $transaction->ID();
120 120
 				break;
121 121
 
122 122
 			case '[PAYMENT_URL]' :
123 123
 				$payment_url = $transaction->payment_overview_url();
124
-				return empty( $payment_url ) ? esc_html__( 'http://dummypaymenturlforpreview.com', 'event_espresso' ) : $payment_url;
124
+				return empty($payment_url) ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') : $payment_url;
125 125
 				break;
126 126
 
127 127
 			case '[INVOICE_LINK]' :
128 128
 				$invoice_url = $transaction->invoice_url();
129
-				$invoice_url = empty( $invoice_url ) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
130
-				return sprintf( esc_html__( '%sClick here for Invoice%s', 'event_espresso' ), '<a href="' . $invoice_url . '">', '</a>' );
129
+				$invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
130
+				return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'), '<a href="'.$invoice_url.'">', '</a>');
131 131
 				break; /**/
132 132
 
133 133
 			case '[INVOICE_URL]' :
134 134
 				$invoice_url = $transaction->invoice_url();
135
-				return empty( $invoice_url ) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
135
+				return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
136 136
 				break;
137 137
 
138 138
 			case '[INVOICE_LOGO_URL]' :
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				break;
141 141
 
142 142
 			case '[INVOICE_LOGO]' :
143
-				return $this->_get_invoice_logo( true );
143
+				return $this->_get_invoice_logo(true);
144 144
 				break;
145 145
 
146 146
 			case '[INVOICE_PAYEE_NAME]' :
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
 
163 163
 			case '[TOTAL_COST]' :
164 164
 				$total = $transaction->total();
165
-				return ! empty($total) ? EEH_Template::format_currency( $total ) : '';
165
+				return ! empty($total) ? EEH_Template::format_currency($total) : '';
166 166
 				break;
167 167
 
168 168
 			case '[PAYMENT_STATUS]' :
169 169
 				$status = $transaction->pretty_status();
170
-				return ! empty($status) ? $status : esc_html__( 'Unknown', 'event_espresso' );
170
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
171 171
 				break; /**/
172 172
 
173 173
 			// note the [payment_status] shortcode is kind of misleading because payment status might be different from txn status so I'm adding this here for clarity.
174 174
 			case '[TXN_STATUS]':
175 175
 				$status = $transaction->pretty_status();
176
-				return ! empty( $status ) ? $status : esc_html__( 'Unknown', 'event_espresso' );
176
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
177 177
 				break;
178 178
 
179 179
 			case '[TXN_STATUS_ID]' :
@@ -181,36 +181,36 @@  discard block
 block discarded – undo
181 181
 				break;
182 182
 
183 183
 			case '[PAYMENT_GATEWAY]' :
184
-				return $this->_get_payment_gateway( $transaction );
184
+				return $this->_get_payment_gateway($transaction);
185 185
 				break;
186 186
 
187 187
 			case '[AMOUNT_PAID]' :
188 188
 				return $payment instanceof EE_Payment
189
-					? EEH_Template::format_currency( $payment->amount() )
190
-					: EEH_Template::format_currency( 0 );
189
+					? EEH_Template::format_currency($payment->amount())
190
+					: EEH_Template::format_currency(0);
191 191
 				break;
192 192
 
193 193
 			case '[LAST_AMOUNT_PAID]' :
194 194
 				$last_payment = $transaction->last_payment();
195 195
 				return $last_payment instanceof EE_Payment
196
-					? EEH_Template::format_currency( $last_payment->amount() )
197
-					: EEH_Template::format_currency( 0 );
196
+					? EEH_Template::format_currency($last_payment->amount())
197
+					: EEH_Template::format_currency(0);
198 198
 
199 199
 			case '[TOTAL_AMOUNT_PAID]' :
200
-				return EEH_Template::format_currency( $transaction->paid() );
200
+				return EEH_Template::format_currency($transaction->paid());
201 201
 				break;
202 202
 
203 203
 			case '[TOTAL_OWING]' :
204 204
 				$total_owing = $transaction->remaining();
205
-				return EEH_Template::format_currency( $total_owing );
205
+				return EEH_Template::format_currency($total_owing);
206 206
 				break;
207 207
 
208 208
 			case '[TXN_SUBTOTAL]' :
209
-				return EEH_Template::format_currency( $this->_get_subtotal() );
209
+				return EEH_Template::format_currency($this->_get_subtotal());
210 210
 				break;
211 211
 
212 212
 			case '[TXN_TAX_SUBTOTAL]' :
213
-				return EEH_Template::format_currency( $this->_get_subtotal( true ) );
213
+				return EEH_Template::format_currency($this->_get_subtotal(true));
214 214
 				break;
215 215
 
216 216
 			case '[TKT_QTY_PURCHASED]' :
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
 				break;
220 220
 
221 221
 			case '[TRANSACTION_ADMIN_URL]' :
222
-				require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
223
-				$query_args = array( 'page' => 'espresso_transactions', 'action' => 'view_transaction', 'TXN_ID' => $transaction->ID() );
224
-				$url = EE_Admin_Page::add_query_args_and_nonce( $query_args, admin_url( 'admin.php' ) );
222
+				require_once EE_CORE.'admin/EE_Admin_Page.core.php';
223
+				$query_args = array('page' => 'espresso_transactions', 'action' => 'view_transaction', 'TXN_ID' => $transaction->ID());
224
+				$url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
225 225
 				return $url;
226 226
 				break;
227 227
 
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 229
 				//get primary_registration
230 230
 				$reg = $this->_data->primary_reg_obj;
231 231
 
232
-				if ( ! $reg instanceof EE_Registration ) {
232
+				if ( ! $reg instanceof EE_Registration) {
233 233
 					return '';
234 234
 				}
235 235
 				return $reg->receipt_url();
236 236
 				break;
237 237
 
238 238
 			case '[INVOICE_RECEIPT_SWITCHER_URL]' :
239
-				return $this->_get_invoice_receipt_switcher( false );
239
+				return $this->_get_invoice_receipt_switcher(false);
240 240
 				break;
241 241
 
242 242
 			case '[INVOICE_RECEIPT_SWITCHER_BUTTON]' :
@@ -246,20 +246,20 @@  discard block
 block discarded – undo
246 246
 
247 247
 		}
248 248
 
249
-		if ( strpos( $shortcode, '[OWING_STATUS_MESSAGE_*' ) !== false ) {
250
-			return $this->_get_custom_total_owing( $shortcode );
249
+		if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
250
+			return $this->_get_custom_total_owing($shortcode);
251 251
 		}
252 252
 
253
-		if ( strpos( $shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*' ) !== false ) {
254
-			return $this->_get_invoice_payee_tax_number( $shortcode );
253
+		if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
254
+			return $this->_get_invoice_payee_tax_number($shortcode);
255 255
 		}
256 256
 
257
-		if ( strpos( $shortcode, '[PAYMENT_LINK_IF_NEEDED_*' ) !== false ) {
258
-			return $this->_get_payment_link_if_needed( $shortcode );
257
+		if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
258
+			return $this->_get_payment_link_if_needed($shortcode);
259 259
 		}
260 260
 
261
-		if ( strpos( $shortcode, '[PAYMENT_DUE_DATE_*' ) !== false ) {
262
-			return $this->_get_payment_due_date( $shortcode, $transaction );
261
+		if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
262
+			return $this->_get_payment_due_date($shortcode, $transaction);
263 263
 		}
264 264
 
265 265
 		return '';
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return string parsed.
278 278
 	 */
279
-	private function _get_custom_total_owing( $shortcode ) {
280
-		$valid_shortcodes = array( 'transaction' );
281
-		$attrs = $this->_get_shortcode_attrs( $shortcode );
279
+	private function _get_custom_total_owing($shortcode) {
280
+		$valid_shortcodes = array('transaction');
281
+		$attrs = $this->_get_shortcode_attrs($shortcode);
282 282
 
283 283
 		//ensure default is set.
284 284
 		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
285 285
 		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction ? $addressee->txn->remaining() : 0;
286 286
 
287
-		if ( $total_owing > 0 ) {
288
-			$owing_content = ! empty( $attrs['still_owing'] ) ? $attrs['still_owing'] : sprintf( esc_html__( '%sPlease make a payment.%s', 'event_espresso' ),  '<a href="[PAYMENT_URL]" class="noPrint">', '</a>' );
289
-			$owing_content = $this->_shortcode_helper->parse_message_template( $owing_content, $addressee, $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message );
287
+		if ($total_owing > 0) {
288
+			$owing_content = ! empty($attrs['still_owing']) ? $attrs['still_owing'] : sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'), '<a href="[PAYMENT_URL]" class="noPrint">', '</a>');
289
+			$owing_content = $this->_shortcode_helper->parse_message_template($owing_content, $addressee, $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message);
290 290
 		} else {
291
-			$owing_content = ! empty( $attrs['none_owing']) ? $attrs['none_owing'] : '';
291
+			$owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
292 292
 		}
293 293
 
294 294
 		return $owing_content;
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	 * @param EE_Transaction $transaction
301 301
 	 * @return string
302 302
 	 */
303
-	private function _get_payment_gateway( $transaction ) {
304
-		$pm = $this->_get_invoice_payment_method( $transaction );
303
+	private function _get_payment_gateway($transaction) {
304
+		$pm = $this->_get_invoice_payment_method($transaction);
305 305
 		return $pm instanceof EE_Payment_Method ? $pm->name() : '';
306 306
 	}
307 307
 
@@ -316,37 +316,37 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @return string url or html
318 318
 	 */
319
-	private function _get_invoice_logo( $img_tags = false ) {
319
+	private function _get_invoice_logo($img_tags = false) {
320 320
 		//try to get the invoice payment method's logo for this transaction image first
321 321
 		$pm = $this->_get_invoice_payment_method();
322
-		if ( $pm instanceof EE_Payment_Method ){
323
-			$invoice_logo_url = $pm->get_extra_meta( 'pdf_logo_image', true );
322
+		if ($pm instanceof EE_Payment_Method) {
323
+			$invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
324 324
 		} else {
325 325
 			$invoice_logo_url = null;
326 326
 		}
327
-		if ( empty( $invoice_logo_url ) ){
327
+		if (empty($invoice_logo_url)) {
328 328
 			$invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
329 329
 		}
330 330
 
331
-		if ( empty( $invoice_logo_url ) ) {
331
+		if (empty($invoice_logo_url)) {
332 332
 			return '';
333 333
 		}
334 334
 
335
-		if ( ! $img_tags ) {
335
+		if ( ! $img_tags) {
336 336
 			return $invoice_logo_url;
337 337
 		}
338 338
 
339 339
 		//image tags have been requested.
340
-		$image_size = getimagesize( $invoice_logo_url );
340
+		$image_size = getimagesize($invoice_logo_url);
341 341
 
342 342
 		//if image is wider than 300px, set the width to 300
343
-		if ( $image_size[0] > 300 ) {
343
+		if ($image_size[0] > 300) {
344 344
 			$image_width = 300;
345 345
 		} else {
346 346
 			$image_width = $image_size[0];
347 347
 		}
348 348
 
349
-		return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
349
+		return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />';
350 350
 	}
351 351
 
352 352
 
@@ -363,10 +363,10 @@  discard block
 block discarded – undo
363 363
 	private function _get_invoice_payee_name() {
364 364
 		$payee_name = null;
365 365
 		$pm = $this->_get_invoice_payment_method();
366
-		if ( $pm instanceof EE_Payment_Method ){
367
-			$payee_name = $pm->get_extra_meta( 'pdf_payee_name', true );
366
+		if ($pm instanceof EE_Payment_Method) {
367
+			$payee_name = $pm->get_extra_meta('pdf_payee_name', true);
368 368
 		}
369
-		$payee_name = empty( $payee_name ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'name' ) : $payee_name;
369
+		$payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
370 370
 		return $payee_name;
371 371
 	}
372 372
 
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 *
378 378
 	 * @return \EE_Payment_Method|null
379 379
 	 */
380
-	private function _get_invoice_payment_method(){
381
-	    if( ! $this->_invoice_pm instanceof EE_Payment_Method ) {
380
+	private function _get_invoice_payment_method() {
381
+	    if ( ! $this->_invoice_pm instanceof EE_Payment_Method) {
382 382
             $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
383 383
             $transaction = ! $transaction instanceof EE_Transaction
384 384
                            && is_array($this->_extra_data)
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
387 387
                 ? $this->_extra_data['data']->txn : $transaction;
388 388
             //get the invoice payment method, and remember it for the next call too
389
-            $this->_invoice_pm = apply_filters( 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', EEM_Payment_Method::instance()->get_one_of_type( 'Invoice' ), $transaction );
389
+            $this->_invoice_pm = apply_filters('FHEE__EE_Transaction_Shortcodes__get_payment_method__default', EEM_Payment_Method::instance()->get_one_of_type('Invoice'), $transaction);
390 390
         }
391 391
         return $this->_invoice_pm;
392 392
 	}
@@ -404,10 +404,10 @@  discard block
 block discarded – undo
404 404
 	private function _get_invoice_payee_email() {
405 405
 		$payee_email = null;
406 406
 		$pm = $this->_get_invoice_payment_method();
407
-		if ( $pm instanceof EE_Payment_Method ){
408
-			$payee_email = $pm->get_extra_meta( 'pdf_payee_email', true );
407
+		if ($pm instanceof EE_Payment_Method) {
408
+			$payee_email = $pm->get_extra_meta('pdf_payee_email', true);
409 409
 		}
410
-		$payee_email = empty( $payee_email ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) : $payee_email;
410
+		$payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') : $payee_email;
411 411
 		return $payee_email;
412 412
 	}
413 413
 
@@ -423,24 +423,24 @@  discard block
 block discarded – undo
423 423
 	 *
424 424
 	 * @return string
425 425
 	 */
426
-	private function _get_invoice_payee_tax_number( $shortcode ) {
426
+	private function _get_invoice_payee_tax_number($shortcode) {
427 427
 		$payee_tax_number = null;
428 428
 		$pm = $this->_get_invoice_payment_method();
429
-		if ( $pm instanceof EE_Payment_Method ){
430
-			$payee_tax_number = $pm->get_extra_meta( 'pdf_payee_tax_number', true );
429
+		if ($pm instanceof EE_Payment_Method) {
430
+			$payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
431 431
 		}
432
-		$payee_tax_number = empty( $payee_tax_number ) ? EE_Registry::instance()->CFG->organization->vat : $payee_tax_number;
432
+		$payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat : $payee_tax_number;
433 433
 
434
-		if ( empty( $payee_tax_number ) ) {
434
+		if (empty($payee_tax_number)) {
435 435
 			return '';
436 436
 		}
437 437
 
438 438
 		//any attributes?
439
-		$attrs = $this->_get_shortcode_attrs( $shortcode );
439
+		$attrs = $this->_get_shortcode_attrs($shortcode);
440 440
 
441 441
 		//prefix?
442
-		$prefix = isset( $attrs['prefix'] ) ? $attrs['prefix'] : esc_html__( 'VAT/Tax Number: ', 'event_espresso' );
443
-		return $prefix . $payee_tax_number;
442
+		$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
443
+		return $prefix.$payee_tax_number;
444 444
 	}
445 445
 
446 446
 
@@ -457,22 +457,22 @@  discard block
 block discarded – undo
457 457
 	private function _get_invoice_payee_address() {
458 458
 		$payee_address = null;
459 459
 		$pm = $this->_get_invoice_payment_method();
460
-		if ( $pm instanceof EE_Payment_Method ){
461
-			$payee_address = $pm->get_extra_meta( 'pdf_payee_address', true );
460
+		if ($pm instanceof EE_Payment_Method) {
461
+			$payee_address = $pm->get_extra_meta('pdf_payee_address', true);
462 462
 		}
463
-		if ( empty( $payee_address ) ) {
463
+		if (empty($payee_address)) {
464 464
 			$organization = EE_Registry::instance()->CFG->organization;
465
-			$payee_address = $organization->get_pretty( 'address_1' ) . '<br>';
466
-			$payee_address .= ! empty( $organization->address_2 ) ? $organization->get_pretty( 'address_2' ) . '<br>' : '';
467
-			$payee_address .= $organization->get_pretty( 'city' ) . '<br>';
465
+			$payee_address = $organization->get_pretty('address_1').'<br>';
466
+			$payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2').'<br>' : '';
467
+			$payee_address .= $organization->get_pretty('city').'<br>';
468 468
 
469 469
 			//state
470
-			$state = EE_Registry::instance()->load_model( 'State' )->get_one_by_ID( $organization->STA_ID );
471
-			$payee_address .= $state instanceof EE_State ? $state->name()  : '';
470
+			$state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
471
+			$payee_address .= $state instanceof EE_State ? $state->name() : '';
472 472
 
473 473
 			//Country
474
-			$payee_address .= ! empty( $organization->CNT_ISO ) ? ', ' . $organization->CNT_ISO . '<br>' : '';
475
-			$payee_address .= ! empty( $organization->zip ) ? $organization->zip : '';
474
+			$payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : '';
475
+			$payee_address .= ! empty($organization->zip) ? $organization->zip : '';
476 476
 		}
477 477
 		return $payee_address;
478 478
 	}
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 	private function _get_invoice_payment_instructions() {
491 491
 		$instructions = null;
492 492
 		$pm = $this->_get_invoice_payment_method();
493
-		return ( $pm instanceof EE_Payment_Method ) ? $pm->get_extra_meta( 'pdf_instructions', true ) : '';
493
+		return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
494 494
 	}
495 495
 
496 496
 
@@ -504,27 +504,27 @@  discard block
 block discarded – undo
504 504
 	 *
505 505
 	 * @return string
506 506
 	 */
507
-	protected function _get_invoice_receipt_switcher( $button = true ) {
507
+	protected function _get_invoice_receipt_switcher($button = true) {
508 508
 		$reg = $this->_data->primary_reg_obj;
509
-		$message_type = isset( $this->_extra_data['message_type'] ) ? $this->_extra_data['message_type'] : '';
510
-		if ( ! $reg instanceof EE_Registration || empty( $message_type ) ) {
509
+		$message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
510
+		if ( ! $reg instanceof EE_Registration || empty($message_type)) {
511 511
 			return '';
512 512
 		}
513 513
 
514
-		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type  ? true : false;
515
-		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type ? esc_html__( 'View Invoice', 'event_espresso' ) : esc_html__( 'Switch to Invoice', 'event_espresso' );
516
-		$switch_to_label = ! $switch_to_invoice ? esc_html__( 'Switch to Receipt', 'event_espresso' ) : $switch_to_label;
514
+		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
515
+		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
516
+		$switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
517 517
 		$switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
518 518
 
519
-		if ( ! $button ) {
519
+		if ( ! $button) {
520 520
 			return $switch_to_url;
521 521
 		}
522 522
 
523
-		if ( ! empty( $switch_to_url ) ) {
523
+		if ( ! empty($switch_to_url)) {
524 524
 
525 525
 			return  '
526
-	<form method="post" action="' . $switch_to_url . '" >
527
-		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
526
+	<form method="post" action="' . $switch_to_url.'" >
527
+		<input class="print_button" type="submit" value="' . $switch_to_label.'" />
528 528
 	</form>
529 529
 			';
530 530
 		}
@@ -542,10 +542,10 @@  discard block
 block discarded – undo
542 542
 	 *
543 543
 	 * @return int
544 544
 	 */
545
-	private function _get_subtotal( $tax = false ) {
546
-		$grand_total = isset( $this->_data->grand_total_line_item ) ? $this->_data->grand_total_line_item : null;
545
+	private function _get_subtotal($tax = false) {
546
+		$grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
547 547
 
548
-		if ( ! $grand_total instanceof EE_Line_Item ) {
548
+		if ( ! $grand_total instanceof EE_Line_Item) {
549 549
 			return 0;
550 550
 		}
551 551
 
@@ -564,26 +564,26 @@  discard block
 block discarded – undo
564 564
 	 *
565 565
 	 * @return string parsed.
566 566
 	 */
567
-	private function _get_payment_link_if_needed( $shortcode ) {
568
-		$valid_shortcodes = array( 'transaction' );
569
-		$attrs = $this->_get_shortcode_attrs( $shortcode );
567
+	private function _get_payment_link_if_needed($shortcode) {
568
+		$valid_shortcodes = array('transaction');
569
+		$attrs = $this->_get_shortcode_attrs($shortcode);
570 570
 
571 571
 		//ensure default is set.
572 572
 		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
573 573
 		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction ? $addressee->txn->remaining() : 0;
574 574
 
575
-		if ( $total_owing > 0 ) {
576
-			$class = isset( $attrs['class'] ) ? $attrs['class'] : 'callout';
577
-			$custom_text = isset( $attrs['custom_text'] ) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
578
-			$container_tag = isset( $attrs['container_tag'] ) ? $attrs['container_tag'] : 'p';
579
-			$opening_tag = ! empty( $container_tag ) ? '<' . $container_tag : '';
580
-			$opening_tag .= ! empty( $opening_tag ) && ! empty( $class ) ? ' class="' . $class . '"' : $opening_tag;
581
-			$opening_tag .= ! empty( $opening_tag ) ? '>' : $opening_tag;
582
-			$closing_tag = ! empty( $container_tag ) ? '</' . $container_tag .'>' : '';
583
-			$content = $opening_tag . sprintf( $custom_text, '<a href="[PAYMENT_URL]">', '</a>' ) . $closing_tag;
575
+		if ($total_owing > 0) {
576
+			$class = isset($attrs['class']) ? $attrs['class'] : 'callout';
577
+			$custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
578
+			$container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
579
+			$opening_tag = ! empty($container_tag) ? '<'.$container_tag : '';
580
+			$opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag;
581
+			$opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
582
+			$closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : '';
583
+			$content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag;
584 584
 
585 585
 			//we need to re run this string through the parser to catch any shortcodes that are in it.
586
-			$owing_content = $this->_shortcode_helper->parse_message_template( $content, $addressee, $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message );
586
+			$owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message);
587 587
 		} else {
588 588
 			return '';
589 589
 		}
@@ -603,31 +603,31 @@  discard block
 block discarded – undo
603 603
 	 * @param EE_Transaction $transaction
604 604
 	 * @return string
605 605
 	 */
606
-	protected function _get_payment_due_date( $shortcode, EE_Transaction $transaction ) {
606
+	protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) {
607 607
 		//if transaction is paid in full then we can just return an empty string
608
-		if ( $transaction->remaining() === 0 ) {
608
+		if ($transaction->remaining() === 0) {
609 609
 			return '';
610 610
 		}
611 611
 
612
-		$attrs = $this->_get_shortcode_attrs( $shortcode );
613
-		$format = isset( $attrs['format'] ) ? $attrs['format'] : get_option( 'date_format' );
614
-		$days_until_due = isset( $attrs['days_until_due'] ) ? (int) $attrs['days_until_due'] : 30;
615
-		$prefix_text = isset( $attrs['prefix_text'] ) ? $attrs['prefix_text'] : esc_html__( 'Payment in full due by: ', 'event_espresso' );
616
-		$transaction_created = $transaction->get_DateTime_object( 'TXN_timestamp' );
612
+		$attrs = $this->_get_shortcode_attrs($shortcode);
613
+		$format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
614
+		$days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
615
+		$prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] : esc_html__('Payment in full due by: ', 'event_espresso');
616
+		$transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
617 617
 
618 618
 		//setup date due:
619 619
 		try {
620
-			if ( $transaction_created instanceof DateTime ) {
621
-				$date_due = $transaction_created->add( new DateInterval( 'P' . $days_until_due . 'D' ) )->format( $format );
620
+			if ($transaction_created instanceof DateTime) {
621
+				$date_due = $transaction_created->add(new DateInterval('P'.$days_until_due.'D'))->format($format);
622 622
 			} else {
623 623
 				throw new Exception();
624 624
 			}
625
-		} catch( Exception $e ) {
625
+		} catch (Exception $e) {
626 626
 			//format was likely invalid.
627 627
 			$date_due = 'Unable to calculate date due, likely the format string is invalid.';
628 628
 		}
629 629
 
630
-		return $prefix_text . $date_due;
630
+		return $prefix_text.$date_due;
631 631
 	}
632 632
 
633 633
 } //end EE_Transaction Shortcodes library
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 
79 79
 
80 80
 	/**
81
-	* @var EE_CPT_Base
82
-	*/
81
+	 * @var EE_CPT_Base
82
+	 */
83 83
 	protected $_cpt_model_obj = FALSE;
84 84
 
85 85
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 		//possibly reset pagenow.
208 208
 		if ( ! empty( $this->_req_data['page'] ) && $this->_req_data['page'] == $this->page_slug && !empty( $this->_req_data['action'] ) && isset( $this->_pagenow_map[$this->_req_data['action'] ] ) ) {
209 209
 			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
210
-            $hook_suffix = $pagenow;
210
+			$hook_suffix = $pagenow;
211 211
 		}
212 212
 	}
213 213
 
@@ -646,12 +646,12 @@  discard block
 block discarded – undo
646 646
 		$model = null;
647 647
 		if (
648 648
 			empty( $this->_cpt_model_names )
649
-		    || (
650
-			     ! $ignore_route_check
651
-			     && ! isset( $this->_cpt_routes[ $this->_req_action ] )
652
-		    ) || (
653
-			     $this->_cpt_model_obj instanceof EE_CPT_Base
654
-			     && $this->_cpt_model_obj->ID() === $id
649
+			|| (
650
+				 ! $ignore_route_check
651
+				 && ! isset( $this->_cpt_routes[ $this->_req_action ] )
652
+			) || (
653
+				 $this->_cpt_model_obj instanceof EE_CPT_Base
654
+				 && $this->_cpt_model_obj->ID() === $id
655 655
 			)
656 656
 		) {
657 657
 			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
@@ -891,9 +891,9 @@  discard block
 block discarded – undo
891 891
 		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892 892
 		if ( $update
893 893
 			&& (
894
-			     ! $this->_cpt_model_obj instanceof EE_CPT_Base
895
-			     || $this->_cpt_model_obj->ID() !== $post_id
896
-		     )
894
+				 ! $this->_cpt_model_obj instanceof EE_CPT_Base
895
+				 || $this->_cpt_model_obj->ID() !== $post_id
896
+			 )
897 897
 		) {
898 898
 			return;
899 899
 		}
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_List_Shortcodes.lib.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
 	exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
 		$this->label = __('Payment List Shortcodes', 'event_espresso');
33 33
 		$this->description = __('All shortcodes specific to payment lists', 'event_espresso');
34 34
 		$this->_shortcodes = array(
35
-			'[PAYMENT_LIST_*]' => __('Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:', 'event_espresso') . '<p><ul>' .
36
-				'<li><strong>no_payments</strong>:' . sprintf( __('Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"', 'event_espresso'),  htmlspecialchars('<td class="aln-cntr" colspan="6">'), htmlspecialchars('</td>') ) . '</li>' .
35
+			'[PAYMENT_LIST_*]' => __('Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:', 'event_espresso').'<p><ul>'.
36
+				'<li><strong>no_payments</strong>:'.sprintf(__('Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"', 'event_espresso'), htmlspecialchars('<td class="aln-cntr" colspan="6">'), htmlspecialchars('</td>')).'</li>'.
37 37
 				'</ul></p>'
38 38
 			);
39 39
 	}
40 40
 
41 41
 
42 42
 
43
-	protected function _parser( $shortcode ) {
43
+	protected function _parser($shortcode) {
44 44
 
45
-		if ( strpos( $shortcode, '[PAYMENT_LIST_*' ) !== FALSE ) {
46
-			return $this->_get_payment_list( $shortcode );
45
+		if (strpos($shortcode, '[PAYMENT_LIST_*') !== FALSE) {
46
+			return $this->_get_payment_list($shortcode);
47 47
 		}
48 48
 		return '';
49 49
 	}
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @return string parsed ticket line item list.
62 62
 	 */
63
-	private function _get_payment_list( $shortcode ) {
63
+	private function _get_payment_list($shortcode) {
64 64
 		$this->_validate_list_requirements();
65 65
 
66 66
 
67
-		if ( ! $this->_data['data'] instanceof EE_Messages_Addressee ) {
67
+		if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
68 68
 			return '';
69 69
 		}
70 70
 
71
-		$valid_shortcodes = array( 'payment' );
71
+		$valid_shortcodes = array('payment');
72 72
 
73 73
 		$addressee_obj = $this->_data['data'];
74 74
 		$templates = $this->_extra_data['template'];
75
-		$payments = apply_filters( 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', $addressee_obj->payments );
75
+		$payments = apply_filters('FHEE__Payment_List_Shortcodes___get_payments_list__payments', $addressee_obj->payments);
76 76
 
77 77
 		//let's get any attributes that may be present and set the defaults.
78
-		$atts = $this->_get_shortcode_attrs( $shortcode );
78
+		$atts = $this->_get_shortcode_attrs($shortcode);
79 79
 
80
-		$no_payments_msg = empty( $atts['no_payments'] ) ?  __('No approved payments have been received.','event_espresso') : $atts['no_payments'];
80
+		$no_payments_msg = empty($atts['no_payments']) ? __('No approved payments have been received.', 'event_espresso') : $atts['no_payments'];
81 81
 
82 82
 		//made it here so we have an array of paymnets, so we should have what we need.
83
-		$payment_content = empty( $payments ) ? $no_payments_msg : '';
83
+		$payment_content = empty($payments) ? $no_payments_msg : '';
84 84
 
85 85
 		$payments = (array) $payments;
86 86
 
87
-		foreach ( $payments as $payment ) {
88
-			$payment_content .= $this->_shortcode_helper->parse_payment_list_template( $templates['payment_list'], $payment, $valid_shortcodes, $this->_extra_data );
87
+		foreach ($payments as $payment) {
88
+			$payment_content .= $this->_shortcode_helper->parse_payment_list_template($templates['payment_list'], $payment, $valid_shortcodes, $this->_extra_data);
89 89
 		}
90 90
 
91 91
 		return $payment_content;
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -9,164 +9,164 @@
 block discarded – undo
9 9
 abstract class EE_Table_Base
10 10
 {
11 11
 
12
-    /**
13
-     * This holds the table_name without the table prefix.
14
-     *
15
-     * @var string
16
-     */
17
-    var $_table_name;
18
-
19
-
20
-    /**
21
-     * This holds what is used as the alias for the table in queries.
22
-     *
23
-     * @var string
24
-     */
25
-    var $_table_alias;
26
-
27
-
28
-    /**
29
-     * Table's private key column
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_pk_column;
34
-
35
-
36
-    /**
37
-     * Whether this table is a global table (in multisite) or specific to site.
38
-     *
39
-     * @var bool
40
-     */
41
-    protected $_global;
42
-
43
-
44
-
45
-    /**
46
-     * @global wpdb   $wpdb
47
-     * @param string  $table_name with or without wpdb prefix
48
-     * @param string  $pk_column
49
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
-     *                            install, or whether each site on a multisite install has a copy of this table
51
-     */
52
-    function __construct($table_name, $pk_column, $global = false)
53
-    {
54
-        $this->_global = $global;
55
-        $prefix = $this->get_table_prefix();
56
-        //if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
-        if (strpos($table_name, $prefix) === 0) {
58
-            $table_name = ltrim($table_name, $prefix);
59
-        }
60
-        $this->_table_name = $table_name;
61
-        $this->_pk_column = $pk_column;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This returns the table prefix for the current model state.
68
-     *
69
-     * @global wpdb $wpdb
70
-     * @return string
71
-     */
72
-    public function get_table_prefix()
73
-    {
74
-        global $wpdb;
75
-        if ($this->_global) {
76
-            $prefix = $wpdb->base_prefix;
77
-        } else {
78
-            $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
-        }
80
-        return $prefix;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Used to set the table_alias property
87
-     *
88
-     * @param string $table_alias
89
-     */
90
-    function _construct_finalize_with_alias($table_alias)
91
-    {
92
-        $this->_table_alias = $table_alias;
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
-     *
100
-     * @return string
101
-     */
102
-    function get_table_name()
103
-    {
104
-        return $this->get_table_prefix() . $this->_table_name;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Provides what is currently set as the alias for the table to be used in queries.
111
-     *
112
-     * @return string
113
-     * @throws EE_Error
114
-     */
115
-    function get_table_alias()
116
-    {
117
-        if ( ! $this->_table_alias) {
118
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
-        }
120
-        return $this->_table_alias;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string name of column of PK
127
-     */
128
-    function get_pk_column()
129
-    {
130
-        return $this->_pk_column;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * returns a string with the table alias, a period, and the private key's column.
137
-     *
138
-     * @return string
139
-     */
140
-    function get_fully_qualified_pk_column()
141
-    {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
-        return $sql;
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * returns the special sql for a inner select with a limit.
150
-     *
151
-     * @return string    SQL select
152
-     */
153
-    public function get_select_join_limit($limit)
154
-    {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
-        return $SQL;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Returns whether or not htis is a global table (ie, on multisite there's
164
-     * only one of these tables, on the main blog)
165
-     *
166
-     * @return boolean
167
-     */
168
-    public function is_global()
169
-    {
170
-        return $this->_global;
171
-    }
12
+	/**
13
+	 * This holds the table_name without the table prefix.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	var $_table_name;
18
+
19
+
20
+	/**
21
+	 * This holds what is used as the alias for the table in queries.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	var $_table_alias;
26
+
27
+
28
+	/**
29
+	 * Table's private key column
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_pk_column;
34
+
35
+
36
+	/**
37
+	 * Whether this table is a global table (in multisite) or specific to site.
38
+	 *
39
+	 * @var bool
40
+	 */
41
+	protected $_global;
42
+
43
+
44
+
45
+	/**
46
+	 * @global wpdb   $wpdb
47
+	 * @param string  $table_name with or without wpdb prefix
48
+	 * @param string  $pk_column
49
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
+	 *                            install, or whether each site on a multisite install has a copy of this table
51
+	 */
52
+	function __construct($table_name, $pk_column, $global = false)
53
+	{
54
+		$this->_global = $global;
55
+		$prefix = $this->get_table_prefix();
56
+		//if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
+		if (strpos($table_name, $prefix) === 0) {
58
+			$table_name = ltrim($table_name, $prefix);
59
+		}
60
+		$this->_table_name = $table_name;
61
+		$this->_pk_column = $pk_column;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This returns the table prefix for the current model state.
68
+	 *
69
+	 * @global wpdb $wpdb
70
+	 * @return string
71
+	 */
72
+	public function get_table_prefix()
73
+	{
74
+		global $wpdb;
75
+		if ($this->_global) {
76
+			$prefix = $wpdb->base_prefix;
77
+		} else {
78
+			$prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
+		}
80
+		return $prefix;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Used to set the table_alias property
87
+	 *
88
+	 * @param string $table_alias
89
+	 */
90
+	function _construct_finalize_with_alias($table_alias)
91
+	{
92
+		$this->_table_alias = $table_alias;
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
+	 *
100
+	 * @return string
101
+	 */
102
+	function get_table_name()
103
+	{
104
+		return $this->get_table_prefix() . $this->_table_name;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Provides what is currently set as the alias for the table to be used in queries.
111
+	 *
112
+	 * @return string
113
+	 * @throws EE_Error
114
+	 */
115
+	function get_table_alias()
116
+	{
117
+		if ( ! $this->_table_alias) {
118
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
+		}
120
+		return $this->_table_alias;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string name of column of PK
127
+	 */
128
+	function get_pk_column()
129
+	{
130
+		return $this->_pk_column;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * returns a string with the table alias, a period, and the private key's column.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	function get_fully_qualified_pk_column()
141
+	{
142
+		$sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
+		return $sql;
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * returns the special sql for a inner select with a limit.
150
+	 *
151
+	 * @return string    SQL select
152
+	 */
153
+	public function get_select_join_limit($limit)
154
+	{
155
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
+		$SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
+		return $SQL;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Returns whether or not htis is a global table (ie, on multisite there's
164
+	 * only one of these tables, on the main blog)
165
+	 *
166
+	 * @return boolean
167
+	 */
168
+	public function is_global()
169
+	{
170
+		return $this->_global;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     function get_table_name()
103 103
     {
104
-        return $this->get_table_prefix() . $this->_table_name;
104
+        return $this->get_table_prefix().$this->_table_name;
105 105
     }
106 106
 
107 107
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     function get_fully_qualified_pk_column()
141 141
     {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
142
+        $sql = $this->get_table_alias().".".$this->get_pk_column();
143 143
         return $sql;
144 144
     }
145 145
 
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function get_select_join_limit($limit)
154 154
     {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
155
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
156
+        $SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
157 157
         return $SQL;
158 158
     }
159 159
 
Please login to merge, or discard this patch.
modules/ticket_selector/DatetimeSelector.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -16,159 +16,159 @@
 block discarded – undo
16 16
 class DatetimeSelector
17 17
 {
18 18
 
19
-    /**
20
-     * @var \EE_Event $event
21
-     */
22
-    protected $event;
23
-
24
-    /**
25
-     * @var \EE_Ticket[] $tickets
26
-     */
27
-    protected $tickets;
28
-
29
-    /**
30
-     * @var \EE_Datetime[] $datetimes
31
-     */
32
-    protected $datetimes;
33
-
34
-    /**
35
-     * @var \EE_Ticket_Selector_Config $template_settings
36
-     */
37
-    protected $template_settings;
38
-
39
-    /**
40
-     * @var boolean $active
41
-     */
42
-    protected $active = false;
43
-
44
-
45
-
46
-    /**
47
-     * DatetimeSelector constructor.
48
-     *
49
-     * @param \EE_Event                  $event
50
-     * @param \EE_Ticket[]               $tickets
51
-     * @param \EE_Ticket_Selector_Config $template_settings
52
-     * @throws \EE_Error
53
-     */
54
-    public function __construct(\EE_Event $event, array $tickets, \EE_Ticket_Selector_Config $template_settings)
55
-    {
56
-        $this->event = $event;
57
-        $this->tickets = $tickets;
58
-        $this->template_settings = $template_settings;
59
-        $this->datetimes = $this->getAllDatetimesForAllTicket($tickets);
60
-        $this->active = $this->template_settings->showDatetimeSelector($this->datetimes);
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * @param \EE_Ticket[] $tickets
67
-     * @return array
68
-     * @throws \EE_Error
69
-     */
70
-    protected function getAllDatetimesForAllTicket($tickets = array())
71
-    {
72
-        $datetimes = array();
73
-        foreach ($tickets as $ticket) {
74
-            $datetimes = $this->getTicketDatetimes($ticket, $datetimes);
75
-        }
76
-        return $datetimes;
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * @param \EE_Ticket      $ticket
83
-     * @param  \EE_Datetime[] $datetimes
84
-     * @return \EE_Datetime[]
85
-     * @throws \EE_Error
86
-     */
87
-    protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array())
88
-    {
89
-        $ticket_datetimes = $ticket->datetimes(
90
-            array(
91
-                'order_by'                 => array(
92
-                    'DTT_order'     => 'ASC',
93
-                    'DTT_EVT_start' => 'ASC'
94
-                ),
95
-                'default_where_conditions' => 'none',
96
-            )
97
-        );
98
-        foreach ($ticket_datetimes as $ticket_datetime) {
99
-            if ( ! $ticket_datetime instanceof \EE_Datetime) {
100
-                continue;
101
-            }
102
-            $datetimes[ $ticket_datetime->ID() ] = $ticket_datetime;
103
-        }
104
-        return $datetimes;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @param \EE_Ticket                 $ticket
111
-     * @return string
112
-     * @throws \EE_Error
113
-     */
114
-    public function getTicketDatetimeClasses( \EE_Ticket $ticket ) {
115
-        if ( ! $this->active) {
116
-            return '';
117
-        }
118
-        $ticket_datetimes = $this->getTicketDatetimes($ticket);
119
-        $classes = '';
120
-        foreach ($this->datetimes as $datetime) {
121
-            if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) {
122
-                continue;
123
-            }
124
-            $classes .= ' ee-ticket-datetimes-' . $datetime->date_range('Y_m_d', '-');
125
-        }
126
-        $classes .= ' ee-hidden-ticket-tr';
127
-        return $classes;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @param string $date_format
134
-     * @return string
135
-     * @throws \EE_Error
136
-     */
137
-    public function getDatetimeSelector($date_format = 'Y-m-d') {
138
-        if ( ! $this->active) {
139
-            return '';
140
-        }
141
-        $datetime_options = array();
142
-        foreach ($this->datetimes as $datetime) {
143
-            if ( ! $datetime instanceof \EE_Datetime) {
144
-                continue;
145
-            }
146
-            $desc = $datetime->name();
147
-            $desc .= ! empty($desc)
148
-                ? '&nbsp;' . $datetime->date_range($date_format)
149
-                : $datetime->date_range($date_format);
150
-            $datetime_options[$datetime->date_range('Y_m_d', '-')] = $desc;
151
-        }
152
-        $dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input(
153
-            $datetime_options,
154
-            array(
155
-                'html_id'               => 'datetime-selector-' . $this->event->ID(),
156
-                'html_name'             => 'datetime_selector_' . $this->event->ID(),
157
-                'html_class'            => 'datetime-selector',
158
-                'select_button_text'       => '<span class="dashicons dashicons-calendar-alt"></span> '
159
-                                            . esc_html__('Select a Datetime', 'event_espresso'),
160
-                'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"',
161
-            )
162
-        );
163
-        return \EEH_HTML::div(
164
-            \EEH_HTML::div(
165
-                $dropdown_selector->get_html_for_input(),
166
-                '', 'select-wrap-dv'
167
-            )
168
-            . \EEH_HTML::br(),
169
-            '', 'datetime_selector-dv'
170
-        );
171
-    }
19
+	/**
20
+	 * @var \EE_Event $event
21
+	 */
22
+	protected $event;
23
+
24
+	/**
25
+	 * @var \EE_Ticket[] $tickets
26
+	 */
27
+	protected $tickets;
28
+
29
+	/**
30
+	 * @var \EE_Datetime[] $datetimes
31
+	 */
32
+	protected $datetimes;
33
+
34
+	/**
35
+	 * @var \EE_Ticket_Selector_Config $template_settings
36
+	 */
37
+	protected $template_settings;
38
+
39
+	/**
40
+	 * @var boolean $active
41
+	 */
42
+	protected $active = false;
43
+
44
+
45
+
46
+	/**
47
+	 * DatetimeSelector constructor.
48
+	 *
49
+	 * @param \EE_Event                  $event
50
+	 * @param \EE_Ticket[]               $tickets
51
+	 * @param \EE_Ticket_Selector_Config $template_settings
52
+	 * @throws \EE_Error
53
+	 */
54
+	public function __construct(\EE_Event $event, array $tickets, \EE_Ticket_Selector_Config $template_settings)
55
+	{
56
+		$this->event = $event;
57
+		$this->tickets = $tickets;
58
+		$this->template_settings = $template_settings;
59
+		$this->datetimes = $this->getAllDatetimesForAllTicket($tickets);
60
+		$this->active = $this->template_settings->showDatetimeSelector($this->datetimes);
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * @param \EE_Ticket[] $tickets
67
+	 * @return array
68
+	 * @throws \EE_Error
69
+	 */
70
+	protected function getAllDatetimesForAllTicket($tickets = array())
71
+	{
72
+		$datetimes = array();
73
+		foreach ($tickets as $ticket) {
74
+			$datetimes = $this->getTicketDatetimes($ticket, $datetimes);
75
+		}
76
+		return $datetimes;
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * @param \EE_Ticket      $ticket
83
+	 * @param  \EE_Datetime[] $datetimes
84
+	 * @return \EE_Datetime[]
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array())
88
+	{
89
+		$ticket_datetimes = $ticket->datetimes(
90
+			array(
91
+				'order_by'                 => array(
92
+					'DTT_order'     => 'ASC',
93
+					'DTT_EVT_start' => 'ASC'
94
+				),
95
+				'default_where_conditions' => 'none',
96
+			)
97
+		);
98
+		foreach ($ticket_datetimes as $ticket_datetime) {
99
+			if ( ! $ticket_datetime instanceof \EE_Datetime) {
100
+				continue;
101
+			}
102
+			$datetimes[ $ticket_datetime->ID() ] = $ticket_datetime;
103
+		}
104
+		return $datetimes;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @param \EE_Ticket                 $ticket
111
+	 * @return string
112
+	 * @throws \EE_Error
113
+	 */
114
+	public function getTicketDatetimeClasses( \EE_Ticket $ticket ) {
115
+		if ( ! $this->active) {
116
+			return '';
117
+		}
118
+		$ticket_datetimes = $this->getTicketDatetimes($ticket);
119
+		$classes = '';
120
+		foreach ($this->datetimes as $datetime) {
121
+			if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) {
122
+				continue;
123
+			}
124
+			$classes .= ' ee-ticket-datetimes-' . $datetime->date_range('Y_m_d', '-');
125
+		}
126
+		$classes .= ' ee-hidden-ticket-tr';
127
+		return $classes;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @param string $date_format
134
+	 * @return string
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function getDatetimeSelector($date_format = 'Y-m-d') {
138
+		if ( ! $this->active) {
139
+			return '';
140
+		}
141
+		$datetime_options = array();
142
+		foreach ($this->datetimes as $datetime) {
143
+			if ( ! $datetime instanceof \EE_Datetime) {
144
+				continue;
145
+			}
146
+			$desc = $datetime->name();
147
+			$desc .= ! empty($desc)
148
+				? '&nbsp;' . $datetime->date_range($date_format)
149
+				: $datetime->date_range($date_format);
150
+			$datetime_options[$datetime->date_range('Y_m_d', '-')] = $desc;
151
+		}
152
+		$dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input(
153
+			$datetime_options,
154
+			array(
155
+				'html_id'               => 'datetime-selector-' . $this->event->ID(),
156
+				'html_name'             => 'datetime_selector_' . $this->event->ID(),
157
+				'html_class'            => 'datetime-selector',
158
+				'select_button_text'       => '<span class="dashicons dashicons-calendar-alt"></span> '
159
+											. esc_html__('Select a Datetime', 'event_espresso'),
160
+				'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"',
161
+			)
162
+		);
163
+		return \EEH_HTML::div(
164
+			\EEH_HTML::div(
165
+				$dropdown_selector->get_html_for_input(),
166
+				'', 'select-wrap-dv'
167
+			)
168
+			. \EEH_HTML::br(),
169
+			'', 'datetime_selector-dv'
170
+		);
171
+	}
172 172
 
173 173
 
174 174
 
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2566 added lines, -2566 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,2572 +17,2572 @@  discard block
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-    /**
46
-     * @var EE_Event
47
-     */
48
-    protected $_cpt_model_obj = false;
49
-
50
-
51
-
52
-    protected function _init_page_props()
53
-    {
54
-        $this->page_slug = EVENTS_PG_SLUG;
55
-        $this->page_label = EVENTS_LABEL;
56
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
57
-        $this->_admin_base_path = EVENTS_ADMIN;
58
-        $this->_cpt_model_names = array(
59
-            'create_new' => 'EEM_Event',
60
-            'edit'       => 'EEM_Event',
61
-        );
62
-        $this->_cpt_edit_routes = array(
63
-            'espresso_events' => 'edit',
64
-        );
65
-        add_action(
66
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
-            array($this, 'verify_event_edit')
68
-        );
69
-    }
70
-
71
-
72
-
73
-    protected function _ajax_hooks()
74
-    {
75
-        //todo: all hooks for events ajax goes in here.
76
-    }
77
-
78
-
79
-
80
-    protected function _define_page_props()
81
-    {
82
-        $this->_admin_page_title = EVENTS_LABEL;
83
-        $this->_labels = array(
84
-            'buttons'      => array(
85
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
86
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
87
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
88
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
89
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
90
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
91
-            ),
92
-            'editor_title' => array(
93
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
94
-            ),
95
-            'publishbox'   => array(
96
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
97
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
98
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
99
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
100
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-
107
-    protected function _set_page_routes()
108
-    {
109
-        //load formatter helper
110
-        //load field generator helper
111
-        //is there a evt_id in the request?
112
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
113
-            ? $this->_req_data['EVT_ID'] : 0;
114
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
115
-        $this->_page_routes = array(
116
-            'default'                       => array(
117
-                'func'       => '_events_overview_list_table',
118
-                'capability' => 'ee_read_events',
119
-            ),
120
-            'create_new'                    => array(
121
-                'func'       => '_create_new_cpt_item',
122
-                'capability' => 'ee_edit_events',
123
-            ),
124
-            'edit'                          => array(
125
-                'func'       => '_edit_cpt_item',
126
-                'capability' => 'ee_edit_event',
127
-                'obj_id'     => $evt_id,
128
-            ),
129
-            'copy_event'                    => array(
130
-                'func'       => '_copy_events',
131
-                'capability' => 'ee_edit_event',
132
-                'obj_id'     => $evt_id,
133
-                'noheader'   => true,
134
-            ),
135
-            'trash_event'                   => array(
136
-                'func'       => '_trash_or_restore_event',
137
-                'args'       => array('event_status' => 'trash'),
138
-                'capability' => 'ee_delete_event',
139
-                'obj_id'     => $evt_id,
140
-                'noheader'   => true,
141
-            ),
142
-            'trash_events'                  => array(
143
-                'func'       => '_trash_or_restore_events',
144
-                'args'       => array('event_status' => 'trash'),
145
-                'capability' => 'ee_delete_events',
146
-                'noheader'   => true,
147
-            ),
148
-            'restore_event'                 => array(
149
-                'func'       => '_trash_or_restore_event',
150
-                'args'       => array('event_status' => 'draft'),
151
-                'capability' => 'ee_delete_event',
152
-                'obj_id'     => $evt_id,
153
-                'noheader'   => true,
154
-            ),
155
-            'restore_events'                => array(
156
-                'func'       => '_trash_or_restore_events',
157
-                'args'       => array('event_status' => 'draft'),
158
-                'capability' => 'ee_delete_events',
159
-                'noheader'   => true,
160
-            ),
161
-            'delete_event'                  => array(
162
-                'func'       => '_delete_event',
163
-                'capability' => 'ee_delete_event',
164
-                'obj_id'     => $evt_id,
165
-                'noheader'   => true,
166
-            ),
167
-            'delete_events'                 => array(
168
-                'func'       => '_delete_events',
169
-                'capability' => 'ee_delete_events',
170
-                'noheader'   => true,
171
-            ),
172
-            'view_report'                   => array(
173
-                'func'      => '_view_report',
174
-                'capablity' => 'ee_edit_events',
175
-            ),
176
-            'default_event_settings'        => array(
177
-                'func'       => '_default_event_settings',
178
-                'capability' => 'manage_options',
179
-            ),
180
-            'update_default_event_settings' => array(
181
-                'func'       => '_update_default_event_settings',
182
-                'capability' => 'manage_options',
183
-                'noheader'   => true,
184
-            ),
185
-            'template_settings'             => array(
186
-                'func'       => '_template_settings',
187
-                'capability' => 'manage_options',
188
-            ),
189
-            //event category tab related
190
-            'add_category'                  => array(
191
-                'func'       => '_category_details',
192
-                'capability' => 'ee_edit_event_category',
193
-                'args'       => array('add'),
194
-            ),
195
-            'edit_category'                 => array(
196
-                'func'       => '_category_details',
197
-                'capability' => 'ee_edit_event_category',
198
-                'args'       => array('edit'),
199
-            ),
200
-            'delete_categories'             => array(
201
-                'func'       => '_delete_categories',
202
-                'capability' => 'ee_delete_event_category',
203
-                'noheader'   => true,
204
-            ),
205
-            'delete_category'               => array(
206
-                'func'       => '_delete_categories',
207
-                'capability' => 'ee_delete_event_category',
208
-                'noheader'   => true,
209
-            ),
210
-            'insert_category'               => array(
211
-                'func'       => '_insert_or_update_category',
212
-                'args'       => array('new_category' => true),
213
-                'capability' => 'ee_edit_event_category',
214
-                'noheader'   => true,
215
-            ),
216
-            'update_category'               => array(
217
-                'func'       => '_insert_or_update_category',
218
-                'args'       => array('new_category' => false),
219
-                'capability' => 'ee_edit_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'category_list'                 => array(
223
-                'func'       => '_category_list_table',
224
-                'capability' => 'ee_manage_event_categories',
225
-            ),
226
-        );
227
-    }
228
-
229
-
230
-
231
-    protected function _set_page_config()
232
-    {
233
-        $this->_page_config = array(
234
-            'default'                => array(
235
-                'nav'           => array(
236
-                    'label' => esc_html__('Overview', 'event_espresso'),
237
-                    'order' => 10,
238
-                ),
239
-                'list_table'    => 'Events_Admin_List_Table',
240
-                'help_tabs'     => array(
241
-                    'events_overview_help_tab'                       => array(
242
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
243
-                        'filename' => 'events_overview',
244
-                    ),
245
-                    'events_overview_table_column_headings_help_tab' => array(
246
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
247
-                        'filename' => 'events_overview_table_column_headings',
248
-                    ),
249
-                    'events_overview_filters_help_tab'               => array(
250
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
251
-                        'filename' => 'events_overview_filters',
252
-                    ),
253
-                    'events_overview_view_help_tab'                  => array(
254
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
255
-                        'filename' => 'events_overview_views',
256
-                    ),
257
-                    'events_overview_other_help_tab'                 => array(
258
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
259
-                        'filename' => 'events_overview_other',
260
-                    ),
261
-                ),
262
-                'help_tour'     => array(
263
-                    'Event_Overview_Help_Tour',
264
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
265
-                ),
266
-                'qtips'         => array(
267
-                    'EE_Event_List_Table_Tips',
268
-                ),
269
-                'require_nonce' => false,
270
-            ),
271
-            'create_new'             => array(
272
-                'nav'           => array(
273
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
274
-                    'order'      => 5,
275
-                    'persistent' => false,
276
-                ),
277
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
278
-                'help_tabs'     => array(
279
-                    'event_editor_help_tab'                            => array(
280
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
281
-                        'filename' => 'event_editor',
282
-                    ),
283
-                    'event_editor_title_richtexteditor_help_tab'       => array(
284
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
285
-                        'filename' => 'event_editor_title_richtexteditor',
286
-                    ),
287
-                    'event_editor_venue_details_help_tab'              => array(
288
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
289
-                        'filename' => 'event_editor_venue_details',
290
-                    ),
291
-                    'event_editor_event_datetimes_help_tab'            => array(
292
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
293
-                        'filename' => 'event_editor_event_datetimes',
294
-                    ),
295
-                    'event_editor_event_tickets_help_tab'              => array(
296
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
297
-                        'filename' => 'event_editor_event_tickets',
298
-                    ),
299
-                    'event_editor_event_registration_options_help_tab' => array(
300
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
301
-                        'filename' => 'event_editor_event_registration_options',
302
-                    ),
303
-                    'event_editor_tags_categories_help_tab'            => array(
304
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
305
-                        'filename' => 'event_editor_tags_categories',
306
-                    ),
307
-                    'event_editor_questions_registrants_help_tab'      => array(
308
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
309
-                        'filename' => 'event_editor_questions_registrants',
310
-                    ),
311
-                    'event_editor_save_new_event_help_tab'             => array(
312
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
313
-                        'filename' => 'event_editor_save_new_event',
314
-                    ),
315
-                    'event_editor_other_help_tab'                      => array(
316
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
317
-                        'filename' => 'event_editor_other',
318
-                    ),
319
-                ),
320
-                'help_tour'     => array(
321
-                    'Event_Editor_Help_Tour',
322
-                ),
323
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
324
-                'require_nonce' => false,
325
-            ),
326
-            'edit'                   => array(
327
-                'nav'           => array(
328
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
329
-                    'order'      => 5,
330
-                    'persistent' => false,
331
-                    'url'        => isset($this->_req_data['post'])
332
-                        ? EE_Admin_Page::add_query_args_and_nonce(
333
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
334
-                            $this->_current_page_view_url
335
-                        )
336
-                        : $this->_admin_base_url,
337
-                ),
338
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
339
-                'help_tabs'     => array(
340
-                    'event_editor_help_tab'                            => array(
341
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
342
-                        'filename' => 'event_editor',
343
-                    ),
344
-                    'event_editor_title_richtexteditor_help_tab'       => array(
345
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
346
-                        'filename' => 'event_editor_title_richtexteditor',
347
-                    ),
348
-                    'event_editor_venue_details_help_tab'              => array(
349
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
350
-                        'filename' => 'event_editor_venue_details',
351
-                    ),
352
-                    'event_editor_event_datetimes_help_tab'            => array(
353
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
354
-                        'filename' => 'event_editor_event_datetimes',
355
-                    ),
356
-                    'event_editor_event_tickets_help_tab'              => array(
357
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
358
-                        'filename' => 'event_editor_event_tickets',
359
-                    ),
360
-                    'event_editor_event_registration_options_help_tab' => array(
361
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
362
-                        'filename' => 'event_editor_event_registration_options',
363
-                    ),
364
-                    'event_editor_tags_categories_help_tab'            => array(
365
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
366
-                        'filename' => 'event_editor_tags_categories',
367
-                    ),
368
-                    'event_editor_questions_registrants_help_tab'      => array(
369
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
370
-                        'filename' => 'event_editor_questions_registrants',
371
-                    ),
372
-                    'event_editor_save_new_event_help_tab'             => array(
373
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
374
-                        'filename' => 'event_editor_save_new_event',
375
-                    ),
376
-                    'event_editor_other_help_tab'                      => array(
377
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
378
-                        'filename' => 'event_editor_other',
379
-                    ),
380
-                ),
381
-                /*'help_tour' => array(
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+	/**
46
+	 * @var EE_Event
47
+	 */
48
+	protected $_cpt_model_obj = false;
49
+
50
+
51
+
52
+	protected function _init_page_props()
53
+	{
54
+		$this->page_slug = EVENTS_PG_SLUG;
55
+		$this->page_label = EVENTS_LABEL;
56
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
57
+		$this->_admin_base_path = EVENTS_ADMIN;
58
+		$this->_cpt_model_names = array(
59
+			'create_new' => 'EEM_Event',
60
+			'edit'       => 'EEM_Event',
61
+		);
62
+		$this->_cpt_edit_routes = array(
63
+			'espresso_events' => 'edit',
64
+		);
65
+		add_action(
66
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
+			array($this, 'verify_event_edit')
68
+		);
69
+	}
70
+
71
+
72
+
73
+	protected function _ajax_hooks()
74
+	{
75
+		//todo: all hooks for events ajax goes in here.
76
+	}
77
+
78
+
79
+
80
+	protected function _define_page_props()
81
+	{
82
+		$this->_admin_page_title = EVENTS_LABEL;
83
+		$this->_labels = array(
84
+			'buttons'      => array(
85
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
86
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
87
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
88
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
89
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
90
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
91
+			),
92
+			'editor_title' => array(
93
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
94
+			),
95
+			'publishbox'   => array(
96
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
97
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
98
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
99
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
100
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+
107
+	protected function _set_page_routes()
108
+	{
109
+		//load formatter helper
110
+		//load field generator helper
111
+		//is there a evt_id in the request?
112
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
113
+			? $this->_req_data['EVT_ID'] : 0;
114
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
115
+		$this->_page_routes = array(
116
+			'default'                       => array(
117
+				'func'       => '_events_overview_list_table',
118
+				'capability' => 'ee_read_events',
119
+			),
120
+			'create_new'                    => array(
121
+				'func'       => '_create_new_cpt_item',
122
+				'capability' => 'ee_edit_events',
123
+			),
124
+			'edit'                          => array(
125
+				'func'       => '_edit_cpt_item',
126
+				'capability' => 'ee_edit_event',
127
+				'obj_id'     => $evt_id,
128
+			),
129
+			'copy_event'                    => array(
130
+				'func'       => '_copy_events',
131
+				'capability' => 'ee_edit_event',
132
+				'obj_id'     => $evt_id,
133
+				'noheader'   => true,
134
+			),
135
+			'trash_event'                   => array(
136
+				'func'       => '_trash_or_restore_event',
137
+				'args'       => array('event_status' => 'trash'),
138
+				'capability' => 'ee_delete_event',
139
+				'obj_id'     => $evt_id,
140
+				'noheader'   => true,
141
+			),
142
+			'trash_events'                  => array(
143
+				'func'       => '_trash_or_restore_events',
144
+				'args'       => array('event_status' => 'trash'),
145
+				'capability' => 'ee_delete_events',
146
+				'noheader'   => true,
147
+			),
148
+			'restore_event'                 => array(
149
+				'func'       => '_trash_or_restore_event',
150
+				'args'       => array('event_status' => 'draft'),
151
+				'capability' => 'ee_delete_event',
152
+				'obj_id'     => $evt_id,
153
+				'noheader'   => true,
154
+			),
155
+			'restore_events'                => array(
156
+				'func'       => '_trash_or_restore_events',
157
+				'args'       => array('event_status' => 'draft'),
158
+				'capability' => 'ee_delete_events',
159
+				'noheader'   => true,
160
+			),
161
+			'delete_event'                  => array(
162
+				'func'       => '_delete_event',
163
+				'capability' => 'ee_delete_event',
164
+				'obj_id'     => $evt_id,
165
+				'noheader'   => true,
166
+			),
167
+			'delete_events'                 => array(
168
+				'func'       => '_delete_events',
169
+				'capability' => 'ee_delete_events',
170
+				'noheader'   => true,
171
+			),
172
+			'view_report'                   => array(
173
+				'func'      => '_view_report',
174
+				'capablity' => 'ee_edit_events',
175
+			),
176
+			'default_event_settings'        => array(
177
+				'func'       => '_default_event_settings',
178
+				'capability' => 'manage_options',
179
+			),
180
+			'update_default_event_settings' => array(
181
+				'func'       => '_update_default_event_settings',
182
+				'capability' => 'manage_options',
183
+				'noheader'   => true,
184
+			),
185
+			'template_settings'             => array(
186
+				'func'       => '_template_settings',
187
+				'capability' => 'manage_options',
188
+			),
189
+			//event category tab related
190
+			'add_category'                  => array(
191
+				'func'       => '_category_details',
192
+				'capability' => 'ee_edit_event_category',
193
+				'args'       => array('add'),
194
+			),
195
+			'edit_category'                 => array(
196
+				'func'       => '_category_details',
197
+				'capability' => 'ee_edit_event_category',
198
+				'args'       => array('edit'),
199
+			),
200
+			'delete_categories'             => array(
201
+				'func'       => '_delete_categories',
202
+				'capability' => 'ee_delete_event_category',
203
+				'noheader'   => true,
204
+			),
205
+			'delete_category'               => array(
206
+				'func'       => '_delete_categories',
207
+				'capability' => 'ee_delete_event_category',
208
+				'noheader'   => true,
209
+			),
210
+			'insert_category'               => array(
211
+				'func'       => '_insert_or_update_category',
212
+				'args'       => array('new_category' => true),
213
+				'capability' => 'ee_edit_event_category',
214
+				'noheader'   => true,
215
+			),
216
+			'update_category'               => array(
217
+				'func'       => '_insert_or_update_category',
218
+				'args'       => array('new_category' => false),
219
+				'capability' => 'ee_edit_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'category_list'                 => array(
223
+				'func'       => '_category_list_table',
224
+				'capability' => 'ee_manage_event_categories',
225
+			),
226
+		);
227
+	}
228
+
229
+
230
+
231
+	protected function _set_page_config()
232
+	{
233
+		$this->_page_config = array(
234
+			'default'                => array(
235
+				'nav'           => array(
236
+					'label' => esc_html__('Overview', 'event_espresso'),
237
+					'order' => 10,
238
+				),
239
+				'list_table'    => 'Events_Admin_List_Table',
240
+				'help_tabs'     => array(
241
+					'events_overview_help_tab'                       => array(
242
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
243
+						'filename' => 'events_overview',
244
+					),
245
+					'events_overview_table_column_headings_help_tab' => array(
246
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
247
+						'filename' => 'events_overview_table_column_headings',
248
+					),
249
+					'events_overview_filters_help_tab'               => array(
250
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
251
+						'filename' => 'events_overview_filters',
252
+					),
253
+					'events_overview_view_help_tab'                  => array(
254
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
255
+						'filename' => 'events_overview_views',
256
+					),
257
+					'events_overview_other_help_tab'                 => array(
258
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
259
+						'filename' => 'events_overview_other',
260
+					),
261
+				),
262
+				'help_tour'     => array(
263
+					'Event_Overview_Help_Tour',
264
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
265
+				),
266
+				'qtips'         => array(
267
+					'EE_Event_List_Table_Tips',
268
+				),
269
+				'require_nonce' => false,
270
+			),
271
+			'create_new'             => array(
272
+				'nav'           => array(
273
+					'label'      => esc_html__('Add Event', 'event_espresso'),
274
+					'order'      => 5,
275
+					'persistent' => false,
276
+				),
277
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
278
+				'help_tabs'     => array(
279
+					'event_editor_help_tab'                            => array(
280
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
281
+						'filename' => 'event_editor',
282
+					),
283
+					'event_editor_title_richtexteditor_help_tab'       => array(
284
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
285
+						'filename' => 'event_editor_title_richtexteditor',
286
+					),
287
+					'event_editor_venue_details_help_tab'              => array(
288
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
289
+						'filename' => 'event_editor_venue_details',
290
+					),
291
+					'event_editor_event_datetimes_help_tab'            => array(
292
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
293
+						'filename' => 'event_editor_event_datetimes',
294
+					),
295
+					'event_editor_event_tickets_help_tab'              => array(
296
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
297
+						'filename' => 'event_editor_event_tickets',
298
+					),
299
+					'event_editor_event_registration_options_help_tab' => array(
300
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
301
+						'filename' => 'event_editor_event_registration_options',
302
+					),
303
+					'event_editor_tags_categories_help_tab'            => array(
304
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
305
+						'filename' => 'event_editor_tags_categories',
306
+					),
307
+					'event_editor_questions_registrants_help_tab'      => array(
308
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
309
+						'filename' => 'event_editor_questions_registrants',
310
+					),
311
+					'event_editor_save_new_event_help_tab'             => array(
312
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
313
+						'filename' => 'event_editor_save_new_event',
314
+					),
315
+					'event_editor_other_help_tab'                      => array(
316
+						'title'    => esc_html__('Event Other', 'event_espresso'),
317
+						'filename' => 'event_editor_other',
318
+					),
319
+				),
320
+				'help_tour'     => array(
321
+					'Event_Editor_Help_Tour',
322
+				),
323
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
324
+				'require_nonce' => false,
325
+			),
326
+			'edit'                   => array(
327
+				'nav'           => array(
328
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
329
+					'order'      => 5,
330
+					'persistent' => false,
331
+					'url'        => isset($this->_req_data['post'])
332
+						? EE_Admin_Page::add_query_args_and_nonce(
333
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
334
+							$this->_current_page_view_url
335
+						)
336
+						: $this->_admin_base_url,
337
+				),
338
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
339
+				'help_tabs'     => array(
340
+					'event_editor_help_tab'                            => array(
341
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
342
+						'filename' => 'event_editor',
343
+					),
344
+					'event_editor_title_richtexteditor_help_tab'       => array(
345
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
346
+						'filename' => 'event_editor_title_richtexteditor',
347
+					),
348
+					'event_editor_venue_details_help_tab'              => array(
349
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
350
+						'filename' => 'event_editor_venue_details',
351
+					),
352
+					'event_editor_event_datetimes_help_tab'            => array(
353
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
354
+						'filename' => 'event_editor_event_datetimes',
355
+					),
356
+					'event_editor_event_tickets_help_tab'              => array(
357
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
358
+						'filename' => 'event_editor_event_tickets',
359
+					),
360
+					'event_editor_event_registration_options_help_tab' => array(
361
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
362
+						'filename' => 'event_editor_event_registration_options',
363
+					),
364
+					'event_editor_tags_categories_help_tab'            => array(
365
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
366
+						'filename' => 'event_editor_tags_categories',
367
+					),
368
+					'event_editor_questions_registrants_help_tab'      => array(
369
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
370
+						'filename' => 'event_editor_questions_registrants',
371
+					),
372
+					'event_editor_save_new_event_help_tab'             => array(
373
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
374
+						'filename' => 'event_editor_save_new_event',
375
+					),
376
+					'event_editor_other_help_tab'                      => array(
377
+						'title'    => esc_html__('Event Other', 'event_espresso'),
378
+						'filename' => 'event_editor_other',
379
+					),
380
+				),
381
+				/*'help_tour' => array(
382 382
 					'Event_Edit_Help_Tour'
383 383
 				),*/
384
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
385
-                'require_nonce' => false,
386
-            ),
387
-            'default_event_settings' => array(
388
-                'nav'           => array(
389
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
390
-                    'order' => 40,
391
-                ),
392
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
393
-                'labels'        => array(
394
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
395
-                ),
396
-                'help_tabs'     => array(
397
-                    'default_settings_help_tab'        => array(
398
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
399
-                        'filename' => 'events_default_settings',
400
-                    ),
401
-                    'default_settings_status_help_tab' => array(
402
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
403
-                        'filename' => 'events_default_settings_status',
404
-                    ),
405
-                ),
406
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
407
-                'require_nonce' => false,
408
-            ),
409
-            //template settings
410
-            'template_settings'      => array(
411
-                'nav'           => array(
412
-                    'label' => esc_html__('Templates', 'event_espresso'),
413
-                    'order' => 30,
414
-                ),
415
-                'metaboxes'     => $this->_default_espresso_metaboxes,
416
-                'help_tabs'     => array(
417
-                    'general_settings_templates_help_tab' => array(
418
-                        'title'    => esc_html__('Templates', 'event_espresso'),
419
-                        'filename' => 'general_settings_templates',
420
-                    ),
421
-                ),
422
-                'help_tour'     => array('Templates_Help_Tour'),
423
-                'require_nonce' => false,
424
-            ),
425
-            //event category stuff
426
-            'add_category'           => array(
427
-                'nav'           => array(
428
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
429
-                    'order'      => 15,
430
-                    'persistent' => false,
431
-                ),
432
-                'help_tabs'     => array(
433
-                    'add_category_help_tab' => array(
434
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
435
-                        'filename' => 'events_add_category',
436
-                    ),
437
-                ),
438
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
439
-                'metaboxes'     => array('_publish_post_box'),
440
-                'require_nonce' => false,
441
-            ),
442
-            'edit_category'          => array(
443
-                'nav'           => array(
444
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
445
-                    'order'      => 15,
446
-                    'persistent' => false,
447
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
448
-                        ? add_query_arg(
449
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
450
-                            $this->_current_page_view_url
451
-                        )
452
-                        : $this->_admin_base_url,
453
-                ),
454
-                'help_tabs'     => array(
455
-                    'edit_category_help_tab' => array(
456
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
457
-                        'filename' => 'events_edit_category',
458
-                    ),
459
-                ),
460
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
461
-                'metaboxes'     => array('_publish_post_box'),
462
-                'require_nonce' => false,
463
-            ),
464
-            'category_list'          => array(
465
-                'nav'           => array(
466
-                    'label' => esc_html__('Categories', 'event_espresso'),
467
-                    'order' => 20,
468
-                ),
469
-                'list_table'    => 'Event_Categories_Admin_List_Table',
470
-                'help_tabs'     => array(
471
-                    'events_categories_help_tab'                       => array(
472
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
473
-                        'filename' => 'events_categories',
474
-                    ),
475
-                    'events_categories_table_column_headings_help_tab' => array(
476
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
477
-                        'filename' => 'events_categories_table_column_headings',
478
-                    ),
479
-                    'events_categories_view_help_tab'                  => array(
480
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
481
-                        'filename' => 'events_categories_views',
482
-                    ),
483
-                    'events_categories_other_help_tab'                 => array(
484
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
485
-                        'filename' => 'events_categories_other',
486
-                    ),
487
-                ),
488
-                'help_tour'     => array(
489
-                    'Event_Categories_Help_Tour',
490
-                ),
491
-                'metaboxes'     => $this->_default_espresso_metaboxes,
492
-                'require_nonce' => false,
493
-            ),
494
-        );
495
-    }
496
-
497
-
498
-
499
-    protected function _add_screen_options()
500
-    {
501
-        //todo
502
-    }
503
-
504
-
505
-
506
-    protected function _add_screen_options_default()
507
-    {
508
-        $this->_per_page_screen_option();
509
-    }
510
-
511
-
512
-
513
-    protected function _add_screen_options_category_list()
514
-    {
515
-        $page_title = $this->_admin_page_title;
516
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
517
-        $this->_per_page_screen_option();
518
-        $this->_admin_page_title = $page_title;
519
-    }
520
-
521
-
522
-
523
-    protected function _add_feature_pointers()
524
-    {
525
-        //todo
526
-    }
527
-
528
-
529
-
530
-    public function load_scripts_styles()
531
-    {
532
-        wp_register_style(
533
-            'events-admin-css',
534
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
535
-            array(),
536
-            EVENT_ESPRESSO_VERSION
537
-        );
538
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
-        wp_enqueue_style('events-admin-css');
540
-        wp_enqueue_style('ee-cat-admin');
541
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
542
-        //registers for all views
543
-        //scripts
544
-        wp_register_script(
545
-            'event_editor_js',
546
-            EVENTS_ASSETS_URL . 'event_editor.js',
547
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548
-            EVENT_ESPRESSO_VERSION,
549
-            true
550
-        );
551
-    }
552
-
553
-
554
-
555
-    /**
556
-     * enqueuing scripts and styles specific to this view
557
-     *
558
-     * @return void
559
-     */
560
-    public function load_scripts_styles_create_new()
561
-    {
562
-        $this->load_scripts_styles_edit();
563
-    }
564
-
565
-
566
-
567
-    /**
568
-     * enqueuing scripts and styles specific to this view
569
-     *
570
-     * @return void
571
-     */
572
-    public function load_scripts_styles_edit()
573
-    {
574
-        //styles
575
-        wp_enqueue_style('espresso-ui-theme');
576
-        wp_register_style(
577
-            'event-editor-css',
578
-            EVENTS_ASSETS_URL . 'event-editor.css',
579
-            array('ee-admin-css'),
580
-            EVENT_ESPRESSO_VERSION
581
-        );
582
-        wp_enqueue_style('event-editor-css');
583
-        //scripts
584
-        wp_register_script(
585
-            'event-datetime-metabox',
586
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
-            array('event_editor_js', 'ee-datepicker'),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_enqueue_script('event-datetime-metabox');
591
-    }
592
-
593
-
594
-
595
-    public function load_scripts_styles_add_category()
596
-    {
597
-        $this->load_scripts_styles_edit_category();
598
-    }
599
-
600
-
601
-
602
-    public function load_scripts_styles_edit_category()
603
-    {
604
-    }
605
-
606
-
607
-
608
-    protected function _set_list_table_views_category_list()
609
-    {
610
-        $this->_views = array(
611
-            'all' => array(
612
-                'slug'        => 'all',
613
-                'label'       => esc_html__('All', 'event_espresso'),
614
-                'count'       => 0,
615
-                'bulk_action' => array(
616
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
-                ),
618
-            ),
619
-        );
620
-    }
621
-
622
-
623
-
624
-    public function admin_init()
625
-    {
626
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
627
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
628
-            'event_espresso'
629
-        );
630
-    }
631
-
632
-
633
-
634
-    //nothing needed for events with these methods.
635
-    public function admin_notices()
636
-    {
637
-    }
638
-
639
-
640
-
641
-    public function admin_footer_scripts()
642
-    {
643
-    }
644
-
645
-
646
-
647
-    /**
648
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
649
-     * warning (via EE_Error::add_error());
650
-     *
651
-     * @param  EE_Event $event Event object
652
-     * @access public
653
-     * @return void
654
-     */
655
-    public function verify_event_edit($event = null)
656
-    {
657
-        // no event?
658
-        if (empty($event)) {
659
-            // set event
660
-            $event = $this->_cpt_model_obj;
661
-        }
662
-        // STILL no event?
663
-        if (empty ($event)) {
664
-            return;
665
-        }
666
-        $orig_status = $event->status();
667
-        // first check if event is active.
668
-        if (
669
-            $orig_status === EEM_Event::cancelled
670
-            || $orig_status === EEM_Event::postponed
671
-            || $event->is_expired()
672
-            || $event->is_inactive()
673
-        ) {
674
-            return;
675
-        }
676
-        //made it here so it IS active... next check that any of the tickets are sold.
677
-        if ($event->is_sold_out(true)) {
678
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
679
-                EE_Error::add_attention(
680
-                    sprintf(
681
-                        esc_html__(
682
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
683
-                            'event_espresso'
684
-                        ),
685
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
686
-                    )
687
-                );
688
-            }
689
-            return;
690
-        } else if ($orig_status === EEM_Event::sold_out) {
691
-            EE_Error::add_attention(
692
-                sprintf(
693
-                    esc_html__(
694
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
695
-                        'event_espresso'
696
-                    ),
697
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
698
-                )
699
-            );
700
-        }
701
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
702
-        if ( ! $event->tickets_on_sale()) {
703
-            return;
704
-        }
705
-        //made it here so show warning
706
-        $this->_edit_event_warning();
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
713
-     * When needed, hook this into a EE_Error::add_error() notice.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _edit_event_warning()
719
-    {
720
-        // we don't want to add warnings during these requests
721
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
722
-            return;
723
-        }
724
-        EE_Error::add_attention(
725
-            esc_html__(
726
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
727
-                'event_espresso'
728
-            )
729
-        );
730
-    }
731
-
732
-
733
-
734
-    /**
735
-     * When a user is creating a new event, notify them if they haven't set their timezone.
736
-     * Otherwise, do the normal logic
737
-     *
738
-     * @return string
739
-     * @throws \EE_Error
740
-     */
741
-    protected function _create_new_cpt_item()
742
-    {
743
-        $gmt_offset = get_option('gmt_offset');
744
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
745
-        if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
746
-            EE_Error::add_attention(
747
-                sprintf(
748
-                    __(
749
-                        'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750
-                        'event_espresso'
751
-                    ),
752
-                    '<a href="' . admin_url('options-general.php') . '">',
753
-                    '</a>'
754
-                ),
755
-                __FILE__,
756
-                __FUNCTION__,
757
-                __LINE__
758
-            );
759
-        }
760
-        return parent::_create_new_cpt_item();
761
-    }
762
-
763
-
764
-
765
-    protected function _set_list_table_views_default()
766
-    {
767
-        $this->_views = array(
768
-            'all'   => array(
769
-                'slug'        => 'all',
770
-                'label'       => esc_html__('View All Events', 'event_espresso'),
771
-                'count'       => 0,
772
-                'bulk_action' => array(
773
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
774
-                ),
775
-            ),
776
-            'draft' => array(
777
-                'slug'        => 'draft',
778
-                'label'       => esc_html__('Draft', 'event_espresso'),
779
-                'count'       => 0,
780
-                'bulk_action' => array(
781
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
782
-                ),
783
-            ),
784
-        );
785
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
786
-            $this->_views['trash'] = array(
787
-                'slug'        => 'trash',
788
-                'label'       => esc_html__('Trash', 'event_espresso'),
789
-                'count'       => 0,
790
-                'bulk_action' => array(
791
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
792
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
793
-                ),
794
-            );
795
-        }
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * @return array
802
-     */
803
-    protected function _event_legend_items()
804
-    {
805
-        $items = array(
806
-            'view_details'   => array(
807
-                'class' => 'dashicons dashicons-search',
808
-                'desc'  => esc_html__('View Event', 'event_espresso'),
809
-            ),
810
-            'edit_event'     => array(
811
-                'class' => 'ee-icon ee-icon-calendar-edit',
812
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
813
-            ),
814
-            'view_attendees' => array(
815
-                'class' => 'dashicons dashicons-groups',
816
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
817
-            ),
818
-        );
819
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820
-        $statuses = array(
821
-            'sold_out_status'  => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824
-            ),
825
-            'active_status'    => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828
-            ),
829
-            'upcoming_status'  => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832
-            ),
833
-            'postponed_status' => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836
-            ),
837
-            'cancelled_status' => array(
838
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840
-            ),
841
-            'expired_status'   => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844
-            ),
845
-            'inactive_status'  => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848
-            ),
849
-        );
850
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
851
-        return array_merge($items, $statuses);
852
-    }
853
-
854
-
855
-
856
-    /**
857
-     * _event_model
858
-     *
859
-     * @return EEM_Event
860
-     */
861
-    private function _event_model()
862
-    {
863
-        if ( ! $this->_event_model instanceof EEM_Event) {
864
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
865
-        }
866
-        return $this->_event_model;
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * Adds extra buttons to the WP CPT permalink field row.
873
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
874
-     *
875
-     * @param  string $return    the current html
876
-     * @param  int    $id        the post id for the page
877
-     * @param  string $new_title What the title is
878
-     * @param  string $new_slug  what the slug is
879
-     * @return string            The new html string for the permalink area
880
-     */
881
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
882
-    {
883
-        //make sure this is only when editing
884
-        if ( ! empty($id)) {
885
-            $post = get_post($id);
886
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
887
-                       . esc_html__('Shortcode', 'event_espresso')
888
-                       . '</a> ';
889
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
890
-                       . $post->ID
891
-                       . ']">';
892
-        }
893
-        return $return;
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * _events_overview_list_table
900
-     * This contains the logic for showing the events_overview list
901
-     *
902
-     * @access protected
903
-     * @return void
904
-     * @throws \EE_Error
905
-     */
906
-    protected function _events_overview_list_table()
907
-    {
908
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
909
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
910
-            ? (array)$this->_template_args['after_list_table']
911
-            : array();
912
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
913
-                                                                              . EEH_Template::get_button_or_link(
914
-                get_post_type_archive_link('espresso_events'),
915
-                esc_html__("View Event Archive Page", "event_espresso"),
916
-                'button'
917
-            );
918
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
919
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
920
-                'create_new',
921
-                'add',
922
-                array(),
923
-                'add-new-h2'
924
-            );
925
-        $this->display_admin_list_table_page_with_no_sidebar();
926
-    }
927
-
928
-
929
-
930
-    /**
931
-     * this allows for extra misc actions in the default WP publish box
932
-     *
933
-     * @return void
934
-     */
935
-    public function extra_misc_actions_publish_box()
936
-    {
937
-        $this->_generate_publish_box_extra_content();
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
944
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
945
-     * data.
946
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
947
-     * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
948
-     * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
949
-     * you handle this accordingly.
950
-     *
951
-     * @access protected
952
-     * @abstract
953
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
954
-     * @param  object $post    The post object of the cpt that was saved.
955
-     * @return void
956
-     */
957
-    protected function _insert_update_cpt_item($post_id, $post)
958
-    {
959
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
960
-            //get out we're not processing an event save.
961
-            return;
962
-        }
963
-        $event_values = array(
964
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
965
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
966
-            'EVT_additional_limit'            => min(
967
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
968
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
969
-            ),
970
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
971
-                ? $this->_req_data['EVT_default_registration_status']
972
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
973
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
974
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
975
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
976
-                ? $this->_req_data['timezone_string'] : null,
977
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
978
-                ? $this->_req_data['externalURL'] : null,
979
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
980
-                ? $this->_req_data['event_phone'] : null,
981
-        );
982
-        //update event
983
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
984
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
985
-        $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
986
-        $event = $this->_event_model()->get_one(array($get_one_where));
987
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
988
-        $event_update_callbacks = apply_filters(
989
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
990
-            array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
991
-        );
992
-        $att_success = true;
993
-        foreach ($event_update_callbacks as $e_callback) {
994
-            $_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
995
-            $att_success = ! $att_success ? $att_success
996
-                : $_succ; //if ANY of these updates fail then we want the appropriate global error message
997
-        }
998
-        //any errors?
999
-        if ($success && false === $att_success) {
1000
-            EE_Error::add_error(
1001
-                esc_html__(
1002
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1003
-                    'event_espresso'
1004
-                ),
1005
-                __FILE__,
1006
-                __FUNCTION__,
1007
-                __LINE__
1008
-            );
1009
-        } else if ($success === false) {
1010
-            EE_Error::add_error(
1011
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1012
-                __FILE__,
1013
-                __FUNCTION__,
1014
-                __LINE__
1015
-            );
1016
-        }
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     * @see parent::restore_item()
1023
-     * @param int $post_id
1024
-     * @param int $revision_id
1025
-     */
1026
-    protected function _restore_cpt_item($post_id, $revision_id)
1027
-    {
1028
-        //copy existing event meta to new post
1029
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1030
-        if ($post_evt instanceof EE_Event) {
1031
-            //meta revision restore
1032
-            $post_evt->restore_revision($revision_id);
1033
-            //related objs restore
1034
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1035
-        }
1036
-    }
1037
-
1038
-
1039
-
1040
-    /**
1041
-     * Attach the venue to the Event
1042
-     *
1043
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1044
-     * @param  array     $data   The request data from the form
1045
-     * @return bool           Success or fail.
1046
-     */
1047
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1048
-    {
1049
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1050
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1051
-        $rows_affected = null;
1052
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1053
-        // very important.  If we don't have a venue name...
1054
-        // then we'll get out because not necessary to create empty venue
1055
-        if (empty($data['venue_title'])) {
1056
-            return false;
1057
-        }
1058
-        $venue_array = array(
1059
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1060
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1061
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1062
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1063
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1064
-                : null,
1065
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1066
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1067
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1068
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1069
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1070
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1071
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1072
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1073
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1074
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1075
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1076
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1077
-            'status'              => 'publish',
1078
-        );
1079
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1080
-        if ( ! empty($venue_id)) {
1081
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1082
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1083
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1084
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1085
-            return $rows_affected > 0 ? true : false;
1086
-        } else {
1087
-            //we insert the venue
1088
-            $venue_id = $venue_model->insert($venue_array);
1089
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1090
-            return ! empty($venue_id) ? true : false;
1091
-        }
1092
-        //when we have the ancestor come in it's already been handled by the revision save.
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1099
-     *
1100
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1101
-     * @param  array    $data   The request data from the form
1102
-     * @return array
1103
-     */
1104
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1105
-    {
1106
-        $success = true;
1107
-        $saved_dtt = null;
1108
-        $saved_tickets = array();
1109
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1110
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1111
-            //trim all values to ensure any excess whitespace is removed.
1112
-            $dtt = array_map('trim', $dtt);
1113
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1114
-                : $dtt['DTT_EVT_start'];
1115
-            $datetime_values = array(
1116
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1117
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1118
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1119
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1120
-                'DTT_order'     => $row,
1121
-            );
1122
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1123
-            if ( ! empty($dtt['DTT_ID'])) {
1124
-                $DTM = EE_Registry::instance()
1125
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1126
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1127
-                $DTM->set_date_format($incoming_date_formats[0]);
1128
-                $DTM->set_time_format($incoming_date_formats[1]);
1129
-                foreach ($datetime_values as $field => $value) {
1130
-                    $DTM->set($field, $value);
1131
-                }
1132
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1133
-                $saved_dtts[$DTM->ID()] = $DTM;
1134
-            } else {
1135
-                $DTM = EE_Registry::instance()->load_class(
1136
-                    'Datetime',
1137
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1138
-                    false,
1139
-                    false
1140
-                );
1141
-                foreach ($datetime_values as $field => $value) {
1142
-                    $DTM->set($field, $value);
1143
-                }
1144
-            }
1145
-            $DTM->save();
1146
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1147
-            //load DTT helper
1148
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1149
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1150
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1151
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1152
-                $DTT->save();
1153
-            }
1154
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1155
-            $saved_dtt = $DTT;
1156
-            $success = ! $success ? $success : $DTT;
1157
-            //if ANY of these updates fail then we want the appropriate global error message.
1158
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1159
-        }
1160
-        //no dtts get deleted so we don't do any of that logic here.
1161
-        //update tickets next
1162
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1163
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1164
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1165
-            $update_prices = false;
1166
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1167
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1168
-            // trim inputs to ensure any excess whitespace is removed.
1169
-            $tkt = array_map('trim', $tkt);
1170
-            if (empty($tkt['TKT_start_date'])) {
1171
-                //let's use now in the set timezone.
1172
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1173
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1174
-            }
1175
-            if (empty($tkt['TKT_end_date'])) {
1176
-                //use the start date of the first datetime
1177
-                $dtt = $evtobj->first_datetime();
1178
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1179
-                    $incoming_date_formats[0],
1180
-                    $incoming_date_formats[1]
1181
-                );
1182
-            }
1183
-            $TKT_values = array(
1184
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1185
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1186
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1187
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1188
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1189
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1190
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1191
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1192
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1193
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1194
-                'TKT_row'         => $row,
1195
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1196
-                'TKT_price'       => $ticket_price,
1197
-            );
1198
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1199
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1200
-                $TKT_values['TKT_ID'] = 0;
1201
-                $TKT_values['TKT_is_default'] = 0;
1202
-                $TKT_values['TKT_price'] = $ticket_price;
1203
-                $update_prices = true;
1204
-            }
1205
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1206
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1207
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1208
-            if ( ! empty($tkt['TKT_ID'])) {
1209
-                $TKT = EE_Registry::instance()
1210
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1211
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1212
-                if ($TKT instanceof EE_Ticket) {
1213
-                    $ticket_sold = $TKT->count_related(
1214
-                        'Registration',
1215
-                        array(
1216
-                            array(
1217
-                                'STS_ID' => array(
1218
-                                    'NOT IN',
1219
-                                    array(EEM_Registration::status_id_incomplete),
1220
-                                ),
1221
-                            ),
1222
-                        )
1223
-                    ) > 0 ? true : false;
1224
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1225
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1226
-                                      && ! $TKT->get(
1227
-                        'TKT_deleted'
1228
-                    ) ? true : false;
1229
-                    $TKT->set_date_format($incoming_date_formats[0]);
1230
-                    $TKT->set_time_format($incoming_date_formats[1]);
1231
-                    //set new values
1232
-                    foreach ($TKT_values as $field => $value) {
1233
-                        if ($field == 'TKT_qty') {
1234
-                            $TKT->set_qty($value);
1235
-                        } else {
1236
-                            $TKT->set($field, $value);
1237
-                        }
1238
-                    }
1239
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1240
-                    if ($create_new_TKT) {
1241
-                        //archive the old ticket first
1242
-                        $TKT->set('TKT_deleted', 1);
1243
-                        $TKT->save();
1244
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1245
-                        $saved_tickets[$TKT->ID()] = $TKT;
1246
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1247
-                        $TKT = clone $TKT;
1248
-                        $TKT->set('TKT_ID', 0);
1249
-                        $TKT->set('TKT_deleted', 0);
1250
-                        $TKT->set('TKT_price', $ticket_price);
1251
-                        $TKT->set('TKT_sold', 0);
1252
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1253
-                        $update_prices = true;
1254
-                    }
1255
-                    //make sure price is set if it hasn't been already
1256
-                    $TKT->set('TKT_price', $ticket_price);
1257
-                }
1258
-            } else {
1259
-                //no TKT_id so a new TKT
1260
-                $TKT_values['TKT_price'] = $ticket_price;
1261
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1262
-                if ($TKT instanceof EE_Ticket) {
1263
-                    //need to reset values to properly account for the date formats
1264
-                    $TKT->set_date_format($incoming_date_formats[0]);
1265
-                    $TKT->set_time_format($incoming_date_formats[1]);
1266
-                    $TKT->set_timezone($evtobj->get_timezone());
1267
-                    //set new values
1268
-                    foreach ($TKT_values as $field => $value) {
1269
-                        if ($field == 'TKT_qty') {
1270
-                            $TKT->set_qty($value);
1271
-                        } else {
1272
-                            $TKT->set($field, $value);
1273
-                        }
1274
-                    }
1275
-                    $update_prices = true;
1276
-                }
1277
-            }
1278
-            // cap ticket qty by datetime reg limits
1279
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1280
-            //update ticket.
1281
-            $TKT->save();
1282
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1283
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1284
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1285
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1286
-                $TKT->save();
1287
-            }
1288
-            //initially let's add the ticket to the dtt
1289
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1290
-            $saved_tickets[$TKT->ID()] = $TKT;
1291
-            //add prices to ticket
1292
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1293
-        }
1294
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1295
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1296
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1297
-        foreach ($tickets_removed as $id) {
1298
-            $id = absint($id);
1299
-            //get the ticket for this id
1300
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1301
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1302
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1303
-            foreach ($dtts as $dtt) {
1304
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1305
-            }
1306
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1307
-            $tkt_to_remove->delete_related_permanently('Price');
1308
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1309
-            $tkt_to_remove->delete_permanently();
1310
-        }
1311
-        return array($saved_dtt, $saved_tickets);
1312
-    }
1313
-
1314
-
1315
-
1316
-    /**
1317
-     * This attaches a list of given prices to a ticket.
1318
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1319
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1320
-     * price info and prices are automatically "archived" via the ticket.
1321
-     *
1322
-     * @access  private
1323
-     * @param array     $prices     Array of prices from the form.
1324
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1325
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1326
-     * @return  void
1327
-     */
1328
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1329
-    {
1330
-        foreach ($prices as $row => $prc) {
1331
-            $PRC_values = array(
1332
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1333
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1334
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1335
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1336
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1337
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1338
-                'PRC_order'      => $row,
1339
-            );
1340
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1341
-                $PRC_values['PRC_ID'] = 0;
1342
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1343
-            } else {
1344
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1345
-                //update this price with new values
1346
-                foreach ($PRC_values as $field => $newprc) {
1347
-                    $PRC->set($field, $newprc);
1348
-                }
1349
-                $PRC->save();
1350
-            }
1351
-            $ticket->_add_relation_to($PRC, 'Price');
1352
-        }
1353
-    }
1354
-
1355
-
1356
-
1357
-    /**
1358
-     * Add in our autosave ajax handlers
1359
-     *
1360
-     * @return void
1361
-     */
1362
-    protected function _ee_autosave_create_new()
1363
-    {
1364
-        // $this->_ee_autosave_edit();
1365
-    }
1366
-
1367
-
1368
-
1369
-    protected function _ee_autosave_edit()
1370
-    {
1371
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1372
-    }
1373
-
1374
-
1375
-
1376
-    /**
1377
-     *    _generate_publish_box_extra_content
1378
-     *
1379
-     * @access private
1380
-     * @return void
1381
-     */
1382
-    private function _generate_publish_box_extra_content()
1383
-    {
1384
-        //load formatter helper
1385
-        //args for getting related registrations
1386
-        $approved_query_args = array(
1387
-            array(
1388
-                'REG_deleted' => 0,
1389
-                'STS_ID'      => EEM_Registration::status_id_approved,
1390
-            ),
1391
-        );
1392
-        $not_approved_query_args = array(
1393
-            array(
1394
-                'REG_deleted' => 0,
1395
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1396
-            ),
1397
-        );
1398
-        $pending_payment_query_args = array(
1399
-            array(
1400
-                'REG_deleted' => 0,
1401
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1402
-            ),
1403
-        );
1404
-        // publish box
1405
-        $publish_box_extra_args = array(
1406
-            'view_approved_reg_url'        => add_query_arg(
1407
-                array(
1408
-                    'action'      => 'default',
1409
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1410
-                    '_reg_status' => EEM_Registration::status_id_approved,
1411
-                ),
1412
-                REG_ADMIN_URL
1413
-            ),
1414
-            'view_not_approved_reg_url'    => add_query_arg(
1415
-                array(
1416
-                    'action'      => 'default',
1417
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1418
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1419
-                ),
1420
-                REG_ADMIN_URL
1421
-            ),
1422
-            'view_pending_payment_reg_url' => add_query_arg(
1423
-                array(
1424
-                    'action'      => 'default',
1425
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1426
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1427
-                ),
1428
-                REG_ADMIN_URL
1429
-            ),
1430
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1431
-                'Registration',
1432
-                $approved_query_args
1433
-            ),
1434
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1435
-                'Registration',
1436
-                $not_approved_query_args
1437
-            ),
1438
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1439
-                'Registration',
1440
-                $pending_payment_query_args
1441
-            ),
1442
-            'misc_pub_section_class'       => apply_filters(
1443
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1444
-                'misc-pub-section'
1445
-            ),
1446
-            //'email_attendees_url' => add_query_arg(
1447
-            //	array(
1448
-            //		'event_admin_reports' => 'event_newsletter',
1449
-            //		'event_id' => $this->_cpt_model_obj->id
1450
-            //	),
1451
-            //	'admin.php?page=espresso_registrations'
1452
-            //),
1453
-        );
1454
-        ob_start();
1455
-        do_action(
1456
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1457
-            $this->_cpt_model_obj
1458
-        );
1459
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1460
-        // load template
1461
-        EEH_Template::display_template(
1462
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1463
-            $publish_box_extra_args
1464
-        );
1465
-    }
1466
-
1467
-
1468
-
1469
-    /**
1470
-     * This just returns whatever is set as the _event object property
1471
-     * //todo this will become obsolete once the models are in place
1472
-     *
1473
-     * @return object
1474
-     */
1475
-    public function get_event_object()
1476
-    {
1477
-        return $this->_cpt_model_obj;
1478
-    }
1479
-
1480
-
1481
-
1482
-
1483
-    /** METABOXES * */
1484
-    /**
1485
-     * _register_event_editor_meta_boxes
1486
-     * add all metaboxes related to the event_editor
1487
-     *
1488
-     * @return void
1489
-     */
1490
-    protected function _register_event_editor_meta_boxes()
1491
-    {
1492
-        $this->verify_cpt_object();
1493
-        add_meta_box(
1494
-            'espresso_event_editor_tickets',
1495
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1496
-            array($this, 'ticket_metabox'),
1497
-            $this->page_slug,
1498
-            'normal',
1499
-            'high'
1500
-        );
1501
-        add_meta_box(
1502
-            'espresso_event_editor_event_options',
1503
-            esc_html__('Event Registration Options', 'event_espresso'),
1504
-            array($this, 'registration_options_meta_box'),
1505
-            $this->page_slug,
1506
-            'side',
1507
-            'default'
1508
-        );
1509
-        // NOTE: if you're looking for other metaboxes in here,
1510
-        // where a metabox has a related management page in the admin
1511
-        // you will find it setup in the related management page's "_Hooks" file.
1512
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1513
-    }
1514
-
1515
-
1516
-
1517
-    public function ticket_metabox()
1518
-    {
1519
-        $existing_datetime_ids = $existing_ticket_ids = array();
1520
-        //defaults for template args
1521
-        $template_args = array(
1522
-            'existing_datetime_ids'    => '',
1523
-            'event_datetime_help_link' => '',
1524
-            'ticket_options_help_link' => '',
1525
-            'time'                     => null,
1526
-            'ticket_rows'              => '',
1527
-            'existing_ticket_ids'      => '',
1528
-            'total_ticket_rows'        => 1,
1529
-            'ticket_js_structure'      => '',
1530
-            'trash_icon'               => 'ee-lock-icon',
1531
-            'disabled'                 => '',
1532
-        );
1533
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1534
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1535
-        /**
1536
-         * 1. Start with retrieving Datetimes
1537
-         * 2. Fore each datetime get related tickets
1538
-         * 3. For each ticket get related prices
1539
-         */
1540
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1541
-        /** @type EE_Datetime $first_datetime */
1542
-        $first_datetime = reset($times);
1543
-        //do we get related tickets?
1544
-        if ($first_datetime instanceof EE_Datetime
1545
-            && $first_datetime->ID() !== 0
1546
-        ) {
1547
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1548
-            $template_args['time'] = $first_datetime;
1549
-            $related_tickets = $first_datetime->tickets(
1550
-                array(
1551
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1552
-                    'default_where_conditions' => 'none',
1553
-                )
1554
-            );
1555
-            if ( ! empty($related_tickets)) {
1556
-                $template_args['total_ticket_rows'] = count($related_tickets);
1557
-                $row = 0;
1558
-                foreach ($related_tickets as $ticket) {
1559
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1560
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1561
-                    $row++;
1562
-                }
1563
-            } else {
1564
-                $template_args['total_ticket_rows'] = 1;
1565
-                /** @type EE_Ticket $ticket */
1566
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1567
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1568
-            }
1569
-        } else {
1570
-            $template_args['time'] = $times[0];
1571
-            /** @type EE_Ticket $ticket */
1572
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1573
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1574
-            // NOTE: we're just sending the first default row
1575
-            // (decaf can't manage default tickets so this should be sufficient);
1576
-        }
1577
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1578
-            'event_editor_event_datetimes_help_tab'
1579
-        );
1580
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1581
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1582
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1583
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1584
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1585
-            true
1586
-        );
1587
-        $template = apply_filters(
1588
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1589
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1590
-        );
1591
-        EEH_Template::display_template($template, $template_args);
1592
-    }
1593
-
1594
-
1595
-
1596
-    /**
1597
-     * Setup an individual ticket form for the decaf event editor page
1598
-     *
1599
-     * @access private
1600
-     * @param  EE_Ticket $ticket   the ticket object
1601
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1602
-     * @param int        $row
1603
-     * @return string generated html for the ticket row.
1604
-     */
1605
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1606
-    {
1607
-        $template_args = array(
1608
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1609
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1610
-                : '',
1611
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1612
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1613
-            'TKT_name'            => $ticket->get('TKT_name'),
1614
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1615
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1616
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1617
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1618
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1619
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1620
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1621
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1622
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1623
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1624
-                : ' disabled=disabled',
1625
-        );
1626
-        $price = $ticket->ID() !== 0
1627
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1628
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1629
-        $price_args = array(
1630
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1631
-            'PRC_amount'            => $price->get('PRC_amount'),
1632
-            'PRT_ID'                => $price->get('PRT_ID'),
1633
-            'PRC_ID'                => $price->get('PRC_ID'),
1634
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1635
-        );
1636
-        //make sure we have default start and end dates if skeleton
1637
-        //handle rows that should NOT be empty
1638
-        if (empty($template_args['TKT_start_date'])) {
1639
-            //if empty then the start date will be now.
1640
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1641
-        }
1642
-        if (empty($template_args['TKT_end_date'])) {
1643
-            //get the earliest datetime (if present);
1644
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1645
-                ? $this->_cpt_model_obj->get_first_related(
1646
-                    'Datetime',
1647
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1648
-                )
1649
-                : null;
1650
-            if ( ! empty($earliest_dtt)) {
1651
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1652
-            } else {
1653
-                $template_args['TKT_end_date'] = date(
1654
-                    'Y-m-d h:i a',
1655
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1656
-                );
1657
-            }
1658
-        }
1659
-        $template_args = array_merge($template_args, $price_args);
1660
-        $template = apply_filters(
1661
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1662
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1663
-            $ticket
1664
-        );
1665
-        return EEH_Template::display_template($template, $template_args, true);
1666
-    }
1667
-
1668
-
1669
-
1670
-    public function registration_options_meta_box()
1671
-    {
1672
-        $yes_no_values = array(
1673
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1674
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1675
-        );
1676
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1677
-            array(
1678
-                EEM_Registration::status_id_cancelled,
1679
-                EEM_Registration::status_id_declined,
1680
-                EEM_Registration::status_id_incomplete,
1681
-            ),
1682
-            true
1683
-        );
1684
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1685
-        $template_args['_event'] = $this->_cpt_model_obj;
1686
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1687
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1688
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1689
-            'default_reg_status',
1690
-            $default_reg_status_values,
1691
-            $this->_cpt_model_obj->default_registration_status()
1692
-        );
1693
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1694
-            'display_desc',
1695
-            $yes_no_values,
1696
-            $this->_cpt_model_obj->display_description()
1697
-        );
1698
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1699
-            'display_ticket_selector',
1700
-            $yes_no_values,
1701
-            $this->_cpt_model_obj->display_ticket_selector(),
1702
-            '',
1703
-            '',
1704
-            false
1705
-        );
1706
-        $template_args['additional_registration_options'] = apply_filters(
1707
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1708
-            '',
1709
-            $template_args,
1710
-            $yes_no_values,
1711
-            $default_reg_status_values
1712
-        );
1713
-        EEH_Template::display_template(
1714
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1715
-            $template_args
1716
-        );
1717
-    }
1718
-
1719
-
1720
-
1721
-    /**
1722
-     * _get_events()
1723
-     * This method simply returns all the events (for the given _view and paging)
1724
-     *
1725
-     * @access public
1726
-     * @param int  $per_page     count of items per page (20 default);
1727
-     * @param int  $current_page what is the current page being viewed.
1728
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1729
-     *                           If FALSE then we return an array of event objects
1730
-     *                           that match the given _view and paging parameters.
1731
-     * @return array an array of event objects.
1732
-     */
1733
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1734
-    {
1735
-        $EEME = $this->_event_model();
1736
-        $offset = ($current_page - 1) * $per_page;
1737
-        $limit = $count ? null : $offset . ',' . $per_page;
1738
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1739
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1740
-        if (isset($this->_req_data['month_range'])) {
1741
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1742
-            $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1743
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1744
-        }
1745
-        $where = array();
1746
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1747
-        //determine what post_status our condition will have for the query.
1748
-        switch ($status) {
1749
-            case 'month' :
1750
-            case 'today' :
1751
-            case null :
1752
-            case 'all' :
1753
-                break;
1754
-            case 'draft' :
1755
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1756
-                break;
1757
-            default :
1758
-                $where['status'] = $status;
1759
-        }
1760
-        //categories?
1761
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1762
-            ? $this->_req_data['EVT_CAT'] : null;
1763
-        if ( ! empty ($category)) {
1764
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1765
-            $where['Term_Taxonomy.term_id'] = $category;
1766
-        }
1767
-        //date where conditions
1768
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1769
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1770
-            $DateTime = new DateTime(
1771
-                $year_r . '-' . $month_r . '-01 00:00:00',
1772
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1773
-            );
1774
-            $start = $DateTime->format(implode(' ', $start_formats));
1775
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1776
-                ->format('t'))->setTime(23, 59, 59)
1777
-                            ->format(implode(' ', $start_formats));
1778
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1779
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1780
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1781
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1782
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1783
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1784
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1785
-            $now = date('Y-m-01');
1786
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1787
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1788
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1789
-                            ->setTime(23, 59, 59)
1790
-                            ->format(implode(' ', $start_formats));
1791
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1792
-        }
1793
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1794
-            $where['EVT_wp_user'] = get_current_user_id();
1795
-        } else {
1796
-            if ( ! isset($where['status'])) {
1797
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1798
-                    $where['OR'] = array(
1799
-                        'status*restrict_private' => array('!=', 'private'),
1800
-                        'AND'                     => array(
1801
-                            'status*inclusive' => array('=', 'private'),
1802
-                            'EVT_wp_user'      => get_current_user_id(),
1803
-                        ),
1804
-                    );
1805
-                }
1806
-            }
1807
-        }
1808
-        if (isset($this->_req_data['EVT_wp_user'])) {
1809
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1810
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1811
-            ) {
1812
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1813
-            }
1814
-        }
1815
-        //search query handling
1816
-        if (isset($this->_req_data['s'])) {
1817
-            $search_string = '%' . $this->_req_data['s'] . '%';
1818
-            $where['OR'] = array(
1819
-                'EVT_name'       => array('LIKE', $search_string),
1820
-                'EVT_desc'       => array('LIKE', $search_string),
1821
-                'EVT_short_desc' => array('LIKE', $search_string),
1822
-            );
1823
-        }
1824
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1825
-        $query_params = apply_filters(
1826
-            'FHEE__Events_Admin_Page__get_events__query_params',
1827
-            array(
1828
-                $where,
1829
-                'limit'    => $limit,
1830
-                'order_by' => $orderby,
1831
-                'order'    => $order,
1832
-                'group_by' => 'EVT_ID',
1833
-            ),
1834
-            $this->_req_data
1835
-        );
1836
-        //let's first check if we have special requests coming in.
1837
-        if (isset($this->_req_data['active_status'])) {
1838
-            switch ($this->_req_data['active_status']) {
1839
-                case 'upcoming' :
1840
-                    return $EEME->get_upcoming_events($query_params, $count);
1841
-                    break;
1842
-                case 'expired' :
1843
-                    return $EEME->get_expired_events($query_params, $count);
1844
-                    break;
1845
-                case 'active' :
1846
-                    return $EEME->get_active_events($query_params, $count);
1847
-                    break;
1848
-                case 'inactive' :
1849
-                    return $EEME->get_inactive_events($query_params, $count);
1850
-                    break;
1851
-            }
1852
-        }
1853
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1854
-        return $events;
1855
-    }
1856
-
1857
-
1858
-
1859
-    /**
1860
-     * handling for WordPress CPT actions (trash, restore, delete)
1861
-     *
1862
-     * @param string $post_id
1863
-     */
1864
-    public function trash_cpt_item($post_id)
1865
-    {
1866
-        $this->_req_data['EVT_ID'] = $post_id;
1867
-        $this->_trash_or_restore_event('trash', false);
1868
-    }
1869
-
1870
-
1871
-
1872
-    /**
1873
-     * @param string $post_id
1874
-     */
1875
-    public function restore_cpt_item($post_id)
1876
-    {
1877
-        $this->_req_data['EVT_ID'] = $post_id;
1878
-        $this->_trash_or_restore_event('draft', false);
1879
-    }
1880
-
1881
-
1882
-
1883
-    /**
1884
-     * @param string $post_id
1885
-     */
1886
-    public function delete_cpt_item($post_id)
1887
-    {
1888
-        $this->_req_data['EVT_ID'] = $post_id;
1889
-        $this->_delete_event(false);
1890
-    }
1891
-
1892
-
1893
-
1894
-    /**
1895
-     * _trash_or_restore_event
1896
-     *
1897
-     * @access protected
1898
-     * @param  string $event_status
1899
-     * @param bool    $redirect_after
1900
-     */
1901
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1902
-    {
1903
-        //determine the event id and set to array.
1904
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1905
-        // loop thru events
1906
-        if ($EVT_ID) {
1907
-            // clean status
1908
-            $event_status = sanitize_key($event_status);
1909
-            // grab status
1910
-            if ( ! empty($event_status)) {
1911
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1912
-            } else {
1913
-                $success = false;
1914
-                $msg = esc_html__(
1915
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1916
-                    'event_espresso'
1917
-                );
1918
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1919
-            }
1920
-        } else {
1921
-            $success = false;
1922
-            $msg = esc_html__(
1923
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1924
-                'event_espresso'
1925
-            );
1926
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1927
-        }
1928
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1929
-        if ($redirect_after) {
1930
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1931
-        }
1932
-    }
1933
-
1934
-
1935
-
1936
-    /**
1937
-     * _trash_or_restore_events
1938
-     *
1939
-     * @access protected
1940
-     * @param  string $event_status
1941
-     * @return void
1942
-     */
1943
-    protected function _trash_or_restore_events($event_status = 'trash')
1944
-    {
1945
-        // clean status
1946
-        $event_status = sanitize_key($event_status);
1947
-        // grab status
1948
-        if ( ! empty($event_status)) {
1949
-            $success = true;
1950
-            //determine the event id and set to array.
1951
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1952
-            // loop thru events
1953
-            foreach ($EVT_IDs as $EVT_ID) {
1954
-                if ($EVT_ID = absint($EVT_ID)) {
1955
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1956
-                    $success = $results !== false ? $success : false;
1957
-                } else {
1958
-                    $msg = sprintf(
1959
-                        esc_html__(
1960
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1961
-                            'event_espresso'
1962
-                        ),
1963
-                        $EVT_ID
1964
-                    );
1965
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1966
-                    $success = false;
1967
-                }
1968
-            }
1969
-        } else {
1970
-            $success = false;
1971
-            $msg = esc_html__(
1972
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1973
-                'event_espresso'
1974
-            );
1975
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1976
-        }
1977
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1978
-        $success = $success ? 2 : false;
1979
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1980
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1981
-    }
1982
-
1983
-
1984
-
1985
-    /**
1986
-     * _trash_or_restore_events
1987
-     *
1988
-     * @access  private
1989
-     * @param  int    $EVT_ID
1990
-     * @param  string $event_status
1991
-     * @return bool
1992
-     */
1993
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
1994
-    {
1995
-        // grab event id
1996
-        if ( ! $EVT_ID) {
1997
-            $msg = esc_html__(
1998
-                'An error occurred. No Event ID or an invalid Event ID was received.',
1999
-                'event_espresso'
2000
-            );
2001
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2002
-            return false;
2003
-        }
2004
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2005
-        // clean status
2006
-        $event_status = sanitize_key($event_status);
2007
-        // grab status
2008
-        if (empty($event_status)) {
2009
-            $msg = esc_html__(
2010
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2011
-                'event_espresso'
2012
-            );
2013
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2014
-            return false;
2015
-        }
2016
-        // was event trashed or restored ?
2017
-        switch ($event_status) {
2018
-            case 'draft' :
2019
-                $action = 'restored from the trash';
2020
-                $hook = 'AHEE_event_restored_from_trash';
2021
-                break;
2022
-            case 'trash' :
2023
-                $action = 'moved to the trash';
2024
-                $hook = 'AHEE_event_moved_to_trash';
2025
-                break;
2026
-            default :
2027
-                $action = 'updated';
2028
-                $hook = false;
2029
-        }
2030
-        //use class to change status
2031
-        $this->_cpt_model_obj->set_status($event_status);
2032
-        $success = $this->_cpt_model_obj->save();
2033
-        if ($success === false) {
2034
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2035
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2036
-            return false;
2037
-        }
2038
-        if ($hook) {
2039
-            do_action($hook);
2040
-        }
2041
-        return true;
2042
-    }
2043
-
2044
-
2045
-
2046
-    /**
2047
-     * _delete_event
2048
-     *
2049
-     * @access protected
2050
-     * @param bool $redirect_after
2051
-     */
2052
-    protected function _delete_event($redirect_after = true)
2053
-    {
2054
-        //determine the event id and set to array.
2055
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2056
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2057
-        // loop thru events
2058
-        if ($EVT_ID) {
2059
-            $success = $this->_permanently_delete_event($EVT_ID);
2060
-            // get list of events with no prices
2061
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2062
-            // remove this event from the list of events with no prices
2063
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2064
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2065
-            }
2066
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2067
-        } else {
2068
-            $success = false;
2069
-            $msg = esc_html__(
2070
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2071
-                'event_espresso'
2072
-            );
2073
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2074
-        }
2075
-        if ($redirect_after) {
2076
-            $this->_redirect_after_action(
2077
-                $success,
2078
-                'Event',
2079
-                'deleted',
2080
-                array('action' => 'default', 'status' => 'trash')
2081
-            );
2082
-        }
2083
-    }
2084
-
2085
-
2086
-
2087
-    /**
2088
-     * _delete_events
2089
-     *
2090
-     * @access protected
2091
-     * @return void
2092
-     */
2093
-    protected function _delete_events()
2094
-    {
2095
-        $success = true;
2096
-        // get list of events with no prices
2097
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2098
-        //determine the event id and set to array.
2099
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2100
-        // loop thru events
2101
-        foreach ($EVT_IDs as $EVT_ID) {
2102
-            $EVT_ID = absint($EVT_ID);
2103
-            if ($EVT_ID) {
2104
-                $results = $this->_permanently_delete_event($EVT_ID);
2105
-                $success = $results !== false ? $success : false;
2106
-                // remove this event from the list of events with no prices
2107
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2108
-            } else {
2109
-                $success = false;
2110
-                $msg = esc_html__(
2111
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2112
-                    'event_espresso'
2113
-                );
2114
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2115
-            }
2116
-        }
2117
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2118
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2119
-        $success = $success ? 2 : false;
2120
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2121
-    }
2122
-
2123
-
2124
-
2125
-    /**
2126
-     * _permanently_delete_event
2127
-     *
2128
-     * @access  private
2129
-     * @param  int $EVT_ID
2130
-     * @return bool
2131
-     */
2132
-    private function _permanently_delete_event($EVT_ID = 0)
2133
-    {
2134
-        // grab event id
2135
-        if ( ! $EVT_ID) {
2136
-            $msg = esc_html__(
2137
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2138
-                'event_espresso'
2139
-            );
2140
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2141
-            return false;
2142
-        }
2143
-        if (
2144
-            ! $this->_cpt_model_obj instanceof EE_Event
2145
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2146
-        ) {
2147
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2148
-        }
2149
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2150
-            return false;
2151
-        }
2152
-        //need to delete related tickets and prices first.
2153
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2154
-        foreach ($datetimes as $datetime) {
2155
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2156
-            $tickets = $datetime->get_many_related('Ticket');
2157
-            foreach ($tickets as $ticket) {
2158
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2159
-                $ticket->delete_related_permanently('Price');
2160
-                $ticket->delete_permanently();
2161
-            }
2162
-            $datetime->delete();
2163
-        }
2164
-        //what about related venues or terms?
2165
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2166
-        foreach ($venues as $venue) {
2167
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2168
-        }
2169
-        //any attached question groups?
2170
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2171
-        if ( ! empty($question_groups)) {
2172
-            foreach ($question_groups as $question_group) {
2173
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2174
-            }
2175
-        }
2176
-        //Message Template Groups
2177
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2178
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2179
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2180
-        foreach ($term_taxonomies as $term_taxonomy) {
2181
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2182
-        }
2183
-        $success = $this->_cpt_model_obj->delete_permanently();
2184
-        // did it all go as planned ?
2185
-        if ($success) {
2186
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2187
-            EE_Error::add_success($msg);
2188
-        } else {
2189
-            $msg = sprintf(
2190
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2191
-                $EVT_ID
2192
-            );
2193
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2194
-            return false;
2195
-        }
2196
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2197
-        return true;
2198
-    }
2199
-
2200
-
2201
-
2202
-    /**
2203
-     * get total number of events
2204
-     *
2205
-     * @access public
2206
-     * @return int
2207
-     */
2208
-    public function total_events()
2209
-    {
2210
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2211
-        return $count;
2212
-    }
2213
-
2214
-
2215
-
2216
-    /**
2217
-     * get total number of draft events
2218
-     *
2219
-     * @access public
2220
-     * @return int
2221
-     */
2222
-    public function total_events_draft()
2223
-    {
2224
-        $where = array(
2225
-            'status' => array('IN', array('draft', 'auto-draft')),
2226
-        );
2227
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2228
-        return $count;
2229
-    }
2230
-
2231
-
2232
-
2233
-    /**
2234
-     * get total number of trashed events
2235
-     *
2236
-     * @access public
2237
-     * @return int
2238
-     */
2239
-    public function total_trashed_events()
2240
-    {
2241
-        $where = array(
2242
-            'status' => 'trash',
2243
-        );
2244
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2245
-        return $count;
2246
-    }
2247
-
2248
-
2249
-
2250
-    /**
2251
-     *    _default_event_settings
2252
-     *    This generates the Default Settings Tab
2253
-     *
2254
-     * @return void
2255
-     */
2256
-    protected function _default_event_settings()
2257
-    {
2258
-        $this->_template_args['values'] = $this->_yes_no_values;
2259
-        $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2260
-        // exclude array
2261
-            array(
2262
-                EEM_Registration::status_id_cancelled,
2263
-                EEM_Registration::status_id_declined,
2264
-                EEM_Registration::status_id_incomplete,
2265
-                EEM_Registration::status_id_wait_list,
2266
-            ),
2267
-            // translated
2268
-            true
2269
-        );
2270
-        $this->_template_args['default_reg_status'] = isset(
2271
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID
2272
-                                                      )
2273
-                                                      && array_key_exists(
2274
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID,
2275
-                                                          $this->_template_args['reg_status_array']
2276
-                                                      )
2277
-            ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2278
-            : EEM_Registration::status_id_pending_payment;
2279
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2280
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2281
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2282
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2283
-            $this->_template_args,
2284
-            true
2285
-        );
2286
-        $this->display_admin_page_with_sidebar();
2287
-    }
2288
-
2289
-
2290
-
2291
-    /**
2292
-     * _update_default_event_settings
2293
-     *
2294
-     * @access protected
2295
-     * @return void
2296
-     */
2297
-    protected function _update_default_event_settings()
2298
-    {
2299
-        EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2300
-            ? sanitize_text_field($this->_req_data['default_reg_status'])
2301
-            : EEM_Registration::status_id_pending_payment;
2302
-        $what = 'Default Event Settings';
2303
-        $success = $this->_update_espresso_configuration(
2304
-            $what,
2305
-            EE_Config::instance(),
2306
-            __FILE__,
2307
-            __FUNCTION__,
2308
-            __LINE__
2309
-        );
2310
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2311
-    }
2312
-
2313
-
2314
-
2315
-    /*************        Templates        *************/
2316
-    protected function _template_settings()
2317
-    {
2318
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2319
-        $this->_template_args['preview_img'] = '<img src="'
2320
-                                               . EVENTS_ASSETS_URL
2321
-                                               . DS
2322
-                                               . 'images'
2323
-                                               . DS
2324
-                                               . 'caffeinated_template_features.jpg" alt="'
2325
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2326
-                                               . '" />';
2327
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2328
-                'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2329
-                'event_espresso'
2330
-            ) . '</strong>';
2331
-        $this->display_admin_caf_preview_page('template_settings_tab');
2332
-    }
2333
-
2334
-
2335
-    /** Event Category Stuff **/
2336
-    /**
2337
-     * set the _category property with the category object for the loaded page.
2338
-     *
2339
-     * @access private
2340
-     * @return void
2341
-     */
2342
-    private function _set_category_object()
2343
-    {
2344
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2345
-            return;
2346
-        } //already have the category object so get out.
2347
-        //set default category object
2348
-        $this->_set_empty_category_object();
2349
-        //only set if we've got an id
2350
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2351
-            return;
2352
-        }
2353
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2354
-        $term = get_term($category_id, 'espresso_event_categories');
2355
-        if ( ! empty($term)) {
2356
-            $this->_category->category_name = $term->name;
2357
-            $this->_category->category_identifier = $term->slug;
2358
-            $this->_category->category_desc = $term->description;
2359
-            $this->_category->id = $term->term_id;
2360
-            $this->_category->parent = $term->parent;
2361
-        }
2362
-    }
2363
-
2364
-
2365
-
2366
-    private function _set_empty_category_object()
2367
-    {
2368
-        $this->_category = new stdClass();
2369
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2370
-        $this->_category->id = $this->_category->parent = 0;
2371
-    }
2372
-
2373
-
2374
-
2375
-    protected function _category_list_table()
2376
-    {
2377
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2378
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2379
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2380
-                'add_category',
2381
-                'add_category',
2382
-                array(),
2383
-                'add-new-h2'
2384
-            );
2385
-        $this->display_admin_list_table_page_with_sidebar();
2386
-    }
2387
-
2388
-
2389
-
2390
-    /**
2391
-     * @param $view
2392
-     */
2393
-    protected function _category_details($view)
2394
-    {
2395
-        //load formatter helper
2396
-        //load field generator helper
2397
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2398
-        $this->_set_add_edit_form_tags($route);
2399
-        $this->_set_category_object();
2400
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2401
-        $delete_action = 'delete_category';
2402
-        //custom redirect
2403
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2404
-            array('action' => 'category_list'),
2405
-            $this->_admin_base_url
2406
-        );
2407
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2408
-        //take care of contents
2409
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2410
-        $this->display_admin_page_with_sidebar();
2411
-    }
2412
-
2413
-
2414
-
2415
-    /**
2416
-     * @return mixed
2417
-     */
2418
-    protected function _category_details_content()
2419
-    {
2420
-        $editor_args['category_desc'] = array(
2421
-            'type'          => 'wp_editor',
2422
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2423
-            'class'         => 'my_editor_custom',
2424
-            'wpeditor_args' => array('media_buttons' => false),
2425
-        );
2426
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2427
-        $all_terms = get_terms(
2428
-            array('espresso_event_categories'),
2429
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2430
-        );
2431
-        //setup category select for term parents.
2432
-        $category_select_values[] = array(
2433
-            'text' => esc_html__('No Parent', 'event_espresso'),
2434
-            'id'   => 0,
2435
-        );
2436
-        foreach ($all_terms as $term) {
2437
-            $category_select_values[] = array(
2438
-                'text' => $term->name,
2439
-                'id'   => $term->term_id,
2440
-            );
2441
-        }
2442
-        $category_select = EEH_Form_Fields::select_input(
2443
-            'category_parent',
2444
-            $category_select_values,
2445
-            $this->_category->parent
2446
-        );
2447
-        $template_args = array(
2448
-            'category'                 => $this->_category,
2449
-            'category_select'          => $category_select,
2450
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2451
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2452
-            'disable'                  => '',
2453
-            'disabled_message'         => false,
2454
-        );
2455
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2456
-        return EEH_Template::display_template($template, $template_args, true);
2457
-    }
2458
-
2459
-
2460
-
2461
-    protected function _delete_categories()
2462
-    {
2463
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2464
-            : (array)$this->_req_data['category_id'];
2465
-        foreach ($cat_ids as $cat_id) {
2466
-            $this->_delete_category($cat_id);
2467
-        }
2468
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2469
-        $query_args = array(
2470
-            'action' => 'category_list',
2471
-        );
2472
-        $this->_redirect_after_action(0, '', '', $query_args);
2473
-    }
2474
-
2475
-
2476
-
2477
-    /**
2478
-     * @param $cat_id
2479
-     */
2480
-    protected function _delete_category($cat_id)
2481
-    {
2482
-        $cat_id = absint($cat_id);
2483
-        wp_delete_term($cat_id, 'espresso_event_categories');
2484
-    }
2485
-
2486
-
2487
-
2488
-    /**
2489
-     * @param $new_category
2490
-     */
2491
-    protected function _insert_or_update_category($new_category)
2492
-    {
2493
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2494
-        $success = 0; //we already have a success message so lets not send another.
2495
-        if ($cat_id) {
2496
-            $query_args = array(
2497
-                'action'     => 'edit_category',
2498
-                'EVT_CAT_ID' => $cat_id,
2499
-            );
2500
-        } else {
2501
-            $query_args = array('action' => 'add_category');
2502
-        }
2503
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2504
-    }
2505
-
2506
-
2507
-
2508
-    /**
2509
-     * @param bool $update
2510
-     * @return bool|mixed|string
2511
-     */
2512
-    private function _insert_category($update = false)
2513
-    {
2514
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2515
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2516
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2517
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2518
-        if (empty($category_name)) {
2519
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2520
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2521
-            return false;
2522
-        }
2523
-        $term_args = array(
2524
-            'name'        => $category_name,
2525
-            'description' => $category_desc,
2526
-            'parent'      => $category_parent,
2527
-        );
2528
-        //was the category_identifier input disabled?
2529
-        if (isset($this->_req_data['category_identifier'])) {
2530
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2531
-        }
2532
-        $insert_ids = $update
2533
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2534
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2535
-        if ( ! is_array($insert_ids)) {
2536
-            $msg = esc_html__(
2537
-                'An error occurred and the category has not been saved to the database.',
2538
-                'event_espresso'
2539
-            );
2540
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2541
-        } else {
2542
-            $cat_id = $insert_ids['term_id'];
2543
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2544
-            EE_Error::add_success($msg);
2545
-        }
2546
-        return $cat_id;
2547
-    }
2548
-
2549
-
2550
-
2551
-    /**
2552
-     * @param int  $per_page
2553
-     * @param int  $current_page
2554
-     * @param bool $count
2555
-     * @return \EE_Base_Class[]|int
2556
-     */
2557
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2558
-    {
2559
-        //testing term stuff
2560
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2561
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2562
-        $limit = ($current_page - 1) * $per_page;
2563
-        $where = array('taxonomy' => 'espresso_event_categories');
2564
-        if (isset($this->_req_data['s'])) {
2565
-            $sstr = '%' . $this->_req_data['s'] . '%';
2566
-            $where['OR'] = array(
2567
-                'Term.name'   => array('LIKE', $sstr),
2568
-                'description' => array('LIKE', $sstr),
2569
-            );
2570
-        }
2571
-        $query_params = array(
2572
-            $where,
2573
-            'order_by'   => array($orderby => $order),
2574
-            'limit'      => $limit . ',' . $per_page,
2575
-            'force_join' => array('Term'),
2576
-        );
2577
-        $categories = $count
2578
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2579
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2580
-        return $categories;
2581
-    }
2582
-
2583
-
2584
-
2585
-    /* end category stuff */
2586
-    /**************/
384
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
385
+				'require_nonce' => false,
386
+			),
387
+			'default_event_settings' => array(
388
+				'nav'           => array(
389
+					'label' => esc_html__('Default Settings', 'event_espresso'),
390
+					'order' => 40,
391
+				),
392
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
393
+				'labels'        => array(
394
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
395
+				),
396
+				'help_tabs'     => array(
397
+					'default_settings_help_tab'        => array(
398
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
399
+						'filename' => 'events_default_settings',
400
+					),
401
+					'default_settings_status_help_tab' => array(
402
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
403
+						'filename' => 'events_default_settings_status',
404
+					),
405
+				),
406
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
407
+				'require_nonce' => false,
408
+			),
409
+			//template settings
410
+			'template_settings'      => array(
411
+				'nav'           => array(
412
+					'label' => esc_html__('Templates', 'event_espresso'),
413
+					'order' => 30,
414
+				),
415
+				'metaboxes'     => $this->_default_espresso_metaboxes,
416
+				'help_tabs'     => array(
417
+					'general_settings_templates_help_tab' => array(
418
+						'title'    => esc_html__('Templates', 'event_espresso'),
419
+						'filename' => 'general_settings_templates',
420
+					),
421
+				),
422
+				'help_tour'     => array('Templates_Help_Tour'),
423
+				'require_nonce' => false,
424
+			),
425
+			//event category stuff
426
+			'add_category'           => array(
427
+				'nav'           => array(
428
+					'label'      => esc_html__('Add Category', 'event_espresso'),
429
+					'order'      => 15,
430
+					'persistent' => false,
431
+				),
432
+				'help_tabs'     => array(
433
+					'add_category_help_tab' => array(
434
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
435
+						'filename' => 'events_add_category',
436
+					),
437
+				),
438
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
439
+				'metaboxes'     => array('_publish_post_box'),
440
+				'require_nonce' => false,
441
+			),
442
+			'edit_category'          => array(
443
+				'nav'           => array(
444
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
445
+					'order'      => 15,
446
+					'persistent' => false,
447
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
448
+						? add_query_arg(
449
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
450
+							$this->_current_page_view_url
451
+						)
452
+						: $this->_admin_base_url,
453
+				),
454
+				'help_tabs'     => array(
455
+					'edit_category_help_tab' => array(
456
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
457
+						'filename' => 'events_edit_category',
458
+					),
459
+				),
460
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
461
+				'metaboxes'     => array('_publish_post_box'),
462
+				'require_nonce' => false,
463
+			),
464
+			'category_list'          => array(
465
+				'nav'           => array(
466
+					'label' => esc_html__('Categories', 'event_espresso'),
467
+					'order' => 20,
468
+				),
469
+				'list_table'    => 'Event_Categories_Admin_List_Table',
470
+				'help_tabs'     => array(
471
+					'events_categories_help_tab'                       => array(
472
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
473
+						'filename' => 'events_categories',
474
+					),
475
+					'events_categories_table_column_headings_help_tab' => array(
476
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
477
+						'filename' => 'events_categories_table_column_headings',
478
+					),
479
+					'events_categories_view_help_tab'                  => array(
480
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
481
+						'filename' => 'events_categories_views',
482
+					),
483
+					'events_categories_other_help_tab'                 => array(
484
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
485
+						'filename' => 'events_categories_other',
486
+					),
487
+				),
488
+				'help_tour'     => array(
489
+					'Event_Categories_Help_Tour',
490
+				),
491
+				'metaboxes'     => $this->_default_espresso_metaboxes,
492
+				'require_nonce' => false,
493
+			),
494
+		);
495
+	}
496
+
497
+
498
+
499
+	protected function _add_screen_options()
500
+	{
501
+		//todo
502
+	}
503
+
504
+
505
+
506
+	protected function _add_screen_options_default()
507
+	{
508
+		$this->_per_page_screen_option();
509
+	}
510
+
511
+
512
+
513
+	protected function _add_screen_options_category_list()
514
+	{
515
+		$page_title = $this->_admin_page_title;
516
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
517
+		$this->_per_page_screen_option();
518
+		$this->_admin_page_title = $page_title;
519
+	}
520
+
521
+
522
+
523
+	protected function _add_feature_pointers()
524
+	{
525
+		//todo
526
+	}
527
+
528
+
529
+
530
+	public function load_scripts_styles()
531
+	{
532
+		wp_register_style(
533
+			'events-admin-css',
534
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
535
+			array(),
536
+			EVENT_ESPRESSO_VERSION
537
+		);
538
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
+		wp_enqueue_style('events-admin-css');
540
+		wp_enqueue_style('ee-cat-admin');
541
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
542
+		//registers for all views
543
+		//scripts
544
+		wp_register_script(
545
+			'event_editor_js',
546
+			EVENTS_ASSETS_URL . 'event_editor.js',
547
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548
+			EVENT_ESPRESSO_VERSION,
549
+			true
550
+		);
551
+	}
552
+
553
+
554
+
555
+	/**
556
+	 * enqueuing scripts and styles specific to this view
557
+	 *
558
+	 * @return void
559
+	 */
560
+	public function load_scripts_styles_create_new()
561
+	{
562
+		$this->load_scripts_styles_edit();
563
+	}
564
+
565
+
566
+
567
+	/**
568
+	 * enqueuing scripts and styles specific to this view
569
+	 *
570
+	 * @return void
571
+	 */
572
+	public function load_scripts_styles_edit()
573
+	{
574
+		//styles
575
+		wp_enqueue_style('espresso-ui-theme');
576
+		wp_register_style(
577
+			'event-editor-css',
578
+			EVENTS_ASSETS_URL . 'event-editor.css',
579
+			array('ee-admin-css'),
580
+			EVENT_ESPRESSO_VERSION
581
+		);
582
+		wp_enqueue_style('event-editor-css');
583
+		//scripts
584
+		wp_register_script(
585
+			'event-datetime-metabox',
586
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
+			array('event_editor_js', 'ee-datepicker'),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_enqueue_script('event-datetime-metabox');
591
+	}
592
+
593
+
594
+
595
+	public function load_scripts_styles_add_category()
596
+	{
597
+		$this->load_scripts_styles_edit_category();
598
+	}
599
+
600
+
601
+
602
+	public function load_scripts_styles_edit_category()
603
+	{
604
+	}
605
+
606
+
607
+
608
+	protected function _set_list_table_views_category_list()
609
+	{
610
+		$this->_views = array(
611
+			'all' => array(
612
+				'slug'        => 'all',
613
+				'label'       => esc_html__('All', 'event_espresso'),
614
+				'count'       => 0,
615
+				'bulk_action' => array(
616
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
+				),
618
+			),
619
+		);
620
+	}
621
+
622
+
623
+
624
+	public function admin_init()
625
+	{
626
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
627
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
628
+			'event_espresso'
629
+		);
630
+	}
631
+
632
+
633
+
634
+	//nothing needed for events with these methods.
635
+	public function admin_notices()
636
+	{
637
+	}
638
+
639
+
640
+
641
+	public function admin_footer_scripts()
642
+	{
643
+	}
644
+
645
+
646
+
647
+	/**
648
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
649
+	 * warning (via EE_Error::add_error());
650
+	 *
651
+	 * @param  EE_Event $event Event object
652
+	 * @access public
653
+	 * @return void
654
+	 */
655
+	public function verify_event_edit($event = null)
656
+	{
657
+		// no event?
658
+		if (empty($event)) {
659
+			// set event
660
+			$event = $this->_cpt_model_obj;
661
+		}
662
+		// STILL no event?
663
+		if (empty ($event)) {
664
+			return;
665
+		}
666
+		$orig_status = $event->status();
667
+		// first check if event is active.
668
+		if (
669
+			$orig_status === EEM_Event::cancelled
670
+			|| $orig_status === EEM_Event::postponed
671
+			|| $event->is_expired()
672
+			|| $event->is_inactive()
673
+		) {
674
+			return;
675
+		}
676
+		//made it here so it IS active... next check that any of the tickets are sold.
677
+		if ($event->is_sold_out(true)) {
678
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
679
+				EE_Error::add_attention(
680
+					sprintf(
681
+						esc_html__(
682
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
683
+							'event_espresso'
684
+						),
685
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
686
+					)
687
+				);
688
+			}
689
+			return;
690
+		} else if ($orig_status === EEM_Event::sold_out) {
691
+			EE_Error::add_attention(
692
+				sprintf(
693
+					esc_html__(
694
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
695
+						'event_espresso'
696
+					),
697
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
698
+				)
699
+			);
700
+		}
701
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
702
+		if ( ! $event->tickets_on_sale()) {
703
+			return;
704
+		}
705
+		//made it here so show warning
706
+		$this->_edit_event_warning();
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
713
+	 * When needed, hook this into a EE_Error::add_error() notice.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _edit_event_warning()
719
+	{
720
+		// we don't want to add warnings during these requests
721
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
722
+			return;
723
+		}
724
+		EE_Error::add_attention(
725
+			esc_html__(
726
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
727
+				'event_espresso'
728
+			)
729
+		);
730
+	}
731
+
732
+
733
+
734
+	/**
735
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
736
+	 * Otherwise, do the normal logic
737
+	 *
738
+	 * @return string
739
+	 * @throws \EE_Error
740
+	 */
741
+	protected function _create_new_cpt_item()
742
+	{
743
+		$gmt_offset = get_option('gmt_offset');
744
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
745
+		if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
746
+			EE_Error::add_attention(
747
+				sprintf(
748
+					__(
749
+						'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750
+						'event_espresso'
751
+					),
752
+					'<a href="' . admin_url('options-general.php') . '">',
753
+					'</a>'
754
+				),
755
+				__FILE__,
756
+				__FUNCTION__,
757
+				__LINE__
758
+			);
759
+		}
760
+		return parent::_create_new_cpt_item();
761
+	}
762
+
763
+
764
+
765
+	protected function _set_list_table_views_default()
766
+	{
767
+		$this->_views = array(
768
+			'all'   => array(
769
+				'slug'        => 'all',
770
+				'label'       => esc_html__('View All Events', 'event_espresso'),
771
+				'count'       => 0,
772
+				'bulk_action' => array(
773
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
774
+				),
775
+			),
776
+			'draft' => array(
777
+				'slug'        => 'draft',
778
+				'label'       => esc_html__('Draft', 'event_espresso'),
779
+				'count'       => 0,
780
+				'bulk_action' => array(
781
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
782
+				),
783
+			),
784
+		);
785
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
786
+			$this->_views['trash'] = array(
787
+				'slug'        => 'trash',
788
+				'label'       => esc_html__('Trash', 'event_espresso'),
789
+				'count'       => 0,
790
+				'bulk_action' => array(
791
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
792
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
793
+				),
794
+			);
795
+		}
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * @return array
802
+	 */
803
+	protected function _event_legend_items()
804
+	{
805
+		$items = array(
806
+			'view_details'   => array(
807
+				'class' => 'dashicons dashicons-search',
808
+				'desc'  => esc_html__('View Event', 'event_espresso'),
809
+			),
810
+			'edit_event'     => array(
811
+				'class' => 'ee-icon ee-icon-calendar-edit',
812
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
813
+			),
814
+			'view_attendees' => array(
815
+				'class' => 'dashicons dashicons-groups',
816
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
817
+			),
818
+		);
819
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820
+		$statuses = array(
821
+			'sold_out_status'  => array(
822
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824
+			),
825
+			'active_status'    => array(
826
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828
+			),
829
+			'upcoming_status'  => array(
830
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832
+			),
833
+			'postponed_status' => array(
834
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836
+			),
837
+			'cancelled_status' => array(
838
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840
+			),
841
+			'expired_status'   => array(
842
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844
+			),
845
+			'inactive_status'  => array(
846
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848
+			),
849
+		);
850
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
851
+		return array_merge($items, $statuses);
852
+	}
853
+
854
+
855
+
856
+	/**
857
+	 * _event_model
858
+	 *
859
+	 * @return EEM_Event
860
+	 */
861
+	private function _event_model()
862
+	{
863
+		if ( ! $this->_event_model instanceof EEM_Event) {
864
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
865
+		}
866
+		return $this->_event_model;
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * Adds extra buttons to the WP CPT permalink field row.
873
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
874
+	 *
875
+	 * @param  string $return    the current html
876
+	 * @param  int    $id        the post id for the page
877
+	 * @param  string $new_title What the title is
878
+	 * @param  string $new_slug  what the slug is
879
+	 * @return string            The new html string for the permalink area
880
+	 */
881
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
882
+	{
883
+		//make sure this is only when editing
884
+		if ( ! empty($id)) {
885
+			$post = get_post($id);
886
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
887
+					   . esc_html__('Shortcode', 'event_espresso')
888
+					   . '</a> ';
889
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
890
+					   . $post->ID
891
+					   . ']">';
892
+		}
893
+		return $return;
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * _events_overview_list_table
900
+	 * This contains the logic for showing the events_overview list
901
+	 *
902
+	 * @access protected
903
+	 * @return void
904
+	 * @throws \EE_Error
905
+	 */
906
+	protected function _events_overview_list_table()
907
+	{
908
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
909
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
910
+			? (array)$this->_template_args['after_list_table']
911
+			: array();
912
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
913
+																			  . EEH_Template::get_button_or_link(
914
+				get_post_type_archive_link('espresso_events'),
915
+				esc_html__("View Event Archive Page", "event_espresso"),
916
+				'button'
917
+			);
918
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
919
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
920
+				'create_new',
921
+				'add',
922
+				array(),
923
+				'add-new-h2'
924
+			);
925
+		$this->display_admin_list_table_page_with_no_sidebar();
926
+	}
927
+
928
+
929
+
930
+	/**
931
+	 * this allows for extra misc actions in the default WP publish box
932
+	 *
933
+	 * @return void
934
+	 */
935
+	public function extra_misc_actions_publish_box()
936
+	{
937
+		$this->_generate_publish_box_extra_content();
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
944
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
945
+	 * data.
946
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
947
+	 * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
948
+	 * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
949
+	 * you handle this accordingly.
950
+	 *
951
+	 * @access protected
952
+	 * @abstract
953
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
954
+	 * @param  object $post    The post object of the cpt that was saved.
955
+	 * @return void
956
+	 */
957
+	protected function _insert_update_cpt_item($post_id, $post)
958
+	{
959
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
960
+			//get out we're not processing an event save.
961
+			return;
962
+		}
963
+		$event_values = array(
964
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
965
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
966
+			'EVT_additional_limit'            => min(
967
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
968
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
969
+			),
970
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
971
+				? $this->_req_data['EVT_default_registration_status']
972
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
973
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
974
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
975
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
976
+				? $this->_req_data['timezone_string'] : null,
977
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
978
+				? $this->_req_data['externalURL'] : null,
979
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
980
+				? $this->_req_data['event_phone'] : null,
981
+		);
982
+		//update event
983
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
984
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
985
+		$get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
986
+		$event = $this->_event_model()->get_one(array($get_one_where));
987
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
988
+		$event_update_callbacks = apply_filters(
989
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
990
+			array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
991
+		);
992
+		$att_success = true;
993
+		foreach ($event_update_callbacks as $e_callback) {
994
+			$_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
995
+			$att_success = ! $att_success ? $att_success
996
+				: $_succ; //if ANY of these updates fail then we want the appropriate global error message
997
+		}
998
+		//any errors?
999
+		if ($success && false === $att_success) {
1000
+			EE_Error::add_error(
1001
+				esc_html__(
1002
+					'Event Details saved successfully but something went wrong with saving attachments.',
1003
+					'event_espresso'
1004
+				),
1005
+				__FILE__,
1006
+				__FUNCTION__,
1007
+				__LINE__
1008
+			);
1009
+		} else if ($success === false) {
1010
+			EE_Error::add_error(
1011
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1012
+				__FILE__,
1013
+				__FUNCTION__,
1014
+				__LINE__
1015
+			);
1016
+		}
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 * @see parent::restore_item()
1023
+	 * @param int $post_id
1024
+	 * @param int $revision_id
1025
+	 */
1026
+	protected function _restore_cpt_item($post_id, $revision_id)
1027
+	{
1028
+		//copy existing event meta to new post
1029
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1030
+		if ($post_evt instanceof EE_Event) {
1031
+			//meta revision restore
1032
+			$post_evt->restore_revision($revision_id);
1033
+			//related objs restore
1034
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1035
+		}
1036
+	}
1037
+
1038
+
1039
+
1040
+	/**
1041
+	 * Attach the venue to the Event
1042
+	 *
1043
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1044
+	 * @param  array     $data   The request data from the form
1045
+	 * @return bool           Success or fail.
1046
+	 */
1047
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1048
+	{
1049
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1050
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1051
+		$rows_affected = null;
1052
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1053
+		// very important.  If we don't have a venue name...
1054
+		// then we'll get out because not necessary to create empty venue
1055
+		if (empty($data['venue_title'])) {
1056
+			return false;
1057
+		}
1058
+		$venue_array = array(
1059
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1060
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1061
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1062
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1063
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1064
+				: null,
1065
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1066
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1067
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1068
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1069
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1070
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1071
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1072
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1073
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1074
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1075
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1076
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1077
+			'status'              => 'publish',
1078
+		);
1079
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1080
+		if ( ! empty($venue_id)) {
1081
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1082
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1083
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1084
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1085
+			return $rows_affected > 0 ? true : false;
1086
+		} else {
1087
+			//we insert the venue
1088
+			$venue_id = $venue_model->insert($venue_array);
1089
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1090
+			return ! empty($venue_id) ? true : false;
1091
+		}
1092
+		//when we have the ancestor come in it's already been handled by the revision save.
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1099
+	 *
1100
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1101
+	 * @param  array    $data   The request data from the form
1102
+	 * @return array
1103
+	 */
1104
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1105
+	{
1106
+		$success = true;
1107
+		$saved_dtt = null;
1108
+		$saved_tickets = array();
1109
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1110
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1111
+			//trim all values to ensure any excess whitespace is removed.
1112
+			$dtt = array_map('trim', $dtt);
1113
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1114
+				: $dtt['DTT_EVT_start'];
1115
+			$datetime_values = array(
1116
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1117
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1118
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1119
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1120
+				'DTT_order'     => $row,
1121
+			);
1122
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1123
+			if ( ! empty($dtt['DTT_ID'])) {
1124
+				$DTM = EE_Registry::instance()
1125
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1126
+								  ->get_one_by_ID($dtt['DTT_ID']);
1127
+				$DTM->set_date_format($incoming_date_formats[0]);
1128
+				$DTM->set_time_format($incoming_date_formats[1]);
1129
+				foreach ($datetime_values as $field => $value) {
1130
+					$DTM->set($field, $value);
1131
+				}
1132
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1133
+				$saved_dtts[$DTM->ID()] = $DTM;
1134
+			} else {
1135
+				$DTM = EE_Registry::instance()->load_class(
1136
+					'Datetime',
1137
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1138
+					false,
1139
+					false
1140
+				);
1141
+				foreach ($datetime_values as $field => $value) {
1142
+					$DTM->set($field, $value);
1143
+				}
1144
+			}
1145
+			$DTM->save();
1146
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1147
+			//load DTT helper
1148
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1149
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1150
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1151
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1152
+				$DTT->save();
1153
+			}
1154
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1155
+			$saved_dtt = $DTT;
1156
+			$success = ! $success ? $success : $DTT;
1157
+			//if ANY of these updates fail then we want the appropriate global error message.
1158
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1159
+		}
1160
+		//no dtts get deleted so we don't do any of that logic here.
1161
+		//update tickets next
1162
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1163
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1164
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1165
+			$update_prices = false;
1166
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1167
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1168
+			// trim inputs to ensure any excess whitespace is removed.
1169
+			$tkt = array_map('trim', $tkt);
1170
+			if (empty($tkt['TKT_start_date'])) {
1171
+				//let's use now in the set timezone.
1172
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1173
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1174
+			}
1175
+			if (empty($tkt['TKT_end_date'])) {
1176
+				//use the start date of the first datetime
1177
+				$dtt = $evtobj->first_datetime();
1178
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1179
+					$incoming_date_formats[0],
1180
+					$incoming_date_formats[1]
1181
+				);
1182
+			}
1183
+			$TKT_values = array(
1184
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1185
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1186
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1187
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1188
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1189
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1190
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1191
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1192
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1193
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1194
+				'TKT_row'         => $row,
1195
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1196
+				'TKT_price'       => $ticket_price,
1197
+			);
1198
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1199
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1200
+				$TKT_values['TKT_ID'] = 0;
1201
+				$TKT_values['TKT_is_default'] = 0;
1202
+				$TKT_values['TKT_price'] = $ticket_price;
1203
+				$update_prices = true;
1204
+			}
1205
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1206
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1207
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1208
+			if ( ! empty($tkt['TKT_ID'])) {
1209
+				$TKT = EE_Registry::instance()
1210
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1211
+								  ->get_one_by_ID($tkt['TKT_ID']);
1212
+				if ($TKT instanceof EE_Ticket) {
1213
+					$ticket_sold = $TKT->count_related(
1214
+						'Registration',
1215
+						array(
1216
+							array(
1217
+								'STS_ID' => array(
1218
+									'NOT IN',
1219
+									array(EEM_Registration::status_id_incomplete),
1220
+								),
1221
+							),
1222
+						)
1223
+					) > 0 ? true : false;
1224
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1225
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1226
+									  && ! $TKT->get(
1227
+						'TKT_deleted'
1228
+					) ? true : false;
1229
+					$TKT->set_date_format($incoming_date_formats[0]);
1230
+					$TKT->set_time_format($incoming_date_formats[1]);
1231
+					//set new values
1232
+					foreach ($TKT_values as $field => $value) {
1233
+						if ($field == 'TKT_qty') {
1234
+							$TKT->set_qty($value);
1235
+						} else {
1236
+							$TKT->set($field, $value);
1237
+						}
1238
+					}
1239
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1240
+					if ($create_new_TKT) {
1241
+						//archive the old ticket first
1242
+						$TKT->set('TKT_deleted', 1);
1243
+						$TKT->save();
1244
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1245
+						$saved_tickets[$TKT->ID()] = $TKT;
1246
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1247
+						$TKT = clone $TKT;
1248
+						$TKT->set('TKT_ID', 0);
1249
+						$TKT->set('TKT_deleted', 0);
1250
+						$TKT->set('TKT_price', $ticket_price);
1251
+						$TKT->set('TKT_sold', 0);
1252
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1253
+						$update_prices = true;
1254
+					}
1255
+					//make sure price is set if it hasn't been already
1256
+					$TKT->set('TKT_price', $ticket_price);
1257
+				}
1258
+			} else {
1259
+				//no TKT_id so a new TKT
1260
+				$TKT_values['TKT_price'] = $ticket_price;
1261
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1262
+				if ($TKT instanceof EE_Ticket) {
1263
+					//need to reset values to properly account for the date formats
1264
+					$TKT->set_date_format($incoming_date_formats[0]);
1265
+					$TKT->set_time_format($incoming_date_formats[1]);
1266
+					$TKT->set_timezone($evtobj->get_timezone());
1267
+					//set new values
1268
+					foreach ($TKT_values as $field => $value) {
1269
+						if ($field == 'TKT_qty') {
1270
+							$TKT->set_qty($value);
1271
+						} else {
1272
+							$TKT->set($field, $value);
1273
+						}
1274
+					}
1275
+					$update_prices = true;
1276
+				}
1277
+			}
1278
+			// cap ticket qty by datetime reg limits
1279
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1280
+			//update ticket.
1281
+			$TKT->save();
1282
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1283
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1284
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1285
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1286
+				$TKT->save();
1287
+			}
1288
+			//initially let's add the ticket to the dtt
1289
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1290
+			$saved_tickets[$TKT->ID()] = $TKT;
1291
+			//add prices to ticket
1292
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1293
+		}
1294
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1295
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1296
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1297
+		foreach ($tickets_removed as $id) {
1298
+			$id = absint($id);
1299
+			//get the ticket for this id
1300
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1301
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1302
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1303
+			foreach ($dtts as $dtt) {
1304
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1305
+			}
1306
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1307
+			$tkt_to_remove->delete_related_permanently('Price');
1308
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1309
+			$tkt_to_remove->delete_permanently();
1310
+		}
1311
+		return array($saved_dtt, $saved_tickets);
1312
+	}
1313
+
1314
+
1315
+
1316
+	/**
1317
+	 * This attaches a list of given prices to a ticket.
1318
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1319
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1320
+	 * price info and prices are automatically "archived" via the ticket.
1321
+	 *
1322
+	 * @access  private
1323
+	 * @param array     $prices     Array of prices from the form.
1324
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1325
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1326
+	 * @return  void
1327
+	 */
1328
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1329
+	{
1330
+		foreach ($prices as $row => $prc) {
1331
+			$PRC_values = array(
1332
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1333
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1334
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1335
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1336
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1337
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1338
+				'PRC_order'      => $row,
1339
+			);
1340
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1341
+				$PRC_values['PRC_ID'] = 0;
1342
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1343
+			} else {
1344
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1345
+				//update this price with new values
1346
+				foreach ($PRC_values as $field => $newprc) {
1347
+					$PRC->set($field, $newprc);
1348
+				}
1349
+				$PRC->save();
1350
+			}
1351
+			$ticket->_add_relation_to($PRC, 'Price');
1352
+		}
1353
+	}
1354
+
1355
+
1356
+
1357
+	/**
1358
+	 * Add in our autosave ajax handlers
1359
+	 *
1360
+	 * @return void
1361
+	 */
1362
+	protected function _ee_autosave_create_new()
1363
+	{
1364
+		// $this->_ee_autosave_edit();
1365
+	}
1366
+
1367
+
1368
+
1369
+	protected function _ee_autosave_edit()
1370
+	{
1371
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1372
+	}
1373
+
1374
+
1375
+
1376
+	/**
1377
+	 *    _generate_publish_box_extra_content
1378
+	 *
1379
+	 * @access private
1380
+	 * @return void
1381
+	 */
1382
+	private function _generate_publish_box_extra_content()
1383
+	{
1384
+		//load formatter helper
1385
+		//args for getting related registrations
1386
+		$approved_query_args = array(
1387
+			array(
1388
+				'REG_deleted' => 0,
1389
+				'STS_ID'      => EEM_Registration::status_id_approved,
1390
+			),
1391
+		);
1392
+		$not_approved_query_args = array(
1393
+			array(
1394
+				'REG_deleted' => 0,
1395
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1396
+			),
1397
+		);
1398
+		$pending_payment_query_args = array(
1399
+			array(
1400
+				'REG_deleted' => 0,
1401
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1402
+			),
1403
+		);
1404
+		// publish box
1405
+		$publish_box_extra_args = array(
1406
+			'view_approved_reg_url'        => add_query_arg(
1407
+				array(
1408
+					'action'      => 'default',
1409
+					'event_id'    => $this->_cpt_model_obj->ID(),
1410
+					'_reg_status' => EEM_Registration::status_id_approved,
1411
+				),
1412
+				REG_ADMIN_URL
1413
+			),
1414
+			'view_not_approved_reg_url'    => add_query_arg(
1415
+				array(
1416
+					'action'      => 'default',
1417
+					'event_id'    => $this->_cpt_model_obj->ID(),
1418
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1419
+				),
1420
+				REG_ADMIN_URL
1421
+			),
1422
+			'view_pending_payment_reg_url' => add_query_arg(
1423
+				array(
1424
+					'action'      => 'default',
1425
+					'event_id'    => $this->_cpt_model_obj->ID(),
1426
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1427
+				),
1428
+				REG_ADMIN_URL
1429
+			),
1430
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1431
+				'Registration',
1432
+				$approved_query_args
1433
+			),
1434
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1435
+				'Registration',
1436
+				$not_approved_query_args
1437
+			),
1438
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1439
+				'Registration',
1440
+				$pending_payment_query_args
1441
+			),
1442
+			'misc_pub_section_class'       => apply_filters(
1443
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1444
+				'misc-pub-section'
1445
+			),
1446
+			//'email_attendees_url' => add_query_arg(
1447
+			//	array(
1448
+			//		'event_admin_reports' => 'event_newsletter',
1449
+			//		'event_id' => $this->_cpt_model_obj->id
1450
+			//	),
1451
+			//	'admin.php?page=espresso_registrations'
1452
+			//),
1453
+		);
1454
+		ob_start();
1455
+		do_action(
1456
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1457
+			$this->_cpt_model_obj
1458
+		);
1459
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1460
+		// load template
1461
+		EEH_Template::display_template(
1462
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1463
+			$publish_box_extra_args
1464
+		);
1465
+	}
1466
+
1467
+
1468
+
1469
+	/**
1470
+	 * This just returns whatever is set as the _event object property
1471
+	 * //todo this will become obsolete once the models are in place
1472
+	 *
1473
+	 * @return object
1474
+	 */
1475
+	public function get_event_object()
1476
+	{
1477
+		return $this->_cpt_model_obj;
1478
+	}
1479
+
1480
+
1481
+
1482
+
1483
+	/** METABOXES * */
1484
+	/**
1485
+	 * _register_event_editor_meta_boxes
1486
+	 * add all metaboxes related to the event_editor
1487
+	 *
1488
+	 * @return void
1489
+	 */
1490
+	protected function _register_event_editor_meta_boxes()
1491
+	{
1492
+		$this->verify_cpt_object();
1493
+		add_meta_box(
1494
+			'espresso_event_editor_tickets',
1495
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1496
+			array($this, 'ticket_metabox'),
1497
+			$this->page_slug,
1498
+			'normal',
1499
+			'high'
1500
+		);
1501
+		add_meta_box(
1502
+			'espresso_event_editor_event_options',
1503
+			esc_html__('Event Registration Options', 'event_espresso'),
1504
+			array($this, 'registration_options_meta_box'),
1505
+			$this->page_slug,
1506
+			'side',
1507
+			'default'
1508
+		);
1509
+		// NOTE: if you're looking for other metaboxes in here,
1510
+		// where a metabox has a related management page in the admin
1511
+		// you will find it setup in the related management page's "_Hooks" file.
1512
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1513
+	}
1514
+
1515
+
1516
+
1517
+	public function ticket_metabox()
1518
+	{
1519
+		$existing_datetime_ids = $existing_ticket_ids = array();
1520
+		//defaults for template args
1521
+		$template_args = array(
1522
+			'existing_datetime_ids'    => '',
1523
+			'event_datetime_help_link' => '',
1524
+			'ticket_options_help_link' => '',
1525
+			'time'                     => null,
1526
+			'ticket_rows'              => '',
1527
+			'existing_ticket_ids'      => '',
1528
+			'total_ticket_rows'        => 1,
1529
+			'ticket_js_structure'      => '',
1530
+			'trash_icon'               => 'ee-lock-icon',
1531
+			'disabled'                 => '',
1532
+		);
1533
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1534
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1535
+		/**
1536
+		 * 1. Start with retrieving Datetimes
1537
+		 * 2. Fore each datetime get related tickets
1538
+		 * 3. For each ticket get related prices
1539
+		 */
1540
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1541
+		/** @type EE_Datetime $first_datetime */
1542
+		$first_datetime = reset($times);
1543
+		//do we get related tickets?
1544
+		if ($first_datetime instanceof EE_Datetime
1545
+			&& $first_datetime->ID() !== 0
1546
+		) {
1547
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1548
+			$template_args['time'] = $first_datetime;
1549
+			$related_tickets = $first_datetime->tickets(
1550
+				array(
1551
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1552
+					'default_where_conditions' => 'none',
1553
+				)
1554
+			);
1555
+			if ( ! empty($related_tickets)) {
1556
+				$template_args['total_ticket_rows'] = count($related_tickets);
1557
+				$row = 0;
1558
+				foreach ($related_tickets as $ticket) {
1559
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1560
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1561
+					$row++;
1562
+				}
1563
+			} else {
1564
+				$template_args['total_ticket_rows'] = 1;
1565
+				/** @type EE_Ticket $ticket */
1566
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1567
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1568
+			}
1569
+		} else {
1570
+			$template_args['time'] = $times[0];
1571
+			/** @type EE_Ticket $ticket */
1572
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1573
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1574
+			// NOTE: we're just sending the first default row
1575
+			// (decaf can't manage default tickets so this should be sufficient);
1576
+		}
1577
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1578
+			'event_editor_event_datetimes_help_tab'
1579
+		);
1580
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1581
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1582
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1583
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1584
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1585
+			true
1586
+		);
1587
+		$template = apply_filters(
1588
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1589
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1590
+		);
1591
+		EEH_Template::display_template($template, $template_args);
1592
+	}
1593
+
1594
+
1595
+
1596
+	/**
1597
+	 * Setup an individual ticket form for the decaf event editor page
1598
+	 *
1599
+	 * @access private
1600
+	 * @param  EE_Ticket $ticket   the ticket object
1601
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1602
+	 * @param int        $row
1603
+	 * @return string generated html for the ticket row.
1604
+	 */
1605
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1606
+	{
1607
+		$template_args = array(
1608
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1609
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1610
+				: '',
1611
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1612
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1613
+			'TKT_name'            => $ticket->get('TKT_name'),
1614
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1615
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1616
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1617
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1618
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1619
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1620
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1621
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1622
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1623
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1624
+				: ' disabled=disabled',
1625
+		);
1626
+		$price = $ticket->ID() !== 0
1627
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1628
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1629
+		$price_args = array(
1630
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1631
+			'PRC_amount'            => $price->get('PRC_amount'),
1632
+			'PRT_ID'                => $price->get('PRT_ID'),
1633
+			'PRC_ID'                => $price->get('PRC_ID'),
1634
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1635
+		);
1636
+		//make sure we have default start and end dates if skeleton
1637
+		//handle rows that should NOT be empty
1638
+		if (empty($template_args['TKT_start_date'])) {
1639
+			//if empty then the start date will be now.
1640
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1641
+		}
1642
+		if (empty($template_args['TKT_end_date'])) {
1643
+			//get the earliest datetime (if present);
1644
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1645
+				? $this->_cpt_model_obj->get_first_related(
1646
+					'Datetime',
1647
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1648
+				)
1649
+				: null;
1650
+			if ( ! empty($earliest_dtt)) {
1651
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1652
+			} else {
1653
+				$template_args['TKT_end_date'] = date(
1654
+					'Y-m-d h:i a',
1655
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1656
+				);
1657
+			}
1658
+		}
1659
+		$template_args = array_merge($template_args, $price_args);
1660
+		$template = apply_filters(
1661
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1662
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1663
+			$ticket
1664
+		);
1665
+		return EEH_Template::display_template($template, $template_args, true);
1666
+	}
1667
+
1668
+
1669
+
1670
+	public function registration_options_meta_box()
1671
+	{
1672
+		$yes_no_values = array(
1673
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1674
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1675
+		);
1676
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1677
+			array(
1678
+				EEM_Registration::status_id_cancelled,
1679
+				EEM_Registration::status_id_declined,
1680
+				EEM_Registration::status_id_incomplete,
1681
+			),
1682
+			true
1683
+		);
1684
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1685
+		$template_args['_event'] = $this->_cpt_model_obj;
1686
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1687
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1688
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1689
+			'default_reg_status',
1690
+			$default_reg_status_values,
1691
+			$this->_cpt_model_obj->default_registration_status()
1692
+		);
1693
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1694
+			'display_desc',
1695
+			$yes_no_values,
1696
+			$this->_cpt_model_obj->display_description()
1697
+		);
1698
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1699
+			'display_ticket_selector',
1700
+			$yes_no_values,
1701
+			$this->_cpt_model_obj->display_ticket_selector(),
1702
+			'',
1703
+			'',
1704
+			false
1705
+		);
1706
+		$template_args['additional_registration_options'] = apply_filters(
1707
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1708
+			'',
1709
+			$template_args,
1710
+			$yes_no_values,
1711
+			$default_reg_status_values
1712
+		);
1713
+		EEH_Template::display_template(
1714
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1715
+			$template_args
1716
+		);
1717
+	}
1718
+
1719
+
1720
+
1721
+	/**
1722
+	 * _get_events()
1723
+	 * This method simply returns all the events (for the given _view and paging)
1724
+	 *
1725
+	 * @access public
1726
+	 * @param int  $per_page     count of items per page (20 default);
1727
+	 * @param int  $current_page what is the current page being viewed.
1728
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1729
+	 *                           If FALSE then we return an array of event objects
1730
+	 *                           that match the given _view and paging parameters.
1731
+	 * @return array an array of event objects.
1732
+	 */
1733
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1734
+	{
1735
+		$EEME = $this->_event_model();
1736
+		$offset = ($current_page - 1) * $per_page;
1737
+		$limit = $count ? null : $offset . ',' . $per_page;
1738
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1739
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1740
+		if (isset($this->_req_data['month_range'])) {
1741
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1742
+			$month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1743
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1744
+		}
1745
+		$where = array();
1746
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1747
+		//determine what post_status our condition will have for the query.
1748
+		switch ($status) {
1749
+			case 'month' :
1750
+			case 'today' :
1751
+			case null :
1752
+			case 'all' :
1753
+				break;
1754
+			case 'draft' :
1755
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1756
+				break;
1757
+			default :
1758
+				$where['status'] = $status;
1759
+		}
1760
+		//categories?
1761
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1762
+			? $this->_req_data['EVT_CAT'] : null;
1763
+		if ( ! empty ($category)) {
1764
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1765
+			$where['Term_Taxonomy.term_id'] = $category;
1766
+		}
1767
+		//date where conditions
1768
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1769
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1770
+			$DateTime = new DateTime(
1771
+				$year_r . '-' . $month_r . '-01 00:00:00',
1772
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1773
+			);
1774
+			$start = $DateTime->format(implode(' ', $start_formats));
1775
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1776
+				->format('t'))->setTime(23, 59, 59)
1777
+							->format(implode(' ', $start_formats));
1778
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1779
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1780
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1781
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1782
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1783
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1784
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1785
+			$now = date('Y-m-01');
1786
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1787
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1788
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1789
+							->setTime(23, 59, 59)
1790
+							->format(implode(' ', $start_formats));
1791
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1792
+		}
1793
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1794
+			$where['EVT_wp_user'] = get_current_user_id();
1795
+		} else {
1796
+			if ( ! isset($where['status'])) {
1797
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1798
+					$where['OR'] = array(
1799
+						'status*restrict_private' => array('!=', 'private'),
1800
+						'AND'                     => array(
1801
+							'status*inclusive' => array('=', 'private'),
1802
+							'EVT_wp_user'      => get_current_user_id(),
1803
+						),
1804
+					);
1805
+				}
1806
+			}
1807
+		}
1808
+		if (isset($this->_req_data['EVT_wp_user'])) {
1809
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1810
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1811
+			) {
1812
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1813
+			}
1814
+		}
1815
+		//search query handling
1816
+		if (isset($this->_req_data['s'])) {
1817
+			$search_string = '%' . $this->_req_data['s'] . '%';
1818
+			$where['OR'] = array(
1819
+				'EVT_name'       => array('LIKE', $search_string),
1820
+				'EVT_desc'       => array('LIKE', $search_string),
1821
+				'EVT_short_desc' => array('LIKE', $search_string),
1822
+			);
1823
+		}
1824
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1825
+		$query_params = apply_filters(
1826
+			'FHEE__Events_Admin_Page__get_events__query_params',
1827
+			array(
1828
+				$where,
1829
+				'limit'    => $limit,
1830
+				'order_by' => $orderby,
1831
+				'order'    => $order,
1832
+				'group_by' => 'EVT_ID',
1833
+			),
1834
+			$this->_req_data
1835
+		);
1836
+		//let's first check if we have special requests coming in.
1837
+		if (isset($this->_req_data['active_status'])) {
1838
+			switch ($this->_req_data['active_status']) {
1839
+				case 'upcoming' :
1840
+					return $EEME->get_upcoming_events($query_params, $count);
1841
+					break;
1842
+				case 'expired' :
1843
+					return $EEME->get_expired_events($query_params, $count);
1844
+					break;
1845
+				case 'active' :
1846
+					return $EEME->get_active_events($query_params, $count);
1847
+					break;
1848
+				case 'inactive' :
1849
+					return $EEME->get_inactive_events($query_params, $count);
1850
+					break;
1851
+			}
1852
+		}
1853
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1854
+		return $events;
1855
+	}
1856
+
1857
+
1858
+
1859
+	/**
1860
+	 * handling for WordPress CPT actions (trash, restore, delete)
1861
+	 *
1862
+	 * @param string $post_id
1863
+	 */
1864
+	public function trash_cpt_item($post_id)
1865
+	{
1866
+		$this->_req_data['EVT_ID'] = $post_id;
1867
+		$this->_trash_or_restore_event('trash', false);
1868
+	}
1869
+
1870
+
1871
+
1872
+	/**
1873
+	 * @param string $post_id
1874
+	 */
1875
+	public function restore_cpt_item($post_id)
1876
+	{
1877
+		$this->_req_data['EVT_ID'] = $post_id;
1878
+		$this->_trash_or_restore_event('draft', false);
1879
+	}
1880
+
1881
+
1882
+
1883
+	/**
1884
+	 * @param string $post_id
1885
+	 */
1886
+	public function delete_cpt_item($post_id)
1887
+	{
1888
+		$this->_req_data['EVT_ID'] = $post_id;
1889
+		$this->_delete_event(false);
1890
+	}
1891
+
1892
+
1893
+
1894
+	/**
1895
+	 * _trash_or_restore_event
1896
+	 *
1897
+	 * @access protected
1898
+	 * @param  string $event_status
1899
+	 * @param bool    $redirect_after
1900
+	 */
1901
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1902
+	{
1903
+		//determine the event id and set to array.
1904
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1905
+		// loop thru events
1906
+		if ($EVT_ID) {
1907
+			// clean status
1908
+			$event_status = sanitize_key($event_status);
1909
+			// grab status
1910
+			if ( ! empty($event_status)) {
1911
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1912
+			} else {
1913
+				$success = false;
1914
+				$msg = esc_html__(
1915
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1916
+					'event_espresso'
1917
+				);
1918
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1919
+			}
1920
+		} else {
1921
+			$success = false;
1922
+			$msg = esc_html__(
1923
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1924
+				'event_espresso'
1925
+			);
1926
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1927
+		}
1928
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1929
+		if ($redirect_after) {
1930
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1931
+		}
1932
+	}
1933
+
1934
+
1935
+
1936
+	/**
1937
+	 * _trash_or_restore_events
1938
+	 *
1939
+	 * @access protected
1940
+	 * @param  string $event_status
1941
+	 * @return void
1942
+	 */
1943
+	protected function _trash_or_restore_events($event_status = 'trash')
1944
+	{
1945
+		// clean status
1946
+		$event_status = sanitize_key($event_status);
1947
+		// grab status
1948
+		if ( ! empty($event_status)) {
1949
+			$success = true;
1950
+			//determine the event id and set to array.
1951
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1952
+			// loop thru events
1953
+			foreach ($EVT_IDs as $EVT_ID) {
1954
+				if ($EVT_ID = absint($EVT_ID)) {
1955
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1956
+					$success = $results !== false ? $success : false;
1957
+				} else {
1958
+					$msg = sprintf(
1959
+						esc_html__(
1960
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1961
+							'event_espresso'
1962
+						),
1963
+						$EVT_ID
1964
+					);
1965
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1966
+					$success = false;
1967
+				}
1968
+			}
1969
+		} else {
1970
+			$success = false;
1971
+			$msg = esc_html__(
1972
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1973
+				'event_espresso'
1974
+			);
1975
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1976
+		}
1977
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1978
+		$success = $success ? 2 : false;
1979
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1980
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1981
+	}
1982
+
1983
+
1984
+
1985
+	/**
1986
+	 * _trash_or_restore_events
1987
+	 *
1988
+	 * @access  private
1989
+	 * @param  int    $EVT_ID
1990
+	 * @param  string $event_status
1991
+	 * @return bool
1992
+	 */
1993
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
1994
+	{
1995
+		// grab event id
1996
+		if ( ! $EVT_ID) {
1997
+			$msg = esc_html__(
1998
+				'An error occurred. No Event ID or an invalid Event ID was received.',
1999
+				'event_espresso'
2000
+			);
2001
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2002
+			return false;
2003
+		}
2004
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2005
+		// clean status
2006
+		$event_status = sanitize_key($event_status);
2007
+		// grab status
2008
+		if (empty($event_status)) {
2009
+			$msg = esc_html__(
2010
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2011
+				'event_espresso'
2012
+			);
2013
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2014
+			return false;
2015
+		}
2016
+		// was event trashed or restored ?
2017
+		switch ($event_status) {
2018
+			case 'draft' :
2019
+				$action = 'restored from the trash';
2020
+				$hook = 'AHEE_event_restored_from_trash';
2021
+				break;
2022
+			case 'trash' :
2023
+				$action = 'moved to the trash';
2024
+				$hook = 'AHEE_event_moved_to_trash';
2025
+				break;
2026
+			default :
2027
+				$action = 'updated';
2028
+				$hook = false;
2029
+		}
2030
+		//use class to change status
2031
+		$this->_cpt_model_obj->set_status($event_status);
2032
+		$success = $this->_cpt_model_obj->save();
2033
+		if ($success === false) {
2034
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2035
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2036
+			return false;
2037
+		}
2038
+		if ($hook) {
2039
+			do_action($hook);
2040
+		}
2041
+		return true;
2042
+	}
2043
+
2044
+
2045
+
2046
+	/**
2047
+	 * _delete_event
2048
+	 *
2049
+	 * @access protected
2050
+	 * @param bool $redirect_after
2051
+	 */
2052
+	protected function _delete_event($redirect_after = true)
2053
+	{
2054
+		//determine the event id and set to array.
2055
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2056
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2057
+		// loop thru events
2058
+		if ($EVT_ID) {
2059
+			$success = $this->_permanently_delete_event($EVT_ID);
2060
+			// get list of events with no prices
2061
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2062
+			// remove this event from the list of events with no prices
2063
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2064
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2065
+			}
2066
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2067
+		} else {
2068
+			$success = false;
2069
+			$msg = esc_html__(
2070
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2071
+				'event_espresso'
2072
+			);
2073
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2074
+		}
2075
+		if ($redirect_after) {
2076
+			$this->_redirect_after_action(
2077
+				$success,
2078
+				'Event',
2079
+				'deleted',
2080
+				array('action' => 'default', 'status' => 'trash')
2081
+			);
2082
+		}
2083
+	}
2084
+
2085
+
2086
+
2087
+	/**
2088
+	 * _delete_events
2089
+	 *
2090
+	 * @access protected
2091
+	 * @return void
2092
+	 */
2093
+	protected function _delete_events()
2094
+	{
2095
+		$success = true;
2096
+		// get list of events with no prices
2097
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2098
+		//determine the event id and set to array.
2099
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2100
+		// loop thru events
2101
+		foreach ($EVT_IDs as $EVT_ID) {
2102
+			$EVT_ID = absint($EVT_ID);
2103
+			if ($EVT_ID) {
2104
+				$results = $this->_permanently_delete_event($EVT_ID);
2105
+				$success = $results !== false ? $success : false;
2106
+				// remove this event from the list of events with no prices
2107
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2108
+			} else {
2109
+				$success = false;
2110
+				$msg = esc_html__(
2111
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2112
+					'event_espresso'
2113
+				);
2114
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2115
+			}
2116
+		}
2117
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2118
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2119
+		$success = $success ? 2 : false;
2120
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2121
+	}
2122
+
2123
+
2124
+
2125
+	/**
2126
+	 * _permanently_delete_event
2127
+	 *
2128
+	 * @access  private
2129
+	 * @param  int $EVT_ID
2130
+	 * @return bool
2131
+	 */
2132
+	private function _permanently_delete_event($EVT_ID = 0)
2133
+	{
2134
+		// grab event id
2135
+		if ( ! $EVT_ID) {
2136
+			$msg = esc_html__(
2137
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2138
+				'event_espresso'
2139
+			);
2140
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2141
+			return false;
2142
+		}
2143
+		if (
2144
+			! $this->_cpt_model_obj instanceof EE_Event
2145
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2146
+		) {
2147
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2148
+		}
2149
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2150
+			return false;
2151
+		}
2152
+		//need to delete related tickets and prices first.
2153
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2154
+		foreach ($datetimes as $datetime) {
2155
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2156
+			$tickets = $datetime->get_many_related('Ticket');
2157
+			foreach ($tickets as $ticket) {
2158
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2159
+				$ticket->delete_related_permanently('Price');
2160
+				$ticket->delete_permanently();
2161
+			}
2162
+			$datetime->delete();
2163
+		}
2164
+		//what about related venues or terms?
2165
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2166
+		foreach ($venues as $venue) {
2167
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2168
+		}
2169
+		//any attached question groups?
2170
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2171
+		if ( ! empty($question_groups)) {
2172
+			foreach ($question_groups as $question_group) {
2173
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2174
+			}
2175
+		}
2176
+		//Message Template Groups
2177
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2178
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2179
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2180
+		foreach ($term_taxonomies as $term_taxonomy) {
2181
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2182
+		}
2183
+		$success = $this->_cpt_model_obj->delete_permanently();
2184
+		// did it all go as planned ?
2185
+		if ($success) {
2186
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2187
+			EE_Error::add_success($msg);
2188
+		} else {
2189
+			$msg = sprintf(
2190
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2191
+				$EVT_ID
2192
+			);
2193
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2194
+			return false;
2195
+		}
2196
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2197
+		return true;
2198
+	}
2199
+
2200
+
2201
+
2202
+	/**
2203
+	 * get total number of events
2204
+	 *
2205
+	 * @access public
2206
+	 * @return int
2207
+	 */
2208
+	public function total_events()
2209
+	{
2210
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2211
+		return $count;
2212
+	}
2213
+
2214
+
2215
+
2216
+	/**
2217
+	 * get total number of draft events
2218
+	 *
2219
+	 * @access public
2220
+	 * @return int
2221
+	 */
2222
+	public function total_events_draft()
2223
+	{
2224
+		$where = array(
2225
+			'status' => array('IN', array('draft', 'auto-draft')),
2226
+		);
2227
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2228
+		return $count;
2229
+	}
2230
+
2231
+
2232
+
2233
+	/**
2234
+	 * get total number of trashed events
2235
+	 *
2236
+	 * @access public
2237
+	 * @return int
2238
+	 */
2239
+	public function total_trashed_events()
2240
+	{
2241
+		$where = array(
2242
+			'status' => 'trash',
2243
+		);
2244
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2245
+		return $count;
2246
+	}
2247
+
2248
+
2249
+
2250
+	/**
2251
+	 *    _default_event_settings
2252
+	 *    This generates the Default Settings Tab
2253
+	 *
2254
+	 * @return void
2255
+	 */
2256
+	protected function _default_event_settings()
2257
+	{
2258
+		$this->_template_args['values'] = $this->_yes_no_values;
2259
+		$this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2260
+		// exclude array
2261
+			array(
2262
+				EEM_Registration::status_id_cancelled,
2263
+				EEM_Registration::status_id_declined,
2264
+				EEM_Registration::status_id_incomplete,
2265
+				EEM_Registration::status_id_wait_list,
2266
+			),
2267
+			// translated
2268
+			true
2269
+		);
2270
+		$this->_template_args['default_reg_status'] = isset(
2271
+														  EE_Registry::instance()->CFG->registration->default_STS_ID
2272
+													  )
2273
+													  && array_key_exists(
2274
+														  EE_Registry::instance()->CFG->registration->default_STS_ID,
2275
+														  $this->_template_args['reg_status_array']
2276
+													  )
2277
+			? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2278
+			: EEM_Registration::status_id_pending_payment;
2279
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2280
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2281
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2282
+			EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2283
+			$this->_template_args,
2284
+			true
2285
+		);
2286
+		$this->display_admin_page_with_sidebar();
2287
+	}
2288
+
2289
+
2290
+
2291
+	/**
2292
+	 * _update_default_event_settings
2293
+	 *
2294
+	 * @access protected
2295
+	 * @return void
2296
+	 */
2297
+	protected function _update_default_event_settings()
2298
+	{
2299
+		EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2300
+			? sanitize_text_field($this->_req_data['default_reg_status'])
2301
+			: EEM_Registration::status_id_pending_payment;
2302
+		$what = 'Default Event Settings';
2303
+		$success = $this->_update_espresso_configuration(
2304
+			$what,
2305
+			EE_Config::instance(),
2306
+			__FILE__,
2307
+			__FUNCTION__,
2308
+			__LINE__
2309
+		);
2310
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2311
+	}
2312
+
2313
+
2314
+
2315
+	/*************        Templates        *************/
2316
+	protected function _template_settings()
2317
+	{
2318
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2319
+		$this->_template_args['preview_img'] = '<img src="'
2320
+											   . EVENTS_ASSETS_URL
2321
+											   . DS
2322
+											   . 'images'
2323
+											   . DS
2324
+											   . 'caffeinated_template_features.jpg" alt="'
2325
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2326
+											   . '" />';
2327
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2328
+				'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2329
+				'event_espresso'
2330
+			) . '</strong>';
2331
+		$this->display_admin_caf_preview_page('template_settings_tab');
2332
+	}
2333
+
2334
+
2335
+	/** Event Category Stuff **/
2336
+	/**
2337
+	 * set the _category property with the category object for the loaded page.
2338
+	 *
2339
+	 * @access private
2340
+	 * @return void
2341
+	 */
2342
+	private function _set_category_object()
2343
+	{
2344
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2345
+			return;
2346
+		} //already have the category object so get out.
2347
+		//set default category object
2348
+		$this->_set_empty_category_object();
2349
+		//only set if we've got an id
2350
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2351
+			return;
2352
+		}
2353
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2354
+		$term = get_term($category_id, 'espresso_event_categories');
2355
+		if ( ! empty($term)) {
2356
+			$this->_category->category_name = $term->name;
2357
+			$this->_category->category_identifier = $term->slug;
2358
+			$this->_category->category_desc = $term->description;
2359
+			$this->_category->id = $term->term_id;
2360
+			$this->_category->parent = $term->parent;
2361
+		}
2362
+	}
2363
+
2364
+
2365
+
2366
+	private function _set_empty_category_object()
2367
+	{
2368
+		$this->_category = new stdClass();
2369
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2370
+		$this->_category->id = $this->_category->parent = 0;
2371
+	}
2372
+
2373
+
2374
+
2375
+	protected function _category_list_table()
2376
+	{
2377
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2378
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2379
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2380
+				'add_category',
2381
+				'add_category',
2382
+				array(),
2383
+				'add-new-h2'
2384
+			);
2385
+		$this->display_admin_list_table_page_with_sidebar();
2386
+	}
2387
+
2388
+
2389
+
2390
+	/**
2391
+	 * @param $view
2392
+	 */
2393
+	protected function _category_details($view)
2394
+	{
2395
+		//load formatter helper
2396
+		//load field generator helper
2397
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2398
+		$this->_set_add_edit_form_tags($route);
2399
+		$this->_set_category_object();
2400
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2401
+		$delete_action = 'delete_category';
2402
+		//custom redirect
2403
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2404
+			array('action' => 'category_list'),
2405
+			$this->_admin_base_url
2406
+		);
2407
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2408
+		//take care of contents
2409
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2410
+		$this->display_admin_page_with_sidebar();
2411
+	}
2412
+
2413
+
2414
+
2415
+	/**
2416
+	 * @return mixed
2417
+	 */
2418
+	protected function _category_details_content()
2419
+	{
2420
+		$editor_args['category_desc'] = array(
2421
+			'type'          => 'wp_editor',
2422
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2423
+			'class'         => 'my_editor_custom',
2424
+			'wpeditor_args' => array('media_buttons' => false),
2425
+		);
2426
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2427
+		$all_terms = get_terms(
2428
+			array('espresso_event_categories'),
2429
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2430
+		);
2431
+		//setup category select for term parents.
2432
+		$category_select_values[] = array(
2433
+			'text' => esc_html__('No Parent', 'event_espresso'),
2434
+			'id'   => 0,
2435
+		);
2436
+		foreach ($all_terms as $term) {
2437
+			$category_select_values[] = array(
2438
+				'text' => $term->name,
2439
+				'id'   => $term->term_id,
2440
+			);
2441
+		}
2442
+		$category_select = EEH_Form_Fields::select_input(
2443
+			'category_parent',
2444
+			$category_select_values,
2445
+			$this->_category->parent
2446
+		);
2447
+		$template_args = array(
2448
+			'category'                 => $this->_category,
2449
+			'category_select'          => $category_select,
2450
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2451
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2452
+			'disable'                  => '',
2453
+			'disabled_message'         => false,
2454
+		);
2455
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2456
+		return EEH_Template::display_template($template, $template_args, true);
2457
+	}
2458
+
2459
+
2460
+
2461
+	protected function _delete_categories()
2462
+	{
2463
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2464
+			: (array)$this->_req_data['category_id'];
2465
+		foreach ($cat_ids as $cat_id) {
2466
+			$this->_delete_category($cat_id);
2467
+		}
2468
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2469
+		$query_args = array(
2470
+			'action' => 'category_list',
2471
+		);
2472
+		$this->_redirect_after_action(0, '', '', $query_args);
2473
+	}
2474
+
2475
+
2476
+
2477
+	/**
2478
+	 * @param $cat_id
2479
+	 */
2480
+	protected function _delete_category($cat_id)
2481
+	{
2482
+		$cat_id = absint($cat_id);
2483
+		wp_delete_term($cat_id, 'espresso_event_categories');
2484
+	}
2485
+
2486
+
2487
+
2488
+	/**
2489
+	 * @param $new_category
2490
+	 */
2491
+	protected function _insert_or_update_category($new_category)
2492
+	{
2493
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2494
+		$success = 0; //we already have a success message so lets not send another.
2495
+		if ($cat_id) {
2496
+			$query_args = array(
2497
+				'action'     => 'edit_category',
2498
+				'EVT_CAT_ID' => $cat_id,
2499
+			);
2500
+		} else {
2501
+			$query_args = array('action' => 'add_category');
2502
+		}
2503
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2504
+	}
2505
+
2506
+
2507
+
2508
+	/**
2509
+	 * @param bool $update
2510
+	 * @return bool|mixed|string
2511
+	 */
2512
+	private function _insert_category($update = false)
2513
+	{
2514
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2515
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2516
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2517
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2518
+		if (empty($category_name)) {
2519
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2520
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2521
+			return false;
2522
+		}
2523
+		$term_args = array(
2524
+			'name'        => $category_name,
2525
+			'description' => $category_desc,
2526
+			'parent'      => $category_parent,
2527
+		);
2528
+		//was the category_identifier input disabled?
2529
+		if (isset($this->_req_data['category_identifier'])) {
2530
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2531
+		}
2532
+		$insert_ids = $update
2533
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2534
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2535
+		if ( ! is_array($insert_ids)) {
2536
+			$msg = esc_html__(
2537
+				'An error occurred and the category has not been saved to the database.',
2538
+				'event_espresso'
2539
+			);
2540
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2541
+		} else {
2542
+			$cat_id = $insert_ids['term_id'];
2543
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2544
+			EE_Error::add_success($msg);
2545
+		}
2546
+		return $cat_id;
2547
+	}
2548
+
2549
+
2550
+
2551
+	/**
2552
+	 * @param int  $per_page
2553
+	 * @param int  $current_page
2554
+	 * @param bool $count
2555
+	 * @return \EE_Base_Class[]|int
2556
+	 */
2557
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2558
+	{
2559
+		//testing term stuff
2560
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2561
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2562
+		$limit = ($current_page - 1) * $per_page;
2563
+		$where = array('taxonomy' => 'espresso_event_categories');
2564
+		if (isset($this->_req_data['s'])) {
2565
+			$sstr = '%' . $this->_req_data['s'] . '%';
2566
+			$where['OR'] = array(
2567
+				'Term.name'   => array('LIKE', $sstr),
2568
+				'description' => array('LIKE', $sstr),
2569
+			);
2570
+		}
2571
+		$query_params = array(
2572
+			$where,
2573
+			'order_by'   => array($orderby => $order),
2574
+			'limit'      => $limit . ',' . $per_page,
2575
+			'force_join' => array('Term'),
2576
+		);
2577
+		$categories = $count
2578
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2579
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2580
+		return $categories;
2581
+	}
2582
+
2583
+
2584
+
2585
+	/* end category stuff */
2586
+	/**************/
2587 2587
 }
2588 2588
 //end class Events_Admin_Page
Please login to merge, or discard this patch.
form_sections/inputs/EE_Checkbox_Dropdown_Selector_Input.input.php 2 patches
Indentation   +36 added lines, -36 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
 
@@ -17,43 +17,43 @@  discard block
 block discarded – undo
17 17
 class EE_Checkbox_Dropdown_Selector_Input extends EE_Form_Input_With_Options_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var string text to display on the select button itself
22
-     */
23
-    protected $_select_button_text;
24
-
25
-    /**
26
-     * @param array $answer_options
27
-     * @param array $input_settings
28
-     */
29
-    public function __construct($answer_options, $input_settings = array())
30
-    {
31
-        $this->_select_button_text = EEH_Array::is_set( $input_settings, 'select_button_text',
32
-            esc_html__('Select', 'event_espresso'));
33
-        $this->_set_display_strategy(
34
-            new EE_Checkbox_Dropdown_Selector_Display_Strategy()
35
-        );
36
-        $this->_add_validation_strategy(
37
-            new EE_Many_Valued_Validation_Strategy(
38
-                array(
39
-                    new EE_Enum_Validation_Strategy(
40
-                        isset($input_settings['validation_error_message'])
41
-                            ? $input_settings['validation_error_message']
42
-                            : null
43
-                    ),
44
-                )
45
-            )
46
-        );
47
-        $this->_multiple_selections = true;
48
-        parent::__construct($answer_options, $input_settings);
49
-    }
50
-
51
-    /*
20
+	/**
21
+	 * @var string text to display on the select button itself
22
+	 */
23
+	protected $_select_button_text;
24
+
25
+	/**
26
+	 * @param array $answer_options
27
+	 * @param array $input_settings
28
+	 */
29
+	public function __construct($answer_options, $input_settings = array())
30
+	{
31
+		$this->_select_button_text = EEH_Array::is_set( $input_settings, 'select_button_text',
32
+			esc_html__('Select', 'event_espresso'));
33
+		$this->_set_display_strategy(
34
+			new EE_Checkbox_Dropdown_Selector_Display_Strategy()
35
+		);
36
+		$this->_add_validation_strategy(
37
+			new EE_Many_Valued_Validation_Strategy(
38
+				array(
39
+					new EE_Enum_Validation_Strategy(
40
+						isset($input_settings['validation_error_message'])
41
+							? $input_settings['validation_error_message']
42
+							: null
43
+					),
44
+				)
45
+			)
46
+		);
47
+		$this->_multiple_selections = true;
48
+		parent::__construct($answer_options, $input_settings);
49
+	}
50
+
51
+	/*
52 52
      * Returns the text to display in the select button
53 53
      */
54
-    public function select_button_text(){
55
-        return $this->_select_button_text;
56
-    }
54
+	public function select_button_text(){
55
+		return $this->_select_button_text;
56
+	}
57 57
 
58 58
 
59 59
 }
60 60
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public function __construct($answer_options, $input_settings = array())
30 30
     {
31
-        $this->_select_button_text = EEH_Array::is_set( $input_settings, 'select_button_text',
31
+        $this->_select_button_text = EEH_Array::is_set($input_settings, 'select_button_text',
32 32
             esc_html__('Select', 'event_espresso'));
33 33
         $this->_set_display_strategy(
34 34
             new EE_Checkbox_Dropdown_Selector_Display_Strategy()
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     /*
52 52
      * Returns the text to display in the select button
53 53
      */
54
-    public function select_button_text(){
54
+    public function select_button_text() {
55 55
         return $this->_select_button_text;
56 56
     }
57 57
 
Please login to merge, or discard this patch.
display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php 2 patches
Indentation   +111 added lines, -111 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
 
@@ -17,121 +17,121 @@  discard block
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * enqueues css and js, so that this can be called statically
22
-     */
23
-    public static function enqueue_styles_and_scripts()
24
-    {
25
-        wp_register_style(
26
-            'checkbox_dropdown_selector',
27
-            EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
28
-            array('espresso_default'),
29
-            EVENT_ESPRESSO_VERSION
30
-        );
31
-        wp_enqueue_style('checkbox_dropdown_selector');
32
-        wp_register_script(
33
-            'checkbox_dropdown_selector',
34
-            EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
35
-            array('jquery'),
36
-            EVENT_ESPRESSO_VERSION,
37
-            true
38
-        );
39
-        wp_enqueue_script('checkbox_dropdown_selector');
40
-    }
20
+	/**
21
+	 * enqueues css and js, so that this can be called statically
22
+	 */
23
+	public static function enqueue_styles_and_scripts()
24
+	{
25
+		wp_register_style(
26
+			'checkbox_dropdown_selector',
27
+			EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
28
+			array('espresso_default'),
29
+			EVENT_ESPRESSO_VERSION
30
+		);
31
+		wp_enqueue_style('checkbox_dropdown_selector');
32
+		wp_register_script(
33
+			'checkbox_dropdown_selector',
34
+			EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
35
+			array('jquery'),
36
+			EVENT_ESPRESSO_VERSION,
37
+			true
38
+		);
39
+		wp_enqueue_script('checkbox_dropdown_selector');
40
+	}
41 41
 
42 42
 
43 43
 
44
-    /**
45
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
46
-     */
47
-    public function enqueue_js(){
48
-        EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
49
-    }
44
+	/**
45
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
46
+	 */
47
+	public function enqueue_js(){
48
+		EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * @throws EE_Error
54
-     * @return string of html to display the field
55
-     */
56
-    public function display()
57
-    {
58
-        $input = $this->get_input();
59
-        $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : '';
60
-        // $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
61
-        $input->set_label_sizes();
62
-        $label_size_class = $input->get_label_size_class();
63
-        if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) {
64
-            EE_Error::doing_it_wrong(
65
-                'EE_Checkbox_Display_Strategy::display()',
66
-                sprintf(
67
-                    esc_html__(
68
-                        'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"',
69
-                        'event_espresso'
70
-                    ),
71
-                    $input->html_id(),
72
-                    var_export($input->raw_value(), true),
73
-                    $input->html_name() . '[]'
74
-                ),
75
-                '4.8.1'
76
-            );
77
-        }
78
-        $html = '<button type="submit"';
79
-        $html .= ' id="' . $input->html_id() . '-btn"';
80
-        // $html .= ' name="' . $input->html_name() . '"';
81
-        $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
82
-        $html .= ' style="' . $input->html_style() . '"';
83
-        $html .= ' data-target="' . $input->html_id() . '-options-dv"';
84
-        $html .= ' ' . $input->html_other_attributes() . '>';
85
-        $html .= '<span class="checkbox-dropdown-selector-selected-spn">';
86
-        $html .= $select_button_text;
87
-        $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
88
-        $html .= '</button>';
89
-        $html .= EEH_HTML::div(
90
-            '',
91
-            $input->html_id() . '-options-dv',
92
-            'checkbox-dropdown-selector'
93
-        );
94
-        $html .= EEH_HTML::link(
95
-            '',
96
-            '<span class="dashicons dashicons-no"></span>',
97
-            esc_html__('close datetime selector', 'event_espresso'),
98
-            '',
99
-            'close-espresso-notice'
100
-        );
101
-        $html .= EEH_HTML::ul();
102
-        $input_raw_value = (array)$input->raw_value();
103
-        foreach ($input->options() as $value => $display_text) {
104
-            $html .= EEH_HTML::li();
105
-            $value = $input->get_normalization_strategy()->unnormalize_one($value);
106
-            $html_id = $this->get_sub_input_id($value);
107
-            $html .= EEH_HTML::nl(0, 'checkbox');
108
-            $html .= '<label for="'
109
-                     . $html_id
110
-                     . '" id="'
111
-                     . $html_id
112
-                     . '-lbl" class="ee-checkbox-label-after'
113
-                     . $label_size_class
114
-                     . '">';
115
-            $html .= EEH_HTML::nl(1, 'checkbox');
116
-            $html .= '<input type="checkbox"';
117
-            $html .= ' name="' . $input->html_name() . '[]"';
118
-            $html .= ' id="' . $html_id . '"';
119
-            $html .= ' class="' . $input->html_class() . '-option"';
120
-            $html .= ' style="' . $input->html_style() . '"';
121
-            $html .= ' value="' . esc_attr($value) . '"';
122
-            $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
123
-                ? ' checked="checked"'
124
-                : '';
125
-            $html .= ' ' . $this->_input->other_html_attributes();
126
-            $html .= '>&nbsp;';
127
-            $html .= $display_text;
128
-            $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
129
-            $html .= EEH_HTML::lix();
130
-        }
131
-        $html .= EEH_HTML::ulx();
132
-        $html .= EEH_HTML::divx();
133
-        return $html;
134
-    }
52
+	/**
53
+	 * @throws EE_Error
54
+	 * @return string of html to display the field
55
+	 */
56
+	public function display()
57
+	{
58
+		$input = $this->get_input();
59
+		$select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : '';
60
+		// $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
61
+		$input->set_label_sizes();
62
+		$label_size_class = $input->get_label_size_class();
63
+		if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) {
64
+			EE_Error::doing_it_wrong(
65
+				'EE_Checkbox_Display_Strategy::display()',
66
+				sprintf(
67
+					esc_html__(
68
+						'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"',
69
+						'event_espresso'
70
+					),
71
+					$input->html_id(),
72
+					var_export($input->raw_value(), true),
73
+					$input->html_name() . '[]'
74
+				),
75
+				'4.8.1'
76
+			);
77
+		}
78
+		$html = '<button type="submit"';
79
+		$html .= ' id="' . $input->html_id() . '-btn"';
80
+		// $html .= ' name="' . $input->html_name() . '"';
81
+		$html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
82
+		$html .= ' style="' . $input->html_style() . '"';
83
+		$html .= ' data-target="' . $input->html_id() . '-options-dv"';
84
+		$html .= ' ' . $input->html_other_attributes() . '>';
85
+		$html .= '<span class="checkbox-dropdown-selector-selected-spn">';
86
+		$html .= $select_button_text;
87
+		$html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
88
+		$html .= '</button>';
89
+		$html .= EEH_HTML::div(
90
+			'',
91
+			$input->html_id() . '-options-dv',
92
+			'checkbox-dropdown-selector'
93
+		);
94
+		$html .= EEH_HTML::link(
95
+			'',
96
+			'<span class="dashicons dashicons-no"></span>',
97
+			esc_html__('close datetime selector', 'event_espresso'),
98
+			'',
99
+			'close-espresso-notice'
100
+		);
101
+		$html .= EEH_HTML::ul();
102
+		$input_raw_value = (array)$input->raw_value();
103
+		foreach ($input->options() as $value => $display_text) {
104
+			$html .= EEH_HTML::li();
105
+			$value = $input->get_normalization_strategy()->unnormalize_one($value);
106
+			$html_id = $this->get_sub_input_id($value);
107
+			$html .= EEH_HTML::nl(0, 'checkbox');
108
+			$html .= '<label for="'
109
+					 . $html_id
110
+					 . '" id="'
111
+					 . $html_id
112
+					 . '-lbl" class="ee-checkbox-label-after'
113
+					 . $label_size_class
114
+					 . '">';
115
+			$html .= EEH_HTML::nl(1, 'checkbox');
116
+			$html .= '<input type="checkbox"';
117
+			$html .= ' name="' . $input->html_name() . '[]"';
118
+			$html .= ' id="' . $html_id . '"';
119
+			$html .= ' class="' . $input->html_class() . '-option"';
120
+			$html .= ' style="' . $input->html_style() . '"';
121
+			$html .= ' value="' . esc_attr($value) . '"';
122
+			$html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
123
+				? ' checked="checked"'
124
+				: '';
125
+			$html .= ' ' . $this->_input->other_html_attributes();
126
+			$html .= '>&nbsp;';
127
+			$html .= $display_text;
128
+			$html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
129
+			$html .= EEH_HTML::lix();
130
+		}
131
+		$html .= EEH_HTML::ulx();
132
+		$html .= EEH_HTML::divx();
133
+		return $html;
134
+	}
135 135
 
136 136
 
137 137
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
     {
25 25
         wp_register_style(
26 26
             'checkbox_dropdown_selector',
27
-            EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
27
+            EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css',
28 28
             array('espresso_default'),
29 29
             EVENT_ESPRESSO_VERSION
30 30
         );
31 31
         wp_enqueue_style('checkbox_dropdown_selector');
32 32
         wp_register_script(
33 33
             'checkbox_dropdown_selector',
34
-            EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
34
+            EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js',
35 35
             array('jquery'),
36 36
             EVENT_ESPRESSO_VERSION,
37 37
             true
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     /**
45 45
      * Informs the rest of the forms system what CSS and JS is needed to display the input
46 46
      */
47
-    public function enqueue_js(){
47
+    public function enqueue_js() {
48 48
         EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
49 49
     }
50 50
 
@@ -70,25 +70,25 @@  discard block
 block discarded – undo
70 70
                     ),
71 71
                     $input->html_id(),
72 72
                     var_export($input->raw_value(), true),
73
-                    $input->html_name() . '[]'
73
+                    $input->html_name().'[]'
74 74
                 ),
75 75
                 '4.8.1'
76 76
             );
77 77
         }
78 78
         $html = '<button type="submit"';
79
-        $html .= ' id="' . $input->html_id() . '-btn"';
79
+        $html .= ' id="'.$input->html_id().'-btn"';
80 80
         // $html .= ' name="' . $input->html_name() . '"';
81
-        $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
82
-        $html .= ' style="' . $input->html_style() . '"';
83
-        $html .= ' data-target="' . $input->html_id() . '-options-dv"';
84
-        $html .= ' ' . $input->html_other_attributes() . '>';
81
+        $html .= ' class="'.$input->html_class().' checkbox-dropdown-selector-btn button-secondary button"';
82
+        $html .= ' style="'.$input->html_style().'"';
83
+        $html .= ' data-target="'.$input->html_id().'-options-dv"';
84
+        $html .= ' '.$input->html_other_attributes().'>';
85 85
         $html .= '<span class="checkbox-dropdown-selector-selected-spn">';
86 86
         $html .= $select_button_text;
87 87
         $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
88 88
         $html .= '</button>';
89 89
         $html .= EEH_HTML::div(
90 90
             '',
91
-            $input->html_id() . '-options-dv',
91
+            $input->html_id().'-options-dv',
92 92
             'checkbox-dropdown-selector'
93 93
         );
94 94
         $html .= EEH_HTML::link(
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             'close-espresso-notice'
100 100
         );
101 101
         $html .= EEH_HTML::ul();
102
-        $input_raw_value = (array)$input->raw_value();
102
+        $input_raw_value = (array) $input->raw_value();
103 103
         foreach ($input->options() as $value => $display_text) {
104 104
             $html .= EEH_HTML::li();
105 105
             $value = $input->get_normalization_strategy()->unnormalize_one($value);
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
                      . '">';
115 115
             $html .= EEH_HTML::nl(1, 'checkbox');
116 116
             $html .= '<input type="checkbox"';
117
-            $html .= ' name="' . $input->html_name() . '[]"';
118
-            $html .= ' id="' . $html_id . '"';
119
-            $html .= ' class="' . $input->html_class() . '-option"';
120
-            $html .= ' style="' . $input->html_style() . '"';
121
-            $html .= ' value="' . esc_attr($value) . '"';
117
+            $html .= ' name="'.$input->html_name().'[]"';
118
+            $html .= ' id="'.$html_id.'"';
119
+            $html .= ' class="'.$input->html_class().'-option"';
120
+            $html .= ' style="'.$input->html_style().'"';
121
+            $html .= ' value="'.esc_attr($value).'"';
122 122
             $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
123 123
                 ? ' checked="checked"'
124 124
                 : '';
125
-            $html .= ' ' . $this->_input->other_html_attributes();
125
+            $html .= ' '.$this->_input->other_html_attributes();
126 126
             $html .= '>&nbsp;';
127 127
             $html .= $display_text;
128
-            $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
128
+            $html .= EEH_HTML::nl(-1, 'checkbox').'</label>';
129 129
             $html .= EEH_HTML::lix();
130 130
         }
131 131
         $html .= EEH_HTML::ulx();
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.041');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.041');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
Please login to merge, or discard this patch.