|
1
|
|
|
<?php use EventEspresso\core\services\orm\ModelFieldFactory; |
|
2
|
|
|
|
|
3
|
|
|
if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4
|
|
|
exit('No direct script access allowed'); |
|
5
|
|
|
} |
|
6
|
|
|
require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* EEM_Event Model |
|
12
|
|
|
* extends EEM_CPT_Base which extends EEM_Base |
|
13
|
|
|
* |
|
14
|
|
|
* @package Event Espresso |
|
15
|
|
|
* @subpackage includes/models/ |
|
16
|
|
|
* @author Michael Nelson, Brent Christensen |
|
17
|
|
|
*/ |
|
18
|
|
|
class EEM_Event extends EEM_CPT_Base |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
23
|
|
|
* event |
|
24
|
|
|
*/ |
|
25
|
|
|
const sold_out = 'sold_out'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
29
|
|
|
* date) |
|
30
|
|
|
*/ |
|
31
|
|
|
const postponed = 'postponed'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* constant used by status(), indicating that the event will no longer occur |
|
35
|
|
|
*/ |
|
36
|
|
|
const cancelled = 'cancelled'; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected static $_default_reg_status; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* This is the default for the additional limit field. |
|
47
|
|
|
* @var int |
|
48
|
|
|
*/ |
|
49
|
|
|
protected static $_default_additional_limit = 10; |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* private instance of the Event object |
|
54
|
|
|
* |
|
55
|
|
|
* @var EEM_Event |
|
56
|
|
|
*/ |
|
57
|
|
|
protected static $_instance; |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Adds a relationship to Term_Taxonomy for each CPT_Base |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $timezone |
|
66
|
|
|
* @throws \EE_Error |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function __construct($timezone = null) |
|
69
|
|
|
{ |
|
70
|
|
|
EE_Registry::instance()->load_model('Registration'); |
|
71
|
|
|
$this->singular_item = esc_html__('Event', 'event_espresso'); |
|
72
|
|
|
$this->plural_item = esc_html__('Events', 'event_espresso'); |
|
73
|
|
|
// to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
74
|
|
|
// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
75
|
|
|
// to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
76
|
|
|
// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
77
|
|
|
// to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
78
|
|
|
// add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
79
|
|
|
$this->_custom_stati = apply_filters( |
|
80
|
|
|
'AFEE__EEM_Event__construct___custom_stati', |
|
81
|
|
|
array( |
|
82
|
|
|
EEM_Event::cancelled => array( |
|
83
|
|
|
'label' => esc_html__('Cancelled', 'event_espresso'), |
|
84
|
|
|
'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
85
|
|
|
), |
|
86
|
|
|
EEM_Event::postponed => array( |
|
87
|
|
|
'label' => esc_html__('Postponed', 'event_espresso'), |
|
88
|
|
|
'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
89
|
|
|
), |
|
90
|
|
|
EEM_Event::sold_out => array( |
|
91
|
|
|
'label' => esc_html__('Sold Out', 'event_espresso'), |
|
92
|
|
|
'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
93
|
|
|
), |
|
94
|
|
|
) |
|
95
|
|
|
); |
|
96
|
|
|
self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
97
|
|
|
: self::$_default_reg_status; |
|
98
|
|
|
$this->_tables = array( |
|
99
|
|
|
'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
100
|
|
|
'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
101
|
|
|
); |
|
102
|
|
|
$this->_fields = array( |
|
103
|
|
|
'Event_CPT' => array( |
|
104
|
|
|
'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
105
|
|
|
esc_html__('Post ID for Event', 'event_espresso')), |
|
106
|
|
|
'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
107
|
|
|
false, |
|
108
|
|
|
''), |
|
109
|
|
|
'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
110
|
|
|
esc_html__('Event Description', 'event_espresso'), |
|
111
|
|
|
false, ''), |
|
112
|
|
|
'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
113
|
|
|
''), |
|
114
|
|
|
'EVT_created' => new EE_Datetime_Field('post_date', |
|
115
|
|
|
esc_html__('Date/Time Event Created', 'event_espresso'), |
|
116
|
|
|
false, EE_Datetime_Field::now), |
|
117
|
|
|
'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
118
|
|
|
esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
119
|
|
|
'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
120
|
|
|
esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
121
|
|
|
'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
122
|
|
|
esc_html__('Event Creator ID', 'event_espresso'), |
|
123
|
|
|
false), |
|
124
|
|
|
'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
125
|
|
|
false, |
|
126
|
|
|
0), |
|
127
|
|
|
'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
128
|
|
|
false, |
|
129
|
|
|
1), |
|
130
|
|
|
'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
131
|
|
|
// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
132
|
|
|
'status' => new EE_WP_Post_Status_Field('post_status', |
|
133
|
|
|
esc_html__('Event Status', 'event_espresso'), |
|
134
|
|
|
false, 'draft', $this->_custom_stati), |
|
135
|
|
|
), |
|
136
|
|
|
'Event_Meta' => array( |
|
137
|
|
|
'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
138
|
|
|
esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
139
|
|
|
'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
140
|
|
|
esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
141
|
|
|
'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
142
|
|
|
esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
143
|
|
|
'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
144
|
|
|
esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
145
|
|
|
'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
146
|
|
|
esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
147
|
|
|
'EVT_additional_limit' => new EE_Integer_Field( |
|
148
|
|
|
'EVT_additional_limit', |
|
149
|
|
|
esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
150
|
|
|
true, |
|
151
|
|
|
self::$_default_additional_limit |
|
152
|
|
|
), |
|
153
|
|
|
'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
154
|
|
|
'EVT_default_registration_status', |
|
155
|
|
|
esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
156
|
|
|
EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
157
|
|
|
), |
|
158
|
|
|
'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
159
|
|
|
esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
160
|
|
|
'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
161
|
|
|
esc_html__('Event Phone Number', 'event_espresso'), false), |
|
162
|
|
|
'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
163
|
|
|
esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
164
|
|
|
'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
165
|
|
|
esc_html__('Timezone (name) for Event times', 'event_espresso'), false), |
|
166
|
|
|
'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
167
|
|
|
esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
168
|
|
|
'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
169
|
|
|
esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
170
|
|
|
), |
|
171
|
|
|
); |
|
172
|
|
|
$this->_model_relations = array( |
|
173
|
|
|
'Registration' => new EE_Has_Many_Relation(), |
|
174
|
|
|
'Datetime' => new EE_Has_Many_Relation(), |
|
175
|
|
|
'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
176
|
|
|
'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
177
|
|
|
'Term_Relationship' => new EE_Has_Many_Relation(), |
|
178
|
|
|
'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
179
|
|
|
'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
180
|
|
|
'Attendee' => new EE_HABTM_Relation('Registration'), |
|
181
|
|
|
'WP_User' => new EE_Belongs_To_Relation(), |
|
182
|
|
|
); |
|
183
|
|
|
//this model is generally available for reading |
|
184
|
|
|
$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
185
|
|
|
parent::__construct($timezone); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @param string $default_reg_status |
|
192
|
|
|
*/ |
|
193
|
|
|
public static function set_default_reg_status($default_reg_status) |
|
194
|
|
|
{ |
|
195
|
|
|
self::$_default_reg_status = $default_reg_status; |
|
196
|
|
|
// if EEM_Event has already been instantiated, |
|
197
|
|
|
// then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
198
|
|
|
if (self::$_instance instanceof EEM_Event) { |
|
199
|
|
|
$default_reg_status = new EE_Enum_Text_Field( |
|
200
|
|
|
'EVT_default_registration_status', |
|
201
|
|
|
esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
202
|
|
|
false, |
|
203
|
|
|
$default_reg_status, |
|
204
|
|
|
EEM_Registration::reg_status_array() |
|
205
|
|
|
); |
|
206
|
|
|
$default_reg_status->_construct_finalize( |
|
207
|
|
|
'Event_Meta', |
|
208
|
|
|
'EVT_default_registration_status', |
|
209
|
|
|
'EEM_Event' |
|
210
|
|
|
); |
|
211
|
|
|
self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Used to override the default for the additional limit field. |
|
218
|
|
|
* @param $additional_limit |
|
219
|
|
|
*/ |
|
220
|
|
|
public static function set_default_additional_limit($additional_limit) |
|
221
|
|
|
{ |
|
222
|
|
|
self::$_default_additional_limit = (int) $additional_limit; |
|
223
|
|
|
if (self::$_instance instanceof EEM_Event) { |
|
224
|
|
|
self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
225
|
|
|
'EVT_additional_limit', |
|
226
|
|
|
__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
227
|
|
|
true, |
|
228
|
|
|
self::$_default_additional_limit |
|
229
|
|
|
); |
|
230
|
|
|
self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
231
|
|
|
'Event_Meta', |
|
232
|
|
|
'EVT_additional_limit', |
|
233
|
|
|
'EEM_Event' |
|
234
|
|
|
); |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Return what is currently set as the default additional limit for the event. |
|
241
|
|
|
* @return int |
|
242
|
|
|
*/ |
|
243
|
|
|
public static function get_default_additional_limit() |
|
244
|
|
|
{ |
|
245
|
|
|
return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* get_question_groups |
|
251
|
|
|
* |
|
252
|
|
|
* @return array |
|
253
|
|
|
* @throws \EE_Error |
|
254
|
|
|
*/ |
|
255
|
|
|
public function get_all_question_groups() |
|
256
|
|
|
{ |
|
257
|
|
|
return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
258
|
|
|
array( |
|
259
|
|
|
array('QSG_deleted' => false), |
|
260
|
|
|
'order_by' => array('QSG_order' => 'ASC'), |
|
261
|
|
|
) |
|
262
|
|
|
); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* get_question_groups |
|
269
|
|
|
* |
|
270
|
|
|
* @param int $EVT_ID |
|
271
|
|
|
* @return array|bool |
|
272
|
|
|
* @throws \EE_Error |
|
273
|
|
|
*/ |
|
274
|
|
View Code Duplication |
public function get_all_event_question_groups($EVT_ID = 0) |
|
275
|
|
|
{ |
|
276
|
|
|
if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
277
|
|
|
EE_Error::add_error( |
|
278
|
|
|
esc_html__( |
|
279
|
|
|
'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
280
|
|
|
'event_espresso' |
|
281
|
|
|
), |
|
282
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
|
283
|
|
|
); |
|
284
|
|
|
return false; |
|
285
|
|
|
} |
|
286
|
|
|
return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
287
|
|
|
array( |
|
288
|
|
|
array('EVT_ID' => $EVT_ID), |
|
289
|
|
|
) |
|
290
|
|
|
); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* get_question_groups |
|
297
|
|
|
* |
|
298
|
|
|
* @param int $EVT_ID |
|
299
|
|
|
* @param boolean $for_primary_attendee |
|
300
|
|
|
* @return array|bool |
|
301
|
|
|
* @throws \EE_Error |
|
302
|
|
|
*/ |
|
303
|
|
View Code Duplication |
public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
304
|
|
|
{ |
|
305
|
|
|
if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
306
|
|
|
EE_Error::add_error( |
|
307
|
|
|
esc_html__( |
|
308
|
|
|
'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
309
|
|
|
'event_espresso' |
|
310
|
|
|
), |
|
311
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
|
312
|
|
|
); |
|
313
|
|
|
return false; |
|
314
|
|
|
} |
|
315
|
|
|
return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
316
|
|
|
array( |
|
317
|
|
|
array( |
|
318
|
|
|
'EVT_ID' => $EVT_ID, |
|
319
|
|
|
'EQG_primary' => $for_primary_attendee, |
|
320
|
|
|
), |
|
321
|
|
|
) |
|
322
|
|
|
); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* get_question_groups |
|
329
|
|
|
* |
|
330
|
|
|
* @param int $EVT_ID |
|
331
|
|
|
* @param EE_Registration $registration |
|
332
|
|
|
* @return array|bool |
|
333
|
|
|
* @throws \EE_Error |
|
334
|
|
|
*/ |
|
335
|
|
|
public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
336
|
|
|
{ |
|
337
|
|
|
if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
338
|
|
|
EE_Error::add_error( |
|
339
|
|
|
esc_html__( |
|
340
|
|
|
'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
341
|
|
|
'event_espresso' |
|
342
|
|
|
), |
|
343
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
|
344
|
|
|
); |
|
345
|
|
|
return false; |
|
346
|
|
|
} |
|
347
|
|
|
$where_params = array( |
|
348
|
|
|
'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
349
|
|
|
'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
350
|
|
|
'QSG_deleted' => false, |
|
351
|
|
|
); |
|
352
|
|
|
return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
353
|
|
|
array( |
|
354
|
|
|
$where_params, |
|
355
|
|
|
'order_by' => array('QSG_order' => 'ASC'), |
|
356
|
|
|
) |
|
357
|
|
|
); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
|
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* get_question_target_db_column |
|
364
|
|
|
* |
|
365
|
|
|
* @param string $QSG_IDs csv list of $QSG IDs |
|
366
|
|
|
* @return array|bool |
|
367
|
|
|
* @throws \EE_Error |
|
368
|
|
|
*/ |
|
369
|
|
View Code Duplication |
public function get_questions_in_groups($QSG_IDs = '') |
|
370
|
|
|
{ |
|
371
|
|
|
if (empty($QSG_IDs)) { |
|
372
|
|
|
EE_Error::add_error( |
|
373
|
|
|
esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
374
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
|
375
|
|
|
); |
|
376
|
|
|
return false; |
|
377
|
|
|
} |
|
378
|
|
|
return EE_Registry::instance()->load_model('Question')->get_all( |
|
379
|
|
|
array( |
|
380
|
|
|
array( |
|
381
|
|
|
'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
382
|
|
|
'QST_deleted' => false, |
|
383
|
|
|
'QST_admin_only' => is_admin(), |
|
384
|
|
|
), |
|
385
|
|
|
'order_by' => 'QST_order', |
|
386
|
|
|
) |
|
387
|
|
|
); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
|
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* get_options_for_question |
|
394
|
|
|
* |
|
395
|
|
|
* @param string $QST_IDs csv list of $QST IDs |
|
396
|
|
|
* @return array|bool |
|
397
|
|
|
* @throws \EE_Error |
|
398
|
|
|
*/ |
|
399
|
|
View Code Duplication |
public function get_options_for_question($QST_IDs) |
|
400
|
|
|
{ |
|
401
|
|
|
if (empty($QST_IDs)) { |
|
402
|
|
|
EE_Error::add_error( |
|
403
|
|
|
esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
404
|
|
|
__FILE__, __FUNCTION__, __LINE__ |
|
405
|
|
|
); |
|
406
|
|
|
return false; |
|
407
|
|
|
} |
|
408
|
|
|
return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
409
|
|
|
array( |
|
410
|
|
|
array( |
|
411
|
|
|
'Question.QST_ID' => array('IN', $QST_IDs), |
|
412
|
|
|
'QSO_deleted' => false, |
|
413
|
|
|
), |
|
414
|
|
|
'order_by' => 'QSO_ID', |
|
415
|
|
|
) |
|
416
|
|
|
); |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
|
|
420
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* Gets all events that are published |
|
427
|
|
|
* and have event start time earlier than now and an event end time later than now |
|
428
|
|
|
* |
|
429
|
|
|
* @param array $query_params An array of query params to further filter on |
|
430
|
|
|
* (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
431
|
|
|
* @param bool $count whether to return the count or not (default FALSE) |
|
432
|
|
|
* @return EE_Event[]|int |
|
433
|
|
|
* @throws \EE_Error |
|
434
|
|
|
*/ |
|
435
|
|
|
public function get_active_events($query_params, $count = false) |
|
436
|
|
|
{ |
|
437
|
|
|
if (array_key_exists(0, $query_params)) { |
|
438
|
|
|
$where_params = $query_params[0]; |
|
439
|
|
|
unset($query_params[0]); |
|
440
|
|
|
} else { |
|
441
|
|
|
$where_params = array(); |
|
442
|
|
|
} |
|
443
|
|
|
// if we have count make sure we don't include group by |
|
444
|
|
|
if ($count && isset($query_params['group_by'])) { |
|
445
|
|
|
unset($query_params['group_by']); |
|
446
|
|
|
} |
|
447
|
|
|
// let's add specific query_params for active_events |
|
448
|
|
|
// keep in mind this will override any sent status in the query AND any date queries. |
|
449
|
|
|
$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
450
|
|
|
//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
451
|
|
|
if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
452
|
|
|
$where_params['Datetime.DTT_EVT_start******'] = array( |
|
453
|
|
|
'<', |
|
454
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
455
|
|
|
); |
|
456
|
|
|
} else { |
|
457
|
|
|
$where_params['Datetime.DTT_EVT_start'] = array( |
|
458
|
|
|
'<', |
|
459
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
460
|
|
|
); |
|
461
|
|
|
} |
|
462
|
|
|
if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
463
|
|
|
$where_params['Datetime.DTT_EVT_end*****'] = array( |
|
464
|
|
|
'>', |
|
465
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
466
|
|
|
); |
|
467
|
|
|
} else { |
|
468
|
|
|
$where_params['Datetime.DTT_EVT_end'] = array( |
|
469
|
|
|
'>', |
|
470
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
471
|
|
|
); |
|
472
|
|
|
} |
|
473
|
|
|
$query_params[0] = $where_params; |
|
474
|
|
|
// don't use $query_params with count() |
|
475
|
|
|
// because we don't want to include additional query clauses like "GROUP BY" |
|
476
|
|
|
return $count |
|
477
|
|
|
? $this->count(array($where_params), 'EVT_ID', true) |
|
478
|
|
|
: $this->get_all($query_params); |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
|
|
483
|
|
|
/** |
|
484
|
|
|
* get all events that are published and have an event start time later than now |
|
485
|
|
|
* |
|
486
|
|
|
* @param array $query_params An array of query params to further filter on |
|
487
|
|
|
* (Note that status and DTT_EVT_start will be overridden) |
|
488
|
|
|
* @param bool $count whether to return the count or not (default FALSE) |
|
489
|
|
|
* @return EE_Event[]|int |
|
490
|
|
|
* @throws \EE_Error |
|
491
|
|
|
*/ |
|
492
|
|
View Code Duplication |
public function get_upcoming_events($query_params, $count = false) |
|
493
|
|
|
{ |
|
494
|
|
|
if (array_key_exists(0, $query_params)) { |
|
495
|
|
|
$where_params = $query_params[0]; |
|
496
|
|
|
unset($query_params[0]); |
|
497
|
|
|
} else { |
|
498
|
|
|
$where_params = array(); |
|
499
|
|
|
} |
|
500
|
|
|
// if we have count make sure we don't include group by |
|
501
|
|
|
if ($count && isset($query_params['group_by'])) { |
|
502
|
|
|
unset($query_params['group_by']); |
|
503
|
|
|
} |
|
504
|
|
|
// let's add specific query_params for active_events |
|
505
|
|
|
// keep in mind this will override any sent status in the query AND any date queries. |
|
506
|
|
|
$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
507
|
|
|
// if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
508
|
|
|
if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
509
|
|
|
$where_params['Datetime.DTT_EVT_start*****'] = array( |
|
510
|
|
|
'>', |
|
511
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
512
|
|
|
); |
|
513
|
|
|
} else { |
|
514
|
|
|
$where_params['Datetime.DTT_EVT_start'] = array( |
|
515
|
|
|
'>', |
|
516
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
517
|
|
|
); |
|
518
|
|
|
} |
|
519
|
|
|
$query_params[0] = $where_params; |
|
520
|
|
|
// don't use $query_params with count() |
|
521
|
|
|
// because we don't want to include additional query clauses like "GROUP BY" |
|
522
|
|
|
return $count |
|
523
|
|
|
? $this->count(array($where_params), 'EVT_ID', true) |
|
524
|
|
|
: $this->get_all($query_params); |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
|
|
528
|
|
|
|
|
529
|
|
|
/** |
|
530
|
|
|
* Gets all events that are published |
|
531
|
|
|
* and have an event end time later than now |
|
532
|
|
|
* |
|
533
|
|
|
* @param array $query_params An array of query params to further filter on |
|
534
|
|
|
* (note that status and DTT_EVT_end will be overridden) |
|
535
|
|
|
* @param bool $count whether to return the count or not (default FALSE) |
|
536
|
|
|
* @return EE_Event[]|int |
|
537
|
|
|
* @throws \EE_Error |
|
538
|
|
|
*/ |
|
539
|
|
View Code Duplication |
public function get_active_and_upcoming_events($query_params, $count = false) |
|
540
|
|
|
{ |
|
541
|
|
|
if (array_key_exists(0, $query_params)) { |
|
542
|
|
|
$where_params = $query_params[0]; |
|
543
|
|
|
unset($query_params[0]); |
|
544
|
|
|
} else { |
|
545
|
|
|
$where_params = array(); |
|
546
|
|
|
} |
|
547
|
|
|
// if we have count make sure we don't include group by |
|
548
|
|
|
if ($count && isset($query_params['group_by'])) { |
|
549
|
|
|
unset($query_params['group_by']); |
|
550
|
|
|
} |
|
551
|
|
|
// let's add specific query_params for active_events |
|
552
|
|
|
// keep in mind this will override any sent status in the query AND any date queries. |
|
553
|
|
|
$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
554
|
|
|
// add where params for DTT_EVT_end |
|
555
|
|
|
if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
556
|
|
|
$where_params['Datetime.DTT_EVT_end*****'] = array( |
|
557
|
|
|
'>', |
|
558
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
559
|
|
|
); |
|
560
|
|
|
} else { |
|
561
|
|
|
$where_params['Datetime.DTT_EVT_end'] = array( |
|
562
|
|
|
'>', |
|
563
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
564
|
|
|
); |
|
565
|
|
|
} |
|
566
|
|
|
$query_params[0] = $where_params; |
|
567
|
|
|
// don't use $query_params with count() |
|
568
|
|
|
// because we don't want to include additional query clauses like "GROUP BY" |
|
569
|
|
|
return $count |
|
570
|
|
|
? $this->count(array($where_params), 'EVT_ID', true) |
|
571
|
|
|
: $this->get_all($query_params); |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
|
|
575
|
|
|
|
|
576
|
|
|
/** |
|
577
|
|
|
* This only returns events that are expired. |
|
578
|
|
|
* They may still be published but all their datetimes have expired. |
|
579
|
|
|
* |
|
580
|
|
|
* @param array $query_params An array of query params to further filter on |
|
581
|
|
|
* (note that status and DTT_EVT_end will be overridden) |
|
582
|
|
|
* @param bool $count whether to return the count or not (default FALSE) |
|
583
|
|
|
* @return EE_Event[]|int |
|
584
|
|
|
* @throws \EE_Error |
|
585
|
|
|
*/ |
|
586
|
|
|
public function get_expired_events($query_params, $count = false) |
|
587
|
|
|
{ |
|
588
|
|
|
$where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
589
|
|
|
// if we have count make sure we don't include group by |
|
590
|
|
|
if ($count && isset($query_params['group_by'])) { |
|
591
|
|
|
unset($query_params['group_by']); |
|
592
|
|
|
} |
|
593
|
|
|
// let's add specific query_params for active_events |
|
594
|
|
|
// keep in mind this will override any sent status in the query AND any date queries. |
|
595
|
|
|
if (isset($where_params['status'])) { |
|
596
|
|
|
unset($where_params['status']); |
|
597
|
|
|
} |
|
598
|
|
|
$exclude_query = $query_params; |
|
599
|
|
|
if (isset($exclude_query[0])) { |
|
600
|
|
|
unset($exclude_query[0]); |
|
601
|
|
|
} |
|
602
|
|
|
$exclude_query[0] = array( |
|
603
|
|
|
'Datetime.DTT_EVT_end' => array( |
|
604
|
|
|
'>', |
|
605
|
|
|
EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
606
|
|
|
), |
|
607
|
|
|
); |
|
608
|
|
|
// first get all events that have datetimes where its not expired. |
|
609
|
|
|
$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
610
|
|
|
$event_ids = array_keys($event_ids); |
|
611
|
|
|
// if we have any additional query_params, let's add them to the 'AND' condition |
|
612
|
|
|
$and_condition = array( |
|
613
|
|
|
'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
614
|
|
|
'EVT_ID' => array('NOT IN', $event_ids), |
|
615
|
|
|
); |
|
616
|
|
View Code Duplication |
if (isset($where_params['OR'])) { |
|
617
|
|
|
$and_condition['OR'] = $where_params['OR']; |
|
618
|
|
|
unset($where_params['OR']); |
|
619
|
|
|
} |
|
620
|
|
View Code Duplication |
if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
621
|
|
|
$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
622
|
|
|
unset($where_params['Datetime.DTT_EVT_end']); |
|
623
|
|
|
} |
|
624
|
|
View Code Duplication |
if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
625
|
|
|
$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
626
|
|
|
unset($where_params['Datetime.DTT_EVT_start']); |
|
627
|
|
|
} |
|
628
|
|
|
// merge remaining $where params with the and conditions. |
|
629
|
|
|
$where_params['AND'] = array_merge($and_condition, $where_params); |
|
630
|
|
|
$query_params[0] = $where_params; |
|
631
|
|
|
// don't use $query_params with count() |
|
632
|
|
|
// because we don't want to include additional query clauses like "GROUP BY" |
|
633
|
|
|
return $count |
|
634
|
|
|
? $this->count(array($where_params), 'EVT_ID', true) |
|
635
|
|
|
: $this->get_all($query_params); |
|
636
|
|
|
} |
|
637
|
|
|
|
|
638
|
|
|
|
|
639
|
|
|
|
|
640
|
|
|
/** |
|
641
|
|
|
* This basically just returns the events that do not have the publish status. |
|
642
|
|
|
* |
|
643
|
|
|
* @param array $query_params An array of query params to further filter on |
|
644
|
|
|
* (note that status will be overwritten) |
|
645
|
|
|
* @param boolean $count whether to return the count or not (default FALSE) |
|
646
|
|
|
* @return EE_Event[]|int |
|
647
|
|
|
* @throws \EE_Error |
|
648
|
|
|
*/ |
|
649
|
|
|
public function get_inactive_events($query_params, $count = false) |
|
650
|
|
|
{ |
|
651
|
|
|
$where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
652
|
|
|
// let's add in specific query_params for inactive events. |
|
653
|
|
|
if (isset($where_params['status'])) { |
|
654
|
|
|
unset($where_params['status']); |
|
655
|
|
|
} |
|
656
|
|
|
// if we have count make sure we don't include group by |
|
657
|
|
|
if ($count && isset($query_params['group_by'])) { |
|
658
|
|
|
unset($query_params['group_by']); |
|
659
|
|
|
} |
|
660
|
|
|
// if we have any additional query_params, let's add them to the 'AND' condition |
|
661
|
|
|
$where_params['AND']['status'] = array('!=', 'publish'); |
|
662
|
|
View Code Duplication |
if (isset($where_params['OR'])) { |
|
663
|
|
|
$where_params['AND']['OR'] = $where_params['OR']; |
|
664
|
|
|
unset($where_params['OR']); |
|
665
|
|
|
} |
|
666
|
|
View Code Duplication |
if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
667
|
|
|
$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
668
|
|
|
unset($where_params['Datetime.DTT_EVT_end']); |
|
669
|
|
|
} |
|
670
|
|
View Code Duplication |
if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
671
|
|
|
$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
672
|
|
|
unset($where_params['Datetime.DTT_EVT_start']); |
|
673
|
|
|
} |
|
674
|
|
|
$query_params[0] = $where_params; |
|
675
|
|
|
// don't use $query_params with count() |
|
676
|
|
|
// because we don't want to include additional query clauses like "GROUP BY" |
|
677
|
|
|
return $count |
|
678
|
|
|
? $this->count(array($where_params), 'EVT_ID', true) |
|
679
|
|
|
: $this->get_all($query_params); |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
|
|
683
|
|
|
|
|
684
|
|
|
/** |
|
685
|
|
|
* This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
686
|
|
|
* because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
687
|
|
|
* attached to the event. See parent for param descriptions |
|
688
|
|
|
* |
|
689
|
|
|
* @param $id_or_obj |
|
690
|
|
|
* @param $other_model_id_or_obj |
|
691
|
|
|
* @param string $relationName |
|
692
|
|
|
* @param array $where_query |
|
693
|
|
|
* @return EE_Base_Class |
|
694
|
|
|
* @throws EE_Error |
|
695
|
|
|
*/ |
|
696
|
|
|
public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
697
|
|
|
{ |
|
698
|
|
|
if ($relationName === 'Price') { |
|
699
|
|
|
//let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
700
|
|
|
$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
701
|
|
|
//if EVT_ID = 0, then this is a default |
|
702
|
|
|
if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
703
|
|
|
//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
704
|
|
|
$prc_chk->set('PRC_ID', 0); |
|
705
|
|
|
} |
|
706
|
|
|
//run parent |
|
707
|
|
|
return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
708
|
|
|
} |
|
709
|
|
|
//otherwise carry on as normal |
|
710
|
|
|
return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
|
|
|
|
714
|
|
|
|
|
715
|
|
|
/******************** DEPRECATED METHODS ********************/ |
|
716
|
|
|
|
|
717
|
|
|
|
|
718
|
|
|
|
|
719
|
|
|
/** |
|
720
|
|
|
* _get_question_target_db_column |
|
721
|
|
|
* |
|
722
|
|
|
* @deprecated as of 4.8.32.rc.001. Instead consider using |
|
723
|
|
|
* EE_Registration_Custom_Questions_Form located in |
|
724
|
|
|
* admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
725
|
|
|
* @access public |
|
726
|
|
|
* @param EE_Registration $registration (so existing answers for registration are included) |
|
727
|
|
|
* @param int $EVT_ID so all question groups are included for event (not just answers from |
|
728
|
|
|
* registration). |
|
729
|
|
|
* @throws EE_Error |
|
730
|
|
|
* @return array |
|
731
|
|
|
*/ |
|
732
|
|
|
public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
733
|
|
|
{ |
|
734
|
|
|
if (empty($EVT_ID)) { |
|
735
|
|
|
throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
736
|
|
|
'event_espresso')); |
|
737
|
|
|
} |
|
738
|
|
|
$questions = array(); |
|
739
|
|
|
// get all question groups for event |
|
740
|
|
|
$qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
741
|
|
|
if (! empty($qgs)) { |
|
742
|
|
|
foreach ($qgs as $qg) { |
|
|
|
|
|
|
743
|
|
|
$qsts = $qg->questions(); |
|
744
|
|
|
$questions[$qg->ID()] = $qg->model_field_array(); |
|
745
|
|
|
$questions[$qg->ID()]['QSG_questions'] = array(); |
|
746
|
|
|
foreach ($qsts as $qst) { |
|
747
|
|
|
if ($qst->is_system_question()) { |
|
748
|
|
|
continue; |
|
749
|
|
|
} |
|
750
|
|
|
$answer = EEM_Answer::instance()->get_one(array( |
|
751
|
|
|
array( |
|
752
|
|
|
'QST_ID' => $qst->ID(), |
|
753
|
|
|
'REG_ID' => $registration->ID(), |
|
754
|
|
|
), |
|
755
|
|
|
)); |
|
756
|
|
|
$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
757
|
|
|
$qst_name = $qstn_id = $qst->ID(); |
|
758
|
|
|
$ans_id = $answer->ID(); |
|
759
|
|
|
$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
760
|
|
|
$input_name = ''; |
|
761
|
|
|
$input_id = sanitize_key($qst->display_text()); |
|
762
|
|
|
$input_class = ''; |
|
763
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
764
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
765
|
|
|
. $input_name |
|
766
|
|
|
. $qst_name; |
|
767
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
768
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
769
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
770
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
771
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
772
|
|
|
//leave responses as-is, don't convert stuff into html entities please! |
|
773
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
774
|
|
|
if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
775
|
|
|
$QSOs = $qst->options(true, $answer->value()); |
|
776
|
|
|
if (is_array($QSOs)) { |
|
777
|
|
|
foreach ($QSOs as $QSO_ID => $QSO) { |
|
778
|
|
|
$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
779
|
|
|
} |
|
780
|
|
|
} |
|
781
|
|
|
} |
|
782
|
|
|
} |
|
783
|
|
|
} |
|
784
|
|
|
} |
|
785
|
|
|
return $questions; |
|
786
|
|
|
} |
|
787
|
|
|
|
|
788
|
|
|
|
|
789
|
|
|
} |
|
790
|
|
|
// End of file EEM_Event.model.php |
|
791
|
|
|
// Location: /includes/models/EEM_Event.model.php |
|
792
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.