Completed
Branch BUG/reg-status-change-recursio... (fbd515)
by
unknown
09:28 queued 36s
created
core/db_models/EEM_Attendee.model.php 1 patch
Indentation   +418 added lines, -418 removed lines patch added patch discarded remove patch
@@ -12,430 +12,430 @@
 block discarded – undo
12 12
 class EEM_Attendee extends EEM_CPT_Base
13 13
 {
14 14
 
15
-    // private instance of the Attendee object
16
-    protected static $_instance = null;
15
+	// private instance of the Attendee object
16
+	protected static $_instance = null;
17 17
 
18
-    /**
19
-     * QST_system for questions are strings not integers now,
20
-     * so these constants are deprecated.
21
-     * Please instead use the EEM_Attendee::system_question_* constants
22
-     *
23
-     * @deprecated
24
-     */
25
-    const fname_question_id = 1;
18
+	/**
19
+	 * QST_system for questions are strings not integers now,
20
+	 * so these constants are deprecated.
21
+	 * Please instead use the EEM_Attendee::system_question_* constants
22
+	 *
23
+	 * @deprecated
24
+	 */
25
+	const fname_question_id = 1;
26 26
 
27
-    /**
28
-     * @deprecated
29
-     */
30
-    const lname_question_id = 2;
27
+	/**
28
+	 * @deprecated
29
+	 */
30
+	const lname_question_id = 2;
31 31
 
32 32
 
33
-    /**
34
-     * @deprecated
35
-     */
36
-    const email_question_id = 3;
33
+	/**
34
+	 * @deprecated
35
+	 */
36
+	const email_question_id = 3;
37 37
 
38 38
 
39
-    /**
40
-     * @deprecated
41
-     */
42
-    const address_question_id = 4;
39
+	/**
40
+	 * @deprecated
41
+	 */
42
+	const address_question_id = 4;
43 43
 
44 44
 
45
-    /**
46
-     * @deprecated
47
-     */
48
-    const address2_question_id = 5;
49
-
50
-
51
-    /**
52
-     * @deprecated
53
-     */
54
-    const city_question_id = 6;
55
-
56
-
57
-    /**
58
-     * @deprecated
59
-     */
60
-    const state_question_id = 7;
61
-
62
-
63
-    /**
64
-     * @deprecated
65
-     */
66
-    const country_question_id = 8;
67
-
68
-
69
-    /**
70
-     * @deprecated
71
-     */
72
-    const zip_question_id = 9;
73
-
74
-
75
-    /**
76
-     * @deprecated
77
-     */
78
-    const phone_question_id = 10;
79
-
80
-    /**
81
-     * When looking for questions that correspond to attendee fields,
82
-     * look for the question with this QST_system value.
83
-     * These replace the old constants like EEM_Attendee::*_question_id
84
-     */
85
-    const system_question_fname = 'fname';
86
-
87
-    const system_question_lname = 'lname';
88
-
89
-    const system_question_email = 'email';
90
-
91
-    const system_question_address = 'address';
92
-
93
-    const system_question_address2 = 'address2';
94
-
95
-    const system_question_city = 'city';
96
-
97
-    const system_question_state = 'state';
98
-
99
-    const system_question_country = 'country';
100
-
101
-    const system_question_zip = 'zip';
102
-
103
-    const system_question_phone = 'phone';
104
-
105
-    /**
106
-     * Keys are all the EEM_Attendee::system_question_* constants, which are
107
-     * also all the values of QST_system in the questions table, and values
108
-     * are their corresponding Attendee field names
109
-     *
110
-     * @var array
111
-     */
112
-    protected $_system_question_to_attendee_field_name = array(
113
-        EEM_Attendee::system_question_fname    => 'ATT_fname',
114
-        EEM_Attendee::system_question_lname    => 'ATT_lname',
115
-        EEM_Attendee::system_question_email    => 'ATT_email',
116
-        EEM_Attendee::system_question_address  => 'ATT_address',
117
-        EEM_Attendee::system_question_address2 => 'ATT_address2',
118
-        EEM_Attendee::system_question_city     => 'ATT_city',
119
-        EEM_Attendee::system_question_state    => 'STA_ID',
120
-        EEM_Attendee::system_question_country  => 'CNT_ISO',
121
-        EEM_Attendee::system_question_zip      => 'ATT_zip',
122
-        EEM_Attendee::system_question_phone    => 'ATT_phone',
123
-    );
124
-
125
-
126
-
127
-    /**
128
-     * EEM_Attendee constructor.
129
-     *
130
-     * @param null              $timezone
131
-     * @param ModelFieldFactory $model_field_factory
132
-     * @throws EE_Error
133
-     * @throws InvalidArgumentException
134
-     */
135
-    protected function __construct($timezone = null, ModelFieldFactory $model_field_factory)
136
-    {
137
-        $this->singular_item = esc_html__('Attendee', 'event_espresso');
138
-        $this->plural_item = esc_html__('Attendees', 'event_espresso');
139
-        $this->_tables = array(
140
-            'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
141
-            'Attendee_Meta' => new EE_Secondary_Table(
142
-                'esp_attendee_meta',
143
-                'ATTM_ID',
144
-                'ATT_ID'
145
-            ),
146
-        );
147
-        $this->_fields = array(
148
-            'Attendee_CPT'  => array(
149
-                'ATT_ID'        => $model_field_factory->createPrimaryKeyIntField(
150
-                    'ID',
151
-                    esc_html__('Attendee ID', 'event_espresso')
152
-                ),
153
-                'ATT_full_name' => $model_field_factory->createPlainTextField(
154
-                    'post_title',
155
-                    esc_html__('Attendee Full Name', 'event_espresso'),
156
-                    false,
157
-                    esc_html__('Unknown', 'event_espresso')
158
-                ),
159
-                'ATT_bio'       => $model_field_factory->createPostContentField(
160
-                    'post_content',
161
-                    esc_html__('Attendee Biography', 'event_espresso'),
162
-                    false,
163
-                    esc_html__('No Biography Provided', 'event_espresso')
164
-                ),
165
-                'ATT_slug'      => $model_field_factory->createSlugField(
166
-                    'post_name',
167
-                    esc_html__('Attendee URL Slug', 'event_espresso')
168
-                ),
169
-                'ATT_created'   => $model_field_factory->createDatetimeField(
170
-                    'post_date',
171
-                    esc_html__('Time Attendee Created', 'event_espresso')
172
-                ),
173
-                'ATT_short_bio' => $model_field_factory->createSimpleHtmlField(
174
-                    'post_excerpt',
175
-                    esc_html__('Attendee Short Biography', 'event_espresso'),
176
-                    true,
177
-                    esc_html__('No Biography Provided', 'event_espresso')
178
-                ),
179
-                'ATT_modified'  => $model_field_factory->createDatetimeField(
180
-                    'post_modified',
181
-                    esc_html__('Time Attendee Last Modified', 'event_espresso')
182
-                ),
183
-                'ATT_author'    => $model_field_factory->createWpUserField(
184
-                    'post_author',
185
-                    esc_html__('Creator ID of the first Event attended', 'event_espresso'),
186
-                    false
187
-                ),
188
-                'ATT_parent'    => $model_field_factory->createDbOnlyIntField(
189
-                    'post_parent',
190
-                    esc_html__('Parent Attendee (unused)', 'event_espresso'),
191
-                    false,
192
-                    0
193
-                ),
194
-                'post_type'     => $model_field_factory->createWpPostTypeField('espresso_attendees'),
195
-                'status'        => $model_field_factory->createWpPostStatusField(
196
-                    'post_status',
197
-                    esc_html__('Attendee Status', 'event_espresso'),
198
-                    false,
199
-                    'publish'
200
-                ),
201
-                'password' => new EE_Password_Field(
202
-                    'post_password',
203
-                    __('Password', 'event_espresso'),
204
-                    false,
205
-                    '',
206
-                    array(
207
-                        'ATT_bio',
208
-                        'ATT_short_bio',
209
-                        'ATT_address',
210
-                        'ATT_address2',
211
-                        'ATT_city',
212
-                        'STA_ID',
213
-                        'CNT_ISO',
214
-                        'ATT_zip',
215
-                        'ATT_email',
216
-                        'ATT_phone'
217
-                    )
218
-                )
219
-            ),
220
-            'Attendee_Meta' => array(
221
-                'ATTM_ID'      => $model_field_factory->createDbOnlyIntField(
222
-                    'ATTM_ID',
223
-                    esc_html__('Attendee Meta Row ID', 'event_espresso'),
224
-                    false
225
-                ),
226
-                'ATT_ID_fk'    => $model_field_factory->createDbOnlyIntField(
227
-                    'ATT_ID',
228
-                    esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'),
229
-                    false
230
-                ),
231
-                'ATT_fname'    => $model_field_factory->createPlainTextField(
232
-                    'ATT_fname',
233
-                    esc_html__('First Name', 'event_espresso')
234
-                ),
235
-                'ATT_lname'    => $model_field_factory->createPlainTextField(
236
-                    'ATT_lname',
237
-                    esc_html__('Last Name', 'event_espresso')
238
-                ),
239
-                'ATT_address'  => $model_field_factory->createPlainTextField(
240
-                    'ATT_address',
241
-                    esc_html__('Address Part 1', 'event_espresso')
242
-                ),
243
-                'ATT_address2' => $model_field_factory->createPlainTextField(
244
-                    'ATT_address2',
245
-                    esc_html__('Address Part 2', 'event_espresso')
246
-                ),
247
-                'ATT_city'     => $model_field_factory->createPlainTextField(
248
-                    'ATT_city',
249
-                    esc_html__('City', 'event_espresso')
250
-                ),
251
-                'STA_ID'       => $model_field_factory->createForeignKeyIntField(
252
-                    'STA_ID',
253
-                    esc_html__('State', 'event_espresso'),
254
-                    true,
255
-                    0,
256
-                    'State'
257
-                ),
258
-                'CNT_ISO'      => $model_field_factory->createForeignKeyStringField(
259
-                    'CNT_ISO',
260
-                    esc_html__('Country', 'event_espresso'),
261
-                    true,
262
-                    '',
263
-                    'Country'
264
-                ),
265
-                'ATT_zip'      => $model_field_factory->createPlainTextField(
266
-                    'ATT_zip',
267
-                    esc_html__('ZIP/Postal Code', 'event_espresso')
268
-                ),
269
-                'ATT_email'    => $model_field_factory->createEmailField(
270
-                    'ATT_email',
271
-                    esc_html__('Email Address', 'event_espresso')
272
-                ),
273
-                'ATT_phone'    => $model_field_factory->createPlainTextField(
274
-                    'ATT_phone',
275
-                    esc_html__('Phone', 'event_espresso')
276
-                ),
277
-            ),
278
-        );
279
-        $this->_model_relations = array(
280
-            'Registration'      => new EE_Has_Many_Relation(),
281
-            'State'             => new EE_Belongs_To_Relation(),
282
-            'Country'           => new EE_Belongs_To_Relation(),
283
-            'Event'             => new EE_HABTM_Relation('Registration', false),
284
-            'WP_User'           => new EE_Belongs_To_Relation(),
285
-            'Message'           => new EE_Has_Many_Any_Relation(false),
286
-            // allow deletion of attendees even if they have messages in the queue for them.
287
-            'Term_Relationship' => new EE_Has_Many_Relation(),
288
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
289
-        );
290
-        $this->_caps_slug = 'contacts';
291
-        $this->model_chain_to_password = '';
292
-        parent::__construct($timezone);
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * Gets the name of the field on the attendee model corresponding to the system question string
299
-     * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
300
-     *
301
-     * @param string $system_question_string
302
-     * @return string|null if not found
303
-     */
304
-    public function get_attendee_field_for_system_question($system_question_string)
305
-    {
306
-        return isset($this->_system_question_to_attendee_field_name[ $system_question_string ])
307
-            ? $this->_system_question_to_attendee_field_name[ $system_question_string ]
308
-            : null;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
315
-     *
316
-     * @return array
317
-     */
318
-    public function system_question_to_attendee_field_mapping()
319
-    {
320
-        return $this->_system_question_to_attendee_field_name;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Gets all the attendees for a transaction (by using the esp_registration as a join table)
327
-     *
328
-     * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
329
-     * @return EE_Attendee[]|EE_Base_Class[]
330
-     * @throws EE_Error
331
-     */
332
-    public function get_attendees_for_transaction($transaction_id_or_obj)
333
-    {
334
-        return $this->get_all(
335
-            array(
336
-                array(
337
-                    'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
338
-                        ? $transaction_id_or_obj->ID()
339
-                        : $transaction_id_or_obj,
340
-                ),
341
-            )
342
-        );
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * retrieve  a single attendee from db via their ID
349
-     *
350
-     * @param $ATT_ID
351
-     * @return mixed array on success, FALSE on fail
352
-     * @deprecated
353
-     */
354
-    public function get_attendee_by_ID($ATT_ID = false)
355
-    {
356
-        // retrieve a particular EE_Attendee
357
-        return $this->get_one_by_ID($ATT_ID);
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * retrieve  a single attendee from db via their ID
364
-     *
365
-     * @param array $where_cols_n_values
366
-     * @return mixed array on success, FALSE on fail
367
-     * @throws EE_Error
368
-     */
369
-    public function get_attendee($where_cols_n_values = array())
370
-    {
371
-        if (empty($where_cols_n_values)) {
372
-            return false;
373
-        }
374
-        $attendee = $this->get_all(array($where_cols_n_values));
375
-        if (! empty($attendee)) {
376
-            return array_shift($attendee);
377
-        }
378
-        return false;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * Search for an existing Attendee record in the DB
385
-     *
386
-     * @param array $where_cols_n_values
387
-     * @return bool|mixed
388
-     * @throws EE_Error
389
-     */
390
-    public function find_existing_attendee($where_cols_n_values = null)
391
-    {
392
-        // search by combo of first and last names plus the email address
393
-        $attendee_data_keys = array(
394
-            'ATT_fname' => $this->_ATT_fname,
395
-            'ATT_lname' => $this->_ATT_lname,
396
-            'ATT_email' => $this->_ATT_email,
397
-        );
398
-        // no search params means attendee object already exists.
399
-        $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values)
400
-            ? $where_cols_n_values
401
-            : $attendee_data_keys;
402
-        $valid_data = true;
403
-        // check for required values
404
-        $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
405
-            ? $valid_data
406
-            : false;
407
-        $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
408
-            ? $valid_data
409
-            : false;
410
-        $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
411
-            ? $valid_data
412
-            : false;
413
-        if ($valid_data) {
414
-            $attendee = $this->get_attendee($where_cols_n_values);
415
-            if ($attendee instanceof EE_Attendee) {
416
-                return $attendee;
417
-            }
418
-        }
419
-        return false;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Takes an incoming array of EE_Registration ids
426
-     * and sends back a list of corresponding non duplicate EE_Attendee objects.
427
-     *
428
-     * @since  4.3.0
429
-     * @param  array $ids array of EE_Registration ids
430
-     * @return EE_Attendee[]|EE_Base_Class[]
431
-     * @throws EE_Error
432
-     */
433
-    public function get_array_of_contacts_from_reg_ids($ids)
434
-    {
435
-        $ids = (array) $ids;
436
-        $_where = array(
437
-            'Registration.REG_ID' => array('in', $ids),
438
-        );
439
-        return $this->get_all(array($_where));
440
-    }
45
+	/**
46
+	 * @deprecated
47
+	 */
48
+	const address2_question_id = 5;
49
+
50
+
51
+	/**
52
+	 * @deprecated
53
+	 */
54
+	const city_question_id = 6;
55
+
56
+
57
+	/**
58
+	 * @deprecated
59
+	 */
60
+	const state_question_id = 7;
61
+
62
+
63
+	/**
64
+	 * @deprecated
65
+	 */
66
+	const country_question_id = 8;
67
+
68
+
69
+	/**
70
+	 * @deprecated
71
+	 */
72
+	const zip_question_id = 9;
73
+
74
+
75
+	/**
76
+	 * @deprecated
77
+	 */
78
+	const phone_question_id = 10;
79
+
80
+	/**
81
+	 * When looking for questions that correspond to attendee fields,
82
+	 * look for the question with this QST_system value.
83
+	 * These replace the old constants like EEM_Attendee::*_question_id
84
+	 */
85
+	const system_question_fname = 'fname';
86
+
87
+	const system_question_lname = 'lname';
88
+
89
+	const system_question_email = 'email';
90
+
91
+	const system_question_address = 'address';
92
+
93
+	const system_question_address2 = 'address2';
94
+
95
+	const system_question_city = 'city';
96
+
97
+	const system_question_state = 'state';
98
+
99
+	const system_question_country = 'country';
100
+
101
+	const system_question_zip = 'zip';
102
+
103
+	const system_question_phone = 'phone';
104
+
105
+	/**
106
+	 * Keys are all the EEM_Attendee::system_question_* constants, which are
107
+	 * also all the values of QST_system in the questions table, and values
108
+	 * are their corresponding Attendee field names
109
+	 *
110
+	 * @var array
111
+	 */
112
+	protected $_system_question_to_attendee_field_name = array(
113
+		EEM_Attendee::system_question_fname    => 'ATT_fname',
114
+		EEM_Attendee::system_question_lname    => 'ATT_lname',
115
+		EEM_Attendee::system_question_email    => 'ATT_email',
116
+		EEM_Attendee::system_question_address  => 'ATT_address',
117
+		EEM_Attendee::system_question_address2 => 'ATT_address2',
118
+		EEM_Attendee::system_question_city     => 'ATT_city',
119
+		EEM_Attendee::system_question_state    => 'STA_ID',
120
+		EEM_Attendee::system_question_country  => 'CNT_ISO',
121
+		EEM_Attendee::system_question_zip      => 'ATT_zip',
122
+		EEM_Attendee::system_question_phone    => 'ATT_phone',
123
+	);
124
+
125
+
126
+
127
+	/**
128
+	 * EEM_Attendee constructor.
129
+	 *
130
+	 * @param null              $timezone
131
+	 * @param ModelFieldFactory $model_field_factory
132
+	 * @throws EE_Error
133
+	 * @throws InvalidArgumentException
134
+	 */
135
+	protected function __construct($timezone = null, ModelFieldFactory $model_field_factory)
136
+	{
137
+		$this->singular_item = esc_html__('Attendee', 'event_espresso');
138
+		$this->plural_item = esc_html__('Attendees', 'event_espresso');
139
+		$this->_tables = array(
140
+			'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
141
+			'Attendee_Meta' => new EE_Secondary_Table(
142
+				'esp_attendee_meta',
143
+				'ATTM_ID',
144
+				'ATT_ID'
145
+			),
146
+		);
147
+		$this->_fields = array(
148
+			'Attendee_CPT'  => array(
149
+				'ATT_ID'        => $model_field_factory->createPrimaryKeyIntField(
150
+					'ID',
151
+					esc_html__('Attendee ID', 'event_espresso')
152
+				),
153
+				'ATT_full_name' => $model_field_factory->createPlainTextField(
154
+					'post_title',
155
+					esc_html__('Attendee Full Name', 'event_espresso'),
156
+					false,
157
+					esc_html__('Unknown', 'event_espresso')
158
+				),
159
+				'ATT_bio'       => $model_field_factory->createPostContentField(
160
+					'post_content',
161
+					esc_html__('Attendee Biography', 'event_espresso'),
162
+					false,
163
+					esc_html__('No Biography Provided', 'event_espresso')
164
+				),
165
+				'ATT_slug'      => $model_field_factory->createSlugField(
166
+					'post_name',
167
+					esc_html__('Attendee URL Slug', 'event_espresso')
168
+				),
169
+				'ATT_created'   => $model_field_factory->createDatetimeField(
170
+					'post_date',
171
+					esc_html__('Time Attendee Created', 'event_espresso')
172
+				),
173
+				'ATT_short_bio' => $model_field_factory->createSimpleHtmlField(
174
+					'post_excerpt',
175
+					esc_html__('Attendee Short Biography', 'event_espresso'),
176
+					true,
177
+					esc_html__('No Biography Provided', 'event_espresso')
178
+				),
179
+				'ATT_modified'  => $model_field_factory->createDatetimeField(
180
+					'post_modified',
181
+					esc_html__('Time Attendee Last Modified', 'event_espresso')
182
+				),
183
+				'ATT_author'    => $model_field_factory->createWpUserField(
184
+					'post_author',
185
+					esc_html__('Creator ID of the first Event attended', 'event_espresso'),
186
+					false
187
+				),
188
+				'ATT_parent'    => $model_field_factory->createDbOnlyIntField(
189
+					'post_parent',
190
+					esc_html__('Parent Attendee (unused)', 'event_espresso'),
191
+					false,
192
+					0
193
+				),
194
+				'post_type'     => $model_field_factory->createWpPostTypeField('espresso_attendees'),
195
+				'status'        => $model_field_factory->createWpPostStatusField(
196
+					'post_status',
197
+					esc_html__('Attendee Status', 'event_espresso'),
198
+					false,
199
+					'publish'
200
+				),
201
+				'password' => new EE_Password_Field(
202
+					'post_password',
203
+					__('Password', 'event_espresso'),
204
+					false,
205
+					'',
206
+					array(
207
+						'ATT_bio',
208
+						'ATT_short_bio',
209
+						'ATT_address',
210
+						'ATT_address2',
211
+						'ATT_city',
212
+						'STA_ID',
213
+						'CNT_ISO',
214
+						'ATT_zip',
215
+						'ATT_email',
216
+						'ATT_phone'
217
+					)
218
+				)
219
+			),
220
+			'Attendee_Meta' => array(
221
+				'ATTM_ID'      => $model_field_factory->createDbOnlyIntField(
222
+					'ATTM_ID',
223
+					esc_html__('Attendee Meta Row ID', 'event_espresso'),
224
+					false
225
+				),
226
+				'ATT_ID_fk'    => $model_field_factory->createDbOnlyIntField(
227
+					'ATT_ID',
228
+					esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'),
229
+					false
230
+				),
231
+				'ATT_fname'    => $model_field_factory->createPlainTextField(
232
+					'ATT_fname',
233
+					esc_html__('First Name', 'event_espresso')
234
+				),
235
+				'ATT_lname'    => $model_field_factory->createPlainTextField(
236
+					'ATT_lname',
237
+					esc_html__('Last Name', 'event_espresso')
238
+				),
239
+				'ATT_address'  => $model_field_factory->createPlainTextField(
240
+					'ATT_address',
241
+					esc_html__('Address Part 1', 'event_espresso')
242
+				),
243
+				'ATT_address2' => $model_field_factory->createPlainTextField(
244
+					'ATT_address2',
245
+					esc_html__('Address Part 2', 'event_espresso')
246
+				),
247
+				'ATT_city'     => $model_field_factory->createPlainTextField(
248
+					'ATT_city',
249
+					esc_html__('City', 'event_espresso')
250
+				),
251
+				'STA_ID'       => $model_field_factory->createForeignKeyIntField(
252
+					'STA_ID',
253
+					esc_html__('State', 'event_espresso'),
254
+					true,
255
+					0,
256
+					'State'
257
+				),
258
+				'CNT_ISO'      => $model_field_factory->createForeignKeyStringField(
259
+					'CNT_ISO',
260
+					esc_html__('Country', 'event_espresso'),
261
+					true,
262
+					'',
263
+					'Country'
264
+				),
265
+				'ATT_zip'      => $model_field_factory->createPlainTextField(
266
+					'ATT_zip',
267
+					esc_html__('ZIP/Postal Code', 'event_espresso')
268
+				),
269
+				'ATT_email'    => $model_field_factory->createEmailField(
270
+					'ATT_email',
271
+					esc_html__('Email Address', 'event_espresso')
272
+				),
273
+				'ATT_phone'    => $model_field_factory->createPlainTextField(
274
+					'ATT_phone',
275
+					esc_html__('Phone', 'event_espresso')
276
+				),
277
+			),
278
+		);
279
+		$this->_model_relations = array(
280
+			'Registration'      => new EE_Has_Many_Relation(),
281
+			'State'             => new EE_Belongs_To_Relation(),
282
+			'Country'           => new EE_Belongs_To_Relation(),
283
+			'Event'             => new EE_HABTM_Relation('Registration', false),
284
+			'WP_User'           => new EE_Belongs_To_Relation(),
285
+			'Message'           => new EE_Has_Many_Any_Relation(false),
286
+			// allow deletion of attendees even if they have messages in the queue for them.
287
+			'Term_Relationship' => new EE_Has_Many_Relation(),
288
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
289
+		);
290
+		$this->_caps_slug = 'contacts';
291
+		$this->model_chain_to_password = '';
292
+		parent::__construct($timezone);
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * Gets the name of the field on the attendee model corresponding to the system question string
299
+	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
300
+	 *
301
+	 * @param string $system_question_string
302
+	 * @return string|null if not found
303
+	 */
304
+	public function get_attendee_field_for_system_question($system_question_string)
305
+	{
306
+		return isset($this->_system_question_to_attendee_field_name[ $system_question_string ])
307
+			? $this->_system_question_to_attendee_field_name[ $system_question_string ]
308
+			: null;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
315
+	 *
316
+	 * @return array
317
+	 */
318
+	public function system_question_to_attendee_field_mapping()
319
+	{
320
+		return $this->_system_question_to_attendee_field_name;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
327
+	 *
328
+	 * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
329
+	 * @return EE_Attendee[]|EE_Base_Class[]
330
+	 * @throws EE_Error
331
+	 */
332
+	public function get_attendees_for_transaction($transaction_id_or_obj)
333
+	{
334
+		return $this->get_all(
335
+			array(
336
+				array(
337
+					'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
338
+						? $transaction_id_or_obj->ID()
339
+						: $transaction_id_or_obj,
340
+				),
341
+			)
342
+		);
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * retrieve  a single attendee from db via their ID
349
+	 *
350
+	 * @param $ATT_ID
351
+	 * @return mixed array on success, FALSE on fail
352
+	 * @deprecated
353
+	 */
354
+	public function get_attendee_by_ID($ATT_ID = false)
355
+	{
356
+		// retrieve a particular EE_Attendee
357
+		return $this->get_one_by_ID($ATT_ID);
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * retrieve  a single attendee from db via their ID
364
+	 *
365
+	 * @param array $where_cols_n_values
366
+	 * @return mixed array on success, FALSE on fail
367
+	 * @throws EE_Error
368
+	 */
369
+	public function get_attendee($where_cols_n_values = array())
370
+	{
371
+		if (empty($where_cols_n_values)) {
372
+			return false;
373
+		}
374
+		$attendee = $this->get_all(array($where_cols_n_values));
375
+		if (! empty($attendee)) {
376
+			return array_shift($attendee);
377
+		}
378
+		return false;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * Search for an existing Attendee record in the DB
385
+	 *
386
+	 * @param array $where_cols_n_values
387
+	 * @return bool|mixed
388
+	 * @throws EE_Error
389
+	 */
390
+	public function find_existing_attendee($where_cols_n_values = null)
391
+	{
392
+		// search by combo of first and last names plus the email address
393
+		$attendee_data_keys = array(
394
+			'ATT_fname' => $this->_ATT_fname,
395
+			'ATT_lname' => $this->_ATT_lname,
396
+			'ATT_email' => $this->_ATT_email,
397
+		);
398
+		// no search params means attendee object already exists.
399
+		$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values)
400
+			? $where_cols_n_values
401
+			: $attendee_data_keys;
402
+		$valid_data = true;
403
+		// check for required values
404
+		$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
405
+			? $valid_data
406
+			: false;
407
+		$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
408
+			? $valid_data
409
+			: false;
410
+		$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
411
+			? $valid_data
412
+			: false;
413
+		if ($valid_data) {
414
+			$attendee = $this->get_attendee($where_cols_n_values);
415
+			if ($attendee instanceof EE_Attendee) {
416
+				return $attendee;
417
+			}
418
+		}
419
+		return false;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Takes an incoming array of EE_Registration ids
426
+	 * and sends back a list of corresponding non duplicate EE_Attendee objects.
427
+	 *
428
+	 * @since  4.3.0
429
+	 * @param  array $ids array of EE_Registration ids
430
+	 * @return EE_Attendee[]|EE_Base_Class[]
431
+	 * @throws EE_Error
432
+	 */
433
+	public function get_array_of_contacts_from_reg_ids($ids)
434
+	{
435
+		$ids = (array) $ids;
436
+		$_where = array(
437
+			'Registration.REG_ID' => array('in', $ids),
438
+		);
439
+		return $this->get_all(array($_where));
440
+	}
441 441
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime_Ticket.model.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,41 +12,41 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    // private instance of the EEM_Datetime_Ticket object
16
-    protected static $_instance = null;
15
+	// private instance of the EEM_Datetime_Ticket object
16
+	protected static $_instance = null;
17 17
 
18
-    /**
19
-     *      private constructor to prevent direct creation
20
-     *      @Constructor
21
-     *      @access private
22
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
-     *      @return void
24
-     */
25
-    protected function __construct($timezone)
26
-    {
27
-        $this->singular_item = __('Datetime Ticket', 'event_espresso');
28
-        $this->plural_item = __('Datetime Tickets', 'event_espresso');
18
+	/**
19
+	 *      private constructor to prevent direct creation
20
+	 *      @Constructor
21
+	 *      @access private
22
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
+	 *      @return void
24
+	 */
25
+	protected function __construct($timezone)
26
+	{
27
+		$this->singular_item = __('Datetime Ticket', 'event_espresso');
28
+		$this->plural_item = __('Datetime Tickets', 'event_espresso');
29 29
 
30
-        $this->_tables = array(
31
-            'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID')
32
-        );
33
-        $this->_fields = array(
34
-            'Datetime_Ticket'=>array(
35
-                'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')),
36
-                'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'),
37
-                'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket')
38
-            ));
39
-        $this->_model_relations = array(
40
-            'Ticket'=>new EE_Belongs_To_Relation(),
41
-            'Datetime'=>new EE_Belongs_To_Relation()
42
-        );
43
-        // this model is generally available for reading
44
-        $path_to_event = 'Datetime.Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
-        $this->model_chain_to_password = $path_to_event;
50
-        parent::__construct($timezone);
51
-    }
30
+		$this->_tables = array(
31
+			'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID')
32
+		);
33
+		$this->_fields = array(
34
+			'Datetime_Ticket'=>array(
35
+				'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')),
36
+				'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'),
37
+				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket')
38
+			));
39
+		$this->_model_relations = array(
40
+			'Ticket'=>new EE_Belongs_To_Relation(),
41
+			'Datetime'=>new EE_Belongs_To_Relation()
42
+		);
43
+		// this model is generally available for reading
44
+		$path_to_event = 'Datetime.Event';
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
+		$this->model_chain_to_password = $path_to_event;
50
+		parent::__construct($timezone);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@
 block discarded – undo
42 42
         );
43 43
         // this model is generally available for reading
44 44
         $path_to_event = 'Datetime.Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49 49
         $this->model_chain_to_password = $path_to_event;
50 50
         parent::__construct($timezone);
51 51
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Relationship.model.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -9,233 +9,233 @@
 block discarded – undo
9 9
 class EEM_Term_Relationship extends EEM_Base
10 10
 {
11 11
 
12
-    // private instance of the Attendee object
13
-    protected static $_instance = null;
14
-
15
-
16
-
17
-    /**
18
-     * EEM_Term_Relationship constructor.
19
-     *
20
-     * @param string $timezone
21
-     */
22
-    protected function __construct($timezone = null)
23
-    {
24
-        $this->singular_item = __('Term Relationship', 'event_espresso');
25
-        $this->plural_item = __('Term Relationships', 'event_espresso');
26
-        $this->_tables = array(
27
-            'Term_Relationship' => new EE_Primary_Table('term_relationships'),
28
-        );
29
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
30
-        $this->_fields = array(
31
-            'Term_Relationship' => array(
32
-                'object_id'        => new EE_Foreign_Key_Int_Field(
33
-                    'object_id',
34
-                    __('Object(Post) ID', 'event_espresso'),
35
-                    false,
36
-                    0,
37
-                    $models_this_can_attach_to
38
-                ),
39
-                'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
40
-                    'term_taxonomy_id',
41
-                    __(
42
-                        'Term (in context of a taxonomy) ID',
43
-                        'event_espresso'
44
-                    ),
45
-                    false,
46
-                    0,
47
-                    'Term_Taxonomy'
48
-                ),
49
-                'term_order'       => new EE_Integer_Field(
50
-                    'term_order',
51
-                    __('Term Order', 'event_espresso'),
52
-                    false,
53
-                    0
54
-                ),
55
-            ),
56
-        );
57
-        $this->_model_relations = array(
58
-            'Term_Taxonomy' => new EE_Belongs_To_Relation(),
59
-        );
60
-        foreach ($models_this_can_attach_to as $model_name) {
61
-            $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
62
-        }
63
-        $this->_wp_core_model = true;
64
-        $this->_indexes = array(
65
-            'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
66
-        );
67
-        $path_to_event_model = 'Event';
68
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
69
-            $path_to_event_model
70
-        );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
-            new EE_Restriction_Generator_Event_Related_Protected(
73
-                $path_to_event_model
74
-            );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
76
-            $path_to_event_model
77
-        );
78
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] =
79
-            new EE_Restriction_Generator_Event_Related_Protected(
80
-                $path_to_event_model,
81
-                EEM_Base::caps_edit
82
-            );
83
-        $path_to_tax_model = 'Term_Taxonomy.';
84
-        // add cap restrictions for editing term relations to the "ee_assign_*"
85
-        // and for deleting term relations too
86
-        $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
87
-        foreach ($cap_contexts_affected as $cap_context_affected) {
88
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
89
-                new EE_Default_Where_Conditions(
90
-                    array(
91
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
92
-                            '!=',
93
-                            'espresso_event_categories',
94
-                        ),
95
-                    )
96
-                );
97
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
98
-                new EE_Default_Where_Conditions(
99
-                    array(
100
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
101
-                            '!=',
102
-                            'espresso_venue_categories',
103
-                        ),
104
-                    )
105
-                );
106
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
107
-                array(
108
-                    $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
109
-                )
110
-            );
111
-        }
112
-        parent::__construct($timezone);
113
-        add_filter(
114
-            'FHEE__Read__create_model_query_params',
115
-            array('EEM_Term_Relationship', 'rest_api_query_params'),
116
-            10,
117
-            3
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * Makes sure all term-taxonomy counts are correct
124
-     *
125
-     * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
126
-     * @global wpdb $wpdb
127
-     * @return int the number of rows affected
128
-     * @throws EE_Error
129
-     */
130
-    public function update_term_taxonomy_counts($term_taxonomy_id = null)
131
-    {
132
-        // because this uses a subquery and sometimes assigning to column to be another column's
133
-        // value, we just write the SQL directly.
134
-        global $wpdb;
135
-
136
-        $query = "
12
+	// private instance of the Attendee object
13
+	protected static $_instance = null;
14
+
15
+
16
+
17
+	/**
18
+	 * EEM_Term_Relationship constructor.
19
+	 *
20
+	 * @param string $timezone
21
+	 */
22
+	protected function __construct($timezone = null)
23
+	{
24
+		$this->singular_item = __('Term Relationship', 'event_espresso');
25
+		$this->plural_item = __('Term Relationships', 'event_espresso');
26
+		$this->_tables = array(
27
+			'Term_Relationship' => new EE_Primary_Table('term_relationships'),
28
+		);
29
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
30
+		$this->_fields = array(
31
+			'Term_Relationship' => array(
32
+				'object_id'        => new EE_Foreign_Key_Int_Field(
33
+					'object_id',
34
+					__('Object(Post) ID', 'event_espresso'),
35
+					false,
36
+					0,
37
+					$models_this_can_attach_to
38
+				),
39
+				'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
40
+					'term_taxonomy_id',
41
+					__(
42
+						'Term (in context of a taxonomy) ID',
43
+						'event_espresso'
44
+					),
45
+					false,
46
+					0,
47
+					'Term_Taxonomy'
48
+				),
49
+				'term_order'       => new EE_Integer_Field(
50
+					'term_order',
51
+					__('Term Order', 'event_espresso'),
52
+					false,
53
+					0
54
+				),
55
+			),
56
+		);
57
+		$this->_model_relations = array(
58
+			'Term_Taxonomy' => new EE_Belongs_To_Relation(),
59
+		);
60
+		foreach ($models_this_can_attach_to as $model_name) {
61
+			$this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
62
+		}
63
+		$this->_wp_core_model = true;
64
+		$this->_indexes = array(
65
+			'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
66
+		);
67
+		$path_to_event_model = 'Event';
68
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
69
+			$path_to_event_model
70
+		);
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
+			new EE_Restriction_Generator_Event_Related_Protected(
73
+				$path_to_event_model
74
+			);
75
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
76
+			$path_to_event_model
77
+		);
78
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] =
79
+			new EE_Restriction_Generator_Event_Related_Protected(
80
+				$path_to_event_model,
81
+				EEM_Base::caps_edit
82
+			);
83
+		$path_to_tax_model = 'Term_Taxonomy.';
84
+		// add cap restrictions for editing term relations to the "ee_assign_*"
85
+		// and for deleting term relations too
86
+		$cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
87
+		foreach ($cap_contexts_affected as $cap_context_affected) {
88
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
89
+				new EE_Default_Where_Conditions(
90
+					array(
91
+						$path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
92
+							'!=',
93
+							'espresso_event_categories',
94
+						),
95
+					)
96
+				);
97
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
98
+				new EE_Default_Where_Conditions(
99
+					array(
100
+						$path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
101
+							'!=',
102
+							'espresso_venue_categories',
103
+						),
104
+					)
105
+				);
106
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
107
+				array(
108
+					$path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
109
+				)
110
+			);
111
+		}
112
+		parent::__construct($timezone);
113
+		add_filter(
114
+			'FHEE__Read__create_model_query_params',
115
+			array('EEM_Term_Relationship', 'rest_api_query_params'),
116
+			10,
117
+			3
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * Makes sure all term-taxonomy counts are correct
124
+	 *
125
+	 * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
126
+	 * @global wpdb $wpdb
127
+	 * @return int the number of rows affected
128
+	 * @throws EE_Error
129
+	 */
130
+	public function update_term_taxonomy_counts($term_taxonomy_id = null)
131
+	{
132
+		// because this uses a subquery and sometimes assigning to column to be another column's
133
+		// value, we just write the SQL directly.
134
+		global $wpdb;
135
+
136
+		$query = "
137 137
                 UPDATE {$wpdb->term_taxonomy} AS tt 
138 138
                 SET count = (
139 139
                     select count(*) as proper_count from {$wpdb->term_relationships} AS tr 
140 140
                     WHERE tt.term_taxonomy_id = tr.term_taxonomy_id
141 141
                 )";
142 142
 
143
-        if ($term_taxonomy_id) {
144
-            $query .= ' WHERE tt.term_taxonomy_id = %d';
145
-            $query = $wpdb->prepare(
146
-                $query,
147
-                $term_taxonomy_id
148
-            );
149
-        }
150
-        $rows_affected = $this->_do_wpdb_query(
151
-            'query',
152
-            array(
153
-                $query,
154
-            )
155
-        );
156
-        return $rows_affected;
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
163
-     * inserting
164
-     *
165
-     * @param array $field_n_values @see EEM_Base::insert
166
-     * @return boolean
167
-     */
168
-    public function insert($field_n_values)
169
-    {
170
-        $return = parent::insert($field_n_values);
171
-        if (isset($field_n_values['term_taxonomy_id'])) {
172
-            $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
173
-        }
174
-        return $return;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
-     * all ok
182
-     *
183
-     * @param array   $fields_n_values         see EEM_Base::update
184
-     * @param array   $query_params            @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
185
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
186
-     *                                         in this model's entity map according to $fields_n_values that match
187
-     *                                         $query_params. This obviously has some overhead, so you can disable it
188
-     *                                         by setting this to FALSE, but be aware that model objects being used
189
-     *                                         could get out-of-sync with the database
190
-     * @return int
191
-     */
192
-    public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
193
-    {
194
-        $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
195
-        if ($count) {
196
-            $this->update_term_taxonomy_counts();
197
-        }
198
-        return $count;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * Overrides parent so that after running this, we also double-check
205
-     * the term taxonomy counts are up-to-date
206
-     *
207
-     * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
208
-     * @param boolean $allow_blocking
209
-     * @return int @see EEM_Base::delete
210
-     */
211
-    public function delete($query_params, $allow_blocking = true)
212
-    {
213
-        $count = parent::delete($query_params, $allow_blocking);
214
-        if ($count) {
215
-            $this->update_term_taxonomy_counts();
216
-        }
217
-        return $count;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Makes sure that during REST API queries, we only return term relationships
224
-     * for term taxonomies which should be shown in the rest api
225
-     *
226
-     * @param array    $model_query_params
227
-     * @param array    $querystring_query_params
228
-     * @param EEM_Base $model
229
-     * @return array
230
-     */
231
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
232
-    {
233
-        if ($model === EEM_Term_Relationship::instance()) {
234
-            $taxonomies = get_taxonomies(array('show_in_rest' => true));
235
-            if (! empty($taxonomies)) {
236
-                $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237
-            }
238
-        }
239
-        return $model_query_params;
240
-    }
143
+		if ($term_taxonomy_id) {
144
+			$query .= ' WHERE tt.term_taxonomy_id = %d';
145
+			$query = $wpdb->prepare(
146
+				$query,
147
+				$term_taxonomy_id
148
+			);
149
+		}
150
+		$rows_affected = $this->_do_wpdb_query(
151
+			'query',
152
+			array(
153
+				$query,
154
+			)
155
+		);
156
+		return $rows_affected;
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
163
+	 * inserting
164
+	 *
165
+	 * @param array $field_n_values @see EEM_Base::insert
166
+	 * @return boolean
167
+	 */
168
+	public function insert($field_n_values)
169
+	{
170
+		$return = parent::insert($field_n_values);
171
+		if (isset($field_n_values['term_taxonomy_id'])) {
172
+			$this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
173
+		}
174
+		return $return;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
+	 * all ok
182
+	 *
183
+	 * @param array   $fields_n_values         see EEM_Base::update
184
+	 * @param array   $query_params            @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
185
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
186
+	 *                                         in this model's entity map according to $fields_n_values that match
187
+	 *                                         $query_params. This obviously has some overhead, so you can disable it
188
+	 *                                         by setting this to FALSE, but be aware that model objects being used
189
+	 *                                         could get out-of-sync with the database
190
+	 * @return int
191
+	 */
192
+	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
193
+	{
194
+		$count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
195
+		if ($count) {
196
+			$this->update_term_taxonomy_counts();
197
+		}
198
+		return $count;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * Overrides parent so that after running this, we also double-check
205
+	 * the term taxonomy counts are up-to-date
206
+	 *
207
+	 * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
208
+	 * @param boolean $allow_blocking
209
+	 * @return int @see EEM_Base::delete
210
+	 */
211
+	public function delete($query_params, $allow_blocking = true)
212
+	{
213
+		$count = parent::delete($query_params, $allow_blocking);
214
+		if ($count) {
215
+			$this->update_term_taxonomy_counts();
216
+		}
217
+		return $count;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Makes sure that during REST API queries, we only return term relationships
224
+	 * for term taxonomies which should be shown in the rest api
225
+	 *
226
+	 * @param array    $model_query_params
227
+	 * @param array    $querystring_query_params
228
+	 * @param EEM_Base $model
229
+	 * @return array
230
+	 */
231
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
232
+	{
233
+		if ($model === EEM_Term_Relationship::instance()) {
234
+			$taxonomies = get_taxonomies(array('show_in_rest' => true));
235
+			if (! empty($taxonomies)) {
236
+				$model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237
+			}
238
+		}
239
+		return $model_query_params;
240
+	}
241 241
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -58,24 +58,24 @@  discard block
 block discarded – undo
58 58
             'Term_Taxonomy' => new EE_Belongs_To_Relation(),
59 59
         );
60 60
         foreach ($models_this_can_attach_to as $model_name) {
61
-            $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
61
+            $this->_model_relations[$model_name] = new EE_Belongs_To_Relation();
62 62
         }
63 63
         $this->_wp_core_model = true;
64 64
         $this->_indexes = array(
65 65
             'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
66 66
         );
67 67
         $path_to_event_model = 'Event';
68
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
68
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public(
69 69
             $path_to_event_model
70 70
         );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
71
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
72 72
             new EE_Restriction_Generator_Event_Related_Protected(
73 73
                 $path_to_event_model
74 74
             );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
75
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected(
76 76
             $path_to_event_model
77 77
         );
78
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] =
78
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] =
79 79
             new EE_Restriction_Generator_Event_Related_Protected(
80 80
                 $path_to_event_model,
81 81
                 EEM_Base::caps_edit
@@ -85,27 +85,27 @@  discard block
 block discarded – undo
85 85
         // and for deleting term relations too
86 86
         $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
87 87
         foreach ($cap_contexts_affected as $cap_context_affected) {
88
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
88
+            $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] =
89 89
                 new EE_Default_Where_Conditions(
90 90
                     array(
91
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
91
+                        $path_to_tax_model.'taxonomy*ee_assign_event_category' => array(
92 92
                             '!=',
93 93
                             'espresso_event_categories',
94 94
                         ),
95 95
                     )
96 96
                 );
97
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
97
+            $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] =
98 98
                 new EE_Default_Where_Conditions(
99 99
                     array(
100
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
100
+                        $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array(
101 101
                             '!=',
102 102
                             'espresso_venue_categories',
103 103
                         ),
104 104
                     )
105 105
                 );
106
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
106
+            $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
107 107
                 array(
108
-                    $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
108
+                    $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
109 109
                 )
110 110
             );
111 111
         }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     {
233 233
         if ($model === EEM_Term_Relationship::instance()) {
234 234
             $taxonomies = get_taxonomies(array('show_in_rest' => true));
235
-            if (! empty($taxonomies)) {
235
+            if ( ! empty($taxonomies)) {
236 236
                 $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237 237
             }
238 238
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket.model.php 2 patches
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -10,322 +10,322 @@
 block discarded – undo
10 10
 class EEM_Ticket extends EEM_Soft_Delete_Base
11 11
 {
12 12
 
13
-    /**
14
-     * private instance of the EEM_Ticket object
15
-     *
16
-     * @var EEM_Ticket $_instance
17
-     */
18
-    protected static $_instance;
13
+	/**
14
+	 * private instance of the EEM_Ticket object
15
+	 *
16
+	 * @var EEM_Ticket $_instance
17
+	 */
18
+	protected static $_instance;
19 19
 
20 20
 
21
-    /**
22
-     * private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
27
-     *                         (and any incoming timezone data that gets saved).
28
-     *                         Note this just sends the timezone info to the date time model field objects.
29
-     *                         Default is NULL
30
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
31
-     * @throws EE_Error
32
-     */
33
-    protected function __construct($timezone)
34
-    {
35
-        $this->singular_item = esc_html__('Ticket', 'event_espresso');
36
-        $this->plural_item = esc_html__('Tickets', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
39
-        );
40
-        $this->_fields = array(
41
-            'Ticket' => array(
42
-                'TKT_ID'          => new EE_Primary_Key_Int_Field(
43
-                    'TKT_ID',
44
-                    esc_html__('Ticket ID', 'event_espresso')
45
-                ),
46
-                'TTM_ID'          => new EE_Foreign_Key_Int_Field(
47
-                    'TTM_ID',
48
-                    esc_html__('Ticket Template ID', 'event_espresso'),
49
-                    false,
50
-                    0,
51
-                    'Ticket_Template'
52
-                ),
53
-                'TKT_name'        => new EE_Plain_Text_Field(
54
-                    'TKT_name',
55
-                    esc_html__('Ticket Name', 'event_espresso'),
56
-                    false,
57
-                    ''
58
-                ),
59
-                'TKT_description' => new EE_Post_Content_Field(
60
-                    'TKT_description',
61
-                    esc_html__('Description of Ticket', 'event_espresso'),
62
-                    false,
63
-                    ''
64
-                ),
65
-                'TKT_start_date'  => new EE_Datetime_Field(
66
-                    'TKT_start_date',
67
-                    esc_html__('Start time/date of Ticket', 'event_espresso'),
68
-                    false,
69
-                    EE_Datetime_Field::now,
70
-                    $timezone
71
-                ),
72
-                'TKT_end_date'    => new EE_Datetime_Field(
73
-                    'TKT_end_date',
74
-                    esc_html__('End time/date of Ticket', 'event_espresso'),
75
-                    false,
76
-                    EE_Datetime_Field::now,
77
-                    $timezone
78
-                ),
79
-                'TKT_min'         => new EE_Integer_Field(
80
-                    'TKT_min',
81
-                    esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
82
-                    false,
83
-                    0
84
-                ),
85
-                'TKT_max'         => new EE_Infinite_Integer_Field(
86
-                    'TKT_max',
87
-                    esc_html__(
88
-                        'Maximum quantity of this ticket that can be purchased in one transaction',
89
-                        'event_espresso'
90
-                    ),
91
-                    false,
92
-                    EE_INF
93
-                ),
94
-                'TKT_price'       => new EE_Money_Field(
95
-                    'TKT_price',
96
-                    esc_html__('Final calculated price for ticket', 'event_espresso'),
97
-                    false,
98
-                    0
99
-                ),
100
-                'TKT_sold'        => new EE_Integer_Field(
101
-                    'TKT_sold',
102
-                    esc_html__('Number of this ticket sold', 'event_espresso'),
103
-                    false,
104
-                    0
105
-                ),
106
-                'TKT_qty'         => new EE_Infinite_Integer_Field(
107
-                    'TKT_qty',
108
-                    esc_html__('Quantity of this ticket that is available', 'event_espresso'),
109
-                    false,
110
-                    EE_INF
111
-                ),
112
-                'TKT_reserved'    => new EE_Integer_Field(
113
-                    'TKT_reserved',
114
-                    esc_html__(
115
-                        'Quantity of this ticket that is reserved, but not yet fully purchased',
116
-                        'event_espresso'
117
-                    ),
118
-                    false,
119
-                    0
120
-                ),
121
-                'TKT_uses'        => new EE_Infinite_Integer_Field(
122
-                    'TKT_uses',
123
-                    esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
124
-                    false,
125
-                    EE_INF
126
-                ),
127
-                'TKT_required'    => new EE_Boolean_Field(
128
-                    'TKT_required',
129
-                    esc_html__(
130
-                        'Flag indicating whether this ticket must be purchased with a transaction',
131
-                        'event_espresso'
132
-                    ),
133
-                    false,
134
-                    false
135
-                ),
136
-                'TKT_taxable'     => new EE_Boolean_Field(
137
-                    'TKT_taxable',
138
-                    esc_html__(
139
-                        'Flag indicating whether there is tax applied on this ticket',
140
-                        'event_espresso'
141
-                    ),
142
-                    false,
143
-                    false
144
-                ),
145
-                'TKT_is_default'  => new EE_Boolean_Field(
146
-                    'TKT_is_default',
147
-                    esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
148
-                    false,
149
-                    false
150
-                ),
151
-                'TKT_order'       => new EE_Integer_Field(
152
-                    'TKT_order',
153
-                    esc_html__(
154
-                        'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
155
-                        'event_espresso'
156
-                    ),
157
-                    false,
158
-                    0
159
-                ),
160
-                'TKT_row'         => new EE_Integer_Field(
161
-                    'TKT_row',
162
-                    esc_html__('How tickets are displayed in the ui', 'event_espresso'),
163
-                    false,
164
-                    0
165
-                ),
166
-                'TKT_deleted'     => new EE_Trashed_Flag_Field(
167
-                    'TKT_deleted',
168
-                    esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
169
-                    false,
170
-                    false
171
-                ),
172
-                'TKT_wp_user'     => new EE_WP_User_Field(
173
-                    'TKT_wp_user',
174
-                    esc_html__('Ticket Creator ID', 'event_espresso'),
175
-                    false
176
-                ),
177
-                'TKT_parent'      => new EE_Integer_Field(
178
-                    'TKT_parent',
179
-                    esc_html__(
180
-                        'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
181
-                        'event_espresso'
182
-                    ),
183
-                    true,
184
-                    0
185
-                ),
186
-            ),
187
-        );
188
-        $this->_model_relations = array(
189
-            'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
190
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
191
-            'Price'           => new EE_HABTM_Relation('Ticket_Price'),
192
-            'Ticket_Template' => new EE_Belongs_To_Relation(),
193
-            'Registration'    => new EE_Has_Many_Relation(),
194
-            'WP_User'         => new EE_Belongs_To_Relation(),
195
-        );
196
-        // this model is generally available for reading
197
-        $path_to_event = 'Datetime.Event';
198
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
199
-            'TKT_is_default',
200
-            $path_to_event
201
-        );
202
-        // account for default tickets in the caps
203
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
204
-            'TKT_is_default',
205
-            $path_to_event
206
-        );
207
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
208
-            'TKT_is_default',
209
-            $path_to_event
210
-        );
211
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
212
-            'TKT_is_default',
213
-            $path_to_event
214
-        );
215
-        $this->model_chain_to_password = $path_to_event;
216
-        parent::__construct($timezone);
217
-    }
21
+	/**
22
+	 * private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
27
+	 *                         (and any incoming timezone data that gets saved).
28
+	 *                         Note this just sends the timezone info to the date time model field objects.
29
+	 *                         Default is NULL
30
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
31
+	 * @throws EE_Error
32
+	 */
33
+	protected function __construct($timezone)
34
+	{
35
+		$this->singular_item = esc_html__('Ticket', 'event_espresso');
36
+		$this->plural_item = esc_html__('Tickets', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
39
+		);
40
+		$this->_fields = array(
41
+			'Ticket' => array(
42
+				'TKT_ID'          => new EE_Primary_Key_Int_Field(
43
+					'TKT_ID',
44
+					esc_html__('Ticket ID', 'event_espresso')
45
+				),
46
+				'TTM_ID'          => new EE_Foreign_Key_Int_Field(
47
+					'TTM_ID',
48
+					esc_html__('Ticket Template ID', 'event_espresso'),
49
+					false,
50
+					0,
51
+					'Ticket_Template'
52
+				),
53
+				'TKT_name'        => new EE_Plain_Text_Field(
54
+					'TKT_name',
55
+					esc_html__('Ticket Name', 'event_espresso'),
56
+					false,
57
+					''
58
+				),
59
+				'TKT_description' => new EE_Post_Content_Field(
60
+					'TKT_description',
61
+					esc_html__('Description of Ticket', 'event_espresso'),
62
+					false,
63
+					''
64
+				),
65
+				'TKT_start_date'  => new EE_Datetime_Field(
66
+					'TKT_start_date',
67
+					esc_html__('Start time/date of Ticket', 'event_espresso'),
68
+					false,
69
+					EE_Datetime_Field::now,
70
+					$timezone
71
+				),
72
+				'TKT_end_date'    => new EE_Datetime_Field(
73
+					'TKT_end_date',
74
+					esc_html__('End time/date of Ticket', 'event_espresso'),
75
+					false,
76
+					EE_Datetime_Field::now,
77
+					$timezone
78
+				),
79
+				'TKT_min'         => new EE_Integer_Field(
80
+					'TKT_min',
81
+					esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
82
+					false,
83
+					0
84
+				),
85
+				'TKT_max'         => new EE_Infinite_Integer_Field(
86
+					'TKT_max',
87
+					esc_html__(
88
+						'Maximum quantity of this ticket that can be purchased in one transaction',
89
+						'event_espresso'
90
+					),
91
+					false,
92
+					EE_INF
93
+				),
94
+				'TKT_price'       => new EE_Money_Field(
95
+					'TKT_price',
96
+					esc_html__('Final calculated price for ticket', 'event_espresso'),
97
+					false,
98
+					0
99
+				),
100
+				'TKT_sold'        => new EE_Integer_Field(
101
+					'TKT_sold',
102
+					esc_html__('Number of this ticket sold', 'event_espresso'),
103
+					false,
104
+					0
105
+				),
106
+				'TKT_qty'         => new EE_Infinite_Integer_Field(
107
+					'TKT_qty',
108
+					esc_html__('Quantity of this ticket that is available', 'event_espresso'),
109
+					false,
110
+					EE_INF
111
+				),
112
+				'TKT_reserved'    => new EE_Integer_Field(
113
+					'TKT_reserved',
114
+					esc_html__(
115
+						'Quantity of this ticket that is reserved, but not yet fully purchased',
116
+						'event_espresso'
117
+					),
118
+					false,
119
+					0
120
+				),
121
+				'TKT_uses'        => new EE_Infinite_Integer_Field(
122
+					'TKT_uses',
123
+					esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
124
+					false,
125
+					EE_INF
126
+				),
127
+				'TKT_required'    => new EE_Boolean_Field(
128
+					'TKT_required',
129
+					esc_html__(
130
+						'Flag indicating whether this ticket must be purchased with a transaction',
131
+						'event_espresso'
132
+					),
133
+					false,
134
+					false
135
+				),
136
+				'TKT_taxable'     => new EE_Boolean_Field(
137
+					'TKT_taxable',
138
+					esc_html__(
139
+						'Flag indicating whether there is tax applied on this ticket',
140
+						'event_espresso'
141
+					),
142
+					false,
143
+					false
144
+				),
145
+				'TKT_is_default'  => new EE_Boolean_Field(
146
+					'TKT_is_default',
147
+					esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
148
+					false,
149
+					false
150
+				),
151
+				'TKT_order'       => new EE_Integer_Field(
152
+					'TKT_order',
153
+					esc_html__(
154
+						'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
155
+						'event_espresso'
156
+					),
157
+					false,
158
+					0
159
+				),
160
+				'TKT_row'         => new EE_Integer_Field(
161
+					'TKT_row',
162
+					esc_html__('How tickets are displayed in the ui', 'event_espresso'),
163
+					false,
164
+					0
165
+				),
166
+				'TKT_deleted'     => new EE_Trashed_Flag_Field(
167
+					'TKT_deleted',
168
+					esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
169
+					false,
170
+					false
171
+				),
172
+				'TKT_wp_user'     => new EE_WP_User_Field(
173
+					'TKT_wp_user',
174
+					esc_html__('Ticket Creator ID', 'event_espresso'),
175
+					false
176
+				),
177
+				'TKT_parent'      => new EE_Integer_Field(
178
+					'TKT_parent',
179
+					esc_html__(
180
+						'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
181
+						'event_espresso'
182
+					),
183
+					true,
184
+					0
185
+				),
186
+			),
187
+		);
188
+		$this->_model_relations = array(
189
+			'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
190
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
191
+			'Price'           => new EE_HABTM_Relation('Ticket_Price'),
192
+			'Ticket_Template' => new EE_Belongs_To_Relation(),
193
+			'Registration'    => new EE_Has_Many_Relation(),
194
+			'WP_User'         => new EE_Belongs_To_Relation(),
195
+		);
196
+		// this model is generally available for reading
197
+		$path_to_event = 'Datetime.Event';
198
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
199
+			'TKT_is_default',
200
+			$path_to_event
201
+		);
202
+		// account for default tickets in the caps
203
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
204
+			'TKT_is_default',
205
+			$path_to_event
206
+		);
207
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
208
+			'TKT_is_default',
209
+			$path_to_event
210
+		);
211
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
212
+			'TKT_is_default',
213
+			$path_to_event
214
+		);
215
+		$this->model_chain_to_password = $path_to_event;
216
+		parent::__construct($timezone);
217
+	}
218 218
 
219 219
 
220
-    /**
221
-     * This returns all tickets that are defaults from the db
222
-     *
223
-     * @return EE_Ticket[]
224
-     * @throws EE_Error
225
-     */
226
-    public function get_all_default_tickets()
227
-    {
228
-        /** @type EE_Ticket[] $tickets */
229
-        $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC')));
230
-        // we need to set the start date and end date to today's date and the start of the default dtt
231
-        return $this->_set_default_dates($tickets);
232
-    }
220
+	/**
221
+	 * This returns all tickets that are defaults from the db
222
+	 *
223
+	 * @return EE_Ticket[]
224
+	 * @throws EE_Error
225
+	 */
226
+	public function get_all_default_tickets()
227
+	{
228
+		/** @type EE_Ticket[] $tickets */
229
+		$tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC')));
230
+		// we need to set the start date and end date to today's date and the start of the default dtt
231
+		return $this->_set_default_dates($tickets);
232
+	}
233 233
 
234 234
 
235
-    /**
236
-     * sets up relevant start and end date for EE_Ticket (s)
237
-     *
238
-     * @param EE_Ticket[] $tickets
239
-     * @return EE_Ticket[]
240
-     * @throws EE_Error
241
-     */
242
-    private function _set_default_dates($tickets)
243
-    {
244
-        foreach ($tickets as $ticket) {
245
-            $ticket->set(
246
-                'TKT_start_date',
247
-                (int) $this->current_time_for_query('TKT_start_date', true)
248
-            );
249
-            $ticket->set(
250
-                'TKT_end_date',
251
-                (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
252
-            );
253
-            $ticket->set_end_time(
254
-                $this->convert_datetime_for_query(
255
-                    'TKT_end_date',
256
-                    '11:59 pm',
257
-                    'g:i a',
258
-                    $this->_timezone
259
-                )
260
-            );
261
-        }
262
-        return $tickets;
263
-    }
235
+	/**
236
+	 * sets up relevant start and end date for EE_Ticket (s)
237
+	 *
238
+	 * @param EE_Ticket[] $tickets
239
+	 * @return EE_Ticket[]
240
+	 * @throws EE_Error
241
+	 */
242
+	private function _set_default_dates($tickets)
243
+	{
244
+		foreach ($tickets as $ticket) {
245
+			$ticket->set(
246
+				'TKT_start_date',
247
+				(int) $this->current_time_for_query('TKT_start_date', true)
248
+			);
249
+			$ticket->set(
250
+				'TKT_end_date',
251
+				(int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
252
+			);
253
+			$ticket->set_end_time(
254
+				$this->convert_datetime_for_query(
255
+					'TKT_end_date',
256
+					'11:59 pm',
257
+					'g:i a',
258
+					$this->_timezone
259
+				)
260
+			);
261
+		}
262
+		return $tickets;
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * Gets the total number of tickets available at a particular datetime (does
268
-     * NOT take int account the datetime's spaces available)
269
-     *
270
-     * @param int   $DTT_ID
271
-     * @param array $query_params
272
-     * @return int
273
-     */
274
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
275
-    {
276
-        return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
277
-    }
266
+	/**
267
+	 * Gets the total number of tickets available at a particular datetime (does
268
+	 * NOT take int account the datetime's spaces available)
269
+	 *
270
+	 * @param int   $DTT_ID
271
+	 * @param array $query_params
272
+	 * @return int
273
+	 */
274
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
275
+	{
276
+		return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
277
+	}
278 278
 
279 279
 
280
-    /**
281
-     * Updates the TKT_sold quantity on all the tickets matching $query_params
282
-     *
283
-     * @param EE_Ticket[] $tickets
284
-     * @return void
285
-     * @throws EE_Error
286
-     */
287
-    public function update_tickets_sold($tickets)
288
-    {
289
-        foreach ($tickets as $ticket) {
290
-            /* @var  $ticket EE_Ticket */
291
-            $ticket->update_tickets_sold();
292
-        }
293
-    }
280
+	/**
281
+	 * Updates the TKT_sold quantity on all the tickets matching $query_params
282
+	 *
283
+	 * @param EE_Ticket[] $tickets
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 */
287
+	public function update_tickets_sold($tickets)
288
+	{
289
+		foreach ($tickets as $ticket) {
290
+			/* @var  $ticket EE_Ticket */
291
+			$ticket->update_tickets_sold();
292
+		}
293
+	}
294 294
 
295 295
 
296
-    /**
297
-     * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
298
-     *
299
-     * @return EE_Base_Class[]|EE_Ticket[]
300
-     * @throws EE_Error
301
-     */
302
-    public function get_tickets_with_reservations()
303
-    {
304
-        return $this->get_all(
305
-            array(
306
-                array(
307
-                    'TKT_reserved' => array('>', 0),
308
-                ),
309
-            )
310
-        );
311
-    }
296
+	/**
297
+	 * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
298
+	 *
299
+	 * @return EE_Base_Class[]|EE_Ticket[]
300
+	 * @throws EE_Error
301
+	 */
302
+	public function get_tickets_with_reservations()
303
+	{
304
+		return $this->get_all(
305
+			array(
306
+				array(
307
+					'TKT_reserved' => array('>', 0),
308
+				),
309
+			)
310
+		);
311
+	}
312 312
 
313 313
 
314
-    /**
315
-     * returns an array of EE_Ticket objects matching the supplied list of IDs
316
-     *
317
-     * @param array $ticket_IDs
318
-     * @return EE_Base_Class[]|EE_Ticket[]
319
-     * @throws EE_Error
320
-     */
321
-    public function get_tickets_with_IDs(array $ticket_IDs)
322
-    {
323
-        return $this->get_all(
324
-            array(
325
-                array(
326
-                    'TKT_ID' => array('IN', $ticket_IDs),
327
-                ),
328
-            )
329
-        );
330
-    }
314
+	/**
315
+	 * returns an array of EE_Ticket objects matching the supplied list of IDs
316
+	 *
317
+	 * @param array $ticket_IDs
318
+	 * @return EE_Base_Class[]|EE_Ticket[]
319
+	 * @throws EE_Error
320
+	 */
321
+	public function get_tickets_with_IDs(array $ticket_IDs)
322
+	{
323
+		return $this->get_all(
324
+			array(
325
+				array(
326
+					'TKT_ID' => array('IN', $ticket_IDs),
327
+				),
328
+			)
329
+		);
330
+	}
331 331
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -195,20 +195,20 @@
 block discarded – undo
195 195
         );
196 196
         // this model is generally available for reading
197 197
         $path_to_event = 'Datetime.Event';
198
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
198
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
199 199
             'TKT_is_default',
200 200
             $path_to_event
201 201
         );
202 202
         // account for default tickets in the caps
203
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
203
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected(
204 204
             'TKT_is_default',
205 205
             $path_to_event
206 206
         );
207
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
207
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
208 208
             'TKT_is_default',
209 209
             $path_to_event
210 210
         );
211
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
211
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
212 212
             'TKT_is_default',
213 213
             $path_to_event
214 214
         );
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Indentation   +895 added lines, -895 removed lines patch added patch discarded remove patch
@@ -13,899 +13,899 @@
 block discarded – undo
13 13
 class EEM_Event extends EEM_CPT_Base
14 14
 {
15 15
 
16
-    /**
17
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
18
-     * event
19
-     */
20
-    const sold_out = 'sold_out';
21
-
22
-    /**
23
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
24
-     * date)
25
-     */
26
-    const postponed = 'postponed';
27
-
28
-    /**
29
-     * constant used by status(), indicating that the event will no longer occur
30
-     */
31
-    const cancelled = 'cancelled';
32
-
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    protected static $_default_reg_status;
38
-
39
-
40
-    /**
41
-     * This is the default for the additional limit field.
42
-     * @var int
43
-     */
44
-    protected static $_default_additional_limit = 10;
45
-
46
-
47
-    /**
48
-     * private instance of the Event object
49
-     *
50
-     * @var EEM_Event
51
-     */
52
-    protected static $_instance;
53
-
54
-
55
-
56
-
57
-    /**
58
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
59
-     *
60
-     * @param string $timezone
61
-     * @throws \EE_Error
62
-     */
63
-    protected function __construct($timezone = null)
64
-    {
65
-        EE_Registry::instance()->load_model('Registration');
66
-        $this->singular_item = esc_html__('Event', 'event_espresso');
67
-        $this->plural_item = esc_html__('Events', 'event_espresso');
68
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
69
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
70
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
71
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
-        $this->_custom_stati = apply_filters(
75
-            'AFEE__EEM_Event__construct___custom_stati',
76
-            array(
77
-                EEM_Event::cancelled => array(
78
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
79
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
80
-                ),
81
-                EEM_Event::postponed => array(
82
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
83
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
84
-                ),
85
-                EEM_Event::sold_out  => array(
86
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
87
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
88
-                ),
89
-            )
90
-        );
91
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
92
-            : self::$_default_reg_status;
93
-        $this->_tables = array(
94
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
95
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
96
-        );
97
-        $this->_fields = array(
98
-            'Event_CPT'  => array(
99
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
100
-                    'ID',
101
-                    esc_html__('Post ID for Event', 'event_espresso')
102
-                ),
103
-                'EVT_name'       => new EE_Plain_Text_Field(
104
-                    'post_title',
105
-                    esc_html__('Event Name', 'event_espresso'),
106
-                    false,
107
-                    ''
108
-                ),
109
-                'EVT_desc'       => new EE_Post_Content_Field(
110
-                    'post_content',
111
-                    esc_html__('Event Description', 'event_espresso'),
112
-                    false,
113
-                    ''
114
-                ),
115
-                'EVT_slug'       => new EE_Slug_Field(
116
-                    'post_name',
117
-                    esc_html__('Event Slug', 'event_espresso'),
118
-                    false,
119
-                    ''
120
-                ),
121
-                'EVT_created'    => new EE_Datetime_Field(
122
-                    'post_date',
123
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
124
-                    false,
125
-                    EE_Datetime_Field::now
126
-                ),
127
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
128
-                    'post_excerpt',
129
-                    esc_html__('Event Short Description', 'event_espresso'),
130
-                    false,
131
-                    ''
132
-                ),
133
-                'EVT_modified'   => new EE_Datetime_Field(
134
-                    'post_modified',
135
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
136
-                    false,
137
-                    EE_Datetime_Field::now
138
-                ),
139
-                'EVT_wp_user'    => new EE_WP_User_Field(
140
-                    'post_author',
141
-                    esc_html__('Event Creator ID', 'event_espresso'),
142
-                    false
143
-                ),
144
-                'parent'         => new EE_Integer_Field(
145
-                    'post_parent',
146
-                    esc_html__('Event Parent ID', 'event_espresso'),
147
-                    false,
148
-                    0
149
-                ),
150
-                'EVT_order'      => new EE_Integer_Field(
151
-                    'menu_order',
152
-                    esc_html__('Event Menu Order', 'event_espresso'),
153
-                    false,
154
-                    1
155
-                ),
156
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
157
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
158
-                'status'         => new EE_WP_Post_Status_Field(
159
-                    'post_status',
160
-                    esc_html__('Event Status', 'event_espresso'),
161
-                    false,
162
-                    'draft',
163
-                    $this->_custom_stati
164
-                ),
165
-                'password' => new EE_Password_Field(
166
-                    'post_password',
167
-                    __('Password', 'event_espresso'),
168
-                    false,
169
-                    '',
170
-                    array(
171
-                        'EVT_desc',
172
-                        'EVT_short_desc',
173
-                        'EVT_display_desc',
174
-                        'EVT_display_ticket_selector',
175
-                        'EVT_visible_on',
176
-                        'EVT_additional_limit',
177
-                        'EVT_default_registration_status',
178
-                        'EVT_member_only',
179
-                        'EVT_phone',
180
-                        'EVT_allow_overflow',
181
-                        'EVT_timezone_string',
182
-                        'EVT_external_URL',
183
-                        'EVT_donations'
184
-                    )
185
-                )
186
-            ),
187
-            'Event_Meta' => array(
188
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
189
-                    'EVTM_ID',
190
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
191
-                    false
192
-                ),
193
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
194
-                    'EVT_ID',
195
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
196
-                    false
197
-                ),
198
-                'EVT_display_desc'                => new EE_Boolean_Field(
199
-                    'EVT_display_desc',
200
-                    esc_html__('Display Description Flag', 'event_espresso'),
201
-                    false,
202
-                    true
203
-                ),
204
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
205
-                    'EVT_display_ticket_selector',
206
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
207
-                    false,
208
-                    true
209
-                ),
210
-                'EVT_visible_on'                  => new EE_Datetime_Field(
211
-                    'EVT_visible_on',
212
-                    esc_html__('Event Visible Date', 'event_espresso'),
213
-                    true,
214
-                    EE_Datetime_Field::now
215
-                ),
216
-                'EVT_additional_limit'            => new EE_Integer_Field(
217
-                    'EVT_additional_limit',
218
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
219
-                    true,
220
-                    self::$_default_additional_limit
221
-                ),
222
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
223
-                    'EVT_default_registration_status',
224
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
225
-                    false,
226
-                    EEM_Event::$_default_reg_status,
227
-                    EEM_Registration::reg_status_array()
228
-                ),
229
-                'EVT_member_only'                 => new EE_Boolean_Field(
230
-                    'EVT_member_only',
231
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
232
-                    false,
233
-                    false
234
-                ),
235
-                'EVT_phone'                       => new EE_Plain_Text_Field(
236
-                    'EVT_phone',
237
-                    esc_html__('Event Phone Number', 'event_espresso'),
238
-                    false,
239
-                    ''
240
-                ),
241
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
242
-                    'EVT_allow_overflow',
243
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
244
-                    false,
245
-                    false
246
-                ),
247
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
248
-                    'EVT_timezone_string',
249
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
250
-                    false,
251
-                    ''
252
-                ),
253
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
254
-                    'EVT_external_URL',
255
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
256
-                    true
257
-                ),
258
-                'EVT_donations'                   => new EE_Boolean_Field(
259
-                    'EVT_donations',
260
-                    esc_html__('Accept Donations?', 'event_espresso'),
261
-                    false,
262
-                    false
263
-                ),
264
-            ),
265
-        );
266
-        $this->_model_relations = array(
267
-            'Registration'           => new EE_Has_Many_Relation(),
268
-            'Datetime'               => new EE_Has_Many_Relation(),
269
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
270
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
271
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
272
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
273
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
274
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
275
-            'WP_User'                => new EE_Belongs_To_Relation(),
276
-        );
277
-        // this model is generally available for reading
278
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
279
-        $this->model_chain_to_password = '';
280
-        parent::__construct($timezone);
281
-    }
282
-
283
-
284
-
285
-    /**
286
-     * @param string $default_reg_status
287
-     */
288
-    public static function set_default_reg_status($default_reg_status)
289
-    {
290
-        self::$_default_reg_status = $default_reg_status;
291
-        // if EEM_Event has already been instantiated,
292
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
293
-        if (self::$_instance instanceof EEM_Event) {
294
-            $default_reg_status = new EE_Enum_Text_Field(
295
-                'EVT_default_registration_status',
296
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
297
-                false,
298
-                $default_reg_status,
299
-                EEM_Registration::reg_status_array()
300
-            );
301
-            $default_reg_status->_construct_finalize(
302
-                'Event_Meta',
303
-                'EVT_default_registration_status',
304
-                'EEM_Event'
305
-            );
306
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
307
-        }
308
-    }
309
-
310
-
311
-    /**
312
-     * Used to override the default for the additional limit field.
313
-     * @param $additional_limit
314
-     */
315
-    public static function set_default_additional_limit($additional_limit)
316
-    {
317
-        self::$_default_additional_limit = (int) $additional_limit;
318
-        if (self::$_instance instanceof EEM_Event) {
319
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
320
-                'EVT_additional_limit',
321
-                __('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
322
-                true,
323
-                self::$_default_additional_limit
324
-            );
325
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
326
-                'Event_Meta',
327
-                'EVT_additional_limit',
328
-                'EEM_Event'
329
-            );
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     * Return what is currently set as the default additional limit for the event.
336
-     * @return int
337
-     */
338
-    public static function get_default_additional_limit()
339
-    {
340
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
341
-    }
342
-
343
-
344
-    /**
345
-     * get_question_groups
346
-     *
347
-     * @return array
348
-     * @throws \EE_Error
349
-     */
350
-    public function get_all_question_groups()
351
-    {
352
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
-            array(
354
-                array('QSG_deleted' => false),
355
-                'order_by' => array('QSG_order' => 'ASC'),
356
-            )
357
-        );
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * get_question_groups
364
-     *
365
-     * @param int $EVT_ID
366
-     * @return array|bool
367
-     * @throws \EE_Error
368
-     */
369
-    public function get_all_event_question_groups($EVT_ID = 0)
370
-    {
371
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
372
-            EE_Error::add_error(
373
-                esc_html__(
374
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
375
-                    'event_espresso'
376
-                ),
377
-                __FILE__,
378
-                __FUNCTION__,
379
-                __LINE__
380
-            );
381
-            return false;
382
-        }
383
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
384
-            array(
385
-                array('EVT_ID' => $EVT_ID),
386
-            )
387
-        );
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * get_question_groups
394
-     *
395
-     * @param int     $EVT_ID
396
-     * @param boolean $for_primary_attendee
397
-     * @return array|bool
398
-     * @throws \EE_Error
399
-     */
400
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
401
-    {
402
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
403
-            EE_Error::add_error(
404
-                esc_html__(
405
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
406
-                    'event_espresso'
407
-                ),
408
-                __FILE__,
409
-                __FUNCTION__,
410
-                __LINE__
411
-            );
412
-            return false;
413
-        }
414
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
415
-            array(
416
-                array(
417
-                    'EVT_ID'      => $EVT_ID,
418
-                    'EQG_primary' => $for_primary_attendee,
419
-                ),
420
-            )
421
-        );
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * get_question_groups
428
-     *
429
-     * @param int             $EVT_ID
430
-     * @param EE_Registration $registration
431
-     * @return array|bool
432
-     * @throws \EE_Error
433
-     */
434
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
435
-    {
436
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
437
-            EE_Error::add_error(
438
-                esc_html__(
439
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
440
-                    'event_espresso'
441
-                ),
442
-                __FILE__,
443
-                __FUNCTION__,
444
-                __LINE__
445
-            );
446
-            return false;
447
-        }
448
-        $where_params = array(
449
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
450
-            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
451
-            'QSG_deleted'                      => false,
452
-        );
453
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
454
-            array(
455
-                $where_params,
456
-                'order_by' => array('QSG_order' => 'ASC'),
457
-            )
458
-        );
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     * get_question_target_db_column
465
-     *
466
-     * @param string $QSG_IDs csv list of $QSG IDs
467
-     * @return array|bool
468
-     * @throws \EE_Error
469
-     */
470
-    public function get_questions_in_groups($QSG_IDs = '')
471
-    {
472
-        if (empty($QSG_IDs)) {
473
-            EE_Error::add_error(
474
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
475
-                __FILE__,
476
-                __FUNCTION__,
477
-                __LINE__
478
-            );
479
-            return false;
480
-        }
481
-        return EE_Registry::instance()->load_model('Question')->get_all(
482
-            array(
483
-                array(
484
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
485
-                    'QST_deleted'           => false,
486
-                    'QST_admin_only'        => is_admin(),
487
-                ),
488
-                'order_by' => 'QST_order',
489
-            )
490
-        );
491
-    }
492
-
493
-
494
-
495
-    /**
496
-     * get_options_for_question
497
-     *
498
-     * @param string $QST_IDs csv list of $QST IDs
499
-     * @return array|bool
500
-     * @throws \EE_Error
501
-     */
502
-    public function get_options_for_question($QST_IDs)
503
-    {
504
-        if (empty($QST_IDs)) {
505
-            EE_Error::add_error(
506
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
507
-                __FILE__,
508
-                __FUNCTION__,
509
-                __LINE__
510
-            );
511
-            return false;
512
-        }
513
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
514
-            array(
515
-                array(
516
-                    'Question.QST_ID' => array('IN', $QST_IDs),
517
-                    'QSO_deleted'     => false,
518
-                ),
519
-                'order_by' => 'QSO_ID',
520
-            )
521
-        );
522
-    }
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-    /**
531
-     * Gets all events that are published
532
-     * and have event start time earlier than now and an event end time later than now
533
-     *
534
-     * @param  array $query_params An array of query params to further filter on
535
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
536
-     * @param bool   $count        whether to return the count or not (default FALSE)
537
-     * @return EE_Event[]|int
538
-     * @throws \EE_Error
539
-     */
540
-    public function get_active_events($query_params, $count = false)
541
-    {
542
-        if (array_key_exists(0, $query_params)) {
543
-            $where_params = $query_params[0];
544
-            unset($query_params[0]);
545
-        } else {
546
-            $where_params = array();
547
-        }
548
-        // if we have count make sure we don't include group by
549
-        if ($count && isset($query_params['group_by'])) {
550
-            unset($query_params['group_by']);
551
-        }
552
-        // let's add specific query_params for active_events
553
-        // keep in mind this will override any sent status in the query AND any date queries.
554
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
555
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
556
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
557
-            $where_params['Datetime.DTT_EVT_start******'] = array(
558
-                '<',
559
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
560
-            );
561
-        } else {
562
-            $where_params['Datetime.DTT_EVT_start'] = array(
563
-                '<',
564
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
565
-            );
566
-        }
567
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
568
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
569
-                '>',
570
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
571
-            );
572
-        } else {
573
-            $where_params['Datetime.DTT_EVT_end'] = array(
574
-                '>',
575
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
576
-            );
577
-        }
578
-        $query_params[0] = $where_params;
579
-        // don't use $query_params with count()
580
-        // because we don't want to include additional query clauses like "GROUP BY"
581
-        return $count
582
-            ? $this->count(array($where_params), 'EVT_ID', true)
583
-            : $this->get_all($query_params);
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * get all events that are published and have an event start time later than now
590
-     *
591
-     * @param  array $query_params An array of query params to further filter on
592
-     *                             (Note that status and DTT_EVT_start will be overridden)
593
-     * @param bool   $count        whether to return the count or not (default FALSE)
594
-     * @return EE_Event[]|int
595
-     * @throws \EE_Error
596
-     */
597
-    public function get_upcoming_events($query_params, $count = false)
598
-    {
599
-        if (array_key_exists(0, $query_params)) {
600
-            $where_params = $query_params[0];
601
-            unset($query_params[0]);
602
-        } else {
603
-            $where_params = array();
604
-        }
605
-        // if we have count make sure we don't include group by
606
-        if ($count && isset($query_params['group_by'])) {
607
-            unset($query_params['group_by']);
608
-        }
609
-        // let's add specific query_params for active_events
610
-        // keep in mind this will override any sent status in the query AND any date queries.
611
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
612
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
613
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
614
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
615
-                '>',
616
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
617
-            );
618
-        } else {
619
-            $where_params['Datetime.DTT_EVT_start'] = array(
620
-                '>',
621
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
622
-            );
623
-        }
624
-        $query_params[0] = $where_params;
625
-        // don't use $query_params with count()
626
-        // because we don't want to include additional query clauses like "GROUP BY"
627
-        return $count
628
-            ? $this->count(array($where_params), 'EVT_ID', true)
629
-            : $this->get_all($query_params);
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * Gets all events that are published
636
-     * and have an event end time later than now
637
-     *
638
-     * @param  array $query_params An array of query params to further filter on
639
-     *                             (note that status and DTT_EVT_end will be overridden)
640
-     * @param bool   $count        whether to return the count or not (default FALSE)
641
-     * @return EE_Event[]|int
642
-     * @throws \EE_Error
643
-     */
644
-    public function get_active_and_upcoming_events($query_params, $count = false)
645
-    {
646
-        if (array_key_exists(0, $query_params)) {
647
-            $where_params = $query_params[0];
648
-            unset($query_params[0]);
649
-        } else {
650
-            $where_params = array();
651
-        }
652
-        // if we have count make sure we don't include group by
653
-        if ($count && isset($query_params['group_by'])) {
654
-            unset($query_params['group_by']);
655
-        }
656
-        // let's add specific query_params for active_events
657
-        // keep in mind this will override any sent status in the query AND any date queries.
658
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
659
-        // add where params for DTT_EVT_end
660
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
661
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
662
-                '>',
663
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
664
-            );
665
-        } else {
666
-            $where_params['Datetime.DTT_EVT_end'] = array(
667
-                '>',
668
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
669
-            );
670
-        }
671
-        $query_params[0] = $where_params;
672
-        // don't use $query_params with count()
673
-        // because we don't want to include additional query clauses like "GROUP BY"
674
-        return $count
675
-            ? $this->count(array($where_params), 'EVT_ID', true)
676
-            : $this->get_all($query_params);
677
-    }
678
-
679
-
680
-
681
-    /**
682
-     * This only returns events that are expired.
683
-     * They may still be published but all their datetimes have expired.
684
-     *
685
-     * @param  array $query_params An array of query params to further filter on
686
-     *                             (note that status and DTT_EVT_end will be overridden)
687
-     * @param bool   $count        whether to return the count or not (default FALSE)
688
-     * @return EE_Event[]|int
689
-     * @throws \EE_Error
690
-     */
691
-    public function get_expired_events($query_params, $count = false)
692
-    {
693
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
694
-        // if we have count make sure we don't include group by
695
-        if ($count && isset($query_params['group_by'])) {
696
-            unset($query_params['group_by']);
697
-        }
698
-        // let's add specific query_params for active_events
699
-        // keep in mind this will override any sent status in the query AND any date queries.
700
-        if (isset($where_params['status'])) {
701
-            unset($where_params['status']);
702
-        }
703
-        $exclude_query = $query_params;
704
-        if (isset($exclude_query[0])) {
705
-            unset($exclude_query[0]);
706
-        }
707
-        $exclude_query[0] = array(
708
-            'Datetime.DTT_EVT_end' => array(
709
-                '>',
710
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
711
-            ),
712
-        );
713
-        // first get all events that have datetimes where its not expired.
714
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
715
-        $event_ids = array_keys($event_ids);
716
-        // if we have any additional query_params, let's add them to the 'AND' condition
717
-        $and_condition = array(
718
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
719
-            'EVT_ID'               => array('NOT IN', $event_ids),
720
-        );
721
-        if (isset($where_params['OR'])) {
722
-            $and_condition['OR'] = $where_params['OR'];
723
-            unset($where_params['OR']);
724
-        }
725
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
726
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
727
-            unset($where_params['Datetime.DTT_EVT_end']);
728
-        }
729
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
730
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
731
-            unset($where_params['Datetime.DTT_EVT_start']);
732
-        }
733
-        // merge remaining $where params with the and conditions.
734
-        $where_params['AND'] = array_merge($and_condition, $where_params);
735
-        $query_params[0] = $where_params;
736
-        // don't use $query_params with count()
737
-        // because we don't want to include additional query clauses like "GROUP BY"
738
-        return $count
739
-            ? $this->count(array($where_params), 'EVT_ID', true)
740
-            : $this->get_all($query_params);
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     * This basically just returns the events that do not have the publish status.
747
-     *
748
-     * @param  array   $query_params An array of query params to further filter on
749
-     *                               (note that status will be overwritten)
750
-     * @param  boolean $count        whether to return the count or not (default FALSE)
751
-     * @return EE_Event[]|int
752
-     * @throws \EE_Error
753
-     */
754
-    public function get_inactive_events($query_params, $count = false)
755
-    {
756
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
757
-        // let's add in specific query_params for inactive events.
758
-        if (isset($where_params['status'])) {
759
-            unset($where_params['status']);
760
-        }
761
-        // if we have count make sure we don't include group by
762
-        if ($count && isset($query_params['group_by'])) {
763
-            unset($query_params['group_by']);
764
-        }
765
-        // if we have any additional query_params, let's add them to the 'AND' condition
766
-        $where_params['AND']['status'] = array('!=', 'publish');
767
-        if (isset($where_params['OR'])) {
768
-            $where_params['AND']['OR'] = $where_params['OR'];
769
-            unset($where_params['OR']);
770
-        }
771
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
772
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
773
-            unset($where_params['Datetime.DTT_EVT_end']);
774
-        }
775
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
776
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
777
-            unset($where_params['Datetime.DTT_EVT_start']);
778
-        }
779
-        $query_params[0] = $where_params;
780
-        // don't use $query_params with count()
781
-        // because we don't want to include additional query clauses like "GROUP BY"
782
-        return $count
783
-            ? $this->count(array($where_params), 'EVT_ID', true)
784
-            : $this->get_all($query_params);
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
791
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
792
-     * attached to the event. See parent for param descriptions
793
-     *
794
-     * @param        $id_or_obj
795
-     * @param        $other_model_id_or_obj
796
-     * @param string $relationName
797
-     * @param array  $where_query
798
-     * @return EE_Base_Class
799
-     * @throws EE_Error
800
-     */
801
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
802
-    {
803
-        if ($relationName === 'Price') {
804
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
805
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
806
-            // if EVT_ID = 0, then this is a default
807
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
808
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
809
-                $prc_chk->set('PRC_ID', 0);
810
-            }
811
-            // run parent
812
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
813
-        }
814
-        // otherwise carry on as normal
815
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
816
-    }
817
-
818
-
819
-
820
-    /******************** DEPRECATED METHODS ********************/
821
-
822
-
823
-
824
-    /**
825
-     * _get_question_target_db_column
826
-     *
827
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
828
-     *             EE_Registration_Custom_Questions_Form located in
829
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
830
-     * @access     public
831
-     * @param    EE_Registration $registration (so existing answers for registration are included)
832
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
833
-     *                                         registration).
834
-     * @throws EE_Error
835
-     * @return    array
836
-     */
837
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
838
-    {
839
-        if (empty($EVT_ID)) {
840
-            throw new EE_Error(__(
841
-                'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
842
-                'event_espresso'
843
-            ));
844
-        }
845
-        $questions = array();
846
-        // get all question groups for event
847
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
848
-        if (! empty($qgs)) {
849
-            foreach ($qgs as $qg) {
850
-                $qsts = $qg->questions();
851
-                $questions[ $qg->ID() ] = $qg->model_field_array();
852
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
853
-                foreach ($qsts as $qst) {
854
-                    if ($qst->is_system_question()) {
855
-                        continue;
856
-                    }
857
-                    $answer = EEM_Answer::instance()->get_one(array(
858
-                        array(
859
-                            'QST_ID' => $qst->ID(),
860
-                            'REG_ID' => $registration->ID(),
861
-                        ),
862
-                    ));
863
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
864
-                    $qst_name = $qstn_id = $qst->ID();
865
-                    $ans_id = $answer->ID();
866
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
867
-                    $input_name = '';
868
-                    $input_id = sanitize_key($qst->display_text());
869
-                    $input_class = '';
870
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
871
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
872
-                                                                                           . $input_name
873
-                                                                                           . $qst_name;
874
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
875
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
876
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
877
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
878
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
879
-                    // leave responses as-is, don't convert stuff into html entities please!
880
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
881
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
882
-                        $QSOs = $qst->options(true, $answer->value());
883
-                        if (is_array($QSOs)) {
884
-                            foreach ($QSOs as $QSO_ID => $QSO) {
885
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
886
-                            }
887
-                        }
888
-                    }
889
-                }
890
-            }
891
-        }
892
-        return $questions;
893
-    }
894
-
895
-
896
-    /**
897
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
898
-     *                             or an stdClass where each property is the name of a column,
899
-     * @return EE_Base_Class
900
-     * @throws \EE_Error
901
-     */
902
-    public function instantiate_class_from_array_or_object($cols_n_values)
903
-    {
904
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
905
-        if ($classInstance instanceof EE_Event) {
906
-            // events have their timezone defined in the DB, so use it immediately
907
-            $this->set_timezone($classInstance->get_timezone());
908
-        }
909
-        return $classInstance;
910
-    }
16
+	/**
17
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
18
+	 * event
19
+	 */
20
+	const sold_out = 'sold_out';
21
+
22
+	/**
23
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
24
+	 * date)
25
+	 */
26
+	const postponed = 'postponed';
27
+
28
+	/**
29
+	 * constant used by status(), indicating that the event will no longer occur
30
+	 */
31
+	const cancelled = 'cancelled';
32
+
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	protected static $_default_reg_status;
38
+
39
+
40
+	/**
41
+	 * This is the default for the additional limit field.
42
+	 * @var int
43
+	 */
44
+	protected static $_default_additional_limit = 10;
45
+
46
+
47
+	/**
48
+	 * private instance of the Event object
49
+	 *
50
+	 * @var EEM_Event
51
+	 */
52
+	protected static $_instance;
53
+
54
+
55
+
56
+
57
+	/**
58
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
59
+	 *
60
+	 * @param string $timezone
61
+	 * @throws \EE_Error
62
+	 */
63
+	protected function __construct($timezone = null)
64
+	{
65
+		EE_Registry::instance()->load_model('Registration');
66
+		$this->singular_item = esc_html__('Event', 'event_espresso');
67
+		$this->plural_item = esc_html__('Events', 'event_espresso');
68
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
69
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
70
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
71
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
+		$this->_custom_stati = apply_filters(
75
+			'AFEE__EEM_Event__construct___custom_stati',
76
+			array(
77
+				EEM_Event::cancelled => array(
78
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
79
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
80
+				),
81
+				EEM_Event::postponed => array(
82
+					'label'  => esc_html__('Postponed', 'event_espresso'),
83
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
84
+				),
85
+				EEM_Event::sold_out  => array(
86
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
87
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
88
+				),
89
+			)
90
+		);
91
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
92
+			: self::$_default_reg_status;
93
+		$this->_tables = array(
94
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
95
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
96
+		);
97
+		$this->_fields = array(
98
+			'Event_CPT'  => array(
99
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
100
+					'ID',
101
+					esc_html__('Post ID for Event', 'event_espresso')
102
+				),
103
+				'EVT_name'       => new EE_Plain_Text_Field(
104
+					'post_title',
105
+					esc_html__('Event Name', 'event_espresso'),
106
+					false,
107
+					''
108
+				),
109
+				'EVT_desc'       => new EE_Post_Content_Field(
110
+					'post_content',
111
+					esc_html__('Event Description', 'event_espresso'),
112
+					false,
113
+					''
114
+				),
115
+				'EVT_slug'       => new EE_Slug_Field(
116
+					'post_name',
117
+					esc_html__('Event Slug', 'event_espresso'),
118
+					false,
119
+					''
120
+				),
121
+				'EVT_created'    => new EE_Datetime_Field(
122
+					'post_date',
123
+					esc_html__('Date/Time Event Created', 'event_espresso'),
124
+					false,
125
+					EE_Datetime_Field::now
126
+				),
127
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
128
+					'post_excerpt',
129
+					esc_html__('Event Short Description', 'event_espresso'),
130
+					false,
131
+					''
132
+				),
133
+				'EVT_modified'   => new EE_Datetime_Field(
134
+					'post_modified',
135
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
136
+					false,
137
+					EE_Datetime_Field::now
138
+				),
139
+				'EVT_wp_user'    => new EE_WP_User_Field(
140
+					'post_author',
141
+					esc_html__('Event Creator ID', 'event_espresso'),
142
+					false
143
+				),
144
+				'parent'         => new EE_Integer_Field(
145
+					'post_parent',
146
+					esc_html__('Event Parent ID', 'event_espresso'),
147
+					false,
148
+					0
149
+				),
150
+				'EVT_order'      => new EE_Integer_Field(
151
+					'menu_order',
152
+					esc_html__('Event Menu Order', 'event_espresso'),
153
+					false,
154
+					1
155
+				),
156
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
157
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
158
+				'status'         => new EE_WP_Post_Status_Field(
159
+					'post_status',
160
+					esc_html__('Event Status', 'event_espresso'),
161
+					false,
162
+					'draft',
163
+					$this->_custom_stati
164
+				),
165
+				'password' => new EE_Password_Field(
166
+					'post_password',
167
+					__('Password', 'event_espresso'),
168
+					false,
169
+					'',
170
+					array(
171
+						'EVT_desc',
172
+						'EVT_short_desc',
173
+						'EVT_display_desc',
174
+						'EVT_display_ticket_selector',
175
+						'EVT_visible_on',
176
+						'EVT_additional_limit',
177
+						'EVT_default_registration_status',
178
+						'EVT_member_only',
179
+						'EVT_phone',
180
+						'EVT_allow_overflow',
181
+						'EVT_timezone_string',
182
+						'EVT_external_URL',
183
+						'EVT_donations'
184
+					)
185
+				)
186
+			),
187
+			'Event_Meta' => array(
188
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
189
+					'EVTM_ID',
190
+					esc_html__('Event Meta Row ID', 'event_espresso'),
191
+					false
192
+				),
193
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
194
+					'EVT_ID',
195
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
196
+					false
197
+				),
198
+				'EVT_display_desc'                => new EE_Boolean_Field(
199
+					'EVT_display_desc',
200
+					esc_html__('Display Description Flag', 'event_espresso'),
201
+					false,
202
+					true
203
+				),
204
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
205
+					'EVT_display_ticket_selector',
206
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
207
+					false,
208
+					true
209
+				),
210
+				'EVT_visible_on'                  => new EE_Datetime_Field(
211
+					'EVT_visible_on',
212
+					esc_html__('Event Visible Date', 'event_espresso'),
213
+					true,
214
+					EE_Datetime_Field::now
215
+				),
216
+				'EVT_additional_limit'            => new EE_Integer_Field(
217
+					'EVT_additional_limit',
218
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
219
+					true,
220
+					self::$_default_additional_limit
221
+				),
222
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
223
+					'EVT_default_registration_status',
224
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
225
+					false,
226
+					EEM_Event::$_default_reg_status,
227
+					EEM_Registration::reg_status_array()
228
+				),
229
+				'EVT_member_only'                 => new EE_Boolean_Field(
230
+					'EVT_member_only',
231
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
232
+					false,
233
+					false
234
+				),
235
+				'EVT_phone'                       => new EE_Plain_Text_Field(
236
+					'EVT_phone',
237
+					esc_html__('Event Phone Number', 'event_espresso'),
238
+					false,
239
+					''
240
+				),
241
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
242
+					'EVT_allow_overflow',
243
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
244
+					false,
245
+					false
246
+				),
247
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
248
+					'EVT_timezone_string',
249
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
250
+					false,
251
+					''
252
+				),
253
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
254
+					'EVT_external_URL',
255
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
256
+					true
257
+				),
258
+				'EVT_donations'                   => new EE_Boolean_Field(
259
+					'EVT_donations',
260
+					esc_html__('Accept Donations?', 'event_espresso'),
261
+					false,
262
+					false
263
+				),
264
+			),
265
+		);
266
+		$this->_model_relations = array(
267
+			'Registration'           => new EE_Has_Many_Relation(),
268
+			'Datetime'               => new EE_Has_Many_Relation(),
269
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
270
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
271
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
272
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
273
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
274
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
275
+			'WP_User'                => new EE_Belongs_To_Relation(),
276
+		);
277
+		// this model is generally available for reading
278
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
279
+		$this->model_chain_to_password = '';
280
+		parent::__construct($timezone);
281
+	}
282
+
283
+
284
+
285
+	/**
286
+	 * @param string $default_reg_status
287
+	 */
288
+	public static function set_default_reg_status($default_reg_status)
289
+	{
290
+		self::$_default_reg_status = $default_reg_status;
291
+		// if EEM_Event has already been instantiated,
292
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
293
+		if (self::$_instance instanceof EEM_Event) {
294
+			$default_reg_status = new EE_Enum_Text_Field(
295
+				'EVT_default_registration_status',
296
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
297
+				false,
298
+				$default_reg_status,
299
+				EEM_Registration::reg_status_array()
300
+			);
301
+			$default_reg_status->_construct_finalize(
302
+				'Event_Meta',
303
+				'EVT_default_registration_status',
304
+				'EEM_Event'
305
+			);
306
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
307
+		}
308
+	}
309
+
310
+
311
+	/**
312
+	 * Used to override the default for the additional limit field.
313
+	 * @param $additional_limit
314
+	 */
315
+	public static function set_default_additional_limit($additional_limit)
316
+	{
317
+		self::$_default_additional_limit = (int) $additional_limit;
318
+		if (self::$_instance instanceof EEM_Event) {
319
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
320
+				'EVT_additional_limit',
321
+				__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
322
+				true,
323
+				self::$_default_additional_limit
324
+			);
325
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
326
+				'Event_Meta',
327
+				'EVT_additional_limit',
328
+				'EEM_Event'
329
+			);
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 * Return what is currently set as the default additional limit for the event.
336
+	 * @return int
337
+	 */
338
+	public static function get_default_additional_limit()
339
+	{
340
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
341
+	}
342
+
343
+
344
+	/**
345
+	 * get_question_groups
346
+	 *
347
+	 * @return array
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function get_all_question_groups()
351
+	{
352
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
+			array(
354
+				array('QSG_deleted' => false),
355
+				'order_by' => array('QSG_order' => 'ASC'),
356
+			)
357
+		);
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * get_question_groups
364
+	 *
365
+	 * @param int $EVT_ID
366
+	 * @return array|bool
367
+	 * @throws \EE_Error
368
+	 */
369
+	public function get_all_event_question_groups($EVT_ID = 0)
370
+	{
371
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
372
+			EE_Error::add_error(
373
+				esc_html__(
374
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
375
+					'event_espresso'
376
+				),
377
+				__FILE__,
378
+				__FUNCTION__,
379
+				__LINE__
380
+			);
381
+			return false;
382
+		}
383
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
384
+			array(
385
+				array('EVT_ID' => $EVT_ID),
386
+			)
387
+		);
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * get_question_groups
394
+	 *
395
+	 * @param int     $EVT_ID
396
+	 * @param boolean $for_primary_attendee
397
+	 * @return array|bool
398
+	 * @throws \EE_Error
399
+	 */
400
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
401
+	{
402
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
403
+			EE_Error::add_error(
404
+				esc_html__(
405
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
406
+					'event_espresso'
407
+				),
408
+				__FILE__,
409
+				__FUNCTION__,
410
+				__LINE__
411
+			);
412
+			return false;
413
+		}
414
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
415
+			array(
416
+				array(
417
+					'EVT_ID'      => $EVT_ID,
418
+					'EQG_primary' => $for_primary_attendee,
419
+				),
420
+			)
421
+		);
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * get_question_groups
428
+	 *
429
+	 * @param int             $EVT_ID
430
+	 * @param EE_Registration $registration
431
+	 * @return array|bool
432
+	 * @throws \EE_Error
433
+	 */
434
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
435
+	{
436
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
437
+			EE_Error::add_error(
438
+				esc_html__(
439
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
440
+					'event_espresso'
441
+				),
442
+				__FILE__,
443
+				__FUNCTION__,
444
+				__LINE__
445
+			);
446
+			return false;
447
+		}
448
+		$where_params = array(
449
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
450
+			'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
451
+			'QSG_deleted'                      => false,
452
+		);
453
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
454
+			array(
455
+				$where_params,
456
+				'order_by' => array('QSG_order' => 'ASC'),
457
+			)
458
+		);
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 * get_question_target_db_column
465
+	 *
466
+	 * @param string $QSG_IDs csv list of $QSG IDs
467
+	 * @return array|bool
468
+	 * @throws \EE_Error
469
+	 */
470
+	public function get_questions_in_groups($QSG_IDs = '')
471
+	{
472
+		if (empty($QSG_IDs)) {
473
+			EE_Error::add_error(
474
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
475
+				__FILE__,
476
+				__FUNCTION__,
477
+				__LINE__
478
+			);
479
+			return false;
480
+		}
481
+		return EE_Registry::instance()->load_model('Question')->get_all(
482
+			array(
483
+				array(
484
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
485
+					'QST_deleted'           => false,
486
+					'QST_admin_only'        => is_admin(),
487
+				),
488
+				'order_by' => 'QST_order',
489
+			)
490
+		);
491
+	}
492
+
493
+
494
+
495
+	/**
496
+	 * get_options_for_question
497
+	 *
498
+	 * @param string $QST_IDs csv list of $QST IDs
499
+	 * @return array|bool
500
+	 * @throws \EE_Error
501
+	 */
502
+	public function get_options_for_question($QST_IDs)
503
+	{
504
+		if (empty($QST_IDs)) {
505
+			EE_Error::add_error(
506
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
507
+				__FILE__,
508
+				__FUNCTION__,
509
+				__LINE__
510
+			);
511
+			return false;
512
+		}
513
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
514
+			array(
515
+				array(
516
+					'Question.QST_ID' => array('IN', $QST_IDs),
517
+					'QSO_deleted'     => false,
518
+				),
519
+				'order_by' => 'QSO_ID',
520
+			)
521
+		);
522
+	}
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+	/**
531
+	 * Gets all events that are published
532
+	 * and have event start time earlier than now and an event end time later than now
533
+	 *
534
+	 * @param  array $query_params An array of query params to further filter on
535
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
536
+	 * @param bool   $count        whether to return the count or not (default FALSE)
537
+	 * @return EE_Event[]|int
538
+	 * @throws \EE_Error
539
+	 */
540
+	public function get_active_events($query_params, $count = false)
541
+	{
542
+		if (array_key_exists(0, $query_params)) {
543
+			$where_params = $query_params[0];
544
+			unset($query_params[0]);
545
+		} else {
546
+			$where_params = array();
547
+		}
548
+		// if we have count make sure we don't include group by
549
+		if ($count && isset($query_params['group_by'])) {
550
+			unset($query_params['group_by']);
551
+		}
552
+		// let's add specific query_params for active_events
553
+		// keep in mind this will override any sent status in the query AND any date queries.
554
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
555
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
556
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
557
+			$where_params['Datetime.DTT_EVT_start******'] = array(
558
+				'<',
559
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
560
+			);
561
+		} else {
562
+			$where_params['Datetime.DTT_EVT_start'] = array(
563
+				'<',
564
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
565
+			);
566
+		}
567
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
568
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
569
+				'>',
570
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
571
+			);
572
+		} else {
573
+			$where_params['Datetime.DTT_EVT_end'] = array(
574
+				'>',
575
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
576
+			);
577
+		}
578
+		$query_params[0] = $where_params;
579
+		// don't use $query_params with count()
580
+		// because we don't want to include additional query clauses like "GROUP BY"
581
+		return $count
582
+			? $this->count(array($where_params), 'EVT_ID', true)
583
+			: $this->get_all($query_params);
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * get all events that are published and have an event start time later than now
590
+	 *
591
+	 * @param  array $query_params An array of query params to further filter on
592
+	 *                             (Note that status and DTT_EVT_start will be overridden)
593
+	 * @param bool   $count        whether to return the count or not (default FALSE)
594
+	 * @return EE_Event[]|int
595
+	 * @throws \EE_Error
596
+	 */
597
+	public function get_upcoming_events($query_params, $count = false)
598
+	{
599
+		if (array_key_exists(0, $query_params)) {
600
+			$where_params = $query_params[0];
601
+			unset($query_params[0]);
602
+		} else {
603
+			$where_params = array();
604
+		}
605
+		// if we have count make sure we don't include group by
606
+		if ($count && isset($query_params['group_by'])) {
607
+			unset($query_params['group_by']);
608
+		}
609
+		// let's add specific query_params for active_events
610
+		// keep in mind this will override any sent status in the query AND any date queries.
611
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
612
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
613
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
614
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
615
+				'>',
616
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
617
+			);
618
+		} else {
619
+			$where_params['Datetime.DTT_EVT_start'] = array(
620
+				'>',
621
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
622
+			);
623
+		}
624
+		$query_params[0] = $where_params;
625
+		// don't use $query_params with count()
626
+		// because we don't want to include additional query clauses like "GROUP BY"
627
+		return $count
628
+			? $this->count(array($where_params), 'EVT_ID', true)
629
+			: $this->get_all($query_params);
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * Gets all events that are published
636
+	 * and have an event end time later than now
637
+	 *
638
+	 * @param  array $query_params An array of query params to further filter on
639
+	 *                             (note that status and DTT_EVT_end will be overridden)
640
+	 * @param bool   $count        whether to return the count or not (default FALSE)
641
+	 * @return EE_Event[]|int
642
+	 * @throws \EE_Error
643
+	 */
644
+	public function get_active_and_upcoming_events($query_params, $count = false)
645
+	{
646
+		if (array_key_exists(0, $query_params)) {
647
+			$where_params = $query_params[0];
648
+			unset($query_params[0]);
649
+		} else {
650
+			$where_params = array();
651
+		}
652
+		// if we have count make sure we don't include group by
653
+		if ($count && isset($query_params['group_by'])) {
654
+			unset($query_params['group_by']);
655
+		}
656
+		// let's add specific query_params for active_events
657
+		// keep in mind this will override any sent status in the query AND any date queries.
658
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
659
+		// add where params for DTT_EVT_end
660
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
661
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
662
+				'>',
663
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
664
+			);
665
+		} else {
666
+			$where_params['Datetime.DTT_EVT_end'] = array(
667
+				'>',
668
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
669
+			);
670
+		}
671
+		$query_params[0] = $where_params;
672
+		// don't use $query_params with count()
673
+		// because we don't want to include additional query clauses like "GROUP BY"
674
+		return $count
675
+			? $this->count(array($where_params), 'EVT_ID', true)
676
+			: $this->get_all($query_params);
677
+	}
678
+
679
+
680
+
681
+	/**
682
+	 * This only returns events that are expired.
683
+	 * They may still be published but all their datetimes have expired.
684
+	 *
685
+	 * @param  array $query_params An array of query params to further filter on
686
+	 *                             (note that status and DTT_EVT_end will be overridden)
687
+	 * @param bool   $count        whether to return the count or not (default FALSE)
688
+	 * @return EE_Event[]|int
689
+	 * @throws \EE_Error
690
+	 */
691
+	public function get_expired_events($query_params, $count = false)
692
+	{
693
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
694
+		// if we have count make sure we don't include group by
695
+		if ($count && isset($query_params['group_by'])) {
696
+			unset($query_params['group_by']);
697
+		}
698
+		// let's add specific query_params for active_events
699
+		// keep in mind this will override any sent status in the query AND any date queries.
700
+		if (isset($where_params['status'])) {
701
+			unset($where_params['status']);
702
+		}
703
+		$exclude_query = $query_params;
704
+		if (isset($exclude_query[0])) {
705
+			unset($exclude_query[0]);
706
+		}
707
+		$exclude_query[0] = array(
708
+			'Datetime.DTT_EVT_end' => array(
709
+				'>',
710
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
711
+			),
712
+		);
713
+		// first get all events that have datetimes where its not expired.
714
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
715
+		$event_ids = array_keys($event_ids);
716
+		// if we have any additional query_params, let's add them to the 'AND' condition
717
+		$and_condition = array(
718
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
719
+			'EVT_ID'               => array('NOT IN', $event_ids),
720
+		);
721
+		if (isset($where_params['OR'])) {
722
+			$and_condition['OR'] = $where_params['OR'];
723
+			unset($where_params['OR']);
724
+		}
725
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
726
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
727
+			unset($where_params['Datetime.DTT_EVT_end']);
728
+		}
729
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
730
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
731
+			unset($where_params['Datetime.DTT_EVT_start']);
732
+		}
733
+		// merge remaining $where params with the and conditions.
734
+		$where_params['AND'] = array_merge($and_condition, $where_params);
735
+		$query_params[0] = $where_params;
736
+		// don't use $query_params with count()
737
+		// because we don't want to include additional query clauses like "GROUP BY"
738
+		return $count
739
+			? $this->count(array($where_params), 'EVT_ID', true)
740
+			: $this->get_all($query_params);
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 * This basically just returns the events that do not have the publish status.
747
+	 *
748
+	 * @param  array   $query_params An array of query params to further filter on
749
+	 *                               (note that status will be overwritten)
750
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
751
+	 * @return EE_Event[]|int
752
+	 * @throws \EE_Error
753
+	 */
754
+	public function get_inactive_events($query_params, $count = false)
755
+	{
756
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
757
+		// let's add in specific query_params for inactive events.
758
+		if (isset($where_params['status'])) {
759
+			unset($where_params['status']);
760
+		}
761
+		// if we have count make sure we don't include group by
762
+		if ($count && isset($query_params['group_by'])) {
763
+			unset($query_params['group_by']);
764
+		}
765
+		// if we have any additional query_params, let's add them to the 'AND' condition
766
+		$where_params['AND']['status'] = array('!=', 'publish');
767
+		if (isset($where_params['OR'])) {
768
+			$where_params['AND']['OR'] = $where_params['OR'];
769
+			unset($where_params['OR']);
770
+		}
771
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
772
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
773
+			unset($where_params['Datetime.DTT_EVT_end']);
774
+		}
775
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
776
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
777
+			unset($where_params['Datetime.DTT_EVT_start']);
778
+		}
779
+		$query_params[0] = $where_params;
780
+		// don't use $query_params with count()
781
+		// because we don't want to include additional query clauses like "GROUP BY"
782
+		return $count
783
+			? $this->count(array($where_params), 'EVT_ID', true)
784
+			: $this->get_all($query_params);
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
791
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
792
+	 * attached to the event. See parent for param descriptions
793
+	 *
794
+	 * @param        $id_or_obj
795
+	 * @param        $other_model_id_or_obj
796
+	 * @param string $relationName
797
+	 * @param array  $where_query
798
+	 * @return EE_Base_Class
799
+	 * @throws EE_Error
800
+	 */
801
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
802
+	{
803
+		if ($relationName === 'Price') {
804
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
805
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
806
+			// if EVT_ID = 0, then this is a default
807
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
808
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
809
+				$prc_chk->set('PRC_ID', 0);
810
+			}
811
+			// run parent
812
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
813
+		}
814
+		// otherwise carry on as normal
815
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
816
+	}
817
+
818
+
819
+
820
+	/******************** DEPRECATED METHODS ********************/
821
+
822
+
823
+
824
+	/**
825
+	 * _get_question_target_db_column
826
+	 *
827
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
828
+	 *             EE_Registration_Custom_Questions_Form located in
829
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
830
+	 * @access     public
831
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
832
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
833
+	 *                                         registration).
834
+	 * @throws EE_Error
835
+	 * @return    array
836
+	 */
837
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
838
+	{
839
+		if (empty($EVT_ID)) {
840
+			throw new EE_Error(__(
841
+				'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
842
+				'event_espresso'
843
+			));
844
+		}
845
+		$questions = array();
846
+		// get all question groups for event
847
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
848
+		if (! empty($qgs)) {
849
+			foreach ($qgs as $qg) {
850
+				$qsts = $qg->questions();
851
+				$questions[ $qg->ID() ] = $qg->model_field_array();
852
+				$questions[ $qg->ID() ]['QSG_questions'] = array();
853
+				foreach ($qsts as $qst) {
854
+					if ($qst->is_system_question()) {
855
+						continue;
856
+					}
857
+					$answer = EEM_Answer::instance()->get_one(array(
858
+						array(
859
+							'QST_ID' => $qst->ID(),
860
+							'REG_ID' => $registration->ID(),
861
+						),
862
+					));
863
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
864
+					$qst_name = $qstn_id = $qst->ID();
865
+					$ans_id = $answer->ID();
866
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
867
+					$input_name = '';
868
+					$input_id = sanitize_key($qst->display_text());
869
+					$input_class = '';
870
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
871
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
872
+																						   . $input_name
873
+																						   . $qst_name;
874
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
875
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
876
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
877
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
878
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
879
+					// leave responses as-is, don't convert stuff into html entities please!
880
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
881
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
882
+						$QSOs = $qst->options(true, $answer->value());
883
+						if (is_array($QSOs)) {
884
+							foreach ($QSOs as $QSO_ID => $QSO) {
885
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
886
+							}
887
+						}
888
+					}
889
+				}
890
+			}
891
+		}
892
+		return $questions;
893
+	}
894
+
895
+
896
+	/**
897
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
898
+	 *                             or an stdClass where each property is the name of a column,
899
+	 * @return EE_Base_Class
900
+	 * @throws \EE_Error
901
+	 */
902
+	public function instantiate_class_from_array_or_object($cols_n_values)
903
+	{
904
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
905
+		if ($classInstance instanceof EE_Event) {
906
+			// events have their timezone defined in the DB, so use it immediately
907
+			$this->set_timezone($classInstance->get_timezone());
908
+		}
909
+		return $classInstance;
910
+	}
911 911
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
             'WP_User'                => new EE_Belongs_To_Relation(),
276 276
         );
277 277
         // this model is generally available for reading
278
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
278
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
279 279
         $this->model_chain_to_password = '';
280 280
         parent::__construct($timezone);
281 281
     }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public function get_all_event_question_groups($EVT_ID = 0)
370 370
     {
371
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
371
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
372 372
             EE_Error::add_error(
373 373
                 esc_html__(
374 374
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      */
400 400
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
401 401
     {
402
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
402
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
403 403
             EE_Error::add_error(
404 404
                 esc_html__(
405 405
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
      */
434 434
     public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
435 435
     {
436
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
436
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
437 437
             EE_Error::add_error(
438 438
                 esc_html__(
439 439
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -845,11 +845,11 @@  discard block
 block discarded – undo
845 845
         $questions = array();
846 846
         // get all question groups for event
847 847
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
848
-        if (! empty($qgs)) {
848
+        if ( ! empty($qgs)) {
849 849
             foreach ($qgs as $qg) {
850 850
                 $qsts = $qg->questions();
851
-                $questions[ $qg->ID() ] = $qg->model_field_array();
852
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
851
+                $questions[$qg->ID()] = $qg->model_field_array();
852
+                $questions[$qg->ID()]['QSG_questions'] = array();
853 853
                 foreach ($qsts as $qst) {
854 854
                     if ($qst->is_system_question()) {
855 855
                         continue;
@@ -863,26 +863,26 @@  discard block
 block discarded – undo
863 863
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
864 864
                     $qst_name = $qstn_id = $qst->ID();
865 865
                     $ans_id = $answer->ID();
866
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
866
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
867 867
                     $input_name = '';
868 868
                     $input_id = sanitize_key($qst->display_text());
869 869
                     $input_class = '';
870
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
871
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
870
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
871
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
872 872
                                                                                            . $input_name
873 873
                                                                                            . $qst_name;
874
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
875
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
876
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
877
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
878
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
874
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
875
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
876
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
877
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
878
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
879 879
                     // leave responses as-is, don't convert stuff into html entities please!
880
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
880
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
881 881
                     if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
882 882
                         $QSOs = $qst->options(true, $answer->value());
883 883
                         if (is_array($QSOs)) {
884 884
                             foreach ($QSOs as $QSO_ID => $QSO) {
885
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
885
+                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
886 886
                             }
887 887
                         }
888 888
                     }
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -10,189 +10,189 @@
 block discarded – undo
10 10
 class EEM_Venue extends EEM_CPT_Base
11 11
 {
12 12
 
13
-    // private instance of the Attendee object
14
-    protected static $_instance = null;
13
+	// private instance of the Attendee object
14
+	protected static $_instance = null;
15 15
 
16 16
 
17 17
 
18
-    protected function __construct($timezone = null)
19
-    {
20
-        $this->singular_item = __('Venue', 'event_espresso');
21
-        $this->plural_item = __('Venues', 'event_espresso');
22
-        $this->_tables = array(
23
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
24
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
25
-        );
26
-        $this->_fields = array(
27
-            'Venue_CPT'  => array(
28
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
29
-                'VNU_name'       => new EE_Plain_Text_Field(
30
-                    'post_title',
31
-                    __("Venue Name", "event_espresso"),
32
-                    false,
33
-                    ''
34
-                ),
35
-                'VNU_desc'       => new EE_Post_Content_Field(
36
-                    'post_content',
37
-                    __("Venue Description", "event_espresso"),
38
-                    false,
39
-                    ''
40
-                ),
41
-                'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
42
-                'VNU_created'    => new EE_Datetime_Field(
43
-                    'post_date',
44
-                    __("Date Venue Created", "event_espresso"),
45
-                    false,
46
-                    EE_Datetime_Field::now
47
-                ),
48
-                'VNU_short_desc' => new EE_Plain_Text_Field(
49
-                    'post_excerpt',
50
-                    __("Short Description of Venue", "event_espresso"),
51
-                    true,
52
-                    ''
53
-                ),
54
-                'VNU_modified'   => new EE_Datetime_Field(
55
-                    'post_modified',
56
-                    __("Venue Modified Date", "event_espresso"),
57
-                    false,
58
-                    EE_Datetime_Field::now
59
-                ),
60
-                'VNU_wp_user'    => new EE_WP_User_Field(
61
-                    'post_author',
62
-                    __("Venue Creator ID", "event_espresso"),
63
-                    false
64
-                ),
65
-                'parent'         => new EE_Integer_Field(
66
-                    'post_parent',
67
-                    __("Venue Parent ID", "event_espresso"),
68
-                    false,
69
-                    0
70
-                ),
71
-                'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
72
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
73
-                'password' => new EE_Password_Field(
74
-                    'post_password',
75
-                    __('Password', 'event_espresso'),
76
-                    false,
77
-                    '',
78
-                    array(
79
-                        'VNU_desc',
80
-                        'VNU_short_desc',
81
-                        'VNU_address',
82
-                        'VNU_address2',
83
-                        'VNU_city',
84
-                        'STA_ID',
85
-                        'CNT_ISO',
86
-                        'VNU_zip',
87
-                        'VNU_phone',
88
-                        'VNU_capacity',
89
-                        'VNU_url',
90
-                        'VNU_virtual_phone',
91
-                        'VNU_virtual_url',
92
-                        'VNU_google_map_link',
93
-                        'VNU_enable_for_gmap',
94
-                    )
95
-                )
96
-            ),
97
-            'Venue_Meta' => array(
98
-                'VNUM_ID'             => new EE_DB_Only_Int_Field(
99
-                    'VNUM_ID',
100
-                    __("ID of Venue Meta Row", "event_espresso"),
101
-                    false
102
-                ),
103
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
104
-                    'VNU_ID',
105
-                    __("Foreign Key to Venue Post ", "event_espresso"),
106
-                    false
107
-                ),
108
-                'VNU_address'         => new EE_Plain_Text_Field(
109
-                    'VNU_address',
110
-                    __("Venue Address line 1", "event_espresso"),
111
-                    true,
112
-                    ''
113
-                ),
114
-                'VNU_address2'        => new EE_Plain_Text_Field(
115
-                    'VNU_address2',
116
-                    __("Venue Address line 2", "event_espresso"),
117
-                    true,
118
-                    ''
119
-                ),
120
-                'VNU_city'            => new EE_Plain_Text_Field(
121
-                    'VNU_city',
122
-                    __("Venue City", "event_espresso"),
123
-                    true,
124
-                    ''
125
-                ),
126
-                'STA_ID'              => new EE_Foreign_Key_Int_Field(
127
-                    'STA_ID',
128
-                    __("State ID", "event_espresso"),
129
-                    true,
130
-                    null,
131
-                    'State'
132
-                ),
133
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field(
134
-                    'CNT_ISO',
135
-                    __("Country Code", "event_espresso"),
136
-                    true,
137
-                    null,
138
-                    'Country'
139
-                ),
140
-                'VNU_zip'             => new EE_Plain_Text_Field(
141
-                    'VNU_zip',
142
-                    __("Venue Zip/Postal Code", "event_espresso"),
143
-                    true
144
-                ),
145
-                'VNU_phone'           => new EE_Plain_Text_Field(
146
-                    'VNU_phone',
147
-                    __("Venue Phone", "event_espresso"),
148
-                    true
149
-                ),
150
-                'VNU_capacity'        => new EE_Infinite_Integer_Field(
151
-                    'VNU_capacity',
152
-                    __("Venue Capacity", "event_espresso"),
153
-                    true,
154
-                    EE_INF
155
-                ),
156
-                'VNU_url'             => new EE_Plain_Text_Field(
157
-                    'VNU_url',
158
-                    __('Venue Website', 'event_espresso'),
159
-                    true
160
-                ),
161
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field(
162
-                    'VNU_virtual_phone',
163
-                    __('Call in Number', 'event_espresso'),
164
-                    true
165
-                ),
166
-                'VNU_virtual_url'     => new EE_Plain_Text_Field(
167
-                    'VNU_virtual_url',
168
-                    __('Virtual URL', 'event_espresso'),
169
-                    true
170
-                ),
171
-                'VNU_google_map_link' => new EE_Plain_Text_Field(
172
-                    'VNU_google_map_link',
173
-                    __('Google Map Link', 'event_espresso'),
174
-                    true
175
-                ),
176
-                'VNU_enable_for_gmap' => new EE_Boolean_Field(
177
-                    'VNU_enable_for_gmap',
178
-                    __('Show Google Map?', 'event_espresso'),
179
-                    false,
180
-                    false
181
-                ),
182
-            ),
183
-        );
184
-        $this->_model_relations = array(
185
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
186
-            'State'             => new EE_Belongs_To_Relation(),
187
-            'Country'           => new EE_Belongs_To_Relation(),
188
-            'Event_Venue'       => new EE_Has_Many_Relation(),
189
-            'WP_User'           => new EE_Belongs_To_Relation(),
190
-            'Term_Relationship' => new EE_Has_Many_Relation(),
191
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
192
-        );
193
-        // this model is generally available for reading
194
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
195
-        $this->model_chain_to_password = '';
196
-        parent::__construct($timezone);
197
-    }
18
+	protected function __construct($timezone = null)
19
+	{
20
+		$this->singular_item = __('Venue', 'event_espresso');
21
+		$this->plural_item = __('Venues', 'event_espresso');
22
+		$this->_tables = array(
23
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
24
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
25
+		);
26
+		$this->_fields = array(
27
+			'Venue_CPT'  => array(
28
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
29
+				'VNU_name'       => new EE_Plain_Text_Field(
30
+					'post_title',
31
+					__("Venue Name", "event_espresso"),
32
+					false,
33
+					''
34
+				),
35
+				'VNU_desc'       => new EE_Post_Content_Field(
36
+					'post_content',
37
+					__("Venue Description", "event_espresso"),
38
+					false,
39
+					''
40
+				),
41
+				'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
42
+				'VNU_created'    => new EE_Datetime_Field(
43
+					'post_date',
44
+					__("Date Venue Created", "event_espresso"),
45
+					false,
46
+					EE_Datetime_Field::now
47
+				),
48
+				'VNU_short_desc' => new EE_Plain_Text_Field(
49
+					'post_excerpt',
50
+					__("Short Description of Venue", "event_espresso"),
51
+					true,
52
+					''
53
+				),
54
+				'VNU_modified'   => new EE_Datetime_Field(
55
+					'post_modified',
56
+					__("Venue Modified Date", "event_espresso"),
57
+					false,
58
+					EE_Datetime_Field::now
59
+				),
60
+				'VNU_wp_user'    => new EE_WP_User_Field(
61
+					'post_author',
62
+					__("Venue Creator ID", "event_espresso"),
63
+					false
64
+				),
65
+				'parent'         => new EE_Integer_Field(
66
+					'post_parent',
67
+					__("Venue Parent ID", "event_espresso"),
68
+					false,
69
+					0
70
+				),
71
+				'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
72
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
73
+				'password' => new EE_Password_Field(
74
+					'post_password',
75
+					__('Password', 'event_espresso'),
76
+					false,
77
+					'',
78
+					array(
79
+						'VNU_desc',
80
+						'VNU_short_desc',
81
+						'VNU_address',
82
+						'VNU_address2',
83
+						'VNU_city',
84
+						'STA_ID',
85
+						'CNT_ISO',
86
+						'VNU_zip',
87
+						'VNU_phone',
88
+						'VNU_capacity',
89
+						'VNU_url',
90
+						'VNU_virtual_phone',
91
+						'VNU_virtual_url',
92
+						'VNU_google_map_link',
93
+						'VNU_enable_for_gmap',
94
+					)
95
+				)
96
+			),
97
+			'Venue_Meta' => array(
98
+				'VNUM_ID'             => new EE_DB_Only_Int_Field(
99
+					'VNUM_ID',
100
+					__("ID of Venue Meta Row", "event_espresso"),
101
+					false
102
+				),
103
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
104
+					'VNU_ID',
105
+					__("Foreign Key to Venue Post ", "event_espresso"),
106
+					false
107
+				),
108
+				'VNU_address'         => new EE_Plain_Text_Field(
109
+					'VNU_address',
110
+					__("Venue Address line 1", "event_espresso"),
111
+					true,
112
+					''
113
+				),
114
+				'VNU_address2'        => new EE_Plain_Text_Field(
115
+					'VNU_address2',
116
+					__("Venue Address line 2", "event_espresso"),
117
+					true,
118
+					''
119
+				),
120
+				'VNU_city'            => new EE_Plain_Text_Field(
121
+					'VNU_city',
122
+					__("Venue City", "event_espresso"),
123
+					true,
124
+					''
125
+				),
126
+				'STA_ID'              => new EE_Foreign_Key_Int_Field(
127
+					'STA_ID',
128
+					__("State ID", "event_espresso"),
129
+					true,
130
+					null,
131
+					'State'
132
+				),
133
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field(
134
+					'CNT_ISO',
135
+					__("Country Code", "event_espresso"),
136
+					true,
137
+					null,
138
+					'Country'
139
+				),
140
+				'VNU_zip'             => new EE_Plain_Text_Field(
141
+					'VNU_zip',
142
+					__("Venue Zip/Postal Code", "event_espresso"),
143
+					true
144
+				),
145
+				'VNU_phone'           => new EE_Plain_Text_Field(
146
+					'VNU_phone',
147
+					__("Venue Phone", "event_espresso"),
148
+					true
149
+				),
150
+				'VNU_capacity'        => new EE_Infinite_Integer_Field(
151
+					'VNU_capacity',
152
+					__("Venue Capacity", "event_espresso"),
153
+					true,
154
+					EE_INF
155
+				),
156
+				'VNU_url'             => new EE_Plain_Text_Field(
157
+					'VNU_url',
158
+					__('Venue Website', 'event_espresso'),
159
+					true
160
+				),
161
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field(
162
+					'VNU_virtual_phone',
163
+					__('Call in Number', 'event_espresso'),
164
+					true
165
+				),
166
+				'VNU_virtual_url'     => new EE_Plain_Text_Field(
167
+					'VNU_virtual_url',
168
+					__('Virtual URL', 'event_espresso'),
169
+					true
170
+				),
171
+				'VNU_google_map_link' => new EE_Plain_Text_Field(
172
+					'VNU_google_map_link',
173
+					__('Google Map Link', 'event_espresso'),
174
+					true
175
+				),
176
+				'VNU_enable_for_gmap' => new EE_Boolean_Field(
177
+					'VNU_enable_for_gmap',
178
+					__('Show Google Map?', 'event_espresso'),
179
+					false,
180
+					false
181
+				),
182
+			),
183
+		);
184
+		$this->_model_relations = array(
185
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
186
+			'State'             => new EE_Belongs_To_Relation(),
187
+			'Country'           => new EE_Belongs_To_Relation(),
188
+			'Event_Venue'       => new EE_Has_Many_Relation(),
189
+			'WP_User'           => new EE_Belongs_To_Relation(),
190
+			'Term_Relationship' => new EE_Has_Many_Relation(),
191
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
192
+		);
193
+		// this model is generally available for reading
194
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
195
+		$this->model_chain_to_password = '';
196
+		parent::__construct($timezone);
197
+	}
198 198
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@
 block discarded – undo
191 191
             'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
192 192
         );
193 193
         // this model is generally available for reading
194
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
194
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
195 195
         $this->model_chain_to_password = '';
196 196
         parent::__construct($timezone);
197 197
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Question_Group.model.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -7,34 +7,34 @@
 block discarded – undo
7 7
  */
8 8
 class EEM_Event_Question_Group extends EEM_Base
9 9
 {
10
-    // private instance of the Attendee object
11
-    protected static $_instance = null;
10
+	// private instance of the Attendee object
11
+	protected static $_instance = null;
12 12
 
13
-    protected function __construct($timezone = null)
14
-    {
15
-        $this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
-        $this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
-        $this->_tables = array(
18
-            'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID')
19
-        );
20
-        $this->_fields = array(
21
-            'Event_Question_Group'=>array(
22
-                'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')),
23
-                'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
-                'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'),
25
-                'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false)
26
-            )
27
-        );
28
-        $this->_model_relations = array(
29
-            'Event'=>new EE_Belongs_To_Relation(),
30
-            'Question_Group'=>new EE_Belongs_To_Relation()
31
-        );
32
-        // this model is generally available for reading
33
-        $path_to_event = 'Event';
34
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
38
-        parent::__construct($timezone);
39
-    }
13
+	protected function __construct($timezone = null)
14
+	{
15
+		$this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
+		$this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
+		$this->_tables = array(
18
+			'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID')
19
+		);
20
+		$this->_fields = array(
21
+			'Event_Question_Group'=>array(
22
+				'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')),
23
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
+				'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'),
25
+				'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false)
26
+			)
27
+		);
28
+		$this->_model_relations = array(
29
+			'Event'=>new EE_Belongs_To_Relation(),
30
+			'Question_Group'=>new EE_Belongs_To_Relation()
31
+		);
32
+		// this model is generally available for reading
33
+		$path_to_event = 'Event';
34
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
38
+		parent::__construct($timezone);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,10 +31,10 @@
 block discarded – undo
31 31
         );
32 32
         // this model is generally available for reading
33 33
         $path_to_event = 'Event';
34
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
34
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
38 38
         parent::__construct($timezone);
39 39
     }
40 40
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Message_Template.model.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -1,95 +1,95 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
  /**
4
- *  EEM_Event_Message_Template
5
- *  Model for relation table between EEM_Message_Template_Group and EEM_Event
6
- *
7
- * @package     Event Espresso
8
- * @subpackage  models
9
- * @since           4.3.0
10
- * @author           Darren Ethier
11
- *
12
- * ------------------------------------------------------------------------
13
- */
4
+  *  EEM_Event_Message_Template
5
+  *  Model for relation table between EEM_Message_Template_Group and EEM_Event
6
+  *
7
+  * @package     Event Espresso
8
+  * @subpackage  models
9
+  * @since           4.3.0
10
+  * @author           Darren Ethier
11
+  *
12
+  * ------------------------------------------------------------------------
13
+  */
14 14
 class EEM_Event_Message_Template extends EEM_Base
15 15
 {
16 16
 
17
-    // private instance of the EEM_Event_Message_Template object
18
-    protected static $_instance = null;
17
+	// private instance of the EEM_Event_Message_Template object
18
+	protected static $_instance = null;
19 19
 
20
-    /**
21
-     * private constructor to prevent direct creation
22
-     * @Constructor
23
-     * @access private
24
-     * @return void
25
-     */
26
-    protected function __construct($timezone = null)
27
-    {
28
-        $this->singlular_item = __('Event Message Template', 'event_espresso');
29
-        $this->plural_item = __('Event Message Templates', 'event_espresso');
20
+	/**
21
+	 * private constructor to prevent direct creation
22
+	 * @Constructor
23
+	 * @access private
24
+	 * @return void
25
+	 */
26
+	protected function __construct($timezone = null)
27
+	{
28
+		$this->singlular_item = __('Event Message Template', 'event_espresso');
29
+		$this->plural_item = __('Event Message Templates', 'event_espresso');
30 30
 
31
-        $this->_tables = array(
32
-            'Event_Message_Template'=> new EE_Primary_Table('esp_event_message_template', 'EMT_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Event_Message_Template'=>array(
36
-                'EMT_ID'=>new EE_Primary_Key_Int_Field('EMT_ID', __('Event Message Template ID', 'event_espresso')),
37
-                'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('The ID to the Event', 'event_espresso'), false, 0, 'Event'),
38
-                'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('The ID to the Message Template Group', 'event_espresso'), false, 0, 'Message_Template_Group')
39
-            ));
40
-        $this->_model_relations = array(
41
-            'Event'=>new EE_Belongs_To_Relation(),
42
-            'Message_Template_Group'=>new EE_Belongs_To_Relation()
43
-        );
44
-        $path_to_event = 'Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
-        parent::__construct($timezone);
50
-    }
31
+		$this->_tables = array(
32
+			'Event_Message_Template'=> new EE_Primary_Table('esp_event_message_template', 'EMT_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Event_Message_Template'=>array(
36
+				'EMT_ID'=>new EE_Primary_Key_Int_Field('EMT_ID', __('Event Message Template ID', 'event_espresso')),
37
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('The ID to the Event', 'event_espresso'), false, 0, 'Event'),
38
+				'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('The ID to the Message Template Group', 'event_espresso'), false, 0, 'Message_Template_Group')
39
+			));
40
+		$this->_model_relations = array(
41
+			'Event'=>new EE_Belongs_To_Relation(),
42
+			'Message_Template_Group'=>new EE_Belongs_To_Relation()
43
+		);
44
+		$path_to_event = 'Event';
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
+		parent::__construct($timezone);
50
+	}
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     * helper method to simply return an array of event ids for events attached to the given
56
-     * message template group.
57
-     *
58
-     * @since 4.3.0
59
-     *
60
-     * @param  int    $GRP_ID The MTP group we want attached events for.
61
-     * @return  array               An array of event ids.
62
-     */
63
-    public function get_attached_event_ids($GRP_ID)
64
-    {
65
-        $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID');
66
-        $event_ids = call_user_func_array('array_merge', $event_ids);
67
-        return $event_ids;
68
-    }
54
+	/**
55
+	 * helper method to simply return an array of event ids for events attached to the given
56
+	 * message template group.
57
+	 *
58
+	 * @since 4.3.0
59
+	 *
60
+	 * @param  int    $GRP_ID The MTP group we want attached events for.
61
+	 * @return  array               An array of event ids.
62
+	 */
63
+	public function get_attached_event_ids($GRP_ID)
64
+	{
65
+		$event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID');
66
+		$event_ids = call_user_func_array('array_merge', $event_ids);
67
+		return $event_ids;
68
+	}
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * helper method for clearing event/group relations for the given event ids and grp ids.
74
-     * @param  array $GRP_IDs  An array of GRP_IDs. Optional. If empty then there must be EVTIDs.
75
-     * @param  array $EVT_IDs  An array of EVT_IDs.  Optional. If empty then there must be
76
-     *                                 GRPIDs.
77
-     * @return int             How many rows were deleted.
78
-     */
79
-    public function delete_event_group_relations($GRP_IDs = array(), $EVT_IDs = array())
80
-    {
81
-        if (empty($GRP_IDs) && empty($EVT_IDs)) {
82
-            throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__));
83
-        }
72
+	/**
73
+	 * helper method for clearing event/group relations for the given event ids and grp ids.
74
+	 * @param  array $GRP_IDs  An array of GRP_IDs. Optional. If empty then there must be EVTIDs.
75
+	 * @param  array $EVT_IDs  An array of EVT_IDs.  Optional. If empty then there must be
76
+	 *                                 GRPIDs.
77
+	 * @return int             How many rows were deleted.
78
+	 */
79
+	public function delete_event_group_relations($GRP_IDs = array(), $EVT_IDs = array())
80
+	{
81
+		if (empty($GRP_IDs) && empty($EVT_IDs)) {
82
+			throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__));
83
+		}
84 84
 
85
-        if (!empty($GRP_IDs)) {
86
-            $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs );
87
-        }
85
+		if (!empty($GRP_IDs)) {
86
+			$where['GRP_ID'] = array( 'IN', (array) $GRP_IDs );
87
+		}
88 88
 
89
-        if (!empty($EVT_IDs)) {
90
-            $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs );
91
-        }
89
+		if (!empty($EVT_IDs)) {
90
+			$where['EVT_ID'] = array( 'IN', (array) $EVT_IDs );
91
+		}
92 92
 
93
-        return $this->delete(array( $where ), false);
94
-    }
93
+		return $this->delete(array( $where ), false);
94
+	}
95 95
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
             'Message_Template_Group'=>new EE_Belongs_To_Relation()
43 43
         );
44 44
         $path_to_event = 'Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49 49
         parent::__construct($timezone);
50 50
     }
51 51
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      */
63 63
     public function get_attached_event_ids($GRP_ID)
64 64
     {
65
-        $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID');
65
+        $event_ids = $this->_get_all_wpdb_results(array(array('GRP_ID' => $GRP_ID)), ARRAY_N, 'EVT_ID');
66 66
         $event_ids = call_user_func_array('array_merge', $event_ids);
67 67
         return $event_ids;
68 68
     }
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
             throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__));
83 83
         }
84 84
 
85
-        if (!empty($GRP_IDs)) {
86
-            $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs );
85
+        if ( ! empty($GRP_IDs)) {
86
+            $where['GRP_ID'] = array('IN', (array) $GRP_IDs);
87 87
         }
88 88
 
89
-        if (!empty($EVT_IDs)) {
90
-            $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs );
89
+        if ( ! empty($EVT_IDs)) {
90
+            $where['EVT_ID'] = array('IN', (array) $EVT_IDs);
91 91
         }
92 92
 
93
-        return $this->delete(array( $where ), false);
93
+        return $this->delete(array($where), false);
94 94
     }
95 95
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Venue.model.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@
 block discarded – undo
7 7
  */
8 8
 class EEM_Event_Venue extends EEM_Base
9 9
 {
10
-    // private instance of the Attendee object
11
-    protected static $_instance = null;
10
+	// private instance of the Attendee object
11
+	protected static $_instance = null;
12 12
 
13
-    protected function __construct($timezone = null)
14
-    {
15
-        $this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
-        $this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
-        $this->_tables = array(
18
-            'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID')
19
-        );
20
-        $this->_fields = array(
21
-            'Event_Venue'=>array(
22
-                'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')),
23
-                'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
-                'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'),
25
-                'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true)
13
+	protected function __construct($timezone = null)
14
+	{
15
+		$this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
+		$this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
+		$this->_tables = array(
18
+			'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID')
19
+		);
20
+		$this->_fields = array(
21
+			'Event_Venue'=>array(
22
+				'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')),
23
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
+				'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'),
25
+				'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true)
26 26
 
27
-            )
28
-        );
29
-        $this->_model_relations = array(
30
-            'Event'=>new EE_Belongs_To_Relation(),
31
-            'Venue'=>new EE_Belongs_To_Relation()
32
-        );
33
-        // this model is generally available for reading
34
-        $path_to_event = 'Event';
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39
-        $this->model_chain_to_password = $path_to_event;
40
-        parent::__construct($timezone);
41
-    }
27
+			)
28
+		);
29
+		$this->_model_relations = array(
30
+			'Event'=>new EE_Belongs_To_Relation(),
31
+			'Venue'=>new EE_Belongs_To_Relation()
32
+		);
33
+		// this model is generally available for reading
34
+		$path_to_event = 'Event';
35
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39
+		$this->model_chain_to_password = $path_to_event;
40
+		parent::__construct($timezone);
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
         );
33 33
         // this model is generally available for reading
34 34
         $path_to_event = 'Event';
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
35
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39 39
         $this->model_chain_to_password = $path_to_event;
40 40
         parent::__construct($timezone);
41 41
     }
Please login to merge, or discard this patch.