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