1
|
|
|
<?php |
2
|
|
|
use EventEspresso\core\services\loaders\Loader; |
3
|
|
|
use EventEspresso\core\services\orm\ModelFieldFactory; |
4
|
|
|
|
5
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Attendee Model |
12
|
|
|
* |
13
|
|
|
* @package Event Espresso |
14
|
|
|
* @subpackage includes/models/ |
15
|
|
|
* @author Mike Nelson, Brent Christensen |
16
|
|
|
*/ |
17
|
|
|
class EEM_Attendee extends EEM_CPT_Base |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
// private instance of the Attendee object |
21
|
|
|
protected static $_instance = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* QST_system for questions are strings not integers now, |
25
|
|
|
* so these constants are deprecated. |
26
|
|
|
* Please instead use the EEM_Attendee::system_question_* constants |
27
|
|
|
* |
28
|
|
|
* @deprecated |
29
|
|
|
*/ |
30
|
|
|
const fname_question_id = 1; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @deprecated |
34
|
|
|
*/ |
35
|
|
|
const lname_question_id = 2; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @deprecated |
40
|
|
|
*/ |
41
|
|
|
const email_question_id = 3; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @deprecated |
46
|
|
|
*/ |
47
|
|
|
const address_question_id = 4; |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @deprecated |
52
|
|
|
*/ |
53
|
|
|
const address2_question_id = 5; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @deprecated |
58
|
|
|
*/ |
59
|
|
|
const city_question_id = 6; |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @deprecated |
64
|
|
|
*/ |
65
|
|
|
const state_question_id = 7; |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @deprecated |
70
|
|
|
*/ |
71
|
|
|
const country_question_id = 8; |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @deprecated |
76
|
|
|
*/ |
77
|
|
|
const zip_question_id = 9; |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @deprecated |
82
|
|
|
*/ |
83
|
|
|
const phone_question_id = 10; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* When looking for questions that correspond to attendee fields, |
87
|
|
|
* look for the question with this QST_system value. |
88
|
|
|
* These replace the old constants like EEM_Attendee::*_question_id |
89
|
|
|
*/ |
90
|
|
|
const system_question_fname = 'fname'; |
91
|
|
|
|
92
|
|
|
const system_question_lname = 'lname'; |
93
|
|
|
|
94
|
|
|
const system_question_email = 'email'; |
95
|
|
|
|
96
|
|
|
const system_question_address = 'address'; |
97
|
|
|
|
98
|
|
|
const system_question_address2 = 'address2'; |
99
|
|
|
|
100
|
|
|
const system_question_city = 'city'; |
101
|
|
|
|
102
|
|
|
const system_question_state = 'state'; |
103
|
|
|
|
104
|
|
|
const system_question_country = 'country'; |
105
|
|
|
|
106
|
|
|
const system_question_zip = 'zip'; |
107
|
|
|
|
108
|
|
|
const system_question_phone = 'phone'; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Keys are all the EEM_Attendee::system_question_* constants, which are |
112
|
|
|
* also all the values of QST_system in the questions table, and values |
113
|
|
|
* are their corresponding Attendee field names |
114
|
|
|
* |
115
|
|
|
* @var array |
116
|
|
|
*/ |
117
|
|
|
protected $_system_question_to_attendee_field_name = array( |
118
|
|
|
EEM_Attendee::system_question_fname => 'ATT_fname', |
119
|
|
|
EEM_Attendee::system_question_lname => 'ATT_lname', |
120
|
|
|
EEM_Attendee::system_question_email => 'ATT_email', |
121
|
|
|
EEM_Attendee::system_question_address => 'ATT_address', |
122
|
|
|
EEM_Attendee::system_question_address2 => 'ATT_address2', |
123
|
|
|
EEM_Attendee::system_question_city => 'ATT_city', |
124
|
|
|
EEM_Attendee::system_question_state => 'STA_ID', |
125
|
|
|
EEM_Attendee::system_question_country => 'CNT_ISO', |
126
|
|
|
EEM_Attendee::system_question_zip => 'ATT_zip', |
127
|
|
|
EEM_Attendee::system_question_phone => 'ATT_phone', |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* EEM_Attendee constructor. |
134
|
|
|
* |
135
|
|
|
* @param null $timezone |
136
|
|
|
* @param ModelFieldFactory $model_field_factory |
137
|
|
|
* @throws EE_Error |
138
|
|
|
* @throws InvalidArgumentException |
139
|
|
|
*/ |
140
|
|
|
protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
141
|
|
|
{ |
142
|
|
|
$this->singular_item = esc_html__('Attendee', 'event_espresso'); |
143
|
|
|
$this->plural_item = esc_html__('Attendees', 'event_espresso'); |
144
|
|
|
$this->_tables = array( |
145
|
|
|
'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
146
|
|
|
'Attendee_Meta' => new EE_Secondary_Table( |
147
|
|
|
'esp_attendee_meta', |
148
|
|
|
'ATTM_ID', |
149
|
|
|
'ATT_ID' |
150
|
|
|
), |
151
|
|
|
); |
152
|
|
|
$this->_fields = array( |
153
|
|
|
'Attendee_CPT' => array( |
154
|
|
|
'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
155
|
|
|
'ID', |
156
|
|
|
esc_html__('Attendee ID', 'event_espresso') |
157
|
|
|
), |
158
|
|
|
'ATT_full_name' => $model_field_factory->createPlainTextField( |
159
|
|
|
'post_title', |
160
|
|
|
esc_html__('Attendee Full Name', 'event_espresso'), |
161
|
|
|
false, |
162
|
|
|
esc_html__('Unknown', 'event_espresso') |
163
|
|
|
), |
164
|
|
|
'ATT_bio' => $model_field_factory->createPostContentField( |
165
|
|
|
'post_content', |
166
|
|
|
esc_html__('Attendee Biography', 'event_espresso'), |
167
|
|
|
false, |
168
|
|
|
esc_html__('No Biography Provided', 'event_espresso') |
169
|
|
|
), |
170
|
|
|
'ATT_slug' => $model_field_factory->createSlugField( |
171
|
|
|
'post_name', |
172
|
|
|
esc_html__('Attendee URL Slug', 'event_espresso') |
173
|
|
|
), |
174
|
|
|
'ATT_created' => $model_field_factory->createDatetimeField( |
175
|
|
|
'post_date', |
176
|
|
|
esc_html__('Time Attendee Created', 'event_espresso') |
177
|
|
|
), |
178
|
|
|
'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
179
|
|
|
'post_excerpt', |
180
|
|
|
esc_html__('Attendee Short Biography', 'event_espresso'), |
181
|
|
|
true, |
182
|
|
|
esc_html__('No Biography Provided', 'event_espresso') |
183
|
|
|
), |
184
|
|
|
'ATT_modified' => $model_field_factory->createDatetimeField( |
185
|
|
|
'post_modified', |
186
|
|
|
esc_html__('Time Attendee Last Modified', 'event_espresso') |
187
|
|
|
), |
188
|
|
|
'ATT_author' => $model_field_factory->createWpUserField( |
189
|
|
|
'post_author', |
190
|
|
|
esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
191
|
|
|
false |
192
|
|
|
), |
193
|
|
|
'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
194
|
|
|
'post_parent', |
195
|
|
|
esc_html__('Parent Attendee (unused)', 'event_espresso'), |
196
|
|
|
false, |
197
|
|
|
0 |
198
|
|
|
), |
199
|
|
|
'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
200
|
|
|
'status' => $model_field_factory->createWpPostStatusField( |
201
|
|
|
'post_status', |
202
|
|
|
esc_html__('Attendee Status', 'event_espresso'), |
203
|
|
|
false, |
204
|
|
|
'publish' |
205
|
|
|
), |
206
|
|
|
), |
207
|
|
|
'Attendee_Meta' => array( |
208
|
|
|
'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
209
|
|
|
'ATTM_ID', |
210
|
|
|
esc_html__('Attendee Meta Row ID', 'event_espresso'), |
211
|
|
|
false |
212
|
|
|
), |
213
|
|
|
'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
214
|
|
|
'ATT_ID', |
215
|
|
|
esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
216
|
|
|
false |
217
|
|
|
), |
218
|
|
|
'ATT_fname' => $model_field_factory->createPlainTextField( |
219
|
|
|
'ATT_fname', |
220
|
|
|
esc_html__('First Name', 'event_espresso') |
221
|
|
|
), |
222
|
|
|
'ATT_lname' => $model_field_factory->createPlainTextField( |
223
|
|
|
'ATT_lname', |
224
|
|
|
esc_html__('Last Name', 'event_espresso') |
225
|
|
|
), |
226
|
|
|
'ATT_address' => $model_field_factory->createPlainTextField( |
227
|
|
|
'ATT_address', |
228
|
|
|
esc_html__('Address Part 1', 'event_espresso') |
229
|
|
|
), |
230
|
|
|
'ATT_address2' => $model_field_factory->createPlainTextField( |
231
|
|
|
'ATT_address2', |
232
|
|
|
esc_html__('Address Part 2', 'event_espresso') |
233
|
|
|
), |
234
|
|
|
'ATT_city' => $model_field_factory->createPlainTextField( |
235
|
|
|
'ATT_city', |
236
|
|
|
esc_html__('City', 'event_espresso') |
237
|
|
|
), |
238
|
|
|
'STA_ID' => $model_field_factory->createForeignKeyIntField( |
239
|
|
|
'STA_ID', |
240
|
|
|
esc_html__('State', 'event_espresso'), |
241
|
|
|
true, |
242
|
|
|
0, |
243
|
|
|
'State' |
244
|
|
|
), |
245
|
|
|
'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
246
|
|
|
'CNT_ISO', |
247
|
|
|
esc_html__('Country', 'event_espresso'), |
248
|
|
|
true, |
249
|
|
|
'', |
250
|
|
|
'Country' |
251
|
|
|
), |
252
|
|
|
'ATT_zip' => $model_field_factory->createPlainTextField( |
253
|
|
|
'ATT_zip', |
254
|
|
|
esc_html__('ZIP/Postal Code', 'event_espresso') |
255
|
|
|
), |
256
|
|
|
'ATT_email' => $model_field_factory->createEmailField( |
257
|
|
|
'ATT_email', |
258
|
|
|
esc_html__('Email Address', 'event_espresso') |
259
|
|
|
), |
260
|
|
|
'ATT_phone' => $model_field_factory->createPlainTextField( |
261
|
|
|
'ATT_phone', |
262
|
|
|
esc_html__('Phone', 'event_espresso') |
263
|
|
|
), |
264
|
|
|
), |
265
|
|
|
); |
266
|
|
|
$this->_model_relations = array( |
267
|
|
|
'Registration' => new EE_Has_Many_Relation(), |
268
|
|
|
'State' => new EE_Belongs_To_Relation(), |
269
|
|
|
'Country' => new EE_Belongs_To_Relation(), |
270
|
|
|
'Event' => new EE_HABTM_Relation('Registration', false), |
271
|
|
|
'WP_User' => new EE_Belongs_To_Relation(), |
272
|
|
|
'Message' => new EE_Has_Many_Any_Relation(false), |
273
|
|
|
//allow deletion of attendees even if they have messages in the queue for them. |
274
|
|
|
'Term_Relationship' => new EE_Has_Many_Relation(), |
275
|
|
|
'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
276
|
|
|
); |
277
|
|
|
$this->_caps_slug = 'contacts'; |
278
|
|
|
parent::__construct($timezone); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
|
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Gets the name of the field on the attendee model corresponding to the system question string |
285
|
|
|
* which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
286
|
|
|
* |
287
|
|
|
* @param string $system_question_string |
288
|
|
|
* @return string|null if not found |
289
|
|
|
*/ |
290
|
|
|
public function get_attendee_field_for_system_question($system_question_string) |
291
|
|
|
{ |
292
|
|
|
return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
293
|
|
|
? $this->_system_question_to_attendee_field_name[$system_question_string] |
294
|
|
|
: null; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
301
|
|
|
* |
302
|
|
|
* @return array |
303
|
|
|
*/ |
304
|
|
|
public function system_question_to_attendee_field_mapping() |
305
|
|
|
{ |
306
|
|
|
return $this->_system_question_to_attendee_field_name; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
|
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Gets all the attendees for a transaction (by using the esp_registration as a join table) |
313
|
|
|
* |
314
|
|
|
* @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
315
|
|
|
* @return EE_Attendee[]|EE_Base_Class[] |
316
|
|
|
* @throws EE_Error |
317
|
|
|
*/ |
318
|
|
|
public function get_attendees_for_transaction($transaction_id_or_obj) |
319
|
|
|
{ |
320
|
|
|
return $this->get_all( |
321
|
|
|
array( |
322
|
|
|
array( |
323
|
|
|
'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
324
|
|
|
? $transaction_id_or_obj->ID() |
325
|
|
|
: $transaction_id_or_obj, |
326
|
|
|
), |
327
|
|
|
) |
328
|
|
|
); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
|
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* retrieve a single attendee from db via their ID |
335
|
|
|
* |
336
|
|
|
* @param $ATT_ID |
337
|
|
|
* @return mixed array on success, FALSE on fail |
338
|
|
|
* @deprecated |
339
|
|
|
*/ |
340
|
|
|
public function get_attendee_by_ID($ATT_ID = false) |
341
|
|
|
{ |
342
|
|
|
// retrieve a particular EE_Attendee |
343
|
|
|
return $this->get_one_by_ID($ATT_ID); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* retrieve a single attendee from db via their ID |
350
|
|
|
* |
351
|
|
|
* @param array $where_cols_n_values |
352
|
|
|
* @return mixed array on success, FALSE on fail |
353
|
|
|
* @throws EE_Error |
354
|
|
|
*/ |
355
|
|
|
public function get_attendee($where_cols_n_values = array()) |
356
|
|
|
{ |
357
|
|
|
if (empty($where_cols_n_values)) { |
358
|
|
|
return false; |
359
|
|
|
} |
360
|
|
|
$attendee = $this->get_all(array($where_cols_n_values)); |
361
|
|
|
if (! empty($attendee)) { |
362
|
|
|
return array_shift($attendee); |
363
|
|
|
} |
364
|
|
|
return false; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
|
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Search for an existing Attendee record in the DB |
371
|
|
|
* |
372
|
|
|
* @param array $where_cols_n_values |
373
|
|
|
* @return bool|mixed |
374
|
|
|
* @throws EE_Error |
375
|
|
|
*/ |
376
|
|
|
public function find_existing_attendee($where_cols_n_values = null) |
377
|
|
|
{ |
378
|
|
|
// search by combo of first and last names plus the email address |
379
|
|
|
$attendee_data_keys = array( |
380
|
|
|
'ATT_fname' => $this->_ATT_fname, |
381
|
|
|
'ATT_lname' => $this->_ATT_lname, |
382
|
|
|
'ATT_email' => $this->_ATT_email, |
383
|
|
|
); |
384
|
|
|
// no search params means attendee object already exists. |
385
|
|
|
$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
386
|
|
|
? $where_cols_n_values |
387
|
|
|
: $attendee_data_keys; |
388
|
|
|
$valid_data = true; |
389
|
|
|
// check for required values |
390
|
|
|
$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
391
|
|
|
? $valid_data |
392
|
|
|
: false; |
393
|
|
|
$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
394
|
|
|
? $valid_data |
395
|
|
|
: false; |
396
|
|
|
$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
397
|
|
|
? $valid_data |
398
|
|
|
: false; |
399
|
|
|
if ($valid_data) { |
400
|
|
|
$attendee = $this->get_attendee($where_cols_n_values); |
401
|
|
|
if ($attendee instanceof EE_Attendee) { |
402
|
|
|
return $attendee; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
return false; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Takes an incoming array of EE_Registration ids |
412
|
|
|
* and sends back a list of corresponding non duplicate EE_Attendee objects. |
413
|
|
|
* |
414
|
|
|
* @since 4.3.0 |
415
|
|
|
* @param array $ids array of EE_Registration ids |
416
|
|
|
* @return EE_Attendee[]|EE_Base_Class[] |
417
|
|
|
* @throws EE_Error |
418
|
|
|
*/ |
419
|
|
|
public function get_array_of_contacts_from_reg_ids($ids) |
420
|
|
|
{ |
421
|
|
|
$ids = (array)$ids; |
422
|
|
|
$_where = array( |
423
|
|
|
'Registration.REG_ID' => array('in', $ids), |
424
|
|
|
); |
425
|
|
|
return $this->get_all(array($_where)); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
|
429
|
|
|
} |
430
|
|
|
// End of file EEM_Attendee.model.php |
431
|
|
|
// Location: /ee-mvc/models/EEM_Attendee.model.php |
432
|
|
|
|