Completed
Branch models-cleanup/main (de94a1)
by
unknown
14:03 queued 11:37
created
core/db_models/EEM_Checkin.model.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -12,69 +12,69 @@
 block discarded – undo
12 12
 class EEM_Checkin extends EEM_Base
13 13
 {
14 14
 
15
-    // private instance of the EEM_Checkin object
16
-    protected static $_instance;
15
+	// private instance of the EEM_Checkin object
16
+	protected static $_instance;
17 17
 
18 18
 
19
-    /**
20
-     * private constructor to prevent direct creation
21
-     *
22
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
23
-     *                              (and any incoming timezone data that gets saved).
24
-     *                              Note this just sends the timezone info to the date time model field objects.
25
-     *                              will use 'timezone_string' wp option as default
26
-     * @return void
27
-     * @throws EE_Error
28
-     * @throws EE_Error
29
-     */
30
-    protected function __construct(string $timezone = '')
31
-    {
32
-        $this->singular_item = esc_html__('Check-In', 'event_espresso');
33
-        $this->plural_item   = esc_html__('Check-Ins', 'event_espresso');
19
+	/**
20
+	 * private constructor to prevent direct creation
21
+	 *
22
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
23
+	 *                              (and any incoming timezone data that gets saved).
24
+	 *                              Note this just sends the timezone info to the date time model field objects.
25
+	 *                              will use 'timezone_string' wp option as default
26
+	 * @return void
27
+	 * @throws EE_Error
28
+	 * @throws EE_Error
29
+	 */
30
+	protected function __construct(string $timezone = '')
31
+	{
32
+		$this->singular_item = esc_html__('Check-In', 'event_espresso');
33
+		$this->plural_item   = esc_html__('Check-Ins', 'event_espresso');
34 34
 
35
-        $this->_tables                 = [
36
-            'Checkin' => new EE_Primary_Table('esp_checkin', 'CHK_ID'),
37
-        ];
38
-        $this->_fields                 = [
39
-            'Checkin' => [
40
-                'CHK_ID'        => new EE_Primary_Key_Int_Field(
41
-                    'CHK_ID',
42
-                    esc_html__('Check-in ID', 'event_espresso')
43
-                ),
44
-                'REG_ID'        => new EE_Foreign_Key_Int_Field(
45
-                    'REG_ID',
46
-                    esc_html__('Registration Id', 'event_espresso'),
47
-                    false,
48
-                    0,
49
-                    'Registration'
50
-                ),
51
-                'DTT_ID'        => new EE_Foreign_Key_Int_Field(
52
-                    'DTT_ID',
53
-                    esc_html__('Datetime Id', 'event_espresso'),
54
-                    false,
55
-                    0,
56
-                    'Datetime'
57
-                ),
58
-                'CHK_in'        => new EE_Boolean_Field(
59
-                    'CHK_in',
60
-                    esc_html__('Whether a person has checked in or checked out', 'event_espresso'),
61
-                    false,
62
-                    true
63
-                ),
64
-                'CHK_timestamp' => new EE_Datetime_Field(
65
-                    'CHK_timestamp',
66
-                    esc_html__('When the row was modified', 'event_espresso'),
67
-                    false,
68
-                    EE_Datetime_Field::now,
69
-                    $timezone
70
-                ),
71
-            ],
72
-        ];
73
-        $this->_model_relations        = [
74
-            'Registration' => new EE_Belongs_To_Relation(),
75
-            'Datetime'     => new EE_Belongs_To_Relation(),
76
-        ];
77
-        $this->_model_chain_to_wp_user = 'Registration.Event';
78
-        parent::__construct($timezone);
79
-    }
35
+		$this->_tables                 = [
36
+			'Checkin' => new EE_Primary_Table('esp_checkin', 'CHK_ID'),
37
+		];
38
+		$this->_fields                 = [
39
+			'Checkin' => [
40
+				'CHK_ID'        => new EE_Primary_Key_Int_Field(
41
+					'CHK_ID',
42
+					esc_html__('Check-in ID', 'event_espresso')
43
+				),
44
+				'REG_ID'        => new EE_Foreign_Key_Int_Field(
45
+					'REG_ID',
46
+					esc_html__('Registration Id', 'event_espresso'),
47
+					false,
48
+					0,
49
+					'Registration'
50
+				),
51
+				'DTT_ID'        => new EE_Foreign_Key_Int_Field(
52
+					'DTT_ID',
53
+					esc_html__('Datetime Id', 'event_espresso'),
54
+					false,
55
+					0,
56
+					'Datetime'
57
+				),
58
+				'CHK_in'        => new EE_Boolean_Field(
59
+					'CHK_in',
60
+					esc_html__('Whether a person has checked in or checked out', 'event_espresso'),
61
+					false,
62
+					true
63
+				),
64
+				'CHK_timestamp' => new EE_Datetime_Field(
65
+					'CHK_timestamp',
66
+					esc_html__('When the row was modified', 'event_espresso'),
67
+					false,
68
+					EE_Datetime_Field::now,
69
+					$timezone
70
+				),
71
+			],
72
+		];
73
+		$this->_model_relations        = [
74
+			'Registration' => new EE_Belongs_To_Relation(),
75
+			'Datetime'     => new EE_Belongs_To_Relation(),
76
+		];
77
+		$this->_model_chain_to_wp_user = 'Registration.Event';
78
+		parent::__construct($timezone);
79
+	}
80 80
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
                 ),
71 71
             ],
72 72
         ];
73
-        $this->_model_relations        = [
73
+        $this->_model_relations = [
74 74
             'Registration' => new EE_Belongs_To_Relation(),
75 75
             'Datetime'     => new EE_Belongs_To_Relation(),
76 76
         ];
Please login to merge, or discard this patch.
core/db_models/EEM_Payment.model.php 2 patches
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -12,330 +12,330 @@
 block discarded – undo
12 12
 class EEM_Payment extends EEM_Base implements EEMI_Payment
13 13
 {
14 14
 
15
-    /**
16
-     * @var EEM_Payment
17
-     */
18
-    protected static $_instance;
19
-
20
-
21
-    /**
22
-     * Status id in esp_status table that represents an approved payment
23
-     */
24
-    const status_id_approved = 'PAP';
25
-
26
-
27
-    /**
28
-     * Status id in esp_status table that represents a pending payment
29
-     */
30
-    const status_id_pending = 'PPN';
31
-
32
-
33
-    /**
34
-     * Status id in esp_status table that represents a cancelled payment (eg, the
35
-     * user went to PayPal, but on the paypal site decided to cancel the payment)
36
-     */
37
-    const status_id_cancelled = 'PCN';
38
-
39
-
40
-    /**
41
-     * Status id in esp_status table that represents a payment that was declined by
42
-     * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
43
-     */
44
-    const status_id_declined = 'PDC';
45
-
46
-
47
-    /**
48
-     * Status id in esp_status table that represents a payment that failed for technical reasons.
49
-     * (Eg, there was some error in communicating with the payment gateway.)
50
-     */
51
-    const status_id_failed = 'PFL';
52
-
53
-
54
-    /**
55
-     * private constructor to prevent direct creation
56
-     *
57
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
58
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
59
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
60
-     *                         timezone in the 'timezone_string' wp option)
61
-     * @throws EE_Error
62
-     * @throws EE_Error
63
-     */
64
-    protected function __construct(string $timezone = '')
65
-    {
66
-
67
-        $this->singular_item = esc_html__('Payment', 'event_espresso');
68
-        $this->plural_item   = esc_html__('Payments', 'event_espresso');
69
-
70
-        $this->_tables                 = [
71
-            'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID'),
72
-        ];
73
-        $this->_fields                 = [
74
-            'Payment' => [
75
-                'PAY_ID'               => new EE_Primary_Key_Int_Field(
76
-                    'PAY_ID',
77
-                    esc_html__('Payment ID', 'event_espresso')
78
-                ),
79
-                'TXN_ID'               => new EE_Foreign_Key_Int_Field(
80
-                    'TXN_ID',
81
-                    esc_html__('Transaction ID', 'event_espresso'),
82
-                    false,
83
-                    0,
84
-                    'Transaction'
85
-                ),
86
-                'STS_ID'               => new EE_Foreign_Key_String_Field(
87
-                    'STS_ID',
88
-                    esc_html__('Status ID', 'event_espresso'),
89
-                    false,
90
-                    EEM_Payment::status_id_failed,
91
-                    'Status'
92
-                ),
93
-                'PAY_timestamp'        => new EE_Datetime_Field(
94
-                    'PAY_timestamp',
95
-                    esc_html__('Timestamp of when payment was attempted', 'event_espresso'),
96
-                    false,
97
-                    EE_Datetime_Field::now,
98
-                    $timezone
99
-                ),
100
-                'PAY_source'           => new EE_All_Caps_Text_Field(
101
-                    'PAY_source',
102
-                    esc_html__('User-friendly description of payment', 'event_espresso'),
103
-                    false,
104
-                    'CART'
105
-                ),
106
-                'PAY_amount'           => new EE_Money_Field(
107
-                    'PAY_amount',
108
-                    esc_html__('Amount Payment should be for', 'event_espresso'),
109
-                    false,
110
-                    0
111
-                ),
112
-                'PMD_ID'               => new EE_Foreign_Key_Int_Field(
113
-                    'PMD_ID',
114
-                    esc_html__("Payment Method ID", 'event_espresso'),
115
-                    false,
116
-                    null,
117
-                    'Payment_Method'
118
-                ),
119
-                'PAY_gateway_response' => new EE_Plain_Text_Field(
120
-                    'PAY_gateway_response',
121
-                    esc_html__('Response from Gateway about the payment', 'event_espresso'),
122
-                    false,
123
-                    ''
124
-                ),
125
-                'PAY_txn_id_chq_nmbr'  => new EE_Plain_Text_Field(
126
-                    'PAY_txn_id_chq_nmbr',
127
-                    esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'),
128
-                    true,
129
-                    ''
130
-                ),
131
-                'PAY_po_number'        => new EE_Plain_Text_Field(
132
-                    'PAY_po_number',
133
-                    esc_html__('Purchase or Sales Number', 'event_espresso'),
134
-                    true,
135
-                    ''
136
-                ),
137
-                'PAY_extra_accntng'    => new EE_Simple_HTML_Field(
138
-                    'PAY_extra_accntng',
139
-                    esc_html__('Extra Account Info', 'event_espresso'),
140
-                    true,
141
-                    ''
142
-                ),
143
-                'PAY_details'          => new EE_Serialized_Text_Field(
144
-                    'PAY_details',
145
-                    esc_html__('Full Gateway response about payment', 'event_espresso'),
146
-                    true,
147
-                    ''
148
-                ),
149
-                'PAY_redirect_url'     => new EE_Plain_Text_Field(
150
-                    'PAY_redirect_url',
151
-                    esc_html__("Redirect URL", 'event_espresso'),
152
-                    true
153
-                ),
154
-                'PAY_redirect_args'    => new EE_Serialized_Text_Field(
155
-                    'PAY_redirect_args',
156
-                    esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'),
157
-                    true
158
-                ),
159
-            ],
160
-        ];
161
-        $this->_model_relations        = [
162
-            'Transaction'          => new EE_Belongs_To_Relation(),
163
-            'Status'               => new EE_Belongs_To_Relation(),
164
-            'Payment_Method'       => new EE_Belongs_To_Relation(),
165
-            'Registration_Payment' => new EE_Has_Many_Relation(),
166
-            'Registration'         => new EE_HABTM_Relation('Registration_Payment'),
167
-        ];
168
-        $this->_model_chain_to_wp_user = 'Payment_Method';
169
-        $this->_caps_slug              = 'transactions';
170
-        parent::__construct($timezone);
171
-    }
172
-
173
-
174
-    /**
175
-     * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
176
-     * to the payment. This is handy for verifying an IPN hasn't already been processed.
177
-     *
178
-     * @param int|string $PAY_txn_id_chq_nmbr
179
-     * @return EE_Payment
180
-     * @throws EE_Error
181
-     * @throws ReflectionException
182
-     */
183
-    public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr): EE_Payment
184
-    {
185
-        return $this->get_one([['PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr]]);
186
-    }
187
-
188
-
189
-    /**
190
-     *       retrieve  all payments from db for a particular transaction, optionally with
191
-     *      a particular status
192
-     *
193
-     * @param int $TXN_ID
194
-     * @param string $status_of_payment   one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided,
195
-     *                                  gets payments with any status
196
-     * @return EE_Payment[]
197
-     * @throws EE_Error
198
-     * @throws ReflectionException
199
-     */
200
-    public function get_payments_for_transaction(int $TXN_ID, string $status_of_payment = ''): array
201
-    {
202
-        // all payments for a TXN ordered chronologically
203
-        $query_params = [['TXN_ID' => $TXN_ID], 'order_by' => ['PAY_timestamp' => 'ASC']];
204
-        // if provided with a status, search specifically for that status. Otherwise get them all
205
-        if ($status_of_payment) {
206
-            $query_params[0]['STS_ID'] = $status_of_payment;
207
-        }
208
-        // retrieve payments
209
-        return $this->get_all($query_params);
210
-    }
211
-
212
-
213
-    /**
214
-     * Only gets payments which have been approved
215
-     *
216
-     * @param int $TXN_ID
217
-     * @return EE_Payment[]
218
-     * @throws EE_Error
219
-     * @throws ReflectionException
220
-     */
221
-    public function get_approved_payments_for_transaction(int $TXN_ID = 0): array
222
-    {
223
-        return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
224
-    }
225
-
226
-
227
-    /**
228
-     * retrieve  all payments from db between two dates,
229
-     *
230
-     * @param string $start_date        incoming start date. If empty the beginning of today is used.
231
-     * @param string $end_date          incoming end date. If empty the end of today is used.
232
-     * @param string $format            If you include $start_date or $end_date then you must include the format string
233
-     *                                  for the format your date is in.
234
-     * @param string $timezone          If your range is in a different timezone then the current setting on this
235
-     *                                  WordPress install, then include it here.
236
-     * @return EE_Payment[]
237
-     * @throws ReflectionException
238
-     *
239
-     * @throws EE_Error
240
-     */
241
-    public function get_payments_made_between_dates(
242
-        string $start_date = '',
243
-        string $end_date = '',
244
-        string $format = '',
245
-        string $timezone = ''
246
-    ): array {
247
-        $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
248
-        // if $start_date or $end date, verify $format is included.
249
-        if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
250
-            throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query',
251
-                                  'event_espresso'));
252
-        }
253
-        $now = new DateTime('now');
254
-        // setup timezone objects once
255
-        $modelDateTimeZone  = new DateTimeZone($this->_timezone);
256
-        $passedDateTimeZone = new DateTimeZone($timezone);
257
-        // setup start date
258
-        $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
259
-        EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
260
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
261
-        $start_date = strtotime($start_date);
262
-        // setup end date
263
-        $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
264
-        EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
265
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
266
-        $end_date = strtotime($end_date);
267
-
268
-        // make sure our start date is the lowest value and vice versa
269
-        $start = min($start_date, $end_date);
270
-        $end   = max($start_date, $end_date);
271
-
272
-        // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
273
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp',
274
-                                                        date('Y-m-d', $start) . ' 00:00:00',
275
-                                                        'Y-m-d H:i:s',
276
-                                                        $this->get_timezone());
277
-        $end_date   = $this->convert_datetime_for_query('PAY_timestamp',
278
-                                                        date('Y-m-d', $end) . ' 23:59:59',
279
-                                                        'Y-m-d H:i:s',
280
-                                                        $this->get_timezone());
281
-
282
-        return $this->get_all([['PAY_timestamp' => ['>=', $start_date], 'PAY_timestamp*' => ['<=', $end_date]]]);
283
-    }
284
-
285
-    /**
286
-     * methods for EEMI_Payment
287
-     */
288
-    /**
289
-     * returns a string for the approved status
290
-     *
291
-     * @return  string
292
-     */
293
-    public function approved_status(): string
294
-    {
295
-        return self::status_id_approved;
296
-    }
297
-
298
-
299
-    /**
300
-     * returns a string for the pending status
301
-     *
302
-     * @return  string
303
-     */
304
-    public function pending_status(): string
305
-    {
306
-        return self::status_id_pending;
307
-    }
308
-
309
-
310
-    /**
311
-     * returns a string for the cancelled status
312
-     *
313
-     * @return  string
314
-     */
315
-    public function cancelled_status(): string
316
-    {
317
-        return self::status_id_cancelled;
318
-    }
319
-
320
-
321
-    /**
322
-     * returns a string for the failed status
323
-     *
324
-     * @return  string
325
-     */
326
-    public function failed_status(): string
327
-    {
328
-        return self::status_id_failed;
329
-    }
330
-
331
-
332
-    /**
333
-     * returns a string for the declined status
334
-     *
335
-     * @return  string
336
-     */
337
-    public function declined_status(): string
338
-    {
339
-        return self::status_id_declined;
340
-    }
15
+	/**
16
+	 * @var EEM_Payment
17
+	 */
18
+	protected static $_instance;
19
+
20
+
21
+	/**
22
+	 * Status id in esp_status table that represents an approved payment
23
+	 */
24
+	const status_id_approved = 'PAP';
25
+
26
+
27
+	/**
28
+	 * Status id in esp_status table that represents a pending payment
29
+	 */
30
+	const status_id_pending = 'PPN';
31
+
32
+
33
+	/**
34
+	 * Status id in esp_status table that represents a cancelled payment (eg, the
35
+	 * user went to PayPal, but on the paypal site decided to cancel the payment)
36
+	 */
37
+	const status_id_cancelled = 'PCN';
38
+
39
+
40
+	/**
41
+	 * Status id in esp_status table that represents a payment that was declined by
42
+	 * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
43
+	 */
44
+	const status_id_declined = 'PDC';
45
+
46
+
47
+	/**
48
+	 * Status id in esp_status table that represents a payment that failed for technical reasons.
49
+	 * (Eg, there was some error in communicating with the payment gateway.)
50
+	 */
51
+	const status_id_failed = 'PFL';
52
+
53
+
54
+	/**
55
+	 * private constructor to prevent direct creation
56
+	 *
57
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
58
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
59
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
60
+	 *                         timezone in the 'timezone_string' wp option)
61
+	 * @throws EE_Error
62
+	 * @throws EE_Error
63
+	 */
64
+	protected function __construct(string $timezone = '')
65
+	{
66
+
67
+		$this->singular_item = esc_html__('Payment', 'event_espresso');
68
+		$this->plural_item   = esc_html__('Payments', 'event_espresso');
69
+
70
+		$this->_tables                 = [
71
+			'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID'),
72
+		];
73
+		$this->_fields                 = [
74
+			'Payment' => [
75
+				'PAY_ID'               => new EE_Primary_Key_Int_Field(
76
+					'PAY_ID',
77
+					esc_html__('Payment ID', 'event_espresso')
78
+				),
79
+				'TXN_ID'               => new EE_Foreign_Key_Int_Field(
80
+					'TXN_ID',
81
+					esc_html__('Transaction ID', 'event_espresso'),
82
+					false,
83
+					0,
84
+					'Transaction'
85
+				),
86
+				'STS_ID'               => new EE_Foreign_Key_String_Field(
87
+					'STS_ID',
88
+					esc_html__('Status ID', 'event_espresso'),
89
+					false,
90
+					EEM_Payment::status_id_failed,
91
+					'Status'
92
+				),
93
+				'PAY_timestamp'        => new EE_Datetime_Field(
94
+					'PAY_timestamp',
95
+					esc_html__('Timestamp of when payment was attempted', 'event_espresso'),
96
+					false,
97
+					EE_Datetime_Field::now,
98
+					$timezone
99
+				),
100
+				'PAY_source'           => new EE_All_Caps_Text_Field(
101
+					'PAY_source',
102
+					esc_html__('User-friendly description of payment', 'event_espresso'),
103
+					false,
104
+					'CART'
105
+				),
106
+				'PAY_amount'           => new EE_Money_Field(
107
+					'PAY_amount',
108
+					esc_html__('Amount Payment should be for', 'event_espresso'),
109
+					false,
110
+					0
111
+				),
112
+				'PMD_ID'               => new EE_Foreign_Key_Int_Field(
113
+					'PMD_ID',
114
+					esc_html__("Payment Method ID", 'event_espresso'),
115
+					false,
116
+					null,
117
+					'Payment_Method'
118
+				),
119
+				'PAY_gateway_response' => new EE_Plain_Text_Field(
120
+					'PAY_gateway_response',
121
+					esc_html__('Response from Gateway about the payment', 'event_espresso'),
122
+					false,
123
+					''
124
+				),
125
+				'PAY_txn_id_chq_nmbr'  => new EE_Plain_Text_Field(
126
+					'PAY_txn_id_chq_nmbr',
127
+					esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'),
128
+					true,
129
+					''
130
+				),
131
+				'PAY_po_number'        => new EE_Plain_Text_Field(
132
+					'PAY_po_number',
133
+					esc_html__('Purchase or Sales Number', 'event_espresso'),
134
+					true,
135
+					''
136
+				),
137
+				'PAY_extra_accntng'    => new EE_Simple_HTML_Field(
138
+					'PAY_extra_accntng',
139
+					esc_html__('Extra Account Info', 'event_espresso'),
140
+					true,
141
+					''
142
+				),
143
+				'PAY_details'          => new EE_Serialized_Text_Field(
144
+					'PAY_details',
145
+					esc_html__('Full Gateway response about payment', 'event_espresso'),
146
+					true,
147
+					''
148
+				),
149
+				'PAY_redirect_url'     => new EE_Plain_Text_Field(
150
+					'PAY_redirect_url',
151
+					esc_html__("Redirect URL", 'event_espresso'),
152
+					true
153
+				),
154
+				'PAY_redirect_args'    => new EE_Serialized_Text_Field(
155
+					'PAY_redirect_args',
156
+					esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'),
157
+					true
158
+				),
159
+			],
160
+		];
161
+		$this->_model_relations        = [
162
+			'Transaction'          => new EE_Belongs_To_Relation(),
163
+			'Status'               => new EE_Belongs_To_Relation(),
164
+			'Payment_Method'       => new EE_Belongs_To_Relation(),
165
+			'Registration_Payment' => new EE_Has_Many_Relation(),
166
+			'Registration'         => new EE_HABTM_Relation('Registration_Payment'),
167
+		];
168
+		$this->_model_chain_to_wp_user = 'Payment_Method';
169
+		$this->_caps_slug              = 'transactions';
170
+		parent::__construct($timezone);
171
+	}
172
+
173
+
174
+	/**
175
+	 * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
176
+	 * to the payment. This is handy for verifying an IPN hasn't already been processed.
177
+	 *
178
+	 * @param int|string $PAY_txn_id_chq_nmbr
179
+	 * @return EE_Payment
180
+	 * @throws EE_Error
181
+	 * @throws ReflectionException
182
+	 */
183
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr): EE_Payment
184
+	{
185
+		return $this->get_one([['PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr]]);
186
+	}
187
+
188
+
189
+	/**
190
+	 *       retrieve  all payments from db for a particular transaction, optionally with
191
+	 *      a particular status
192
+	 *
193
+	 * @param int $TXN_ID
194
+	 * @param string $status_of_payment   one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided,
195
+	 *                                  gets payments with any status
196
+	 * @return EE_Payment[]
197
+	 * @throws EE_Error
198
+	 * @throws ReflectionException
199
+	 */
200
+	public function get_payments_for_transaction(int $TXN_ID, string $status_of_payment = ''): array
201
+	{
202
+		// all payments for a TXN ordered chronologically
203
+		$query_params = [['TXN_ID' => $TXN_ID], 'order_by' => ['PAY_timestamp' => 'ASC']];
204
+		// if provided with a status, search specifically for that status. Otherwise get them all
205
+		if ($status_of_payment) {
206
+			$query_params[0]['STS_ID'] = $status_of_payment;
207
+		}
208
+		// retrieve payments
209
+		return $this->get_all($query_params);
210
+	}
211
+
212
+
213
+	/**
214
+	 * Only gets payments which have been approved
215
+	 *
216
+	 * @param int $TXN_ID
217
+	 * @return EE_Payment[]
218
+	 * @throws EE_Error
219
+	 * @throws ReflectionException
220
+	 */
221
+	public function get_approved_payments_for_transaction(int $TXN_ID = 0): array
222
+	{
223
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
224
+	}
225
+
226
+
227
+	/**
228
+	 * retrieve  all payments from db between two dates,
229
+	 *
230
+	 * @param string $start_date        incoming start date. If empty the beginning of today is used.
231
+	 * @param string $end_date          incoming end date. If empty the end of today is used.
232
+	 * @param string $format            If you include $start_date or $end_date then you must include the format string
233
+	 *                                  for the format your date is in.
234
+	 * @param string $timezone          If your range is in a different timezone then the current setting on this
235
+	 *                                  WordPress install, then include it here.
236
+	 * @return EE_Payment[]
237
+	 * @throws ReflectionException
238
+	 *
239
+	 * @throws EE_Error
240
+	 */
241
+	public function get_payments_made_between_dates(
242
+		string $start_date = '',
243
+		string $end_date = '',
244
+		string $format = '',
245
+		string $timezone = ''
246
+	): array {
247
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
248
+		// if $start_date or $end date, verify $format is included.
249
+		if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
250
+			throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query',
251
+								  'event_espresso'));
252
+		}
253
+		$now = new DateTime('now');
254
+		// setup timezone objects once
255
+		$modelDateTimeZone  = new DateTimeZone($this->_timezone);
256
+		$passedDateTimeZone = new DateTimeZone($timezone);
257
+		// setup start date
258
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
259
+		EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
260
+		$start_date = $start_date->format('Y-m-d') . ' 00:00:00';
261
+		$start_date = strtotime($start_date);
262
+		// setup end date
263
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
264
+		EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
265
+		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
266
+		$end_date = strtotime($end_date);
267
+
268
+		// make sure our start date is the lowest value and vice versa
269
+		$start = min($start_date, $end_date);
270
+		$end   = max($start_date, $end_date);
271
+
272
+		// yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
273
+		$start_date = $this->convert_datetime_for_query('PAY_timestamp',
274
+														date('Y-m-d', $start) . ' 00:00:00',
275
+														'Y-m-d H:i:s',
276
+														$this->get_timezone());
277
+		$end_date   = $this->convert_datetime_for_query('PAY_timestamp',
278
+														date('Y-m-d', $end) . ' 23:59:59',
279
+														'Y-m-d H:i:s',
280
+														$this->get_timezone());
281
+
282
+		return $this->get_all([['PAY_timestamp' => ['>=', $start_date], 'PAY_timestamp*' => ['<=', $end_date]]]);
283
+	}
284
+
285
+	/**
286
+	 * methods for EEMI_Payment
287
+	 */
288
+	/**
289
+	 * returns a string for the approved status
290
+	 *
291
+	 * @return  string
292
+	 */
293
+	public function approved_status(): string
294
+	{
295
+		return self::status_id_approved;
296
+	}
297
+
298
+
299
+	/**
300
+	 * returns a string for the pending status
301
+	 *
302
+	 * @return  string
303
+	 */
304
+	public function pending_status(): string
305
+	{
306
+		return self::status_id_pending;
307
+	}
308
+
309
+
310
+	/**
311
+	 * returns a string for the cancelled status
312
+	 *
313
+	 * @return  string
314
+	 */
315
+	public function cancelled_status(): string
316
+	{
317
+		return self::status_id_cancelled;
318
+	}
319
+
320
+
321
+	/**
322
+	 * returns a string for the failed status
323
+	 *
324
+	 * @return  string
325
+	 */
326
+	public function failed_status(): string
327
+	{
328
+		return self::status_id_failed;
329
+	}
330
+
331
+
332
+	/**
333
+	 * returns a string for the declined status
334
+	 *
335
+	 * @return  string
336
+	 */
337
+	public function declined_status(): string
338
+	{
339
+		return self::status_id_declined;
340
+	}
341 341
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
                 ),
159 159
             ],
160 160
         ];
161
-        $this->_model_relations        = [
161
+        $this->_model_relations = [
162 162
             'Transaction'          => new EE_Belongs_To_Relation(),
163 163
             'Status'               => new EE_Belongs_To_Relation(),
164 164
             'Payment_Method'       => new EE_Belongs_To_Relation(),
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     ): array {
247 247
         $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
248 248
         // if $start_date or $end date, verify $format is included.
249
-        if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
249
+        if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) {
250 250
             throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query',
251 251
                                   'event_espresso'));
252 252
         }
@@ -257,12 +257,12 @@  discard block
 block discarded – undo
257 257
         // setup start date
258 258
         $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
259 259
         EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
260
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
260
+        $start_date = $start_date->format('Y-m-d').' 00:00:00';
261 261
         $start_date = strtotime($start_date);
262 262
         // setup end date
263 263
         $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
264 264
         EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
265
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
265
+        $end_date = $end_date->format('Y-m-d').' 23:59:59';
266 266
         $end_date = strtotime($end_date);
267 267
 
268 268
         // make sure our start date is the lowest value and vice versa
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 
272 272
         // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
273 273
         $start_date = $this->convert_datetime_for_query('PAY_timestamp',
274
-                                                        date('Y-m-d', $start) . ' 00:00:00',
274
+                                                        date('Y-m-d', $start).' 00:00:00',
275 275
                                                         'Y-m-d H:i:s',
276 276
                                                         $this->get_timezone());
277
-        $end_date   = $this->convert_datetime_for_query('PAY_timestamp',
278
-                                                        date('Y-m-d', $end) . ' 23:59:59',
277
+        $end_date = $this->convert_datetime_for_query('PAY_timestamp',
278
+                                                        date('Y-m-d', $end).' 23:59:59',
279 279
                                                         'Y-m-d H:i:s',
280 280
                                                         $this->get_timezone());
281 281
 
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -10,209 +10,209 @@
 block discarded – undo
10 10
 class EEM_Venue extends EEM_CPT_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @var EEM_Venue
15
-     */
16
-    protected static $_instance;
13
+	/**
14
+	 * @var EEM_Venue
15
+	 */
16
+	protected static $_instance;
17 17
 
18 18
 
19
-    /**
20
-     * EEM_Venue constructor.
21
-     *
22
-     * @param string $timezone
23
-     * @throws EE_Error
24
-     */
25
-    protected function __construct(string $timezone = '')
26
-    {
27
-        $this->singular_item    = esc_html__('Venue', 'event_espresso');
28
-        $this->plural_item      = esc_html__('Venues', 'event_espresso');
29
-        $this->_tables          = [
30
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
31
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
32
-        ];
33
-        $this->_fields          = [
34
-            'Venue_CPT'  => [
35
-                'VNU_ID'         => new EE_Primary_Key_Int_Field(
36
-                    'ID',
37
-                    esc_html__("Venue ID", "event_espresso")
38
-                ),
39
-                'VNU_name'       => new EE_Plain_Text_Field(
40
-                    'post_title',
41
-                    esc_html__("Venue Name", "event_espresso"),
42
-                    false,
43
-                    ''
44
-                ),
45
-                'VNU_desc'       => new EE_Post_Content_Field(
46
-                    'post_content',
47
-                    esc_html__("Venue Description", "event_espresso"),
48
-                    false,
49
-                    ''
50
-                ),
51
-                'VNU_identifier' => new EE_Slug_Field(
52
-                    'post_name',
53
-                    esc_html__("Venue Identifier", "event_espresso"),
54
-                    false,
55
-                    ''
56
-                ),
57
-                'VNU_created'    => new EE_Datetime_Field(
58
-                    'post_date',
59
-                    esc_html__("Date Venue Created", "event_espresso"),
60
-                    false,
61
-                    EE_Datetime_Field::now
62
-                ),
63
-                'VNU_short_desc' => new EE_Plain_Text_Field(
64
-                    'post_excerpt',
65
-                    esc_html__("Short Description of Venue", "event_espresso"),
66
-                    true,
67
-                    ''
68
-                ),
69
-                'VNU_modified'   => new EE_Datetime_Field(
70
-                    'post_modified',
71
-                    esc_html__("Venue Modified Date", "event_espresso"),
72
-                    false,
73
-                    EE_Datetime_Field::now
74
-                ),
75
-                'VNU_wp_user'    => new EE_WP_User_Field(
76
-                    'post_author',
77
-                    esc_html__("Venue Creator ID", "event_espresso"),
78
-                    false
79
-                ),
80
-                'parent'         => new EE_Integer_Field(
81
-                    'post_parent',
82
-                    esc_html__("Venue Parent ID", "event_espresso"),
83
-                    false,
84
-                    0
85
-                ),
86
-                'VNU_order'      => new EE_Integer_Field(
87
-                    'menu_order',
88
-                    esc_html__("Venue order", "event_espresso"),
89
-                    false,
90
-                    1
91
-                ),
92
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
93
-                'password'       => new EE_Password_Field(
94
-                    'post_password',
95
-                    esc_html__('Password', 'event_espresso'),
96
-                    false,
97
-                    '',
98
-                    [
99
-                        'VNU_desc',
100
-                        'VNU_short_desc',
101
-                        'VNU_address',
102
-                        'VNU_address2',
103
-                        'VNU_city',
104
-                        'STA_ID',
105
-                        'CNT_ISO',
106
-                        'VNU_zip',
107
-                        'VNU_phone',
108
-                        'VNU_capacity',
109
-                        'VNU_url',
110
-                        'VNU_virtual_phone',
111
-                        'VNU_virtual_url',
112
-                        'VNU_google_map_link',
113
-                        'VNU_enable_for_gmap',
114
-                    ]
115
-                ),
116
-            ],
117
-            'Venue_Meta' => [
118
-                'VNUM_ID'             => new EE_DB_Only_Int_Field(
119
-                    'VNUM_ID',
120
-                    esc_html__("ID of Venue Meta Row", "event_espresso"),
121
-                    false
122
-                ),
123
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
124
-                    'VNU_ID',
125
-                    esc_html__("Foreign Key to Venue Post ", "event_espresso"),
126
-                    false
127
-                ),
128
-                'VNU_address'         => new EE_Plain_Text_Field(
129
-                    'VNU_address',
130
-                    esc_html__("Venue Address line 1", "event_espresso"),
131
-                    true,
132
-                    ''
133
-                ),
134
-                'VNU_address2'        => new EE_Plain_Text_Field(
135
-                    'VNU_address2',
136
-                    esc_html__("Venue Address line 2", "event_espresso"),
137
-                    true,
138
-                    ''
139
-                ),
140
-                'VNU_city'            => new EE_Plain_Text_Field(
141
-                    'VNU_city',
142
-                    esc_html__("Venue City", "event_espresso"),
143
-                    true,
144
-                    ''
145
-                ),
146
-                'STA_ID'              => new EE_Foreign_Key_Int_Field(
147
-                    'STA_ID',
148
-                    esc_html__("State ID", "event_espresso"),
149
-                    true,
150
-                    null,
151
-                    'State'
152
-                ),
153
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field(
154
-                    'CNT_ISO',
155
-                    esc_html__("Country Code", "event_espresso"),
156
-                    true,
157
-                    null,
158
-                    'Country'
159
-                ),
160
-                'VNU_zip'             => new EE_Plain_Text_Field(
161
-                    'VNU_zip',
162
-                    esc_html__("Venue Zip/Postal Code", "event_espresso"),
163
-                    true
164
-                ),
165
-                'VNU_phone'           => new EE_Plain_Text_Field(
166
-                    'VNU_phone',
167
-                    esc_html__("Venue Phone", "event_espresso"),
168
-                    true
169
-                ),
170
-                'VNU_capacity'        => new EE_Infinite_Integer_Field(
171
-                    'VNU_capacity',
172
-                    esc_html__("Venue Capacity", "event_espresso"),
173
-                    true,
174
-                    EE_INF
175
-                ),
176
-                'VNU_url'             => new EE_Plain_Text_Field(
177
-                    'VNU_url',
178
-                    esc_html__('Venue Website', 'event_espresso'),
179
-                    true
180
-                ),
181
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field(
182
-                    'VNU_virtual_phone',
183
-                    esc_html__('Call in Number', 'event_espresso'),
184
-                    true
185
-                ),
186
-                'VNU_virtual_url'     => new EE_Plain_Text_Field(
187
-                    'VNU_virtual_url',
188
-                    esc_html__('Virtual URL', 'event_espresso'),
189
-                    true
190
-                ),
191
-                'VNU_google_map_link' => new EE_Plain_Text_Field(
192
-                    'VNU_google_map_link',
193
-                    esc_html__('Google Map Link', 'event_espresso'),
194
-                    true
195
-                ),
196
-                'VNU_enable_for_gmap' => new EE_Boolean_Field(
197
-                    'VNU_enable_for_gmap',
198
-                    esc_html__('Show Google Map?', 'event_espresso'),
199
-                    false,
200
-                    false
201
-                ),
202
-            ],
203
-        ];
204
-        $this->_model_relations = [
205
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
206
-            'State'             => new EE_Belongs_To_Relation(),
207
-            'Country'           => new EE_Belongs_To_Relation(),
208
-            'Event_Venue'       => new EE_Has_Many_Relation(),
209
-            'WP_User'           => new EE_Belongs_To_Relation(),
210
-            'Term_Relationship' => new EE_Has_Many_Relation(),
211
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
212
-        ];
213
-        // this model is generally available for reading
214
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
215
-        $this->model_chain_to_password                            = '';
216
-        parent::__construct($timezone);
217
-    }
19
+	/**
20
+	 * EEM_Venue constructor.
21
+	 *
22
+	 * @param string $timezone
23
+	 * @throws EE_Error
24
+	 */
25
+	protected function __construct(string $timezone = '')
26
+	{
27
+		$this->singular_item    = esc_html__('Venue', 'event_espresso');
28
+		$this->plural_item      = esc_html__('Venues', 'event_espresso');
29
+		$this->_tables          = [
30
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
31
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
32
+		];
33
+		$this->_fields          = [
34
+			'Venue_CPT'  => [
35
+				'VNU_ID'         => new EE_Primary_Key_Int_Field(
36
+					'ID',
37
+					esc_html__("Venue ID", "event_espresso")
38
+				),
39
+				'VNU_name'       => new EE_Plain_Text_Field(
40
+					'post_title',
41
+					esc_html__("Venue Name", "event_espresso"),
42
+					false,
43
+					''
44
+				),
45
+				'VNU_desc'       => new EE_Post_Content_Field(
46
+					'post_content',
47
+					esc_html__("Venue Description", "event_espresso"),
48
+					false,
49
+					''
50
+				),
51
+				'VNU_identifier' => new EE_Slug_Field(
52
+					'post_name',
53
+					esc_html__("Venue Identifier", "event_espresso"),
54
+					false,
55
+					''
56
+				),
57
+				'VNU_created'    => new EE_Datetime_Field(
58
+					'post_date',
59
+					esc_html__("Date Venue Created", "event_espresso"),
60
+					false,
61
+					EE_Datetime_Field::now
62
+				),
63
+				'VNU_short_desc' => new EE_Plain_Text_Field(
64
+					'post_excerpt',
65
+					esc_html__("Short Description of Venue", "event_espresso"),
66
+					true,
67
+					''
68
+				),
69
+				'VNU_modified'   => new EE_Datetime_Field(
70
+					'post_modified',
71
+					esc_html__("Venue Modified Date", "event_espresso"),
72
+					false,
73
+					EE_Datetime_Field::now
74
+				),
75
+				'VNU_wp_user'    => new EE_WP_User_Field(
76
+					'post_author',
77
+					esc_html__("Venue Creator ID", "event_espresso"),
78
+					false
79
+				),
80
+				'parent'         => new EE_Integer_Field(
81
+					'post_parent',
82
+					esc_html__("Venue Parent ID", "event_espresso"),
83
+					false,
84
+					0
85
+				),
86
+				'VNU_order'      => new EE_Integer_Field(
87
+					'menu_order',
88
+					esc_html__("Venue order", "event_espresso"),
89
+					false,
90
+					1
91
+				),
92
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
93
+				'password'       => new EE_Password_Field(
94
+					'post_password',
95
+					esc_html__('Password', 'event_espresso'),
96
+					false,
97
+					'',
98
+					[
99
+						'VNU_desc',
100
+						'VNU_short_desc',
101
+						'VNU_address',
102
+						'VNU_address2',
103
+						'VNU_city',
104
+						'STA_ID',
105
+						'CNT_ISO',
106
+						'VNU_zip',
107
+						'VNU_phone',
108
+						'VNU_capacity',
109
+						'VNU_url',
110
+						'VNU_virtual_phone',
111
+						'VNU_virtual_url',
112
+						'VNU_google_map_link',
113
+						'VNU_enable_for_gmap',
114
+					]
115
+				),
116
+			],
117
+			'Venue_Meta' => [
118
+				'VNUM_ID'             => new EE_DB_Only_Int_Field(
119
+					'VNUM_ID',
120
+					esc_html__("ID of Venue Meta Row", "event_espresso"),
121
+					false
122
+				),
123
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
124
+					'VNU_ID',
125
+					esc_html__("Foreign Key to Venue Post ", "event_espresso"),
126
+					false
127
+				),
128
+				'VNU_address'         => new EE_Plain_Text_Field(
129
+					'VNU_address',
130
+					esc_html__("Venue Address line 1", "event_espresso"),
131
+					true,
132
+					''
133
+				),
134
+				'VNU_address2'        => new EE_Plain_Text_Field(
135
+					'VNU_address2',
136
+					esc_html__("Venue Address line 2", "event_espresso"),
137
+					true,
138
+					''
139
+				),
140
+				'VNU_city'            => new EE_Plain_Text_Field(
141
+					'VNU_city',
142
+					esc_html__("Venue City", "event_espresso"),
143
+					true,
144
+					''
145
+				),
146
+				'STA_ID'              => new EE_Foreign_Key_Int_Field(
147
+					'STA_ID',
148
+					esc_html__("State ID", "event_espresso"),
149
+					true,
150
+					null,
151
+					'State'
152
+				),
153
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field(
154
+					'CNT_ISO',
155
+					esc_html__("Country Code", "event_espresso"),
156
+					true,
157
+					null,
158
+					'Country'
159
+				),
160
+				'VNU_zip'             => new EE_Plain_Text_Field(
161
+					'VNU_zip',
162
+					esc_html__("Venue Zip/Postal Code", "event_espresso"),
163
+					true
164
+				),
165
+				'VNU_phone'           => new EE_Plain_Text_Field(
166
+					'VNU_phone',
167
+					esc_html__("Venue Phone", "event_espresso"),
168
+					true
169
+				),
170
+				'VNU_capacity'        => new EE_Infinite_Integer_Field(
171
+					'VNU_capacity',
172
+					esc_html__("Venue Capacity", "event_espresso"),
173
+					true,
174
+					EE_INF
175
+				),
176
+				'VNU_url'             => new EE_Plain_Text_Field(
177
+					'VNU_url',
178
+					esc_html__('Venue Website', 'event_espresso'),
179
+					true
180
+				),
181
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field(
182
+					'VNU_virtual_phone',
183
+					esc_html__('Call in Number', 'event_espresso'),
184
+					true
185
+				),
186
+				'VNU_virtual_url'     => new EE_Plain_Text_Field(
187
+					'VNU_virtual_url',
188
+					esc_html__('Virtual URL', 'event_espresso'),
189
+					true
190
+				),
191
+				'VNU_google_map_link' => new EE_Plain_Text_Field(
192
+					'VNU_google_map_link',
193
+					esc_html__('Google Map Link', 'event_espresso'),
194
+					true
195
+				),
196
+				'VNU_enable_for_gmap' => new EE_Boolean_Field(
197
+					'VNU_enable_for_gmap',
198
+					esc_html__('Show Google Map?', 'event_espresso'),
199
+					false,
200
+					false
201
+				),
202
+			],
203
+		];
204
+		$this->_model_relations = [
205
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
206
+			'State'             => new EE_Belongs_To_Relation(),
207
+			'Country'           => new EE_Belongs_To_Relation(),
208
+			'Event_Venue'       => new EE_Has_Many_Relation(),
209
+			'WP_User'           => new EE_Belongs_To_Relation(),
210
+			'Term_Relationship' => new EE_Has_Many_Relation(),
211
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
212
+		];
213
+		// this model is generally available for reading
214
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
215
+		$this->model_chain_to_password                            = '';
216
+		parent::__construct($timezone);
217
+	}
218 218
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
             'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
31 31
             'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
32 32
         ];
33
-        $this->_fields          = [
33
+        $this->_fields = [
34 34
             'Venue_CPT'  => [
35 35
                 'VNU_ID'         => new EE_Primary_Key_Int_Field(
36 36
                     'ID',
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
             'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
212 212
         ];
213 213
         // this model is generally available for reading
214
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
214
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
215 215
         $this->model_chain_to_password                            = '';
216 216
         parent::__construct($timezone);
217 217
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Extra_Join.model.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -21,65 +21,65 @@
 block discarded – undo
21 21
  */
22 22
 class EEM_Extra_Join extends EEM_Base
23 23
 {
24
-    // private instance of the Extra Join object
25
-    protected static $_instance;
24
+	// private instance of the Extra Join object
25
+	protected static $_instance;
26 26
 
27 27
 
28
-    /**
29
-     * EEM_Extra_Join constructor.
30
-     *
31
-     * @param string $timezone
32
-     * @throws EE_Error
33
-     */
34
-    public function __construct(string $timezone = '')
35
-    {
36
-        $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models);
37
-        $this->_tables        = [
38
-            'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'),
39
-        ];
40
-        $this->_fields        = [
41
-            'Extra_Join' => [
42
-                'EXJ_ID'                => new EE_Primary_Key_Int_Field(
43
-                    'EXJ_ID', esc_html__('Extra Join ID', 'event_espresso')
44
-                ),
45
-                'EXJ_first_model_ID'    => new EE_Foreign_Key_String_Field(
46
-                    'EXJ_first_model_ID',
47
-                    esc_html__('First Model ID', 'event_espresso'),
48
-                    true,
49
-                    0,
50
-                    $models_this_can_join
51
-                ),
52
-                'EXJ_first_model_name'  => new EE_Any_Foreign_Model_Name_Field(
53
-                    'EXJ_first_model_name',
54
-                    esc_html__('First Model Name', 'event_espresso'),
55
-                    true,
56
-                    '',
57
-                    $models_this_can_join
58
-                ),
59
-                'EXJ_second_model_ID'   => new EE_Foreign_Key_String_Field(
60
-                    'EXJ_second_model_ID',
61
-                    esc_html__('Second Model ID', 'event_espresso'),
62
-                    true,
63
-                    0,
64
-                    $models_this_can_join
65
-                ),
66
-                'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field(
67
-                    'EXJ_second_model_name',
68
-                    esc_html__('Second Model Name', 'event_espresso'),
69
-                    true,
70
-                    '',
71
-                    $models_this_can_join
72
-                ),
28
+	/**
29
+	 * EEM_Extra_Join constructor.
30
+	 *
31
+	 * @param string $timezone
32
+	 * @throws EE_Error
33
+	 */
34
+	public function __construct(string $timezone = '')
35
+	{
36
+		$models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models);
37
+		$this->_tables        = [
38
+			'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'),
39
+		];
40
+		$this->_fields        = [
41
+			'Extra_Join' => [
42
+				'EXJ_ID'                => new EE_Primary_Key_Int_Field(
43
+					'EXJ_ID', esc_html__('Extra Join ID', 'event_espresso')
44
+				),
45
+				'EXJ_first_model_ID'    => new EE_Foreign_Key_String_Field(
46
+					'EXJ_first_model_ID',
47
+					esc_html__('First Model ID', 'event_espresso'),
48
+					true,
49
+					0,
50
+					$models_this_can_join
51
+				),
52
+				'EXJ_first_model_name'  => new EE_Any_Foreign_Model_Name_Field(
53
+					'EXJ_first_model_name',
54
+					esc_html__('First Model Name', 'event_espresso'),
55
+					true,
56
+					'',
57
+					$models_this_can_join
58
+				),
59
+				'EXJ_second_model_ID'   => new EE_Foreign_Key_String_Field(
60
+					'EXJ_second_model_ID',
61
+					esc_html__('Second Model ID', 'event_espresso'),
62
+					true,
63
+					0,
64
+					$models_this_can_join
65
+				),
66
+				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field(
67
+					'EXJ_second_model_name',
68
+					esc_html__('Second Model Name', 'event_espresso'),
69
+					true,
70
+					'',
71
+					$models_this_can_join
72
+				),
73 73
 
74
-            ],
75
-        ];
76
-        // this model is weird in that it has two foreign key columns which can point to any model/table.
77
-        // eg a foreign key to event will be in "EXJ_first_model_ID", provided the other
78
-        // model linked to is alphabetically greater than event (eg venue).
79
-        // but if the model linked to is alphabetically lower (eg attendee),
80
-        // the foreign key to the event will be in "EXJ_second_model_ID"
81
-        // so normal usage of foreign keys is weird. So don't define any
82
-        // relations to other models because they won't work properly with this model
83
-        parent::__construct($timezone);
84
-    }
74
+			],
75
+		];
76
+		// this model is weird in that it has two foreign key columns which can point to any model/table.
77
+		// eg a foreign key to event will be in "EXJ_first_model_ID", provided the other
78
+		// model linked to is alphabetically greater than event (eg venue).
79
+		// but if the model linked to is alphabetically lower (eg attendee),
80
+		// the foreign key to the event will be in "EXJ_second_model_ID"
81
+		// so normal usage of foreign keys is weird. So don't define any
82
+		// relations to other models because they won't work properly with this model
83
+		parent::__construct($timezone);
84
+	}
85 85
 }
Please login to merge, or discard this patch.
core/db_models/EEM_State.model.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -10,213 +10,213 @@
 block discarded – undo
10 10
 class EEM_State extends EEM_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @var EEM_State
15
-     */
16
-    protected static $_instance;
17
-
18
-    /**
19
-     * @var EE_State[]
20
-     */
21
-    private static $_all_states;
22
-
23
-    /**
24
-     * @var EE_State[]
25
-     */
26
-    private static $_active_states;
27
-
28
-
29
-    protected function __construct(string $timezone = '')
30
-    {
31
-        $this->singular_item = esc_html__('State/Province', 'event_espresso');
32
-        $this->plural_item   = esc_html__('States/Provinces', 'event_espresso');
33
-
34
-        $this->_tables = [
35
-            'State' => new EE_Primary_Table('esp_state', 'STA_ID'),
36
-        ];
37
-
38
-        $this->_fields          = [
39
-            'State' => [
40
-                'STA_ID'     => new EE_Primary_Key_Int_Field(
41
-                    'STA_ID',
42
-                    esc_html__('State ID', 'event_espresso')
43
-                ),
44
-                'CNT_ISO'    => new EE_Foreign_Key_String_Field(
45
-                    'CNT_ISO',
46
-                    esc_html__('Country ISO Code', 'event_espresso'),
47
-                    false,
48
-                    null,
49
-                    'Country'
50
-                ),
51
-                'STA_abbrev' => new EE_Plain_Text_Field(
52
-                    'STA_abbrev',
53
-                    esc_html__('State Abbreviation', 'event_espresso'),
54
-                    false,
55
-                    ''
56
-                ),
57
-                'STA_name'   => new EE_Plain_Text_Field(
58
-                    'STA_name',
59
-                    esc_html__('State Name', 'event_espresso'),
60
-                    false,
61
-                    ''
62
-                ),
63
-                'STA_active' => new EE_Boolean_Field(
64
-                    'STA_active',
65
-                    esc_html__('State Active Flag', 'event_espresso'),
66
-                    false,
67
-                    false
68
-                ),
69
-            ],
70
-        ];
71
-        $this->_model_relations = [
72
-            'Attendee' => new EE_Has_Many_Relation(),
73
-            'Country'  => new EE_Belongs_To_Relation(),
74
-            'Venue'    => new EE_Has_Many_Relation(),
75
-        ];
76
-        // this model is generally available for reading
77
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
78
-        // @todo: only show STA_active
79
-        parent::__construct($timezone);
80
-    }
81
-
82
-
83
-    /**
84
-     * reset_cached_states
85
-     *
86
-     * @return void
87
-     */
88
-    public function reset_cached_states()
89
-    {
90
-        EEM_State::$_active_states = null;
91
-        EEM_State::$_all_states    = null;
92
-    }
93
-
94
-
95
-    /**
96
-     * _get_states
97
-     *
98
-     * @return EE_State[]
99
-     * @throws EE_Error
100
-     * @throws ReflectionException
101
-     */
102
-    public function get_all_states(): array
103
-    {
104
-        if (self::$_all_states === null) {
105
-            self::$_all_states = $this->get_all(['order_by' => ['STA_name' => 'ASC'], 'limit' => [0, 99999]]);
106
-        }
107
-        return self::$_all_states;
108
-    }
109
-
110
-
111
-    /**
112
-     * @param EE_Country[] $countries
113
-     * @param bool         $flush_cache
114
-     * @return EE_State[]
115
-     * @throws EE_Error
116
-     * @throws ReflectionException
117
-     */
118
-    public function get_all_active_states(array $countries = [], bool $flush_cache = false): array
119
-    {
120
-        if (! self::$_active_states || $flush_cache) {
121
-            $countries            = ! empty($countries) && is_array($countries)
122
-                ? $countries
123
-                : EEM_Country::instance()->get_all_active_countries();
124
-            self::$_active_states = $this->get_all(
125
-                [
126
-                    [
127
-                        'STA_active' => true,
128
-                        'CNT_ISO'    => ['IN', array_keys($countries)],
129
-                    ],
130
-                    'order_by'   => ['STA_name' => 'ASC'],
131
-                    'limit'      => [0, 99999],
132
-                    'force_join' => ['Country'],
133
-                ]
134
-            );
135
-        }
136
-        return self::$_active_states;
137
-    }
138
-
139
-
140
-    /**
141
-     *  get_all_states_of_active_countries
142
-     *
143
-     * @return EE_State[]
144
-     * @throws EE_Error
145
-     * @throws ReflectionException
146
-     */
147
-    public function get_all_states_of_active_countries(): array
148
-    {
149
-        return $this->get_all(
150
-            [
151
-                ['Country.CNT_active' => true, 'STA_active' => true],
152
-                'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
153
-            ]
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *  get_all_states_of_active_countries
160
-     *
161
-     * @param $countries
162
-     * @return EE_State[]
163
-     * @throws EE_Error
164
-     * @throws ReflectionException
165
-     */
166
-    public function get_all_active_states_for_these_countries($countries): array
167
-    {
168
-        if (! $countries) {
169
-            return [];
170
-        }
171
-        return $this->get_all(
172
-            [
173
-                ['Country.CNT_ISO' => ['IN', array_keys($countries)], 'STA_active' => true],
174
-                'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
175
-            ]
176
-        );
177
-    }
178
-
179
-
180
-    /**
181
-     *  get_all_states_of_active_countries
182
-     *
183
-     * @param $countries
184
-     * @return EE_State[]
185
-     * @throws EE_Error
186
-     * @throws ReflectionException
187
-     */
188
-    public function get_all_states_for_these_countries($countries): array
189
-    {
190
-        if (! $countries) {
191
-            return [];
192
-        }
193
-        return $this->get_all(
194
-            [
195
-                ['Country.CNT_ISO' => ['IN', array_keys($countries)]],
196
-                'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
197
-            ]
198
-        );
199
-    }
200
-
201
-
202
-    /**
203
-     * Gets the state's name by its ID
204
-     *
205
-     * @param string $state_ID
206
-     * @return string
207
-     * @throws EE_Error
208
-     * @throws ReflectionException
209
-     */
210
-    public function get_state_name_by_ID(string $state_ID): string
211
-    {
212
-        if (
213
-            isset(self::$_all_states[ $state_ID ]) && self::$_all_states[ $state_ID ] instanceof EE_State
214
-        ) {
215
-            return self::$_all_states[ $state_ID ]->name();
216
-        }
217
-        $names = $this->get_col([['STA_ID' => $state_ID], 'limit' => 1], 'STA_name');
218
-        return is_array($names) && ! empty($names)
219
-            ? reset($names)
220
-            : '';
221
-    }
13
+	/**
14
+	 * @var EEM_State
15
+	 */
16
+	protected static $_instance;
17
+
18
+	/**
19
+	 * @var EE_State[]
20
+	 */
21
+	private static $_all_states;
22
+
23
+	/**
24
+	 * @var EE_State[]
25
+	 */
26
+	private static $_active_states;
27
+
28
+
29
+	protected function __construct(string $timezone = '')
30
+	{
31
+		$this->singular_item = esc_html__('State/Province', 'event_espresso');
32
+		$this->plural_item   = esc_html__('States/Provinces', 'event_espresso');
33
+
34
+		$this->_tables = [
35
+			'State' => new EE_Primary_Table('esp_state', 'STA_ID'),
36
+		];
37
+
38
+		$this->_fields          = [
39
+			'State' => [
40
+				'STA_ID'     => new EE_Primary_Key_Int_Field(
41
+					'STA_ID',
42
+					esc_html__('State ID', 'event_espresso')
43
+				),
44
+				'CNT_ISO'    => new EE_Foreign_Key_String_Field(
45
+					'CNT_ISO',
46
+					esc_html__('Country ISO Code', 'event_espresso'),
47
+					false,
48
+					null,
49
+					'Country'
50
+				),
51
+				'STA_abbrev' => new EE_Plain_Text_Field(
52
+					'STA_abbrev',
53
+					esc_html__('State Abbreviation', 'event_espresso'),
54
+					false,
55
+					''
56
+				),
57
+				'STA_name'   => new EE_Plain_Text_Field(
58
+					'STA_name',
59
+					esc_html__('State Name', 'event_espresso'),
60
+					false,
61
+					''
62
+				),
63
+				'STA_active' => new EE_Boolean_Field(
64
+					'STA_active',
65
+					esc_html__('State Active Flag', 'event_espresso'),
66
+					false,
67
+					false
68
+				),
69
+			],
70
+		];
71
+		$this->_model_relations = [
72
+			'Attendee' => new EE_Has_Many_Relation(),
73
+			'Country'  => new EE_Belongs_To_Relation(),
74
+			'Venue'    => new EE_Has_Many_Relation(),
75
+		];
76
+		// this model is generally available for reading
77
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
78
+		// @todo: only show STA_active
79
+		parent::__construct($timezone);
80
+	}
81
+
82
+
83
+	/**
84
+	 * reset_cached_states
85
+	 *
86
+	 * @return void
87
+	 */
88
+	public function reset_cached_states()
89
+	{
90
+		EEM_State::$_active_states = null;
91
+		EEM_State::$_all_states    = null;
92
+	}
93
+
94
+
95
+	/**
96
+	 * _get_states
97
+	 *
98
+	 * @return EE_State[]
99
+	 * @throws EE_Error
100
+	 * @throws ReflectionException
101
+	 */
102
+	public function get_all_states(): array
103
+	{
104
+		if (self::$_all_states === null) {
105
+			self::$_all_states = $this->get_all(['order_by' => ['STA_name' => 'ASC'], 'limit' => [0, 99999]]);
106
+		}
107
+		return self::$_all_states;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param EE_Country[] $countries
113
+	 * @param bool         $flush_cache
114
+	 * @return EE_State[]
115
+	 * @throws EE_Error
116
+	 * @throws ReflectionException
117
+	 */
118
+	public function get_all_active_states(array $countries = [], bool $flush_cache = false): array
119
+	{
120
+		if (! self::$_active_states || $flush_cache) {
121
+			$countries            = ! empty($countries) && is_array($countries)
122
+				? $countries
123
+				: EEM_Country::instance()->get_all_active_countries();
124
+			self::$_active_states = $this->get_all(
125
+				[
126
+					[
127
+						'STA_active' => true,
128
+						'CNT_ISO'    => ['IN', array_keys($countries)],
129
+					],
130
+					'order_by'   => ['STA_name' => 'ASC'],
131
+					'limit'      => [0, 99999],
132
+					'force_join' => ['Country'],
133
+				]
134
+			);
135
+		}
136
+		return self::$_active_states;
137
+	}
138
+
139
+
140
+	/**
141
+	 *  get_all_states_of_active_countries
142
+	 *
143
+	 * @return EE_State[]
144
+	 * @throws EE_Error
145
+	 * @throws ReflectionException
146
+	 */
147
+	public function get_all_states_of_active_countries(): array
148
+	{
149
+		return $this->get_all(
150
+			[
151
+				['Country.CNT_active' => true, 'STA_active' => true],
152
+				'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
153
+			]
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *  get_all_states_of_active_countries
160
+	 *
161
+	 * @param $countries
162
+	 * @return EE_State[]
163
+	 * @throws EE_Error
164
+	 * @throws ReflectionException
165
+	 */
166
+	public function get_all_active_states_for_these_countries($countries): array
167
+	{
168
+		if (! $countries) {
169
+			return [];
170
+		}
171
+		return $this->get_all(
172
+			[
173
+				['Country.CNT_ISO' => ['IN', array_keys($countries)], 'STA_active' => true],
174
+				'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
175
+			]
176
+		);
177
+	}
178
+
179
+
180
+	/**
181
+	 *  get_all_states_of_active_countries
182
+	 *
183
+	 * @param $countries
184
+	 * @return EE_State[]
185
+	 * @throws EE_Error
186
+	 * @throws ReflectionException
187
+	 */
188
+	public function get_all_states_for_these_countries($countries): array
189
+	{
190
+		if (! $countries) {
191
+			return [];
192
+		}
193
+		return $this->get_all(
194
+			[
195
+				['Country.CNT_ISO' => ['IN', array_keys($countries)]],
196
+				'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
197
+			]
198
+		);
199
+	}
200
+
201
+
202
+	/**
203
+	 * Gets the state's name by its ID
204
+	 *
205
+	 * @param string $state_ID
206
+	 * @return string
207
+	 * @throws EE_Error
208
+	 * @throws ReflectionException
209
+	 */
210
+	public function get_state_name_by_ID(string $state_ID): string
211
+	{
212
+		if (
213
+			isset(self::$_all_states[ $state_ID ]) && self::$_all_states[ $state_ID ] instanceof EE_State
214
+		) {
215
+			return self::$_all_states[ $state_ID ]->name();
216
+		}
217
+		$names = $this->get_col([['STA_ID' => $state_ID], 'limit' => 1], 'STA_name');
218
+		return is_array($names) && ! empty($names)
219
+			? reset($names)
220
+			: '';
221
+	}
222 222
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
             'State' => new EE_Primary_Table('esp_state', 'STA_ID'),
36 36
         ];
37 37
 
38
-        $this->_fields          = [
38
+        $this->_fields = [
39 39
             'State' => [
40 40
                 'STA_ID'     => new EE_Primary_Key_Int_Field(
41 41
                     'STA_ID',
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             'Venue'    => new EE_Has_Many_Relation(),
75 75
         ];
76 76
         // this model is generally available for reading
77
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
77
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
78 78
         // @todo: only show STA_active
79 79
         parent::__construct($timezone);
80 80
     }
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      */
118 118
     public function get_all_active_states(array $countries = [], bool $flush_cache = false): array
119 119
     {
120
-        if (! self::$_active_states || $flush_cache) {
120
+        if ( ! self::$_active_states || $flush_cache) {
121 121
             $countries            = ! empty($countries) && is_array($countries)
122 122
                 ? $countries
123 123
                 : EEM_Country::instance()->get_all_active_countries();
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function get_all_active_states_for_these_countries($countries): array
167 167
     {
168
-        if (! $countries) {
168
+        if ( ! $countries) {
169 169
             return [];
170 170
         }
171 171
         return $this->get_all(
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function get_all_states_for_these_countries($countries): array
189 189
     {
190
-        if (! $countries) {
190
+        if ( ! $countries) {
191 191
             return [];
192 192
         }
193 193
         return $this->get_all(
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
     public function get_state_name_by_ID(string $state_ID): string
211 211
     {
212 212
         if (
213
-            isset(self::$_all_states[ $state_ID ]) && self::$_all_states[ $state_ID ] instanceof EE_State
213
+            isset(self::$_all_states[$state_ID]) && self::$_all_states[$state_ID] instanceof EE_State
214 214
         ) {
215
-            return self::$_all_states[ $state_ID ]->name();
215
+            return self::$_all_states[$state_ID]->name();
216 216
         }
217 217
         $names = $this->get_col([['STA_ID' => $state_ID], 'limit' => 1], 'STA_name');
218 218
         return is_array($names) && ! empty($names)
Please login to merge, or discard this patch.
core/db_models/EEM_Post_Meta.model.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -18,56 +18,56 @@
 block discarded – undo
18 18
 class EEM_Post_Meta extends EEM_Base
19 19
 {
20 20
 
21
-    // private instance of the EE_Post_Meta object
22
-    protected static $_instance;
21
+	// private instance of the EE_Post_Meta object
22
+	protected static $_instance;
23 23
 
24 24
 
25 25
 
26
-    protected function __construct(string $timezone = '')
27
-    {
28
-        $this->singular_item = esc_html__('Post Meta', 'event_espresso');
29
-        $this->plural_item = esc_html__('Post Metas', 'event_espresso');
30
-        $this->_tables = array(
31
-            'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
32
-        );
33
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
34
-        $this->_fields = array(
35
-            'Post_Meta' => array(
36
-                'meta_id'    => new EE_Primary_Key_Int_Field(
37
-                    'meta_id',
38
-                    esc_html__("Meta ID", "event_espresso")
39
-                ),
40
-                'post_id'    => new EE_Foreign_Key_Int_Field(
41
-                    'post_id',
42
-                    esc_html__("Primary Key of Post", "event_espresso"),
43
-                    false,
44
-                    0,
45
-                    $models_this_can_attach_to
46
-                ),
47
-                'meta_key'   => new EE_Plain_Text_Field(
48
-                    'meta_key',
49
-                    esc_html__("Meta Key", "event_espresso"),
50
-                    false,
51
-                    ''
52
-                ),
53
-                'meta_value' => new EE_Maybe_Serialized_Text_Field(
54
-                    'meta_value',
55
-                    esc_html__("Meta Value", "event_espresso"),
56
-                    true
57
-                ),
58
-            ),
59
-        );
60
-        $this->_model_relations = array();
61
-        foreach ($models_this_can_attach_to as $model) {
62
-            $this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
63
-        }
64
-        $this->_wp_core_model = true;
65
-        foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
66
-            $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
67
-                'meta_key',
68
-                'meta_value'
69
-            );
70
-        }
71
-        parent::__construct($timezone);
72
-    }
26
+	protected function __construct(string $timezone = '')
27
+	{
28
+		$this->singular_item = esc_html__('Post Meta', 'event_espresso');
29
+		$this->plural_item = esc_html__('Post Metas', 'event_espresso');
30
+		$this->_tables = array(
31
+			'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
32
+		);
33
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
34
+		$this->_fields = array(
35
+			'Post_Meta' => array(
36
+				'meta_id'    => new EE_Primary_Key_Int_Field(
37
+					'meta_id',
38
+					esc_html__("Meta ID", "event_espresso")
39
+				),
40
+				'post_id'    => new EE_Foreign_Key_Int_Field(
41
+					'post_id',
42
+					esc_html__("Primary Key of Post", "event_espresso"),
43
+					false,
44
+					0,
45
+					$models_this_can_attach_to
46
+				),
47
+				'meta_key'   => new EE_Plain_Text_Field(
48
+					'meta_key',
49
+					esc_html__("Meta Key", "event_espresso"),
50
+					false,
51
+					''
52
+				),
53
+				'meta_value' => new EE_Maybe_Serialized_Text_Field(
54
+					'meta_value',
55
+					esc_html__("Meta Value", "event_espresso"),
56
+					true
57
+				),
58
+			),
59
+		);
60
+		$this->_model_relations = array();
61
+		foreach ($models_this_can_attach_to as $model) {
62
+			$this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
63
+		}
64
+		$this->_wp_core_model = true;
65
+		foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
66
+			$this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
67
+				'meta_key',
68
+				'meta_value'
69
+			);
70
+		}
71
+		parent::__construct($timezone);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Question_Group.model.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -15,113 +15,113 @@
 block discarded – undo
15 15
 class EEM_Event_Question_Group extends EEM_Base
16 16
 {
17 17
 
18
-    /**
19
-     * Name of the field indicating an event should use the question group for the primary attendee
20
-     */
21
-    const PRIMARY = 'EQG_primary';
18
+	/**
19
+	 * Name of the field indicating an event should use the question group for the primary attendee
20
+	 */
21
+	const PRIMARY = 'EQG_primary';
22 22
 
23
-    /**
24
-     * Name of hte field indicating an event should use the question group for additional attendees
25
-     */
26
-    const ADDITIONAL = 'EQG_additional';
23
+	/**
24
+	 * Name of hte field indicating an event should use the question group for additional attendees
25
+	 */
26
+	const ADDITIONAL = 'EQG_additional';
27 27
 
28
-    // private instance of the Event_Question_Group object
29
-    protected static $_instance;
28
+	// private instance of the Event_Question_Group object
29
+	protected static $_instance;
30 30
 
31 31
 
32
-    protected function __construct(string $timezone = '')
33
-    {
34
-        $this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
35
-        $this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
36
-        $this->_tables          = [
37
-            'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID'),
38
-        ];
39
-        $this->_fields          = [
40
-            'Event_Question_Group' => [
41
-                'EQG_ID'         => new EE_Primary_Key_Int_Field(
42
-                    'EQG_ID',
43
-                    esc_html__('Event to Question Group Link ID', 'event_espresso')
44
-                ),
45
-                'EVT_ID'         => new EE_Foreign_Key_Int_Field(
46
-                    'EVT_ID',
47
-                    esc_html__('Event ID', 'event_espresso'),
48
-                    false,
49
-                    0,
50
-                    'Event'
51
-                ),
52
-                'QSG_ID'         => new EE_Foreign_Key_Int_Field(
53
-                    'QSG_ID',
54
-                    esc_html__('Question Group Id', 'event_espresso'),
55
-                    false,
56
-                    0,
57
-                    'Question_Group'
58
-                ),
59
-                'EQG_additional' => new EE_Boolean_Field(
60
-                    'EQG_additional',
61
-                    esc_html__(
62
-                        'Flag indicating question is only for additional attendees',
63
-                        'event_espresso'
64
-                    ),
65
-                    false,
66
-                    false
67
-                ),
68
-                'EQG_primary'    => new EE_Boolean_Field(
69
-                    'EQG_primary',
70
-                    esc_html__(
71
-                        'Flag indicating question is only for primary attendees',
72
-                        'event_espresso'
73
-                    ),
74
-                    false,
75
-                    false
76
-                ),
77
-            ],
78
-        ];
79
-        $this->_model_relations = [
80
-            'Event'          => new EE_Belongs_To_Relation(),
81
-            'Question_Group' => new EE_Belongs_To_Relation(),
82
-        ];
32
+	protected function __construct(string $timezone = '')
33
+	{
34
+		$this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
35
+		$this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
36
+		$this->_tables          = [
37
+			'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID'),
38
+		];
39
+		$this->_fields          = [
40
+			'Event_Question_Group' => [
41
+				'EQG_ID'         => new EE_Primary_Key_Int_Field(
42
+					'EQG_ID',
43
+					esc_html__('Event to Question Group Link ID', 'event_espresso')
44
+				),
45
+				'EVT_ID'         => new EE_Foreign_Key_Int_Field(
46
+					'EVT_ID',
47
+					esc_html__('Event ID', 'event_espresso'),
48
+					false,
49
+					0,
50
+					'Event'
51
+				),
52
+				'QSG_ID'         => new EE_Foreign_Key_Int_Field(
53
+					'QSG_ID',
54
+					esc_html__('Question Group Id', 'event_espresso'),
55
+					false,
56
+					0,
57
+					'Question_Group'
58
+				),
59
+				'EQG_additional' => new EE_Boolean_Field(
60
+					'EQG_additional',
61
+					esc_html__(
62
+						'Flag indicating question is only for additional attendees',
63
+						'event_espresso'
64
+					),
65
+					false,
66
+					false
67
+				),
68
+				'EQG_primary'    => new EE_Boolean_Field(
69
+					'EQG_primary',
70
+					esc_html__(
71
+						'Flag indicating question is only for primary attendees',
72
+						'event_espresso'
73
+					),
74
+					false,
75
+					false
76
+				),
77
+			],
78
+		];
79
+		$this->_model_relations = [
80
+			'Event'          => new EE_Belongs_To_Relation(),
81
+			'Question_Group' => new EE_Belongs_To_Relation(),
82
+		];
83 83
 
84
-        // this model is generally available for reading
85
-        $path_to_event = 'Event';
84
+		// this model is generally available for reading
85
+		$path_to_event = 'Event';
86 86
 
87
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
88
-            new EE_Restriction_Generator_Event_Related_Public($path_to_event);
89
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
90
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
91
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
92
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
93
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
94
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
87
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
88
+			new EE_Restriction_Generator_Event_Related_Public($path_to_event);
89
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
90
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
91
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
92
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
93
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
94
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
95 95
 
96
-        parent::__construct($timezone);
97
-    }
96
+		parent::__construct($timezone);
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether
102
-     * this is concerning primary attendees or additional attendees.
103
-     * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns
104
-     * EQG_additional.
105
-     *
106
-     * @param string|boolean|int $context
107
-     * @return string
108
-     * @since 4.10.0.p
109
-     */
110
-    public function fieldNameForContext($context): string
111
-    {
112
-        // Basically do a strict switch statement.
113
-        switch (true) {
114
-            case $context === 'additional':
115
-            case $context === false:
116
-            case $context === 0:
117
-                $field_name = EEM_Event_Question_Group::ADDITIONAL;
118
-                break;
119
-            case $context === 'primary':
120
-            case $context === true:
121
-            case $context === 1:
122
-            default:
123
-                $field_name = EEM_Event_Question_Group::PRIMARY;
124
-        }
125
-        return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context);
126
-    }
100
+	/**
101
+	 * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether
102
+	 * this is concerning primary attendees or additional attendees.
103
+	 * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns
104
+	 * EQG_additional.
105
+	 *
106
+	 * @param string|boolean|int $context
107
+	 * @return string
108
+	 * @since 4.10.0.p
109
+	 */
110
+	public function fieldNameForContext($context): string
111
+	{
112
+		// Basically do a strict switch statement.
113
+		switch (true) {
114
+			case $context === 'additional':
115
+			case $context === false:
116
+			case $context === 0:
117
+				$field_name = EEM_Event_Question_Group::ADDITIONAL;
118
+				break;
119
+			case $context === 'primary':
120
+			case $context === true:
121
+			case $context === 1:
122
+			default:
123
+				$field_name = EEM_Event_Question_Group::PRIMARY;
124
+		}
125
+		return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context);
126
+	}
127 127
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Question.model.php 2 patches
Indentation   +575 added lines, -575 removed lines patch added patch discarded remove patch
@@ -10,580 +10,580 @@
 block discarded – undo
10 10
 class EEM_Question extends EEM_Soft_Delete_Base
11 11
 {
12 12
 
13
-    // constant used to indicate that the question type is CHECKBOX
14
-    const QST_type_checkbox = 'CHECKBOX';
13
+	// constant used to indicate that the question type is CHECKBOX
14
+	const QST_type_checkbox = 'CHECKBOX';
15 15
 
16
-    // constant used to indicate that the question type is COUNTRY
17
-    const QST_type_country = 'COUNTRY';
18
-
19
-    // constant used to indicate that the question type is DATE
20
-    const QST_type_date = 'DATE';
21
-
22
-    // constant used to indicate that the question type is a decimal (float)
23
-    const QST_type_decimal = 'DECIMAL';
24
-
25
-    // constant used to indicate that the question type is DROPDOWN
26
-    const QST_type_dropdown = 'DROPDOWN';
27
-
28
-    // constant used to indicate that the question type is an email input
29
-    const QST_type_email = 'EMAIL';
30
-
31
-    // constant used to indicate that the question type is an email input
32
-    const QST_type_email_confirm = 'EMAIL_CONFIRM';
33
-
34
-    // constant used to indicate that the question type is a TEXTAREA that allows simple html
35
-    const QST_type_html_textarea = 'HTML_TEXTAREA';
36
-
37
-    // constant used to indicate that the question type is an integer (whole number)
38
-    const QST_type_int = 'INTEGER';
39
-
40
-    // constant used to indicate that the question type is a multi-select
41
-    const QST_type_multi_select = 'MULTI_SELECT';
42
-
43
-    // constant used to indicate that the question type is RADIO_BTN
44
-    const QST_type_radio = 'RADIO_BTN';
45
-
46
-    // constant used to indicate that the question type is STATE
47
-    const QST_type_state = 'STATE';
48
-
49
-    // constant used to indicate that the question type is TEXT
50
-    const QST_type_text = 'TEXT';
51
-
52
-    // constant used to indicate that the question type is TEXTAREA
53
-    const QST_type_textarea = 'TEXTAREA';
54
-
55
-    // constant used to indicate that the question type is a valid URL
56
-    const QST_type_url = 'URL';
57
-
58
-    // constant used to indicate that the question type is a US-formatted phone number
59
-    const QST_type_us_phone = 'US_PHONE';
60
-
61
-    // constant used to indicate that the question type is a YEAR
62
-    const QST_type_year = 'YEAR';
63
-
64
-    /**
65
-     * lists all the question types which should be allowed. Ideally, this will be extensible.
66
-     *
67
-     * @var array $_allowed_question_types
68
-     */
69
-    protected $_allowed_question_types = [];
70
-
71
-
72
-    // private instance of the Attendee object
73
-    protected static $_instance;
74
-
75
-    /**
76
-     * brief descriptions for all the question types
77
-     *
78
-     * @var EEM_Question $_instance
79
-     */
80
-    protected $_question_descriptions;
81
-
82
-    /**
83
-     * Question types that are interchangeable, even after answers have been provided for them.
84
-     * Top-level keys are category slugs, next level is an array of question types. If question types
85
-     * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
86
-     *
87
-     * @var array   $_question_type_categories {
88
-     *      @type string $text
89
-     *      @type string $single -answer-enum
90
-     *      @type string $multi -answer-enum
91
-     * }
92
-     */
93
-    protected $_question_type_categories = [];
94
-
95
-
96
-    /**
97
-     * Question types that should have an admin-defined max input length
98
-     *
99
-     * @var array
100
-     */
101
-    protected $question_types_with_max_length;
102
-
103
-
104
-    /**
105
-     * EEM_Question constructor.
106
-     *
107
-     * @param string $timezone
108
-     * @throws EE_Error
109
-     */
110
-    protected function __construct(string $timezone = '')
111
-    {
112
-        $this->singular_item                  = esc_html__('Question', 'event_espresso');
113
-        $this->plural_item                    = esc_html__('Questions', 'event_espresso');
114
-        $this->_allowed_question_types        = apply_filters(
115
-            'FHEE__EEM_Question__construct__allowed_question_types',
116
-            [
117
-                EEM_Question::QST_type_checkbox      => esc_html__('Checkboxes', 'event_espresso'),
118
-                EEM_Question::QST_type_country       => esc_html__('Country Dropdown', 'event_espresso'),
119
-                EEM_Question::QST_type_date          => esc_html__('Date Picker', 'event_espresso'),
120
-                EEM_Question::QST_type_decimal       => esc_html__('Number', 'event_espresso'),
121
-                EEM_Question::QST_type_dropdown      => esc_html__('Dropdown', 'event_espresso'),
122
-                EEM_Question::QST_type_email         => esc_html__('Email', 'event_espresso'),
123
-                EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
124
-                EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
125
-                EEM_Question::QST_type_int           => esc_html__('Whole Number', 'event_espresso'),
126
-                EEM_Question::QST_type_multi_select  => esc_html__('Multi Select', 'event_espresso'),
127
-                EEM_Question::QST_type_radio         => esc_html__('Radio Buttons', 'event_espresso'),
128
-                EEM_Question::QST_type_state         => esc_html__('State/Province Dropdown', 'event_espresso'),
129
-                EEM_Question::QST_type_text          => esc_html__('Text', 'event_espresso'),
130
-                EEM_Question::QST_type_textarea      => esc_html__('Textarea', 'event_espresso'),
131
-                EEM_Question::QST_type_url           => esc_html__('URL', 'event_espresso'),
132
-                EEM_Question::QST_type_us_phone      => esc_html__('USA - Format Phone', 'event_espresso'),
133
-                EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
134
-            ]
135
-        );
136
-        $this->_question_descriptions         = apply_filters(
137
-            'FHEE__EEM_Question__construct__question_descriptions',
138
-            [
139
-                EEM_Question::QST_type_checkbox      => esc_html__(
140
-                    'Allows multiple preset options to be selected',
141
-                    'event_espresso'
142
-                ),
143
-                EEM_Question::QST_type_country       => esc_html__(
144
-                    'A dropdown that lists countries',
145
-                    'event_espresso'
146
-                ),
147
-                EEM_Question::QST_type_date          => esc_html__(
148
-                    'A popup calendar that allows date selections',
149
-                    'event_espresso'
150
-                ),
151
-                EEM_Question::QST_type_decimal       => esc_html__(
152
-                    'A text field that allows number values with decimals',
153
-                    'event_espresso'
154
-                ),
155
-                EEM_Question::QST_type_dropdown      => esc_html__(
156
-                    'A dropdown that allows a single selection',
157
-                    'event_espresso'
158
-                ),
159
-                EEM_Question::QST_type_email         => esc_html__(
160
-                    'A text field that must contain a valid Email address',
161
-                    'event_espresso'
162
-                ),
163
-                EEM_Question::QST_type_email_confirm => esc_html__(
164
-                    'A text field that must contain a valid Email address and be equal to Email field',
165
-                    'event_espresso'
166
-                ),
167
-                EEM_Question::QST_type_html_textarea => esc_html__(
168
-                    'A multi line text input field that allows HTML',
169
-                    'event_espresso'
170
-                ),
171
-                EEM_Question::QST_type_int           => esc_html__(
172
-                    'A text field that only allows whole numbers (no decimals)',
173
-                    'event_espresso'
174
-                ),
175
-                EEM_Question::QST_type_multi_select  => esc_html__(
176
-                    'A dropdown that allows multiple selections',
177
-                    'event_espresso'
178
-                ),
179
-                EEM_Question::QST_type_radio         => esc_html__(
180
-                    'Allows a single preset option to be selected',
181
-                    'event_espresso'
182
-                ),
183
-                EEM_Question::QST_type_state         => esc_html__(
184
-                    'A dropdown that lists states/provinces',
185
-                    'event_espresso'
186
-                ),
187
-                EEM_Question::QST_type_text          => esc_html__(
188
-                    'A single line text input field',
189
-                    'event_espresso'
190
-                ),
191
-                EEM_Question::QST_type_textarea      => esc_html__(
192
-                    'A multi line text input field',
193
-                    'event_espresso'
194
-                ),
195
-                EEM_Question::QST_type_url           => esc_html__(
196
-                    'A text field that must contain a valid URL',
197
-                    'event_espresso'
198
-                ),
199
-                EEM_Question::QST_type_us_phone      => esc_html__(
200
-                    'A text field that must contain a valid US phone number',
201
-                    'event_espresso'
202
-                ),
203
-                EEM_Question::QST_type_year          => esc_html__(
204
-                    'A dropdown that lists the last 100 years',
205
-                    'event_espresso'
206
-                ),
207
-            ]
208
-        );
209
-        $this->_question_type_categories      = (array) apply_filters(
210
-            'FHEE__EEM_Question__construct__question_type_categories',
211
-            [
212
-                'text'               => [
213
-                    EEM_Question::QST_type_date,
214
-                    EEM_Question::QST_type_decimal,
215
-                    EEM_Question::QST_type_email,
216
-                    EEM_Question::QST_type_email_confirm,
217
-                    EEM_Question::QST_type_html_textarea,
218
-                    EEM_Question::QST_type_int,
219
-                    EEM_Question::QST_type_text,
220
-                    EEM_Question::QST_type_textarea,
221
-                    EEM_Question::QST_type_url,
222
-                    EEM_Question::QST_type_us_phone,
223
-                    EEM_Question::QST_type_year,
224
-                ],
225
-                'single-answer-enum' => [
226
-                    EEM_Question::QST_type_dropdown,
227
-                    EEM_Question::QST_type_radio,
228
-                ],
229
-                'multi-answer-enum'  => [
230
-                    EEM_Question::QST_type_multi_select,
231
-                    EEM_Question::QST_type_checkbox,
232
-                ],
233
-            ]
234
-        );
235
-        $this->question_types_with_max_length = apply_filters(
236
-            'FHEE__EEM_Question___construct__question_types_with_max_length',
237
-            [
238
-                EEM_Question::QST_type_html_textarea,
239
-                EEM_Question::QST_type_text,
240
-                EEM_Question::QST_type_textarea,
241
-            ]
242
-        );
243
-
244
-        $this->_tables          = [
245
-            'Question' => new EE_Primary_Table('esp_question', 'QST_ID'),
246
-        ];
247
-        $this->_fields          = [
248
-            'Question' => [
249
-                'QST_ID'            => new EE_Primary_Key_Int_Field(
250
-                    'QST_ID',
251
-                    esc_html__('Question ID', 'event_espresso')
252
-                ),
253
-                'QST_admin_label'   => new EE_Plain_Text_Field(
254
-                    'QST_admin_label',
255
-                    esc_html__('Question Label (admin-only)', 'event_espresso'),
256
-                    true,
257
-                    ''
258
-                ),
259
-                'QST_admin_only'    => new EE_Boolean_Field(
260
-                    'QST_admin_only',
261
-                    esc_html__('Admin-Only Question?', 'event_espresso'),
262
-                    false,
263
-                    false
264
-                ),
265
-                'QST_deleted'       => new EE_Trashed_Flag_Field(
266
-                    'QST_deleted',
267
-                    esc_html__('Flag Indicating question was deleted', 'event_espresso'),
268
-                    false,
269
-                    false
270
-                ),
271
-                'QST_display_text'  => new EE_Post_Content_Field(
272
-                    'QST_display_text',
273
-                    esc_html__('Question Text', 'event_espresso'),
274
-                    true,
275
-                    ''
276
-                ),
277
-                'QST_max'           => new EE_Infinite_Integer_Field(
278
-                    'QST_max',
279
-                    esc_html__('Max Size', 'event_espresso'),
280
-                    false,
281
-                    EE_INF
282
-                ),
283
-                'QST_order'         => new EE_Integer_Field(
284
-                    'QST_order',
285
-                    esc_html__('Question Order', 'event_espresso'),
286
-                    false,
287
-                    0
288
-                ),
289
-                'QST_required'      => new EE_Boolean_Field(
290
-                    'QST_required',
291
-                    esc_html__('Required Question?', 'event_espresso'),
292
-                    false,
293
-                    false
294
-                ),
295
-                'QST_required_text' => new EE_Simple_HTML_Field(
296
-                    'QST_required_text',
297
-                    esc_html__('Text to Display if Not Provided', 'event_espresso'),
298
-                    true,
299
-                    ''
300
-                ),
301
-                'QST_system'        => new EE_Plain_Text_Field(
302
-                    'QST_system',
303
-                    esc_html__('Internal string ID for question', 'event_espresso'),
304
-                    false,
305
-                    ''
306
-                ),
307
-                'QST_type'          => new EE_Enum_Text_Field(
308
-                    'QST_type',
309
-                    esc_html__('Question Type', 'event_espresso'),
310
-                    false,
311
-                    'TEXT',
312
-                    $this->_allowed_question_types
313
-                ),
314
-                'QST_wp_user'       => new EE_WP_User_Field(
315
-                    'QST_wp_user',
316
-                    esc_html__('Question Creator ID', 'event_espresso'),
317
-                    false
318
-                ),
319
-            ],
320
-        ];
321
-        $this->_model_relations = [
322
-            'Answer'                  => new EE_Has_Many_Relation(),
323
-            'Question_Group'          => new EE_HABTM_Relation('Question_Group_Question'),
324
-            // for QST_order column
325
-            'Question_Group_Question' => new EE_Has_Many_Relation(),
326
-            'Question_Option'         => new EE_Has_Many_Relation(),
327
-            'WP_User'                 => new EE_Belongs_To_Relation(),
328
-        ];
329
-        // this model is generally available for reading
330
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
331
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form(
332
-            'QST_system'
333
-        );
334
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form(
335
-                'QST_system'
336
-        );
337
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form(
338
-                'QST_system'
339
-        );
340
-
341
-        parent::__construct($timezone);
342
-    }
343
-
344
-
345
-    /**
346
-     * Returns the list of allowed question types, which are normally:
347
-     * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended
348
-     *
349
-     * @return string[]
350
-     */
351
-    public function allowed_question_types(): array
352
-    {
353
-        return $this->_allowed_question_types;
354
-    }
355
-
356
-
357
-    /**
358
-     * Gets all the question types in the same category
359
-     *
360
-     * @param string $question_type one of EEM_Question::allowed_question_types(
361
-     * @return string[] like EEM_Question::allowed_question_types()
362
-     */
363
-    public function question_types_in_same_category(string $question_type): array
364
-    {
365
-        $question_types = [$question_type];
366
-        foreach ($this->_question_type_categories as $question_types_in_category) {
367
-            if (in_array($question_type, $question_types_in_category)) {
368
-                $question_types = $question_types_in_category;
369
-                break;
370
-            }
371
-        }
372
-
373
-        return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
374
-    }
375
-
376
-
377
-    /**
378
-     * Determines if the given question type is in the given question type category
379
-     *
380
-     * @param string $question_type one of EEM_Question::allowed_question_types()
381
-     * @param string $category      one of the top-level keys of EEM_Question::question_type_categories()
382
-     * @return boolean
383
-     */
384
-    public function question_type_is_in_category(string $question_type, string $category): bool
385
-    {
386
-        if (! isset($this->_question_type_categories[ $category ])) {
387
-            return false;
388
-        }
389
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
390
-    }
391
-
392
-
393
-    /**
394
-     * Returns all the question types in the given category
395
-     *
396
-     * @param string $category
397
-     * @return array|mixed
398
-     */
399
-    public function question_types_in_category(string $category): array
400
-    {
401
-        if (isset($this->_question_type_categories[ $category ])) {
402
-            return $this->_question_type_categories[ $category ];
403
-        }
404
-        return [];
405
-    }
406
-
407
-
408
-    /**
409
-     * Returns all the question types that should have question options
410
-     *
411
-     * @return array
412
-     */
413
-    public function question_types_with_options(): array
414
-    {
415
-        return array_merge(
416
-            $this->question_types_in_category('single-answer-enum'),
417
-            $this->question_types_in_category('multi-answer-enum')
418
-        );
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns the question type categories 2d array
424
-     *
425
-     * @return array see EEM_Question::_question_type_categories
426
-     */
427
-    public function question_type_categories(): array
428
-    {
429
-        return $this->_question_type_categories;
430
-    }
431
-
432
-
433
-    /**
434
-     * Returns an array of all the QST_system values that can be allowed in the system question group
435
-     * identified by $system_question_group_id
436
-     *
437
-     * @param string $system_question_group_id QSG_system
438
-     * @return array of system question names (QST_system)
439
-     */
440
-    public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array
441
-    {
442
-        $question_system_ids = [];
443
-        switch ($system_question_group_id) {
444
-            case EEM_Question_Group::system_personal:
445
-                $question_system_ids = [
446
-                    EEM_Attendee::system_question_fname,
447
-                    EEM_Attendee::system_question_lname,
448
-                    EEM_Attendee::system_question_email,
449
-                    EEM_Attendee::system_question_email_confirm,
450
-                    EEM_Attendee::system_question_phone,
451
-                ];
452
-                break;
453
-            case EEM_Question_Group::system_address:
454
-                $question_system_ids = [
455
-                    EEM_Attendee::system_question_address,
456
-                    EEM_Attendee::system_question_address2,
457
-                    EEM_Attendee::system_question_city,
458
-                    EEM_Attendee::system_question_state,
459
-                    EEM_Attendee::system_question_country,
460
-                    EEM_Attendee::system_question_zip,
461
-                    EEM_Attendee::system_question_phone,
462
-                ];
463
-                break;
464
-        }
465
-        return apply_filters(
466
-            'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return',
467
-            $question_system_ids,
468
-            $system_question_group_id
469
-        );
470
-    }
471
-
472
-
473
-    /**
474
-     * Returns an array of all the QST_system values that are required in the system question group
475
-     * identified by $system_question_group_id
476
-     *
477
-     * @param string $system_question_group_id QSG_system
478
-     * @return array of system question names (QST_system)
479
-     */
480
-    public function required_system_questions_in_system_question_group(string $system_question_group_id): array
481
-    {
482
-        switch ($system_question_group_id) {
483
-            case EEM_Question_Group::system_personal:
484
-                $question_system_ids = [
485
-                    EEM_Attendee::system_question_fname,
486
-                    EEM_Attendee::system_question_email,
487
-                ];
488
-                break;
489
-            default:
490
-                $question_system_ids = [];
491
-        }
492
-        return apply_filters(
493
-            'FHEE__EEM_Question__system_questions_required_in_system_question_group',
494
-            $question_system_ids,
495
-            $system_question_group_id
496
-        );
497
-    }
498
-
499
-
500
-    /**
501
-     * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
502
-     * which system question QST_ID corresponds to the QST_system 'city', use
503
-     * EEM_Question::instance()->get_Question_ID_from_system_string('city');
504
-     *
505
-     * @param $QST_system
506
-     * @return int of QST_ID for the question that corresponds to that QST_system
507
-     * @throws EE_Error
508
-     * @throws ReflectionException
509
-     */
510
-    public function get_Question_ID_from_system_string($QST_system): int
511
-    {
512
-        return $this->get_var([['QST_system' => $QST_system]]);
513
-    }
514
-
515
-
516
-    /**
517
-     * searches the db for the question with the latest question order and returns that value.
518
-     *
519
-     * @return int
520
-     * @throws EE_Error
521
-     * @throws ReflectionException
522
-     */
523
-    public function get_latest_question_order(): int
524
-    {
525
-        $columns_to_select = [
526
-            'max_order' => ["MAX(QST_order)", "%d"],
527
-        ];
528
-        $max               = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select);
529
-        return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
530
-    }
531
-
532
-
533
-    /**
534
-     * Returns an array where keys are system question QST_system values,
535
-     * and values are the highest question max the admin can set on the question
536
-     * (aka the "max max"; eg, a site admin can change the zip question to have a max
537
-     * of 5, but no larger than 12)
538
-     *
539
-     * @return array
540
-     */
541
-    public function system_question_maxes(): array
542
-    {
543
-        return [
544
-            'fname'         => 45,
545
-            'lname'         => 45,
546
-            'address'       => 255,
547
-            'address2'      => 255,
548
-            'city'          => 45,
549
-            'zip'           => 12,
550
-            'email'         => 255,
551
-            'email_confirm' => 255,
552
-            'phone'         => 45,
553
-        ];
554
-    }
555
-
556
-
557
-    /**
558
-     * Given a QST_system value, gets the question's largest allowable max input.
559
-     *
560
-     * @param string $system_question_value
561
-     * @return int|float
562
-     * @see Registration_Form_Admin_Page::system_question_maxes()
563
-     */
564
-    public function absolute_max_for_system_question(string $system_question_value)
565
-    {
566
-        $maxes = $this->system_question_maxes();
567
-        return $maxes[ $system_question_value ] ?? EE_INF;
568
-    }
569
-
570
-
571
-    /**
572
-     * @return array
573
-     */
574
-    public function question_descriptions(): array
575
-    {
576
-        return $this->_question_descriptions;
577
-    }
578
-
579
-
580
-    /**
581
-     * Returns all the question types that should have an admin-defined max input length
582
-     *
583
-     * @return array
584
-     */
585
-    public function questionTypesWithMaxLength(): array
586
-    {
587
-        return (array) $this->question_types_with_max_length;
588
-    }
16
+	// constant used to indicate that the question type is COUNTRY
17
+	const QST_type_country = 'COUNTRY';
18
+
19
+	// constant used to indicate that the question type is DATE
20
+	const QST_type_date = 'DATE';
21
+
22
+	// constant used to indicate that the question type is a decimal (float)
23
+	const QST_type_decimal = 'DECIMAL';
24
+
25
+	// constant used to indicate that the question type is DROPDOWN
26
+	const QST_type_dropdown = 'DROPDOWN';
27
+
28
+	// constant used to indicate that the question type is an email input
29
+	const QST_type_email = 'EMAIL';
30
+
31
+	// constant used to indicate that the question type is an email input
32
+	const QST_type_email_confirm = 'EMAIL_CONFIRM';
33
+
34
+	// constant used to indicate that the question type is a TEXTAREA that allows simple html
35
+	const QST_type_html_textarea = 'HTML_TEXTAREA';
36
+
37
+	// constant used to indicate that the question type is an integer (whole number)
38
+	const QST_type_int = 'INTEGER';
39
+
40
+	// constant used to indicate that the question type is a multi-select
41
+	const QST_type_multi_select = 'MULTI_SELECT';
42
+
43
+	// constant used to indicate that the question type is RADIO_BTN
44
+	const QST_type_radio = 'RADIO_BTN';
45
+
46
+	// constant used to indicate that the question type is STATE
47
+	const QST_type_state = 'STATE';
48
+
49
+	// constant used to indicate that the question type is TEXT
50
+	const QST_type_text = 'TEXT';
51
+
52
+	// constant used to indicate that the question type is TEXTAREA
53
+	const QST_type_textarea = 'TEXTAREA';
54
+
55
+	// constant used to indicate that the question type is a valid URL
56
+	const QST_type_url = 'URL';
57
+
58
+	// constant used to indicate that the question type is a US-formatted phone number
59
+	const QST_type_us_phone = 'US_PHONE';
60
+
61
+	// constant used to indicate that the question type is a YEAR
62
+	const QST_type_year = 'YEAR';
63
+
64
+	/**
65
+	 * lists all the question types which should be allowed. Ideally, this will be extensible.
66
+	 *
67
+	 * @var array $_allowed_question_types
68
+	 */
69
+	protected $_allowed_question_types = [];
70
+
71
+
72
+	// private instance of the Attendee object
73
+	protected static $_instance;
74
+
75
+	/**
76
+	 * brief descriptions for all the question types
77
+	 *
78
+	 * @var EEM_Question $_instance
79
+	 */
80
+	protected $_question_descriptions;
81
+
82
+	/**
83
+	 * Question types that are interchangeable, even after answers have been provided for them.
84
+	 * Top-level keys are category slugs, next level is an array of question types. If question types
85
+	 * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
86
+	 *
87
+	 * @var array   $_question_type_categories {
88
+	 *      @type string $text
89
+	 *      @type string $single -answer-enum
90
+	 *      @type string $multi -answer-enum
91
+	 * }
92
+	 */
93
+	protected $_question_type_categories = [];
94
+
95
+
96
+	/**
97
+	 * Question types that should have an admin-defined max input length
98
+	 *
99
+	 * @var array
100
+	 */
101
+	protected $question_types_with_max_length;
102
+
103
+
104
+	/**
105
+	 * EEM_Question constructor.
106
+	 *
107
+	 * @param string $timezone
108
+	 * @throws EE_Error
109
+	 */
110
+	protected function __construct(string $timezone = '')
111
+	{
112
+		$this->singular_item                  = esc_html__('Question', 'event_espresso');
113
+		$this->plural_item                    = esc_html__('Questions', 'event_espresso');
114
+		$this->_allowed_question_types        = apply_filters(
115
+			'FHEE__EEM_Question__construct__allowed_question_types',
116
+			[
117
+				EEM_Question::QST_type_checkbox      => esc_html__('Checkboxes', 'event_espresso'),
118
+				EEM_Question::QST_type_country       => esc_html__('Country Dropdown', 'event_espresso'),
119
+				EEM_Question::QST_type_date          => esc_html__('Date Picker', 'event_espresso'),
120
+				EEM_Question::QST_type_decimal       => esc_html__('Number', 'event_espresso'),
121
+				EEM_Question::QST_type_dropdown      => esc_html__('Dropdown', 'event_espresso'),
122
+				EEM_Question::QST_type_email         => esc_html__('Email', 'event_espresso'),
123
+				EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
124
+				EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
125
+				EEM_Question::QST_type_int           => esc_html__('Whole Number', 'event_espresso'),
126
+				EEM_Question::QST_type_multi_select  => esc_html__('Multi Select', 'event_espresso'),
127
+				EEM_Question::QST_type_radio         => esc_html__('Radio Buttons', 'event_espresso'),
128
+				EEM_Question::QST_type_state         => esc_html__('State/Province Dropdown', 'event_espresso'),
129
+				EEM_Question::QST_type_text          => esc_html__('Text', 'event_espresso'),
130
+				EEM_Question::QST_type_textarea      => esc_html__('Textarea', 'event_espresso'),
131
+				EEM_Question::QST_type_url           => esc_html__('URL', 'event_espresso'),
132
+				EEM_Question::QST_type_us_phone      => esc_html__('USA - Format Phone', 'event_espresso'),
133
+				EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
134
+			]
135
+		);
136
+		$this->_question_descriptions         = apply_filters(
137
+			'FHEE__EEM_Question__construct__question_descriptions',
138
+			[
139
+				EEM_Question::QST_type_checkbox      => esc_html__(
140
+					'Allows multiple preset options to be selected',
141
+					'event_espresso'
142
+				),
143
+				EEM_Question::QST_type_country       => esc_html__(
144
+					'A dropdown that lists countries',
145
+					'event_espresso'
146
+				),
147
+				EEM_Question::QST_type_date          => esc_html__(
148
+					'A popup calendar that allows date selections',
149
+					'event_espresso'
150
+				),
151
+				EEM_Question::QST_type_decimal       => esc_html__(
152
+					'A text field that allows number values with decimals',
153
+					'event_espresso'
154
+				),
155
+				EEM_Question::QST_type_dropdown      => esc_html__(
156
+					'A dropdown that allows a single selection',
157
+					'event_espresso'
158
+				),
159
+				EEM_Question::QST_type_email         => esc_html__(
160
+					'A text field that must contain a valid Email address',
161
+					'event_espresso'
162
+				),
163
+				EEM_Question::QST_type_email_confirm => esc_html__(
164
+					'A text field that must contain a valid Email address and be equal to Email field',
165
+					'event_espresso'
166
+				),
167
+				EEM_Question::QST_type_html_textarea => esc_html__(
168
+					'A multi line text input field that allows HTML',
169
+					'event_espresso'
170
+				),
171
+				EEM_Question::QST_type_int           => esc_html__(
172
+					'A text field that only allows whole numbers (no decimals)',
173
+					'event_espresso'
174
+				),
175
+				EEM_Question::QST_type_multi_select  => esc_html__(
176
+					'A dropdown that allows multiple selections',
177
+					'event_espresso'
178
+				),
179
+				EEM_Question::QST_type_radio         => esc_html__(
180
+					'Allows a single preset option to be selected',
181
+					'event_espresso'
182
+				),
183
+				EEM_Question::QST_type_state         => esc_html__(
184
+					'A dropdown that lists states/provinces',
185
+					'event_espresso'
186
+				),
187
+				EEM_Question::QST_type_text          => esc_html__(
188
+					'A single line text input field',
189
+					'event_espresso'
190
+				),
191
+				EEM_Question::QST_type_textarea      => esc_html__(
192
+					'A multi line text input field',
193
+					'event_espresso'
194
+				),
195
+				EEM_Question::QST_type_url           => esc_html__(
196
+					'A text field that must contain a valid URL',
197
+					'event_espresso'
198
+				),
199
+				EEM_Question::QST_type_us_phone      => esc_html__(
200
+					'A text field that must contain a valid US phone number',
201
+					'event_espresso'
202
+				),
203
+				EEM_Question::QST_type_year          => esc_html__(
204
+					'A dropdown that lists the last 100 years',
205
+					'event_espresso'
206
+				),
207
+			]
208
+		);
209
+		$this->_question_type_categories      = (array) apply_filters(
210
+			'FHEE__EEM_Question__construct__question_type_categories',
211
+			[
212
+				'text'               => [
213
+					EEM_Question::QST_type_date,
214
+					EEM_Question::QST_type_decimal,
215
+					EEM_Question::QST_type_email,
216
+					EEM_Question::QST_type_email_confirm,
217
+					EEM_Question::QST_type_html_textarea,
218
+					EEM_Question::QST_type_int,
219
+					EEM_Question::QST_type_text,
220
+					EEM_Question::QST_type_textarea,
221
+					EEM_Question::QST_type_url,
222
+					EEM_Question::QST_type_us_phone,
223
+					EEM_Question::QST_type_year,
224
+				],
225
+				'single-answer-enum' => [
226
+					EEM_Question::QST_type_dropdown,
227
+					EEM_Question::QST_type_radio,
228
+				],
229
+				'multi-answer-enum'  => [
230
+					EEM_Question::QST_type_multi_select,
231
+					EEM_Question::QST_type_checkbox,
232
+				],
233
+			]
234
+		);
235
+		$this->question_types_with_max_length = apply_filters(
236
+			'FHEE__EEM_Question___construct__question_types_with_max_length',
237
+			[
238
+				EEM_Question::QST_type_html_textarea,
239
+				EEM_Question::QST_type_text,
240
+				EEM_Question::QST_type_textarea,
241
+			]
242
+		);
243
+
244
+		$this->_tables          = [
245
+			'Question' => new EE_Primary_Table('esp_question', 'QST_ID'),
246
+		];
247
+		$this->_fields          = [
248
+			'Question' => [
249
+				'QST_ID'            => new EE_Primary_Key_Int_Field(
250
+					'QST_ID',
251
+					esc_html__('Question ID', 'event_espresso')
252
+				),
253
+				'QST_admin_label'   => new EE_Plain_Text_Field(
254
+					'QST_admin_label',
255
+					esc_html__('Question Label (admin-only)', 'event_espresso'),
256
+					true,
257
+					''
258
+				),
259
+				'QST_admin_only'    => new EE_Boolean_Field(
260
+					'QST_admin_only',
261
+					esc_html__('Admin-Only Question?', 'event_espresso'),
262
+					false,
263
+					false
264
+				),
265
+				'QST_deleted'       => new EE_Trashed_Flag_Field(
266
+					'QST_deleted',
267
+					esc_html__('Flag Indicating question was deleted', 'event_espresso'),
268
+					false,
269
+					false
270
+				),
271
+				'QST_display_text'  => new EE_Post_Content_Field(
272
+					'QST_display_text',
273
+					esc_html__('Question Text', 'event_espresso'),
274
+					true,
275
+					''
276
+				),
277
+				'QST_max'           => new EE_Infinite_Integer_Field(
278
+					'QST_max',
279
+					esc_html__('Max Size', 'event_espresso'),
280
+					false,
281
+					EE_INF
282
+				),
283
+				'QST_order'         => new EE_Integer_Field(
284
+					'QST_order',
285
+					esc_html__('Question Order', 'event_espresso'),
286
+					false,
287
+					0
288
+				),
289
+				'QST_required'      => new EE_Boolean_Field(
290
+					'QST_required',
291
+					esc_html__('Required Question?', 'event_espresso'),
292
+					false,
293
+					false
294
+				),
295
+				'QST_required_text' => new EE_Simple_HTML_Field(
296
+					'QST_required_text',
297
+					esc_html__('Text to Display if Not Provided', 'event_espresso'),
298
+					true,
299
+					''
300
+				),
301
+				'QST_system'        => new EE_Plain_Text_Field(
302
+					'QST_system',
303
+					esc_html__('Internal string ID for question', 'event_espresso'),
304
+					false,
305
+					''
306
+				),
307
+				'QST_type'          => new EE_Enum_Text_Field(
308
+					'QST_type',
309
+					esc_html__('Question Type', 'event_espresso'),
310
+					false,
311
+					'TEXT',
312
+					$this->_allowed_question_types
313
+				),
314
+				'QST_wp_user'       => new EE_WP_User_Field(
315
+					'QST_wp_user',
316
+					esc_html__('Question Creator ID', 'event_espresso'),
317
+					false
318
+				),
319
+			],
320
+		];
321
+		$this->_model_relations = [
322
+			'Answer'                  => new EE_Has_Many_Relation(),
323
+			'Question_Group'          => new EE_HABTM_Relation('Question_Group_Question'),
324
+			// for QST_order column
325
+			'Question_Group_Question' => new EE_Has_Many_Relation(),
326
+			'Question_Option'         => new EE_Has_Many_Relation(),
327
+			'WP_User'                 => new EE_Belongs_To_Relation(),
328
+		];
329
+		// this model is generally available for reading
330
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
331
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form(
332
+			'QST_system'
333
+		);
334
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form(
335
+				'QST_system'
336
+		);
337
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form(
338
+				'QST_system'
339
+		);
340
+
341
+		parent::__construct($timezone);
342
+	}
343
+
344
+
345
+	/**
346
+	 * Returns the list of allowed question types, which are normally:
347
+	 * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended
348
+	 *
349
+	 * @return string[]
350
+	 */
351
+	public function allowed_question_types(): array
352
+	{
353
+		return $this->_allowed_question_types;
354
+	}
355
+
356
+
357
+	/**
358
+	 * Gets all the question types in the same category
359
+	 *
360
+	 * @param string $question_type one of EEM_Question::allowed_question_types(
361
+	 * @return string[] like EEM_Question::allowed_question_types()
362
+	 */
363
+	public function question_types_in_same_category(string $question_type): array
364
+	{
365
+		$question_types = [$question_type];
366
+		foreach ($this->_question_type_categories as $question_types_in_category) {
367
+			if (in_array($question_type, $question_types_in_category)) {
368
+				$question_types = $question_types_in_category;
369
+				break;
370
+			}
371
+		}
372
+
373
+		return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
374
+	}
375
+
376
+
377
+	/**
378
+	 * Determines if the given question type is in the given question type category
379
+	 *
380
+	 * @param string $question_type one of EEM_Question::allowed_question_types()
381
+	 * @param string $category      one of the top-level keys of EEM_Question::question_type_categories()
382
+	 * @return boolean
383
+	 */
384
+	public function question_type_is_in_category(string $question_type, string $category): bool
385
+	{
386
+		if (! isset($this->_question_type_categories[ $category ])) {
387
+			return false;
388
+		}
389
+		return in_array($question_type, $this->_question_type_categories[ $category ]);
390
+	}
391
+
392
+
393
+	/**
394
+	 * Returns all the question types in the given category
395
+	 *
396
+	 * @param string $category
397
+	 * @return array|mixed
398
+	 */
399
+	public function question_types_in_category(string $category): array
400
+	{
401
+		if (isset($this->_question_type_categories[ $category ])) {
402
+			return $this->_question_type_categories[ $category ];
403
+		}
404
+		return [];
405
+	}
406
+
407
+
408
+	/**
409
+	 * Returns all the question types that should have question options
410
+	 *
411
+	 * @return array
412
+	 */
413
+	public function question_types_with_options(): array
414
+	{
415
+		return array_merge(
416
+			$this->question_types_in_category('single-answer-enum'),
417
+			$this->question_types_in_category('multi-answer-enum')
418
+		);
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns the question type categories 2d array
424
+	 *
425
+	 * @return array see EEM_Question::_question_type_categories
426
+	 */
427
+	public function question_type_categories(): array
428
+	{
429
+		return $this->_question_type_categories;
430
+	}
431
+
432
+
433
+	/**
434
+	 * Returns an array of all the QST_system values that can be allowed in the system question group
435
+	 * identified by $system_question_group_id
436
+	 *
437
+	 * @param string $system_question_group_id QSG_system
438
+	 * @return array of system question names (QST_system)
439
+	 */
440
+	public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array
441
+	{
442
+		$question_system_ids = [];
443
+		switch ($system_question_group_id) {
444
+			case EEM_Question_Group::system_personal:
445
+				$question_system_ids = [
446
+					EEM_Attendee::system_question_fname,
447
+					EEM_Attendee::system_question_lname,
448
+					EEM_Attendee::system_question_email,
449
+					EEM_Attendee::system_question_email_confirm,
450
+					EEM_Attendee::system_question_phone,
451
+				];
452
+				break;
453
+			case EEM_Question_Group::system_address:
454
+				$question_system_ids = [
455
+					EEM_Attendee::system_question_address,
456
+					EEM_Attendee::system_question_address2,
457
+					EEM_Attendee::system_question_city,
458
+					EEM_Attendee::system_question_state,
459
+					EEM_Attendee::system_question_country,
460
+					EEM_Attendee::system_question_zip,
461
+					EEM_Attendee::system_question_phone,
462
+				];
463
+				break;
464
+		}
465
+		return apply_filters(
466
+			'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return',
467
+			$question_system_ids,
468
+			$system_question_group_id
469
+		);
470
+	}
471
+
472
+
473
+	/**
474
+	 * Returns an array of all the QST_system values that are required in the system question group
475
+	 * identified by $system_question_group_id
476
+	 *
477
+	 * @param string $system_question_group_id QSG_system
478
+	 * @return array of system question names (QST_system)
479
+	 */
480
+	public function required_system_questions_in_system_question_group(string $system_question_group_id): array
481
+	{
482
+		switch ($system_question_group_id) {
483
+			case EEM_Question_Group::system_personal:
484
+				$question_system_ids = [
485
+					EEM_Attendee::system_question_fname,
486
+					EEM_Attendee::system_question_email,
487
+				];
488
+				break;
489
+			default:
490
+				$question_system_ids = [];
491
+		}
492
+		return apply_filters(
493
+			'FHEE__EEM_Question__system_questions_required_in_system_question_group',
494
+			$question_system_ids,
495
+			$system_question_group_id
496
+		);
497
+	}
498
+
499
+
500
+	/**
501
+	 * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
502
+	 * which system question QST_ID corresponds to the QST_system 'city', use
503
+	 * EEM_Question::instance()->get_Question_ID_from_system_string('city');
504
+	 *
505
+	 * @param $QST_system
506
+	 * @return int of QST_ID for the question that corresponds to that QST_system
507
+	 * @throws EE_Error
508
+	 * @throws ReflectionException
509
+	 */
510
+	public function get_Question_ID_from_system_string($QST_system): int
511
+	{
512
+		return $this->get_var([['QST_system' => $QST_system]]);
513
+	}
514
+
515
+
516
+	/**
517
+	 * searches the db for the question with the latest question order and returns that value.
518
+	 *
519
+	 * @return int
520
+	 * @throws EE_Error
521
+	 * @throws ReflectionException
522
+	 */
523
+	public function get_latest_question_order(): int
524
+	{
525
+		$columns_to_select = [
526
+			'max_order' => ["MAX(QST_order)", "%d"],
527
+		];
528
+		$max               = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select);
529
+		return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
530
+	}
531
+
532
+
533
+	/**
534
+	 * Returns an array where keys are system question QST_system values,
535
+	 * and values are the highest question max the admin can set on the question
536
+	 * (aka the "max max"; eg, a site admin can change the zip question to have a max
537
+	 * of 5, but no larger than 12)
538
+	 *
539
+	 * @return array
540
+	 */
541
+	public function system_question_maxes(): array
542
+	{
543
+		return [
544
+			'fname'         => 45,
545
+			'lname'         => 45,
546
+			'address'       => 255,
547
+			'address2'      => 255,
548
+			'city'          => 45,
549
+			'zip'           => 12,
550
+			'email'         => 255,
551
+			'email_confirm' => 255,
552
+			'phone'         => 45,
553
+		];
554
+	}
555
+
556
+
557
+	/**
558
+	 * Given a QST_system value, gets the question's largest allowable max input.
559
+	 *
560
+	 * @param string $system_question_value
561
+	 * @return int|float
562
+	 * @see Registration_Form_Admin_Page::system_question_maxes()
563
+	 */
564
+	public function absolute_max_for_system_question(string $system_question_value)
565
+	{
566
+		$maxes = $this->system_question_maxes();
567
+		return $maxes[ $system_question_value ] ?? EE_INF;
568
+	}
569
+
570
+
571
+	/**
572
+	 * @return array
573
+	 */
574
+	public function question_descriptions(): array
575
+	{
576
+		return $this->_question_descriptions;
577
+	}
578
+
579
+
580
+	/**
581
+	 * Returns all the question types that should have an admin-defined max input length
582
+	 *
583
+	 * @return array
584
+	 */
585
+	public function questionTypesWithMaxLength(): array
586
+	{
587
+		return (array) $this->question_types_with_max_length;
588
+	}
589 589
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
                 EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
134 134
             ]
135 135
         );
136
-        $this->_question_descriptions         = apply_filters(
136
+        $this->_question_descriptions = apply_filters(
137 137
             'FHEE__EEM_Question__construct__question_descriptions',
138 138
             [
139 139
                 EEM_Question::QST_type_checkbox      => esc_html__(
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
                 ),
207 207
             ]
208 208
         );
209
-        $this->_question_type_categories      = (array) apply_filters(
209
+        $this->_question_type_categories = (array) apply_filters(
210 210
             'FHEE__EEM_Question__construct__question_type_categories',
211 211
             [
212 212
                 'text'               => [
@@ -327,14 +327,14 @@  discard block
 block discarded – undo
327 327
             'WP_User'                 => new EE_Belongs_To_Relation(),
328 328
         ];
329 329
         // this model is generally available for reading
330
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
331
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form(
330
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
331
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form(
332 332
             'QST_system'
333 333
         );
334
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form(
334
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form(
335 335
                 'QST_system'
336 336
         );
337
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form(
337
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form(
338 338
                 'QST_system'
339 339
         );
340 340
 
@@ -383,10 +383,10 @@  discard block
 block discarded – undo
383 383
      */
384 384
     public function question_type_is_in_category(string $question_type, string $category): bool
385 385
     {
386
-        if (! isset($this->_question_type_categories[ $category ])) {
386
+        if ( ! isset($this->_question_type_categories[$category])) {
387 387
             return false;
388 388
         }
389
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
389
+        return in_array($question_type, $this->_question_type_categories[$category]);
390 390
     }
391 391
 
392 392
 
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
      */
399 399
     public function question_types_in_category(string $category): array
400 400
     {
401
-        if (isset($this->_question_type_categories[ $category ])) {
402
-            return $this->_question_type_categories[ $category ];
401
+        if (isset($this->_question_type_categories[$category])) {
402
+            return $this->_question_type_categories[$category];
403 403
         }
404 404
         return [];
405 405
     }
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
     public function absolute_max_for_system_question(string $system_question_value)
565 565
     {
566 566
         $maxes = $this->system_question_maxes();
567
-        return $maxes[ $system_question_value ] ?? EE_INF;
567
+        return $maxes[$system_question_value] ?? EE_INF;
568 568
     }
569 569
 
570 570
 
Please login to merge, or discard this patch.
core/db_models/EEM_Currency_Payment_Method.model.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -9,54 +9,54 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Currency_Payment_Method extends EEM_Base
11 11
 {
12
-    /**
13
-     * @var EEM_Currency_Payment_Method
14
-     */
15
-    protected static $_instance;
12
+	/**
13
+	 * @var EEM_Currency_Payment_Method
14
+	 */
15
+	protected static $_instance;
16 16
 
17 17
 
18
-    /**
19
-     * EEM_Currency_Payment_Method constructor.
20
-     *
21
-     * @param string $timezone
22
-     * @throws EE_Error
23
-     */
24
-    protected function __construct(string $timezone = '')
25
-    {
26
-        $this->singular_item    = esc_html__('Currency Usable by Payment Method', 'event_espresso');
27
-        $this->plural_item      = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
28
-        $this->_tables          = [
29
-            'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'),
30
-        ];
31
-        $this->_fields          = [
32
-            'Currency_Payment_Method' => [
33
-                'CPM_ID'   => new EE_Primary_Key_Int_Field(
34
-                    'CPM_ID',
35
-                    esc_html__('Currency to Payment Method LInk ID', 'event_espresso')
36
-                ),
37
-                'CUR_code' => new EE_Foreign_Key_String_Field(
38
-                    'CUR_code',
39
-                    esc_html__('Currency Code', 'event_espresso'),
40
-                    false,
41
-                    '',
42
-                    'Currency'
43
-                ),
44
-                'PMD_ID'   => new EE_Foreign_Key_Int_Field(
45
-                    'PMD_ID',
46
-                    esc_html__('Payment Method ID', 'event_espresso'),
47
-                    false,
48
-                    0,
49
-                    'Payment_Method'
50
-                ),
51
-            ],
52
-        ];
53
-        $this->_model_relations = [
54
-            'Currency'       => new EE_Belongs_To_Relation(),
55
-            'Payment_Method' => new EE_Belongs_To_Relation(),
56
-        ];
57
-        // this model is generally available for reading
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
59
-        $this->_caps_slug                                         = 'payment_methods';
60
-        parent::__construct($timezone);
61
-    }
18
+	/**
19
+	 * EEM_Currency_Payment_Method constructor.
20
+	 *
21
+	 * @param string $timezone
22
+	 * @throws EE_Error
23
+	 */
24
+	protected function __construct(string $timezone = '')
25
+	{
26
+		$this->singular_item    = esc_html__('Currency Usable by Payment Method', 'event_espresso');
27
+		$this->plural_item      = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
28
+		$this->_tables          = [
29
+			'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'),
30
+		];
31
+		$this->_fields          = [
32
+			'Currency_Payment_Method' => [
33
+				'CPM_ID'   => new EE_Primary_Key_Int_Field(
34
+					'CPM_ID',
35
+					esc_html__('Currency to Payment Method LInk ID', 'event_espresso')
36
+				),
37
+				'CUR_code' => new EE_Foreign_Key_String_Field(
38
+					'CUR_code',
39
+					esc_html__('Currency Code', 'event_espresso'),
40
+					false,
41
+					'',
42
+					'Currency'
43
+				),
44
+				'PMD_ID'   => new EE_Foreign_Key_Int_Field(
45
+					'PMD_ID',
46
+					esc_html__('Payment Method ID', 'event_espresso'),
47
+					false,
48
+					0,
49
+					'Payment_Method'
50
+				),
51
+			],
52
+		];
53
+		$this->_model_relations = [
54
+			'Currency'       => new EE_Belongs_To_Relation(),
55
+			'Payment_Method' => new EE_Belongs_To_Relation(),
56
+		];
57
+		// this model is generally available for reading
58
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
59
+		$this->_caps_slug                                         = 'payment_methods';
60
+		parent::__construct($timezone);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
             'Payment_Method' => new EE_Belongs_To_Relation(),
56 56
         ];
57 57
         // this model is generally available for reading
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
58
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
59 59
         $this->_caps_slug                                         = 'payment_methods';
60 60
         parent::__construct($timezone);
61 61
     }
Please login to merge, or discard this patch.