Completed
Branch FET-10486-add-timestamp-checki... (786b14)
by
unknown
79:06 queued 65:28
created
4_6_0_stages/EE_DMS_4_6_0_question_types.dmsstage.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 */
27 27
 	public function __construct() {
28 28
 		global $wpdb;
29
-		$this->_pretty_name = __( 'Question Types', 'event_espresso' );
29
+		$this->_pretty_name = __('Question Types', 'event_espresso');
30 30
 		$this->_old_table = $wpdb->prefix.'esp_question';
31 31
 		$this->_question_type_conversions = array(
32 32
 			'MULTIPLE' 			=> 'CHECKBOX',
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 		//when fetching rows, because we automatically use a limit and offset
36 36
 		//rows counted before migrating any rows, need to ALSO be counted after a bunch of rows were counted
37 37
 		//so we need to include both the migrated rows as well as the non-migrated rows
38
-		$QST_types_to_count = array_merge( array_keys( $this->_question_type_conversions ), $this->_question_type_conversions );
39
-		$this->_extra_where_sql = "WHERE QST_type IN ('" . implode( "', '", $QST_types_to_count ) . "')" ;
38
+		$QST_types_to_count = array_merge(array_keys($this->_question_type_conversions), $this->_question_type_conversions);
39
+		$this->_extra_where_sql = "WHERE QST_type IN ('".implode("', '", $QST_types_to_count)."')";
40 40
 		parent::__construct();
41 41
 	}
42 42
 
@@ -44,21 +44,21 @@  discard block
 block discarded – undo
44 44
 	 * @param array $question an associative array where keys are column names and values are their values.
45 45
 	 * @return null
46 46
 	 */
47
-	protected function _migrate_old_row( $question ) {
47
+	protected function _migrate_old_row($question) {
48 48
 		global $wpdb;
49
-		if ( $question['QST_ID'] && isset( $this->_question_type_conversions[ $question['QST_type'] ] )) {
49
+		if ($question['QST_ID'] && isset($this->_question_type_conversions[$question['QST_type']])) {
50 50
 			$success = $wpdb->update(
51 51
 				$this->_old_table,
52
-				array( 'QST_type' => $this->_question_type_conversions[ $question['QST_type'] ] ), 	// data
53
-				array( 'QST_ID' => $question['QST_ID'] ),  // where
54
-				array( '%s' ),   // data format
55
-				array( '%d' )  // where format
52
+				array('QST_type' => $this->_question_type_conversions[$question['QST_type']]), // data
53
+				array('QST_ID' => $question['QST_ID']), // where
54
+				array('%s'), // data format
55
+				array('%d')  // where format
56 56
 			);
57
-			if ( ! $success ) {
57
+			if ( ! $success) {
58 58
 				$this->add_error(
59 59
 					sprintf(
60
-						__( 'Could not update question type %1$s for question ID=%2$d because "%3$s"', 'event_espresso' ),
61
-						wp_json_encode( $question['QST_type'] ),
60
+						__('Could not update question type %1$s for question ID=%2$d because "%3$s"', 'event_espresso'),
61
+						wp_json_encode($question['QST_type']),
62 62
 						$question['QST_ID'],
63 63
 						$wpdb->last_error
64 64
 					)
Please login to merge, or discard this patch.
4_6_0_stages/EE_DMS_4_6_0_country_system_question.dmsstage.php 1 patch
Spacing   +12 added lines, -12 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
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @author				Brent Christensen
14 14
  *
15 15
  */
16
-class EE_DMS_4_6_0_country_system_question extends EE_Data_Migration_Script_Stage_Table{
16
+class EE_DMS_4_6_0_country_system_question extends EE_Data_Migration_Script_Stage_Table {
17 17
 
18 18
 
19 19
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct() {
26 26
 		global $wpdb;
27
-		$this->_pretty_name = __( 'Country - System Question', 'event_espresso' );
27
+		$this->_pretty_name = __('Country - System Question', 'event_espresso');
28 28
 		$this->_old_table = $wpdb->prefix.'esp_question';
29 29
 		$this->_extra_where_sql = "WHERE QST_system = 'country'";
30 30
 		parent::__construct();
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 	 * @param array $question an associative array where keys are column names and values are their values.
38 38
 	 * @return null
39 39
 	 */
40
-	protected function _migrate_old_row( $question ) {
41
-		if ( $question['QST_ID'] && $question['QST_system'] == 'country' ) {
40
+	protected function _migrate_old_row($question) {
41
+		if ($question['QST_ID'] && $question['QST_system'] == 'country') {
42 42
 			global $wpdb;
43 43
 			$success = $wpdb->update(
44 44
 				$this->_old_table,
45
-				array( 'QST_type' => 'COUNTRY' ),  // data
46
-				array( 'QST_ID' => $question['QST_ID'] ),  // where
47
-				array( '%s' ),   // data format
48
-				array( '%d' )  // where format
45
+				array('QST_type' => 'COUNTRY'), // data
46
+				array('QST_ID' => $question['QST_ID']), // where
47
+				array('%s'), // data format
48
+				array('%d')  // where format
49 49
 			);
50
-			if ( ! $success ) {
50
+			if ( ! $success) {
51 51
 				$this->add_error(
52 52
 					sprintf(
53
-						__( 'Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso' ),
54
-						wp_json_encode( $question['QST_system'] ),
53
+						__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
54
+						wp_json_encode($question['QST_system']),
55 55
 						$question['QST_ID'],
56 56
 						$wpdb->last_error
57 57
 					)
Please login to merge, or discard this patch.
core/data_migration_scripts/4_6_0_stages/EE_DMS_4_6_0_gateways.dmsstage.php 2 patches
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
 	exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * Migrates 4.1-4.5-style gateway settings (which were stores in EE_Config)
15 15
  * to 4.6-style payment methods (which have their database table)
16 16
  */
17
-class EE_DMS_4_6_0_gateways extends EE_Data_Migration_Script_Stage{
17
+class EE_DMS_4_6_0_gateways extends EE_Data_Migration_Script_Stage {
18 18
 
19 19
 	protected $_new_table_name;
20 20
 	protected $_extra_meta_table_name;
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	protected function _migration_step($num_items_to_migrate = 50) {
75 75
 		$items_actually_migrated = 0;
76
-		$gateways_to_deal_with = array_slice(EE_Config::instance()->gateway->payment_settings,$this->count_records_migrated(),$num_items_to_migrate);
77
-		foreach($gateways_to_deal_with as $old_gateway_slug => $old_gateway_settings){
76
+		$gateways_to_deal_with = array_slice(EE_Config::instance()->gateway->payment_settings, $this->count_records_migrated(), $num_items_to_migrate);
77
+		foreach ($gateways_to_deal_with as $old_gateway_slug => $old_gateway_settings) {
78 78
 
79
-			if( in_array( $old_gateway_slug, $this->_gateway_we_know_to_migrate ) ) {
80
-				if( ! $old_gateway_settings){
79
+			if (in_array($old_gateway_slug, $this->_gateway_we_know_to_migrate)) {
80
+				if ( ! $old_gateway_settings) {
81 81
 					//no settings existed for this gateway anyways... weird...
82 82
 					$items_actually_migrated++;
83 83
 					continue;
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
 				$success = $this->_convert_gateway_settings(
87 87
 						$old_gateway_slug,
88 88
 						$old_gateway_settings,
89
-						isset( EE_Config::instance()->gateway->active_gateways[ $old_gateway_slug ] ) );
90
-				if( $success ) {
91
-					EE_Config::instance()->gateway->payment_settings[ $old_gateway_slug ] = 'Deprecated';
89
+						isset(EE_Config::instance()->gateway->active_gateways[$old_gateway_slug]) );
90
+				if ($success) {
91
+					EE_Config::instance()->gateway->payment_settings[$old_gateway_slug] = 'Deprecated';
92 92
 				}
93 93
 			}
94 94
 			$items_actually_migrated++;
95 95
 		}
96 96
 
97
-		EE_Config::instance()->update_espresso_config(false,false);
98
-		if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){
97
+		EE_Config::instance()->update_espresso_config(false, false);
98
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
99 99
 			$this->set_completed();
100 100
 		}
101 101
 		return $items_actually_migrated;
@@ -108,22 +108,22 @@  discard block
 block discarded – undo
108 108
 	 * @param boolean $active indicates the gateway is currently active
109 109
 	 * @return boolean success
110 110
 	 */
111
-	protected function _convert_gateway_settings($old_gateway_slug,$old_gateway_settings,$active){
112
-		switch($old_gateway_slug){
111
+	protected function _convert_gateway_settings($old_gateway_slug, $old_gateway_settings, $active) {
112
+		switch ($old_gateway_slug) {
113 113
 			case 'Aim':
114 114
 				$extra_meta_key_values = array(
115 115
 					'login_id'=>$old_gateway_settings['authnet_aim_login_id'],
116 116
 					'transaction_key'=>$old_gateway_settings['authnet_aim_transaction_key'],
117 117
 					'test_transactions'=>$old_gateway_settings['test_transactions']
118 118
 				);
119
-				$desc = __( 'Please provide the following billing information.', 'event_espresso' );
119
+				$desc = __('Please provide the following billing information.', 'event_espresso');
120 120
 				break;
121 121
 			case 'Bank':
122 122
 				$extra_meta_key_values = array(
123 123
 					'page_title'=>$old_gateway_settings['page_title'],
124 124
 					'payment_instructions'=>
125
-					sprintf( __('%1$s<br/>Name on Bank Account: %2$s<br/>Bank Account Number: %3$s<br/>Bank Name: %4$s<br/>Bank Address:%5$s', 'event_espresso'), $old_gateway_settings['bank_instructions'] , $old_gateway_settings['account_name'], $old_gateway_settings['account_number'], $old_gateway_settings['bank_name'], $old_gateway_settings['bank_address'] ) );
126
-				$desc = __( 'Make payment using an electronic funds transfer from your bank.', 'event_espresso' );
125
+					sprintf(__('%1$s<br/>Name on Bank Account: %2$s<br/>Bank Account Number: %3$s<br/>Bank Name: %4$s<br/>Bank Address:%5$s', 'event_espresso'), $old_gateway_settings['bank_instructions'], $old_gateway_settings['account_name'], $old_gateway_settings['account_number'], $old_gateway_settings['bank_name'], $old_gateway_settings['bank_address']) );
126
+				$desc = __('Make payment using an electronic funds transfer from your bank.', 'event_espresso');
127 127
 				break;
128 128
 			case 'Check':
129 129
 				$extra_meta_key_values = array(
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 					'payment_instructions'=>$old_gateway_settings['check_instructions'],
132 132
 					'address_to_send_payment'=>$old_gateway_settings['payment_address']
133 133
 				);
134
-				$desc = __( 'On the next page you will be given instructions on how to make a payment by check.', 'event_espresso' );
134
+				$desc = __('On the next page you will be given instructions on how to make a payment by check.', 'event_espresso');
135 135
 				break;
136 136
 			case 'Invoice':
137 137
 				$extra_meta_key_values = array(
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
 					'pdf_payee_email' => $old_gateway_settings['template_invoice_email'],
140 140
 					'pdf_payee_tax_number' => $old_gateway_settings['template_invoice_tax_number'],
141 141
 					'pdf_payee_address' => $old_gateway_settings['template_invoice_address'],
142
-					'pdf_instructions' => $old_gateway_settings[ 'template_payment_instructions' ],
143
-					'pdf_logo_image' => $old_gateway_settings[ 'invoice_logo_url' ],
144
-					'page_confirmation_text' => isset( $old_gateway_settings[ 'page_instructions' ] ) ? $old_gateway_settings[ 'page_instructions' ] : '',
145
-					'page_extra_info' => isset( $old_gateway_settings[ 'payment_address' ] ) ? $old_gateway_settings[ 'payment_address' ] : '',
142
+					'pdf_instructions' => $old_gateway_settings['template_payment_instructions'],
143
+					'pdf_logo_image' => $old_gateway_settings['invoice_logo_url'],
144
+					'page_confirmation_text' => isset($old_gateway_settings['page_instructions']) ? $old_gateway_settings['page_instructions'] : '',
145
+					'page_extra_info' => isset($old_gateway_settings['payment_address']) ? $old_gateway_settings['payment_address'] : '',
146 146
 					'legacy_invoice_css' => $old_gateway_settings['invoice_css']
147 147
 				);
148 148
 				//if they didnt want the invoiec gateway to show, pretend it was inactive
149
-				if( ! $old_gateway_settings['show'] ){
149
+				if ( ! $old_gateway_settings['show']) {
150 150
 					$active = FALSE;
151 151
 				}
152
-				$desc = __( 'On the next page you will be able to access your invoice and instructions on how to pay it.', 'event_espresso' );
152
+				$desc = __('On the next page you will be able to access your invoice and instructions on how to pay it.', 'event_espresso');
153 153
 				break;
154 154
 			case 'Mijireh':
155 155
 				$extra_meta_key_values = array(
156
-					'access_key' => $old_gateway_settings[ 'access_key' ]
156
+					'access_key' => $old_gateway_settings['access_key']
157 157
 				);
158
-				$desc =  __( 'On the next page you will be able to enter your billing information to make the payment.', 'event_espresso' );
158
+				$desc = __('On the next page you will be able to enter your billing information to make the payment.', 'event_espresso');
159 159
 				break;
160 160
 			case 'Paypal_Pro':
161 161
 				$extra_meta_key_values = array(
@@ -164,31 +164,31 @@  discard block
 block discarded – undo
164 164
 					'signature'=>$old_gateway_settings['signature'],
165 165
 					'credit_card_types'=>$old_gateway_settings['credit_cards'],
166 166
 				);
167
-				$desc = __( 'Please provide the following billing information.', 'event_espresso' );
167
+				$desc = __('Please provide the following billing information.', 'event_espresso');
168 168
 				break;
169 169
 			case 'Paypal_Standard':
170 170
 				$extra_meta_key_values = array(
171
-					'paypal_id' => $old_gateway_settings[ 'paypal_id' ],
172
-					'image_url' => $old_gateway_settings[ 'image_url' ],
173
-					'shipping_details' => isset( $old_gateway_settings[ 'no_shipping' ] ) ? $old_gateway_settings[ 'no_shipping' ] : false,
171
+					'paypal_id' => $old_gateway_settings['paypal_id'],
172
+					'image_url' => $old_gateway_settings['image_url'],
173
+					'shipping_details' => isset($old_gateway_settings['no_shipping']) ? $old_gateway_settings['no_shipping'] : false,
174 174
 
175 175
 				);
176
-				$desc = sprintf( __( 'After clicking \'Finalize Registration\', you will be forwarded to PayPal to make your payment. Make sure you return to this site in order to properly finalize your registration.', 'event_espresso' ), '<strong>','</strong>' );
176
+				$desc = sprintf(__('After clicking \'Finalize Registration\', you will be forwarded to PayPal to make your payment. Make sure you return to this site in order to properly finalize your registration.', 'event_espresso'), '<strong>', '</strong>');
177 177
 				break;
178 178
 			default:
179 179
 				//if we don't recognize the payment method, just put everything in it into extra meta. At least this way its preserved somewhere
180 180
 				$extra_meta_key_values = $old_gateway_settings;
181 181
 				$desc = '';
182 182
 		}
183
-		$pretty_name = isset( $old_gateway_settings[ 'display_name' ] ) ? $old_gateway_settings[ 'display_name' ] : $old_gateway_slug;
184
-		$offline_gateways = array( 'Bank', 'Check', 'Invoice' );
185
-		if( $active && in_array( $old_gateway_slug, $offline_gateways ) ) {
186
-			$scope = array( 'CART', 'ADMIN');
187
-		}elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) {
188
-			$scope = array( 'CART' );
189
-		}elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) {
190
-			$scope = array( 'ADMIN' );
191
-		}else{
183
+		$pretty_name = isset($old_gateway_settings['display_name']) ? $old_gateway_settings['display_name'] : $old_gateway_slug;
184
+		$offline_gateways = array('Bank', 'Check', 'Invoice');
185
+		if ($active && in_array($old_gateway_slug, $offline_gateways)) {
186
+			$scope = array('CART', 'ADMIN');
187
+		}elseif ($active && ! in_array($old_gateway_slug, $offline_gateways)) {
188
+			$scope = array('CART');
189
+		}elseif ( ! $active && in_array($old_gateway_slug, $offline_gateways)) {
190
+			$scope = array('ADMIN');
191
+		} else {
192 192
 			$scope = array();
193 193
 		}
194 194
 		$payment_method_col_values = array(
@@ -196,25 +196,25 @@  discard block
 block discarded – undo
196 196
 			'PMD_name' => $pretty_name,
197 197
 			'PMD_desc' => $desc,
198 198
 			'PMD_admin_name' => $pretty_name,
199
-			'PMD_slug' => sanitize_key( $old_gateway_slug ),
200
-			'PMD_debug_mode' => isset( $old_gateway_settings[ 'use_sandbox' ] ) ? $old_gateway_settings['use_sandbox'] : FALSE,
201
-			'PMD_button_url' => isset( $old_gateway_settings[ 'button_url' ] ) ? $old_gateway_settings[ 'button_url' ] : NULL,
202
-			'PMD_scope' =>  serialize( $scope )
199
+			'PMD_slug' => sanitize_key($old_gateway_slug),
200
+			'PMD_debug_mode' => isset($old_gateway_settings['use_sandbox']) ? $old_gateway_settings['use_sandbox'] : FALSE,
201
+			'PMD_button_url' => isset($old_gateway_settings['button_url']) ? $old_gateway_settings['button_url'] : NULL,
202
+			'PMD_scope' =>  serialize($scope)
203 203
 		);
204 204
 		$db_types = array(
205
-			'%s',//PMD_type
206
-			'%s',//PMD_name
207
-			'%s',//PMD_desc
208
-			'%s',//PMD_admin_name
209
-			'%s',//PMD_slug
210
-			'%d',//PMD_debug_mode
211
-			'%s',//PMD_button_url
212
-			'%s',//PMD_scope
205
+			'%s', //PMD_type
206
+			'%s', //PMD_name
207
+			'%s', //PMD_desc
208
+			'%s', //PMD_admin_name
209
+			'%s', //PMD_slug
210
+			'%d', //PMD_debug_mode
211
+			'%s', //PMD_button_url
212
+			'%s', //PMD_scope
213 213
 		);
214 214
 		global $wpdb;
215 215
 		//first: check if it already exists
216
-		$id = $wpdb->get_var( $wpdb->prepare( "SELECT PMD_ID FROM {$this->_new_table_name} WHERE PMD_slug=%s", $payment_method_col_values[ 'PMD_slug' ] ) );
217
-		if( $id ){
216
+		$id = $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM {$this->_new_table_name} WHERE PMD_slug=%s", $payment_method_col_values['PMD_slug']));
217
+		if ($id) {
218 218
 			//just update that payment method instead of creating a new one
219 219
 			$success = $wpdb->update(
220 220
 					$this->_new_table_name,
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
 					),
225 225
 					$db_types,
226 226
 					array(
227
-						'%d',//PMD_ID
227
+						'%d', //PMD_ID
228 228
 					));
229
-			if( ! $success ){
230
-				$this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"),$id,wp_json_encode($payment_method_col_values),$wpdb->last_error));
229
+			if ( ! $success) {
230
+				$this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"), $id, wp_json_encode($payment_method_col_values), $wpdb->last_error));
231 231
 			}
232
-		}else{
232
+		} else {
233 233
 			$success = $wpdb->insert(
234 234
 					$this->_new_table_name,
235 235
 					$payment_method_col_values,
236 236
 					$db_types);
237
-			if ( ! $success ) {
237
+			if ( ! $success) {
238 238
 				$this->add_error($wpdb->last_error);
239 239
 				return false;
240
-			}else{
240
+			} else {
241 241
 				$id = $wpdb->insert_id;
242 242
 			}
243 243
 		}
244 244
 
245
-		if( $id ){
246
-			$this->_convert_extra_meta_values( $id, $extra_meta_key_values );
247
-			$this->get_migration_script()->set_mapping( 'EE_Gateway_Config', $old_gateway_slug, $this->_new_table_name, $id );
245
+		if ($id) {
246
+			$this->_convert_extra_meta_values($id, $extra_meta_key_values);
247
+			$this->get_migration_script()->set_mapping('EE_Gateway_Config', $old_gateway_slug, $this->_new_table_name, $id);
248 248
 			return true;
249 249
 		}
250 250
 		return false;
@@ -258,26 +258,26 @@  discard block
 block discarded – undo
258 258
 	 * @param int $id
259 259
 	 * @param array $extra_meta_key_values
260 260
 	 */
261
-	private function _convert_extra_meta_values($id,$extra_meta_key_values){
261
+	private function _convert_extra_meta_values($id, $extra_meta_key_values) {
262 262
 		global $wpdb;
263
-		foreach( $extra_meta_key_values as $key => $value ){
263
+		foreach ($extra_meta_key_values as $key => $value) {
264 264
 			$exm_args = array(
265 265
 				'OBJ_ID'=>$id,
266 266
 				'EXM_type'=>'Payment_Method',
267 267
 				'EXM_key'=>$key,
268
-				'EXM_value'=> maybe_serialize($value )
268
+				'EXM_value'=> maybe_serialize($value)
269 269
 			);
270 270
 			$success = $wpdb->insert(
271 271
 					$this->_extra_meta_table_name,
272 272
 					$exm_args,
273 273
 					array(
274
-						'%d',//OBJ_ID
275
-						'%s',//EXM_type
276
-						'%s',//EXM_key
277
-						'%s',//EXM_value
274
+						'%d', //OBJ_ID
275
+						'%s', //EXM_type
276
+						'%s', //EXM_key
277
+						'%s', //EXM_value
278 278
 					));
279
-			if( ! $success ){
280
-				$this->add_error(sprintf(__('Could not insert extra meta key with values %s. %s', "event_espresso"),wp_json_encode($exm_args),$wpdb->last_error));
279
+			if ( ! $success) {
280
+				$this->add_error(sprintf(__('Could not insert extra meta key with values %s. %s', "event_espresso"), wp_json_encode($exm_args), $wpdb->last_error));
281 281
 			}
282 282
 		}
283 283
 	}
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
 		$offline_gateways = array( 'Bank', 'Check', 'Invoice' );
185 185
 		if( $active && in_array( $old_gateway_slug, $offline_gateways ) ) {
186 186
 			$scope = array( 'CART', 'ADMIN');
187
-		}elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) {
187
+		} elseif( $active && ! in_array( $old_gateway_slug, $offline_gateways ) ) {
188 188
 			$scope = array( 'CART' );
189
-		}elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) {
189
+		} elseif( ! $active && in_array($old_gateway_slug,$offline_gateways ) ) {
190 190
 			$scope = array( 'ADMIN' );
191
-		}else{
191
+		} else{
192 192
 			$scope = array();
193 193
 		}
194 194
 		$payment_method_col_values = array(
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			if( ! $success ){
230 230
 				$this->add_error(sprintf(__('Could not update payment method %d with properties %s because %s', "event_espresso"),$id,wp_json_encode($payment_method_col_values),$wpdb->last_error));
231 231
 			}
232
-		}else{
232
+		} else{
233 233
 			$success = $wpdb->insert(
234 234
 					$this->_new_table_name,
235 235
 					$payment_method_col_values,
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 			if ( ! $success ) {
238 238
 				$this->add_error($wpdb->last_error);
239 239
 				return false;
240
-			}else{
240
+			} else{
241 241
 				$id = $wpdb->insert_id;
242 242
 			}
243 243
 		}
Please login to merge, or discard this patch.
4_9_0_stages/EE_DMS_4_9_0_Email_System_Question.dmsstage.php 1 patch
Spacing   +12 added lines, -12 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
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @author				Brent Christensen
14 14
  *
15 15
  */
16
-class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table{
16
+class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table {
17 17
 
18 18
 
19 19
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct() {
26 26
 		global $wpdb;
27
-		$this->_pretty_name = __( 'Email - System Question', 'event_espresso' );
27
+		$this->_pretty_name = __('Email - System Question', 'event_espresso');
28 28
 		$this->_old_table = $wpdb->prefix.'esp_question';
29 29
 		$this->_extra_where_sql = "WHERE QST_system = 'email'";
30 30
 		parent::__construct();
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 	 * @param array $question an associative array where keys are column names and values are their values.
38 38
 	 * @return null
39 39
 	 */
40
-	protected function _migrate_old_row( $question ) {
41
-		if ( $question['QST_ID'] && $question['QST_system'] == 'email' ) {
40
+	protected function _migrate_old_row($question) {
41
+		if ($question['QST_ID'] && $question['QST_system'] == 'email') {
42 42
 			global $wpdb;
43 43
 			$success = $wpdb->update(
44 44
 				$this->_old_table,
45
-				array( 'QST_type' => 'EMAIL' ),  // data
46
-				array( 'QST_ID' => $question['QST_ID'] ),  // where
47
-				array( '%s' ),   // data format
48
-				array( '%d' )  // where format
45
+				array('QST_type' => 'EMAIL'), // data
46
+				array('QST_ID' => $question['QST_ID']), // where
47
+				array('%s'), // data format
48
+				array('%d')  // where format
49 49
 			);
50
-			if ( ! $success ) {
50
+			if ( ! $success) {
51 51
 				$this->add_error(
52 52
 					sprintf(
53
-						__( 'Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso' ),
54
-						wp_json_encode( $question['QST_system'] ),
53
+						__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
54
+						wp_json_encode($question['QST_system']),
55 55
 						$question['QST_ID'],
56 56
 						$wpdb->last_error
57 57
 					)
Please login to merge, or discard this patch.
templates/txn_admin_details_side_meta_box_registrant.template.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 <?php else : ?>
18 18
     <p class="clearfix">
19 19
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
20
+					'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21 21
     </p>
22 22
     <p class="clearfix">
23 23
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     </p>
26 26
     <p class="clearfix">
27 27
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Phone #',
28
-                    'event_espresso'); ?></span><?php echo $prime_reg_phone; ?>
28
+					'event_espresso'); ?></span><?php echo $prime_reg_phone; ?>
29 29
     </p>
30 30
     <p class="clearfix">
31 31
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Address', 'event_espresso'); ?></span>
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
     </div> <!-- end #admin-side-mbox-primary-registrant-dv -->
37 37
 
38 38
     <?php
39
-    /** only show if logged in user has access */
40
-    if ( EE_Registry::instance()->CAP->current_user_can(
41
-            'ee_edit_contact',
42
-            'view_or_edit_contact_button',
43
-            $ATT_ID
44
-    )
45
-    ) : ?>
39
+	/** only show if logged in user has access */
40
+	if ( EE_Registry::instance()->CAP->current_user_can(
41
+			'ee_edit_contact',
42
+			'view_or_edit_contact_button',
43
+			$ATT_ID
44
+	)
45
+	) : ?>
46 46
     <p style="text-align:right;">
47 47
         <a class="button button-small" href="<?php echo $edit_attendee_url; ?>"
48 48
            title="<?php esc_attr_e('View details for this contact.', 'event_espresso'); ?>">
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 <?php else : ?>
18 18
     <p class="clearfix">
19 19
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
20
+                    'event_espresso'); ?></span><?php echo $prime_reg_fname.' '.$prime_reg_lname; ?>
21 21
     </p>
22 22
     <p class="clearfix">
23 23
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     <?php
39 39
     /** only show if logged in user has access */
40
-    if ( EE_Registry::instance()->CAP->current_user_can(
40
+    if (EE_Registry::instance()->CAP->current_user_can(
41 41
             'ee_edit_contact',
42 42
             'view_or_edit_contact_button',
43 43
             $ATT_ID
@@ -50,4 +50,4 @@  discard block
 block discarded – undo
50 50
         </a>
51 51
     </p>
52 52
     <?php endif; ?>
53
-<?php endif;  //end no attendee check?>
53
+<?php endif; //end no attendee check?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,10 +14,13 @@
 block discarded – undo
14 14
         <?php echo $no_attendee_message; ?>
15 15
     </p>
16 16
 </div> <!-- end #admin-side-mbox-primary-registrant-dv -->
17
-<?php else : ?>
17
+<?php else {
18
+	: ?>
18 19
     <p class="clearfix">
19 20
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21
+                    'event_espresso');
22
+}
23
+?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21 24
     </p>
22 25
     <p class="clearfix">
23 26
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -529,7 +529,7 @@
 block discarded – undo
529 529
     /**
530 530
      * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
531 531
      *
532
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
532
+     * @param  string[] $stati_to_include If included you can restrict the statuses we return counts for by including the
533 533
      *                                 stati you want counts for as values in the array.  An empty array returns counts
534 534
      *                                 for all valid stati.
535 535
      * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -482,9 +482,9 @@
 block discarded – undo
482 482
         $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
483 483
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
484 484
         $columns_to_select = array(
485
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
486
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
487
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
485
+            'dtt_year'      => array('YEAR('.$query_interval.')', '%s'),
486
+            'dtt_month'     => array('MONTHNAME('.$query_interval.')', '%s'),
487
+            'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'),
488 488
         );
489 489
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
490 490
     }
Please login to merge, or discard this patch.
Indentation   +581 added lines, -581 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Class Datetime Model
@@ -11,586 +11,586 @@  discard block
 block discarded – undo
11 11
 class EEM_Datetime extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var EEM_Datetime $_instance
16
-     */
17
-    protected static $_instance;
18
-
19
-
20
-
21
-    /**
22
-     *        private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
-     *                         timezone in the 'timezone_string' wp option)
30
-     * @throws \EE_Error
31
-     */
32
-    protected function __construct($timezone)
33
-    {
34
-        $this->singular_item = __('Datetime', 'event_espresso');
35
-        $this->plural_item = __('Datetimes', 'event_espresso');
36
-        $this->_tables = array(
37
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
-        );
39
-        $this->_fields = array(
40
-            'Datetime' => array(
41
-                'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
-                    'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
-                ),
45
-                'DTT_name'        => new EE_Plain_Text_Field(
46
-                    'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
-                ),
48
-                'DTT_description' => new EE_Post_Content_Field(
49
-                    'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
-                ),
51
-                'DTT_EVT_start'   => new EE_Datetime_Field(
52
-                    'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
-                    $timezone
54
-                ),
55
-                'DTT_EVT_end'     => new EE_Datetime_Field(
56
-                    'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
-                    $timezone
58
-                ),
59
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
-                    'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
-                'DTT_sold'        => new EE_Integer_Field(
62
-                    'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
-                ),
64
-                'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
-                    __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
-                ),
67
-                'DTT_is_primary'  => new EE_Boolean_Field(
68
-                    'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
-                    false, false
70
-                ),
71
-                'DTT_order'       => new EE_Integer_Field(
72
-                    'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
-                ),
74
-                'DTT_parent'      => new EE_Integer_Field(
75
-                    'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
-                ),
77
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
-                    'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
-                ),
80
-            ),
81
-        );
82
-        $this->_model_relations = array(
83
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
-            'Event'   => new EE_Belongs_To_Relation(),
85
-            'Checkin' => new EE_Has_Many_Relation(),
86
-        );
87
-        $this->_model_chain_to_wp_user = 'Event';
88
-        //this model is generally available for reading
89
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
-            EEM_Base::caps_edit);
94
-        parent::__construct($timezone);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * create new blank datetime
101
-     *
102
-     * @access public
103
-     * @return EE_Datetime[] array on success, FALSE on fail
104
-     * @throws \EE_Error
105
-     */
106
-    public function create_new_blank_datetime()
107
-    {
108
-        //makes sure timezone is always set.
109
-        $timezone_string = $this->get_timezone();
110
-        $blank_datetime = EE_Datetime::new_instance(
111
-            array(
112
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
-                'DTT_order'     => 1,
115
-                'DTT_reg_limit' => EE_INF,
116
-            ),
117
-            $timezone_string
118
-        );
119
-        $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
-            $timezone_string));
121
-        $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
-        return array($blank_datetime);
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * get event start date from db
129
-     *
130
-     * @access public
131
-     * @param  int $EVT_ID
132
-     * @return EE_Datetime[] array on success, FALSE on fail
133
-     * @throws \EE_Error
134
-     */
135
-    public function get_all_event_dates($EVT_ID = 0)
136
-    {
137
-        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
-            return $this->create_new_blank_datetime();
139
-        }
140
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
-        if (empty($results)) {
142
-            return $this->create_new_blank_datetime();
143
-        }
144
-        return $results;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * get all datetimes attached to an event ordered by the DTT_order field
151
-     *
152
-     * @public
153
-     * @param  int    $EVT_ID     event id
154
-     * @param boolean $include_expired
155
-     * @param boolean $include_deleted
156
-     * @param  int    $limit      If included then limit the count of results by
157
-     *                            the given number
158
-     * @return EE_Datetime[]
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_datetimes_for_event_ordered_by_DTT_order(
162
-        $EVT_ID,
163
-        $include_expired = true,
164
-        $include_deleted = true,
165
-        $limit = null
166
-    ) {
167
-        //sanitize EVT_ID
168
-        $EVT_ID = absint($EVT_ID);
169
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
172
-        $query_params = ! empty($limit)
173
-            ? array(
174
-                $where_params,
175
-                'limit'                    => $limit,
176
-                'order_by'                 => array('DTT_order' => 'ASC'),
177
-                'default_where_conditions' => 'none',
178
-            )
179
-            : array(
180
-                $where_params,
181
-                'order_by'                 => array('DTT_order' => 'ASC'),
182
-                'default_where_conditions' => 'none',
183
-            );
184
-        if ( ! $include_expired) {
185
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
-        }
187
-        if ($include_deleted) {
188
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
-        }
190
-        /** @var EE_Datetime[] $result */
191
-        $result = $this->get_all($query_params);
192
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
193
-        return $result;
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
-     * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
-     * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
-     *
203
-     * @param int $EVT_ID
204
-     * @param int $limit
205
-     * @return EE_Datetime[]|EE_Base_Class[]
206
-     * @throws \EE_Error
207
-     */
208
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
-    {
210
-        return $this->get_all(
211
-            array(
212
-                array('Event.EVT_ID' => $EVT_ID),
213
-                'limit'                    => $limit,
214
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
-                'default_where_conditions' => 'none',
216
-            )
217
-        );
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * @param int     $EVT_ID
224
-     * @param boolean $include_expired
225
-     * @param boolean $include_deleted
226
-     * @return EE_Datetime
227
-     * @throws \EE_Error
228
-     */
229
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
-    {
231
-        $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
-        if ($results) {
233
-            return array_shift($results);
234
-        } else {
235
-            return null;
236
-        }
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * Gets the 'primary' datetime for an event.
243
-     *
244
-     * @param int  $EVT_ID
245
-     * @param bool $try_to_exclude_expired
246
-     * @param bool $try_to_exclude_deleted
247
-     * @return \EE_Datetime
248
-     * @throws \EE_Error
249
-     */
250
-    public function get_primary_datetime_for_event(
251
-        $EVT_ID,
252
-        $try_to_exclude_expired = true,
253
-        $try_to_exclude_deleted = true
254
-    ) {
255
-        if ($try_to_exclude_expired) {
256
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
-            if ($non_expired) {
258
-                return $non_expired;
259
-            }
260
-        }
261
-        if ($try_to_exclude_deleted) {
262
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
-            if ($expired_even) {
264
-                return $expired_even;
265
-            }
266
-        }
267
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
-     * only by start date
275
-     *
276
-     * @param int     $EVT_ID
277
-     * @param boolean $include_expired
278
-     * @param boolean $include_deleted
279
-     * @param int     $limit
280
-     * @return EE_Datetime[]
281
-     * @throws \EE_Error
282
-     */
283
-    public function get_datetimes_for_event_ordered_by_start_time(
284
-        $EVT_ID,
285
-        $include_expired = true,
286
-        $include_deleted = true,
287
-        $limit = null
288
-    ) {
289
-        //sanitize EVT_ID
290
-        $EVT_ID = absint($EVT_ID);
291
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
-        if ( ! $include_expired) {
295
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
-        }
297
-        if ($include_deleted) {
298
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
-        }
300
-        if ($limit) {
301
-            $query_params['limit'] = $limit;
302
-        }
303
-        /** @var EE_Datetime[] $result */
304
-        $result = $this->get_all($query_params);
305
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
306
-        return $result;
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
-     * only by start date
314
-     *
315
-     * @param int     $TKT_ID
316
-     * @param boolean $include_expired
317
-     * @param boolean $include_deleted
318
-     * @param int     $limit
319
-     * @return EE_Datetime[]
320
-     * @throws \EE_Error
321
-     */
322
-    public function get_datetimes_for_ticket_ordered_by_start_time(
323
-        $TKT_ID,
324
-        $include_expired = true,
325
-        $include_deleted = true,
326
-        $limit = null
327
-    ) {
328
-        //sanitize TKT_ID
329
-        $TKT_ID = absint($TKT_ID);
330
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
-        if ( ! $include_expired) {
334
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
-        }
336
-        if ($include_deleted) {
337
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
-        }
339
-        if ($limit) {
340
-            $query_params['limit'] = $limit;
341
-        }
342
-        /** @var EE_Datetime[] $result */
343
-        $result = $this->get_all($query_params);
344
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
345
-        return $result;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
-     * datetimes.
353
-     *
354
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
-     * @param  boolean  $include_expired whether to include expired datetimes or not
356
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
-     * @param  int|null $limit           if null, no limit, if int then limit results by
358
-     *                                   that number
359
-     * @return EE_Datetime[]
360
-     * @throws \EE_Error
361
-     */
362
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
-        $TKT_ID,
364
-        $include_expired = true,
365
-        $include_deleted = true,
366
-        $limit = null
367
-    ) {
368
-        //sanitize id.
369
-        $TKT_ID = absint($TKT_ID);
370
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
-        if ( ! $include_expired) {
375
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
-        }
377
-        if ($include_deleted) {
378
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
-        }
380
-        if ($limit) {
381
-            $query_params['limit'] = $limit;
382
-        }
383
-        /** @var EE_Datetime[] $result */
384
-        $result = $this->get_all($query_params);
385
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
386
-        return $result;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
-     * reason it doesn't exist, we consider the earliest event the most important)
394
-     *
395
-     * @param int $EVT_ID
396
-     * @return EE_Datetime
397
-     * @throws \EE_Error
398
-     */
399
-    public function get_most_important_datetime_for_event($EVT_ID)
400
-    {
401
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
-        if ($results) {
403
-            return array_shift($results);
404
-        } else {
405
-            return null;
406
-        }
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
-     * grouped by month and year.
414
-     *
415
-     * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
-     *                                   Can be:
418
-     *                                   - '' = no filter
419
-     *                                   - upcoming = Published events with at least one upcoming datetime.
420
-     *                                   - expired = Events with all datetimes expired.
421
-     *                                   - active = Events that are published and have at least one datetime that
422
-     *                                   starts before now and ends after now.
423
-     *                                   - inactive = Events that are either not published.
424
-     * @return EE_Base_Class[]
425
-     * @throws \EE_Error
426
-     */
427
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
-    {
429
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
-        $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
-        switch ($evt_active_status) {
432
-            case 'upcoming' :
433
-                $where_params['Event.status'] = 'publish';
434
-                //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
-                if (isset($where_params['DTT_EVT_start'])) {
436
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
-                }
438
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
-                break;
440
-            case 'expired' :
441
-                if (isset($where_params['Event.status'])) {
442
-                    unset($where_params['Event.status']);
443
-                }
444
-                //get events to exclude
445
-                $exclude_query[0] = array_merge($where_params,
446
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
-                //first get all events that have datetimes where its not expired.
448
-                $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
-                $event_ids = array_keys($event_ids);
450
-                if (isset($where_params['DTT_EVT_end'])) {
451
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
-                }
453
-                $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
-                break;
456
-            case 'active' :
457
-                $where_params['Event.status'] = 'publish';
458
-                if (isset($where_params['DTT_EVT_start'])) {
459
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
-                }
461
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
-                }
464
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
-                $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
-                break;
467
-            case 'inactive' :
468
-                if (isset($where_params['Event.status'])) {
469
-                    unset($where_params['Event.status']);
470
-                }
471
-                if (isset($where_params['OR'])) {
472
-                    $where_params['AND']['OR'] = $where_params['OR'];
473
-                }
474
-                if (isset($where_params['DTT_EVT_end'])) {
475
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
-                    unset($where_params['DTT_EVT_end']);
477
-                }
478
-                if (isset($where_params['DTT_EVT_start'])) {
479
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
-                    unset($where_params['DTT_EVT_start']);
481
-                }
482
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
483
-                break;
484
-        }
485
-        $query_params[0] = $where_params;
486
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
487
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
-        $columns_to_select = array(
490
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
-        );
494
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
501
-     * for the tickets for each datetime)
502
-     *
503
-     * @param EE_Datetime[] $datetimes
504
-     */
505
-    public function update_sold($datetimes)
506
-    {
507
-        foreach ($datetimes as $datetime) {
508
-            $datetime->update_sold();
509
-        }
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     *    Gets the total number of tickets available at a particular datetime
516
-     *    (does NOT take into account the datetime's spaces available)
517
-     *
518
-     * @param int   $DTT_ID
519
-     * @param array $query_params
520
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
521
-     *             tickets attached to datetime then FALSE is returned.
522
-     */
523
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
524
-    {
525
-        $datetime = $this->get_one_by_ID($DTT_ID);
526
-        if ($datetime instanceof EE_Datetime) {
527
-            return $datetime->tickets_remaining($query_params);
528
-        }
529
-        return 0;
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
536
-     *
537
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
538
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
539
-     *                                 for all valid stati.
540
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
541
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
542
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
543
-     * @throws \EE_Error
544
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
545
-     */
546
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
547
-    {
548
-        //only accept where conditions for this query.
549
-        $_where = isset($query_params[0]) ? $query_params[0] : array();
550
-        $status_query_args = array(
551
-            EE_Datetime::active   => array_merge(
552
-                $_where,
553
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
554
-            ),
555
-            EE_Datetime::upcoming => array_merge(
556
-                $_where,
557
-                array('DTT_EVT_start' => array('>', time()))
558
-            ),
559
-            EE_Datetime::expired  => array_merge(
560
-                $_where,
561
-                array('DTT_EVT_end' => array('<', time()))
562
-            ),
563
-        );
564
-        if ( ! empty($stati_to_include)) {
565
-            foreach (array_keys($status_query_args) as $status) {
566
-                if ( ! in_array($status, $stati_to_include, true)) {
567
-                    unset($status_query_args[$status]);
568
-                }
569
-            }
570
-        }
571
-        //loop through and query counts for each stati.
572
-        $status_query_results = array();
573
-        foreach ($status_query_args as $status => $status_where_conditions) {
574
-            $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
575
-        }
576
-        return $status_query_results;
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     * Returns the specific count for a given Datetime status matching any given query_params.
583
-     *
584
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
585
-     * @param array  $query_params
586
-     * @return int
587
-     * @throws \EE_Error
588
-     */
589
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
590
-    {
591
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
592
-        return ! empty($count[$status]) ? $count[$status] : 0;
593
-    }
14
+	/**
15
+	 * @var EEM_Datetime $_instance
16
+	 */
17
+	protected static $_instance;
18
+
19
+
20
+
21
+	/**
22
+	 *        private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
+	 *                         timezone in the 'timezone_string' wp option)
30
+	 * @throws \EE_Error
31
+	 */
32
+	protected function __construct($timezone)
33
+	{
34
+		$this->singular_item = __('Datetime', 'event_espresso');
35
+		$this->plural_item = __('Datetimes', 'event_espresso');
36
+		$this->_tables = array(
37
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
+		);
39
+		$this->_fields = array(
40
+			'Datetime' => array(
41
+				'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
+					'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
+				),
45
+				'DTT_name'        => new EE_Plain_Text_Field(
46
+					'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
+				),
48
+				'DTT_description' => new EE_Post_Content_Field(
49
+					'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
+				),
51
+				'DTT_EVT_start'   => new EE_Datetime_Field(
52
+					'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
+					$timezone
54
+				),
55
+				'DTT_EVT_end'     => new EE_Datetime_Field(
56
+					'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
+					$timezone
58
+				),
59
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
+					'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
+				'DTT_sold'        => new EE_Integer_Field(
62
+					'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
+				),
64
+				'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
+					__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
+				),
67
+				'DTT_is_primary'  => new EE_Boolean_Field(
68
+					'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
+					false, false
70
+				),
71
+				'DTT_order'       => new EE_Integer_Field(
72
+					'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
+				),
74
+				'DTT_parent'      => new EE_Integer_Field(
75
+					'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
+				),
77
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
+					'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
+				),
80
+			),
81
+		);
82
+		$this->_model_relations = array(
83
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
+			'Event'   => new EE_Belongs_To_Relation(),
85
+			'Checkin' => new EE_Has_Many_Relation(),
86
+		);
87
+		$this->_model_chain_to_wp_user = 'Event';
88
+		//this model is generally available for reading
89
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
+			EEM_Base::caps_edit);
94
+		parent::__construct($timezone);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * create new blank datetime
101
+	 *
102
+	 * @access public
103
+	 * @return EE_Datetime[] array on success, FALSE on fail
104
+	 * @throws \EE_Error
105
+	 */
106
+	public function create_new_blank_datetime()
107
+	{
108
+		//makes sure timezone is always set.
109
+		$timezone_string = $this->get_timezone();
110
+		$blank_datetime = EE_Datetime::new_instance(
111
+			array(
112
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
+				'DTT_order'     => 1,
115
+				'DTT_reg_limit' => EE_INF,
116
+			),
117
+			$timezone_string
118
+		);
119
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
+			$timezone_string));
121
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
+		return array($blank_datetime);
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * get event start date from db
129
+	 *
130
+	 * @access public
131
+	 * @param  int $EVT_ID
132
+	 * @return EE_Datetime[] array on success, FALSE on fail
133
+	 * @throws \EE_Error
134
+	 */
135
+	public function get_all_event_dates($EVT_ID = 0)
136
+	{
137
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
+			return $this->create_new_blank_datetime();
139
+		}
140
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
+		if (empty($results)) {
142
+			return $this->create_new_blank_datetime();
143
+		}
144
+		return $results;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * get all datetimes attached to an event ordered by the DTT_order field
151
+	 *
152
+	 * @public
153
+	 * @param  int    $EVT_ID     event id
154
+	 * @param boolean $include_expired
155
+	 * @param boolean $include_deleted
156
+	 * @param  int    $limit      If included then limit the count of results by
157
+	 *                            the given number
158
+	 * @return EE_Datetime[]
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_datetimes_for_event_ordered_by_DTT_order(
162
+		$EVT_ID,
163
+		$include_expired = true,
164
+		$include_deleted = true,
165
+		$limit = null
166
+	) {
167
+		//sanitize EVT_ID
168
+		$EVT_ID = absint($EVT_ID);
169
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
172
+		$query_params = ! empty($limit)
173
+			? array(
174
+				$where_params,
175
+				'limit'                    => $limit,
176
+				'order_by'                 => array('DTT_order' => 'ASC'),
177
+				'default_where_conditions' => 'none',
178
+			)
179
+			: array(
180
+				$where_params,
181
+				'order_by'                 => array('DTT_order' => 'ASC'),
182
+				'default_where_conditions' => 'none',
183
+			);
184
+		if ( ! $include_expired) {
185
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
+		}
187
+		if ($include_deleted) {
188
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
+		}
190
+		/** @var EE_Datetime[] $result */
191
+		$result = $this->get_all($query_params);
192
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
193
+		return $result;
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
+	 * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
+	 * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
+	 *
203
+	 * @param int $EVT_ID
204
+	 * @param int $limit
205
+	 * @return EE_Datetime[]|EE_Base_Class[]
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
+	{
210
+		return $this->get_all(
211
+			array(
212
+				array('Event.EVT_ID' => $EVT_ID),
213
+				'limit'                    => $limit,
214
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
+				'default_where_conditions' => 'none',
216
+			)
217
+		);
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * @param int     $EVT_ID
224
+	 * @param boolean $include_expired
225
+	 * @param boolean $include_deleted
226
+	 * @return EE_Datetime
227
+	 * @throws \EE_Error
228
+	 */
229
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
+	{
231
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
+		if ($results) {
233
+			return array_shift($results);
234
+		} else {
235
+			return null;
236
+		}
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * Gets the 'primary' datetime for an event.
243
+	 *
244
+	 * @param int  $EVT_ID
245
+	 * @param bool $try_to_exclude_expired
246
+	 * @param bool $try_to_exclude_deleted
247
+	 * @return \EE_Datetime
248
+	 * @throws \EE_Error
249
+	 */
250
+	public function get_primary_datetime_for_event(
251
+		$EVT_ID,
252
+		$try_to_exclude_expired = true,
253
+		$try_to_exclude_deleted = true
254
+	) {
255
+		if ($try_to_exclude_expired) {
256
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
+			if ($non_expired) {
258
+				return $non_expired;
259
+			}
260
+		}
261
+		if ($try_to_exclude_deleted) {
262
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
+			if ($expired_even) {
264
+				return $expired_even;
265
+			}
266
+		}
267
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
+	 * only by start date
275
+	 *
276
+	 * @param int     $EVT_ID
277
+	 * @param boolean $include_expired
278
+	 * @param boolean $include_deleted
279
+	 * @param int     $limit
280
+	 * @return EE_Datetime[]
281
+	 * @throws \EE_Error
282
+	 */
283
+	public function get_datetimes_for_event_ordered_by_start_time(
284
+		$EVT_ID,
285
+		$include_expired = true,
286
+		$include_deleted = true,
287
+		$limit = null
288
+	) {
289
+		//sanitize EVT_ID
290
+		$EVT_ID = absint($EVT_ID);
291
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
+		if ( ! $include_expired) {
295
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
+		}
297
+		if ($include_deleted) {
298
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
+		}
300
+		if ($limit) {
301
+			$query_params['limit'] = $limit;
302
+		}
303
+		/** @var EE_Datetime[] $result */
304
+		$result = $this->get_all($query_params);
305
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
306
+		return $result;
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
+	 * only by start date
314
+	 *
315
+	 * @param int     $TKT_ID
316
+	 * @param boolean $include_expired
317
+	 * @param boolean $include_deleted
318
+	 * @param int     $limit
319
+	 * @return EE_Datetime[]
320
+	 * @throws \EE_Error
321
+	 */
322
+	public function get_datetimes_for_ticket_ordered_by_start_time(
323
+		$TKT_ID,
324
+		$include_expired = true,
325
+		$include_deleted = true,
326
+		$limit = null
327
+	) {
328
+		//sanitize TKT_ID
329
+		$TKT_ID = absint($TKT_ID);
330
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
+		if ( ! $include_expired) {
334
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
+		}
336
+		if ($include_deleted) {
337
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
+		}
339
+		if ($limit) {
340
+			$query_params['limit'] = $limit;
341
+		}
342
+		/** @var EE_Datetime[] $result */
343
+		$result = $this->get_all($query_params);
344
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
345
+		return $result;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
+	 * datetimes.
353
+	 *
354
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
356
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
358
+	 *                                   that number
359
+	 * @return EE_Datetime[]
360
+	 * @throws \EE_Error
361
+	 */
362
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
+		$TKT_ID,
364
+		$include_expired = true,
365
+		$include_deleted = true,
366
+		$limit = null
367
+	) {
368
+		//sanitize id.
369
+		$TKT_ID = absint($TKT_ID);
370
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
+		if ( ! $include_expired) {
375
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
+		}
377
+		if ($include_deleted) {
378
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
+		}
380
+		if ($limit) {
381
+			$query_params['limit'] = $limit;
382
+		}
383
+		/** @var EE_Datetime[] $result */
384
+		$result = $this->get_all($query_params);
385
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
386
+		return $result;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
+	 * reason it doesn't exist, we consider the earliest event the most important)
394
+	 *
395
+	 * @param int $EVT_ID
396
+	 * @return EE_Datetime
397
+	 * @throws \EE_Error
398
+	 */
399
+	public function get_most_important_datetime_for_event($EVT_ID)
400
+	{
401
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
+		if ($results) {
403
+			return array_shift($results);
404
+		} else {
405
+			return null;
406
+		}
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
+	 * grouped by month and year.
414
+	 *
415
+	 * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
+	 *                                   Can be:
418
+	 *                                   - '' = no filter
419
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
420
+	 *                                   - expired = Events with all datetimes expired.
421
+	 *                                   - active = Events that are published and have at least one datetime that
422
+	 *                                   starts before now and ends after now.
423
+	 *                                   - inactive = Events that are either not published.
424
+	 * @return EE_Base_Class[]
425
+	 * @throws \EE_Error
426
+	 */
427
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
+	{
429
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
+		switch ($evt_active_status) {
432
+			case 'upcoming' :
433
+				$where_params['Event.status'] = 'publish';
434
+				//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
+				if (isset($where_params['DTT_EVT_start'])) {
436
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
+				}
438
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
+				break;
440
+			case 'expired' :
441
+				if (isset($where_params['Event.status'])) {
442
+					unset($where_params['Event.status']);
443
+				}
444
+				//get events to exclude
445
+				$exclude_query[0] = array_merge($where_params,
446
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
+				//first get all events that have datetimes where its not expired.
448
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
+				$event_ids = array_keys($event_ids);
450
+				if (isset($where_params['DTT_EVT_end'])) {
451
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
+				}
453
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
+				break;
456
+			case 'active' :
457
+				$where_params['Event.status'] = 'publish';
458
+				if (isset($where_params['DTT_EVT_start'])) {
459
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
+				}
461
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
+				}
464
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
+				break;
467
+			case 'inactive' :
468
+				if (isset($where_params['Event.status'])) {
469
+					unset($where_params['Event.status']);
470
+				}
471
+				if (isset($where_params['OR'])) {
472
+					$where_params['AND']['OR'] = $where_params['OR'];
473
+				}
474
+				if (isset($where_params['DTT_EVT_end'])) {
475
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
+					unset($where_params['DTT_EVT_end']);
477
+				}
478
+				if (isset($where_params['DTT_EVT_start'])) {
479
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
+					unset($where_params['DTT_EVT_start']);
481
+				}
482
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
483
+				break;
484
+		}
485
+		$query_params[0] = $where_params;
486
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
487
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
+		$columns_to_select = array(
490
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
+		);
494
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
501
+	 * for the tickets for each datetime)
502
+	 *
503
+	 * @param EE_Datetime[] $datetimes
504
+	 */
505
+	public function update_sold($datetimes)
506
+	{
507
+		foreach ($datetimes as $datetime) {
508
+			$datetime->update_sold();
509
+		}
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 *    Gets the total number of tickets available at a particular datetime
516
+	 *    (does NOT take into account the datetime's spaces available)
517
+	 *
518
+	 * @param int   $DTT_ID
519
+	 * @param array $query_params
520
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
521
+	 *             tickets attached to datetime then FALSE is returned.
522
+	 */
523
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
524
+	{
525
+		$datetime = $this->get_one_by_ID($DTT_ID);
526
+		if ($datetime instanceof EE_Datetime) {
527
+			return $datetime->tickets_remaining($query_params);
528
+		}
529
+		return 0;
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
536
+	 *
537
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
538
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
539
+	 *                                 for all valid stati.
540
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
541
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
542
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
543
+	 * @throws \EE_Error
544
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
545
+	 */
546
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
547
+	{
548
+		//only accept where conditions for this query.
549
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
550
+		$status_query_args = array(
551
+			EE_Datetime::active   => array_merge(
552
+				$_where,
553
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
554
+			),
555
+			EE_Datetime::upcoming => array_merge(
556
+				$_where,
557
+				array('DTT_EVT_start' => array('>', time()))
558
+			),
559
+			EE_Datetime::expired  => array_merge(
560
+				$_where,
561
+				array('DTT_EVT_end' => array('<', time()))
562
+			),
563
+		);
564
+		if ( ! empty($stati_to_include)) {
565
+			foreach (array_keys($status_query_args) as $status) {
566
+				if ( ! in_array($status, $stati_to_include, true)) {
567
+					unset($status_query_args[$status]);
568
+				}
569
+			}
570
+		}
571
+		//loop through and query counts for each stati.
572
+		$status_query_results = array();
573
+		foreach ($status_query_args as $status => $status_where_conditions) {
574
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
575
+		}
576
+		return $status_query_results;
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 * Returns the specific count for a given Datetime status matching any given query_params.
583
+	 *
584
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
585
+	 * @param array  $query_params
586
+	 * @return int
587
+	 * @throws \EE_Error
588
+	 */
589
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
590
+	{
591
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
592
+		return ! empty($count[$status]) ? $count[$status] : 0;
593
+	}
594 594
 
595 595
 
596 596
 
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-datetimes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' &nbsp; <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>';
3 3
 
4
-if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) :
4
+if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) :
5 5
 global $post;
6
-do_action( 'AHEE_event_details_before_event_date', $post );
6
+do_action('AHEE_event_details_before_event_date', $post);
7 7
 ?>
8 8
 	<div class="event-datetimes">
9
-		<?php espresso_list_of_event_dates( $post->ID );?>
9
+		<?php espresso_list_of_event_dates($post->ID); ?>
10 10
 	</div>
11 11
 	<!-- .event-datetimes -->
12 12
 <?php
13
-do_action( 'AHEE_event_details_after_event_date', $post );
13
+do_action('AHEE_event_details_after_event_date', $post);
14 14
 endif;
15 15
 ?>
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Indentation   +1222 added lines, -1222 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
 
@@ -16,1229 +16,1229 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * admin_init
211
-     */
212
-    public function admin_init()
213
-    {
214
-        EE_Registry::$i18n_js_strings = array_merge(
215
-            EE_Registry::$i18n_js_strings,
216
-            array(
217
-                'image_confirm'          => esc_html__(
218
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
-                    'event_espresso'
220
-                ),
221
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
-     * accordingly.
235
-     *
236
-     * @param array $response The existing heartbeat response array.
237
-     * @param array $data     The incoming data package.
238
-     * @return array  possibly appended response.
239
-     */
240
-    public function heartbeat_response($response, $data)
241
-    {
242
-        /**
243
-         * check whether count of tickets is approaching the potential
244
-         * limits for the server.
245
-         */
246
-        if ( ! empty($data['input_count'])) {
247
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
-                $data['input_count']
249
-            );
250
-        }
251
-        return $response;
252
-    }
253
-
254
-
255
-
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * @param string $return
265
-     * @param int    $id
266
-     * @param string $new_title
267
-     * @param string $new_slug
268
-     * @return string
269
-     */
270
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
-    {
272
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
-        //make sure this is only when editing
274
-        if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
276
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
-                $this->_admin_base_url
278
-            );
279
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
280
-            $return .= '<a href="'
281
-                       . $href
282
-                       . '" title="'
283
-                       . $title
284
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
-                       . $title
286
-                       . '</button>';
287
-        }
288
-        return $return;
289
-    }
290
-
291
-
292
-
293
-    public function _set_list_table_views_ticket_list_table()
294
-    {
295
-        $this->_views = array(
296
-            'all'     => array(
297
-                'slug'        => 'all',
298
-                'label'       => esc_html__('All', 'event_espresso'),
299
-                'count'       => 0,
300
-                'bulk_action' => array(
301
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
-                ),
303
-            ),
304
-            'trashed' => array(
305
-                'slug'        => 'trashed',
306
-                'label'       => esc_html__('Trash', 'event_espresso'),
307
-                'count'       => 0,
308
-                'bulk_action' => array(
309
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
-                ),
312
-            ),
313
-        );
314
-    }
315
-
316
-
317
-
318
-    public function load_scripts_styles_edit()
319
-    {
320
-        wp_register_script(
321
-            'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
-            array('ee_admin_js', 'heartbeat'),
324
-            EVENT_ESPRESSO_VERSION,
325
-            true
326
-        );
327
-        /**
328
-         * load accounting js.
329
-         */
330
-        add_filter('FHEE_load_accounting_js', '__return_true');
331
-        //styles
332
-        wp_enqueue_style('espresso-ui-theme');
333
-        wp_enqueue_script('event_editor_js');
334
-        wp_enqueue_script('ee-event-editor-heartbeat');
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * @param $template
341
-     * @param $template_args
342
-     * @return mixed
343
-     */
344
-    public function add_additional_datetime_button($template, $template_args)
345
-    {
346
-        return EEH_Template::display_template(
347
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
348
-            $template_args,
349
-            true
350
-        );
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * @param $template
357
-     * @param $template_args
358
-     * @return mixed
359
-     */
360
-    public function add_datetime_clone_button($template, $template_args)
361
-    {
362
-        return EEH_Template::display_template(
363
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
364
-            $template_args,
365
-            true
366
-        );
367
-    }
368
-
369
-
370
-
371
-    /**
372
-     * @param $template
373
-     * @param $template_args
374
-     * @return mixed
375
-     */
376
-    public function datetime_timezones_template($template, $template_args)
377
-    {
378
-        return EEH_Template::display_template(
379
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
380
-            $template_args,
381
-            true
382
-        );
383
-    }
384
-
385
-
386
-
387
-    protected function _set_list_table_views_default()
388
-    {
389
-        parent::_set_list_table_views_default();
390
-        $new_views = array(
391
-            'today' => array(
392
-                'slug'        => 'today',
393
-                'label'       => esc_html__('Today', 'event_espresso'),
394
-                'count'       => $this->total_events_today(),
395
-                'bulk_action' => array(
396
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
397
-                ),
398
-            ),
399
-            'month' => array(
400
-                'slug'        => 'month',
401
-                'label'       => esc_html__('This Month', 'event_espresso'),
402
-                'count'       => $this->total_events_this_month(),
403
-                'bulk_action' => array(
404
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
405
-                ),
406
-            ),
407
-        );
408
-        $this->_views = array_merge($this->_views, $new_views);
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * @param array     $action_links
415
-     * @param \EE_Event $event
416
-     * @return array
417
-     */
418
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
419
-    {
420
-        if (
421
-        EE_Registry::instance()->CAP->current_user_can(
422
-            'ee_read_registrations',
423
-            'espresso_registrations_reports',
424
-            $event->ID()
425
-        )
426
-        ) {
427
-            $reports_query_args = array(
428
-                'action' => 'reports',
429
-                'EVT_ID' => $event->ID(),
430
-            );
431
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
432
-            $action_links[]     = '<a href="'
433
-                                  . $reports_link
434
-                                  . '" title="'
435
-                                  . esc_attr__('View Report', 'event_espresso')
436
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
437
-                                  . "\n\t";
438
-        }
439
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
440
-            EE_Registry::instance()->load_helper('MSG_Template');
441
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
442
-                'see_notifications_for',
443
-                null,
444
-                array('EVT_ID' => $event->ID())
445
-            );
446
-        }
447
-        return $action_links;
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     * @param $items
454
-     * @return mixed
455
-     */
456
-    public function additional_legend_items($items)
457
-    {
458
-        if (
459
-        EE_Registry::instance()->CAP->current_user_can(
460
-            'ee_read_registrations',
461
-            'espresso_registrations_reports'
462
-        )
463
-        ) {
464
-            $items['reports'] = array(
465
-                'class' => 'dashicons dashicons-chart-bar',
466
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
467
-            );
468
-        }
469
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
470
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
471
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
472
-                $items['view_related_messages'] = array(
473
-                    'class' => $related_for_icon['css_class'],
474
-                    'desc'  => $related_for_icon['label'],
475
-                );
476
-            }
477
-        }
478
-        return $items;
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * This is the callback method for the duplicate event route
485
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
486
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
487
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
488
-     * After duplication the redirect is to the new event edit page.
489
-     *
490
-     * @return void
491
-     * @access protected
492
-     * @throws EE_Error If EE_Event is not available with given ID
493
-     */
494
-    protected function _duplicate_event()
495
-    {
496
-        // first make sure the ID for the event is in the request.
497
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
498
-        if ( ! isset($this->_req_data['EVT_ID'])) {
499
-            EE_Error::add_error(
500
-                esc_html__(
501
-                    'In order to duplicate an event an Event ID is required.  None was given.',
502
-                    'event_espresso'
503
-                ),
504
-                __FILE__,
505
-                __FUNCTION__,
506
-                __LINE__
507
-            );
508
-            $this->_redirect_after_action(false, '', '', array(), true);
509
-            return;
510
-        }
511
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
512
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
513
-        if ( ! $orig_event instanceof EE_Event) {
514
-            throw new EE_Error(
515
-                sprintf(
516
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
517
-                    $this->_req_data['EVT_ID']
518
-                )
519
-            );
520
-        }
521
-        //k now let's clone the $orig_event before getting relations
522
-        $new_event = clone $orig_event;
523
-        //original datetimes
524
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
525
-        //other original relations
526
-        $orig_ven = $orig_event->get_many_related('Venue');
527
-        //reset the ID and modify other details to make it clear this is a dupe
528
-        $new_event->set('EVT_ID', 0);
529
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
530
-        $new_event->set('EVT_name', $new_name);
531
-        $new_event->set(
532
-            'EVT_slug',
533
-            wp_unique_post_slug(
534
-                sanitize_title($orig_event->name()),
535
-                0,
536
-                'publish',
537
-                'espresso_events',
538
-                0
539
-            )
540
-        );
541
-        $new_event->set('status', 'draft');
542
-        //duplicate discussion settings
543
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
544
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
545
-        //save the new event
546
-        $new_event->save();
547
-        //venues
548
-        foreach ($orig_ven as $ven) {
549
-            $new_event->_add_relation_to($ven, 'Venue');
550
-        }
551
-        $new_event->save();
552
-        //now we need to get the question group relations and handle that
553
-        //first primary question groups
554
-        $orig_primary_qgs = $orig_event->get_many_related(
555
-            'Question_Group',
556
-            array(array('Event_Question_Group.EQG_primary' => 1))
557
-        );
558
-        if ( ! empty($orig_primary_qgs)) {
559
-            foreach ($orig_primary_qgs as $id => $obj) {
560
-                if ($obj instanceof EE_Question_Group) {
561
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
562
-                }
563
-            }
564
-        }
565
-        //next additional attendee question groups
566
-        $orig_additional_qgs = $orig_event->get_many_related(
567
-            'Question_Group',
568
-            array(array('Event_Question_Group.EQG_primary' => 0))
569
-        );
570
-        if ( ! empty($orig_additional_qgs)) {
571
-            foreach ($orig_additional_qgs as $id => $obj) {
572
-                if ($obj instanceof EE_Question_Group) {
573
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
574
-                }
575
-            }
576
-        }
577
-        //now save
578
-        $new_event->save();
579
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
580
-        $cloned_tickets = array();
581
-        foreach ($orig_datetimes as $orig_dtt) {
582
-            if ( ! $orig_dtt instanceof EE_Datetime) {
583
-                continue;
584
-            }
585
-            $new_dtt   = clone $orig_dtt;
586
-            $orig_tkts = $orig_dtt->tickets();
587
-            //save new dtt then add to event
588
-            $new_dtt->set('DTT_ID', 0);
589
-            $new_dtt->set('DTT_sold', 0);
590
-            $new_dtt->save();
591
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
592
-            $new_event->save();
593
-            //now let's get the ticket relations setup.
594
-            foreach ((array)$orig_tkts as $orig_tkt) {
595
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
596
-                if ( ! $orig_tkt instanceof EE_Ticket) {
597
-                    continue;
598
-                }
599
-                //is this ticket archived?  If it is then let's skip
600
-                if ($orig_tkt->get('TKT_deleted')) {
601
-                    continue;
602
-                }
603
-                // does this original ticket already exist in the clone_tickets cache?
604
-                //  If so we'll just use the new ticket from it.
605
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
606
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
607
-                } else {
608
-                    $new_tkt = clone $orig_tkt;
609
-                    //get relations on the $orig_tkt that we need to setup.
610
-                    $orig_prices = $orig_tkt->prices();
611
-                    $new_tkt->set('TKT_ID', 0);
612
-                    $new_tkt->set('TKT_sold', 0);
613
-                    $new_tkt->set('TKT_reserved', 0);
614
-                    $new_tkt->save(); //make sure new ticket has ID.
615
-                    //price relations on new ticket need to be setup.
616
-                    foreach ($orig_prices as $orig_price) {
617
-                        $new_price = clone $orig_price;
618
-                        $new_price->set('PRC_ID', 0);
619
-                        $new_price->save();
620
-                        $new_tkt->_add_relation_to($new_price, 'Price');
621
-                        $new_tkt->save();
622
-                    }
623
-                }
624
-                // k now we can add the new ticket as a relation to the new datetime
625
-                // and make sure its added to our cached $cloned_tickets array
626
-                // for use with later datetimes that have the same ticket.
627
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
628
-                $new_dtt->save();
629
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
630
-            }
631
-        }
632
-        //clone taxonomy information
633
-        $taxonomies_to_clone_with = apply_filters(
634
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
635
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
636
-        );
637
-        //get terms for original event (notice)
638
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
639
-        //loop through terms and add them to new event.
640
-        foreach ($orig_terms as $term) {
641
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
642
-        }
643
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
644
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
645
-        if ($new_event->ID()) {
646
-            $redirect_args = array(
647
-                'post'   => $new_event->ID(),
648
-                'action' => 'edit',
649
-            );
650
-            EE_Error::add_success(
651
-                esc_html__(
652
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
653
-                    'event_espresso'
654
-                )
655
-            );
656
-        } else {
657
-            $redirect_args = array(
658
-                'action' => 'default',
659
-            );
660
-            EE_Error::add_error(
661
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
662
-                __FILE__,
663
-                __FUNCTION__,
664
-                __LINE__
665
-            );
666
-        }
667
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
668
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * admin_init
211
+	 */
212
+	public function admin_init()
213
+	{
214
+		EE_Registry::$i18n_js_strings = array_merge(
215
+			EE_Registry::$i18n_js_strings,
216
+			array(
217
+				'image_confirm'          => esc_html__(
218
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
+					'event_espresso'
220
+				),
221
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
+	 * accordingly.
235
+	 *
236
+	 * @param array $response The existing heartbeat response array.
237
+	 * @param array $data     The incoming data package.
238
+	 * @return array  possibly appended response.
239
+	 */
240
+	public function heartbeat_response($response, $data)
241
+	{
242
+		/**
243
+		 * check whether count of tickets is approaching the potential
244
+		 * limits for the server.
245
+		 */
246
+		if ( ! empty($data['input_count'])) {
247
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
+				$data['input_count']
249
+			);
250
+		}
251
+		return $response;
252
+	}
253
+
254
+
255
+
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * @param string $return
265
+	 * @param int    $id
266
+	 * @param string $new_title
267
+	 * @param string $new_slug
268
+	 * @return string
269
+	 */
270
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
+	{
272
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
+		//make sure this is only when editing
274
+		if ( ! empty($id)) {
275
+			$href  = EE_Admin_Page::add_query_args_and_nonce(
276
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
+				$this->_admin_base_url
278
+			);
279
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
280
+			$return .= '<a href="'
281
+					   . $href
282
+					   . '" title="'
283
+					   . $title
284
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
+					   . $title
286
+					   . '</button>';
287
+		}
288
+		return $return;
289
+	}
290
+
291
+
292
+
293
+	public function _set_list_table_views_ticket_list_table()
294
+	{
295
+		$this->_views = array(
296
+			'all'     => array(
297
+				'slug'        => 'all',
298
+				'label'       => esc_html__('All', 'event_espresso'),
299
+				'count'       => 0,
300
+				'bulk_action' => array(
301
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
+				),
303
+			),
304
+			'trashed' => array(
305
+				'slug'        => 'trashed',
306
+				'label'       => esc_html__('Trash', 'event_espresso'),
307
+				'count'       => 0,
308
+				'bulk_action' => array(
309
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
+				),
312
+			),
313
+		);
314
+	}
315
+
316
+
317
+
318
+	public function load_scripts_styles_edit()
319
+	{
320
+		wp_register_script(
321
+			'ee-event-editor-heartbeat',
322
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
+			array('ee_admin_js', 'heartbeat'),
324
+			EVENT_ESPRESSO_VERSION,
325
+			true
326
+		);
327
+		/**
328
+		 * load accounting js.
329
+		 */
330
+		add_filter('FHEE_load_accounting_js', '__return_true');
331
+		//styles
332
+		wp_enqueue_style('espresso-ui-theme');
333
+		wp_enqueue_script('event_editor_js');
334
+		wp_enqueue_script('ee-event-editor-heartbeat');
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * @param $template
341
+	 * @param $template_args
342
+	 * @return mixed
343
+	 */
344
+	public function add_additional_datetime_button($template, $template_args)
345
+	{
346
+		return EEH_Template::display_template(
347
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
348
+			$template_args,
349
+			true
350
+		);
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * @param $template
357
+	 * @param $template_args
358
+	 * @return mixed
359
+	 */
360
+	public function add_datetime_clone_button($template, $template_args)
361
+	{
362
+		return EEH_Template::display_template(
363
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
364
+			$template_args,
365
+			true
366
+		);
367
+	}
368
+
369
+
370
+
371
+	/**
372
+	 * @param $template
373
+	 * @param $template_args
374
+	 * @return mixed
375
+	 */
376
+	public function datetime_timezones_template($template, $template_args)
377
+	{
378
+		return EEH_Template::display_template(
379
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
380
+			$template_args,
381
+			true
382
+		);
383
+	}
384
+
385
+
386
+
387
+	protected function _set_list_table_views_default()
388
+	{
389
+		parent::_set_list_table_views_default();
390
+		$new_views = array(
391
+			'today' => array(
392
+				'slug'        => 'today',
393
+				'label'       => esc_html__('Today', 'event_espresso'),
394
+				'count'       => $this->total_events_today(),
395
+				'bulk_action' => array(
396
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
397
+				),
398
+			),
399
+			'month' => array(
400
+				'slug'        => 'month',
401
+				'label'       => esc_html__('This Month', 'event_espresso'),
402
+				'count'       => $this->total_events_this_month(),
403
+				'bulk_action' => array(
404
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
405
+				),
406
+			),
407
+		);
408
+		$this->_views = array_merge($this->_views, $new_views);
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * @param array     $action_links
415
+	 * @param \EE_Event $event
416
+	 * @return array
417
+	 */
418
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
419
+	{
420
+		if (
421
+		EE_Registry::instance()->CAP->current_user_can(
422
+			'ee_read_registrations',
423
+			'espresso_registrations_reports',
424
+			$event->ID()
425
+		)
426
+		) {
427
+			$reports_query_args = array(
428
+				'action' => 'reports',
429
+				'EVT_ID' => $event->ID(),
430
+			);
431
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
432
+			$action_links[]     = '<a href="'
433
+								  . $reports_link
434
+								  . '" title="'
435
+								  . esc_attr__('View Report', 'event_espresso')
436
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
437
+								  . "\n\t";
438
+		}
439
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
440
+			EE_Registry::instance()->load_helper('MSG_Template');
441
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
442
+				'see_notifications_for',
443
+				null,
444
+				array('EVT_ID' => $event->ID())
445
+			);
446
+		}
447
+		return $action_links;
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 * @param $items
454
+	 * @return mixed
455
+	 */
456
+	public function additional_legend_items($items)
457
+	{
458
+		if (
459
+		EE_Registry::instance()->CAP->current_user_can(
460
+			'ee_read_registrations',
461
+			'espresso_registrations_reports'
462
+		)
463
+		) {
464
+			$items['reports'] = array(
465
+				'class' => 'dashicons dashicons-chart-bar',
466
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
467
+			);
468
+		}
469
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
470
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
471
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
472
+				$items['view_related_messages'] = array(
473
+					'class' => $related_for_icon['css_class'],
474
+					'desc'  => $related_for_icon['label'],
475
+				);
476
+			}
477
+		}
478
+		return $items;
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * This is the callback method for the duplicate event route
485
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
486
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
487
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
488
+	 * After duplication the redirect is to the new event edit page.
489
+	 *
490
+	 * @return void
491
+	 * @access protected
492
+	 * @throws EE_Error If EE_Event is not available with given ID
493
+	 */
494
+	protected function _duplicate_event()
495
+	{
496
+		// first make sure the ID for the event is in the request.
497
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
498
+		if ( ! isset($this->_req_data['EVT_ID'])) {
499
+			EE_Error::add_error(
500
+				esc_html__(
501
+					'In order to duplicate an event an Event ID is required.  None was given.',
502
+					'event_espresso'
503
+				),
504
+				__FILE__,
505
+				__FUNCTION__,
506
+				__LINE__
507
+			);
508
+			$this->_redirect_after_action(false, '', '', array(), true);
509
+			return;
510
+		}
511
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
512
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
513
+		if ( ! $orig_event instanceof EE_Event) {
514
+			throw new EE_Error(
515
+				sprintf(
516
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
517
+					$this->_req_data['EVT_ID']
518
+				)
519
+			);
520
+		}
521
+		//k now let's clone the $orig_event before getting relations
522
+		$new_event = clone $orig_event;
523
+		//original datetimes
524
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
525
+		//other original relations
526
+		$orig_ven = $orig_event->get_many_related('Venue');
527
+		//reset the ID and modify other details to make it clear this is a dupe
528
+		$new_event->set('EVT_ID', 0);
529
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
530
+		$new_event->set('EVT_name', $new_name);
531
+		$new_event->set(
532
+			'EVT_slug',
533
+			wp_unique_post_slug(
534
+				sanitize_title($orig_event->name()),
535
+				0,
536
+				'publish',
537
+				'espresso_events',
538
+				0
539
+			)
540
+		);
541
+		$new_event->set('status', 'draft');
542
+		//duplicate discussion settings
543
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
544
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
545
+		//save the new event
546
+		$new_event->save();
547
+		//venues
548
+		foreach ($orig_ven as $ven) {
549
+			$new_event->_add_relation_to($ven, 'Venue');
550
+		}
551
+		$new_event->save();
552
+		//now we need to get the question group relations and handle that
553
+		//first primary question groups
554
+		$orig_primary_qgs = $orig_event->get_many_related(
555
+			'Question_Group',
556
+			array(array('Event_Question_Group.EQG_primary' => 1))
557
+		);
558
+		if ( ! empty($orig_primary_qgs)) {
559
+			foreach ($orig_primary_qgs as $id => $obj) {
560
+				if ($obj instanceof EE_Question_Group) {
561
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
562
+				}
563
+			}
564
+		}
565
+		//next additional attendee question groups
566
+		$orig_additional_qgs = $orig_event->get_many_related(
567
+			'Question_Group',
568
+			array(array('Event_Question_Group.EQG_primary' => 0))
569
+		);
570
+		if ( ! empty($orig_additional_qgs)) {
571
+			foreach ($orig_additional_qgs as $id => $obj) {
572
+				if ($obj instanceof EE_Question_Group) {
573
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
574
+				}
575
+			}
576
+		}
577
+		//now save
578
+		$new_event->save();
579
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
580
+		$cloned_tickets = array();
581
+		foreach ($orig_datetimes as $orig_dtt) {
582
+			if ( ! $orig_dtt instanceof EE_Datetime) {
583
+				continue;
584
+			}
585
+			$new_dtt   = clone $orig_dtt;
586
+			$orig_tkts = $orig_dtt->tickets();
587
+			//save new dtt then add to event
588
+			$new_dtt->set('DTT_ID', 0);
589
+			$new_dtt->set('DTT_sold', 0);
590
+			$new_dtt->save();
591
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
592
+			$new_event->save();
593
+			//now let's get the ticket relations setup.
594
+			foreach ((array)$orig_tkts as $orig_tkt) {
595
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
596
+				if ( ! $orig_tkt instanceof EE_Ticket) {
597
+					continue;
598
+				}
599
+				//is this ticket archived?  If it is then let's skip
600
+				if ($orig_tkt->get('TKT_deleted')) {
601
+					continue;
602
+				}
603
+				// does this original ticket already exist in the clone_tickets cache?
604
+				//  If so we'll just use the new ticket from it.
605
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
606
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
607
+				} else {
608
+					$new_tkt = clone $orig_tkt;
609
+					//get relations on the $orig_tkt that we need to setup.
610
+					$orig_prices = $orig_tkt->prices();
611
+					$new_tkt->set('TKT_ID', 0);
612
+					$new_tkt->set('TKT_sold', 0);
613
+					$new_tkt->set('TKT_reserved', 0);
614
+					$new_tkt->save(); //make sure new ticket has ID.
615
+					//price relations on new ticket need to be setup.
616
+					foreach ($orig_prices as $orig_price) {
617
+						$new_price = clone $orig_price;
618
+						$new_price->set('PRC_ID', 0);
619
+						$new_price->save();
620
+						$new_tkt->_add_relation_to($new_price, 'Price');
621
+						$new_tkt->save();
622
+					}
623
+				}
624
+				// k now we can add the new ticket as a relation to the new datetime
625
+				// and make sure its added to our cached $cloned_tickets array
626
+				// for use with later datetimes that have the same ticket.
627
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
628
+				$new_dtt->save();
629
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
630
+			}
631
+		}
632
+		//clone taxonomy information
633
+		$taxonomies_to_clone_with = apply_filters(
634
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
635
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
636
+		);
637
+		//get terms for original event (notice)
638
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
639
+		//loop through terms and add them to new event.
640
+		foreach ($orig_terms as $term) {
641
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
642
+		}
643
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
644
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
645
+		if ($new_event->ID()) {
646
+			$redirect_args = array(
647
+				'post'   => $new_event->ID(),
648
+				'action' => 'edit',
649
+			);
650
+			EE_Error::add_success(
651
+				esc_html__(
652
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
653
+					'event_espresso'
654
+				)
655
+			);
656
+		} else {
657
+			$redirect_args = array(
658
+				'action' => 'default',
659
+			);
660
+			EE_Error::add_error(
661
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
662
+				__FILE__,
663
+				__FUNCTION__,
664
+				__LINE__
665
+			);
666
+		}
667
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
668
+	}
669 669
     
670 670
     
671
-    protected function _import_page()
672
-    {
673
-        $title                                      = esc_html__('Import', 'event_espresso');
674
-        $intro                                      = esc_html__(
675
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
676
-            'event_espresso'
677
-        );
678
-        $form_url                                   = EVENTS_ADMIN_URL;
679
-        $action                                     = 'import_events';
680
-        $type                                       = 'csv';
681
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
682
-            $title, $intro, $form_url, $action, $type
683
-        );
684
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
685
-            array('action' => 'sample_export_file'),
686
-            $this->_admin_base_url
687
-        );
688
-        $content                                    = EEH_Template::display_template(
689
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
690
-            $this->_template_args,
691
-            true
692
-        );
693
-        $this->_template_args['admin_page_content'] = $content;
694
-        $this->display_admin_page_with_sidebar();
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     * _import_events
701
-     * This handles displaying the screen and running imports for importing events.
702
-     *
703
-     * @return void
704
-     */
705
-    protected function _import_events()
706
-    {
707
-        require_once(EE_CLASSES . 'EE_Import.class.php');
708
-        $success = EE_Import::instance()->import();
709
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
710
-    }
711
-
712
-
713
-
714
-    /**
715
-     * _events_export
716
-     * Will export all (or just the given event) to a Excel compatible file.
717
-     *
718
-     * @access protected
719
-     * @return void
720
-     */
721
-    protected function _events_export()
722
-    {
723
-        if (isset($this->_req_data['EVT_ID'])) {
724
-            $event_ids = $this->_req_data['EVT_ID'];
725
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
726
-            $event_ids = $this->_req_data['EVT_IDs'];
727
-        } else {
728
-            $event_ids = null;
729
-        }
730
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
731
-        $new_request_args = array(
732
-            'export' => 'report',
733
-            'action' => 'all_event_data',
734
-            'EVT_ID' => $event_ids,
735
-        );
736
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
737
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
738
-            require_once(EE_CLASSES . 'EE_Export.class.php');
739
-            $EE_Export = EE_Export::instance($this->_req_data);
740
-            $EE_Export->export();
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * handle category exports()
748
-     *
749
-     * @return void
750
-     */
751
-    protected function _categories_export()
752
-    {
753
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
754
-        $new_request_args = array(
755
-            'export'       => 'report',
756
-            'action'       => 'categories',
757
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
758
-        );
759
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
760
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
761
-            require_once(EE_CLASSES . 'EE_Export.class.php');
762
-            $EE_Export = EE_Export::instance($this->_req_data);
763
-            $EE_Export->export();
764
-        }
765
-    }
766
-
767
-
768
-
769
-    /**
770
-     * Creates a sample CSV file for importing
771
-     */
772
-    protected function _sample_export_file()
773
-    {
774
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
775
-        EE_Export::instance()->export_sample();
776
-    }
777
-
778
-
779
-
780
-    /*************        Template Settings        *************/
781
-    protected function _template_settings()
782
-    {
783
-        $this->_template_args['values'] = $this->_yes_no_values;
784
-        /**
785
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
786
-         * from General_Settings_Admin_Page to here.
787
-         */
788
-        $this->_template_args = apply_filters(
789
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
790
-            $this->_template_args
791
-        );
792
-        $this->_set_add_edit_form_tags('update_template_settings');
793
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
794
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
795
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
796
-            $this->_template_args,
797
-            true
798
-        );
799
-        $this->display_admin_page_with_sidebar();
800
-    }
801
-
802
-
803
-
804
-    protected function _update_template_settings()
805
-    {
806
-        /**
807
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
808
-         * from General_Settings_Admin_Page to here.
809
-         */
810
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
811
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
812
-            EE_Registry::instance()->CFG->template_settings,
813
-            $this->_req_data
814
-        );
815
-        //update custom post type slugs and detect if we need to flush rewrite rules
816
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
817
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
818
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
819
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
820
-        $what                                              = 'Template Settings';
821
-        $success                                           = $this->_update_espresso_configuration(
822
-            $what,
823
-            EE_Registry::instance()->CFG->template_settings,
824
-            __FILE__,
825
-            __FUNCTION__,
826
-            __LINE__
827
-        );
828
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
829
-            update_option('ee_flush_rewrite_rules', true);
830
-        }
831
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
832
-    }
833
-
834
-
835
-
836
-    /**
837
-     * _premium_event_editor_meta_boxes
838
-     * add all metaboxes related to the event_editor
839
-     *
840
-     * @access protected
841
-     * @return void
842
-     */
843
-    protected function _premium_event_editor_meta_boxes()
844
-    {
845
-        $this->verify_cpt_object();
846
-        add_meta_box(
847
-            'espresso_event_editor_event_options',
848
-            esc_html__('Event Registration Options', 'event_espresso'),
849
-            array($this, 'registration_options_meta_box'),
850
-            $this->page_slug,
851
-            'side',
852
-            'core'
853
-        );
854
-    }
855
-
856
-
857
-
858
-    /**
859
-     * override caf metabox
860
-     *
861
-     * @return void
862
-     */
863
-    public function registration_options_meta_box()
864
-    {
865
-        $yes_no_values = array(
866
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
867
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
868
-        );
869
-        $default_reg_status_values = EEM_Registration::reg_status_array(
870
-            array(
871
-                EEM_Registration::status_id_cancelled,
872
-                EEM_Registration::status_id_declined,
873
-                EEM_Registration::status_id_incomplete,
874
-                EEM_Registration::status_id_wait_list,
875
-            ),
876
-            true
877
-        );
878
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
879
-        $template_args['_event']                          = $this->_cpt_model_obj;
880
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
881
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
882
-            'default_reg_status',
883
-            $default_reg_status_values,
884
-            $this->_cpt_model_obj->default_registration_status()
885
-        );
886
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
887
-            'display_desc',
888
-            $yes_no_values,
889
-            $this->_cpt_model_obj->display_description()
890
-        );
891
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
892
-            'display_ticket_selector',
893
-            $yes_no_values,
894
-            $this->_cpt_model_obj->display_ticket_selector(),
895
-            '',
896
-            '',
897
-            false
898
-        );
899
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
900
-            'EVT_default_registration_status',
901
-            $default_reg_status_values,
902
-            $this->_cpt_model_obj->default_registration_status()
903
-        );
904
-        $template_args['additional_registration_options'] = apply_filters(
905
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
906
-            '',
907
-            $template_args,
908
-            $yes_no_values,
909
-            $default_reg_status_values
910
-        );
911
-        EEH_Template::display_template(
912
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
913
-            $template_args
914
-        );
915
-    }
916
-
917
-
918
-
919
-    /**
920
-     * wp_list_table_mods for caf
921
-     * ============================
922
-     */
923
-    /**
924
-     * hook into list table filters and provide filters for caffeinated list table
925
-     *
926
-     * @param  array $old_filters    any existing filters present
927
-     * @param  array $list_table_obj the list table object
928
-     * @return array                  new filters
929
-     */
930
-    public function list_table_filters($old_filters, $list_table_obj)
931
-    {
932
-        $filters = array();
933
-        //first month/year filters
934
-        $filters[] = $this->espresso_event_months_dropdown();
935
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
936
-        //active status dropdown
937
-        if ($status !== 'draft') {
938
-            $filters[] = $this->active_status_dropdown(
939
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
940
-            );
941
-        }
942
-        //category filter
943
-        $filters[] = $this->category_dropdown();
944
-        return array_merge($old_filters, $filters);
945
-    }
946
-
947
-
948
-
949
-    /**
950
-     * espresso_event_months_dropdown
951
-     *
952
-     * @access public
953
-     * @return string                dropdown listing month/year selections for events.
954
-     */
955
-    public function espresso_event_months_dropdown()
956
-    {
957
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
958
-        // Note we need to include any other filters that are set!
959
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
960
-        //categories?
961
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
962
-            ? $this->_req_data['EVT_CAT']
963
-            : null;
964
-        //active status?
965
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
966
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
967
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
968
-    }
969
-
970
-
971
-
972
-    /**
973
-     * returns a list of "active" statuses on the event
974
-     *
975
-     * @param  string $current_value whatever the current active status is
976
-     * @return string
977
-     */
978
-    public function active_status_dropdown($current_value = '')
979
-    {
980
-        $select_name = 'active_status';
981
-        $values      = array(
982
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
983
-            'active'   => esc_html__('Active', 'event_espresso'),
984
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
985
-            'expired'  => esc_html__('Expired', 'event_espresso'),
986
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
987
-        );
988
-        $id          = 'id="espresso-active-status-dropdown-filter"';
989
-        $class       = 'wide';
990
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
991
-    }
992
-
993
-
994
-
995
-    /**
996
-     * output a dropdown of the categories for the category filter on the event admin list table
997
-     *
998
-     * @access  public
999
-     * @return string html
1000
-     */
1001
-    public function category_dropdown()
1002
-    {
1003
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1004
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1005
-    }
1006
-
1007
-
1008
-
1009
-    /**
1010
-     * get total number of events today
1011
-     *
1012
-     * @access public
1013
-     * @return int
1014
-     */
1015
-    public function total_events_today()
1016
-    {
1017
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1018
-            'DTT_EVT_start',
1019
-            date('Y-m-d') . ' 00:00:00',
1020
-            'Y-m-d H:i:s',
1021
-            'UTC'
1022
-        );
1023
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1024
-            'DTT_EVT_start',
1025
-            date('Y-m-d') . ' 23:59:59',
1026
-            'Y-m-d H:i:s',
1027
-            'UTC'
1028
-        );
1029
-        $where = array(
1030
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1031
-        );
1032
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1033
-        return $count;
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     * get total number of events this month
1040
-     *
1041
-     * @access public
1042
-     * @return int
1043
-     */
1044
-    public function total_events_this_month()
1045
-    {
1046
-        //Dates
1047
-        $this_year_r     = date('Y');
1048
-        $this_month_r    = date('m');
1049
-        $days_this_month = date('t');
1050
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1051
-            'DTT_EVT_start',
1052
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1053
-            'Y-m-d H:i:s',
1054
-            'UTC'
1055
-        );
1056
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1057
-            'DTT_EVT_start',
1058
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1059
-            'Y-m-d H:i:s',
1060
-            'UTC'
1061
-        );
1062
-        $where = array(
1063
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1064
-        );
1065
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1066
-        return $count;
1067
-    }
1068
-
1069
-
1070
-
1071
-    /** DEFAULT TICKETS STUFF **/
1072
-    public function _tickets_overview_list_table()
1073
-    {
1074
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1075
-        $this->display_admin_list_table_page_with_no_sidebar();
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * @param int  $per_page
1082
-     * @param bool $count
1083
-     * @param bool $trashed
1084
-     * @return \EE_Soft_Delete_Base_Class[]|int
1085
-     */
1086
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1087
-    {
1088
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1089
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1090
-        switch ($orderby) {
1091
-            case 'TKT_name' :
1092
-                $orderby = array('TKT_name' => $order);
1093
-                break;
1094
-            case 'TKT_price' :
1095
-                $orderby = array('TKT_price' => $order);
1096
-                break;
1097
-            case 'TKT_uses' :
1098
-                $orderby = array('TKT_uses' => $order);
1099
-                break;
1100
-            case 'TKT_min' :
1101
-                $orderby = array('TKT_min' => $order);
1102
-                break;
1103
-            case 'TKT_max' :
1104
-                $orderby = array('TKT_max' => $order);
1105
-                break;
1106
-            case 'TKT_qty' :
1107
-                $orderby = array('TKT_qty' => $order);
1108
-                break;
1109
-        }
1110
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1111
-            ? $this->_req_data['paged']
1112
-            : 1;
1113
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1114
-            ? $this->_req_data['perpage']
1115
-            : $per_page;
1116
-        $_where       = array(
1117
-            'TKT_is_default' => 1,
1118
-            'TKT_deleted'    => $trashed,
1119
-        );
1120
-        $offset       = ($current_page - 1) * $per_page;
1121
-        $limit        = array($offset, $per_page);
1122
-        if (isset($this->_req_data['s'])) {
1123
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1124
-            $_where['OR'] = array(
1125
-                'TKT_name'        => array('LIKE', $sstr),
1126
-                'TKT_description' => array('LIKE', $sstr),
1127
-            );
1128
-        }
1129
-        $query_params = array(
1130
-            $_where,
1131
-            'order_by' => $orderby,
1132
-            'limit'    => $limit,
1133
-            'group_by' => 'TKT_ID',
1134
-        );
1135
-        if ($count) {
1136
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1137
-        } else {
1138
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1139
-        }
1140
-    }
1141
-
1142
-
1143
-
1144
-    /**
1145
-     * @param bool $trash
1146
-     */
1147
-    protected function _trash_or_restore_ticket($trash = false)
1148
-    {
1149
-        $success = 1;
1150
-        $TKT = EEM_Ticket::instance();
1151
-        //checkboxes?
1152
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1153
-            //if array has more than one element then success message should be plural
1154
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1155
-            //cycle thru the boxes
1156
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1157
-                if ($trash) {
1158
-                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1159
-                        $success = 0;
1160
-                    }
1161
-                } else {
1162
-                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1163
-                        $success = 0;
1164
-                    }
1165
-                }
1166
-            }
1167
-        } else {
1168
-            //grab single id and trash
1169
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1170
-            if ($trash) {
1171
-                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1172
-                    $success = 0;
1173
-                }
1174
-            } else {
1175
-                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1176
-                    $success = 0;
1177
-                }
1178
-            }
1179
-        }
1180
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1181
-        $query_args  = array(
1182
-            'action' => 'ticket_list_table',
1183
-            'status' => $trash ? '' : 'trashed',
1184
-        );
1185
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1186
-    }
1187
-
1188
-
1189
-
1190
-    protected function _delete_ticket()
1191
-    {
1192
-        $success = 1;
1193
-        //checkboxes?
1194
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1195
-            //if array has more than one element then success message should be plural
1196
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1197
-            //cycle thru the boxes
1198
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1199
-                //delete
1200
-                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1201
-                    $success = 0;
1202
-                }
1203
-            }
1204
-        } else {
1205
-            //grab single id and trash
1206
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1207
-            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1208
-                $success = 0;
1209
-            }
1210
-        }
1211
-        $action_desc = 'deleted';
1212
-        $query_args  = array(
1213
-            'action' => 'ticket_list_table',
1214
-            'status' => 'trashed',
1215
-        );
1216
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1217
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1218
-            array(array('TKT_is_default' => 1)),
1219
-            'TKT_ID',
1220
-            true
1221
-        )
1222
-        ) {
1223
-            $query_args = array();
1224
-        }
1225
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1226
-    }
1227
-
1228
-
1229
-
1230
-    /**
1231
-     * @param int $TKT_ID
1232
-     * @return bool|int
1233
-     */
1234
-    protected function _delete_the_ticket($TKT_ID)
1235
-    {
1236
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1237
-        $tkt->_remove_relations('Datetime');
1238
-        //delete all related prices first
1239
-        $tkt->delete_related_permanently('Price');
1240
-        return $tkt->delete_permanently();
1241
-    }
671
+	protected function _import_page()
672
+	{
673
+		$title                                      = esc_html__('Import', 'event_espresso');
674
+		$intro                                      = esc_html__(
675
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
676
+			'event_espresso'
677
+		);
678
+		$form_url                                   = EVENTS_ADMIN_URL;
679
+		$action                                     = 'import_events';
680
+		$type                                       = 'csv';
681
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
682
+			$title, $intro, $form_url, $action, $type
683
+		);
684
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
685
+			array('action' => 'sample_export_file'),
686
+			$this->_admin_base_url
687
+		);
688
+		$content                                    = EEH_Template::display_template(
689
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
690
+			$this->_template_args,
691
+			true
692
+		);
693
+		$this->_template_args['admin_page_content'] = $content;
694
+		$this->display_admin_page_with_sidebar();
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 * _import_events
701
+	 * This handles displaying the screen and running imports for importing events.
702
+	 *
703
+	 * @return void
704
+	 */
705
+	protected function _import_events()
706
+	{
707
+		require_once(EE_CLASSES . 'EE_Import.class.php');
708
+		$success = EE_Import::instance()->import();
709
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
710
+	}
711
+
712
+
713
+
714
+	/**
715
+	 * _events_export
716
+	 * Will export all (or just the given event) to a Excel compatible file.
717
+	 *
718
+	 * @access protected
719
+	 * @return void
720
+	 */
721
+	protected function _events_export()
722
+	{
723
+		if (isset($this->_req_data['EVT_ID'])) {
724
+			$event_ids = $this->_req_data['EVT_ID'];
725
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
726
+			$event_ids = $this->_req_data['EVT_IDs'];
727
+		} else {
728
+			$event_ids = null;
729
+		}
730
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
731
+		$new_request_args = array(
732
+			'export' => 'report',
733
+			'action' => 'all_event_data',
734
+			'EVT_ID' => $event_ids,
735
+		);
736
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
737
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
738
+			require_once(EE_CLASSES . 'EE_Export.class.php');
739
+			$EE_Export = EE_Export::instance($this->_req_data);
740
+			$EE_Export->export();
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * handle category exports()
748
+	 *
749
+	 * @return void
750
+	 */
751
+	protected function _categories_export()
752
+	{
753
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
754
+		$new_request_args = array(
755
+			'export'       => 'report',
756
+			'action'       => 'categories',
757
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
758
+		);
759
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
760
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
761
+			require_once(EE_CLASSES . 'EE_Export.class.php');
762
+			$EE_Export = EE_Export::instance($this->_req_data);
763
+			$EE_Export->export();
764
+		}
765
+	}
766
+
767
+
768
+
769
+	/**
770
+	 * Creates a sample CSV file for importing
771
+	 */
772
+	protected function _sample_export_file()
773
+	{
774
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
775
+		EE_Export::instance()->export_sample();
776
+	}
777
+
778
+
779
+
780
+	/*************        Template Settings        *************/
781
+	protected function _template_settings()
782
+	{
783
+		$this->_template_args['values'] = $this->_yes_no_values;
784
+		/**
785
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
786
+		 * from General_Settings_Admin_Page to here.
787
+		 */
788
+		$this->_template_args = apply_filters(
789
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
790
+			$this->_template_args
791
+		);
792
+		$this->_set_add_edit_form_tags('update_template_settings');
793
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
794
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
795
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
796
+			$this->_template_args,
797
+			true
798
+		);
799
+		$this->display_admin_page_with_sidebar();
800
+	}
801
+
802
+
803
+
804
+	protected function _update_template_settings()
805
+	{
806
+		/**
807
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
808
+		 * from General_Settings_Admin_Page to here.
809
+		 */
810
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
811
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
812
+			EE_Registry::instance()->CFG->template_settings,
813
+			$this->_req_data
814
+		);
815
+		//update custom post type slugs and detect if we need to flush rewrite rules
816
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
817
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
818
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
819
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
820
+		$what                                              = 'Template Settings';
821
+		$success                                           = $this->_update_espresso_configuration(
822
+			$what,
823
+			EE_Registry::instance()->CFG->template_settings,
824
+			__FILE__,
825
+			__FUNCTION__,
826
+			__LINE__
827
+		);
828
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
829
+			update_option('ee_flush_rewrite_rules', true);
830
+		}
831
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
832
+	}
833
+
834
+
835
+
836
+	/**
837
+	 * _premium_event_editor_meta_boxes
838
+	 * add all metaboxes related to the event_editor
839
+	 *
840
+	 * @access protected
841
+	 * @return void
842
+	 */
843
+	protected function _premium_event_editor_meta_boxes()
844
+	{
845
+		$this->verify_cpt_object();
846
+		add_meta_box(
847
+			'espresso_event_editor_event_options',
848
+			esc_html__('Event Registration Options', 'event_espresso'),
849
+			array($this, 'registration_options_meta_box'),
850
+			$this->page_slug,
851
+			'side',
852
+			'core'
853
+		);
854
+	}
855
+
856
+
857
+
858
+	/**
859
+	 * override caf metabox
860
+	 *
861
+	 * @return void
862
+	 */
863
+	public function registration_options_meta_box()
864
+	{
865
+		$yes_no_values = array(
866
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
867
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
868
+		);
869
+		$default_reg_status_values = EEM_Registration::reg_status_array(
870
+			array(
871
+				EEM_Registration::status_id_cancelled,
872
+				EEM_Registration::status_id_declined,
873
+				EEM_Registration::status_id_incomplete,
874
+				EEM_Registration::status_id_wait_list,
875
+			),
876
+			true
877
+		);
878
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
879
+		$template_args['_event']                          = $this->_cpt_model_obj;
880
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
881
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
882
+			'default_reg_status',
883
+			$default_reg_status_values,
884
+			$this->_cpt_model_obj->default_registration_status()
885
+		);
886
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
887
+			'display_desc',
888
+			$yes_no_values,
889
+			$this->_cpt_model_obj->display_description()
890
+		);
891
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
892
+			'display_ticket_selector',
893
+			$yes_no_values,
894
+			$this->_cpt_model_obj->display_ticket_selector(),
895
+			'',
896
+			'',
897
+			false
898
+		);
899
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
900
+			'EVT_default_registration_status',
901
+			$default_reg_status_values,
902
+			$this->_cpt_model_obj->default_registration_status()
903
+		);
904
+		$template_args['additional_registration_options'] = apply_filters(
905
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
906
+			'',
907
+			$template_args,
908
+			$yes_no_values,
909
+			$default_reg_status_values
910
+		);
911
+		EEH_Template::display_template(
912
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
913
+			$template_args
914
+		);
915
+	}
916
+
917
+
918
+
919
+	/**
920
+	 * wp_list_table_mods for caf
921
+	 * ============================
922
+	 */
923
+	/**
924
+	 * hook into list table filters and provide filters for caffeinated list table
925
+	 *
926
+	 * @param  array $old_filters    any existing filters present
927
+	 * @param  array $list_table_obj the list table object
928
+	 * @return array                  new filters
929
+	 */
930
+	public function list_table_filters($old_filters, $list_table_obj)
931
+	{
932
+		$filters = array();
933
+		//first month/year filters
934
+		$filters[] = $this->espresso_event_months_dropdown();
935
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
936
+		//active status dropdown
937
+		if ($status !== 'draft') {
938
+			$filters[] = $this->active_status_dropdown(
939
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
940
+			);
941
+		}
942
+		//category filter
943
+		$filters[] = $this->category_dropdown();
944
+		return array_merge($old_filters, $filters);
945
+	}
946
+
947
+
948
+
949
+	/**
950
+	 * espresso_event_months_dropdown
951
+	 *
952
+	 * @access public
953
+	 * @return string                dropdown listing month/year selections for events.
954
+	 */
955
+	public function espresso_event_months_dropdown()
956
+	{
957
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
958
+		// Note we need to include any other filters that are set!
959
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
960
+		//categories?
961
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
962
+			? $this->_req_data['EVT_CAT']
963
+			: null;
964
+		//active status?
965
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
966
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
967
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
968
+	}
969
+
970
+
971
+
972
+	/**
973
+	 * returns a list of "active" statuses on the event
974
+	 *
975
+	 * @param  string $current_value whatever the current active status is
976
+	 * @return string
977
+	 */
978
+	public function active_status_dropdown($current_value = '')
979
+	{
980
+		$select_name = 'active_status';
981
+		$values      = array(
982
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
983
+			'active'   => esc_html__('Active', 'event_espresso'),
984
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
985
+			'expired'  => esc_html__('Expired', 'event_espresso'),
986
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
987
+		);
988
+		$id          = 'id="espresso-active-status-dropdown-filter"';
989
+		$class       = 'wide';
990
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
991
+	}
992
+
993
+
994
+
995
+	/**
996
+	 * output a dropdown of the categories for the category filter on the event admin list table
997
+	 *
998
+	 * @access  public
999
+	 * @return string html
1000
+	 */
1001
+	public function category_dropdown()
1002
+	{
1003
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1004
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1005
+	}
1006
+
1007
+
1008
+
1009
+	/**
1010
+	 * get total number of events today
1011
+	 *
1012
+	 * @access public
1013
+	 * @return int
1014
+	 */
1015
+	public function total_events_today()
1016
+	{
1017
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1018
+			'DTT_EVT_start',
1019
+			date('Y-m-d') . ' 00:00:00',
1020
+			'Y-m-d H:i:s',
1021
+			'UTC'
1022
+		);
1023
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1024
+			'DTT_EVT_start',
1025
+			date('Y-m-d') . ' 23:59:59',
1026
+			'Y-m-d H:i:s',
1027
+			'UTC'
1028
+		);
1029
+		$where = array(
1030
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1031
+		);
1032
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1033
+		return $count;
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 * get total number of events this month
1040
+	 *
1041
+	 * @access public
1042
+	 * @return int
1043
+	 */
1044
+	public function total_events_this_month()
1045
+	{
1046
+		//Dates
1047
+		$this_year_r     = date('Y');
1048
+		$this_month_r    = date('m');
1049
+		$days_this_month = date('t');
1050
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1051
+			'DTT_EVT_start',
1052
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1053
+			'Y-m-d H:i:s',
1054
+			'UTC'
1055
+		);
1056
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1057
+			'DTT_EVT_start',
1058
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1059
+			'Y-m-d H:i:s',
1060
+			'UTC'
1061
+		);
1062
+		$where = array(
1063
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1064
+		);
1065
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1066
+		return $count;
1067
+	}
1068
+
1069
+
1070
+
1071
+	/** DEFAULT TICKETS STUFF **/
1072
+	public function _tickets_overview_list_table()
1073
+	{
1074
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1075
+		$this->display_admin_list_table_page_with_no_sidebar();
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * @param int  $per_page
1082
+	 * @param bool $count
1083
+	 * @param bool $trashed
1084
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1085
+	 */
1086
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1087
+	{
1088
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1089
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1090
+		switch ($orderby) {
1091
+			case 'TKT_name' :
1092
+				$orderby = array('TKT_name' => $order);
1093
+				break;
1094
+			case 'TKT_price' :
1095
+				$orderby = array('TKT_price' => $order);
1096
+				break;
1097
+			case 'TKT_uses' :
1098
+				$orderby = array('TKT_uses' => $order);
1099
+				break;
1100
+			case 'TKT_min' :
1101
+				$orderby = array('TKT_min' => $order);
1102
+				break;
1103
+			case 'TKT_max' :
1104
+				$orderby = array('TKT_max' => $order);
1105
+				break;
1106
+			case 'TKT_qty' :
1107
+				$orderby = array('TKT_qty' => $order);
1108
+				break;
1109
+		}
1110
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1111
+			? $this->_req_data['paged']
1112
+			: 1;
1113
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1114
+			? $this->_req_data['perpage']
1115
+			: $per_page;
1116
+		$_where       = array(
1117
+			'TKT_is_default' => 1,
1118
+			'TKT_deleted'    => $trashed,
1119
+		);
1120
+		$offset       = ($current_page - 1) * $per_page;
1121
+		$limit        = array($offset, $per_page);
1122
+		if (isset($this->_req_data['s'])) {
1123
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1124
+			$_where['OR'] = array(
1125
+				'TKT_name'        => array('LIKE', $sstr),
1126
+				'TKT_description' => array('LIKE', $sstr),
1127
+			);
1128
+		}
1129
+		$query_params = array(
1130
+			$_where,
1131
+			'order_by' => $orderby,
1132
+			'limit'    => $limit,
1133
+			'group_by' => 'TKT_ID',
1134
+		);
1135
+		if ($count) {
1136
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1137
+		} else {
1138
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1139
+		}
1140
+	}
1141
+
1142
+
1143
+
1144
+	/**
1145
+	 * @param bool $trash
1146
+	 */
1147
+	protected function _trash_or_restore_ticket($trash = false)
1148
+	{
1149
+		$success = 1;
1150
+		$TKT = EEM_Ticket::instance();
1151
+		//checkboxes?
1152
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1153
+			//if array has more than one element then success message should be plural
1154
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1155
+			//cycle thru the boxes
1156
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1157
+				if ($trash) {
1158
+					if ( ! $TKT->delete_by_ID($TKT_ID)) {
1159
+						$success = 0;
1160
+					}
1161
+				} else {
1162
+					if ( ! $TKT->restore_by_ID($TKT_ID)) {
1163
+						$success = 0;
1164
+					}
1165
+				}
1166
+			}
1167
+		} else {
1168
+			//grab single id and trash
1169
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1170
+			if ($trash) {
1171
+				if ( ! $TKT->delete_by_ID($TKT_ID)) {
1172
+					$success = 0;
1173
+				}
1174
+			} else {
1175
+				if ( ! $TKT->restore_by_ID($TKT_ID)) {
1176
+					$success = 0;
1177
+				}
1178
+			}
1179
+		}
1180
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1181
+		$query_args  = array(
1182
+			'action' => 'ticket_list_table',
1183
+			'status' => $trash ? '' : 'trashed',
1184
+		);
1185
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1186
+	}
1187
+
1188
+
1189
+
1190
+	protected function _delete_ticket()
1191
+	{
1192
+		$success = 1;
1193
+		//checkboxes?
1194
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1195
+			//if array has more than one element then success message should be plural
1196
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1197
+			//cycle thru the boxes
1198
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1199
+				//delete
1200
+				if ( ! $this->_delete_the_ticket($TKT_ID)) {
1201
+					$success = 0;
1202
+				}
1203
+			}
1204
+		} else {
1205
+			//grab single id and trash
1206
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1207
+			if ( ! $this->_delete_the_ticket($TKT_ID)) {
1208
+				$success = 0;
1209
+			}
1210
+		}
1211
+		$action_desc = 'deleted';
1212
+		$query_args  = array(
1213
+			'action' => 'ticket_list_table',
1214
+			'status' => 'trashed',
1215
+		);
1216
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1217
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1218
+			array(array('TKT_is_default' => 1)),
1219
+			'TKT_ID',
1220
+			true
1221
+		)
1222
+		) {
1223
+			$query_args = array();
1224
+		}
1225
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1226
+	}
1227
+
1228
+
1229
+
1230
+	/**
1231
+	 * @param int $TKT_ID
1232
+	 * @return bool|int
1233
+	 */
1234
+	protected function _delete_the_ticket($TKT_ID)
1235
+	{
1236
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1237
+		$tkt->_remove_relations('Datetime');
1238
+		//delete all related prices first
1239
+		$tkt->delete_related_permanently('Price');
1240
+		return $tkt->delete_permanently();
1241
+	}
1242 1242
 
1243 1243
 
1244 1244
 
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
     {
26 26
         parent::__construct($routing);
27 27
         if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
28
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
29
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
30
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
31 31
         }
32 32
     }
33 33
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
     protected function _extend_page_config()
37 37
     {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
38
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
39 39
         //is there a evt_id in the request?
40 40
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41 41
             ? $this->_req_data['EVT_ID']
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273 273
         //make sure this is only when editing
274 274
         if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
275
+            $href = EE_Admin_Page::add_query_args_and_nonce(
276 276
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
277 277
                 $this->_admin_base_url
278 278
             );
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
     {
320 320
         wp_register_script(
321 321
             'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
322
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
323 323
             array('ee_admin_js', 'heartbeat'),
324 324
             EVENT_ESPRESSO_VERSION,
325 325
             true
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
     public function add_additional_datetime_button($template, $template_args)
345 345
     {
346 346
         return EEH_Template::display_template(
347
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
347
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
348 348
             $template_args,
349 349
             true
350 350
         );
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
     public function add_datetime_clone_button($template, $template_args)
361 361
     {
362 362
         return EEH_Template::display_template(
363
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
363
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
364 364
             $template_args,
365 365
             true
366 366
         );
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
     public function datetime_timezones_template($template, $template_args)
377 377
     {
378 378
         return EEH_Template::display_template(
379
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
379
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
380 380
             $template_args,
381 381
             true
382 382
         );
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
         $orig_ven = $orig_event->get_many_related('Venue');
527 527
         //reset the ID and modify other details to make it clear this is a dupe
528 528
         $new_event->set('EVT_ID', 0);
529
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
529
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
530 530
         $new_event->set('EVT_name', $new_name);
531 531
         $new_event->set(
532 532
             'EVT_slug',
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
             $new_event->_add_relation_to($new_dtt, 'Datetime');
592 592
             $new_event->save();
593 593
             //now let's get the ticket relations setup.
594
-            foreach ((array)$orig_tkts as $orig_tkt) {
594
+            foreach ((array) $orig_tkts as $orig_tkt) {
595 595
                 //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
596 596
                 if ( ! $orig_tkt instanceof EE_Ticket) {
597 597
                     continue;
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
             array('action' => 'sample_export_file'),
686 686
             $this->_admin_base_url
687 687
         );
688
-        $content                                    = EEH_Template::display_template(
689
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
688
+        $content = EEH_Template::display_template(
689
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
690 690
             $this->_template_args,
691 691
             true
692 692
         );
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
      */
705 705
     protected function _import_events()
706 706
     {
707
-        require_once(EE_CLASSES . 'EE_Import.class.php');
707
+        require_once(EE_CLASSES.'EE_Import.class.php');
708 708
         $success = EE_Import::instance()->import();
709 709
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
710 710
     }
@@ -733,9 +733,9 @@  discard block
 block discarded – undo
733 733
             'action' => 'all_event_data',
734 734
             'EVT_ID' => $event_ids,
735 735
         );
736
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
737
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
738
-            require_once(EE_CLASSES . 'EE_Export.class.php');
736
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
737
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
738
+            require_once(EE_CLASSES.'EE_Export.class.php');
739 739
             $EE_Export = EE_Export::instance($this->_req_data);
740 740
             $EE_Export->export();
741 741
         }
@@ -756,9 +756,9 @@  discard block
 block discarded – undo
756 756
             'action'       => 'categories',
757 757
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
758 758
         );
759
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
760
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
761
-            require_once(EE_CLASSES . 'EE_Export.class.php');
759
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
760
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
761
+            require_once(EE_CLASSES.'EE_Export.class.php');
762 762
             $EE_Export = EE_Export::instance($this->_req_data);
763 763
             $EE_Export->export();
764 764
         }
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
         $this->_set_add_edit_form_tags('update_template_settings');
793 793
         $this->_set_publish_post_box_vars(null, false, false, null, false);
794 794
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
795
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
795
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
796 796
             $this->_template_args,
797 797
             true
798 798
         );
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
             $default_reg_status_values
910 910
         );
911 911
         EEH_Template::display_template(
912
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
912
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
913 913
             $template_args
914 914
         );
915 915
     }
@@ -1016,13 +1016,13 @@  discard block
 block discarded – undo
1016 1016
     {
1017 1017
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1018 1018
             'DTT_EVT_start',
1019
-            date('Y-m-d') . ' 00:00:00',
1019
+            date('Y-m-d').' 00:00:00',
1020 1020
             'Y-m-d H:i:s',
1021 1021
             'UTC'
1022 1022
         );
1023
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1023
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1024 1024
             'DTT_EVT_start',
1025
-            date('Y-m-d') . ' 23:59:59',
1025
+            date('Y-m-d').' 23:59:59',
1026 1026
             'Y-m-d H:i:s',
1027 1027
             'UTC'
1028 1028
         );
@@ -1049,13 +1049,13 @@  discard block
 block discarded – undo
1049 1049
         $days_this_month = date('t');
1050 1050
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1051 1051
             'DTT_EVT_start',
1052
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1052
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1053 1053
             'Y-m-d H:i:s',
1054 1054
             'UTC'
1055 1055
         );
1056 1056
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1057 1057
             'DTT_EVT_start',
1058
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1058
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1059 1059
             'Y-m-d H:i:s',
1060 1060
             'UTC'
1061 1061
         );
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
         $offset       = ($current_page - 1) * $per_page;
1121 1121
         $limit        = array($offset, $per_page);
1122 1122
         if (isset($this->_req_data['s'])) {
1123
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1123
+            $sstr         = '%'.$this->_req_data['s'].'%';
1124 1124
             $_where['OR'] = array(
1125 1125
                 'TKT_name'        => array('LIKE', $sstr),
1126 1126
                 'TKT_description' => array('LIKE', $sstr),
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     /**
340 340
      * @param $template
341 341
      * @param $template_args
342
-     * @return mixed
342
+     * @return string
343 343
      */
344 344
     public function add_additional_datetime_button($template, $template_args)
345 345
     {
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     /**
356 356
      * @param $template
357 357
      * @param $template_args
358
-     * @return mixed
358
+     * @return string
359 359
      */
360 360
     public function add_datetime_clone_button($template, $template_args)
361 361
     {
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     /**
372 372
      * @param $template
373 373
      * @param $template_args
374
-     * @return mixed
374
+     * @return string
375 375
      */
376 376
     public function datetime_timezones_template($template, $template_args)
377 377
     {
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_List_Shortcodes.lib.php 2 patches
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.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,8 +6,9 @@
 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 13
 /**
13 14
  *
Please login to merge, or discard this patch.