Completed
Branch ENHANCE/255/add-wp-version-to-... (1ced86)
by
unknown
30:38 queued 22:17
created
core/domain/services/pue/StatsGatherer.php 2 patches
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -15,295 +15,295 @@
 block discarded – undo
15 15
 class StatsGatherer
16 16
 {
17 17
 
18
-    const COUNT_ALL_EVENTS = 'event';
19
-    const COUNT_ACTIVE_EVENTS = 'active_event';
20
-    const COUNT_DATETIMES = 'datetime';
21
-    const COUNT_TICKETS = 'ticket';
22
-    const COUNT_DATETIMES_SOLD = 'datetime_sold';
23
-    const COUNT_TICKETS_FREE = 'free_ticket';
24
-    const COUNT_TICKETS_PAID = 'paid_ticket';
25
-    const COUNT_TICKETS_SOLD = 'ticket_sold';
26
-    const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved';
27
-    const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved';
28
-    const COUNT_REGISTRATIONS_PENDING = 'registrations_pending';
29
-    const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete';
30
-    const COUNT_REGISTRATIONS_ALL = 'registrations_all';
31
-    const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled';
32
-    const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined';
33
-    const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum';
34
-    const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid';
35
-    const INFO_SITE_CURRENCY = 'site_currency';
18
+	const COUNT_ALL_EVENTS = 'event';
19
+	const COUNT_ACTIVE_EVENTS = 'active_event';
20
+	const COUNT_DATETIMES = 'datetime';
21
+	const COUNT_TICKETS = 'ticket';
22
+	const COUNT_DATETIMES_SOLD = 'datetime_sold';
23
+	const COUNT_TICKETS_FREE = 'free_ticket';
24
+	const COUNT_TICKETS_PAID = 'paid_ticket';
25
+	const COUNT_TICKETS_SOLD = 'ticket_sold';
26
+	const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved';
27
+	const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved';
28
+	const COUNT_REGISTRATIONS_PENDING = 'registrations_pending';
29
+	const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete';
30
+	const COUNT_REGISTRATIONS_ALL = 'registrations_all';
31
+	const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled';
32
+	const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined';
33
+	const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum';
34
+	const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid';
35
+	const INFO_SITE_CURRENCY = 'site_currency';
36 36
 
37 37
 
38
-    /**
39
-     * @var EEM_Payment_Method
40
-     */
41
-    private $payment_method_model;
38
+	/**
39
+	 * @var EEM_Payment_Method
40
+	 */
41
+	private $payment_method_model;
42 42
 
43 43
 
44
-    /**
45
-     * @var EEM_Event
46
-     */
47
-    private $event_model;
44
+	/**
45
+	 * @var EEM_Event
46
+	 */
47
+	private $event_model;
48 48
 
49
-    /**
50
-     * @var EEM_Datetime
51
-     */
52
-    private $datetime_model;
49
+	/**
50
+	 * @var EEM_Datetime
51
+	 */
52
+	private $datetime_model;
53 53
 
54 54
 
55
-    /**
56
-     * @var EEM_Ticket
57
-     */
58
-    private $ticket_model;
55
+	/**
56
+	 * @var EEM_Ticket
57
+	 */
58
+	private $ticket_model;
59 59
 
60 60
 
61
-    /**
62
-     * @var EEM_Registration
63
-     */
64
-    private $registration_model;
61
+	/**
62
+	 * @var EEM_Registration
63
+	 */
64
+	private $registration_model;
65 65
 
66 66
 
67
-    /**
68
-     * @var EEM_Transaction
69
-     */
70
-    private $transaction_model;
67
+	/**
68
+	 * @var EEM_Transaction
69
+	 */
70
+	private $transaction_model;
71 71
 
72 72
 
73
-    /**
74
-     * @var EE_Config
75
-     */
76
-    private $config;
73
+	/**
74
+	 * @var EE_Config
75
+	 */
76
+	private $config;
77 77
 
78 78
 
79
-    /**
80
-     * StatsGatherer constructor.
81
-     *
82
-     * @param EEM_Payment_Method $payment_method_model
83
-     * @param EEM_Event          $event_model
84
-     * @param EEM_Datetime       $datetime_model
85
-     * @param EEM_Ticket         $ticket_model
86
-     * @param EEM_Registration   $registration_model
87
-     * @param EEM_Transaction    $transaction_model
88
-     * @param EE_Config          $config
89
-     */
90
-    public function __construct(
91
-        EEM_Payment_Method $payment_method_model,
92
-        EEM_Event $event_model,
93
-        EEM_Datetime $datetime_model,
94
-        EEM_Ticket $ticket_model,
95
-        EEM_Registration $registration_model,
96
-        EEM_Transaction $transaction_model,
97
-        EE_Config $config
98
-    ) {
99
-        $this->payment_method_model = $payment_method_model;
100
-        $this->event_model = $event_model;
101
-        $this->datetime_model = $datetime_model;
102
-        $this->ticket_model = $ticket_model;
103
-        $this->registration_model = $registration_model;
104
-        $this->transaction_model = $transaction_model;
105
-        $this->config = $config;
106
-    }
79
+	/**
80
+	 * StatsGatherer constructor.
81
+	 *
82
+	 * @param EEM_Payment_Method $payment_method_model
83
+	 * @param EEM_Event          $event_model
84
+	 * @param EEM_Datetime       $datetime_model
85
+	 * @param EEM_Ticket         $ticket_model
86
+	 * @param EEM_Registration   $registration_model
87
+	 * @param EEM_Transaction    $transaction_model
88
+	 * @param EE_Config          $config
89
+	 */
90
+	public function __construct(
91
+		EEM_Payment_Method $payment_method_model,
92
+		EEM_Event $event_model,
93
+		EEM_Datetime $datetime_model,
94
+		EEM_Ticket $ticket_model,
95
+		EEM_Registration $registration_model,
96
+		EEM_Transaction $transaction_model,
97
+		EE_Config $config
98
+	) {
99
+		$this->payment_method_model = $payment_method_model;
100
+		$this->event_model = $event_model;
101
+		$this->datetime_model = $datetime_model;
102
+		$this->ticket_model = $ticket_model;
103
+		$this->registration_model = $registration_model;
104
+		$this->transaction_model = $transaction_model;
105
+		$this->config = $config;
106
+	}
107 107
 
108 108
 
109
-    /**
110
-     * Return the stats array for PUE UXIP stats.
111
-     *
112
-     * @return array
113
-     */
114
-    public function stats()
115
-    {
116
-        global $wp_version;
117
-        $stats = $this->paymentMethodStats();
118
-        // a-ok so let's setup our stats.
119
-        $stats = array_merge($stats, array(
120
-            'is_multisite'                    => is_multisite() && is_main_site(),
121
-            'active_theme'                    => $this->getActiveThemeStat(),
122
-            'ee4_all_events_count'            => $this->getCountFor(self::COUNT_ALL_EVENTS),
123
-            'ee4_active_events_count'         => $this->getCountFor(self::COUNT_ACTIVE_EVENTS),
124
-            'all_dtts_count'                  => $this->getCountFor(self::COUNT_DATETIMES),
125
-            'dtt_sold'                        => $this->getCountFor(self::COUNT_DATETIMES_SOLD),
126
-            'all_tkt_count'                   => $this->getCountFor(self::COUNT_TICKETS),
127
-            'free_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_FREE),
128
-            'paid_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_PAID),
129
-            'tkt_sold'                        => $this->getCountFor(self::COUNT_TICKETS_SOLD),
130
-            'approve_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED),
131
-            'pending_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING),
132
-            'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED),
133
-            'incomplete_registration_count'   => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE),
134
-            'cancelled_registration_count'    => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED),
135
-            'declined_registration_count'     => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED),
136
-            'all_registration_count'          => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL),
137
-            'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL),
138
-            'all_transaction_paid_sum'        => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID),
139
-            self::INFO_SITE_CURRENCY          => $this->config->currency instanceof EE_Currency_Config
140
-                ? $this->config->currency->code
141
-                : 'unknown',
142
-            'phpversion'                      => implode(
143
-                '.',
144
-                array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION)
145
-            ),
146
-            'wpversion'                       => $wp_version,
147
-        ));
148
-        // remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
149
-        return array_filter($stats, function ($value) {
150
-            return $value !== null;
151
-        });
152
-    }
109
+	/**
110
+	 * Return the stats array for PUE UXIP stats.
111
+	 *
112
+	 * @return array
113
+	 */
114
+	public function stats()
115
+	{
116
+		global $wp_version;
117
+		$stats = $this->paymentMethodStats();
118
+		// a-ok so let's setup our stats.
119
+		$stats = array_merge($stats, array(
120
+			'is_multisite'                    => is_multisite() && is_main_site(),
121
+			'active_theme'                    => $this->getActiveThemeStat(),
122
+			'ee4_all_events_count'            => $this->getCountFor(self::COUNT_ALL_EVENTS),
123
+			'ee4_active_events_count'         => $this->getCountFor(self::COUNT_ACTIVE_EVENTS),
124
+			'all_dtts_count'                  => $this->getCountFor(self::COUNT_DATETIMES),
125
+			'dtt_sold'                        => $this->getCountFor(self::COUNT_DATETIMES_SOLD),
126
+			'all_tkt_count'                   => $this->getCountFor(self::COUNT_TICKETS),
127
+			'free_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_FREE),
128
+			'paid_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_PAID),
129
+			'tkt_sold'                        => $this->getCountFor(self::COUNT_TICKETS_SOLD),
130
+			'approve_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED),
131
+			'pending_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING),
132
+			'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED),
133
+			'incomplete_registration_count'   => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE),
134
+			'cancelled_registration_count'    => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED),
135
+			'declined_registration_count'     => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED),
136
+			'all_registration_count'          => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL),
137
+			'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL),
138
+			'all_transaction_paid_sum'        => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID),
139
+			self::INFO_SITE_CURRENCY          => $this->config->currency instanceof EE_Currency_Config
140
+				? $this->config->currency->code
141
+				: 'unknown',
142
+			'phpversion'                      => implode(
143
+				'.',
144
+				array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION)
145
+			),
146
+			'wpversion'                       => $wp_version,
147
+		));
148
+		// remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
149
+		return array_filter($stats, function ($value) {
150
+			return $value !== null;
151
+		});
152
+	}
153 153
 
154
-    /**
155
-     * @param string $which enum (@see constants prefixed with COUNT)
156
-     * @return int|null
157
-     */
158
-    private function getCountFor($which)
159
-    {
160
-        try {
161
-            switch ($which) {
162
-                case self::COUNT_ALL_EVENTS:
163
-                    $count = $this->event_model->count();
164
-                    break;
165
-                case self::COUNT_TICKETS:
166
-                    $count = $this->ticket_model->count();
167
-                    break;
168
-                case self::COUNT_DATETIMES:
169
-                    $count = $this->datetime_model->count();
170
-                    break;
171
-                case self::COUNT_ACTIVE_EVENTS:
172
-                    $count = $this->event_model->get_active_events(array(), true);
173
-                    break;
174
-                case self::COUNT_DATETIMES_SOLD:
175
-                    $count = $this->datetime_model->sum(array(), 'DTT_sold');
176
-                    break;
177
-                case self::COUNT_TICKETS_FREE:
178
-                    $count = $this->ticket_model->count(array(
179
-                        array(
180
-                            'TKT_price' => 0,
181
-                        ),
182
-                    ));
183
-                    break;
184
-                case self::COUNT_TICKETS_PAID:
185
-                    $count = $this->ticket_model->count(array(
186
-                        array(
187
-                            'TKT_price' => array('>', 0),
188
-                        ),
189
-                    ));
190
-                    break;
191
-                case self::COUNT_TICKETS_SOLD:
192
-                    $count = $this->ticket_model->sum(array(), 'TKT_sold');
193
-                    break;
194
-                case self::COUNT_REGISTRATIONS_ALL:
195
-                    $count = $this->registration_model->count();
196
-                    break;
197
-                case self::COUNT_REGISTRATIONS_CANCELLED:
198
-                    $count = $this->registration_model->count(
199
-                        array(
200
-                            array(
201
-                                'STS_ID' => EEM_Registration::status_id_cancelled,
202
-                            ),
203
-                        )
204
-                    );
205
-                    break;
206
-                case self::COUNT_REGISTRATIONS_INCOMPLETE:
207
-                    $count = $this->registration_model->count(
208
-                        array(
209
-                            array(
210
-                                'STS_ID' => EEM_Registration::status_id_incomplete,
211
-                            ),
212
-                        )
213
-                    );
214
-                    break;
215
-                case self::COUNT_REGISTRATIONS_NOT_APPROVED:
216
-                    $count = $this->registration_model->count(
217
-                        array(
218
-                            array(
219
-                                'STS_ID' => EEM_Registration::status_id_not_approved,
220
-                            ),
221
-                        )
222
-                    );
223
-                    break;
224
-                case self::COUNT_REGISTRATIONS_DECLINED:
225
-                    $count = $this->registration_model->count(
226
-                        array(
227
-                            array(
228
-                                'STS_ID' => EEM_Registration::status_id_declined,
229
-                            ),
230
-                        )
231
-                    );
232
-                    break;
233
-                case self::COUNT_REGISTRATIONS_PENDING:
234
-                    $count = $this->registration_model->count(
235
-                        array(
236
-                            array(
237
-                                'STS_ID' => EEM_Registration::status_id_pending_payment,
238
-                            ),
239
-                        )
240
-                    );
241
-                    break;
242
-                case self::COUNT_REGISTRATIONS_APPROVED:
243
-                    $count = $this->registration_model->count(
244
-                        array(
245
-                            array(
246
-                                'STS_ID' => EEM_Registration::status_id_approved,
247
-                            ),
248
-                        )
249
-                    );
250
-                    break;
251
-                case self::SUM_TRANSACTIONS_COMPLETE_TOTAL:
252
-                    $count = $this->transaction_model->sum(
253
-                        array(
254
-                            array(
255
-                                'STS_ID' => EEM_Transaction::complete_status_code,
256
-                            ),
257
-                        ),
258
-                        'TXN_total'
259
-                    );
260
-                    break;
261
-                case self::SUM_TRANSACTIONS_ALL_PAID:
262
-                    $count = $this->transaction_model->sum(
263
-                        array(),
264
-                        'TXN_paid'
265
-                    );
266
-                    break;
267
-                default:
268
-                    $count = null;
269
-                    break;
270
-            }
271
-        } catch (Exception $e) {
272
-            $count = null;
273
-        }
274
-        return $count;
275
-    }
154
+	/**
155
+	 * @param string $which enum (@see constants prefixed with COUNT)
156
+	 * @return int|null
157
+	 */
158
+	private function getCountFor($which)
159
+	{
160
+		try {
161
+			switch ($which) {
162
+				case self::COUNT_ALL_EVENTS:
163
+					$count = $this->event_model->count();
164
+					break;
165
+				case self::COUNT_TICKETS:
166
+					$count = $this->ticket_model->count();
167
+					break;
168
+				case self::COUNT_DATETIMES:
169
+					$count = $this->datetime_model->count();
170
+					break;
171
+				case self::COUNT_ACTIVE_EVENTS:
172
+					$count = $this->event_model->get_active_events(array(), true);
173
+					break;
174
+				case self::COUNT_DATETIMES_SOLD:
175
+					$count = $this->datetime_model->sum(array(), 'DTT_sold');
176
+					break;
177
+				case self::COUNT_TICKETS_FREE:
178
+					$count = $this->ticket_model->count(array(
179
+						array(
180
+							'TKT_price' => 0,
181
+						),
182
+					));
183
+					break;
184
+				case self::COUNT_TICKETS_PAID:
185
+					$count = $this->ticket_model->count(array(
186
+						array(
187
+							'TKT_price' => array('>', 0),
188
+						),
189
+					));
190
+					break;
191
+				case self::COUNT_TICKETS_SOLD:
192
+					$count = $this->ticket_model->sum(array(), 'TKT_sold');
193
+					break;
194
+				case self::COUNT_REGISTRATIONS_ALL:
195
+					$count = $this->registration_model->count();
196
+					break;
197
+				case self::COUNT_REGISTRATIONS_CANCELLED:
198
+					$count = $this->registration_model->count(
199
+						array(
200
+							array(
201
+								'STS_ID' => EEM_Registration::status_id_cancelled,
202
+							),
203
+						)
204
+					);
205
+					break;
206
+				case self::COUNT_REGISTRATIONS_INCOMPLETE:
207
+					$count = $this->registration_model->count(
208
+						array(
209
+							array(
210
+								'STS_ID' => EEM_Registration::status_id_incomplete,
211
+							),
212
+						)
213
+					);
214
+					break;
215
+				case self::COUNT_REGISTRATIONS_NOT_APPROVED:
216
+					$count = $this->registration_model->count(
217
+						array(
218
+							array(
219
+								'STS_ID' => EEM_Registration::status_id_not_approved,
220
+							),
221
+						)
222
+					);
223
+					break;
224
+				case self::COUNT_REGISTRATIONS_DECLINED:
225
+					$count = $this->registration_model->count(
226
+						array(
227
+							array(
228
+								'STS_ID' => EEM_Registration::status_id_declined,
229
+							),
230
+						)
231
+					);
232
+					break;
233
+				case self::COUNT_REGISTRATIONS_PENDING:
234
+					$count = $this->registration_model->count(
235
+						array(
236
+							array(
237
+								'STS_ID' => EEM_Registration::status_id_pending_payment,
238
+							),
239
+						)
240
+					);
241
+					break;
242
+				case self::COUNT_REGISTRATIONS_APPROVED:
243
+					$count = $this->registration_model->count(
244
+						array(
245
+							array(
246
+								'STS_ID' => EEM_Registration::status_id_approved,
247
+							),
248
+						)
249
+					);
250
+					break;
251
+				case self::SUM_TRANSACTIONS_COMPLETE_TOTAL:
252
+					$count = $this->transaction_model->sum(
253
+						array(
254
+							array(
255
+								'STS_ID' => EEM_Transaction::complete_status_code,
256
+							),
257
+						),
258
+						'TXN_total'
259
+					);
260
+					break;
261
+				case self::SUM_TRANSACTIONS_ALL_PAID:
262
+					$count = $this->transaction_model->sum(
263
+						array(),
264
+						'TXN_paid'
265
+					);
266
+					break;
267
+				default:
268
+					$count = null;
269
+					break;
270
+			}
271
+		} catch (Exception $e) {
272
+			$count = null;
273
+		}
274
+		return $count;
275
+	}
276 276
 
277
-    /**
278
-     * Return the active theme.
279
-     *
280
-     * @return false|string
281
-     */
282
-    private function getActiveThemeStat()
283
-    {
284
-        $theme = wp_get_theme();
285
-        return $theme->get('Name');
286
-    }
277
+	/**
278
+	 * Return the active theme.
279
+	 *
280
+	 * @return false|string
281
+	 */
282
+	private function getActiveThemeStat()
283
+	{
284
+		$theme = wp_get_theme();
285
+		return $theme->get('Name');
286
+	}
287 287
 
288
-    /**
289
-     * @return array
290
-     */
291
-    private function paymentMethodStats()
292
-    {
293
-        $payment_method_stats = array();
294
-        try {
295
-            $active_payment_methods = $this->payment_method_model->get_all_active(
296
-                null,
297
-                array('group_by' => 'PMD_type')
298
-            );
299
-            if ($active_payment_methods) {
300
-                foreach ($active_payment_methods as $payment_method) {
301
-                    $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1;
302
-                }
303
-            }
304
-        } catch (Exception $e) {
305
-            // do nothing just prevents fatals.
306
-        }
307
-        return $payment_method_stats;
308
-    }
288
+	/**
289
+	 * @return array
290
+	 */
291
+	private function paymentMethodStats()
292
+	{
293
+		$payment_method_stats = array();
294
+		try {
295
+			$active_payment_methods = $this->payment_method_model->get_all_active(
296
+				null,
297
+				array('group_by' => 'PMD_type')
298
+			);
299
+			if ($active_payment_methods) {
300
+				foreach ($active_payment_methods as $payment_method) {
301
+					$payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1;
302
+				}
303
+			}
304
+		} catch (Exception $e) {
305
+			// do nothing just prevents fatals.
306
+		}
307
+		return $payment_method_stats;
308
+	}
309 309
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
             'wpversion'                       => $wp_version,
147 147
         ));
148 148
         // remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
149
-        return array_filter($stats, function ($value) {
149
+        return array_filter($stats, function($value) {
150 150
             return $value !== null;
151 151
         });
152 152
     }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
             );
299 299
             if ($active_payment_methods) {
300 300
                 foreach ($active_payment_methods as $payment_method) {
301
-                    $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1;
301
+                    $payment_method_stats[$payment_method->name().'_active_payment_method'] = 1;
302 302
                 }
303 303
             }
304 304
         } catch (Exception $e) {
Please login to merge, or discard this patch.