Completed
Branch dev (18e544)
by
unknown
02:53 queued 17s
created
core/domain/services/admin/registrations/list_table/QueryBuilder.php 2 patches
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -21,384 +21,384 @@
 block discarded – undo
21 21
 class QueryBuilder
22 22
 {
23 23
 
24
-    /**
25
-     * @var RequestInterface $request
26
-     */
27
-    protected $request;
28
-
29
-    /**
30
-     * @var EEM_Registration $registration_model
31
-     */
32
-    protected $registration_model;
33
-
34
-    /**
35
-     * @var string $view
36
-     */
37
-    protected $view;
38
-
39
-    /**
40
-     * @var array $where_params
41
-     */
42
-    protected $where_params;
43
-
44
-
45
-    /**
46
-     * QueryBuilder constructor.
47
-     *
48
-     * @param array            $extra_request_params
49
-     * @param RequestInterface $request
50
-     * @param EEM_Registration $registration_model
51
-     */
52
-    public function __construct(
53
-        array $extra_request_params,
54
-        RequestInterface $request,
55
-        EEM_Registration $registration_model
56
-    ) {
57
-        $this->request = $request;
58
-        $this->registration_model = $registration_model;
59
-        foreach ($extra_request_params as $key => $value) {
60
-            $this->request->setRequestParam($key, $value);
61
-        }
62
-        $this->view = $this->request->getRequestParam('status', '');
63
-        $this->where_params = [];
64
-    }
65
-
66
-
67
-    /**
68
-     * Sets up the where conditions for the registrations query.
69
-     *
70
-     * @param int  $per_page
71
-     * @param bool $count_query
72
-     * @return array
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     */
78
-    public function getQueryParams($per_page = 10, $count_query = false)
79
-    {
80
-        $query_params = [
81
-            0                          => $this->getWhereClause(),
82
-            'caps'                     => EEM_Registration::caps_read_admin,
83
-            'default_where_conditions' => 'this_model_only',
84
-        ];
85
-        if (! $count_query) {
86
-            $query_params = array_merge(
87
-                $query_params,
88
-                $this->getOrderbyClause(),
89
-                $this->getLimitClause($per_page)
90
-            );
91
-        }
92
-
93
-        return $query_params;
94
-    }
95
-
96
-
97
-    /**
98
-     * Sets up the where conditions for the registrations query.
99
-     *
100
-     * @return array
101
-     * @throws EE_Error
102
-     * @throws InvalidArgumentException
103
-     * @throws InvalidDataTypeException
104
-     * @throws InvalidInterfaceException
105
-     */
106
-    protected function getWhereClause()
107
-    {
108
-        $this->addAttendeeIdToWhereConditions();
109
-        $this->addEventIdToWhereConditions();
110
-        $this->addCategoryIdToWhereConditions();
111
-        $this->addDatetimeIdToWhereConditions();
112
-        $this->addTicketIdToWhereConditions();
113
-        $this->addRegistrationStatusToWhereConditions();
114
-        $this->addDateToWhereConditions();
115
-        $this->addSearchToWhereConditions();
116
-        return apply_filters(
117
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
118
-            $this->where_params,
119
-            $this->request->requestParams()
120
-        );
121
-    }
122
-
123
-
124
-    /**
125
-     * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters.
126
-     */
127
-    protected function addAttendeeIdToWhereConditions()
128
-    {
129
-        $ATT_ID = $this->request->getRequestParam('attendee_id');
130
-        $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID);
131
-        if ($ATT_ID) {
132
-            $this->where_params['ATT_ID'] = absint($ATT_ID);
133
-        }
134
-    }
135
-
136
-
137
-    /**
138
-     * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters.
139
-     */
140
-    protected function addEventIdToWhereConditions()
141
-    {
142
-        $EVT_ID = $this->request->getRequestParam('event_id');
143
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID);
144
-        if ($EVT_ID) {
145
-            $this->where_params['EVT_ID'] = absint($EVT_ID);
146
-        }
147
-    }
148
-
149
-
150
-    /**
151
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
152
-     */
153
-    protected function addCategoryIdToWhereConditions()
154
-    {
155
-        $EVT_CAT = (int) $this->request->getRequestParam('EVT_CAT');
156
-        if ($EVT_CAT > 0) {
157
-            $this->where_params['Event.Term_Taxonomy.term_id'] = absint($EVT_CAT);
158
-        }
159
-    }
160
-
161
-
162
-    /**
163
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
164
-     */
165
-    protected function addDatetimeIdToWhereConditions()
166
-    {
167
-        // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value
168
-        $DTT_ID = $this->request->getRequestParam('datetime_id');
169
-        $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID);
170
-        if ($DTT_ID) {
171
-            $this->where_params['Ticket.Datetime.DTT_ID'] = absint($DTT_ID);
172
-        }
173
-    }
174
-
175
-
176
-    /**
177
-     * Adds the ticket ID if it exists in the request to the where conditions for the registrations query.
178
-     */
179
-    protected function addTicketIdToWhereConditions()
180
-    {
181
-        // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value
182
-        $TKT_ID = $this->request->getRequestParam('ticket_id');
183
-        $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID);
184
-        if ($TKT_ID) {
185
-            $this->where_params['TKT_ID'] = absint($TKT_ID);
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     * Adds the correct registration status to the where conditions for the registrations query.
192
-     * If filtering by registration status, then we show registrations matching that status.
193
-     * If not filtering by specified status, then we show all registrations excluding incomplete registrations
194
-     * UNLESS viewing trashed registrations.
195
-     */
196
-    protected function addRegistrationStatusToWhereConditions()
197
-    {
198
-        $registration_status = $this->request->getRequestParam('_reg_status');
199
-        if ($registration_status) {
200
-            $this->where_params['STS_ID'] = sanitize_text_field($registration_status);
201
-            return;
202
-        }
203
-        // make sure we exclude incomplete registrations, but only if not trashed.
204
-        if ($this->view === 'trash') {
205
-            $this->where_params['REG_deleted'] = true;
206
-            return;
207
-        }
208
-        $this->where_params['STS_ID'] = $this->view === 'incomplete'
209
-            ? EEM_Registration::status_id_incomplete
210
-            : ['!=', EEM_Registration::status_id_incomplete];
211
-    }
212
-
213
-
214
-    /**
215
-     * Adds any provided date restraints to the where conditions for the registrations query.
216
-     *
217
-     * @throws EE_Error
218
-     * @throws InvalidArgumentException
219
-     * @throws InvalidDataTypeException
220
-     * @throws InvalidInterfaceException
221
-     */
222
-    protected function addDateToWhereConditions()
223
-    {
224
-        if ($this->view === 'today') {
225
-            $now = date('Y-m-d', current_time('timestamp'));
226
-            $this->where_params['REG_date'] = [
227
-                'BETWEEN',
228
-                [
229
-                    $this->registration_model->convert_datetime_for_query(
230
-                        'REG_date',
231
-                        $now . ' 00:00:00',
232
-                        'Y-m-d H:i:s'
233
-                    ),
234
-                    $this->registration_model->convert_datetime_for_query(
235
-                        'REG_date',
236
-                        $now . ' 23:59:59',
237
-                        'Y-m-d H:i:s'
238
-                    ),
239
-                ],
240
-            ];
241
-            return;
242
-        }
243
-        if ($this->view === 'month') {
244
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
245
-            $days_this_month = date('t', current_time('timestamp'));
246
-            $this->where_params['REG_date'] = [
247
-                'BETWEEN',
248
-                [
249
-                    $this->registration_model->convert_datetime_for_query(
250
-                        'REG_date',
251
-                        $current_year_and_month . '-01 00:00:00',
252
-                        'Y-m-d H:i:s'
253
-                    ),
254
-                    $this->registration_model->convert_datetime_for_query(
255
-                        'REG_date',
256
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
257
-                        'Y-m-d H:i:s'
258
-                    ),
259
-                ],
260
-            ];
261
-            return;
262
-        }
263
-        $month_range = $this->request->getRequestParam('month_range');
264
-        if ($month_range) {
265
-            $month_range = sanitize_text_field($month_range);
266
-            $pieces = explode(' ', $month_range, 3);
267
-            $month_requested = ! empty($pieces[0])
268
-                ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
269
-                : '';
270
-            $year_requested = ! empty($pieces[1])
271
-                ? $pieces[1]
272
-                : '';
273
-            // if there is not a month or year then we can't go further
274
-            if ($month_requested && $year_requested) {
275
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
276
-                $this->where_params['REG_date'] = [
277
-                    'BETWEEN',
278
-                    [
279
-                        $this->registration_model->convert_datetime_for_query(
280
-                            'REG_date',
281
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
282
-                            'Y-m-d H:i:s'
283
-                        ),
284
-                        $this->registration_model->convert_datetime_for_query(
285
-                            'REG_date',
286
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
287
-                            'Y-m-d H:i:s'
288
-                        ),
289
-                    ],
290
-                ];
291
-            }
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * Adds any provided search restraints to the where conditions for the registrations query
298
-     */
299
-    protected function addSearchToWhereConditions()
300
-    {
301
-        $search = $this->request->getRequestParam('s');
302
-        if ($search) {
303
-            $search_string = '%' . sanitize_text_field($search) . '%';
304
-            $this->where_params['OR*search_conditions'] = [
305
-                'Event.EVT_name'                          => ['LIKE', $search_string],
306
-                'Event.EVT_desc'                          => ['LIKE', $search_string],
307
-                'Event.EVT_short_desc'                    => ['LIKE', $search_string],
308
-                'Attendee.ATT_full_name'                  => ['LIKE', $search_string],
309
-                'Attendee.ATT_fname'                      => ['LIKE', $search_string],
310
-                'Attendee.ATT_lname'                      => ['LIKE', $search_string],
311
-                'Attendee.ATT_short_bio'                  => ['LIKE', $search_string],
312
-                'Attendee.ATT_email'                      => ['LIKE', $search_string],
313
-                'Attendee.ATT_address'                    => ['LIKE', $search_string],
314
-                'Attendee.ATT_address2'                   => ['LIKE', $search_string],
315
-                'Attendee.ATT_city'                       => ['LIKE', $search_string],
316
-                'REG_final_price'                         => ['LIKE', $search_string],
317
-                'REG_code'                                => ['LIKE', $search_string],
318
-                'REG_count'                               => ['LIKE', $search_string],
319
-                'REG_group_size'                          => ['LIKE', $search_string],
320
-                'Ticket.TKT_name'                         => ['LIKE', $search_string],
321
-                'Ticket.TKT_description'                  => ['LIKE', $search_string],
322
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string],
323
-            ];
324
-        }
325
-    }
326
-
327
-
328
-    /**
329
-     * Sets up the orderby for the registrations query.
330
-     *
331
-     * @return array
332
-     */
333
-    protected function getOrderbyClause()
334
-    {
335
-        $orderby_field = $this->request->getRequestParam('orderby');
336
-        $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date';
337
-        switch ($orderby_field) {
338
-            case '_REG_ID':
339
-                $orderby = ['REG_ID'];
340
-                break;
341
-            case '_Reg_status':
342
-                $orderby = ['STS_ID'];
343
-                break;
344
-            case 'ATT_fname':
345
-                $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname'];
346
-                break;
347
-            case 'ATT_lname':
348
-                $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname'];
349
-                break;
350
-            case 'event_name':
351
-                $orderby = ['Event.EVT_name'];
352
-                break;
353
-            case 'DTT_EVT_start':
354
-                $orderby = ['Event.Datetime.DTT_EVT_start'];
355
-                break;
356
-            case '_REG_date':
357
-                $orderby = ['REG_date'];
358
-                break;
359
-            default:
360
-                $orderby = [$orderby_field];
361
-                break;
362
-        }
363
-        $order = $this->request->getRequestParam('order');
364
-        $order = $order ? sanitize_text_field($order) : 'DESC';
365
-
366
-        $orderby = array_combine(
367
-            $orderby,
368
-            array_fill(0, count($orderby), $order)
369
-        );
370
-        // because there are many registrations with the same date, define
371
-        // a secondary way to order them, otherwise MySQL seems to be a bit random
372
-        if (empty($orderby['REG_ID'])) {
373
-            $orderby['REG_ID'] = $order;
374
-        }
375
-
376
-        $orderby = apply_filters(
377
-            'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
378
-            $orderby,
379
-            $this->request->requestParams()
380
-        );
381
-        return ['order_by' => $orderby];
382
-    }
383
-
384
-
385
-    /**
386
-     * Sets up the limit for the registrations query.
387
-     *
388
-     * @param $per_page
389
-     * @return array
390
-     */
391
-    protected function getLimitClause($per_page)
392
-    {
393
-        $current_page = $this->request->getRequestParam('paged');
394
-        $current_page = $current_page ? absint($current_page) : 1;
395
-        $per_page = (int) $this->request->getRequestParam('perpage', $per_page);
396
-        // -1 means return all results so get out if that's set.
397
-        if ($per_page === -1) {
398
-            return [];
399
-        }
400
-        $per_page = absint($per_page);
401
-        $offset = ($current_page - 1) * $per_page;
402
-        return ['limit' => [$offset, $per_page]];
403
-    }
24
+	/**
25
+	 * @var RequestInterface $request
26
+	 */
27
+	protected $request;
28
+
29
+	/**
30
+	 * @var EEM_Registration $registration_model
31
+	 */
32
+	protected $registration_model;
33
+
34
+	/**
35
+	 * @var string $view
36
+	 */
37
+	protected $view;
38
+
39
+	/**
40
+	 * @var array $where_params
41
+	 */
42
+	protected $where_params;
43
+
44
+
45
+	/**
46
+	 * QueryBuilder constructor.
47
+	 *
48
+	 * @param array            $extra_request_params
49
+	 * @param RequestInterface $request
50
+	 * @param EEM_Registration $registration_model
51
+	 */
52
+	public function __construct(
53
+		array $extra_request_params,
54
+		RequestInterface $request,
55
+		EEM_Registration $registration_model
56
+	) {
57
+		$this->request = $request;
58
+		$this->registration_model = $registration_model;
59
+		foreach ($extra_request_params as $key => $value) {
60
+			$this->request->setRequestParam($key, $value);
61
+		}
62
+		$this->view = $this->request->getRequestParam('status', '');
63
+		$this->where_params = [];
64
+	}
65
+
66
+
67
+	/**
68
+	 * Sets up the where conditions for the registrations query.
69
+	 *
70
+	 * @param int  $per_page
71
+	 * @param bool $count_query
72
+	 * @return array
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 */
78
+	public function getQueryParams($per_page = 10, $count_query = false)
79
+	{
80
+		$query_params = [
81
+			0                          => $this->getWhereClause(),
82
+			'caps'                     => EEM_Registration::caps_read_admin,
83
+			'default_where_conditions' => 'this_model_only',
84
+		];
85
+		if (! $count_query) {
86
+			$query_params = array_merge(
87
+				$query_params,
88
+				$this->getOrderbyClause(),
89
+				$this->getLimitClause($per_page)
90
+			);
91
+		}
92
+
93
+		return $query_params;
94
+	}
95
+
96
+
97
+	/**
98
+	 * Sets up the where conditions for the registrations query.
99
+	 *
100
+	 * @return array
101
+	 * @throws EE_Error
102
+	 * @throws InvalidArgumentException
103
+	 * @throws InvalidDataTypeException
104
+	 * @throws InvalidInterfaceException
105
+	 */
106
+	protected function getWhereClause()
107
+	{
108
+		$this->addAttendeeIdToWhereConditions();
109
+		$this->addEventIdToWhereConditions();
110
+		$this->addCategoryIdToWhereConditions();
111
+		$this->addDatetimeIdToWhereConditions();
112
+		$this->addTicketIdToWhereConditions();
113
+		$this->addRegistrationStatusToWhereConditions();
114
+		$this->addDateToWhereConditions();
115
+		$this->addSearchToWhereConditions();
116
+		return apply_filters(
117
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
118
+			$this->where_params,
119
+			$this->request->requestParams()
120
+		);
121
+	}
122
+
123
+
124
+	/**
125
+	 * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters.
126
+	 */
127
+	protected function addAttendeeIdToWhereConditions()
128
+	{
129
+		$ATT_ID = $this->request->getRequestParam('attendee_id');
130
+		$ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID);
131
+		if ($ATT_ID) {
132
+			$this->where_params['ATT_ID'] = absint($ATT_ID);
133
+		}
134
+	}
135
+
136
+
137
+	/**
138
+	 * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters.
139
+	 */
140
+	protected function addEventIdToWhereConditions()
141
+	{
142
+		$EVT_ID = $this->request->getRequestParam('event_id');
143
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID);
144
+		if ($EVT_ID) {
145
+			$this->where_params['EVT_ID'] = absint($EVT_ID);
146
+		}
147
+	}
148
+
149
+
150
+	/**
151
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
152
+	 */
153
+	protected function addCategoryIdToWhereConditions()
154
+	{
155
+		$EVT_CAT = (int) $this->request->getRequestParam('EVT_CAT');
156
+		if ($EVT_CAT > 0) {
157
+			$this->where_params['Event.Term_Taxonomy.term_id'] = absint($EVT_CAT);
158
+		}
159
+	}
160
+
161
+
162
+	/**
163
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
164
+	 */
165
+	protected function addDatetimeIdToWhereConditions()
166
+	{
167
+		// first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value
168
+		$DTT_ID = $this->request->getRequestParam('datetime_id');
169
+		$DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID);
170
+		if ($DTT_ID) {
171
+			$this->where_params['Ticket.Datetime.DTT_ID'] = absint($DTT_ID);
172
+		}
173
+	}
174
+
175
+
176
+	/**
177
+	 * Adds the ticket ID if it exists in the request to the where conditions for the registrations query.
178
+	 */
179
+	protected function addTicketIdToWhereConditions()
180
+	{
181
+		// first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value
182
+		$TKT_ID = $this->request->getRequestParam('ticket_id');
183
+		$TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID);
184
+		if ($TKT_ID) {
185
+			$this->where_params['TKT_ID'] = absint($TKT_ID);
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 * Adds the correct registration status to the where conditions for the registrations query.
192
+	 * If filtering by registration status, then we show registrations matching that status.
193
+	 * If not filtering by specified status, then we show all registrations excluding incomplete registrations
194
+	 * UNLESS viewing trashed registrations.
195
+	 */
196
+	protected function addRegistrationStatusToWhereConditions()
197
+	{
198
+		$registration_status = $this->request->getRequestParam('_reg_status');
199
+		if ($registration_status) {
200
+			$this->where_params['STS_ID'] = sanitize_text_field($registration_status);
201
+			return;
202
+		}
203
+		// make sure we exclude incomplete registrations, but only if not trashed.
204
+		if ($this->view === 'trash') {
205
+			$this->where_params['REG_deleted'] = true;
206
+			return;
207
+		}
208
+		$this->where_params['STS_ID'] = $this->view === 'incomplete'
209
+			? EEM_Registration::status_id_incomplete
210
+			: ['!=', EEM_Registration::status_id_incomplete];
211
+	}
212
+
213
+
214
+	/**
215
+	 * Adds any provided date restraints to the where conditions for the registrations query.
216
+	 *
217
+	 * @throws EE_Error
218
+	 * @throws InvalidArgumentException
219
+	 * @throws InvalidDataTypeException
220
+	 * @throws InvalidInterfaceException
221
+	 */
222
+	protected function addDateToWhereConditions()
223
+	{
224
+		if ($this->view === 'today') {
225
+			$now = date('Y-m-d', current_time('timestamp'));
226
+			$this->where_params['REG_date'] = [
227
+				'BETWEEN',
228
+				[
229
+					$this->registration_model->convert_datetime_for_query(
230
+						'REG_date',
231
+						$now . ' 00:00:00',
232
+						'Y-m-d H:i:s'
233
+					),
234
+					$this->registration_model->convert_datetime_for_query(
235
+						'REG_date',
236
+						$now . ' 23:59:59',
237
+						'Y-m-d H:i:s'
238
+					),
239
+				],
240
+			];
241
+			return;
242
+		}
243
+		if ($this->view === 'month') {
244
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
245
+			$days_this_month = date('t', current_time('timestamp'));
246
+			$this->where_params['REG_date'] = [
247
+				'BETWEEN',
248
+				[
249
+					$this->registration_model->convert_datetime_for_query(
250
+						'REG_date',
251
+						$current_year_and_month . '-01 00:00:00',
252
+						'Y-m-d H:i:s'
253
+					),
254
+					$this->registration_model->convert_datetime_for_query(
255
+						'REG_date',
256
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
257
+						'Y-m-d H:i:s'
258
+					),
259
+				],
260
+			];
261
+			return;
262
+		}
263
+		$month_range = $this->request->getRequestParam('month_range');
264
+		if ($month_range) {
265
+			$month_range = sanitize_text_field($month_range);
266
+			$pieces = explode(' ', $month_range, 3);
267
+			$month_requested = ! empty($pieces[0])
268
+				? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
269
+				: '';
270
+			$year_requested = ! empty($pieces[1])
271
+				? $pieces[1]
272
+				: '';
273
+			// if there is not a month or year then we can't go further
274
+			if ($month_requested && $year_requested) {
275
+				$days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
276
+				$this->where_params['REG_date'] = [
277
+					'BETWEEN',
278
+					[
279
+						$this->registration_model->convert_datetime_for_query(
280
+							'REG_date',
281
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
282
+							'Y-m-d H:i:s'
283
+						),
284
+						$this->registration_model->convert_datetime_for_query(
285
+							'REG_date',
286
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
287
+							'Y-m-d H:i:s'
288
+						),
289
+					],
290
+				];
291
+			}
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * Adds any provided search restraints to the where conditions for the registrations query
298
+	 */
299
+	protected function addSearchToWhereConditions()
300
+	{
301
+		$search = $this->request->getRequestParam('s');
302
+		if ($search) {
303
+			$search_string = '%' . sanitize_text_field($search) . '%';
304
+			$this->where_params['OR*search_conditions'] = [
305
+				'Event.EVT_name'                          => ['LIKE', $search_string],
306
+				'Event.EVT_desc'                          => ['LIKE', $search_string],
307
+				'Event.EVT_short_desc'                    => ['LIKE', $search_string],
308
+				'Attendee.ATT_full_name'                  => ['LIKE', $search_string],
309
+				'Attendee.ATT_fname'                      => ['LIKE', $search_string],
310
+				'Attendee.ATT_lname'                      => ['LIKE', $search_string],
311
+				'Attendee.ATT_short_bio'                  => ['LIKE', $search_string],
312
+				'Attendee.ATT_email'                      => ['LIKE', $search_string],
313
+				'Attendee.ATT_address'                    => ['LIKE', $search_string],
314
+				'Attendee.ATT_address2'                   => ['LIKE', $search_string],
315
+				'Attendee.ATT_city'                       => ['LIKE', $search_string],
316
+				'REG_final_price'                         => ['LIKE', $search_string],
317
+				'REG_code'                                => ['LIKE', $search_string],
318
+				'REG_count'                               => ['LIKE', $search_string],
319
+				'REG_group_size'                          => ['LIKE', $search_string],
320
+				'Ticket.TKT_name'                         => ['LIKE', $search_string],
321
+				'Ticket.TKT_description'                  => ['LIKE', $search_string],
322
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string],
323
+			];
324
+		}
325
+	}
326
+
327
+
328
+	/**
329
+	 * Sets up the orderby for the registrations query.
330
+	 *
331
+	 * @return array
332
+	 */
333
+	protected function getOrderbyClause()
334
+	{
335
+		$orderby_field = $this->request->getRequestParam('orderby');
336
+		$orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date';
337
+		switch ($orderby_field) {
338
+			case '_REG_ID':
339
+				$orderby = ['REG_ID'];
340
+				break;
341
+			case '_Reg_status':
342
+				$orderby = ['STS_ID'];
343
+				break;
344
+			case 'ATT_fname':
345
+				$orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname'];
346
+				break;
347
+			case 'ATT_lname':
348
+				$orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname'];
349
+				break;
350
+			case 'event_name':
351
+				$orderby = ['Event.EVT_name'];
352
+				break;
353
+			case 'DTT_EVT_start':
354
+				$orderby = ['Event.Datetime.DTT_EVT_start'];
355
+				break;
356
+			case '_REG_date':
357
+				$orderby = ['REG_date'];
358
+				break;
359
+			default:
360
+				$orderby = [$orderby_field];
361
+				break;
362
+		}
363
+		$order = $this->request->getRequestParam('order');
364
+		$order = $order ? sanitize_text_field($order) : 'DESC';
365
+
366
+		$orderby = array_combine(
367
+			$orderby,
368
+			array_fill(0, count($orderby), $order)
369
+		);
370
+		// because there are many registrations with the same date, define
371
+		// a secondary way to order them, otherwise MySQL seems to be a bit random
372
+		if (empty($orderby['REG_ID'])) {
373
+			$orderby['REG_ID'] = $order;
374
+		}
375
+
376
+		$orderby = apply_filters(
377
+			'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
378
+			$orderby,
379
+			$this->request->requestParams()
380
+		);
381
+		return ['order_by' => $orderby];
382
+	}
383
+
384
+
385
+	/**
386
+	 * Sets up the limit for the registrations query.
387
+	 *
388
+	 * @param $per_page
389
+	 * @return array
390
+	 */
391
+	protected function getLimitClause($per_page)
392
+	{
393
+		$current_page = $this->request->getRequestParam('paged');
394
+		$current_page = $current_page ? absint($current_page) : 1;
395
+		$per_page = (int) $this->request->getRequestParam('perpage', $per_page);
396
+		// -1 means return all results so get out if that's set.
397
+		if ($per_page === -1) {
398
+			return [];
399
+		}
400
+		$per_page = absint($per_page);
401
+		$offset = ($current_page - 1) * $per_page;
402
+		return ['limit' => [$offset, $per_page]];
403
+	}
404 404
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             'caps'                     => EEM_Registration::caps_read_admin,
83 83
             'default_where_conditions' => 'this_model_only',
84 84
         ];
85
-        if (! $count_query) {
85
+        if ( ! $count_query) {
86 86
             $query_params = array_merge(
87 87
                 $query_params,
88 88
                 $this->getOrderbyClause(),
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
                 [
229 229
                     $this->registration_model->convert_datetime_for_query(
230 230
                         'REG_date',
231
-                        $now . ' 00:00:00',
231
+                        $now.' 00:00:00',
232 232
                         'Y-m-d H:i:s'
233 233
                     ),
234 234
                     $this->registration_model->convert_datetime_for_query(
235 235
                         'REG_date',
236
-                        $now . ' 23:59:59',
236
+                        $now.' 23:59:59',
237 237
                         'Y-m-d H:i:s'
238 238
                     ),
239 239
                 ],
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
                 [
249 249
                     $this->registration_model->convert_datetime_for_query(
250 250
                         'REG_date',
251
-                        $current_year_and_month . '-01 00:00:00',
251
+                        $current_year_and_month.'-01 00:00:00',
252 252
                         'Y-m-d H:i:s'
253 253
                     ),
254 254
                     $this->registration_model->convert_datetime_for_query(
255 255
                         'REG_date',
256
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
256
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
257 257
                         'Y-m-d H:i:s'
258 258
                     ),
259 259
                 ],
@@ -272,18 +272,18 @@  discard block
 block discarded – undo
272 272
                 : '';
273 273
             // if there is not a month or year then we can't go further
274 274
             if ($month_requested && $year_requested) {
275
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
275
+                $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
276 276
                 $this->where_params['REG_date'] = [
277 277
                     'BETWEEN',
278 278
                     [
279 279
                         $this->registration_model->convert_datetime_for_query(
280 280
                             'REG_date',
281
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
281
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
282 282
                             'Y-m-d H:i:s'
283 283
                         ),
284 284
                         $this->registration_model->convert_datetime_for_query(
285 285
                             'REG_date',
286
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
286
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
287 287
                             'Y-m-d H:i:s'
288 288
                         ),
289 289
                     ],
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
     {
301 301
         $search = $this->request->getRequestParam('s');
302 302
         if ($search) {
303
-            $search_string = '%' . sanitize_text_field($search) . '%';
303
+            $search_string = '%'.sanitize_text_field($search).'%';
304 304
             $this->where_params['OR*search_conditions'] = [
305 305
                 'Event.EVT_name'                          => ['LIKE', $search_string],
306 306
                 'Event.EVT_desc'                          => ['LIKE', $search_string],
Please login to merge, or discard this patch.
core/domain/services/contexts/RequestTypeContextFactory.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -17,128 +17,128 @@
 block discarded – undo
17 17
 class RequestTypeContextFactory implements RequestTypeContextFactoryInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var LoaderInterface $loader
22
-     */
23
-    private $loader;
20
+	/**
21
+	 * @var LoaderInterface $loader
22
+	 */
23
+	private $loader;
24 24
 
25 25
 
26
-    /**
27
-     * RequestTypeContextFactory constructor.
28
-     *
29
-     * @param LoaderInterface $loader
30
-     */
31
-    public function __construct(LoaderInterface $loader)
32
-    {
33
-        $this->loader = $loader;
34
-    }
26
+	/**
27
+	 * RequestTypeContextFactory constructor.
28
+	 *
29
+	 * @param LoaderInterface $loader
30
+	 */
31
+	public function __construct(LoaderInterface $loader)
32
+	{
33
+		$this->loader = $loader;
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * @param string $slug
39
-     * @return RequestTypeContext
40
-     */
41
-    public function create($slug)
42
-    {
43
-        switch ($slug) {
44
-            case RequestTypeContext::ACTIVATION:
45
-                $description = esc_html__(
46
-                    'The current request is for some form of activation',
47
-                    'event_espresso'
48
-                );
49
-                break;
50
-            case RequestTypeContext::API:
51
-                $description = esc_html__(
52
-                    'The current request is for the EE REST API',
53
-                    'event_espresso'
54
-                );
55
-                break;
56
-            case RequestTypeContext::AJAX_FRONT:
57
-                $description = esc_html__(
58
-                    'The current request is for the frontend via AJAX',
59
-                    'event_espresso'
60
-                );
61
-                break;
62
-            case RequestTypeContext::AJAX_ADMIN:
63
-                $description = esc_html__(
64
-                    'The current request is for the admin via AJAX',
65
-                    'event_espresso'
66
-                );
67
-                break;
68
-            case RequestTypeContext::AJAX_HEARTBEAT:
69
-                $description = esc_html__(
70
-                    'The current request is for the WP Heartbeat',
71
-                    'event_espresso'
72
-                );
73
-                break;
74
-            case RequestTypeContext::AJAX_OTHER:
75
-                $description = esc_html__(
76
-                    'The current request is for non-EE related code via AJAX',
77
-                    'event_espresso'
78
-                );
79
-                break;
80
-            case RequestTypeContext::CRON:
81
-                $description = esc_html__(
82
-                    'The current request is for a WP_Cron',
83
-                    'event_espresso'
84
-                );
85
-                break;
86
-            case RequestTypeContext::CLI:
87
-                $description = esc_html__(
88
-                    'The current request is from the command line',
89
-                    'event_espresso'
90
-                );
91
-                break;
92
-            case RequestTypeContext::ADMIN:
93
-                $description = esc_html__(
94
-                    'The current request is for the admin',
95
-                    'event_espresso'
96
-                );
97
-                break;
98
-            case RequestTypeContext::IFRAME:
99
-                $description = esc_html__(
100
-                    'The current request is for an iframe',
101
-                    'event_espresso'
102
-                );
103
-                break;
104
-            case RequestTypeContext::FEED:
105
-                $description = esc_html__(
106
-                    'The current request is for a feed (ie: RSS)',
107
-                    'event_espresso'
108
-                );
109
-                break;
110
-            case RequestTypeContext::GQL:
111
-                $description = esc_html__(
112
-                    'The current request is for the EE GraphQL Manager',
113
-                    'event_espresso'
114
-                );
115
-                break;
116
-            case RequestTypeContext::WP_API:
117
-                $description = esc_html__(
118
-                    'The current request is for the WordPress REST API',
119
-                    'event_espresso'
120
-                );
121
-                break;
122
-            case RequestTypeContext::WP_SCRAPE:
123
-                $description = esc_html__(
124
-                    'The current request is for a WordPress loopback scrape',
125
-                    'event_espresso'
126
-                );
127
-                break;
128
-            case RequestTypeContext::FRONTEND:
129
-            default:
130
-                $description = esc_html__(
131
-                    'The current request is for the frontend',
132
-                    'event_espresso'
133
-                );
134
-                break;
135
-        }
136
-        // we're using the Loader with sharing turned on,
137
-        // so that the generated RequestTypeContext object is accessible anywhere
138
-        // by simply requesting it again from the loader
139
-        return $this->loader->getShared(
140
-            'EventEspresso\core\domain\entities\contexts\RequestTypeContext',
141
-            array($slug, $description)
142
-        );
143
-    }
37
+	/**
38
+	 * @param string $slug
39
+	 * @return RequestTypeContext
40
+	 */
41
+	public function create($slug)
42
+	{
43
+		switch ($slug) {
44
+			case RequestTypeContext::ACTIVATION:
45
+				$description = esc_html__(
46
+					'The current request is for some form of activation',
47
+					'event_espresso'
48
+				);
49
+				break;
50
+			case RequestTypeContext::API:
51
+				$description = esc_html__(
52
+					'The current request is for the EE REST API',
53
+					'event_espresso'
54
+				);
55
+				break;
56
+			case RequestTypeContext::AJAX_FRONT:
57
+				$description = esc_html__(
58
+					'The current request is for the frontend via AJAX',
59
+					'event_espresso'
60
+				);
61
+				break;
62
+			case RequestTypeContext::AJAX_ADMIN:
63
+				$description = esc_html__(
64
+					'The current request is for the admin via AJAX',
65
+					'event_espresso'
66
+				);
67
+				break;
68
+			case RequestTypeContext::AJAX_HEARTBEAT:
69
+				$description = esc_html__(
70
+					'The current request is for the WP Heartbeat',
71
+					'event_espresso'
72
+				);
73
+				break;
74
+			case RequestTypeContext::AJAX_OTHER:
75
+				$description = esc_html__(
76
+					'The current request is for non-EE related code via AJAX',
77
+					'event_espresso'
78
+				);
79
+				break;
80
+			case RequestTypeContext::CRON:
81
+				$description = esc_html__(
82
+					'The current request is for a WP_Cron',
83
+					'event_espresso'
84
+				);
85
+				break;
86
+			case RequestTypeContext::CLI:
87
+				$description = esc_html__(
88
+					'The current request is from the command line',
89
+					'event_espresso'
90
+				);
91
+				break;
92
+			case RequestTypeContext::ADMIN:
93
+				$description = esc_html__(
94
+					'The current request is for the admin',
95
+					'event_espresso'
96
+				);
97
+				break;
98
+			case RequestTypeContext::IFRAME:
99
+				$description = esc_html__(
100
+					'The current request is for an iframe',
101
+					'event_espresso'
102
+				);
103
+				break;
104
+			case RequestTypeContext::FEED:
105
+				$description = esc_html__(
106
+					'The current request is for a feed (ie: RSS)',
107
+					'event_espresso'
108
+				);
109
+				break;
110
+			case RequestTypeContext::GQL:
111
+				$description = esc_html__(
112
+					'The current request is for the EE GraphQL Manager',
113
+					'event_espresso'
114
+				);
115
+				break;
116
+			case RequestTypeContext::WP_API:
117
+				$description = esc_html__(
118
+					'The current request is for the WordPress REST API',
119
+					'event_espresso'
120
+				);
121
+				break;
122
+			case RequestTypeContext::WP_SCRAPE:
123
+				$description = esc_html__(
124
+					'The current request is for a WordPress loopback scrape',
125
+					'event_espresso'
126
+				);
127
+				break;
128
+			case RequestTypeContext::FRONTEND:
129
+			default:
130
+				$description = esc_html__(
131
+					'The current request is for the frontend',
132
+					'event_espresso'
133
+				);
134
+				break;
135
+		}
136
+		// we're using the Loader with sharing turned on,
137
+		// so that the generated RequestTypeContext object is accessible anywhere
138
+		// by simply requesting it again from the loader
139
+		return $this->loader->getShared(
140
+			'EventEspresso\core\domain\entities\contexts\RequestTypeContext',
141
+			array($slug, $description)
142
+		);
143
+	}
144 144
 }
Please login to merge, or discard this patch.
core/domain/services/converters/json/DatetimeToJson.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         $jsonDates = [];
38 38
         foreach ($datetimes as $datetime) {
39 39
             if ($datetime instanceof EE_Datetime) {
40
-                $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
40
+                $jsonDates[$datetime->ID()] = $this->convertAndEncode($datetime);
41 41
             }
42 42
         }
43 43
         return $jsonDates;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $arrayOfDates = [];
76 76
         foreach ($datetimes as $datetime) {
77 77
             if ($datetime instanceof EE_Datetime) {
78
-                $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
78
+                $arrayOfDates[$datetime->ID()] = $this->convert($datetime);
79 79
             }
80 80
         }
81 81
         return $arrayOfDates;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $jsonDates = [];
128 128
         foreach ($datetimes as $datetime) {
129 129
             if ($datetime instanceof EE_Datetime) {
130
-                $jsonDates[ $datetime->ID() ] = $this->encode($datetime);
130
+                $jsonDates[$datetime->ID()] = $this->encode($datetime);
131 131
             }
132 132
         }
133 133
         return $jsonDates;
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -22,125 +22,125 @@
 block discarded – undo
22 22
 class DatetimeToJson implements ModelObjectToJsonConverterInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @param EE_Datetime[] $datetimes
27
-     * @return array
28
-     * @throws EE_Error
29
-     * @throws InvalidArgumentException
30
-     * @throws InvalidDataTypeException
31
-     * @throws InvalidInterfaceException
32
-     * @throws ReflectionException
33
-     * @since $VID:$
34
-     */
35
-    public function convertAndEncodeArrayOf(array $datetimes)
36
-    {
37
-        $jsonDates = [];
38
-        foreach ($datetimes as $datetime) {
39
-            if ($datetime instanceof EE_Datetime) {
40
-                $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
41
-            }
42
-        }
43
-        return $jsonDates;
44
-    }
25
+	/**
26
+	 * @param EE_Datetime[] $datetimes
27
+	 * @return array
28
+	 * @throws EE_Error
29
+	 * @throws InvalidArgumentException
30
+	 * @throws InvalidDataTypeException
31
+	 * @throws InvalidInterfaceException
32
+	 * @throws ReflectionException
33
+	 * @since $VID:$
34
+	 */
35
+	public function convertAndEncodeArrayOf(array $datetimes)
36
+	{
37
+		$jsonDates = [];
38
+		foreach ($datetimes as $datetime) {
39
+			if ($datetime instanceof EE_Datetime) {
40
+				$jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
41
+			}
42
+		}
43
+		return $jsonDates;
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * @param EE_Datetime $datetime
49
-     * @return false|string
50
-     * @throws EE_Error
51
-     * @throws InvalidArgumentException
52
-     * @throws InvalidDataTypeException
53
-     * @throws InvalidInterfaceException
54
-     * @throws ReflectionException
55
-     * @since $VID:$
56
-     */
57
-    public function convertAndEncode($datetime)
58
-    {
59
-        return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false;
60
-    }
47
+	/**
48
+	 * @param EE_Datetime $datetime
49
+	 * @return false|string
50
+	 * @throws EE_Error
51
+	 * @throws InvalidArgumentException
52
+	 * @throws InvalidDataTypeException
53
+	 * @throws InvalidInterfaceException
54
+	 * @throws ReflectionException
55
+	 * @since $VID:$
56
+	 */
57
+	public function convertAndEncode($datetime)
58
+	{
59
+		return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @param EE_Datetime[] $datetimes
65
-     * @return array
66
-     * @throws EE_Error
67
-     * @throws InvalidArgumentException
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     * @throws ReflectionException
71
-     * @since $VID:$
72
-     */
73
-    public function convertArrayOf(array $datetimes)
74
-    {
75
-        $arrayOfDates = [];
76
-        foreach ($datetimes as $datetime) {
77
-            if ($datetime instanceof EE_Datetime) {
78
-                $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
79
-            }
80
-        }
81
-        return $arrayOfDates;
82
-    }
63
+	/**
64
+	 * @param EE_Datetime[] $datetimes
65
+	 * @return array
66
+	 * @throws EE_Error
67
+	 * @throws InvalidArgumentException
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws ReflectionException
71
+	 * @since $VID:$
72
+	 */
73
+	public function convertArrayOf(array $datetimes)
74
+	{
75
+		$arrayOfDates = [];
76
+		foreach ($datetimes as $datetime) {
77
+			if ($datetime instanceof EE_Datetime) {
78
+				$arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
79
+			}
80
+		}
81
+		return $arrayOfDates;
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * @param EE_Datetime $datetime
87
-     * @return array
88
-     * @throws EE_Error
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @throws InvalidArgumentException
92
-     * @throws ReflectionException
93
-     * @since $VID:$
94
-     */
95
-    public function convert($datetime)
96
-    {
97
-        return $datetime instanceof EE_Datetime ? [
98
-            'DTT_ID'          => $datetime->ID(),
99
-            'EVT_ID'          => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0,
100
-            'DTT_name'        => $datetime->name(),
101
-            'DTT_description' => $datetime->description(),
102
-            'DTT_EVT_start'   => $datetime->start_date(DATE_ATOM),
103
-            'DTT_EVT_end'     => $datetime->end_date(DATE_ATOM),
104
-            'DTT_sold'        => $datetime->sold(),
105
-            'DTT_reserved'    => $datetime->reserved(),
106
-            'DTT_reg_limit'   => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(),
107
-            'DTT_is_primary'  => $datetime->get_active_status(),
108
-            'DTT_order'       => $datetime->order(),
109
-            'DTT_parent'      => $datetime->parent(),
110
-            'DTT_deleted'     => $datetime->get('DTT_deleted'),
111
-        ] : [];
112
-    }
85
+	/**
86
+	 * @param EE_Datetime $datetime
87
+	 * @return array
88
+	 * @throws EE_Error
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @throws InvalidArgumentException
92
+	 * @throws ReflectionException
93
+	 * @since $VID:$
94
+	 */
95
+	public function convert($datetime)
96
+	{
97
+		return $datetime instanceof EE_Datetime ? [
98
+			'DTT_ID'          => $datetime->ID(),
99
+			'EVT_ID'          => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0,
100
+			'DTT_name'        => $datetime->name(),
101
+			'DTT_description' => $datetime->description(),
102
+			'DTT_EVT_start'   => $datetime->start_date(DATE_ATOM),
103
+			'DTT_EVT_end'     => $datetime->end_date(DATE_ATOM),
104
+			'DTT_sold'        => $datetime->sold(),
105
+			'DTT_reserved'    => $datetime->reserved(),
106
+			'DTT_reg_limit'   => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(),
107
+			'DTT_is_primary'  => $datetime->get_active_status(),
108
+			'DTT_order'       => $datetime->order(),
109
+			'DTT_parent'      => $datetime->parent(),
110
+			'DTT_deleted'     => $datetime->get('DTT_deleted'),
111
+		] : [];
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * @param EE_Datetime[] $datetimes
117
-     * @return array
118
-     * @throws EE_Error
119
-     * @throws InvalidArgumentException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     * @throws ReflectionException
123
-     * @since $VID:$
124
-     */
125
-    public function encodeArrayOf(array $datetimes)
126
-    {
127
-        $jsonDates = [];
128
-        foreach ($datetimes as $datetime) {
129
-            if ($datetime instanceof EE_Datetime) {
130
-                $jsonDates[ $datetime->ID() ] = $this->encode($datetime);
131
-            }
132
-        }
133
-        return $jsonDates;
134
-    }
115
+	/**
116
+	 * @param EE_Datetime[] $datetimes
117
+	 * @return array
118
+	 * @throws EE_Error
119
+	 * @throws InvalidArgumentException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 * @throws ReflectionException
123
+	 * @since $VID:$
124
+	 */
125
+	public function encodeArrayOf(array $datetimes)
126
+	{
127
+		$jsonDates = [];
128
+		foreach ($datetimes as $datetime) {
129
+			if ($datetime instanceof EE_Datetime) {
130
+				$jsonDates[ $datetime->ID() ] = $this->encode($datetime);
131
+			}
132
+		}
133
+		return $jsonDates;
134
+	}
135 135
 
136 136
 
137
-    /**
138
-     * @param array $datetime_array
139
-     * @return false|string
140
-     * @since $VID:$
141
-     */
142
-    public function encode(array $datetime_array)
143
-    {
144
-        return wp_json_encode($datetime_array);
145
-    }
137
+	/**
138
+	 * @param array $datetime_array
139
+	 * @return false|string
140
+	 * @since $VID:$
141
+	 */
142
+	public function encode(array $datetime_array)
143
+	{
144
+		return wp_json_encode($datetime_array);
145
+	}
146 146
 }
Please login to merge, or discard this patch.
reg_steps/attendee_information/attendee_info_main.template.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 6
 <?php if (!is_admin()) : ?>
7 7
     <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text">
8 8
         <?php echo apply_filters(
9
-            'FHEE__registration_page_attendee_information__attendee_information_pg',
10
-            sprintf(
11
-                __(
12
-                    'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
-                    'event_espresso'
14
-                ),
15
-                '<br />',
16
-                '<span class="asterisk">*</span>'
17
-            )
18
-        ); ?>
9
+			'FHEE__registration_page_attendee_information__attendee_information_pg',
10
+			sprintf(
11
+				__(
12
+					'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
+					'event_espresso'
14
+				),
15
+				'<br />',
16
+				'<span class="asterisk">*</span>'
17
+			)
18
+		); ?>
19 19
 </p>
20 20
 <?php endif; ?>
21 21
 
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 $prev_ticket = 0;
26 26
 
27 27
 if (count($registrations) > 0) {
28
-    foreach ($registrations as $registration) {
29
-        if ($registration instanceof EE_Registration) {
30
-            $att_nmbr++;
31
-            ?>
28
+	foreach ($registrations as $registration) {
29
+		if ($registration instanceof EE_Registration) {
30
+			$att_nmbr++;
31
+			?>
32 32
 
33 33
             <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>"
34 34
                  class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>">
@@ -50,19 +50,19 @@  discard block
 block discarded – undo
50 50
                                     <th scope="col" width="" class="jst-left"><?php _e('Name and Description', 'event_espresso'); ?></th>
51 51
                                     <th scope="col" width="7.5%" class="jst-rght">
52 52
                                         <?php _e(
53
-                                            'Qty',
54
-                                            'event_espresso'
55
-                                        ); ?></th>
53
+											'Qty',
54
+											'event_espresso'
55
+										); ?></th>
56 56
                                     <th scope="col" width="17.5%" class="jst-rght">
57 57
                                         <?php _e(
58
-                                            'Price',
59
-                                            'event_espresso'
60
-                                        ); ?></th>
58
+											'Price',
59
+											'event_espresso'
60
+										); ?></th>
61 61
                                     <th scope="col" width="17.5%" class="jst-rght">
62 62
                                         <?php _e(
63
-                                            'Total',
64
-                                            'event_espresso'
65
-                                        ); ?></th>
63
+											'Total',
64
+											'event_espresso'
65
+										); ?></th>
66 66
                                 </tr>
67 67
                                 </thead>
68 68
                                 <tbody>
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
                 <?php } ?>
75 75
 
76 76
                 <?php
77
-                // ATTENDEE QUESTIONS
78
-                $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
79
-                echo ${$reg_form};
80
-                ?>
77
+				// ATTENDEE QUESTIONS
78
+				$reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
79
+				echo ${$reg_form};
80
+				?>
81 81
 
82 82
             </div>
83 83
             <?php
84
-            $prev_event = $registration->event()->ID();
85
-            $prev_ticket = $registration->ticket()->ID();
86
-        } // if ( $registration instanceof EE_Registration )
87
-    } // end foreach ( $registrations as $registration )
84
+			$prev_event = $registration->event()->ID();
85
+			$prev_ticket = $registration->ticket()->ID();
86
+		} // if ( $registration instanceof EE_Registration )
87
+	} // end foreach ( $registrations as $registration )
88 88
 
89
-    echo $default_hidden_inputs;
89
+	echo $default_hidden_inputs;
90 90
 } // end if ( count( $registrations ) > 0 )
91 91
 
92 92
 ?>
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 /** @var array $ticket_line_item */
4 4
 /** @var string $default_hidden_inputs */
5 5
 ?>
6
-<?php if (!is_admin()) : ?>
6
+<?php if ( ! is_admin()) : ?>
7 7
     <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text">
8 8
         <?php echo apply_filters(
9 9
             'FHEE__registration_page_attendee_information__attendee_information_pg',
@@ -33,15 +33,15 @@  discard block
 block discarded – undo
33 33
             <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>"
34 34
                  class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>">
35 35
 
36
-                <?php if (!is_admin() && $registration->event()->ID() !== $prev_event) { ?>
36
+                <?php if ( ! is_admin() && $registration->event()->ID() !== $prev_event) { ?>
37 37
                     <h4 id="event_title-<?php echo $registration->event()->ID() ?>" class="big-event-title-hdr">
38 38
                         <?php echo $registration->event()->name(); ?>
39 39
                     </h4>
40 40
                 <?php } ?>
41 41
                 <?php if ($registration->ticket()->ID() !== $prev_ticket) { ?>
42
-                    <?php if (! $revisit) { ?>
42
+                    <?php if ( ! $revisit) { ?>
43 43
                         <div class="spco-ticket-info-dv small-text">
44
-                            <?php if (!is_admin()) : ?>
44
+                            <?php if ( ! is_admin()) : ?>
45 45
                                 <h5><?php _e('Details', 'event_espresso'); ?></h5>
46 46
                             <?php endif; ?>
47 47
                             <table class="spco-ticket-details">
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                                 </tr>
67 67
                                 </thead>
68 68
                                 <tbody>
69
-                                <?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?>
69
+                                <?php echo $ticket_line_item[$registration->ticket()->ID()]; ?>
70 70
                                 </tbody>
71 71
                             </table>
72 72
                         </div>
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
         $version = ''
177 177
     ) {
178 178
         $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
179
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
180 180
         return $this->addJavascript(
181 181
             $handle,
182 182
             "{$vendor_path}{$handle}{$dev_suffix}.js",
Please login to merge, or discard this patch.
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -23,332 +23,332 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection|Asset[] $assets
28
-     */
29
-    protected $assets;
30
-
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
35
-
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
40
-
41
-
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        $this->registry->addAssetCollection($assets);
55
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return AssetCollection
62
-     */
63
-    public function getAssets()
64
-    {
65
-        return $this->assets;
66
-    }
67
-
68
-
69
-    /**
70
-     * @since 4.9.71.p
71
-     * @return string
72
-     */
73
-    public function assetNamespace()
74
-    {
75
-        return $this->domain->assetNamespace();
76
-    }
77
-
78
-
79
-    /**
80
-     * @param string $handle
81
-     * @param string $source
82
-     * @param array  $dependencies
83
-     * @param bool   $load_in_footer
84
-     * @param string $version
85
-     * @return JavascriptAsset
86
-     * @throws DuplicateCollectionIdentifierException
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidEntityException
89
-     * @throws DomainException
90
-     * @since 4.9.62.p
91
-     */
92
-    public function addJavascript(
93
-        $handle,
94
-        $source,
95
-        array $dependencies = array(),
96
-        $load_in_footer = true,
97
-        $version = ''
98
-    ) {
99
-        $asset = new JavascriptAsset(
100
-            $handle,
101
-            $source,
102
-            array_unique($dependencies),
103
-            $load_in_footer,
104
-            $this->domain,
105
-            $version
106
-        );
107
-        $this->assets->add($asset, $handle);
108
-        return $asset;
109
-    }
110
-
111
-
112
-    /**
113
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
-     *
115
-     * @param string       $handle
116
-     * @param string|array $extra_dependencies
117
-     * @return JavascriptAsset
118
-     * @throws DuplicateCollectionIdentifierException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidEntityException
121
-     * @throws DomainException
122
-     */
123
-    public function addJs($handle, $extra_dependencies = [])
124
-    {
125
-        $details = $this->getAssetDetails(
126
-            Asset::TYPE_JS,
127
-            $handle,
128
-            $extra_dependencies
129
-        );
130
-        $source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
-        return $this->addJavascript(
132
-            $handle,
133
-            $source,
134
-            $details['dependencies'],
135
-            true,
136
-            $details['version']
137
-        );
138
-    }
139
-
140
-
141
-    /**
142
-     * @param string $handle
143
-     * @param array  $dependencies
144
-     * @param bool   $load_in_footer
145
-     * @param string $version
146
-     * @return JavascriptAsset
147
-     * @throws DomainException
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @since 4.9.71.p
152
-     */
153
-    public function addVendorJavascript(
154
-        $handle,
155
-        array $dependencies = array(),
156
-        $load_in_footer = true,
157
-        $version = ''
158
-    ) {
159
-        $dev_suffix = wp_scripts_get_suffix('dev');
160
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
-        return $this->addJavascript(
162
-            $handle,
163
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
164
-            $dependencies,
165
-            $load_in_footer,
166
-            $version
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * @param string $handle
173
-     * @param string $source
174
-     * @param array  $dependencies
175
-     * @param string $media
176
-     * @param string $version
177
-     * @return StylesheetAsset
178
-     * @throws DomainException
179
-     * @throws DuplicateCollectionIdentifierException
180
-     * @throws InvalidDataTypeException
181
-     * @throws InvalidEntityException
182
-     * @since 4.9.62.p
183
-     */
184
-    public function addStylesheet(
185
-        $handle,
186
-        $source,
187
-        array $dependencies = array(),
188
-        $media = 'all',
189
-        $version = ''
190
-    ) {
191
-        $asset = new StylesheetAsset(
192
-            $handle,
193
-            $source,
194
-            array_unique($dependencies),
195
-            $this->domain,
196
-            $media,
197
-            $version
198
-        );
199
-        $this->assets->add($asset, $handle);
200
-        return $asset;
201
-    }
202
-
203
-
204
-    /**
205
-     * Used to register a css asset where everything is dynamically derived from the given handle.
206
-     *
207
-     * @param string       $handle
208
-     * @param string|array $extra_dependencies
209
-     * @return StylesheetAsset
210
-     * @throws DuplicateCollectionIdentifierException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidEntityException
213
-     * @throws DomainException
214
-     */
215
-    public function addCss($handle, $extra_dependencies = [])
216
-    {
217
-        $details = $this->getAssetDetails(
218
-            Asset::TYPE_CSS,
219
-            $handle,
220
-            $extra_dependencies
221
-        );
222
-        return $this->addStylesheet(
223
-            $handle,
224
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
-            $details['dependencies'],
226
-            'all',
227
-            $details['version']
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * @param string $handle
234
-     * @return bool
235
-     * @since 4.9.62.p
236
-     */
237
-    public function enqueueAsset($handle)
238
-    {
239
-        if ($this->assets->has($handle)) {
240
-            /** @var Asset $asset */
241
-            $asset = $this->assets->get($handle);
242
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
-                $asset->enqueueAsset();
244
-                return true;
245
-            }
246
-        }
247
-        return false;
248
-    }
249
-
250
-
251
-    /**
252
-     * @return  void
253
-     * @since   $VID:$
254
-     */
255
-    public function enqueueBrowserAssets()
256
-    {
257
-        foreach ($this->assets as $asset) {
258
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
-                $asset->enqueueAsset();
260
-            }
261
-        }
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $asset_type
267
-     * @param string $handle
268
-     * @param array  $extra_dependencies
269
-     * @return array
270
-     * @since 4.10.2.p
271
-     */
272
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
-    {
274
-        $getAssetDetails = '';
275
-        switch ($asset_type) {
276
-            case Asset::TYPE_JS :
277
-                $getAssetDetails = 'getJsAssetDetails';
278
-                break;
279
-            case Asset::TYPE_CSS :
280
-                $getAssetDetails = 'getCssAssetDetails';
281
-                break;
282
-        }
283
-        if ($getAssetDetails === '') {
284
-            return ['dependencies' => [], 'version' => ''];
285
-        }
286
-        $details = $this->registry->$getAssetDetails(
287
-            $this->domain->assetNamespace(),
288
-            $handle
289
-        );
290
-        $details['dependencies'] = isset($details['dependencies'])
291
-            ? $details['dependencies']
292
-            : [];
293
-        $details['version'] = isset($details['version'])
294
-            ? $details['version']
295
-            : '';
296
-        $details['dependencies'] = ! empty($extra_dependencies)
297
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
298
-            : $details['dependencies'];
299
-        return $details;
300
-
301
-    }
302
-
303
-
304
-    /**
305
-     * @param string $handle
306
-     * @return bool
307
-     * @throws DomainException
308
-     */
309
-    public function verifyAssetIsRegistered($handle)
310
-    {
311
-        if (wp_script_is($handle, 'registered')) {
312
-            return true;
313
-        }
314
-        if (WP_DEBUG) {
315
-            throw new DomainException(
316
-                sprintf(
317
-                    esc_html__(
318
-                        'The "%1$s" script is not registered when it should be!%2$s
26
+	/**
27
+	 * @var AssetCollection|Asset[] $assets
28
+	 */
29
+	protected $assets;
30
+
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35
+
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40
+
41
+
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		$this->registry->addAssetCollection($assets);
55
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return AssetCollection
62
+	 */
63
+	public function getAssets()
64
+	{
65
+		return $this->assets;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @since 4.9.71.p
71
+	 * @return string
72
+	 */
73
+	public function assetNamespace()
74
+	{
75
+		return $this->domain->assetNamespace();
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param string $handle
81
+	 * @param string $source
82
+	 * @param array  $dependencies
83
+	 * @param bool   $load_in_footer
84
+	 * @param string $version
85
+	 * @return JavascriptAsset
86
+	 * @throws DuplicateCollectionIdentifierException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidEntityException
89
+	 * @throws DomainException
90
+	 * @since 4.9.62.p
91
+	 */
92
+	public function addJavascript(
93
+		$handle,
94
+		$source,
95
+		array $dependencies = array(),
96
+		$load_in_footer = true,
97
+		$version = ''
98
+	) {
99
+		$asset = new JavascriptAsset(
100
+			$handle,
101
+			$source,
102
+			array_unique($dependencies),
103
+			$load_in_footer,
104
+			$this->domain,
105
+			$version
106
+		);
107
+		$this->assets->add($asset, $handle);
108
+		return $asset;
109
+	}
110
+
111
+
112
+	/**
113
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
+	 *
115
+	 * @param string       $handle
116
+	 * @param string|array $extra_dependencies
117
+	 * @return JavascriptAsset
118
+	 * @throws DuplicateCollectionIdentifierException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidEntityException
121
+	 * @throws DomainException
122
+	 */
123
+	public function addJs($handle, $extra_dependencies = [])
124
+	{
125
+		$details = $this->getAssetDetails(
126
+			Asset::TYPE_JS,
127
+			$handle,
128
+			$extra_dependencies
129
+		);
130
+		$source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
+		return $this->addJavascript(
132
+			$handle,
133
+			$source,
134
+			$details['dependencies'],
135
+			true,
136
+			$details['version']
137
+		);
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param string $handle
143
+	 * @param array  $dependencies
144
+	 * @param bool   $load_in_footer
145
+	 * @param string $version
146
+	 * @return JavascriptAsset
147
+	 * @throws DomainException
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @since 4.9.71.p
152
+	 */
153
+	public function addVendorJavascript(
154
+		$handle,
155
+		array $dependencies = array(),
156
+		$load_in_footer = true,
157
+		$version = ''
158
+	) {
159
+		$dev_suffix = wp_scripts_get_suffix('dev');
160
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
+		return $this->addJavascript(
162
+			$handle,
163
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
164
+			$dependencies,
165
+			$load_in_footer,
166
+			$version
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param string $handle
173
+	 * @param string $source
174
+	 * @param array  $dependencies
175
+	 * @param string $media
176
+	 * @param string $version
177
+	 * @return StylesheetAsset
178
+	 * @throws DomainException
179
+	 * @throws DuplicateCollectionIdentifierException
180
+	 * @throws InvalidDataTypeException
181
+	 * @throws InvalidEntityException
182
+	 * @since 4.9.62.p
183
+	 */
184
+	public function addStylesheet(
185
+		$handle,
186
+		$source,
187
+		array $dependencies = array(),
188
+		$media = 'all',
189
+		$version = ''
190
+	) {
191
+		$asset = new StylesheetAsset(
192
+			$handle,
193
+			$source,
194
+			array_unique($dependencies),
195
+			$this->domain,
196
+			$media,
197
+			$version
198
+		);
199
+		$this->assets->add($asset, $handle);
200
+		return $asset;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
206
+	 *
207
+	 * @param string       $handle
208
+	 * @param string|array $extra_dependencies
209
+	 * @return StylesheetAsset
210
+	 * @throws DuplicateCollectionIdentifierException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidEntityException
213
+	 * @throws DomainException
214
+	 */
215
+	public function addCss($handle, $extra_dependencies = [])
216
+	{
217
+		$details = $this->getAssetDetails(
218
+			Asset::TYPE_CSS,
219
+			$handle,
220
+			$extra_dependencies
221
+		);
222
+		return $this->addStylesheet(
223
+			$handle,
224
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
+			$details['dependencies'],
226
+			'all',
227
+			$details['version']
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param string $handle
234
+	 * @return bool
235
+	 * @since 4.9.62.p
236
+	 */
237
+	public function enqueueAsset($handle)
238
+	{
239
+		if ($this->assets->has($handle)) {
240
+			/** @var Asset $asset */
241
+			$asset = $this->assets->get($handle);
242
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
+				$asset->enqueueAsset();
244
+				return true;
245
+			}
246
+		}
247
+		return false;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @return  void
253
+	 * @since   $VID:$
254
+	 */
255
+	public function enqueueBrowserAssets()
256
+	{
257
+		foreach ($this->assets as $asset) {
258
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
+				$asset->enqueueAsset();
260
+			}
261
+		}
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $asset_type
267
+	 * @param string $handle
268
+	 * @param array  $extra_dependencies
269
+	 * @return array
270
+	 * @since 4.10.2.p
271
+	 */
272
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
+	{
274
+		$getAssetDetails = '';
275
+		switch ($asset_type) {
276
+			case Asset::TYPE_JS :
277
+				$getAssetDetails = 'getJsAssetDetails';
278
+				break;
279
+			case Asset::TYPE_CSS :
280
+				$getAssetDetails = 'getCssAssetDetails';
281
+				break;
282
+		}
283
+		if ($getAssetDetails === '') {
284
+			return ['dependencies' => [], 'version' => ''];
285
+		}
286
+		$details = $this->registry->$getAssetDetails(
287
+			$this->domain->assetNamespace(),
288
+			$handle
289
+		);
290
+		$details['dependencies'] = isset($details['dependencies'])
291
+			? $details['dependencies']
292
+			: [];
293
+		$details['version'] = isset($details['version'])
294
+			? $details['version']
295
+			: '';
296
+		$details['dependencies'] = ! empty($extra_dependencies)
297
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
298
+			: $details['dependencies'];
299
+		return $details;
300
+
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param string $handle
306
+	 * @return bool
307
+	 * @throws DomainException
308
+	 */
309
+	public function verifyAssetIsRegistered($handle)
310
+	{
311
+		if (wp_script_is($handle, 'registered')) {
312
+			return true;
313
+		}
314
+		if (WP_DEBUG) {
315
+			throw new DomainException(
316
+				sprintf(
317
+					esc_html__(
318
+						'The "%1$s" script is not registered when it should be!%2$s
319 319
                         Are you running the Barista plugin for development purposes? 
320 320
                         If so, then you need to build the appropriate assets for this domain.%2$s
321 321
                         If you are seeing this error on a live website, then you should not have 
322 322
                         the WP_DEBUG constant in your wp-config.php file set to "true". 
323 323
                         Please contact Event Espresso support for more information.',
324
-                        'event_espresso'
325
-                    ),
326
-                    $handle,
327
-                    '<br />'
328
-                )
329
-            );
330
-        }
331
-        return false;
332
-    }
333
-
334
-
335
-    /**************** deprecated ****************/
336
-
337
-
338
-    /**
339
-     * @return void
340
-     * @deprecated $VID:$
341
-     */
342
-    public function addManifestFile()
343
-    {
344
-    }
345
-
346
-
347
-    /**
348
-     * @return void
349
-     * @deprecated $VID:$
350
-     */
351
-    public function getManifestFile()
352
-    {
353
-    }
324
+						'event_espresso'
325
+					),
326
+					$handle,
327
+					'<br />'
328
+				)
329
+			);
330
+		}
331
+		return false;
332
+	}
333
+
334
+
335
+	/**************** deprecated ****************/
336
+
337
+
338
+	/**
339
+	 * @return void
340
+	 * @deprecated $VID:$
341
+	 */
342
+	public function addManifestFile()
343
+	{
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return void
349
+	 * @deprecated $VID:$
350
+	 */
351
+	public function getManifestFile()
352
+	{
353
+	}
354 354
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT_Init.core.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -14,44 +14,44 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    public function do_initial_loads()
18
-    {
19
-        // we want to use the corresponding admin page object (but not route it!).
20
-        // To do this we just set _routing to false.
21
-        // That way this page object is being loaded on all pages to make sure we hook into admin properly.
22
-        // But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
23
-        // This is important because we have hooks that help redirect custom post type saves
24
-        $requested_page = isset($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : '';
25
-        if ($requested_page !== $this->_menu_map->menu_slug) {
26
-            $this->_routing = false;
27
-            $this->_initialize_admin_page();
28
-        } else {
29
-            // normal init loads
30
-            $this->_initialize_admin_page();
31
-            // added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality
32
-            remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
33
-            add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100);
34
-            // end removal of autosave functionality.
35
-        }
36
-    }
17
+	public function do_initial_loads()
18
+	{
19
+		// we want to use the corresponding admin page object (but not route it!).
20
+		// To do this we just set _routing to false.
21
+		// That way this page object is being loaded on all pages to make sure we hook into admin properly.
22
+		// But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
23
+		// This is important because we have hooks that help redirect custom post type saves
24
+		$requested_page = isset($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : '';
25
+		if ($requested_page !== $this->_menu_map->menu_slug) {
26
+			$this->_routing = false;
27
+			$this->_initialize_admin_page();
28
+		} else {
29
+			// normal init loads
30
+			$this->_initialize_admin_page();
31
+			// added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality
32
+			remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
33
+			add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100);
34
+			// end removal of autosave functionality.
35
+		}
36
+	}
37 37
 
38 38
 
39
-    public function wp_just_in_time_script_localization()
40
-    {
41
-        wp_localize_script(
42
-            'autosave',
43
-            'autosaveL10n',
44
-            array(
45
-                'autosaveInterval' => 172800,
46
-                'savingText'       => __('Saving Draft&#8230;', 'event_espresso'),
47
-                'saveAlert'        => __('The changes you made will be lost if you navigate away from this page.', 'event_espresso'),
48
-            )
49
-        );
50
-    }
39
+	public function wp_just_in_time_script_localization()
40
+	{
41
+		wp_localize_script(
42
+			'autosave',
43
+			'autosaveL10n',
44
+			array(
45
+				'autosaveInterval' => 172800,
46
+				'savingText'       => __('Saving Draft&#8230;', 'event_espresso'),
47
+				'saveAlert'        => __('The changes you made will be lost if you navigate away from this page.', 'event_espresso'),
48
+			)
49
+		);
50
+	}
51 51
 
52 52
 
53
-    public function adjust_post_lock_window($interval)
54
-    {
55
-        return 172800;
56
-    }
53
+	public function adjust_post_lock_window($interval)
54
+	{
55
+		return 172800;
56
+	}
57 57
 }
Please login to merge, or discard this patch.
services/admin/events/default_settings/AdvancedEditorAdminFormSection.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -39,86 +39,86 @@
 block discarded – undo
39 39
 class AdvancedEditorAdminFormSection
40 40
 {
41 41
 
42
-    /**
43
-     * @var EE_Admin_Config
44
-     */
45
-    protected $admin_config;
42
+	/**
43
+	 * @var EE_Admin_Config
44
+	 */
45
+	protected $admin_config;
46 46
 
47 47
 
48
-    /**
49
-     * AdvancedEditorAdminForm constructor.
50
-     *
51
-     * @param EE_Admin_Config $admin_config
52
-     */
53
-    public function __construct(EE_Admin_Config $admin_config)
54
-    {
55
-        $this->admin_config = $admin_config;
56
-        add_filter(
57
-            'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
58
-            [$this, 'mergeFormSubsections']
59
-        );
60
-        add_action(
61
-            'AHEE__Events_Admin_Page___update_default_event_settings',
62
-            [$this, 'updateAdminFormSettings'],
63
-            10,
64
-            2
65
-        );
66
-    }
48
+	/**
49
+	 * AdvancedEditorAdminForm constructor.
50
+	 *
51
+	 * @param EE_Admin_Config $admin_config
52
+	 */
53
+	public function __construct(EE_Admin_Config $admin_config)
54
+	{
55
+		$this->admin_config = $admin_config;
56
+		add_filter(
57
+			'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
58
+			[$this, 'mergeFormSubsections']
59
+		);
60
+		add_action(
61
+			'AHEE__Events_Admin_Page___update_default_event_settings',
62
+			[$this, 'updateAdminFormSettings'],
63
+			10,
64
+			2
65
+		);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * @param array $default_event_settings_form_subsections
71
-     * @return array
72
-     * @since $VID:$
73
-     */
74
-    public function mergeFormSubsections(array $default_event_settings_form_subsections)
75
-    {
76
-        return [
77
-                   'use_advanced_editor'     => new EE_Select_Input(
78
-                       apply_filters(
79
-                           'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
80
-                           [
81
-                               esc_html__('Legacy Editor', 'event_espresso'),
82
-                               esc_html__('Advanced Editor', 'event_espresso'),
83
-                           ]
84
-                       ),
85
-                       apply_filters(
86
-                           'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
87
-                           [
88
-                               'default'         => $this->admin_config->useAdvancedEditor(),
89
-                               'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
90
-                               'html_help_text'  => sprintf(
91
-                                   esc_html__(
92
-                                       'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
93
-                                       'event_espresso'
94
-                                   ),
95
-                                   '<br />'
96
-                               ),
97
-                           ]
98
-                       )
99
-                   ),
100
-                   'defaults_section_header' => new EE_Form_Section_HTML(
101
-                       EEH_HTML::h2(
102
-                           esc_html__('Default Settings', 'event_espresso'),
103
-                           '',
104
-                           'ee-admin-settings-hdr'
105
-                       )
106
-                   ),
107
-               ] + $default_event_settings_form_subsections;
108
-    }
69
+	/**
70
+	 * @param array $default_event_settings_form_subsections
71
+	 * @return array
72
+	 * @since $VID:$
73
+	 */
74
+	public function mergeFormSubsections(array $default_event_settings_form_subsections)
75
+	{
76
+		return [
77
+				   'use_advanced_editor'     => new EE_Select_Input(
78
+					   apply_filters(
79
+						   'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
80
+						   [
81
+							   esc_html__('Legacy Editor', 'event_espresso'),
82
+							   esc_html__('Advanced Editor', 'event_espresso'),
83
+						   ]
84
+					   ),
85
+					   apply_filters(
86
+						   'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
87
+						   [
88
+							   'default'         => $this->admin_config->useAdvancedEditor(),
89
+							   'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
90
+							   'html_help_text'  => sprintf(
91
+								   esc_html__(
92
+									   'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
93
+									   'event_espresso'
94
+								   ),
95
+								   '<br />'
96
+							   ),
97
+						   ]
98
+					   )
99
+				   ),
100
+				   'defaults_section_header' => new EE_Form_Section_HTML(
101
+					   EEH_HTML::h2(
102
+						   esc_html__('Default Settings', 'event_espresso'),
103
+						   '',
104
+						   'ee-admin-settings-hdr'
105
+					   )
106
+				   ),
107
+			   ] + $default_event_settings_form_subsections;
108
+	}
109 109
 
110 110
 
111
-    /**
112
-     * @param array     $valid_data
113
-     * @param EE_Config $config
114
-     * @since $VID:$
115
-     */
116
-    public function updateAdminFormSettings(array $valid_data, EE_Config $config)
117
-    {
118
-        $config->admin->setUseAdvancedEditor(
119
-            isset($valid_data['use_advanced_editor'])
120
-                ? $valid_data['use_advanced_editor']
121
-                : false
122
-        );
123
-    }
111
+	/**
112
+	 * @param array     $valid_data
113
+	 * @param EE_Config $config
114
+	 * @since $VID:$
115
+	 */
116
+	public function updateAdminFormSettings(array $valid_data, EE_Config $config)
117
+	{
118
+		$config->admin->setUseAdvancedEditor(
119
+			isset($valid_data['use_advanced_editor'])
120
+				? $valid_data['use_advanced_editor']
121
+				: false
122
+		);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
core/services/graphql/fields/GraphQLField.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     public function shouldResolve()
136 136
     {
137 137
         foreach ($this->caps as $cap) {
138
-            if (! current_user_can($cap)) {
138
+            if ( ! current_user_can($cap)) {
139 139
                 return false;
140 140
             }
141 141
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
168 168
     {
169
-        if (! $this->hasInternalResolver()) {
169
+        if ( ! $this->hasInternalResolver()) {
170 170
             throw new LogicException('GraphQLField has no internal resolver.');
171 171
         }
172 172
         // dynamic methods using $this don't play nice
Please login to merge, or discard this patch.
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -20,254 +20,254 @@
 block discarded – undo
20 20
 class GraphQLField implements GraphQLFieldInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var string $name
25
-     */
26
-    protected $name;
27
-
28
-    /**
29
-     * @var string|string[] $type
30
-     */
31
-    protected $type;
32
-
33
-    /**
34
-     * @var string|null $key
35
-     */
36
-    protected $key;
37
-
38
-    /**
39
-     * @var string $description
40
-     */
41
-    protected $description;
42
-
43
-    /**
44
-     * @var callable $formatter
45
-     */
46
-    protected $formatter;
47
-
48
-    /**
49
-     * @var callable $resolve
50
-     */
51
-    protected $resolver;
52
-
53
-    /**
54
-     * @var array $caps
55
-     */
56
-    protected $caps;
57
-
58
-    /**
59
-     * @var bool $use_for_input
60
-     */
61
-    protected $use_for_input = true;
62
-
63
-    /**
64
-     * @var bool $use_for_output
65
-     */
66
-    protected $use_for_output = true;
67
-
68
-
69
-    /**
70
-     * @param string          $name
71
-     * @param string|string[] $type
72
-     * @param string|null     $key
73
-     * @param string          $description
74
-     * @param callable|null   $formatter
75
-     * @param callable|null   $resolver
76
-     * @param array           $args
77
-     * @param array           $caps
78
-     */
79
-    public function __construct(
80
-        $name,
81
-        $type,
82
-        $key = null,
83
-        $description = '',
84
-        callable $formatter = null,
85
-        callable $resolver = null,
86
-        array $caps = []
87
-    ) {
88
-        $this->name = $name;
89
-        $this->type = $type;
90
-        $this->key = $key;
91
-        $this->description = $description;
92
-        $this->formatter = $formatter;
93
-        $this->resolver = $resolver;
94
-        $this->caps = $caps;
95
-    }
96
-
97
-
98
-    /**
99
-     * @return array
100
-     */
101
-    public function caps()
102
-    {
103
-        return $this->caps;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function description()
111
-    {
112
-        return $this->description;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return string
118
-     */
119
-    public function key()
120
-    {
121
-        return $this->key;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function name()
129
-    {
130
-        return $this->name;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return string|string[]
136
-     */
137
-    public function type()
138
-    {
139
-        return $this->type;
140
-    }
141
-
142
-
143
-    /**
144
-     * Convert the field to array to be
145
-     * able to pass as config to WP GraphQL
146
-     *
147
-     * @return array
148
-     */
149
-    public function toArray()
150
-    {
151
-        return get_object_vars($this);
152
-    }
153
-
154
-
155
-    /**
156
-     * Sets the value for use_for_input.
157
-     *
158
-     * @param bool $use_for_input
159
-     */
160
-    protected function setUseForInput($use_for_input)
161
-    {
162
-        $this->use_for_input = filter_var($use_for_input, FILTER_VALIDATE_BOOLEAN);
163
-    }
164
-
165
-
166
-    /**
167
-     * Whether the field should be used for
168
-     * mutation inputs.
169
-     *
170
-     * @return bool
171
-     */
172
-    public function useForInput()
173
-    {
174
-        return (bool) $this->use_for_input;
175
-    }
176
-
177
-
178
-    /**
179
-     * Whether the field should be used for
180
-     * query outputs.
181
-     *
182
-     * @return bool
183
-     */
184
-    public function useForOutput()
185
-    {
186
-        return (bool) $this->use_for_output;
187
-    }
188
-
189
-
190
-    /**
191
-     * Sets the value for use_for_output
192
-     *
193
-     * @param bool $use_for_output
194
-     */
195
-    protected function setUseForOutput($use_for_output)
196
-    {
197
-        $this->use_for_output = filter_var($use_for_output, FILTER_VALIDATE_BOOLEAN);
198
-    }
199
-
200
-
201
-    /**
202
-     * Whether the field should resolve
203
-     * based on the user caps etc.
204
-     *
205
-     * @return boolean
206
-     */
207
-    public function shouldResolve()
208
-    {
209
-        foreach ($this->caps as $cap) {
210
-            if (! current_user_can($cap)) {
211
-                return false;
212
-            }
213
-        }
214
-        return true;
215
-    }
216
-
217
-
218
-    /**
219
-     * Whether the field has an explicit resolver set.
220
-     *
221
-     * @return boolean
222
-     */
223
-    public function hasInternalResolver()
224
-    {
225
-        return is_callable($this->resolver);
226
-    }
227
-
228
-
229
-    /**
230
-     * Whether the field has an explicit resolver set.
231
-     *
232
-     * @param mixed       $source  The source that's passed down the GraphQL queries
233
-     * @param array       $args    The inputArgs on the field
234
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
235
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
236
-     * @return mixed
237
-     * @throws LogicException
238
-     */
239
-    public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
240
-    {
241
-        if (! $this->hasInternalResolver()) {
242
-            throw new LogicException('GraphQLField has no internal resolver.');
243
-        }
244
-        // dynamic methods using $this don't play nice
245
-        // so capture resolver to a single var first
246
-        $resolver = $this->resolver;
247
-        return $resolver($source, $args, $context, $info);
248
-    }
249
-
250
-
251
-    /**
252
-     * Checks if the format callback is set.
253
-     * If yes, then uses it to format the value.
254
-     *
255
-     * @param mixed         $value
256
-     * @param EE_Base_Class $source
257
-     * @return mixed The formatted value.
258
-     * @throws InvalidDataTypeException
259
-     * @throws InvalidInterfaceException
260
-     * @throws InvalidArgumentException
261
-     * @throws ReflectionException
262
-     */
263
-    public function mayBeFormatValue($value, EE_Base_Class $source)
264
-    {
265
-        if (is_callable($this->formatter)) {
266
-            // dynamic methods using $this don't play nice
267
-            // so capture formatter to a single var first
268
-            $formatter = $this->formatter;
269
-            return $formatter($value, $source);
270
-        }
271
-        return $value;
272
-    }
23
+	/**
24
+	 * @var string $name
25
+	 */
26
+	protected $name;
27
+
28
+	/**
29
+	 * @var string|string[] $type
30
+	 */
31
+	protected $type;
32
+
33
+	/**
34
+	 * @var string|null $key
35
+	 */
36
+	protected $key;
37
+
38
+	/**
39
+	 * @var string $description
40
+	 */
41
+	protected $description;
42
+
43
+	/**
44
+	 * @var callable $formatter
45
+	 */
46
+	protected $formatter;
47
+
48
+	/**
49
+	 * @var callable $resolve
50
+	 */
51
+	protected $resolver;
52
+
53
+	/**
54
+	 * @var array $caps
55
+	 */
56
+	protected $caps;
57
+
58
+	/**
59
+	 * @var bool $use_for_input
60
+	 */
61
+	protected $use_for_input = true;
62
+
63
+	/**
64
+	 * @var bool $use_for_output
65
+	 */
66
+	protected $use_for_output = true;
67
+
68
+
69
+	/**
70
+	 * @param string          $name
71
+	 * @param string|string[] $type
72
+	 * @param string|null     $key
73
+	 * @param string          $description
74
+	 * @param callable|null   $formatter
75
+	 * @param callable|null   $resolver
76
+	 * @param array           $args
77
+	 * @param array           $caps
78
+	 */
79
+	public function __construct(
80
+		$name,
81
+		$type,
82
+		$key = null,
83
+		$description = '',
84
+		callable $formatter = null,
85
+		callable $resolver = null,
86
+		array $caps = []
87
+	) {
88
+		$this->name = $name;
89
+		$this->type = $type;
90
+		$this->key = $key;
91
+		$this->description = $description;
92
+		$this->formatter = $formatter;
93
+		$this->resolver = $resolver;
94
+		$this->caps = $caps;
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return array
100
+	 */
101
+	public function caps()
102
+	{
103
+		return $this->caps;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function description()
111
+	{
112
+		return $this->description;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return string
118
+	 */
119
+	public function key()
120
+	{
121
+		return $this->key;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function name()
129
+	{
130
+		return $this->name;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return string|string[]
136
+	 */
137
+	public function type()
138
+	{
139
+		return $this->type;
140
+	}
141
+
142
+
143
+	/**
144
+	 * Convert the field to array to be
145
+	 * able to pass as config to WP GraphQL
146
+	 *
147
+	 * @return array
148
+	 */
149
+	public function toArray()
150
+	{
151
+		return get_object_vars($this);
152
+	}
153
+
154
+
155
+	/**
156
+	 * Sets the value for use_for_input.
157
+	 *
158
+	 * @param bool $use_for_input
159
+	 */
160
+	protected function setUseForInput($use_for_input)
161
+	{
162
+		$this->use_for_input = filter_var($use_for_input, FILTER_VALIDATE_BOOLEAN);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Whether the field should be used for
168
+	 * mutation inputs.
169
+	 *
170
+	 * @return bool
171
+	 */
172
+	public function useForInput()
173
+	{
174
+		return (bool) $this->use_for_input;
175
+	}
176
+
177
+
178
+	/**
179
+	 * Whether the field should be used for
180
+	 * query outputs.
181
+	 *
182
+	 * @return bool
183
+	 */
184
+	public function useForOutput()
185
+	{
186
+		return (bool) $this->use_for_output;
187
+	}
188
+
189
+
190
+	/**
191
+	 * Sets the value for use_for_output
192
+	 *
193
+	 * @param bool $use_for_output
194
+	 */
195
+	protected function setUseForOutput($use_for_output)
196
+	{
197
+		$this->use_for_output = filter_var($use_for_output, FILTER_VALIDATE_BOOLEAN);
198
+	}
199
+
200
+
201
+	/**
202
+	 * Whether the field should resolve
203
+	 * based on the user caps etc.
204
+	 *
205
+	 * @return boolean
206
+	 */
207
+	public function shouldResolve()
208
+	{
209
+		foreach ($this->caps as $cap) {
210
+			if (! current_user_can($cap)) {
211
+				return false;
212
+			}
213
+		}
214
+		return true;
215
+	}
216
+
217
+
218
+	/**
219
+	 * Whether the field has an explicit resolver set.
220
+	 *
221
+	 * @return boolean
222
+	 */
223
+	public function hasInternalResolver()
224
+	{
225
+		return is_callable($this->resolver);
226
+	}
227
+
228
+
229
+	/**
230
+	 * Whether the field has an explicit resolver set.
231
+	 *
232
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
233
+	 * @param array       $args    The inputArgs on the field
234
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
235
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
236
+	 * @return mixed
237
+	 * @throws LogicException
238
+	 */
239
+	public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
240
+	{
241
+		if (! $this->hasInternalResolver()) {
242
+			throw new LogicException('GraphQLField has no internal resolver.');
243
+		}
244
+		// dynamic methods using $this don't play nice
245
+		// so capture resolver to a single var first
246
+		$resolver = $this->resolver;
247
+		return $resolver($source, $args, $context, $info);
248
+	}
249
+
250
+
251
+	/**
252
+	 * Checks if the format callback is set.
253
+	 * If yes, then uses it to format the value.
254
+	 *
255
+	 * @param mixed         $value
256
+	 * @param EE_Base_Class $source
257
+	 * @return mixed The formatted value.
258
+	 * @throws InvalidDataTypeException
259
+	 * @throws InvalidInterfaceException
260
+	 * @throws InvalidArgumentException
261
+	 * @throws ReflectionException
262
+	 */
263
+	public function mayBeFormatValue($value, EE_Base_Class $source)
264
+	{
265
+		if (is_callable($this->formatter)) {
266
+			// dynamic methods using $this don't play nice
267
+			// so capture formatter to a single var first
268
+			$formatter = $this->formatter;
269
+			return $formatter($value, $source);
270
+		}
271
+		return $value;
272
+	}
273 273
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Money.helper.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
         $format = 'f';
169 169
         $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
170 170
         // first get the decimal place and number of places
171
-        $format = "%'." . $currency_config->dec_plc . $format;
171
+        $format = "%'.".$currency_config->dec_plc.$format;
172 172
         // currency symbol on right side.
173
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
173
+        $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
174 174
         return $format;
175 175
     }
176 176
 
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
         $currency_config = EEH_Money::get_currency_config($CNT_ISO);
191 191
         $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
192 192
         // first get the decimal place and number of places
193
-        $format = '#,##0.' . $decimal_places_placeholder;
193
+        $format = '#,##0.'.$decimal_places_placeholder;
194 194
         // currency symbol on right side.
195 195
         $format = $currency_config->sign_b4
196
-            ? $currency_config->sign . $format
196
+            ? $currency_config->sign.$format
197 197
             : $format
198 198
               . $currency_config->sign;
199 199
         $formatterObject = array(
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
             ? new EE_Currency_Config($CNT_ISO)
226 226
             : null;
227 227
         // default currency settings for site if not set
228
-        if (! $currency_config instanceof EE_Currency_Config) {
228
+        if ( ! $currency_config instanceof EE_Currency_Config) {
229 229
             $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
230 230
                 ? EE_Registry::instance()->CFG->currency
231 231
                 : new EE_Currency_Config();
Please login to merge, or discard this patch.
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -12,226 +12,226 @@
 block discarded – undo
12 12
 class EEH_Money extends EEH_Base
13 13
 {
14 14
 
15
-    /**
16
-     * This removes all localized money formatting from the incoming value
17
-     * Note: uses this site's currency settings for deciding what is considered a
18
-     * "thousands separator" (usually the character "," )
19
-     * and what is a "decimal mark" (usually the character ".")
20
-     *
21
-     * @param int|float|string $money_value
22
-     * @param string           $CNT_ISO
23
-     * @return float
24
-     * @throws EE_Error
25
-     */
26
-    public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
-    {
28
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
-        $money_value = str_replace(
30
-            array(
31
-                $currency_config->thsnds,
32
-                $currency_config->dec_mrk,
33
-            ),
34
-            array(
35
-                '', // remove thousands separator
36
-                '.', // convert decimal mark to what PHP expects
37
-            ),
38
-            $money_value
39
-        );
40
-        $money_value = filter_var(
41
-            $money_value,
42
-            FILTER_SANITIZE_NUMBER_FLOAT,
43
-            FILTER_FLAG_ALLOW_FRACTION
44
-        );
45
-        return $money_value;
46
-    }
15
+	/**
16
+	 * This removes all localized money formatting from the incoming value
17
+	 * Note: uses this site's currency settings for deciding what is considered a
18
+	 * "thousands separator" (usually the character "," )
19
+	 * and what is a "decimal mark" (usually the character ".")
20
+	 *
21
+	 * @param int|float|string $money_value
22
+	 * @param string           $CNT_ISO
23
+	 * @return float
24
+	 * @throws EE_Error
25
+	 */
26
+	public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
+	{
28
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
+		$money_value = str_replace(
30
+			array(
31
+				$currency_config->thsnds,
32
+				$currency_config->dec_mrk,
33
+			),
34
+			array(
35
+				'', // remove thousands separator
36
+				'.', // convert decimal mark to what PHP expects
37
+			),
38
+			$money_value
39
+		);
40
+		$money_value = filter_var(
41
+			$money_value,
42
+			FILTER_SANITIZE_NUMBER_FLOAT,
43
+			FILTER_FLAG_ALLOW_FRACTION
44
+		);
45
+		return $money_value;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * This converts an incoming localized money value into a standard float item (to three decimal places)
51
-     * Only use this if you know the $money_value follows your currency configuration's
52
-     * settings. Note: this uses this site's currency settings for deciding what is considered a
53
-     * "thousands separator" (usually the character "," )
54
-     * and what is a "decimal mark" (usually the character ".")
55
-     *
56
-     * @param int|string $money_value
57
-     * @return float
58
-     * @throws EE_Error
59
-     */
60
-    public static function convert_to_float_from_localized_money($money_value)
61
-    {
62
-        // float it! and round to three decimal places
63
-        return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
-    }
49
+	/**
50
+	 * This converts an incoming localized money value into a standard float item (to three decimal places)
51
+	 * Only use this if you know the $money_value follows your currency configuration's
52
+	 * settings. Note: this uses this site's currency settings for deciding what is considered a
53
+	 * "thousands separator" (usually the character "," )
54
+	 * and what is a "decimal mark" (usually the character ".")
55
+	 *
56
+	 * @param int|string $money_value
57
+	 * @return float
58
+	 * @throws EE_Error
59
+	 */
60
+	public static function convert_to_float_from_localized_money($money_value)
61
+	{
62
+		// float it! and round to three decimal places
63
+		return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
-     * This should be used to compare floats instead of normal '==' because floats
70
-     * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
-     * but actually differ by 0.00000001.
72
-     *
73
-     * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
-     * @param float  $float1
75
-     * @param float  $float2
76
-     * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
-     * @return bool whether the equation is true or false
78
-     * @throws EE_Error
79
-     */
80
-    public static function compare_floats($float1, $float2, $operator = '=')
81
-    {
82
-        // Check numbers to 5 digits of precision
83
-        $epsilon = 0.00001;
84
-        $float1 = (float) $float1;
85
-        $float2 = (float) $float2;
86
-        switch ($operator) {
87
-            // equal
88
-            case '=':
89
-            case '==':
90
-            case '===':
91
-            case 'eq':
92
-                if (abs($float1 - $float2) < $epsilon) {
93
-                    return true;
94
-                }
95
-                break;
96
-            // less than
97
-            case '<':
98
-            case 'lt':
99
-                if (abs($float1 - $float2) < $epsilon) {
100
-                    return false;
101
-                }
102
-                if ($float1 < $float2) {
103
-                    return true;
104
-                }
105
-                break;
106
-            // less than or equal
107
-            case '<=':
108
-            case 'lte':
109
-                if (
110
-                    self::compare_floats($float1, $float2, '<')
111
-                    || self::compare_floats($float1, $float2, '=')
112
-                ) {
113
-                    return true;
114
-                }
115
-                break;
116
-            // greater than
117
-            case '>':
118
-            case 'gt':
119
-                if (abs($float1 - $float2) < $epsilon) {
120
-                    return false;
121
-                }
122
-                if ($float1 > $float2) {
123
-                    return true;
124
-                }
125
-                break;
126
-            // greater than or equal
127
-            case '>=':
128
-            case 'gte':
129
-                if (
130
-                    self::compare_floats($float1, $float2, '>')
131
-                    || self::compare_floats($float1, $float2, '=')
132
-                ) {
133
-                    return true;
134
-                }
135
-                break;
136
-            case '<>':
137
-            case '!=':
138
-            case '!==':
139
-            case 'ne':
140
-                if (abs($float1 - $float2) > $epsilon) {
141
-                    return true;
142
-                }
143
-                break;
144
-            default:
145
-                throw new EE_Error(
146
-                    sprintf(
147
-                        __(
148
-                            'Unknown operator %s in EEH_Money::compare_floats()',
149
-                            'event_espresso'
150
-                        ),
151
-                        $operator
152
-                    )
153
-                );
154
-        }
155
-        return false;
156
-    }
67
+	/**
68
+	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
+	 * This should be used to compare floats instead of normal '==' because floats
70
+	 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
+	 * but actually differ by 0.00000001.
72
+	 *
73
+	 * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
+	 * @param float  $float1
75
+	 * @param float  $float2
76
+	 * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
+	 * @return bool whether the equation is true or false
78
+	 * @throws EE_Error
79
+	 */
80
+	public static function compare_floats($float1, $float2, $operator = '=')
81
+	{
82
+		// Check numbers to 5 digits of precision
83
+		$epsilon = 0.00001;
84
+		$float1 = (float) $float1;
85
+		$float2 = (float) $float2;
86
+		switch ($operator) {
87
+			// equal
88
+			case '=':
89
+			case '==':
90
+			case '===':
91
+			case 'eq':
92
+				if (abs($float1 - $float2) < $epsilon) {
93
+					return true;
94
+				}
95
+				break;
96
+			// less than
97
+			case '<':
98
+			case 'lt':
99
+				if (abs($float1 - $float2) < $epsilon) {
100
+					return false;
101
+				}
102
+				if ($float1 < $float2) {
103
+					return true;
104
+				}
105
+				break;
106
+			// less than or equal
107
+			case '<=':
108
+			case 'lte':
109
+				if (
110
+					self::compare_floats($float1, $float2, '<')
111
+					|| self::compare_floats($float1, $float2, '=')
112
+				) {
113
+					return true;
114
+				}
115
+				break;
116
+			// greater than
117
+			case '>':
118
+			case 'gt':
119
+				if (abs($float1 - $float2) < $epsilon) {
120
+					return false;
121
+				}
122
+				if ($float1 > $float2) {
123
+					return true;
124
+				}
125
+				break;
126
+			// greater than or equal
127
+			case '>=':
128
+			case 'gte':
129
+				if (
130
+					self::compare_floats($float1, $float2, '>')
131
+					|| self::compare_floats($float1, $float2, '=')
132
+				) {
133
+					return true;
134
+				}
135
+				break;
136
+			case '<>':
137
+			case '!=':
138
+			case '!==':
139
+			case 'ne':
140
+				if (abs($float1 - $float2) > $epsilon) {
141
+					return true;
142
+				}
143
+				break;
144
+			default:
145
+				throw new EE_Error(
146
+					sprintf(
147
+						__(
148
+							'Unknown operator %s in EEH_Money::compare_floats()',
149
+							'event_espresso'
150
+						),
151
+						$operator
152
+					)
153
+				);
154
+		}
155
+		return false;
156
+	}
157 157
 
158 158
 
159
-    /**
160
-     * This returns a localized format string suitable for jQplot.
161
-     *
162
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
163
-     *                         Otherwise will use currency settings for current active country on site.
164
-     * @return string
165
-     * @throws EE_Error
166
-     */
167
-    public static function get_format_for_jqplot($CNT_ISO = '')
168
-    {
169
-        // default format
170
-        $format = 'f';
171
-        $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
172
-        // first get the decimal place and number of places
173
-        $format = "%'." . $currency_config->dec_plc . $format;
174
-        // currency symbol on right side.
175
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
176
-        return $format;
177
-    }
159
+	/**
160
+	 * This returns a localized format string suitable for jQplot.
161
+	 *
162
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
163
+	 *                         Otherwise will use currency settings for current active country on site.
164
+	 * @return string
165
+	 * @throws EE_Error
166
+	 */
167
+	public static function get_format_for_jqplot($CNT_ISO = '')
168
+	{
169
+		// default format
170
+		$format = 'f';
171
+		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
172
+		// first get the decimal place and number of places
173
+		$format = "%'." . $currency_config->dec_plc . $format;
174
+		// currency symbol on right side.
175
+		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
176
+		return $format;
177
+	}
178 178
 
179 179
 
180
-    /**
181
-     * This returns a localized format string suitable for usage with the Google Charts API format param.
182
-     *
183
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
184
-     *                         Otherwise will use currency settings for current active country on site.
185
-     *                         Note: GoogleCharts uses ICU pattern set
186
-     *                         (@return array
187
-     * @throws EE_Error
188
-     * @see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
189
-     */
190
-    public static function get_format_for_google_charts($CNT_ISO = '')
191
-    {
192
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
193
-        $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
194
-        // first get the decimal place and number of places
195
-        $format = '#,##0.' . $decimal_places_placeholder;
196
-        // currency symbol on right side.
197
-        $format = $currency_config->sign_b4
198
-            ? $currency_config->sign . $format
199
-            : $format
200
-              . $currency_config->sign;
201
-        $formatterObject = array(
202
-            'decimalSymbol'  => $currency_config->dec_mrk,
203
-            'groupingSymbol' => $currency_config->thsnds,
204
-            'fractionDigits' => $currency_config->dec_plc,
205
-        );
206
-        if ($currency_config->sign_b4) {
207
-            $formatterObject['prefix'] = $currency_config->sign;
208
-        } else {
209
-            $formatterObject['suffix'] = $currency_config->sign;
210
-        }
211
-        return array(
212
-            'format'          => $format,
213
-            'formatterObject' => $formatterObject,
214
-        );
215
-    }
180
+	/**
181
+	 * This returns a localized format string suitable for usage with the Google Charts API format param.
182
+	 *
183
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
184
+	 *                         Otherwise will use currency settings for current active country on site.
185
+	 *                         Note: GoogleCharts uses ICU pattern set
186
+	 *                         (@return array
187
+	 * @throws EE_Error
188
+	 * @see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
189
+	 */
190
+	public static function get_format_for_google_charts($CNT_ISO = '')
191
+	{
192
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
193
+		$decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
194
+		// first get the decimal place and number of places
195
+		$format = '#,##0.' . $decimal_places_placeholder;
196
+		// currency symbol on right side.
197
+		$format = $currency_config->sign_b4
198
+			? $currency_config->sign . $format
199
+			: $format
200
+			  . $currency_config->sign;
201
+		$formatterObject = array(
202
+			'decimalSymbol'  => $currency_config->dec_mrk,
203
+			'groupingSymbol' => $currency_config->thsnds,
204
+			'fractionDigits' => $currency_config->dec_plc,
205
+		);
206
+		if ($currency_config->sign_b4) {
207
+			$formatterObject['prefix'] = $currency_config->sign;
208
+		} else {
209
+			$formatterObject['suffix'] = $currency_config->sign;
210
+		}
211
+		return array(
212
+			'format'          => $format,
213
+			'formatterObject' => $formatterObject,
214
+		);
215
+	}
216 216
 
217 217
 
218
-    /**
219
-     * @param string $CNT_ISO
220
-     * @return EE_Currency_Config
221
-     * @throws EE_Error
222
-     */
223
-    public static function get_currency_config($CNT_ISO = '')
224
-    {
225
-        // if CNT_ISO passed lets try to get currency settings for it.
226
-        $currency_config = $CNT_ISO !== ''
227
-            ? new EE_Currency_Config($CNT_ISO)
228
-            : null;
229
-        // default currency settings for site if not set
230
-        if (! $currency_config instanceof EE_Currency_Config) {
231
-            $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
232
-                ? EE_Registry::instance()->CFG->currency
233
-                : new EE_Currency_Config();
234
-        }
235
-        return $currency_config;
236
-    }
218
+	/**
219
+	 * @param string $CNT_ISO
220
+	 * @return EE_Currency_Config
221
+	 * @throws EE_Error
222
+	 */
223
+	public static function get_currency_config($CNT_ISO = '')
224
+	{
225
+		// if CNT_ISO passed lets try to get currency settings for it.
226
+		$currency_config = $CNT_ISO !== ''
227
+			? new EE_Currency_Config($CNT_ISO)
228
+			: null;
229
+		// default currency settings for site if not set
230
+		if (! $currency_config instanceof EE_Currency_Config) {
231
+			$currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
232
+				? EE_Registry::instance()->CFG->currency
233
+				: new EE_Currency_Config();
234
+		}
235
+		return $currency_config;
236
+	}
237 237
 }
Please login to merge, or discard this patch.