Completed
Branch master (d4ace2)
by
unknown
04:43
created
core/db_models/EEM_Status.model.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -10,308 +10,308 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Status extends EEM_Base
12 12
 {
13
-    protected static ?EEM_Status $_instance = null;
13
+	protected static ?EEM_Status $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * @param string|null $timezone
18
-     * @throws EE_Error
19
-     */
20
-    protected function __construct(?string $timezone = '')
21
-    {
22
-        $this->singular_item    = esc_html__('Status', 'event_espresso');
23
-        $this->plural_item      = esc_html__('Stati', 'event_espresso');
24
-        $this->_tables          = [
25
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
26
-        ];
27
-        $this->_fields          = [
28
-            'StatusTable' => [
29
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')),
30
-                'STS_code'     => new EE_Plain_Text_Field(
31
-                    'STS_code', esc_html__('Status Code', 'event_espresso'), false, ''
32
-                ),
33
-                'STS_type'     => new EE_Enum_Text_Field(
34
-                    'STS_type',
35
-                    esc_html__("Type", "event_espresso"),
36
-                    false,
37
-                    'event',
38
-                    [
39
-                        'event'        => esc_html__("Event", "event_espresso"),// deprecated
40
-                        'registration' => esc_html__("Registration", "event_espresso"),
41
-                        'transaction'  => esc_html__("Transaction", "event_espresso"),
42
-                        'payment'      => esc_html__("Payment", "event_espresso"),
43
-                        'email'        => esc_html__("Email", "event_espresso"),
44
-                        'message'      => esc_html__("Message", "event_espresso"),
45
-                    ]
46
-                ),
47
-                'STS_can_edit' => new EE_Boolean_Field(
48
-                    'STS_can_edit',
49
-                    esc_html__('Editable?', 'event_espresso'),
50
-                    false,
51
-                    false
52
-                ),
53
-                'STS_desc'     => new EE_Simple_HTML_Field(
54
-                    'STS_desc',
55
-                    esc_html__("Description", "event_espresso"),
56
-                    false,
57
-                    ''
58
-                ),
59
-                'STS_open'     => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false),
60
-            ],
61
-        ];
62
-        $this->_model_relations = [
63
-            'Registration' => new EE_Has_Many_Relation(),
64
-            'Transaction'  => new EE_Has_Many_Relation(),
65
-            'Payment'      => new EE_Has_Many_Relation(),
66
-        ];
67
-        // this model is generally available for reading
68
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
16
+	/**
17
+	 * @param string|null $timezone
18
+	 * @throws EE_Error
19
+	 */
20
+	protected function __construct(?string $timezone = '')
21
+	{
22
+		$this->singular_item    = esc_html__('Status', 'event_espresso');
23
+		$this->plural_item      = esc_html__('Stati', 'event_espresso');
24
+		$this->_tables          = [
25
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
26
+		];
27
+		$this->_fields          = [
28
+			'StatusTable' => [
29
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')),
30
+				'STS_code'     => new EE_Plain_Text_Field(
31
+					'STS_code', esc_html__('Status Code', 'event_espresso'), false, ''
32
+				),
33
+				'STS_type'     => new EE_Enum_Text_Field(
34
+					'STS_type',
35
+					esc_html__("Type", "event_espresso"),
36
+					false,
37
+					'event',
38
+					[
39
+						'event'        => esc_html__("Event", "event_espresso"),// deprecated
40
+						'registration' => esc_html__("Registration", "event_espresso"),
41
+						'transaction'  => esc_html__("Transaction", "event_espresso"),
42
+						'payment'      => esc_html__("Payment", "event_espresso"),
43
+						'email'        => esc_html__("Email", "event_espresso"),
44
+						'message'      => esc_html__("Message", "event_espresso"),
45
+					]
46
+				),
47
+				'STS_can_edit' => new EE_Boolean_Field(
48
+					'STS_can_edit',
49
+					esc_html__('Editable?', 'event_espresso'),
50
+					false,
51
+					false
52
+				),
53
+				'STS_desc'     => new EE_Simple_HTML_Field(
54
+					'STS_desc',
55
+					esc_html__("Description", "event_espresso"),
56
+					false,
57
+					''
58
+				),
59
+				'STS_open'     => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false),
60
+			],
61
+		];
62
+		$this->_model_relations = [
63
+			'Registration' => new EE_Has_Many_Relation(),
64
+			'Transaction'  => new EE_Has_Many_Relation(),
65
+			'Payment'      => new EE_Has_Many_Relation(),
66
+		];
67
+		// this model is generally available for reading
68
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
69 69
 
70
-        parent::__construct($timezone);
71
-    }
70
+		parent::__construct($timezone);
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * This method provides the localized singular or plural string for a given status id
76
-     *
77
-     * @param array   $statuses  This should be an array of statuses in the format array( $status_id, $status_code ).
78
-     *                           That way if there isn't a translation in the index we'll return the default code.
79
-     * @param boolean $plural    Whether to return plural string or not. Note, nearly all of the plural strings are the
80
-     *                           same as the singular (in English), however, this may NOT be the case with other
81
-     *                           languages
82
-     * @param string  $schema    This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
83
-     *                           the status string returned ( UPPER, lower, Sentence)
84
-     * @return array             an array of translated strings for the incoming status id.
85
-     * @throws EE_Error
86
-     */
87
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
88
-    {
89
-        // note these are all in lower case because ucwords() on upper case will NOT convert.
90
-        $translation_array = [
91
-            EEM_Registration::status_id_pending_payment => [
92
-                esc_html__('pending payment', 'event_espresso'), // singular
93
-                esc_html__('pending payments', 'event_espresso'), // plural
94
-            ],
95
-            EEM_Registration::status_id_approved        => [
96
-                esc_html__('approved', 'event_espresso'), // singular
97
-                esc_html__('approved', 'event_espresso'), // plural
98
-            ],
99
-            EEM_Registration::status_id_not_approved    => [
100
-                esc_html__('not approved', 'event_espresso'),
101
-                esc_html__('not approved', 'event_espresso'),
102
-            ],
103
-            EEM_Registration::status_id_cancelled       => [
104
-                esc_html__('cancelled', 'event_espresso'),
105
-                esc_html__('cancelled', 'event_espresso'),
106
-            ],
107
-            EEM_Registration::status_id_incomplete      => [
108
-                esc_html__('incomplete', 'event_espresso'),
109
-                esc_html__('incomplete', 'event_espresso'),
110
-            ],
111
-            EEM_Registration::status_id_declined        => [
112
-                esc_html__('declined', 'event_espresso'),
113
-                esc_html__('declined', 'event_espresso'),
114
-            ],
115
-            EEM_Registration::status_id_wait_list       => [
116
-                esc_html__('wait list', 'event_espresso'),
117
-                esc_html__('wait list', 'event_espresso'),
118
-            ],
119
-            EEM_Transaction::overpaid_status_code       => [
120
-                esc_html__('overpaid', 'event_espresso'),
121
-                esc_html__('overpaid', 'event_espresso'),
122
-            ],
123
-            EEM_Transaction::complete_status_code       => [
124
-                esc_html__('complete', 'event_espresso'),
125
-                esc_html__('complete', 'event_espresso'),
126
-            ],
127
-            EEM_Transaction::incomplete_status_code     => [
128
-                esc_html__('incomplete', 'event_espresso'),
129
-                esc_html__('incomplete', 'event_espresso'),
130
-            ],
131
-            EEM_Transaction::failed_status_code         => [
132
-                esc_html__('failed', 'event_espresso'),
133
-                esc_html__('failed', 'event_espresso'),
134
-            ],
135
-            EEM_Transaction::abandoned_status_code      => [
136
-                esc_html__('abandoned', 'event_espresso'),
137
-                esc_html__('abandoned', 'event_espresso'),
138
-            ],
139
-            EEM_Payment::status_id_approved             => [
140
-                esc_html__('accepted', 'event_espresso'),
141
-                esc_html__('accepted', 'event_espresso'),
142
-            ],
143
-            EEM_Payment::status_id_pending              => [
144
-                esc_html__('pending', 'event_espresso'),
145
-                esc_html__('pending', 'event_espresso'),
146
-            ],
147
-            EEM_Payment::status_id_cancelled            => [
148
-                esc_html__('cancelled', 'event_espresso'),
149
-                esc_html__('cancelled', 'event_espresso'),
150
-            ],
151
-            EEM_Payment::status_id_declined             => [
152
-                esc_html__('declined', 'event_espresso'),
153
-                esc_html__('declined', 'event_espresso'),
154
-            ],
155
-            EEM_Payment::status_id_failed               => [
156
-                esc_html__('failed', 'event_espresso'),
157
-                esc_html__('failed', 'event_espresso'),
158
-            ],
159
-            // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
160
-            EEM_Event::sold_out                         => [
161
-                esc_html__('sold out', 'event_espresso'),
162
-                esc_html__('sold out', 'event_espresso'),
163
-            ],
164
-            EEM_Event::postponed                        => [
165
-                esc_html__('postponed', 'event_espresso'),
166
-                esc_html__('Postponed', 'event_espresso'),
167
-            ],
168
-            EEM_Event::cancelled                        => [
169
-                esc_html__('cancelled', 'event_espresso'),
170
-                esc_html__('cancelled', 'event_espresso'),
171
-            ],
172
-            EE_Ticket::archived                         => [
173
-                esc_html__('archived', 'event_espresso'),
174
-                esc_html__('archived', 'event_espresso'),
175
-            ],
176
-            EE_Ticket::expired                          => [
177
-                esc_html__('expired', 'event_espresso'),
178
-                esc_html__('expired', 'event_espresso'),
179
-            ],
180
-            EE_Ticket::sold_out                         => [
181
-                esc_html__('sold out', 'event_espresso'),
182
-                esc_html__('sold out', 'event_espresso'),
183
-            ],
184
-            EE_Ticket::pending                          => [
185
-                esc_html__('upcoming', 'event_espresso'),
186
-                esc_html__('upcoming', 'event_espresso'),
187
-            ],
188
-            EE_Ticket::onsale                           => [
189
-                esc_html__('on sale', 'event_espresso'),
190
-                esc_html__('on sale', 'event_espresso'),
191
-            ],
192
-            EE_Datetime::cancelled                      => [
193
-                esc_html__('cancelled', 'event_espresso'),
194
-                esc_html__('cancelled', 'event_espresso'),
195
-            ],
196
-            EE_Datetime::sold_out                       => [
197
-                esc_html__('sold out', 'event_espresso'),
198
-                esc_html__('sold out', 'event_espresso'),
199
-            ],
200
-            EE_Datetime::expired                        => [
201
-                esc_html__('expired', 'event_espresso'),
202
-                esc_html__('expired', 'event_espresso'),
203
-            ],
204
-            EE_Datetime::inactive                       => [
205
-                esc_html__('inactive', 'event_espresso'),
206
-                esc_html__('inactive', 'event_espresso'),
207
-            ],
208
-            EE_Datetime::upcoming                       => [
209
-                esc_html__('upcoming', 'event_espresso'),
210
-                esc_html__('upcoming', 'event_espresso'),
211
-            ],
212
-            EE_Datetime::active                         => [
213
-                esc_html__('active', 'event_espresso'),
214
-                esc_html__('active', 'event_espresso'),
215
-            ],
216
-            EE_Datetime::postponed                      => [
217
-                esc_html__('postponed', 'event_espresso'),
218
-                esc_html__('postponed', 'event_espresso'),
219
-            ],
220
-            // messages related
221
-            EEM_Message::status_sent                    => [
222
-                esc_html__('sent', 'event_espresso'),
223
-                esc_html__('sent', 'event_espresso'),
224
-            ],
225
-            EEM_Message::status_idle                    => [
226
-                esc_html__('queued for sending', 'event_espresso'),
227
-                esc_html__('queued for sending', 'event_espresso'),
228
-            ],
229
-            EEM_Message::status_failed                  => [
230
-                esc_html__('failed', 'event_espresso'),
231
-                esc_html__('failed', 'event_espresso'),
232
-            ],
233
-            EEM_Message::status_debug_only              => [
234
-                esc_html__('debug only', 'event_espresso'),
235
-                esc_html__('debug only', 'event_espresso'),
236
-            ],
237
-            EEM_Message::status_messenger_executing     => [
238
-                esc_html__('messenger is executing', 'event_espresso'),
239
-                esc_html__('messenger is executing', 'event_espresso'),
240
-            ],
241
-            EEM_Message::status_resend                  => [
242
-                esc_html__('queued for resending', 'event_espresso'),
243
-                esc_html__('queued for resending', 'event_espresso'),
244
-            ],
245
-            EEM_Message::status_incomplete              => [
246
-                esc_html__('queued for generating', 'event_espresso'),
247
-                esc_html__('queued for generating', 'event_espresso'),
248
-            ],
249
-            EEM_Message::status_retry                   => [
250
-                esc_html__('failed sending, can be retried', 'event_espresso'),
251
-                esc_html__('failed sending, can be retried', 'event_espresso'),
252
-            ],
253
-            EEM_CPT_Base::post_status_publish           => [
254
-                esc_html__('published', 'event_espresso'),
255
-                esc_html__('published', 'event_espresso'),
256
-            ],
257
-            EEM_CPT_Base::post_status_future            => [
258
-                esc_html__('scheduled', 'event_espresso'),
259
-                esc_html__('scheduled', 'event_espresso'),
260
-            ],
261
-            EEM_CPT_Base::post_status_draft             => [
262
-                esc_html__('draft', 'event_espresso'),
263
-                esc_html__('draft', 'event_espresso'),
264
-            ],
265
-            EEM_CPT_Base::post_status_pending           => [
266
-                esc_html__('pending', 'event_espresso'),
267
-                esc_html__('pending', 'event_espresso'),
268
-            ],
269
-            EEM_CPT_Base::post_status_private           => [
270
-                esc_html__('private', 'event_espresso'),
271
-                esc_html__('private', 'event_espresso'),
272
-            ],
273
-            EEM_CPT_Base::post_status_trashed           => [
274
-                esc_html__('trashed', 'event_espresso'),
275
-                esc_html__('trashed', 'event_espresso'),
276
-            ],
277
-        ];
74
+	/**
75
+	 * This method provides the localized singular or plural string for a given status id
76
+	 *
77
+	 * @param array   $statuses  This should be an array of statuses in the format array( $status_id, $status_code ).
78
+	 *                           That way if there isn't a translation in the index we'll return the default code.
79
+	 * @param boolean $plural    Whether to return plural string or not. Note, nearly all of the plural strings are the
80
+	 *                           same as the singular (in English), however, this may NOT be the case with other
81
+	 *                           languages
82
+	 * @param string  $schema    This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
83
+	 *                           the status string returned ( UPPER, lower, Sentence)
84
+	 * @return array             an array of translated strings for the incoming status id.
85
+	 * @throws EE_Error
86
+	 */
87
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
88
+	{
89
+		// note these are all in lower case because ucwords() on upper case will NOT convert.
90
+		$translation_array = [
91
+			EEM_Registration::status_id_pending_payment => [
92
+				esc_html__('pending payment', 'event_espresso'), // singular
93
+				esc_html__('pending payments', 'event_espresso'), // plural
94
+			],
95
+			EEM_Registration::status_id_approved        => [
96
+				esc_html__('approved', 'event_espresso'), // singular
97
+				esc_html__('approved', 'event_espresso'), // plural
98
+			],
99
+			EEM_Registration::status_id_not_approved    => [
100
+				esc_html__('not approved', 'event_espresso'),
101
+				esc_html__('not approved', 'event_espresso'),
102
+			],
103
+			EEM_Registration::status_id_cancelled       => [
104
+				esc_html__('cancelled', 'event_espresso'),
105
+				esc_html__('cancelled', 'event_espresso'),
106
+			],
107
+			EEM_Registration::status_id_incomplete      => [
108
+				esc_html__('incomplete', 'event_espresso'),
109
+				esc_html__('incomplete', 'event_espresso'),
110
+			],
111
+			EEM_Registration::status_id_declined        => [
112
+				esc_html__('declined', 'event_espresso'),
113
+				esc_html__('declined', 'event_espresso'),
114
+			],
115
+			EEM_Registration::status_id_wait_list       => [
116
+				esc_html__('wait list', 'event_espresso'),
117
+				esc_html__('wait list', 'event_espresso'),
118
+			],
119
+			EEM_Transaction::overpaid_status_code       => [
120
+				esc_html__('overpaid', 'event_espresso'),
121
+				esc_html__('overpaid', 'event_espresso'),
122
+			],
123
+			EEM_Transaction::complete_status_code       => [
124
+				esc_html__('complete', 'event_espresso'),
125
+				esc_html__('complete', 'event_espresso'),
126
+			],
127
+			EEM_Transaction::incomplete_status_code     => [
128
+				esc_html__('incomplete', 'event_espresso'),
129
+				esc_html__('incomplete', 'event_espresso'),
130
+			],
131
+			EEM_Transaction::failed_status_code         => [
132
+				esc_html__('failed', 'event_espresso'),
133
+				esc_html__('failed', 'event_espresso'),
134
+			],
135
+			EEM_Transaction::abandoned_status_code      => [
136
+				esc_html__('abandoned', 'event_espresso'),
137
+				esc_html__('abandoned', 'event_espresso'),
138
+			],
139
+			EEM_Payment::status_id_approved             => [
140
+				esc_html__('accepted', 'event_espresso'),
141
+				esc_html__('accepted', 'event_espresso'),
142
+			],
143
+			EEM_Payment::status_id_pending              => [
144
+				esc_html__('pending', 'event_espresso'),
145
+				esc_html__('pending', 'event_espresso'),
146
+			],
147
+			EEM_Payment::status_id_cancelled            => [
148
+				esc_html__('cancelled', 'event_espresso'),
149
+				esc_html__('cancelled', 'event_espresso'),
150
+			],
151
+			EEM_Payment::status_id_declined             => [
152
+				esc_html__('declined', 'event_espresso'),
153
+				esc_html__('declined', 'event_espresso'),
154
+			],
155
+			EEM_Payment::status_id_failed               => [
156
+				esc_html__('failed', 'event_espresso'),
157
+				esc_html__('failed', 'event_espresso'),
158
+			],
159
+			// following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
160
+			EEM_Event::sold_out                         => [
161
+				esc_html__('sold out', 'event_espresso'),
162
+				esc_html__('sold out', 'event_espresso'),
163
+			],
164
+			EEM_Event::postponed                        => [
165
+				esc_html__('postponed', 'event_espresso'),
166
+				esc_html__('Postponed', 'event_espresso'),
167
+			],
168
+			EEM_Event::cancelled                        => [
169
+				esc_html__('cancelled', 'event_espresso'),
170
+				esc_html__('cancelled', 'event_espresso'),
171
+			],
172
+			EE_Ticket::archived                         => [
173
+				esc_html__('archived', 'event_espresso'),
174
+				esc_html__('archived', 'event_espresso'),
175
+			],
176
+			EE_Ticket::expired                          => [
177
+				esc_html__('expired', 'event_espresso'),
178
+				esc_html__('expired', 'event_espresso'),
179
+			],
180
+			EE_Ticket::sold_out                         => [
181
+				esc_html__('sold out', 'event_espresso'),
182
+				esc_html__('sold out', 'event_espresso'),
183
+			],
184
+			EE_Ticket::pending                          => [
185
+				esc_html__('upcoming', 'event_espresso'),
186
+				esc_html__('upcoming', 'event_espresso'),
187
+			],
188
+			EE_Ticket::onsale                           => [
189
+				esc_html__('on sale', 'event_espresso'),
190
+				esc_html__('on sale', 'event_espresso'),
191
+			],
192
+			EE_Datetime::cancelled                      => [
193
+				esc_html__('cancelled', 'event_espresso'),
194
+				esc_html__('cancelled', 'event_espresso'),
195
+			],
196
+			EE_Datetime::sold_out                       => [
197
+				esc_html__('sold out', 'event_espresso'),
198
+				esc_html__('sold out', 'event_espresso'),
199
+			],
200
+			EE_Datetime::expired                        => [
201
+				esc_html__('expired', 'event_espresso'),
202
+				esc_html__('expired', 'event_espresso'),
203
+			],
204
+			EE_Datetime::inactive                       => [
205
+				esc_html__('inactive', 'event_espresso'),
206
+				esc_html__('inactive', 'event_espresso'),
207
+			],
208
+			EE_Datetime::upcoming                       => [
209
+				esc_html__('upcoming', 'event_espresso'),
210
+				esc_html__('upcoming', 'event_espresso'),
211
+			],
212
+			EE_Datetime::active                         => [
213
+				esc_html__('active', 'event_espresso'),
214
+				esc_html__('active', 'event_espresso'),
215
+			],
216
+			EE_Datetime::postponed                      => [
217
+				esc_html__('postponed', 'event_espresso'),
218
+				esc_html__('postponed', 'event_espresso'),
219
+			],
220
+			// messages related
221
+			EEM_Message::status_sent                    => [
222
+				esc_html__('sent', 'event_espresso'),
223
+				esc_html__('sent', 'event_espresso'),
224
+			],
225
+			EEM_Message::status_idle                    => [
226
+				esc_html__('queued for sending', 'event_espresso'),
227
+				esc_html__('queued for sending', 'event_espresso'),
228
+			],
229
+			EEM_Message::status_failed                  => [
230
+				esc_html__('failed', 'event_espresso'),
231
+				esc_html__('failed', 'event_espresso'),
232
+			],
233
+			EEM_Message::status_debug_only              => [
234
+				esc_html__('debug only', 'event_espresso'),
235
+				esc_html__('debug only', 'event_espresso'),
236
+			],
237
+			EEM_Message::status_messenger_executing     => [
238
+				esc_html__('messenger is executing', 'event_espresso'),
239
+				esc_html__('messenger is executing', 'event_espresso'),
240
+			],
241
+			EEM_Message::status_resend                  => [
242
+				esc_html__('queued for resending', 'event_espresso'),
243
+				esc_html__('queued for resending', 'event_espresso'),
244
+			],
245
+			EEM_Message::status_incomplete              => [
246
+				esc_html__('queued for generating', 'event_espresso'),
247
+				esc_html__('queued for generating', 'event_espresso'),
248
+			],
249
+			EEM_Message::status_retry                   => [
250
+				esc_html__('failed sending, can be retried', 'event_espresso'),
251
+				esc_html__('failed sending, can be retried', 'event_espresso'),
252
+			],
253
+			EEM_CPT_Base::post_status_publish           => [
254
+				esc_html__('published', 'event_espresso'),
255
+				esc_html__('published', 'event_espresso'),
256
+			],
257
+			EEM_CPT_Base::post_status_future            => [
258
+				esc_html__('scheduled', 'event_espresso'),
259
+				esc_html__('scheduled', 'event_espresso'),
260
+			],
261
+			EEM_CPT_Base::post_status_draft             => [
262
+				esc_html__('draft', 'event_espresso'),
263
+				esc_html__('draft', 'event_espresso'),
264
+			],
265
+			EEM_CPT_Base::post_status_pending           => [
266
+				esc_html__('pending', 'event_espresso'),
267
+				esc_html__('pending', 'event_espresso'),
268
+			],
269
+			EEM_CPT_Base::post_status_private           => [
270
+				esc_html__('private', 'event_espresso'),
271
+				esc_html__('private', 'event_espresso'),
272
+			],
273
+			EEM_CPT_Base::post_status_trashed           => [
274
+				esc_html__('trashed', 'event_espresso'),
275
+				esc_html__('trashed', 'event_espresso'),
276
+			],
277
+		];
278 278
 
279
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
279
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
280 280
 
281
-        if (! is_array($statuses)) {
282
-            throw new EE_Error(
283
-                esc_html__(
284
-                    'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
285
-                    'event_espresso'
286
-                )
287
-            );
288
-        }
281
+		if (! is_array($statuses)) {
282
+			throw new EE_Error(
283
+				esc_html__(
284
+					'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
285
+					'event_espresso'
286
+				)
287
+			);
288
+		}
289 289
 
290
-        $translation = [];
290
+		$translation = [];
291 291
 
292
-        foreach ($statuses as $id => $code) {
293
-            if (isset($translation_array[ $id ])) {
294
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
295
-            } else {
296
-                $translation[ $id ] = $code;
297
-            }
292
+		foreach ($statuses as $id => $code) {
293
+			if (isset($translation_array[ $id ])) {
294
+				$translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
295
+			} else {
296
+				$translation[ $id ] = $code;
297
+			}
298 298
 
299
-            // schema
300
-            switch ($schema) {
301
-                case 'lower':
302
-                    $translation[ $id ] = strtolower(
303
-                        $translation[ $id ]
304
-                    ); // even though these start in lower case, this will catch any statuses added via filter.
305
-                    break;
306
-                case 'sentence':
307
-                    $translation[ $id ] = ucwords($translation[ $id ]);
308
-                    break;
309
-                case 'upper':
310
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
311
-                    break;
312
-            }
313
-        }
299
+			// schema
300
+			switch ($schema) {
301
+				case 'lower':
302
+					$translation[ $id ] = strtolower(
303
+						$translation[ $id ]
304
+					); // even though these start in lower case, this will catch any statuses added via filter.
305
+					break;
306
+				case 'sentence':
307
+					$translation[ $id ] = ucwords($translation[ $id ]);
308
+					break;
309
+				case 'upper':
310
+					$translation[ $id ] = strtoupper($translation[ $id ]);
311
+					break;
312
+			}
313
+		}
314 314
 
315
-        return $translation;
316
-    }
315
+		return $translation;
316
+	}
317 317
 }
Please login to merge, or discard this patch.
core/db_models/EEM_WP_User.model.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -12,124 +12,124 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_WP_User extends EEM_Base
14 14
 {
15
-    protected static ?EEM_WP_User $_instance = null;
15
+	protected static ?EEM_WP_User $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * @param string|null            $timezone
20
-     * @param ModelFieldFactory|null $model_field_factory
21
-     * @throws EE_Error
22
-     */
23
-    protected function __construct(?string $timezone = '', ModelFieldFactory $model_field_factory = null)
24
-    {
25
-        $this->singular_item = esc_html__('WP_User', 'event_espresso');
26
-        $this->plural_item   = esc_html__('WP_Users', 'event_espresso');
27
-        global $wpdb;
28
-        $this->_tables                                                      = [
29
-            'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
30
-        ];
31
-        $this->_fields                                                      = [
32
-            'WP_User' => [
33
-                'ID'                  => $model_field_factory->createPrimaryKeyIntField(
34
-                    'ID',
35
-                    esc_html__('WP_User ID', 'event_espresso')
36
-                ),
37
-                'user_login'          => $model_field_factory->createPlainTextField(
38
-                    'user_login',
39
-                    esc_html__('User Login', 'event_espresso'),
40
-                    false
41
-                ),
42
-                'user_pass'           => $model_field_factory->createPlainTextField(
43
-                    'user_pass',
44
-                    esc_html__('User Password', 'event_espresso'),
45
-                    false
46
-                ),
47
-                'user_nicename'       => $model_field_factory->createPlainTextField(
48
-                    'user_nicename',
49
-                    esc_html__(' User Nice Name', 'event_espresso'),
50
-                    false
51
-                ),
52
-                'user_email'          => $model_field_factory->createEmailField(
53
-                    'user_email',
54
-                    esc_html__('User Email', 'event_espresso'),
55
-                    false
56
-                ),
57
-                'user_registered'     => $model_field_factory->createDatetimeField(
58
-                    'user_registered',
59
-                    esc_html__('Date User Registered', 'event_espresso'),
60
-                    $timezone
61
-                ),
62
-                'user_activation_key' => $model_field_factory->createPlainTextField(
63
-                    'user_activation_key',
64
-                    esc_html__('User Activation Key', 'event_espresso'),
65
-                    false
66
-                ),
67
-                'user_status'         => $model_field_factory->createIntegerField(
68
-                    'user_status',
69
-                    esc_html__('User Status', 'event_espresso')
70
-                ),
71
-                'display_name'        => $model_field_factory->createPlainTextField(
72
-                    'display_name',
73
-                    esc_html__('Display Name', 'event_espresso'),
74
-                    false
75
-                ),
76
-            ],
77
-        ];
78
-        $this->_model_relations                                             = [
79
-            'Attendee'       => new EE_Has_Many_Relation(),
80
-            // all models are related to the change log
81
-            // 'Change_Log'     => new EE_Has_Many_Relation(),
82
-            'Event'          => new EE_Has_Many_Relation(),
83
-            'Message'        => new EE_Has_Many_Relation(),
84
-            'Payment_Method' => new EE_Has_Many_Relation(),
85
-            'Price'          => new EE_Has_Many_Relation(),
86
-            'Price_Type'     => new EE_Has_Many_Relation(),
87
-            'Question'       => new EE_Has_Many_Relation(),
88
-            'Question_Group' => new EE_Has_Many_Relation(),
89
-            'Ticket'         => new EE_Has_Many_Relation(),
90
-            'Venue'          => new EE_Has_Many_Relation(),
91
-        ];
92
-        $this->foreign_key_aliases                                          = [
93
-            'Event.EVT_wp_user'          => 'WP_User.ID',
94
-            'Payment_Method.PMD_wp_user' => 'WP_User.ID',
95
-            'Price.PRC_wp_user'          => 'WP_User.ID',
96
-            'Price_Type.PRT_wp_user'     => 'WP_User.ID',
97
-            'Question.QST_wp_user'       => 'WP_User.ID',
98
-            'Question_Group.QSG_wp_user' => 'WP_User.ID',
99
-            'Ticket.VNU_wp_user'         => 'WP_User.ID',
100
-            'Venue.TKT_wp_user'          => 'WP_User.ID',
101
-        ];
102
-        $this->_wp_core_model                                               = true;
103
-        $this->_caps_slug                                                   = 'users';
104
-        $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ]       = 'list';
105
-        $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list';
106
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
107
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User();
108
-        }
109
-        // @todo: account for create_users controls whether they can create users at all
110
-        parent::__construct($timezone);
111
-    }
18
+	/**
19
+	 * @param string|null            $timezone
20
+	 * @param ModelFieldFactory|null $model_field_factory
21
+	 * @throws EE_Error
22
+	 */
23
+	protected function __construct(?string $timezone = '', ModelFieldFactory $model_field_factory = null)
24
+	{
25
+		$this->singular_item = esc_html__('WP_User', 'event_espresso');
26
+		$this->plural_item   = esc_html__('WP_Users', 'event_espresso');
27
+		global $wpdb;
28
+		$this->_tables                                                      = [
29
+			'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
30
+		];
31
+		$this->_fields                                                      = [
32
+			'WP_User' => [
33
+				'ID'                  => $model_field_factory->createPrimaryKeyIntField(
34
+					'ID',
35
+					esc_html__('WP_User ID', 'event_espresso')
36
+				),
37
+				'user_login'          => $model_field_factory->createPlainTextField(
38
+					'user_login',
39
+					esc_html__('User Login', 'event_espresso'),
40
+					false
41
+				),
42
+				'user_pass'           => $model_field_factory->createPlainTextField(
43
+					'user_pass',
44
+					esc_html__('User Password', 'event_espresso'),
45
+					false
46
+				),
47
+				'user_nicename'       => $model_field_factory->createPlainTextField(
48
+					'user_nicename',
49
+					esc_html__(' User Nice Name', 'event_espresso'),
50
+					false
51
+				),
52
+				'user_email'          => $model_field_factory->createEmailField(
53
+					'user_email',
54
+					esc_html__('User Email', 'event_espresso'),
55
+					false
56
+				),
57
+				'user_registered'     => $model_field_factory->createDatetimeField(
58
+					'user_registered',
59
+					esc_html__('Date User Registered', 'event_espresso'),
60
+					$timezone
61
+				),
62
+				'user_activation_key' => $model_field_factory->createPlainTextField(
63
+					'user_activation_key',
64
+					esc_html__('User Activation Key', 'event_espresso'),
65
+					false
66
+				),
67
+				'user_status'         => $model_field_factory->createIntegerField(
68
+					'user_status',
69
+					esc_html__('User Status', 'event_espresso')
70
+				),
71
+				'display_name'        => $model_field_factory->createPlainTextField(
72
+					'display_name',
73
+					esc_html__('Display Name', 'event_espresso'),
74
+					false
75
+				),
76
+			],
77
+		];
78
+		$this->_model_relations                                             = [
79
+			'Attendee'       => new EE_Has_Many_Relation(),
80
+			// all models are related to the change log
81
+			// 'Change_Log'     => new EE_Has_Many_Relation(),
82
+			'Event'          => new EE_Has_Many_Relation(),
83
+			'Message'        => new EE_Has_Many_Relation(),
84
+			'Payment_Method' => new EE_Has_Many_Relation(),
85
+			'Price'          => new EE_Has_Many_Relation(),
86
+			'Price_Type'     => new EE_Has_Many_Relation(),
87
+			'Question'       => new EE_Has_Many_Relation(),
88
+			'Question_Group' => new EE_Has_Many_Relation(),
89
+			'Ticket'         => new EE_Has_Many_Relation(),
90
+			'Venue'          => new EE_Has_Many_Relation(),
91
+		];
92
+		$this->foreign_key_aliases                                          = [
93
+			'Event.EVT_wp_user'          => 'WP_User.ID',
94
+			'Payment_Method.PMD_wp_user' => 'WP_User.ID',
95
+			'Price.PRC_wp_user'          => 'WP_User.ID',
96
+			'Price_Type.PRT_wp_user'     => 'WP_User.ID',
97
+			'Question.QST_wp_user'       => 'WP_User.ID',
98
+			'Question_Group.QSG_wp_user' => 'WP_User.ID',
99
+			'Ticket.VNU_wp_user'         => 'WP_User.ID',
100
+			'Venue.TKT_wp_user'          => 'WP_User.ID',
101
+		];
102
+		$this->_wp_core_model                                               = true;
103
+		$this->_caps_slug                                                   = 'users';
104
+		$this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ]       = 'list';
105
+		$this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list';
106
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
107
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User();
108
+		}
109
+		// @todo: account for create_users controls whether they can create users at all
110
+		parent::__construct($timezone);
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * We don't need a foreign key to the WP_User model, we just need its primary key
116
-     *
117
-     * @return string
118
-     * @throws EE_Error
119
-     */
120
-    public function wp_user_field_name()
121
-    {
122
-        return $this->primary_key_name();
123
-    }
114
+	/**
115
+	 * We don't need a foreign key to the WP_User model, we just need its primary key
116
+	 *
117
+	 * @return string
118
+	 * @throws EE_Error
119
+	 */
120
+	public function wp_user_field_name()
121
+	{
122
+		return $this->primary_key_name();
123
+	}
124 124
 
125 125
 
126
-    /**
127
-     * This WP_User model IS owned, even though it doesn't have a foreign key to itself
128
-     *
129
-     * @return boolean
130
-     */
131
-    public function is_owned()
132
-    {
133
-        return true;
134
-    }
126
+	/**
127
+	 * This WP_User model IS owned, even though it doesn't have a foreign key to itself
128
+	 *
129
+	 * @return boolean
130
+	 */
131
+	public function is_owned()
132
+	{
133
+		return true;
134
+	}
135 135
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Payment.model.php 1 patch
Indentation   +338 added lines, -338 removed lines patch added patch discarded remove patch
@@ -9,342 +9,342 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Payment extends EEM_Base implements EEMI_Payment
11 11
 {
12
-    protected static ?EEM_Payment $_instance = null;
13
-
14
-
15
-    /**
16
-     * Status id in esp_status table that represents an approved payment
17
-     */
18
-    const status_id_approved = 'PAP';
19
-
20
-
21
-    /**
22
-     * Status id in esp_status table that represents a pending payment
23
-     */
24
-    const status_id_pending = 'PPN';
25
-
26
-
27
-    /**
28
-     * Status id in esp_status table that represents a cancelled payment (eg, the
29
-     * user went to PayPal, but on the paypal site decided to cancel the payment)
30
-     */
31
-    const status_id_cancelled = 'PCN';
32
-
33
-
34
-    /**
35
-     * Status id in esp_status table that represents a payment that was declined by
36
-     * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
37
-     */
38
-    const status_id_declined = 'PDC';
39
-
40
-
41
-    /**
42
-     * Status id in esp_status table that represents a payment that failed for technical reasons.
43
-     * (Eg, there was some error in communicating with the payment gateway.)
44
-     */
45
-    const status_id_failed = 'PFL';
46
-
47
-
48
-    /**
49
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
50
-     *                              any incoming timezone data that gets saved).  Note this just sends the timezone
51
-     *                              info to the date time model field objects.  Default is NULL (and will be assumed
52
-     *                              using the set timezone in the 'timezone_string' wp option)
53
-     * @throws EE_Error
54
-     * @throws ReflectionException
55
-     */
56
-    protected function __construct(?string $timezone = '')
57
-    {
58
-        $this->singular_item = esc_html__('Payment', 'event_espresso');
59
-        $this->plural_item   = esc_html__('Payments', 'event_espresso');
60
-
61
-        $this->_tables                 = [
62
-            'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID'),
63
-        ];
64
-        $this->_fields                 = [
65
-            'Payment' => [
66
-                'PAY_ID'               => new EE_Primary_Key_Int_Field(
67
-                    'PAY_ID',
68
-                    esc_html__('Payment ID', 'event_espresso')
69
-                ),
70
-                'TXN_ID'               => new EE_Foreign_Key_Int_Field(
71
-                    'TXN_ID',
72
-                    esc_html__('Transaction ID', 'event_espresso'),
73
-                    false,
74
-                    0,
75
-                    'Transaction'
76
-                ),
77
-                'STS_ID'               => new EE_Foreign_Key_String_Field(
78
-                    'STS_ID',
79
-                    esc_html__('Status ID', 'event_espresso'),
80
-                    false,
81
-                    EEM_Payment::status_id_failed,
82
-                    'Status'
83
-                ),
84
-                'PAY_timestamp'        => new EE_Datetime_Field(
85
-                    'PAY_timestamp',
86
-                    esc_html__(
87
-                        'Timestamp of when payment was attempted',
88
-                        'event_espresso'
89
-                    ),
90
-                    false,
91
-                    EE_Datetime_Field::now,
92
-                    $timezone
93
-                ),
94
-                'PAY_source'           => new EE_All_Caps_Text_Field(
95
-                    'PAY_source',
96
-                    esc_html__(
97
-                        'User-friendly description of payment',
98
-                        'event_espresso'
99
-                    ),
100
-                    false,
101
-                    'CART'
102
-                ),
103
-                'PAY_amount'           => new EE_Money_Field(
104
-                    'PAY_amount',
105
-                    esc_html__('Amount Payment should be for', 'event_espresso'),
106
-                    false,
107
-                    0
108
-                ),
109
-                'PMD_ID'               => new EE_Foreign_Key_Int_Field(
110
-                    'PMD_ID',
111
-                    esc_html__("Payment Method ID", 'event_espresso'),
112
-                    false,
113
-                    null,
114
-                    'Payment_Method'
115
-                ),
116
-                'PAY_gateway_response' => new EE_Plain_Text_Field(
117
-                    'PAY_gateway_response',
118
-                    esc_html__(
119
-                        'Response from Gateway about the payment',
120
-                        'event_espresso'
121
-                    ),
122
-                    false,
123
-                    ''
124
-                ),
125
-                'PAY_txn_id_chq_nmbr'  => new EE_Plain_Text_Field(
126
-                    'PAY_txn_id_chq_nmbr',
127
-                    esc_html__(
128
-                        'Gateway Transaction ID or Cheque Number',
129
-                        'event_espresso'
130
-                    ),
131
-                    true,
132
-                    ''
133
-                ),
134
-                'PAY_po_number'        => new EE_Plain_Text_Field(
135
-                    'PAY_po_number',
136
-                    esc_html__(
137
-                        'Purchase or Sales Number',
138
-                        'event_espresso'
139
-                    ),
140
-                    true,
141
-                    ''
142
-                ),
143
-                'PAY_extra_accntng'    => new EE_Simple_HTML_Field(
144
-                    'PAY_extra_accntng',
145
-                    esc_html__('Extra Account Info', 'event_espresso'),
146
-                    true,
147
-                    ''
148
-                ),
149
-                'PAY_details'          => new EE_Serialized_Text_Field(
150
-                    'PAY_details',
151
-                    esc_html__(
152
-                        'Full Gateway response about payment',
153
-                        'event_espresso'
154
-                    ),
155
-                    true,
156
-                    ''
157
-                ),
158
-                'PAY_redirect_url'     => new EE_Plain_Text_Field(
159
-                    'PAY_redirect_url',
160
-                    esc_html__("Redirect URL", 'event_espresso'),
161
-                    true
162
-                ),
163
-                'PAY_redirect_args'    => new EE_Serialized_Text_Field(
164
-                    'PAY_redirect_args',
165
-                    esc_html__(
166
-                        "Key-Value POST vars to send along with redirect",
167
-                        'event_espresso'
168
-                    ),
169
-                    true
170
-                ),
171
-            ],
172
-        ];
173
-        $this->_model_relations        = [
174
-            'Transaction'          => new EE_Belongs_To_Relation(),
175
-            'Status'               => new EE_Belongs_To_Relation(),
176
-            'Payment_Method'       => new EE_Belongs_To_Relation(),
177
-            'Registration_Payment' => new EE_Has_Many_Relation(),
178
-            'Registration'         => new EE_HABTM_Relation('Registration_Payment'),
179
-        ];
180
-        $this->_model_chain_to_wp_user = 'Payment_Method';
181
-        $this->_caps_slug              = 'transactions';
182
-        parent::__construct($timezone);
183
-    }
184
-
185
-
186
-    /**
187
-     * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
188
-     * to the payment. This is handy for verifying an IPN hasn't already been processed.
189
-     *
190
-     * @param string $PAY_txn_id_chq_nmbr
191
-     * @return EE_Payment
192
-     */
193
-    public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
194
-    {
195
-        return $this->get_one([['PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr]]);
196
-    }
197
-
198
-
199
-    /**
200
-     *       retrieve  all payments from db for a particular transaction, optionally with
201
-     *      a particular status
202
-     *
203
-     * @access     public
204
-     * @param        $TXN_ID
205
-     * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided,
206
-     *                                  gets payments with any status
207
-     * @return     EE_Payment[]
208
-     */
209
-    public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
210
-    {
211
-        // all payments for a TXN ordered chronologically
212
-        $query_params = [['TXN_ID' => $TXN_ID], 'order_by' => ['PAY_timestamp' => 'ASC']];
213
-        // if provided with a status, search specifically for that status. Otherwise get them all
214
-        if ($status_of_payment) {
215
-            $query_params[0]['STS_ID'] = $status_of_payment;
216
-        }
217
-        // retrieve payments
218
-        return $this->get_all($query_params);
219
-    }
220
-
221
-
222
-    /**
223
-     * Only gets payments which have been approved
224
-     *
225
-     * @param int $TXN_ID
226
-     * @return EE_Payment[]
227
-     */
228
-    public function get_approved_payments_for_transaction($TXN_ID = 0)
229
-    {
230
-        return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
231
-    }
232
-
233
-
234
-    /**
235
-     * retrieve  all payments from db between two dates,
236
-     *
237
-     * @param string $start_date        incoming start date. If empty the beginning of today is used.
238
-     * @param string $end_date          incoming end date. If empty the end of today is used.
239
-     * @param string $format            If you include $start_date or $end_date then you must include the format string
240
-     *                                  for the format your date is in.
241
-     * @param string $timezone          If your range is in a different timezone then the current setting on this
242
-     *                                  WordPress install, then include it here.
243
-     * @return EE_Payment[]
244
-     * @throws EE_Error
245
-     */
246
-    public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
247
-    {
248
-        $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
249
-        // if $start_date or $end date, verify $format is included.
250
-        if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
251
-            throw new EE_Error(
252
-                esc_html__(
253
-                    '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',
254
-                    'event_espresso'
255
-                )
256
-            );
257
-        }
258
-        $now = new DateTime('now');
259
-        // setup timezone objects once
260
-        $modelDateTimeZone  = new DateTimeZone($this->_timezone);
261
-        $passedDateTimeZone = new DateTimeZone($timezone);
262
-        // setup start date
263
-        $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
264
-        EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
265
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
266
-        $start_date = strtotime($start_date);
267
-        // setup end date
268
-        $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
269
-        EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
270
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
271
-        $end_date = strtotime($end_date);
272
-
273
-        // make sure our start date is the lowest value and vice versa
274
-        $start = min($start_date, $end_date);
275
-        $end   = max($start_date, $end_date);
276
-
277
-        // 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.
278
-        $start_date = $this->convert_datetime_for_query(
279
-            'PAY_timestamp',
280
-            date('Y-m-d', $start) . ' 00:00:00',
281
-            'Y-m-d H:i:s',
282
-            $this->get_timezone()
283
-        );
284
-        $end_date   = $this->convert_datetime_for_query(
285
-            'PAY_timestamp',
286
-            date('Y-m-d', $end) . ' 23:59:59',
287
-            'Y-m-d H:i:s',
288
-            $this->get_timezone()
289
-        );
290
-
291
-        return $this->get_all([['PAY_timestamp' => ['>=', $start_date], 'PAY_timestamp*' => ['<=', $end_date]]]);
292
-    }
293
-
294
-    /**
295
-     * methods for EEMI_Payment
296
-     */
297
-    /**
298
-     * returns a string for the approved status
299
-     *
300
-     * @return  string
301
-     */
302
-    public function approved_status()
303
-    {
304
-        return self::status_id_approved;
305
-    }
306
-
307
-
308
-    /**
309
-     * returns a string for the pending status
310
-     *
311
-     * @return  string
312
-     */
313
-    public function pending_status()
314
-    {
315
-        return self::status_id_pending;
316
-    }
317
-
318
-
319
-    /**
320
-     * returns a string for the cancelled status
321
-     *
322
-     * @return  string
323
-     */
324
-    public function cancelled_status()
325
-    {
326
-        return self::status_id_cancelled;
327
-    }
328
-
329
-
330
-    /**
331
-     * returns a string for the failed status
332
-     *
333
-     * @return  string
334
-     */
335
-    public function failed_status()
336
-    {
337
-        return self::status_id_failed;
338
-    }
339
-
340
-
341
-    /**
342
-     * returns a string for the declined status
343
-     *
344
-     * @return  string
345
-     */
346
-    public function declined_status()
347
-    {
348
-        return self::status_id_declined;
349
-    }
12
+	protected static ?EEM_Payment $_instance = null;
13
+
14
+
15
+	/**
16
+	 * Status id in esp_status table that represents an approved payment
17
+	 */
18
+	const status_id_approved = 'PAP';
19
+
20
+
21
+	/**
22
+	 * Status id in esp_status table that represents a pending payment
23
+	 */
24
+	const status_id_pending = 'PPN';
25
+
26
+
27
+	/**
28
+	 * Status id in esp_status table that represents a cancelled payment (eg, the
29
+	 * user went to PayPal, but on the paypal site decided to cancel the payment)
30
+	 */
31
+	const status_id_cancelled = 'PCN';
32
+
33
+
34
+	/**
35
+	 * Status id in esp_status table that represents a payment that was declined by
36
+	 * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
37
+	 */
38
+	const status_id_declined = 'PDC';
39
+
40
+
41
+	/**
42
+	 * Status id in esp_status table that represents a payment that failed for technical reasons.
43
+	 * (Eg, there was some error in communicating with the payment gateway.)
44
+	 */
45
+	const status_id_failed = 'PFL';
46
+
47
+
48
+	/**
49
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
50
+	 *                              any incoming timezone data that gets saved).  Note this just sends the timezone
51
+	 *                              info to the date time model field objects.  Default is NULL (and will be assumed
52
+	 *                              using the set timezone in the 'timezone_string' wp option)
53
+	 * @throws EE_Error
54
+	 * @throws ReflectionException
55
+	 */
56
+	protected function __construct(?string $timezone = '')
57
+	{
58
+		$this->singular_item = esc_html__('Payment', 'event_espresso');
59
+		$this->plural_item   = esc_html__('Payments', 'event_espresso');
60
+
61
+		$this->_tables                 = [
62
+			'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID'),
63
+		];
64
+		$this->_fields                 = [
65
+			'Payment' => [
66
+				'PAY_ID'               => new EE_Primary_Key_Int_Field(
67
+					'PAY_ID',
68
+					esc_html__('Payment ID', 'event_espresso')
69
+				),
70
+				'TXN_ID'               => new EE_Foreign_Key_Int_Field(
71
+					'TXN_ID',
72
+					esc_html__('Transaction ID', 'event_espresso'),
73
+					false,
74
+					0,
75
+					'Transaction'
76
+				),
77
+				'STS_ID'               => new EE_Foreign_Key_String_Field(
78
+					'STS_ID',
79
+					esc_html__('Status ID', 'event_espresso'),
80
+					false,
81
+					EEM_Payment::status_id_failed,
82
+					'Status'
83
+				),
84
+				'PAY_timestamp'        => new EE_Datetime_Field(
85
+					'PAY_timestamp',
86
+					esc_html__(
87
+						'Timestamp of when payment was attempted',
88
+						'event_espresso'
89
+					),
90
+					false,
91
+					EE_Datetime_Field::now,
92
+					$timezone
93
+				),
94
+				'PAY_source'           => new EE_All_Caps_Text_Field(
95
+					'PAY_source',
96
+					esc_html__(
97
+						'User-friendly description of payment',
98
+						'event_espresso'
99
+					),
100
+					false,
101
+					'CART'
102
+				),
103
+				'PAY_amount'           => new EE_Money_Field(
104
+					'PAY_amount',
105
+					esc_html__('Amount Payment should be for', 'event_espresso'),
106
+					false,
107
+					0
108
+				),
109
+				'PMD_ID'               => new EE_Foreign_Key_Int_Field(
110
+					'PMD_ID',
111
+					esc_html__("Payment Method ID", 'event_espresso'),
112
+					false,
113
+					null,
114
+					'Payment_Method'
115
+				),
116
+				'PAY_gateway_response' => new EE_Plain_Text_Field(
117
+					'PAY_gateway_response',
118
+					esc_html__(
119
+						'Response from Gateway about the payment',
120
+						'event_espresso'
121
+					),
122
+					false,
123
+					''
124
+				),
125
+				'PAY_txn_id_chq_nmbr'  => new EE_Plain_Text_Field(
126
+					'PAY_txn_id_chq_nmbr',
127
+					esc_html__(
128
+						'Gateway Transaction ID or Cheque Number',
129
+						'event_espresso'
130
+					),
131
+					true,
132
+					''
133
+				),
134
+				'PAY_po_number'        => new EE_Plain_Text_Field(
135
+					'PAY_po_number',
136
+					esc_html__(
137
+						'Purchase or Sales Number',
138
+						'event_espresso'
139
+					),
140
+					true,
141
+					''
142
+				),
143
+				'PAY_extra_accntng'    => new EE_Simple_HTML_Field(
144
+					'PAY_extra_accntng',
145
+					esc_html__('Extra Account Info', 'event_espresso'),
146
+					true,
147
+					''
148
+				),
149
+				'PAY_details'          => new EE_Serialized_Text_Field(
150
+					'PAY_details',
151
+					esc_html__(
152
+						'Full Gateway response about payment',
153
+						'event_espresso'
154
+					),
155
+					true,
156
+					''
157
+				),
158
+				'PAY_redirect_url'     => new EE_Plain_Text_Field(
159
+					'PAY_redirect_url',
160
+					esc_html__("Redirect URL", 'event_espresso'),
161
+					true
162
+				),
163
+				'PAY_redirect_args'    => new EE_Serialized_Text_Field(
164
+					'PAY_redirect_args',
165
+					esc_html__(
166
+						"Key-Value POST vars to send along with redirect",
167
+						'event_espresso'
168
+					),
169
+					true
170
+				),
171
+			],
172
+		];
173
+		$this->_model_relations        = [
174
+			'Transaction'          => new EE_Belongs_To_Relation(),
175
+			'Status'               => new EE_Belongs_To_Relation(),
176
+			'Payment_Method'       => new EE_Belongs_To_Relation(),
177
+			'Registration_Payment' => new EE_Has_Many_Relation(),
178
+			'Registration'         => new EE_HABTM_Relation('Registration_Payment'),
179
+		];
180
+		$this->_model_chain_to_wp_user = 'Payment_Method';
181
+		$this->_caps_slug              = 'transactions';
182
+		parent::__construct($timezone);
183
+	}
184
+
185
+
186
+	/**
187
+	 * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
188
+	 * to the payment. This is handy for verifying an IPN hasn't already been processed.
189
+	 *
190
+	 * @param string $PAY_txn_id_chq_nmbr
191
+	 * @return EE_Payment
192
+	 */
193
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
194
+	{
195
+		return $this->get_one([['PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr]]);
196
+	}
197
+
198
+
199
+	/**
200
+	 *       retrieve  all payments from db for a particular transaction, optionally with
201
+	 *      a particular status
202
+	 *
203
+	 * @access     public
204
+	 * @param        $TXN_ID
205
+	 * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided,
206
+	 *                                  gets payments with any status
207
+	 * @return     EE_Payment[]
208
+	 */
209
+	public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
210
+	{
211
+		// all payments for a TXN ordered chronologically
212
+		$query_params = [['TXN_ID' => $TXN_ID], 'order_by' => ['PAY_timestamp' => 'ASC']];
213
+		// if provided with a status, search specifically for that status. Otherwise get them all
214
+		if ($status_of_payment) {
215
+			$query_params[0]['STS_ID'] = $status_of_payment;
216
+		}
217
+		// retrieve payments
218
+		return $this->get_all($query_params);
219
+	}
220
+
221
+
222
+	/**
223
+	 * Only gets payments which have been approved
224
+	 *
225
+	 * @param int $TXN_ID
226
+	 * @return EE_Payment[]
227
+	 */
228
+	public function get_approved_payments_for_transaction($TXN_ID = 0)
229
+	{
230
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
231
+	}
232
+
233
+
234
+	/**
235
+	 * retrieve  all payments from db between two dates,
236
+	 *
237
+	 * @param string $start_date        incoming start date. If empty the beginning of today is used.
238
+	 * @param string $end_date          incoming end date. If empty the end of today is used.
239
+	 * @param string $format            If you include $start_date or $end_date then you must include the format string
240
+	 *                                  for the format your date is in.
241
+	 * @param string $timezone          If your range is in a different timezone then the current setting on this
242
+	 *                                  WordPress install, then include it here.
243
+	 * @return EE_Payment[]
244
+	 * @throws EE_Error
245
+	 */
246
+	public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
247
+	{
248
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
249
+		// if $start_date or $end date, verify $format is included.
250
+		if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
251
+			throw new EE_Error(
252
+				esc_html__(
253
+					'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',
254
+					'event_espresso'
255
+				)
256
+			);
257
+		}
258
+		$now = new DateTime('now');
259
+		// setup timezone objects once
260
+		$modelDateTimeZone  = new DateTimeZone($this->_timezone);
261
+		$passedDateTimeZone = new DateTimeZone($timezone);
262
+		// setup start date
263
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
264
+		EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
265
+		$start_date = $start_date->format('Y-m-d') . ' 00:00:00';
266
+		$start_date = strtotime($start_date);
267
+		// setup end date
268
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
269
+		EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
270
+		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
271
+		$end_date = strtotime($end_date);
272
+
273
+		// make sure our start date is the lowest value and vice versa
274
+		$start = min($start_date, $end_date);
275
+		$end   = max($start_date, $end_date);
276
+
277
+		// 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.
278
+		$start_date = $this->convert_datetime_for_query(
279
+			'PAY_timestamp',
280
+			date('Y-m-d', $start) . ' 00:00:00',
281
+			'Y-m-d H:i:s',
282
+			$this->get_timezone()
283
+		);
284
+		$end_date   = $this->convert_datetime_for_query(
285
+			'PAY_timestamp',
286
+			date('Y-m-d', $end) . ' 23:59:59',
287
+			'Y-m-d H:i:s',
288
+			$this->get_timezone()
289
+		);
290
+
291
+		return $this->get_all([['PAY_timestamp' => ['>=', $start_date], 'PAY_timestamp*' => ['<=', $end_date]]]);
292
+	}
293
+
294
+	/**
295
+	 * methods for EEMI_Payment
296
+	 */
297
+	/**
298
+	 * returns a string for the approved status
299
+	 *
300
+	 * @return  string
301
+	 */
302
+	public function approved_status()
303
+	{
304
+		return self::status_id_approved;
305
+	}
306
+
307
+
308
+	/**
309
+	 * returns a string for the pending status
310
+	 *
311
+	 * @return  string
312
+	 */
313
+	public function pending_status()
314
+	{
315
+		return self::status_id_pending;
316
+	}
317
+
318
+
319
+	/**
320
+	 * returns a string for the cancelled status
321
+	 *
322
+	 * @return  string
323
+	 */
324
+	public function cancelled_status()
325
+	{
326
+		return self::status_id_cancelled;
327
+	}
328
+
329
+
330
+	/**
331
+	 * returns a string for the failed status
332
+	 *
333
+	 * @return  string
334
+	 */
335
+	public function failed_status()
336
+	{
337
+		return self::status_id_failed;
338
+	}
339
+
340
+
341
+	/**
342
+	 * returns a string for the declined status
343
+	 *
344
+	 * @return  string
345
+	 */
346
+	public function declined_status()
347
+	{
348
+		return self::status_id_declined;
349
+	}
350 350
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Form_Element.model.php 1 patch
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -26,228 +26,228 @@
 block discarded – undo
26 26
  */
27 27
 class EEM_Form_Element extends EEM_Base
28 28
 {
29
-    protected static ?EEM_Form_Element $_instance = null;
30
-
31
-    private RequestInterface $request;
32
-
33
-    private InputTypes $input_types;
34
-
35
-
36
-    /**
37
-     * EEM_Form_Element constructor.
38
-     *
39
-     * @param FormStatus  $form_status
40
-     * @param InputTypes  $input_types
41
-     * @param string|null $timezone
42
-     * @throws EE_Error
43
-     */
44
-    protected function __construct(FormStatus $form_status, InputTypes $input_types, ?string $timezone = '')
45
-    {
46
-        $this->input_types   = $input_types;
47
-        $this->singular_item = esc_html__('Form Element', 'event_espresso');
48
-        $this->plural_item   = esc_html__('Form Elements', 'event_espresso');
49
-
50
-        $this->_tables = [
51
-            'Form_Element' => new EE_Primary_Table('esp_form_element', 'FIN_UUID'),
52
-        ];
53
-        $this->_fields = [
54
-            'Form_Element' => [
55
-                'FIN_UUID'       => new EE_Primary_Key_String_Field(
56
-                    'FIN_UUID',
57
-                    esc_html__('Form Element UUID (universally unique identifier)', 'event_espresso')
58
-                ),
59
-                'FSC_UUID'       => new EE_Foreign_Key_String_Field(
60
-                    'FSC_UUID',
61
-                    esc_html__('UUID of parent form section this form input belongs to.', 'event_espresso'),
62
-                    false,
63
-                    null,
64
-                    ['Form_Section'],
65
-                    false
66
-                ),
67
-                'FIN_adminOnly'  => new EE_Boolean_Field(
68
-                    'FIN_adminOnly',
69
-                    esc_html__(
70
-                        'Whether or not input is only displayed in the admin. If false, input will appear in public forms',
71
-                        'event_espresso'
72
-                    ),
73
-                    false,
74
-                    false
75
-                ),
76
-                'FIN_attributes' => new EE_JSON_Field(
77
-                    'FIN_attributes',
78
-                    esc_html__(
79
-                        'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.',
80
-                        'event_espresso'
81
-                    ),
82
-                    true,
83
-                    '{}'
84
-                ),
85
-                'FIN_helpText'   => new EE_JSON_Field(
86
-                    'FIN_helpText',
87
-                    esc_html__(
88
-                        'JSON string of properties pertaining to any help text required for an input.',
89
-                        'event_espresso'
90
-                    ),
91
-                    true,
92
-                    '{}'
93
-                ),
94
-                'FIN_label'      => new EE_JSON_Field(
95
-                    'FIN_label',
96
-                    esc_html__(
97
-                        'JSON string of properties pertaining to an element\'s label.',
98
-                        'event_espresso'
99
-                    ),
100
-                    true,
101
-                    '{}'
102
-                ),
103
-                'FIN_mapsTo'     => new EE_Plain_Text_Field(
104
-                    'FIN_mapsTo',
105
-                    esc_html__(
106
-                        'Model and Fields name that this element maps to; ex: Attendee.email',
107
-                        'event_espresso'
108
-                    ),
109
-                    true,
110
-                    null
111
-                ),
112
-                'FIN_options'    => new EE_JSON_Field(
113
-                    'FIN_options',
114
-                    esc_html__(
115
-                        'JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.',
116
-                        'event_espresso'
117
-                    ),
118
-                    true,
119
-                    '[]'
120
-                ),
121
-                'FIN_order'      => new EE_Integer_Field(
122
-                    'FIN_order',
123
-                    esc_html__('Order in which form input appears in a form.', 'event_espresso'),
124
-                    false,
125
-                    0
126
-                ),
127
-                'FIN_required'   => new EE_JSON_Field(
128
-                    'FIN_required',
129
-                    esc_html__(
130
-                        'properties pertaining to an input\'s required status and the validation text to display.',
131
-                        'event_espresso'
132
-                    ),
133
-                    false,
134
-                    false
135
-                ),
136
-                'FIN_status'     => new EE_Enum_Text_Field(
137
-                    'FIN_status',
138
-                    esc_html(
139
-                        sprintf(
140
-                        /* translators: 1 class name */
141
-                            __(
142
-                                'Whether form element is active, archived, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.',
143
-                                'event_espresso'
144
-                            ),
145
-                            'EventEspresso\core\services\form\meta\FormStatus'
146
-                        )
147
-                    ),
148
-                    false,
149
-                    FormStatus::ACTIVE,
150
-                    $form_status->validStatusOptions()
151
-                ),
152
-                'FIN_type'       => new EE_Enum_Text_Field(
153
-                    'FIN_type',
154
-                    esc_html__('Form element type.', 'event_espresso'),
155
-                    false,
156
-                    null,
157
-                    $input_types->validTypeOptions()
158
-                ),
159
-                'FIN_wpUser'     => new EE_WP_User_Field(
160
-                    'FIN_wpUser',
161
-                    esc_html__('ID of the WP User that created this form input.', 'event_espresso'),
162
-                    false
163
-                ),
164
-            ],
165
-        ];
166
-
167
-        $this->_model_relations = [
168
-            'Form_Section' => new EE_Belongs_To_Relation(),
169
-            'WP_User'      => new EE_Belongs_To_Relation(),
170
-        ];
171
-        // this model is generally available for reading
172
-        $this->_cap_restriction_generators = [
173
-            EEM_Base::caps_read       => new EE_Restriction_Generator_Public(),
174
-            EEM_Base::caps_read_admin => new EE_Restriction_Generator_Reg_Form('FIN_applies_to'),
175
-            EEM_Base::caps_edit       => new EE_Restriction_Generator_Reg_Form('FIN_applies_to'),
176
-            EEM_Base::caps_delete     => new EE_Restriction_Generator_Reg_Form('FIN_applies_to'),
177
-        ];
178
-        parent::__construct($timezone);
179
-        $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
180
-    }
181
-
182
-
183
-    /**
184
-     * @param array $query_params
185
-     * @return array
186
-     */
187
-    private function addDefaultWhereConditions(array $query_params): array
188
-    {
189
-        // might need to add a way to identify GQL requests for admin domains
190
-        $admin_request                            = $this->request->isAdmin() || $this->request->isAdminAjax();
191
-        $query_params['default_where_conditions'] = $admin_request
192
-            ? EEM_Base::default_where_conditions_none
193
-            : EEM_Base::default_where_conditions_all;
194
-        return $query_params;
195
-    }
196
-
197
-
198
-    /**
199
-     * form inputs should always be sorted in ascending order via the FIN_order field
200
-     *
201
-     * @param array $query_params
202
-     * @return array
203
-     */
204
-    private function addOrderByQueryParams(array $query_params): array
205
-    {
206
-        $query_params['order_by'] = ['FIN_order' => 'ASC'];
207
-        return $query_params;
208
-    }
209
-
210
-
211
-    /**
212
-     * @param EE_Form_Section   $form_section
213
-     * @param EE_Form_Element[] $all_form_elements
214
-     * @return EE_Form_Element[]
215
-     * @throws EE_Error
216
-     * @throws ReflectionException
217
-     */
218
-    public function filterFormElementsForFormSection(EE_Form_Section $form_section, array $all_form_elements): array
219
-    {
220
-        return array_filter($all_form_elements, $form_section->formElementFilter());
221
-    }
222
-
223
-
224
-    /**
225
-     * @param EE_Form_Section[] $form_sections
226
-     * @return EE_Form_Element[]
227
-     * @throws EE_Error
228
-     * @throws ReflectionException
229
-     */
230
-    public function getAllFormElementsForFormSections(array $form_sections): array
231
-    {
232
-        $FSC_UUIDs = [];
233
-        foreach ($form_sections as $form_section) {
234
-            if ($form_section instanceof EE_Form_Section) {
235
-                $FSC_UUIDs[] = $form_section->UUID();
236
-            }
237
-        }
238
-        $where_params = ['FSC_UUID' => ['IN', $FSC_UUIDs]];
239
-        $query_params = $this->addDefaultWhereConditions([$where_params]);
240
-        $query_params = $this->addOrderByQueryParams($query_params);
241
-        return $this->get_all($query_params);
242
-    }
243
-
244
-
245
-    /**
246
-     * @param bool $constants_only
247
-     * @return array
248
-     */
249
-    public function validTypeOptions(bool $constants_only = false): array
250
-    {
251
-        return $this->input_types->validTypeOptions($constants_only);
252
-    }
29
+	protected static ?EEM_Form_Element $_instance = null;
30
+
31
+	private RequestInterface $request;
32
+
33
+	private InputTypes $input_types;
34
+
35
+
36
+	/**
37
+	 * EEM_Form_Element constructor.
38
+	 *
39
+	 * @param FormStatus  $form_status
40
+	 * @param InputTypes  $input_types
41
+	 * @param string|null $timezone
42
+	 * @throws EE_Error
43
+	 */
44
+	protected function __construct(FormStatus $form_status, InputTypes $input_types, ?string $timezone = '')
45
+	{
46
+		$this->input_types   = $input_types;
47
+		$this->singular_item = esc_html__('Form Element', 'event_espresso');
48
+		$this->plural_item   = esc_html__('Form Elements', 'event_espresso');
49
+
50
+		$this->_tables = [
51
+			'Form_Element' => new EE_Primary_Table('esp_form_element', 'FIN_UUID'),
52
+		];
53
+		$this->_fields = [
54
+			'Form_Element' => [
55
+				'FIN_UUID'       => new EE_Primary_Key_String_Field(
56
+					'FIN_UUID',
57
+					esc_html__('Form Element UUID (universally unique identifier)', 'event_espresso')
58
+				),
59
+				'FSC_UUID'       => new EE_Foreign_Key_String_Field(
60
+					'FSC_UUID',
61
+					esc_html__('UUID of parent form section this form input belongs to.', 'event_espresso'),
62
+					false,
63
+					null,
64
+					['Form_Section'],
65
+					false
66
+				),
67
+				'FIN_adminOnly'  => new EE_Boolean_Field(
68
+					'FIN_adminOnly',
69
+					esc_html__(
70
+						'Whether or not input is only displayed in the admin. If false, input will appear in public forms',
71
+						'event_espresso'
72
+					),
73
+					false,
74
+					false
75
+				),
76
+				'FIN_attributes' => new EE_JSON_Field(
77
+					'FIN_attributes',
78
+					esc_html__(
79
+						'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.',
80
+						'event_espresso'
81
+					),
82
+					true,
83
+					'{}'
84
+				),
85
+				'FIN_helpText'   => new EE_JSON_Field(
86
+					'FIN_helpText',
87
+					esc_html__(
88
+						'JSON string of properties pertaining to any help text required for an input.',
89
+						'event_espresso'
90
+					),
91
+					true,
92
+					'{}'
93
+				),
94
+				'FIN_label'      => new EE_JSON_Field(
95
+					'FIN_label',
96
+					esc_html__(
97
+						'JSON string of properties pertaining to an element\'s label.',
98
+						'event_espresso'
99
+					),
100
+					true,
101
+					'{}'
102
+				),
103
+				'FIN_mapsTo'     => new EE_Plain_Text_Field(
104
+					'FIN_mapsTo',
105
+					esc_html__(
106
+						'Model and Fields name that this element maps to; ex: Attendee.email',
107
+						'event_espresso'
108
+					),
109
+					true,
110
+					null
111
+				),
112
+				'FIN_options'    => new EE_JSON_Field(
113
+					'FIN_options',
114
+					esc_html__(
115
+						'JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.',
116
+						'event_espresso'
117
+					),
118
+					true,
119
+					'[]'
120
+				),
121
+				'FIN_order'      => new EE_Integer_Field(
122
+					'FIN_order',
123
+					esc_html__('Order in which form input appears in a form.', 'event_espresso'),
124
+					false,
125
+					0
126
+				),
127
+				'FIN_required'   => new EE_JSON_Field(
128
+					'FIN_required',
129
+					esc_html__(
130
+						'properties pertaining to an input\'s required status and the validation text to display.',
131
+						'event_espresso'
132
+					),
133
+					false,
134
+					false
135
+				),
136
+				'FIN_status'     => new EE_Enum_Text_Field(
137
+					'FIN_status',
138
+					esc_html(
139
+						sprintf(
140
+						/* translators: 1 class name */
141
+							__(
142
+								'Whether form element is active, archived, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.',
143
+								'event_espresso'
144
+							),
145
+							'EventEspresso\core\services\form\meta\FormStatus'
146
+						)
147
+					),
148
+					false,
149
+					FormStatus::ACTIVE,
150
+					$form_status->validStatusOptions()
151
+				),
152
+				'FIN_type'       => new EE_Enum_Text_Field(
153
+					'FIN_type',
154
+					esc_html__('Form element type.', 'event_espresso'),
155
+					false,
156
+					null,
157
+					$input_types->validTypeOptions()
158
+				),
159
+				'FIN_wpUser'     => new EE_WP_User_Field(
160
+					'FIN_wpUser',
161
+					esc_html__('ID of the WP User that created this form input.', 'event_espresso'),
162
+					false
163
+				),
164
+			],
165
+		];
166
+
167
+		$this->_model_relations = [
168
+			'Form_Section' => new EE_Belongs_To_Relation(),
169
+			'WP_User'      => new EE_Belongs_To_Relation(),
170
+		];
171
+		// this model is generally available for reading
172
+		$this->_cap_restriction_generators = [
173
+			EEM_Base::caps_read       => new EE_Restriction_Generator_Public(),
174
+			EEM_Base::caps_read_admin => new EE_Restriction_Generator_Reg_Form('FIN_applies_to'),
175
+			EEM_Base::caps_edit       => new EE_Restriction_Generator_Reg_Form('FIN_applies_to'),
176
+			EEM_Base::caps_delete     => new EE_Restriction_Generator_Reg_Form('FIN_applies_to'),
177
+		];
178
+		parent::__construct($timezone);
179
+		$this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
180
+	}
181
+
182
+
183
+	/**
184
+	 * @param array $query_params
185
+	 * @return array
186
+	 */
187
+	private function addDefaultWhereConditions(array $query_params): array
188
+	{
189
+		// might need to add a way to identify GQL requests for admin domains
190
+		$admin_request                            = $this->request->isAdmin() || $this->request->isAdminAjax();
191
+		$query_params['default_where_conditions'] = $admin_request
192
+			? EEM_Base::default_where_conditions_none
193
+			: EEM_Base::default_where_conditions_all;
194
+		return $query_params;
195
+	}
196
+
197
+
198
+	/**
199
+	 * form inputs should always be sorted in ascending order via the FIN_order field
200
+	 *
201
+	 * @param array $query_params
202
+	 * @return array
203
+	 */
204
+	private function addOrderByQueryParams(array $query_params): array
205
+	{
206
+		$query_params['order_by'] = ['FIN_order' => 'ASC'];
207
+		return $query_params;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param EE_Form_Section   $form_section
213
+	 * @param EE_Form_Element[] $all_form_elements
214
+	 * @return EE_Form_Element[]
215
+	 * @throws EE_Error
216
+	 * @throws ReflectionException
217
+	 */
218
+	public function filterFormElementsForFormSection(EE_Form_Section $form_section, array $all_form_elements): array
219
+	{
220
+		return array_filter($all_form_elements, $form_section->formElementFilter());
221
+	}
222
+
223
+
224
+	/**
225
+	 * @param EE_Form_Section[] $form_sections
226
+	 * @return EE_Form_Element[]
227
+	 * @throws EE_Error
228
+	 * @throws ReflectionException
229
+	 */
230
+	public function getAllFormElementsForFormSections(array $form_sections): array
231
+	{
232
+		$FSC_UUIDs = [];
233
+		foreach ($form_sections as $form_section) {
234
+			if ($form_section instanceof EE_Form_Section) {
235
+				$FSC_UUIDs[] = $form_section->UUID();
236
+			}
237
+		}
238
+		$where_params = ['FSC_UUID' => ['IN', $FSC_UUIDs]];
239
+		$query_params = $this->addDefaultWhereConditions([$where_params]);
240
+		$query_params = $this->addOrderByQueryParams($query_params);
241
+		return $this->get_all($query_params);
242
+	}
243
+
244
+
245
+	/**
246
+	 * @param bool $constants_only
247
+	 * @return array
248
+	 */
249
+	public function validTypeOptions(bool $constants_only = false): array
250
+	{
251
+		return $this->input_types->validTypeOptions($constants_only);
252
+	}
253 253
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Checkin.model.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -10,67 +10,67 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Checkin extends EEM_Base
12 12
 {
13
-    protected static ?EEM_Checkin $_instance = null;
13
+	protected static ?EEM_Checkin $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * private constructor to prevent direct creation
18
-     *
19
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
20
-     *                              (and any incoming timezone data that gets saved).
21
-     *                              Note this just sends the timezone info to the date time model field objects.
22
-     *                              Default is NULL
23
-     *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
24
-     * @throws EE_Error
25
-     */
26
-    protected function __construct(?string $timezone = '')
27
-    {
28
-        $this->singular_item = esc_html__('Check-In', 'event_espresso');
29
-        $this->plural_item   = esc_html__('Check-Ins', 'event_espresso');
16
+	/**
17
+	 * private constructor to prevent direct creation
18
+	 *
19
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
20
+	 *                              (and any incoming timezone data that gets saved).
21
+	 *                              Note this just sends the timezone info to the date time model field objects.
22
+	 *                              Default is NULL
23
+	 *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
24
+	 * @throws EE_Error
25
+	 */
26
+	protected function __construct(?string $timezone = '')
27
+	{
28
+		$this->singular_item = esc_html__('Check-In', 'event_espresso');
29
+		$this->plural_item   = esc_html__('Check-Ins', 'event_espresso');
30 30
 
31
-        $this->_tables                 = [
32
-            'Checkin' => new EE_Primary_Table('esp_checkin', 'CHK_ID'),
33
-        ];
34
-        $this->_fields                 = [
35
-            'Checkin' => [
36
-                'CHK_ID'        => new EE_Primary_Key_Int_Field(
37
-                    'CHK_ID',
38
-                    esc_html__('Check-in ID', 'event_espresso')
39
-                ),
40
-                'REG_ID'        => new EE_Foreign_Key_Int_Field(
41
-                    'REG_ID',
42
-                    esc_html__('Registration Id', 'event_espresso'),
43
-                    false,
44
-                    0,
45
-                    'Registration'
46
-                ),
47
-                'DTT_ID'        => new EE_Foreign_Key_Int_Field(
48
-                    'DTT_ID',
49
-                    esc_html__('Datetime Id', 'event_espresso'),
50
-                    false,
51
-                    0,
52
-                    'Datetime'
53
-                ),
54
-                'CHK_in'        => new EE_Boolean_Field(
55
-                    'CHK_in',
56
-                    esc_html__('Whether a person has checked in or checked out', 'event_espresso'),
57
-                    false,
58
-                    true
59
-                ),
60
-                'CHK_timestamp' => new EE_Datetime_Field(
61
-                    'CHK_timestamp',
62
-                    esc_html__('When the row was modified', 'event_espresso'),
63
-                    false,
64
-                    EE_Datetime_Field::now,
65
-                    $timezone
66
-                ),
67
-            ],
68
-        ];
69
-        $this->_model_relations        = [
70
-            'Registration' => new EE_Belongs_To_Relation(),
71
-            'Datetime'     => new EE_Belongs_To_Relation(),
72
-        ];
73
-        $this->_model_chain_to_wp_user = 'Registration.Event';
74
-        parent::__construct($timezone);
75
-    }
31
+		$this->_tables                 = [
32
+			'Checkin' => new EE_Primary_Table('esp_checkin', 'CHK_ID'),
33
+		];
34
+		$this->_fields                 = [
35
+			'Checkin' => [
36
+				'CHK_ID'        => new EE_Primary_Key_Int_Field(
37
+					'CHK_ID',
38
+					esc_html__('Check-in ID', 'event_espresso')
39
+				),
40
+				'REG_ID'        => new EE_Foreign_Key_Int_Field(
41
+					'REG_ID',
42
+					esc_html__('Registration Id', 'event_espresso'),
43
+					false,
44
+					0,
45
+					'Registration'
46
+				),
47
+				'DTT_ID'        => new EE_Foreign_Key_Int_Field(
48
+					'DTT_ID',
49
+					esc_html__('Datetime Id', 'event_espresso'),
50
+					false,
51
+					0,
52
+					'Datetime'
53
+				),
54
+				'CHK_in'        => new EE_Boolean_Field(
55
+					'CHK_in',
56
+					esc_html__('Whether a person has checked in or checked out', 'event_espresso'),
57
+					false,
58
+					true
59
+				),
60
+				'CHK_timestamp' => new EE_Datetime_Field(
61
+					'CHK_timestamp',
62
+					esc_html__('When the row was modified', 'event_espresso'),
63
+					false,
64
+					EE_Datetime_Field::now,
65
+					$timezone
66
+				),
67
+			],
68
+		];
69
+		$this->_model_relations        = [
70
+			'Registration' => new EE_Belongs_To_Relation(),
71
+			'Datetime'     => new EE_Belongs_To_Relation(),
72
+		];
73
+		$this->_model_chain_to_wp_user = 'Registration.Event';
74
+		parent::__construct($timezone);
75
+	}
76 76
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Question_Option.model.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -9,83 +9,83 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Question_Option extends EEM_Soft_Delete_Base
11 11
 {
12
-    protected static ?EEM_Question_Option $_instance = null;
12
+	protected static ?EEM_Question_Option $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * @param string|null $timezone
17
-     * @throws EE_Error
18
-     */
19
-    protected function __construct(?string $timezone = '')
20
-    {
21
-        $this->singular_item = esc_html__('Question Option', 'event_espresso');
22
-        $this->plural_item   = esc_html__('Question Options', 'event_espresso');
15
+	/**
16
+	 * @param string|null $timezone
17
+	 * @throws EE_Error
18
+	 */
19
+	protected function __construct(?string $timezone = '')
20
+	{
21
+		$this->singular_item = esc_html__('Question Option', 'event_espresso');
22
+		$this->plural_item   = esc_html__('Question Options', 'event_espresso');
23 23
 
24
-        $this->_tables          = [
25
-            'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'),
26
-        ];
27
-        $this->_fields          = [
28
-            'Question_Option' => [
29
-                'QSO_ID'      => new EE_Primary_Key_Int_Field(
30
-                    'QSO_ID',
31
-                    esc_html__('Question Option ID', 'event_espresso')
32
-                ),
33
-                'QST_ID'      => new EE_Foreign_Key_Int_Field(
34
-                    'QST_ID',
35
-                    esc_html__('Question ID', 'event_espresso'),
36
-                    false,
37
-                    0,
38
-                    'Question'
39
-                ),
40
-                'QSO_deleted' => new EE_Trashed_Flag_Field(
41
-                    'QSO_deleted',
42
-                    esc_html__('Flag indicating Option was trashed', 'event_espresso'),
43
-                    false,
44
-                    false
45
-                ),
46
-                'QSO_desc'    => new EE_Post_Content_Field(
47
-                    'QSO_desc',
48
-                    esc_html__('Question Option Description', 'event_espresso'),
49
-                    false,
50
-                    ''
51
-                ),
52
-                'QSO_order'   => new EE_Integer_Field(
53
-                    'QSO_order',
54
-                    esc_html__('Question Option Order', 'event_espresso'),
55
-                    false,
56
-                    0
57
-                ),
58
-                'QSO_system'  => new EE_Plain_Text_Field(
59
-                    'QSO_system',
60
-                    esc_html__('Internal string ID for question option', 'event_espresso'),
61
-                    true,
62
-                    null
63
-                ),
64
-                'QSO_value'   => new EE_Plain_Text_Field(
65
-                    'QSO_value',
66
-                    esc_html__("Question Option Value", "event_espresso"),
67
-                    false,
68
-                    ''
69
-                ),
70
-            ],
71
-        ];
72
-        $this->_model_relations = [
73
-            'Question' => new EE_Belongs_To_Relation(),
74
-        ];
24
+		$this->_tables          = [
25
+			'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'),
26
+		];
27
+		$this->_fields          = [
28
+			'Question_Option' => [
29
+				'QSO_ID'      => new EE_Primary_Key_Int_Field(
30
+					'QSO_ID',
31
+					esc_html__('Question Option ID', 'event_espresso')
32
+				),
33
+				'QST_ID'      => new EE_Foreign_Key_Int_Field(
34
+					'QST_ID',
35
+					esc_html__('Question ID', 'event_espresso'),
36
+					false,
37
+					0,
38
+					'Question'
39
+				),
40
+				'QSO_deleted' => new EE_Trashed_Flag_Field(
41
+					'QSO_deleted',
42
+					esc_html__('Flag indicating Option was trashed', 'event_espresso'),
43
+					false,
44
+					false
45
+				),
46
+				'QSO_desc'    => new EE_Post_Content_Field(
47
+					'QSO_desc',
48
+					esc_html__('Question Option Description', 'event_espresso'),
49
+					false,
50
+					''
51
+				),
52
+				'QSO_order'   => new EE_Integer_Field(
53
+					'QSO_order',
54
+					esc_html__('Question Option Order', 'event_espresso'),
55
+					false,
56
+					0
57
+				),
58
+				'QSO_system'  => new EE_Plain_Text_Field(
59
+					'QSO_system',
60
+					esc_html__('Internal string ID for question option', 'event_espresso'),
61
+					true,
62
+					null
63
+				),
64
+				'QSO_value'   => new EE_Plain_Text_Field(
65
+					'QSO_value',
66
+					esc_html__("Question Option Value", "event_espresso"),
67
+					false,
68
+					''
69
+				),
70
+			],
71
+		];
72
+		$this->_model_relations = [
73
+			'Question' => new EE_Belongs_To_Relation(),
74
+		];
75 75
 
76
-        $this->_caps_slug              = 'questions';
77
-        $this->_model_chain_to_wp_user = 'Question';
76
+		$this->_caps_slug              = 'questions';
77
+		$this->_model_chain_to_wp_user = 'Question';
78 78
 
79
-        // this model is generally available for reading
80
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
81
-            new EE_Restriction_Generator_Public();
82
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
83
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
84
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
85
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
86
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
87
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
79
+		// this model is generally available for reading
80
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
81
+			new EE_Restriction_Generator_Public();
82
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
83
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
84
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
85
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
86
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
87
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
88 88
 
89
-        parent::__construct($timezone);
90
-    }
89
+		parent::__construct($timezone);
90
+	}
91 91
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Taxonomy.model.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -10,136 +10,136 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Term_Taxonomy extends EEM_Base
12 12
 {
13
-    protected static ?EEM_Term_Taxonomy $_instance = null;
13
+	protected static ?EEM_Term_Taxonomy $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * @param string|null $timezone
18
-     * @throws EE_Error
19
-     */
20
-    protected function __construct(?string $timezone = '')
21
-    {
22
-        $this->singular_item    = esc_html__('Term Taxonomy', 'event_espresso');
23
-        $this->plural_item      = esc_html__('Term Taxonomy', 'event_espresso');
24
-        $this->_tables          = [
25
-            'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
26
-        ];
27
-        $this->_fields          = [
28
-            'Term_Taxonomy' => [
29
-                'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
30
-                    'term_taxonomy_id',
31
-                    esc_html__('Term-Taxonomy ID', 'event_espresso')
32
-                ),
33
-                'term_id'          => new EE_Foreign_Key_Int_Field(
34
-                    'term_id',
35
-                    esc_html__("Term Id", "event_espresso"),
36
-                    false,
37
-                    0,
38
-                    'Term'
39
-                ),
40
-                'taxonomy'         => new EE_Plain_Text_Field(
41
-                    'taxonomy',
42
-                    esc_html__('Taxonomy Name', 'event_espresso'),
43
-                    false,
44
-                    'category'
45
-                ),
46
-                'description'      => new EE_Post_Content_Field(
47
-                    'description',
48
-                    esc_html__("Description of Term", "event_espresso"),
49
-                    false,
50
-                    ''
51
-                ),
52
-                'parent'           => new EE_Integer_Field(
53
-                    'parent',
54
-                    esc_html__("Parent Term ID", "event_espresso"),
55
-                    false,
56
-                    0
57
-                ),
58
-                'term_count'       => new EE_Integer_Field(
59
-                    'count',
60
-                    esc_html__("Count of Objects attached", 'event_espresso'),
61
-                    false,
62
-                    0
63
-                ),
64
-            ],
65
-        ];
66
-        $this->_model_relations = [
67
-            'Term_Relationship' => new EE_Has_Many_Relation(),
68
-            'Term'              => new EE_Belongs_To_Relation(),
69
-        ];
70
-        $cpt_models             = array_keys(EE_Registry::instance()->cpt_models());
71
-        foreach ($cpt_models as $model_name) {
72
-            $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
73
-        }
74
-        $this->_wp_core_model                                           = true;
75
-        $this->_indexes                                                 = [
76
-            'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']),
77
-        ];
78
-        $path_to_tax_model                                              = '';
79
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
80
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
81
-            new EE_Restriction_Generator_Taxonomy_Protected(
82
-                $path_to_tax_model
83
-            );
84
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
85
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
86
-        // add cap restrictions for editing relating to the "ee_edit_*"
87
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
88
-            [
89
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
90
-            ]
91
-        );
92
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
93
-            [
94
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
95
-            ]
96
-        );
97
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
98
-            [
99
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
100
-            ]
101
-        );
102
-        // add cap restrictions for deleting relating to the "ee_deleting_*"
103
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
104
-            [
105
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
106
-            ]
107
-        );
108
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
109
-            [
110
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
111
-            ]
112
-        );
113
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
114
-            [
115
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
116
-            ]
117
-        );
118
-        parent::__construct($timezone);
119
-        add_filter('FHEE__Read__create_model_query_params', ['EEM_Term_Taxonomy', 'rest_api_query_params'], 10, 3);
120
-    }
16
+	/**
17
+	 * @param string|null $timezone
18
+	 * @throws EE_Error
19
+	 */
20
+	protected function __construct(?string $timezone = '')
21
+	{
22
+		$this->singular_item    = esc_html__('Term Taxonomy', 'event_espresso');
23
+		$this->plural_item      = esc_html__('Term Taxonomy', 'event_espresso');
24
+		$this->_tables          = [
25
+			'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
26
+		];
27
+		$this->_fields          = [
28
+			'Term_Taxonomy' => [
29
+				'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
30
+					'term_taxonomy_id',
31
+					esc_html__('Term-Taxonomy ID', 'event_espresso')
32
+				),
33
+				'term_id'          => new EE_Foreign_Key_Int_Field(
34
+					'term_id',
35
+					esc_html__("Term Id", "event_espresso"),
36
+					false,
37
+					0,
38
+					'Term'
39
+				),
40
+				'taxonomy'         => new EE_Plain_Text_Field(
41
+					'taxonomy',
42
+					esc_html__('Taxonomy Name', 'event_espresso'),
43
+					false,
44
+					'category'
45
+				),
46
+				'description'      => new EE_Post_Content_Field(
47
+					'description',
48
+					esc_html__("Description of Term", "event_espresso"),
49
+					false,
50
+					''
51
+				),
52
+				'parent'           => new EE_Integer_Field(
53
+					'parent',
54
+					esc_html__("Parent Term ID", "event_espresso"),
55
+					false,
56
+					0
57
+				),
58
+				'term_count'       => new EE_Integer_Field(
59
+					'count',
60
+					esc_html__("Count of Objects attached", 'event_espresso'),
61
+					false,
62
+					0
63
+				),
64
+			],
65
+		];
66
+		$this->_model_relations = [
67
+			'Term_Relationship' => new EE_Has_Many_Relation(),
68
+			'Term'              => new EE_Belongs_To_Relation(),
69
+		];
70
+		$cpt_models             = array_keys(EE_Registry::instance()->cpt_models());
71
+		foreach ($cpt_models as $model_name) {
72
+			$this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
73
+		}
74
+		$this->_wp_core_model                                           = true;
75
+		$this->_indexes                                                 = [
76
+			'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']),
77
+		];
78
+		$path_to_tax_model                                              = '';
79
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
80
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
81
+			new EE_Restriction_Generator_Taxonomy_Protected(
82
+				$path_to_tax_model
83
+			);
84
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
85
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
86
+		// add cap restrictions for editing relating to the "ee_edit_*"
87
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
88
+			[
89
+				$path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
90
+			]
91
+		);
92
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
93
+			[
94
+				$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
95
+			]
96
+		);
97
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
98
+			[
99
+				$path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
100
+			]
101
+		);
102
+		// add cap restrictions for deleting relating to the "ee_deleting_*"
103
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
104
+			[
105
+				$path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
106
+			]
107
+		);
108
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
109
+			[
110
+				$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
111
+			]
112
+		);
113
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
114
+			[
115
+				$path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
116
+			]
117
+		);
118
+		parent::__construct($timezone);
119
+		add_filter('FHEE__Read__create_model_query_params', ['EEM_Term_Taxonomy', 'rest_api_query_params'], 10, 3);
120
+	}
121 121
 
122 122
 
123
-    /**
124
-     * Makes sure that during REST API queries, we only return term-taxonomies
125
-     * for term taxonomies which should be shown in the rest api
126
-     *
127
-     * @param array    $model_query_params
128
-     * @param array    $querystring_query_params
129
-     * @param EEM_Base $model
130
-     * @return array
131
-     * @throws EE_Error
132
-     */
133
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
134
-    {
135
-        if ($model === EEM_Term_Taxonomy::instance()) {
136
-            $taxonomies = get_taxonomies(['show_in_rest' => true]);
137
-            if (! empty($taxonomies)) {
138
-                $model_query_params[0]['taxonomy'] = ['IN', $taxonomies];
139
-            }
140
-        }
141
-        return $model_query_params;
142
-    }
123
+	/**
124
+	 * Makes sure that during REST API queries, we only return term-taxonomies
125
+	 * for term taxonomies which should be shown in the rest api
126
+	 *
127
+	 * @param array    $model_query_params
128
+	 * @param array    $querystring_query_params
129
+	 * @param EEM_Base $model
130
+	 * @return array
131
+	 * @throws EE_Error
132
+	 */
133
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
134
+	{
135
+		if ($model === EEM_Term_Taxonomy::instance()) {
136
+			$taxonomies = get_taxonomies(['show_in_rest' => true]);
137
+			if (! empty($taxonomies)) {
138
+				$model_query_params[0]['taxonomy'] = ['IN', $taxonomies];
139
+			}
140
+		}
141
+		return $model_query_params;
142
+	}
143 143
 }
144 144
 // End of file EEM_Term_Taxonomy.model.php
145 145
 // Location: /includes/models/EEM_Term_Taxonomy.model.php
Please login to merge, or discard this patch.
core/db_models/EEM_Post_Meta.model.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -17,58 +17,58 @@
 block discarded – undo
17 17
  */
18 18
 class EEM_Post_Meta extends EEM_Base
19 19
 {
20
-    protected static ?EEM_Post_Meta $_instance = null;
20
+	protected static ?EEM_Post_Meta $_instance = null;
21 21
 
22 22
 
23
-    /**
24
-     * @param string|null $timezone
25
-     * @throws EE_Error
26
-     */
27
-    protected function __construct(?string $timezone = '')
28
-    {
29
-        $this->singular_item       = esc_html__('Post Meta', 'event_espresso');
30
-        $this->plural_item         = esc_html__('Post Metas', 'event_espresso');
31
-        $this->_tables             = [
32
-            'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
33
-        ];
34
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
35
-        $this->_fields             = [
36
-            'Post_Meta' => [
37
-                'meta_id'    => new EE_Primary_Key_Int_Field(
38
-                    'meta_id',
39
-                    esc_html__("Meta ID", "event_espresso")
40
-                ),
41
-                'post_id'    => new EE_Foreign_Key_Int_Field(
42
-                    'post_id',
43
-                    esc_html__("Primary Key of Post", "event_espresso"),
44
-                    false,
45
-                    0,
46
-                    $models_this_can_attach_to
47
-                ),
48
-                'meta_key'   => new EE_Plain_Text_Field(
49
-                    'meta_key',
50
-                    esc_html__("Meta Key", "event_espresso"),
51
-                    false,
52
-                    ''
53
-                ),
54
-                'meta_value' => new EE_Maybe_Serialized_Text_Field(
55
-                    'meta_value',
56
-                    esc_html__("Meta Value", "event_espresso"),
57
-                    true
58
-                ),
59
-            ],
60
-        ];
61
-        $this->_model_relations    = [];
62
-        foreach ($models_this_can_attach_to as $model) {
63
-            $this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
64
-        }
65
-        $this->_wp_core_model = true;
66
-        foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
67
-            $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
68
-                'meta_key',
69
-                'meta_value'
70
-            );
71
-        }
72
-        parent::__construct($timezone);
73
-    }
23
+	/**
24
+	 * @param string|null $timezone
25
+	 * @throws EE_Error
26
+	 */
27
+	protected function __construct(?string $timezone = '')
28
+	{
29
+		$this->singular_item       = esc_html__('Post Meta', 'event_espresso');
30
+		$this->plural_item         = esc_html__('Post Metas', 'event_espresso');
31
+		$this->_tables             = [
32
+			'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
33
+		];
34
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
35
+		$this->_fields             = [
36
+			'Post_Meta' => [
37
+				'meta_id'    => new EE_Primary_Key_Int_Field(
38
+					'meta_id',
39
+					esc_html__("Meta ID", "event_espresso")
40
+				),
41
+				'post_id'    => new EE_Foreign_Key_Int_Field(
42
+					'post_id',
43
+					esc_html__("Primary Key of Post", "event_espresso"),
44
+					false,
45
+					0,
46
+					$models_this_can_attach_to
47
+				),
48
+				'meta_key'   => new EE_Plain_Text_Field(
49
+					'meta_key',
50
+					esc_html__("Meta Key", "event_espresso"),
51
+					false,
52
+					''
53
+				),
54
+				'meta_value' => new EE_Maybe_Serialized_Text_Field(
55
+					'meta_value',
56
+					esc_html__("Meta Value", "event_espresso"),
57
+					true
58
+				),
59
+			],
60
+		];
61
+		$this->_model_relations    = [];
62
+		foreach ($models_this_can_attach_to as $model) {
63
+			$this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
64
+		}
65
+		$this->_wp_core_model = true;
66
+		foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
67
+			$this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
68
+				'meta_key',
69
+				'meta_value'
70
+			);
71
+		}
72
+		parent::__construct($timezone);
73
+	}
74 74
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Term.model.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -11,269 +11,269 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Term extends EEM_Base
13 13
 {
14
-    protected static ?EEM_Term $_instance = null;
14
+	protected static ?EEM_Term $_instance = null;
15 15
 
16 16
 
17
-    /**
18
-     * @param string|null $timezone
19
-     * @throws EE_Error
20
-     */
21
-    protected function __construct(?string $timezone = '')
22
-    {
23
-        $this->singular_item                                            = esc_html__('Term', 'event_espresso');
24
-        $this->plural_item                                              = esc_html__('Terms', 'event_espresso');
25
-        $this->_tables                                                  = [
26
-            'Term' => new EE_Primary_Table('terms', 'term_id'),
27
-        ];
28
-        $this->_fields                                                  = [
29
-            'Term' => [
30
-                'term_id'    => new EE_Primary_Key_Int_Field('term_id', esc_html__('Term ID', 'event_espresso')),
31
-                'name'       => new EE_Plain_Text_Field('name', esc_html__('Term Name', 'event_espresso'), false, ''),
32
-                'slug'       => new EE_Slug_Field('slug', esc_html__('Term Slug', 'event_espresso'), false),
33
-                'term_group' => new EE_Integer_Field(
34
-                    'term_group', esc_html__("Term Group", "event_espresso"), false, 0
35
-                ),
36
-            ],
37
-        ];
38
-        $this->_model_relations                                         = [
39
-            'Term_Taxonomy' => new EE_Has_Many_Relation(),
40
-        ];
41
-        $this->_wp_core_model                                           = true;
42
-        $path_to_tax_model                                              = 'Term_Taxonomy';
43
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
45
-            new EE_Restriction_Generator_Taxonomy_Protected(
46
-                $path_to_tax_model
47
-            );
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
50
-        $path_to_tax_model                                              = $path_to_tax_model . '.';
51
-        // add cap restrictions for editing relating to the "ee_edit_*"
52
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
53
-            [
54
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
55
-            ]
56
-        );
57
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
58
-            [
59
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
60
-            ]
61
-        );
62
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
63
-            [
64
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
65
-            ]
66
-        );
67
-        // add cap restrictions for deleting relating to the "ee_deleting_*"
68
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
69
-            [
70
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
71
-            ]
72
-        );
73
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
74
-            [
75
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
76
-            ]
77
-        );
78
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
79
-            [
80
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
81
-            ]
82
-        );
83
-        parent::__construct($timezone);
84
-        add_filter('FHEE__Read__create_model_query_params', ['EEM_Term', 'rest_api_query_params'], 10, 3);
85
-    }
17
+	/**
18
+	 * @param string|null $timezone
19
+	 * @throws EE_Error
20
+	 */
21
+	protected function __construct(?string $timezone = '')
22
+	{
23
+		$this->singular_item                                            = esc_html__('Term', 'event_espresso');
24
+		$this->plural_item                                              = esc_html__('Terms', 'event_espresso');
25
+		$this->_tables                                                  = [
26
+			'Term' => new EE_Primary_Table('terms', 'term_id'),
27
+		];
28
+		$this->_fields                                                  = [
29
+			'Term' => [
30
+				'term_id'    => new EE_Primary_Key_Int_Field('term_id', esc_html__('Term ID', 'event_espresso')),
31
+				'name'       => new EE_Plain_Text_Field('name', esc_html__('Term Name', 'event_espresso'), false, ''),
32
+				'slug'       => new EE_Slug_Field('slug', esc_html__('Term Slug', 'event_espresso'), false),
33
+				'term_group' => new EE_Integer_Field(
34
+					'term_group', esc_html__("Term Group", "event_espresso"), false, 0
35
+				),
36
+			],
37
+		];
38
+		$this->_model_relations                                         = [
39
+			'Term_Taxonomy' => new EE_Has_Many_Relation(),
40
+		];
41
+		$this->_wp_core_model                                           = true;
42
+		$path_to_tax_model                                              = 'Term_Taxonomy';
43
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
45
+			new EE_Restriction_Generator_Taxonomy_Protected(
46
+				$path_to_tax_model
47
+			);
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
50
+		$path_to_tax_model                                              = $path_to_tax_model . '.';
51
+		// add cap restrictions for editing relating to the "ee_edit_*"
52
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
53
+			[
54
+				$path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
55
+			]
56
+		);
57
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
58
+			[
59
+				$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
60
+			]
61
+		);
62
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
63
+			[
64
+				$path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
65
+			]
66
+		);
67
+		// add cap restrictions for deleting relating to the "ee_deleting_*"
68
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
69
+			[
70
+				$path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
71
+			]
72
+		);
73
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
74
+			[
75
+				$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
76
+			]
77
+		);
78
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
79
+			[
80
+				$path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
81
+			]
82
+		);
83
+		parent::__construct($timezone);
84
+		add_filter('FHEE__Read__create_model_query_params', ['EEM_Term', 'rest_api_query_params'], 10, 3);
85
+	}
86 86
 
87 87
 
88
-    /**
89
-     * retrieves a list of all EE event categories
90
-     *
91
-     * @access public
92
-     * @param bool $show_uncategorized
93
-     * @return EE_Base_Class[]
94
-     * @throws EE_Error
95
-     * @throws ReflectionException
96
-     */
97
-    public function get_all_ee_categories($show_uncategorized = false)
98
-    {
99
-        $where_params = [
100
-            'Term_Taxonomy.taxonomy' => 'espresso_event_categories',
101
-            'NOT'                    => ['name' => esc_html__('Uncategorized', 'event_espresso')],
102
-        ];
103
-        if ($show_uncategorized) {
104
-            unset($where_params['NOT']);
105
-        }
106
-        return EEM_Term::instance()->get_all(
107
-            [
108
-                $where_params,
109
-                'order_by' => ['name' => 'ASC'],
110
-            ]
111
-        );
112
-    }
88
+	/**
89
+	 * retrieves a list of all EE event categories
90
+	 *
91
+	 * @access public
92
+	 * @param bool $show_uncategorized
93
+	 * @return EE_Base_Class[]
94
+	 * @throws EE_Error
95
+	 * @throws ReflectionException
96
+	 */
97
+	public function get_all_ee_categories($show_uncategorized = false)
98
+	{
99
+		$where_params = [
100
+			'Term_Taxonomy.taxonomy' => 'espresso_event_categories',
101
+			'NOT'                    => ['name' => esc_html__('Uncategorized', 'event_espresso')],
102
+		];
103
+		if ($show_uncategorized) {
104
+			unset($where_params['NOT']);
105
+		}
106
+		return EEM_Term::instance()->get_all(
107
+			[
108
+				$where_params,
109
+				'order_by' => ['name' => 'ASC'],
110
+			]
111
+		);
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * retrieves a list of all post_tags associated with an EE CPT
117
-     *
118
-     * @access public
119
-     * @param string $post_type
120
-     * @return array
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public function get_all_CPT_post_tags($post_type = '')
125
-    {
126
-        switch ($post_type) {
127
-            case EspressoPostType::EVENTS:
128
-                return $this->get_all_event_post_tags();
115
+	/**
116
+	 * retrieves a list of all post_tags associated with an EE CPT
117
+	 *
118
+	 * @access public
119
+	 * @param string $post_type
120
+	 * @return array
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public function get_all_CPT_post_tags($post_type = '')
125
+	{
126
+		switch ($post_type) {
127
+			case EspressoPostType::EVENTS:
128
+				return $this->get_all_event_post_tags();
129 129
 
130
-            case EspressoPostType::VENUES:
131
-                return $this->get_all_venue_post_tags();
130
+			case EspressoPostType::VENUES:
131
+				return $this->get_all_venue_post_tags();
132 132
 
133
-            default:
134
-                $event_tags = $this->get_all_event_post_tags();
135
-                $venue_tags = $this->get_all_venue_post_tags();
136
-                return array_merge($event_tags, $venue_tags);
137
-        }
138
-    }
133
+			default:
134
+				$event_tags = $this->get_all_event_post_tags();
135
+				$venue_tags = $this->get_all_venue_post_tags();
136
+				return array_merge($event_tags, $venue_tags);
137
+		}
138
+	}
139 139
 
140 140
 
141
-    /**
142
-     * returns an EE_Term object for the given tag
143
-     * if it has been utilized by any EE_Events or EE_Venues
144
-     *
145
-     * @param string $tag
146
-     * @return EE_Term|null
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    public function get_post_tag_for_event_or_venue($tag)
151
-    {
152
-        $post_tag_results = $this->get_all_wpdb_results(
153
-            [
154
-                [
155
-                    'slug'                   => $tag,
156
-                    'Term_Taxonomy.taxonomy' => 'post_tag',
157
-                    'OR'                     => [
158
-                        'Term_Taxonomy.Venue.post_type' => EspressoPostType::VENUES,
159
-                        'Term_Taxonomy.Event.post_type' => EspressoPostType::EVENTS,
160
-                    ],
161
-                ],
162
-                'default_where_conditions' => 'none',
163
-                'extra_selects'            => [
164
-                    'event_post_type' => ['Term_Taxonomy___Event_CPT.post_type', '%s'],
165
-                    'venue_post_type' => ['Term_Taxonomy___Venue_CPT.post_type', '%s'],
166
-                ],
167
-                'group_by'                 => [
168
-                    'event_post_type',
169
-                    'venue_post_type',
170
-                ],
171
-                'limit'                    => 2,
172
-            ]
173
-        );
174
-        if (! $post_tag_results) {
175
-            return null;
176
-        }
141
+	/**
142
+	 * returns an EE_Term object for the given tag
143
+	 * if it has been utilized by any EE_Events or EE_Venues
144
+	 *
145
+	 * @param string $tag
146
+	 * @return EE_Term|null
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	public function get_post_tag_for_event_or_venue($tag)
151
+	{
152
+		$post_tag_results = $this->get_all_wpdb_results(
153
+			[
154
+				[
155
+					'slug'                   => $tag,
156
+					'Term_Taxonomy.taxonomy' => 'post_tag',
157
+					'OR'                     => [
158
+						'Term_Taxonomy.Venue.post_type' => EspressoPostType::VENUES,
159
+						'Term_Taxonomy.Event.post_type' => EspressoPostType::EVENTS,
160
+					],
161
+				],
162
+				'default_where_conditions' => 'none',
163
+				'extra_selects'            => [
164
+					'event_post_type' => ['Term_Taxonomy___Event_CPT.post_type', '%s'],
165
+					'venue_post_type' => ['Term_Taxonomy___Venue_CPT.post_type', '%s'],
166
+				],
167
+				'group_by'                 => [
168
+					'event_post_type',
169
+					'venue_post_type',
170
+				],
171
+				'limit'                    => 2,
172
+			]
173
+		);
174
+		if (! $post_tag_results) {
175
+			return null;
176
+		}
177 177
 
178
-        $post_types = [];
179
-        foreach ((array) $post_tag_results as $row) {
180
-            if ($row['event_post_type'] === EspressoPostType::EVENTS) {
181
-                $post_types[] = EEM_Event::instance()->post_type();
182
-            } elseif ($row['venue_post_type'] === EspressoPostType::VENUES) {
183
-                $post_types[] = EEM_Venue::instance()->post_type();
184
-            }
185
-        }
186
-        $post_tag_row = reset($post_tag_results);
187
-        $post_tag     = $this->instantiate_class_from_array_or_object($post_tag_row);
188
-        if (! $post_tag instanceof EE_Term) {
189
-            return null;
190
-        }
178
+		$post_types = [];
179
+		foreach ((array) $post_tag_results as $row) {
180
+			if ($row['event_post_type'] === EspressoPostType::EVENTS) {
181
+				$post_types[] = EEM_Event::instance()->post_type();
182
+			} elseif ($row['venue_post_type'] === EspressoPostType::VENUES) {
183
+				$post_types[] = EEM_Venue::instance()->post_type();
184
+			}
185
+		}
186
+		$post_tag_row = reset($post_tag_results);
187
+		$post_tag     = $this->instantiate_class_from_array_or_object($post_tag_row);
188
+		if (! $post_tag instanceof EE_Term) {
189
+			return null;
190
+		}
191 191
 
192
-        if ($post_tag->post_type === null) {
193
-            $post_tag->post_type = [];
194
-        }
195
-        $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types));
196
-        return $post_tag;
197
-    }
192
+		if ($post_tag->post_type === null) {
193
+			$post_tag->post_type = [];
194
+		}
195
+		$post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types));
196
+		return $post_tag;
197
+	}
198 198
 
199 199
 
200
-    /**
201
-     * get_all_event_post_tags
202
-     *
203
-     * @return EE_Base_Class[]
204
-     * @throws EE_Error
205
-     * @throws ReflectionException
206
-     */
207
-    public function get_all_event_post_tags()
208
-    {
209
-        $post_tags = EEM_Term::instance()->get_all(
210
-            [
211
-                [
212
-                    'Term_Taxonomy.taxonomy'        => 'post_tag',
213
-                    'Term_Taxonomy.Event.post_type' => EspressoPostType::EVENTS,
214
-                ],
215
-                'order_by'   => ['name' => 'ASC'],
216
-                'force_join' => ['Term_Taxonomy.Event'],
217
-            ]
218
-        );
219
-        foreach ($post_tags as $key => $post_tag) {
220
-            if (! isset($post_tags[ $key ]->post_type)) {
221
-                $post_tags[ $key ]->post_type = [];
222
-            }
223
-            $post_tags[ $key ]->post_type[] = EspressoPostType::EVENTS;
224
-        }
225
-        return $post_tags;
226
-    }
200
+	/**
201
+	 * get_all_event_post_tags
202
+	 *
203
+	 * @return EE_Base_Class[]
204
+	 * @throws EE_Error
205
+	 * @throws ReflectionException
206
+	 */
207
+	public function get_all_event_post_tags()
208
+	{
209
+		$post_tags = EEM_Term::instance()->get_all(
210
+			[
211
+				[
212
+					'Term_Taxonomy.taxonomy'        => 'post_tag',
213
+					'Term_Taxonomy.Event.post_type' => EspressoPostType::EVENTS,
214
+				],
215
+				'order_by'   => ['name' => 'ASC'],
216
+				'force_join' => ['Term_Taxonomy.Event'],
217
+			]
218
+		);
219
+		foreach ($post_tags as $key => $post_tag) {
220
+			if (! isset($post_tags[ $key ]->post_type)) {
221
+				$post_tags[ $key ]->post_type = [];
222
+			}
223
+			$post_tags[ $key ]->post_type[] = EspressoPostType::EVENTS;
224
+		}
225
+		return $post_tags;
226
+	}
227 227
 
228 228
 
229
-    /**
230
-     * get_all_venue_post_tags
231
-     *
232
-     * @return EE_Base_Class[]
233
-     * @throws EE_Error
234
-     * @throws ReflectionException
235
-     */
236
-    public function get_all_venue_post_tags()
237
-    {
238
-        $post_tags = EEM_Term::instance()->get_all(
239
-            [
240
-                [
241
-                    'Term_Taxonomy.taxonomy'        => 'post_tag',
242
-                    'Term_Taxonomy.Venue.post_type' => EspressoPostType::VENUES,
243
-                ],
244
-                'order_by'   => ['name' => 'ASC'],
245
-                'force_join' => ['Term_Taxonomy'],
246
-            ]
247
-        );
248
-        foreach ($post_tags as $key => $post_tag) {
249
-            if (! isset($post_tags[ $key ]->post_type)) {
250
-                $post_tags[ $key ]->post_type = [];
251
-            }
252
-            $post_tags[ $key ]->post_type[] = EspressoPostType::VENUES;
253
-        }
254
-        return $post_tags;
255
-    }
229
+	/**
230
+	 * get_all_venue_post_tags
231
+	 *
232
+	 * @return EE_Base_Class[]
233
+	 * @throws EE_Error
234
+	 * @throws ReflectionException
235
+	 */
236
+	public function get_all_venue_post_tags()
237
+	{
238
+		$post_tags = EEM_Term::instance()->get_all(
239
+			[
240
+				[
241
+					'Term_Taxonomy.taxonomy'        => 'post_tag',
242
+					'Term_Taxonomy.Venue.post_type' => EspressoPostType::VENUES,
243
+				],
244
+				'order_by'   => ['name' => 'ASC'],
245
+				'force_join' => ['Term_Taxonomy'],
246
+			]
247
+		);
248
+		foreach ($post_tags as $key => $post_tag) {
249
+			if (! isset($post_tags[ $key ]->post_type)) {
250
+				$post_tags[ $key ]->post_type = [];
251
+			}
252
+			$post_tags[ $key ]->post_type[] = EspressoPostType::VENUES;
253
+		}
254
+		return $post_tags;
255
+	}
256 256
 
257 257
 
258
-    /**
259
-     * Makes sure that during REST API queries, we only return terms
260
-     * for term taxonomies which should be shown in the rest api
261
-     *
262
-     * @param array    $model_query_params
263
-     * @param array    $querystring_query_params
264
-     * @param EEM_Base $model
265
-     * @return array
266
-     * @throws EE_Error
267
-     * @throws ReflectionException
268
-     */
269
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
270
-    {
271
-        if ($model === EEM_Term::instance()) {
272
-            $taxonomies = get_taxonomies(['show_in_rest' => true]);
273
-            if (! empty($taxonomies)) {
274
-                $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies];
275
-            }
276
-        }
277
-        return $model_query_params;
278
-    }
258
+	/**
259
+	 * Makes sure that during REST API queries, we only return terms
260
+	 * for term taxonomies which should be shown in the rest api
261
+	 *
262
+	 * @param array    $model_query_params
263
+	 * @param array    $querystring_query_params
264
+	 * @param EEM_Base $model
265
+	 * @return array
266
+	 * @throws EE_Error
267
+	 * @throws ReflectionException
268
+	 */
269
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
270
+	{
271
+		if ($model === EEM_Term::instance()) {
272
+			$taxonomies = get_taxonomies(['show_in_rest' => true]);
273
+			if (! empty($taxonomies)) {
274
+				$model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies];
275
+			}
276
+		}
277
+		return $model_query_params;
278
+	}
279 279
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -40,44 +40,44 @@  discard block
 block discarded – undo
40 40
         ];
41 41
         $this->_wp_core_model                                           = true;
42 42
         $path_to_tax_model                                              = 'Term_Taxonomy';
43
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
43
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       = new EE_Restriction_Generator_Public();
44
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
45 45
             new EE_Restriction_Generator_Taxonomy_Protected(
46 46
                 $path_to_tax_model
47 47
             );
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
50
-        $path_to_tax_model                                              = $path_to_tax_model . '.';
48
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       = false;
49
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     = false;
50
+        $path_to_tax_model                                              = $path_to_tax_model.'.';
51 51
         // add cap restrictions for editing relating to the "ee_edit_*"
52
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
52
+        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
53 53
             [
54
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
54
+                $path_to_tax_model.'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
55 55
             ]
56 56
         );
57
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
57
+        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
58 58
             [
59
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
59
+                $path_to_tax_model.'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
60 60
             ]
61 61
         );
62
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
62
+        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
63 63
             [
64
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
64
+                $path_to_tax_model.'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
65 65
             ]
66 66
         );
67 67
         // add cap restrictions for deleting relating to the "ee_deleting_*"
68
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
68
+        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
69 69
             [
70
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
70
+                $path_to_tax_model.'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
71 71
             ]
72 72
         );
73
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
73
+        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
74 74
             [
75
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
75
+                $path_to_tax_model.'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
76 76
             ]
77 77
         );
78
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
78
+        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
79 79
             [
80
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
80
+                $path_to_tax_model.'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
81 81
             ]
82 82
         );
83 83
         parent::__construct($timezone);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
                 'limit'                    => 2,
172 172
             ]
173 173
         );
174
-        if (! $post_tag_results) {
174
+        if ( ! $post_tag_results) {
175 175
             return null;
176 176
         }
177 177
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         }
186 186
         $post_tag_row = reset($post_tag_results);
187 187
         $post_tag     = $this->instantiate_class_from_array_or_object($post_tag_row);
188
-        if (! $post_tag instanceof EE_Term) {
188
+        if ( ! $post_tag instanceof EE_Term) {
189 189
             return null;
190 190
         }
191 191
 
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
             ]
218 218
         );
219 219
         foreach ($post_tags as $key => $post_tag) {
220
-            if (! isset($post_tags[ $key ]->post_type)) {
221
-                $post_tags[ $key ]->post_type = [];
220
+            if ( ! isset($post_tags[$key]->post_type)) {
221
+                $post_tags[$key]->post_type = [];
222 222
             }
223
-            $post_tags[ $key ]->post_type[] = EspressoPostType::EVENTS;
223
+            $post_tags[$key]->post_type[] = EspressoPostType::EVENTS;
224 224
         }
225 225
         return $post_tags;
226 226
     }
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
             ]
247 247
         );
248 248
         foreach ($post_tags as $key => $post_tag) {
249
-            if (! isset($post_tags[ $key ]->post_type)) {
250
-                $post_tags[ $key ]->post_type = [];
249
+            if ( ! isset($post_tags[$key]->post_type)) {
250
+                $post_tags[$key]->post_type = [];
251 251
             }
252
-            $post_tags[ $key ]->post_type[] = EspressoPostType::VENUES;
252
+            $post_tags[$key]->post_type[] = EspressoPostType::VENUES;
253 253
         }
254 254
         return $post_tags;
255 255
     }
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     {
271 271
         if ($model === EEM_Term::instance()) {
272 272
             $taxonomies = get_taxonomies(['show_in_rest' => true]);
273
-            if (! empty($taxonomies)) {
273
+            if ( ! empty($taxonomies)) {
274 274
                 $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies];
275 275
             }
276 276
         }
Please login to merge, or discard this patch.