@@ -10,9 +10,9 @@ discard block |
||
10 | 10 | $stages = glob(EE_CORE . 'data_migration_scripts/4_12_0_stages/*'); |
11 | 11 | $class_to_filepath = []; |
12 | 12 | foreach ($stages as $filepath) { |
13 | - $matches = []; |
|
14 | - preg_match('~4_12_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
15 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
13 | + $matches = []; |
|
14 | + preg_match('~4_12_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
15 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
16 | 16 | } |
17 | 17 | // give addons a chance to autoload their stages too |
18 | 18 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_12_0__autoloaded_stages', $class_to_filepath); |
@@ -28,63 +28,63 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class EE_DMS_Core_4_12_0 extends EE_Data_Migration_Script_Base |
30 | 30 | { |
31 | - /** |
|
32 | - * |
|
33 | - * @param EE_DMS_Core_4_11_0 $dms_4_11 |
|
34 | - * @param TableManager|null $table_manager |
|
35 | - * @param TableAnalysis|null $table_analysis |
|
36 | - */ |
|
37 | - public function __construct( |
|
38 | - EE_DMS_Core_4_11_0 $dms_4_11, |
|
39 | - TableManager $table_manager = null, |
|
40 | - TableAnalysis $table_analysis = null |
|
41 | - ) { |
|
42 | - $this->previous_dms = $dms_4_11; |
|
43 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.12.0", "event_espresso"); |
|
44 | - $this->_priority = 10; |
|
45 | - $this->_migration_stages = [ |
|
46 | - new EE_DMS_4_12_0_Event_Venues(), |
|
47 | - ]; |
|
48 | - parent::__construct($table_manager, $table_analysis); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Whether to migrate or not. |
|
54 | - * |
|
55 | - * @param array $version_array |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function can_migrate_from_version($version_array): bool |
|
59 | - { |
|
60 | - $version_string = $version_array['Core']; |
|
61 | - return $version_string |
|
62 | - && version_compare($version_string, '4.12.0.decaf', '<') |
|
63 | - && version_compare($version_string, '4.11.0.decaf', '>='); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return bool |
|
69 | - * @throws EE_Error |
|
70 | - * @throws ReflectionException |
|
71 | - */ |
|
72 | - public function schema_changes_before_migration(): bool |
|
73 | - { |
|
74 | - require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
75 | - |
|
76 | - $table_name = 'esp_answer'; |
|
77 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
31 | + /** |
|
32 | + * |
|
33 | + * @param EE_DMS_Core_4_11_0 $dms_4_11 |
|
34 | + * @param TableManager|null $table_manager |
|
35 | + * @param TableAnalysis|null $table_analysis |
|
36 | + */ |
|
37 | + public function __construct( |
|
38 | + EE_DMS_Core_4_11_0 $dms_4_11, |
|
39 | + TableManager $table_manager = null, |
|
40 | + TableAnalysis $table_analysis = null |
|
41 | + ) { |
|
42 | + $this->previous_dms = $dms_4_11; |
|
43 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.12.0", "event_espresso"); |
|
44 | + $this->_priority = 10; |
|
45 | + $this->_migration_stages = [ |
|
46 | + new EE_DMS_4_12_0_Event_Venues(), |
|
47 | + ]; |
|
48 | + parent::__construct($table_manager, $table_analysis); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Whether to migrate or not. |
|
54 | + * |
|
55 | + * @param array $version_array |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function can_migrate_from_version($version_array): bool |
|
59 | + { |
|
60 | + $version_string = $version_array['Core']; |
|
61 | + return $version_string |
|
62 | + && version_compare($version_string, '4.12.0.decaf', '<') |
|
63 | + && version_compare($version_string, '4.11.0.decaf', '>='); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return bool |
|
69 | + * @throws EE_Error |
|
70 | + * @throws ReflectionException |
|
71 | + */ |
|
72 | + public function schema_changes_before_migration(): bool |
|
73 | + { |
|
74 | + require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
75 | + |
|
76 | + $table_name = 'esp_answer'; |
|
77 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
78 | 78 | REG_ID int(10) unsigned NOT NULL, |
79 | 79 | QST_ID int(10) unsigned NOT NULL, |
80 | 80 | ANS_value text NOT NULL, |
81 | 81 | PRIMARY KEY (ANS_ID), |
82 | 82 | KEY REG_ID (REG_ID), |
83 | 83 | KEY QST_ID (QST_ID)"; |
84 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
84 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
85 | 85 | |
86 | - $table_name = 'esp_attendee_meta'; |
|
87 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
86 | + $table_name = 'esp_attendee_meta'; |
|
87 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
88 | 88 | ATT_ID bigint(20) unsigned NOT NULL, |
89 | 89 | ATT_fname varchar(45) NOT NULL, |
90 | 90 | ATT_lname varchar(45) NOT NULL, |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | KEY ATT_email (ATT_email(191)), |
102 | 102 | KEY ATT_lname (ATT_lname), |
103 | 103 | KEY ATT_fname (ATT_fname)"; |
104 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
104 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
105 | 105 | |
106 | - $table_name = 'esp_checkin'; |
|
107 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
106 | + $table_name = 'esp_checkin'; |
|
107 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
108 | 108 | REG_ID int(10) unsigned NOT NULL, |
109 | 109 | DTT_ID int(10) unsigned NOT NULL, |
110 | 110 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | PRIMARY KEY (CHK_ID), |
113 | 113 | KEY REG_ID (REG_ID), |
114 | 114 | KEY DTT_ID (DTT_ID)"; |
115 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
115 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
116 | 116 | |
117 | - $table_name = 'esp_country'; |
|
118 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
117 | + $table_name = 'esp_country'; |
|
118 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
119 | 119 | CNT_ISO3 varchar(3) NOT NULL, |
120 | 120 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
121 | 121 | CNT_name varchar(45) NOT NULL, |
@@ -131,32 +131,32 @@ discard block |
||
131 | 131 | CNT_is_EU tinyint(1) DEFAULT '0', |
132 | 132 | CNT_active tinyint(1) DEFAULT '0', |
133 | 133 | PRIMARY KEY (CNT_ISO)"; |
134 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
134 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
135 | 135 | |
136 | - $table_name = 'esp_currency'; |
|
137 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
136 | + $table_name = 'esp_currency'; |
|
137 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
138 | 138 | CUR_single varchar(45) DEFAULT 'dollar', |
139 | 139 | CUR_plural varchar(45) DEFAULT 'dollars', |
140 | 140 | CUR_sign varchar(45) DEFAULT '$', |
141 | 141 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
142 | 142 | CUR_active tinyint(1) DEFAULT '0', |
143 | 143 | PRIMARY KEY (CUR_code)"; |
144 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
145 | - |
|
146 | - // note: although this table is no longer in use, |
|
147 | - // it hasn't been removed because then queries to the model will have errors. |
|
148 | - // but you should expect this table and its corresponding model to be removed in |
|
149 | - // the next few months |
|
150 | - $table_name = 'esp_currency_payment_method'; |
|
151 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
144 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
145 | + |
|
146 | + // note: although this table is no longer in use, |
|
147 | + // it hasn't been removed because then queries to the model will have errors. |
|
148 | + // but you should expect this table and its corresponding model to be removed in |
|
149 | + // the next few months |
|
150 | + $table_name = 'esp_currency_payment_method'; |
|
151 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
152 | 152 | CUR_code varchar(6) NOT NULL, |
153 | 153 | PMD_ID int(11) NOT NULL, |
154 | 154 | PRIMARY KEY (CPM_ID), |
155 | 155 | KEY PMD_ID (PMD_ID)"; |
156 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
156 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
157 | 157 | |
158 | - $table_name = 'esp_datetime'; |
|
159 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
158 | + $table_name = 'esp_datetime'; |
|
159 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
160 | 160 | EVT_ID bigint(20) unsigned NOT NULL, |
161 | 161 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
162 | 162 | DTT_name varchar(255) NOT NULL DEFAULT '', |
@@ -174,28 +174,28 @@ discard block |
||
174 | 174 | KEY DTT_EVT_start (DTT_EVT_start), |
175 | 175 | KEY EVT_ID (EVT_ID), |
176 | 176 | KEY DTT_is_primary (DTT_is_primary)"; |
177 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
177 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
178 | 178 | |
179 | - $table_name = "esp_datetime_ticket"; |
|
180 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
179 | + $table_name = "esp_datetime_ticket"; |
|
180 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | 181 | DTT_ID int(10) unsigned NOT NULL, |
182 | 182 | TKT_ID int(10) unsigned NOT NULL, |
183 | 183 | PRIMARY KEY (DTK_ID), |
184 | 184 | KEY DTT_ID (DTT_ID), |
185 | 185 | KEY TKT_ID (TKT_ID)"; |
186 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
186 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
187 | 187 | |
188 | - $table_name = 'esp_event_message_template'; |
|
189 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
188 | + $table_name = 'esp_event_message_template'; |
|
189 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
190 | 190 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
191 | 191 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
192 | 192 | PRIMARY KEY (EMT_ID), |
193 | 193 | KEY EVT_ID (EVT_ID), |
194 | 194 | KEY GRP_ID (GRP_ID)"; |
195 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
195 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
196 | 196 | |
197 | - $table_name = 'esp_event_meta'; |
|
198 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $table_name = 'esp_event_meta'; |
|
198 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
199 | 199 | EVT_ID bigint(20) unsigned NOT NULL, |
200 | 200 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | FSC_UUID varchar(25) DEFAULT NULL, |
213 | 213 | PRIMARY KEY (EVTM_ID), |
214 | 214 | KEY EVT_ID (EVT_ID)"; |
215 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
216 | 216 | |
217 | - $table_name = 'esp_event_question_group'; |
|
218 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | + $table_name = 'esp_event_question_group'; |
|
218 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
219 | 219 | EVT_ID bigint(20) unsigned NOT NULL, |
220 | 220 | QSG_ID int(10) unsigned NOT NULL, |
221 | 221 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
@@ -223,28 +223,28 @@ discard block |
||
223 | 223 | PRIMARY KEY (EQG_ID), |
224 | 224 | KEY EVT_ID (EVT_ID), |
225 | 225 | KEY QSG_ID (QSG_ID)"; |
226 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
226 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
227 | 227 | |
228 | - $table_name = 'esp_event_venue'; |
|
229 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
228 | + $table_name = 'esp_event_venue'; |
|
229 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | 230 | EVT_ID bigint(20) unsigned NOT NULL, |
231 | 231 | VNU_ID bigint(20) unsigned NOT NULL, |
232 | 232 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
233 | 233 | PRIMARY KEY (EVV_ID)"; |
234 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
234 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
235 | 235 | |
236 | - $table_name = 'esp_extra_meta'; |
|
237 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
236 | + $table_name = 'esp_extra_meta'; |
|
237 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
238 | 238 | OBJ_ID int(11) DEFAULT NULL, |
239 | 239 | EXM_type varchar(45) DEFAULT NULL, |
240 | 240 | EXM_key varchar(45) DEFAULT NULL, |
241 | 241 | EXM_value text, |
242 | 242 | PRIMARY KEY (EXM_ID), |
243 | 243 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
244 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
244 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
245 | 245 | |
246 | - $table_name = 'esp_extra_join'; |
|
247 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
246 | + $table_name = 'esp_extra_join'; |
|
247 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
248 | 248 | EXJ_first_model_id varchar(6) NOT NULL, |
249 | 249 | EXJ_first_model_name varchar(20) NOT NULL, |
250 | 250 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | PRIMARY KEY (EXJ_ID), |
253 | 253 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
254 | 254 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
255 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
255 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
256 | 256 | |
257 | - $table_name = 'esp_form_element'; |
|
258 | - $sql = "FIN_UUID varchar(25) NOT NULL, |
|
257 | + $table_name = 'esp_form_element'; |
|
258 | + $sql = "FIN_UUID varchar(25) NOT NULL, |
|
259 | 259 | FSC_UUID varchar(25) NOT NULL, |
260 | 260 | FIN_adminOnly tinyint(1) unsigned NOT NULL DEFAULT 0, |
261 | 261 | FIN_attributes text DEFAULT NULL, |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | KEY FSC_UUID (FSC_UUID), |
273 | 273 | KEY FIN_order (FIN_order), |
274 | 274 | KEY FIN_status (FIN_status)"; |
275 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
276 | 276 | |
277 | - $table_name = 'esp_form_section'; |
|
278 | - $sql = "FSC_UUID varchar(25) NOT NULL, |
|
277 | + $table_name = 'esp_form_section'; |
|
278 | + $sql = "FSC_UUID varchar(25) NOT NULL, |
|
279 | 279 | FSC_appliesTo tinytext NOT NULL, |
280 | 280 | FSC_attributes text DEFAULT NULL, |
281 | 281 | FSC_belongsTo varchar(25) DEFAULT NULL, |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | KEY FSC_belongsTo (FSC_belongsTo), |
288 | 288 | KEY FSC_order (FSC_order), |
289 | 289 | KEY FSC_status (FSC_status)"; |
290 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
290 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
291 | 291 | |
292 | - $table_name = 'esp_form_submission'; |
|
293 | - $sql = "FSB_UUID varchar(25) NOT NULL, |
|
292 | + $table_name = 'esp_form_submission'; |
|
293 | + $sql = "FSB_UUID varchar(25) NOT NULL, |
|
294 | 294 | FSC_UUID varchar(25) NOT NULL, |
295 | 295 | TXN_ID int(10) DEFAULT NULL, |
296 | 296 | FSB_data mediumtext DEFAULT NULL, |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | PRIMARY KEY (FSB_UUID), |
299 | 299 | KEY FSC_UUID (FSC_UUID), |
300 | 300 | KEY TXN_ID (TXN_ID)"; |
301 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
301 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
302 | 302 | |
303 | - $table_name = 'esp_line_item'; |
|
304 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
303 | + $table_name = 'esp_line_item'; |
|
304 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
305 | 305 | LIN_code varchar(245) NOT NULL DEFAULT '', |
306 | 306 | TXN_ID int(10) DEFAULT NULL, |
307 | 307 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -322,10 +322,10 @@ discard block |
||
322 | 322 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
323 | 323 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
324 | 324 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
325 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
326 | 326 | |
327 | - $table_name = 'esp_log'; |
|
328 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
327 | + $table_name = 'esp_log'; |
|
328 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
329 | 329 | LOG_time datetime DEFAULT NULL, |
330 | 330 | OBJ_ID varchar(45) DEFAULT NULL, |
331 | 331 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | KEY LOG_time (LOG_time), |
337 | 337 | KEY OBJ (OBJ_type,OBJ_ID), |
338 | 338 | KEY LOG_type (LOG_type)"; |
339 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
339 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
340 | 340 | |
341 | - $table_name = 'esp_message'; |
|
342 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
341 | + $table_name = 'esp_message'; |
|
342 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
343 | 343 | GRP_ID int(10) unsigned NULL, |
344 | 344 | MSG_token varchar(255) NULL, |
345 | 345 | TXN_ID int(10) unsigned NULL, |
@@ -371,20 +371,20 @@ discard block |
||
371 | 371 | KEY STS_ID (STS_ID), |
372 | 372 | KEY MSG_created (MSG_created), |
373 | 373 | KEY MSG_modified (MSG_modified)"; |
374 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
374 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
375 | 375 | |
376 | - $table_name = 'esp_message_template'; |
|
377 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
376 | + $table_name = 'esp_message_template'; |
|
377 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
378 | 378 | GRP_ID int(10) unsigned NOT NULL, |
379 | 379 | MTP_context varchar(50) NOT NULL, |
380 | 380 | MTP_template_field varchar(30) NOT NULL, |
381 | 381 | MTP_content text NOT NULL, |
382 | 382 | PRIMARY KEY (MTP_ID), |
383 | 383 | KEY GRP_ID (GRP_ID)"; |
384 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
385 | 385 | |
386 | - $table_name = 'esp_message_template_group'; |
|
387 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
386 | + $table_name = 'esp_message_template_group'; |
|
387 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
388 | 388 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
389 | 389 | MTP_name varchar(245) NOT NULL DEFAULT '', |
390 | 390 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
397 | 397 | PRIMARY KEY (GRP_ID), |
398 | 398 | KEY MTP_user_id (MTP_user_id)"; |
399 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
399 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | 400 | |
401 | - $table_name = 'esp_payment'; |
|
402 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
401 | + $table_name = 'esp_payment'; |
|
402 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
403 | 403 | TXN_ID int(10) unsigned DEFAULT NULL, |
404 | 404 | STS_ID varchar(3) DEFAULT NULL, |
405 | 405 | PAY_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
@@ -416,10 +416,10 @@ discard block |
||
416 | 416 | PRIMARY KEY (PAY_ID), |
417 | 417 | KEY PAY_timestamp (PAY_timestamp), |
418 | 418 | KEY TXN_ID (TXN_ID)"; |
419 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
419 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
420 | 420 | |
421 | - $table_name = 'esp_payment_method'; |
|
422 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
421 | + $table_name = 'esp_payment_method'; |
|
422 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
423 | 423 | PMD_type varchar(124) DEFAULT NULL, |
424 | 424 | PMD_name varchar(255) DEFAULT NULL, |
425 | 425 | PMD_desc text, |
@@ -435,10 +435,10 @@ discard block |
||
435 | 435 | PRIMARY KEY (PMD_ID), |
436 | 436 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
437 | 437 | KEY PMD_type (PMD_type)"; |
438 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
438 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
439 | 439 | |
440 | - $table_name = "esp_price"; |
|
441 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
440 | + $table_name = "esp_price"; |
|
441 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
442 | 442 | PRT_ID tinyint(3) unsigned NOT NULL, |
443 | 443 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
444 | 444 | PRC_name varchar(245) NOT NULL, |
@@ -451,10 +451,10 @@ discard block |
||
451 | 451 | PRC_parent int(10) unsigned DEFAULT 0, |
452 | 452 | PRIMARY KEY (PRC_ID), |
453 | 453 | KEY PRT_ID (PRT_ID)"; |
454 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
454 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
455 | 455 | |
456 | - $table_name = "esp_price_type"; |
|
457 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
456 | + $table_name = "esp_price_type"; |
|
457 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
458 | 458 | PRT_name varchar(45) NOT NULL, |
459 | 459 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
460 | 460 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -463,27 +463,27 @@ discard block |
||
463 | 463 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
464 | 464 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
465 | 465 | PRIMARY KEY (PRT_ID)"; |
466 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
466 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
467 | 467 | |
468 | - $table_name = "esp_ticket_price"; |
|
469 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
468 | + $table_name = "esp_ticket_price"; |
|
469 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
470 | 470 | TKT_ID int(10) unsigned NOT NULL, |
471 | 471 | PRC_ID int(10) unsigned NOT NULL, |
472 | 472 | PRIMARY KEY (TKP_ID), |
473 | 473 | KEY TKT_ID (TKT_ID), |
474 | 474 | KEY PRC_ID (PRC_ID)"; |
475 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
475 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
476 | 476 | |
477 | - $table_name = "esp_ticket_template"; |
|
478 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
477 | + $table_name = "esp_ticket_template"; |
|
478 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
479 | 479 | TTM_name varchar(45) NOT NULL, |
480 | 480 | TTM_description text, |
481 | 481 | TTM_file varchar(45), |
482 | 482 | PRIMARY KEY (TTM_ID)"; |
483 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
483 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
484 | 484 | |
485 | - $table_name = 'esp_question'; |
|
486 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
485 | + $table_name = 'esp_question'; |
|
486 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
487 | 487 | QST_display_text text NOT NULL, |
488 | 488 | QST_admin_label varchar(255) NOT NULL, |
489 | 489 | QST_system varchar(25) DEFAULT NULL, |
@@ -497,10 +497,10 @@ discard block |
||
497 | 497 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
498 | 498 | PRIMARY KEY (QST_ID), |
499 | 499 | KEY QST_order (QST_order)'; |
500 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
500 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
501 | 501 | |
502 | - $table_name = 'esp_question_group'; |
|
503 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
502 | + $table_name = 'esp_question_group'; |
|
503 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
504 | 504 | QSG_name varchar(255) NOT NULL, |
505 | 505 | QSG_identifier varchar(100) NOT NULL, |
506 | 506 | QSG_desc text NULL, |
@@ -513,20 +513,20 @@ discard block |
||
513 | 513 | PRIMARY KEY (QSG_ID), |
514 | 514 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
515 | 515 | KEY QSG_order (QSG_order)'; |
516 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
516 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
517 | 517 | |
518 | - $table_name = 'esp_question_group_question'; |
|
519 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
518 | + $table_name = 'esp_question_group_question'; |
|
519 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
520 | 520 | QSG_ID int(10) unsigned NOT NULL, |
521 | 521 | QST_ID int(10) unsigned NOT NULL, |
522 | 522 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
523 | 523 | PRIMARY KEY (QGQ_ID), |
524 | 524 | KEY QST_ID (QST_ID), |
525 | 525 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
526 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
526 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | 527 | |
528 | - $table_name = 'esp_question_option'; |
|
529 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
528 | + $table_name = 'esp_question_option'; |
|
529 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
530 | 530 | QSO_value varchar(255) NOT NULL, |
531 | 531 | QSO_desc text NOT NULL, |
532 | 532 | QST_ID int(10) unsigned NOT NULL, |
@@ -536,10 +536,10 @@ discard block |
||
536 | 536 | PRIMARY KEY (QSO_ID), |
537 | 537 | KEY QST_ID (QST_ID), |
538 | 538 | KEY QSO_order (QSO_order)"; |
539 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
540 | 540 | |
541 | - $table_name = 'esp_registration'; |
|
542 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
541 | + $table_name = 'esp_registration'; |
|
542 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
543 | 543 | EVT_ID bigint(20) unsigned NOT NULL, |
544 | 544 | ATT_ID bigint(20) unsigned NOT NULL, |
545 | 545 | TXN_ID int(10) unsigned NOT NULL, |
@@ -563,20 +563,20 @@ discard block |
||
563 | 563 | KEY TKT_ID (TKT_ID), |
564 | 564 | KEY EVT_ID (EVT_ID), |
565 | 565 | KEY STS_ID (STS_ID)"; |
566 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
566 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
567 | 567 | |
568 | - $table_name = 'esp_registration_payment'; |
|
569 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
568 | + $table_name = 'esp_registration_payment'; |
|
569 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
570 | 570 | REG_ID int(10) unsigned NOT NULL, |
571 | 571 | PAY_ID int(10) unsigned NULL, |
572 | 572 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
573 | 573 | PRIMARY KEY (RPY_ID), |
574 | 574 | KEY REG_ID (REG_ID), |
575 | 575 | KEY PAY_ID (PAY_ID)"; |
576 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
576 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
577 | 577 | |
578 | - $table_name = 'esp_state'; |
|
579 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
578 | + $table_name = 'esp_state'; |
|
579 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
580 | 580 | CNT_ISO varchar(2) NOT NULL, |
581 | 581 | STA_abbrev varchar(24) NOT NULL, |
582 | 582 | STA_name varchar(100) NOT NULL, |
@@ -584,10 +584,10 @@ discard block |
||
584 | 584 | PRIMARY KEY (STA_ID), |
585 | 585 | KEY STA_abbrev (STA_abbrev), |
586 | 586 | KEY CNT_ISO (CNT_ISO)"; |
587 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
587 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
588 | 588 | |
589 | - $table_name = 'esp_status'; |
|
590 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
589 | + $table_name = 'esp_status'; |
|
590 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
591 | 591 | STS_code varchar(45) NOT NULL, |
592 | 592 | STS_type varchar(45) NOT NULL, |
593 | 593 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -595,10 +595,10 @@ discard block |
||
595 | 595 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
596 | 596 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
597 | 597 | KEY STS_type (STS_type)"; |
598 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
598 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
599 | 599 | |
600 | - $table_name = "esp_ticket"; |
|
601 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
600 | + $table_name = "esp_ticket"; |
|
601 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
602 | 602 | TTM_ID int(10) unsigned NOT NULL, |
603 | 603 | TKT_name varchar(245) NOT NULL DEFAULT '', |
604 | 604 | TKT_description text NOT NULL, |
@@ -623,10 +623,10 @@ discard block |
||
623 | 623 | TKT_visibility smallint(6) unsigned NOT NULL DEFAULT 100, |
624 | 624 | PRIMARY KEY (TKT_ID), |
625 | 625 | KEY TKT_start_date (TKT_start_date)"; |
626 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
626 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
627 | 627 | |
628 | - $table_name = 'esp_transaction'; |
|
629 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
628 | + $table_name = 'esp_transaction'; |
|
629 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
630 | 630 | TXN_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
631 | 631 | TXN_total decimal(12,3) DEFAULT '0.00', |
632 | 632 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -638,10 +638,10 @@ discard block |
||
638 | 638 | PRIMARY KEY (TXN_ID), |
639 | 639 | KEY TXN_timestamp (TXN_timestamp), |
640 | 640 | KEY STS_ID (STS_ID)"; |
641 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
641 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
642 | 642 | |
643 | - $table_name = 'esp_venue_meta'; |
|
644 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
643 | + $table_name = 'esp_venue_meta'; |
|
644 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
645 | 645 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
646 | 646 | VNU_address varchar(255) DEFAULT NULL, |
647 | 647 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -660,18 +660,18 @@ discard block |
||
660 | 660 | KEY VNU_ID (VNU_ID), |
661 | 661 | KEY STA_ID (STA_ID), |
662 | 662 | KEY CNT_ISO (CNT_ISO)"; |
663 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
663 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
664 | 664 | |
665 | - $this->previous_dms->insert_default_data(); |
|
666 | - return true; |
|
667 | - } |
|
665 | + $this->previous_dms->insert_default_data(); |
|
666 | + return true; |
|
667 | + } |
|
668 | 668 | |
669 | 669 | |
670 | - /** |
|
671 | - * @return boolean |
|
672 | - */ |
|
673 | - public function schema_changes_after_migration(): bool |
|
674 | - { |
|
675 | - return true; |
|
676 | - } |
|
670 | + /** |
|
671 | + * @return boolean |
|
672 | + */ |
|
673 | + public function schema_changes_after_migration(): bool |
|
674 | + { |
|
675 | + return true; |
|
676 | + } |
|
677 | 677 | } |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | // unfortunately, this needs to be done upon INCLUSION of this file, |
8 | 8 | // instead of construction, because it only gets constructed on first page load |
9 | 9 | // (all other times it gets resurrected from a wordpress option) |
10 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_12_0_stages/*'); |
|
10 | +$stages = glob(EE_CORE.'data_migration_scripts/4_12_0_stages/*'); |
|
11 | 11 | $class_to_filepath = []; |
12 | 12 | foreach ($stages as $filepath) { |
13 | 13 | $matches = []; |
14 | 14 | preg_match('~4_12_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
15 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
15 | + $class_to_filepath[$matches[1]] = $filepath; |
|
16 | 16 | } |
17 | 17 | // give addons a chance to autoload their stages too |
18 | 18 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_12_0__autoloaded_stages', $class_to_filepath); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function schema_changes_before_migration(): bool |
73 | 73 | { |
74 | - require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
74 | + require_once EE_HELPERS.'EEH_Activation.helper.php'; |
|
75 | 75 | |
76 | 76 | $table_name = 'esp_answer'; |
77 | 77 | $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -12,54 +12,54 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_DMS_4_12_0_Event_Venues extends EE_Data_Migration_Script_Stage_Table |
14 | 14 | { |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - private $_event_meta; |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + private $_event_meta; |
|
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * Just initializes the status of the migration |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - global $wpdb; |
|
27 | - $this->_pretty_name = esc_html__('Event Venue Relations', 'event_espresso'); |
|
28 | - $this->_old_table = $wpdb->prefix . 'esp_event_venue'; |
|
29 | - $this->_event_meta = $wpdb->prefix . 'esp_event_meta'; |
|
30 | - parent::__construct(); |
|
31 | - } |
|
21 | + /** |
|
22 | + * Just initializes the status of the migration |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + global $wpdb; |
|
27 | + $this->_pretty_name = esc_html__('Event Venue Relations', 'event_espresso'); |
|
28 | + $this->_old_table = $wpdb->prefix . 'esp_event_venue'; |
|
29 | + $this->_event_meta = $wpdb->prefix . 'esp_event_meta'; |
|
30 | + parent::__construct(); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Copies Venue IDs from `wp_esp_event_venue` to `wp_esp_event_meta` for each Event |
|
36 | - * |
|
37 | - * @param array $old_row an associative array where keys are column names and values are their values. |
|
38 | - * @return null |
|
39 | - */ |
|
40 | - protected function _migrate_old_row($old_row): ?bool |
|
41 | - { |
|
42 | - $EVT_ID = |
|
43 | - isset($old_row['EVT_ID']) |
|
44 | - ? absint($old_row['EVT_ID']) |
|
45 | - : 0; |
|
46 | - $VNU_ID = |
|
47 | - isset($old_row['VNU_ID']) |
|
48 | - ? absint($old_row['VNU_ID']) |
|
49 | - : 0; |
|
50 | - if ($EVT_ID && $VNU_ID) { |
|
51 | - global $wpdb; |
|
52 | - // If the question group was also for primary attendees, we should just update that row. |
|
53 | - // And we delete this row. |
|
54 | - $result = $wpdb->update( |
|
55 | - $this->_event_meta, |
|
56 | - ['VNU_ID' => $VNU_ID], // data |
|
57 | - ['EVT_ID' => $EVT_ID], // where |
|
58 | - ['%d'], // data format |
|
59 | - ['%d'] // where format |
|
60 | - ); |
|
61 | - return filter_var($result, FILTER_VALIDATE_BOOLEAN); |
|
62 | - } |
|
63 | - return false; |
|
64 | - } |
|
34 | + /** |
|
35 | + * Copies Venue IDs from `wp_esp_event_venue` to `wp_esp_event_meta` for each Event |
|
36 | + * |
|
37 | + * @param array $old_row an associative array where keys are column names and values are their values. |
|
38 | + * @return null |
|
39 | + */ |
|
40 | + protected function _migrate_old_row($old_row): ?bool |
|
41 | + { |
|
42 | + $EVT_ID = |
|
43 | + isset($old_row['EVT_ID']) |
|
44 | + ? absint($old_row['EVT_ID']) |
|
45 | + : 0; |
|
46 | + $VNU_ID = |
|
47 | + isset($old_row['VNU_ID']) |
|
48 | + ? absint($old_row['VNU_ID']) |
|
49 | + : 0; |
|
50 | + if ($EVT_ID && $VNU_ID) { |
|
51 | + global $wpdb; |
|
52 | + // If the question group was also for primary attendees, we should just update that row. |
|
53 | + // And we delete this row. |
|
54 | + $result = $wpdb->update( |
|
55 | + $this->_event_meta, |
|
56 | + ['VNU_ID' => $VNU_ID], // data |
|
57 | + ['EVT_ID' => $EVT_ID], // where |
|
58 | + ['%d'], // data format |
|
59 | + ['%d'] // where format |
|
60 | + ); |
|
61 | + return filter_var($result, FILTER_VALIDATE_BOOLEAN); |
|
62 | + } |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | } |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | { |
26 | 26 | global $wpdb; |
27 | 27 | $this->_pretty_name = esc_html__('Event Venue Relations', 'event_espresso'); |
28 | - $this->_old_table = $wpdb->prefix . 'esp_event_venue'; |
|
29 | - $this->_event_meta = $wpdb->prefix . 'esp_event_meta'; |
|
28 | + $this->_old_table = $wpdb->prefix.'esp_event_venue'; |
|
29 | + $this->_event_meta = $wpdb->prefix.'esp_event_meta'; |
|
30 | 30 | parent::__construct(); |
31 | 31 | } |
32 | 32 | |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | // And we delete this row. |
54 | 54 | $result = $wpdb->update( |
55 | 55 | $this->_event_meta, |
56 | - ['VNU_ID' => $VNU_ID], // data |
|
57 | - ['EVT_ID' => $EVT_ID], // where |
|
58 | - ['%d'], // data format |
|
56 | + ['VNU_ID' => $VNU_ID], // data |
|
57 | + ['EVT_ID' => $EVT_ID], // where |
|
58 | + ['%d'], // data format |
|
59 | 59 | ['%d'] // where format |
60 | 60 | ); |
61 | 61 | return filter_var($result, FILTER_VALIDATE_BOOLEAN); |
@@ -13,842 +13,842 @@ |
||
13 | 13 | class EEM_Datetime extends EEM_Soft_Delete_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var EEM_Datetime $_instance |
|
18 | - */ |
|
19 | - protected static $_instance; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * private constructor to prevent direct creation |
|
24 | - * |
|
25 | - * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
26 | - * (and any incoming timezone data that gets saved). |
|
27 | - * Note this just sends the timezone info to the date time model field objects. |
|
28 | - * Default is NULL |
|
29 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | - * @throws EE_Error |
|
31 | - * @throws InvalidArgumentException |
|
32 | - * @throws InvalidArgumentException |
|
33 | - */ |
|
34 | - protected function __construct($timezone) |
|
35 | - { |
|
36 | - $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
37 | - $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
38 | - $this->_tables = [ |
|
39 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
40 | - ]; |
|
41 | - $this->_fields = [ |
|
42 | - 'Datetime' => [ |
|
43 | - 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
44 | - 'DTT_ID', |
|
45 | - esc_html__('Datetime ID', 'event_espresso') |
|
46 | - ), |
|
47 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
48 | - 'EVT_ID', |
|
49 | - esc_html__('Event ID', 'event_espresso'), |
|
50 | - false, |
|
51 | - 0, |
|
52 | - 'Event' |
|
53 | - ), |
|
54 | - 'VNU_ID' => new EE_Foreign_Key_Int_Field( |
|
55 | - 'VNU_ID', |
|
56 | - __('Venue ID', 'event_espresso'), |
|
57 | - false, |
|
58 | - 0, |
|
59 | - 'Venue' |
|
60 | - ), |
|
61 | - 'DTT_name' => new EE_Plain_Text_Field( |
|
62 | - 'DTT_name', |
|
63 | - esc_html__('Datetime Name', 'event_espresso'), |
|
64 | - false, |
|
65 | - '' |
|
66 | - ), |
|
67 | - 'DTT_description' => new EE_Post_Content_Field( |
|
68 | - 'DTT_description', |
|
69 | - esc_html__('Description for Datetime', 'event_espresso'), |
|
70 | - false, |
|
71 | - '' |
|
72 | - ), |
|
73 | - 'DTT_EVT_start' => new EE_Datetime_Field( |
|
74 | - 'DTT_EVT_start', |
|
75 | - esc_html__('Start time/date of Event', 'event_espresso'), |
|
76 | - false, |
|
77 | - EE_Datetime_Field::now, |
|
78 | - $timezone |
|
79 | - ), |
|
80 | - 'DTT_EVT_end' => new EE_Datetime_Field( |
|
81 | - 'DTT_EVT_end', |
|
82 | - esc_html__('End time/date of Event', 'event_espresso'), |
|
83 | - false, |
|
84 | - EE_Datetime_Field::now, |
|
85 | - $timezone |
|
86 | - ), |
|
87 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
88 | - 'DTT_reg_limit', |
|
89 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
90 | - true, |
|
91 | - EE_INF |
|
92 | - ), |
|
93 | - 'DTT_sold' => new EE_Integer_Field( |
|
94 | - 'DTT_sold', |
|
95 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
96 | - true, |
|
97 | - 0 |
|
98 | - ), |
|
99 | - 'DTT_reserved' => new EE_Integer_Field( |
|
100 | - 'DTT_reserved', |
|
101 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
102 | - false, |
|
103 | - 0 |
|
104 | - ), |
|
105 | - 'DTT_is_primary' => new EE_Boolean_Field( |
|
106 | - 'DTT_is_primary', |
|
107 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
108 | - false, |
|
109 | - false |
|
110 | - ), |
|
111 | - 'DTT_order' => new EE_Integer_Field( |
|
112 | - 'DTT_order', |
|
113 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
114 | - false, |
|
115 | - 0 |
|
116 | - ), |
|
117 | - 'DTT_parent' => new EE_Integer_Field( |
|
118 | - 'DTT_parent', |
|
119 | - esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
120 | - true, |
|
121 | - 0 |
|
122 | - ), |
|
123 | - 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
124 | - 'DTT_deleted', |
|
125 | - esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
126 | - false, |
|
127 | - false |
|
128 | - ), |
|
129 | - ], |
|
130 | - ]; |
|
131 | - $this->_model_relations = [ |
|
132 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
133 | - 'Event' => new EE_Belongs_To_Relation(), |
|
134 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
135 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
136 | - 'Venue' => new EE_Belongs_To_Relation(), |
|
137 | - ]; |
|
138 | - $path_to_event_model = 'Event'; |
|
139 | - $this->model_chain_to_password = $path_to_event_model; |
|
140 | - $this->_model_chain_to_wp_user = $path_to_event_model; |
|
141 | - // this model is generally available for reading |
|
142 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
143 | - new EE_Restriction_Generator_Event_Related_Public( |
|
144 | - $path_to_event_model |
|
145 | - ); |
|
146 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
147 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
148 | - $path_to_event_model |
|
149 | - ); |
|
150 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
151 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
152 | - $path_to_event_model |
|
153 | - ); |
|
154 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
155 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
156 | - $path_to_event_model, |
|
157 | - EEM_Base::caps_edit |
|
158 | - ); |
|
159 | - parent::__construct($timezone); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * create new blank datetime |
|
165 | - * |
|
166 | - * @access public |
|
167 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
168 | - * @throws EE_Error |
|
169 | - * @throws InvalidArgumentException |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - * @throws ReflectionException |
|
172 | - * @throws InvalidInterfaceException |
|
173 | - */ |
|
174 | - public function create_new_blank_datetime() |
|
175 | - { |
|
176 | - // makes sure timezone is always set. |
|
177 | - $timezone_string = $this->get_timezone(); |
|
178 | - /** |
|
179 | - * Filters the initial start date for the new datetime. |
|
180 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
181 | - * |
|
182 | - * @param int $start_date Unix timestamp representing now + 30 days in seconds. |
|
183 | - * @return int Unix timestamp |
|
184 | - */ |
|
185 | - $start_date = apply_filters( |
|
186 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
187 | - $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
188 | - ); |
|
189 | - /** |
|
190 | - * Filters the initial end date for the new datetime. |
|
191 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
192 | - * |
|
193 | - * @param int $end_data Unix timestamp representing now + 30 days in seconds. |
|
194 | - * @return int Unix timestamp |
|
195 | - */ |
|
196 | - $end_date = apply_filters( |
|
197 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
198 | - $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
199 | - ); |
|
200 | - $blank_datetime = EE_Datetime::new_instance( |
|
201 | - [ |
|
202 | - 'DTT_EVT_start' => $start_date, |
|
203 | - 'DTT_EVT_end' => $end_date, |
|
204 | - 'DTT_order' => 1, |
|
205 | - 'DTT_reg_limit' => EE_INF, |
|
206 | - ], |
|
207 | - $timezone_string |
|
208 | - ); |
|
209 | - /** |
|
210 | - * Filters the initial start time and format for the new EE_Datetime instance. |
|
211 | - * |
|
212 | - * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
213 | - * format. |
|
214 | - * @return array |
|
215 | - */ |
|
216 | - $start_time = apply_filters( |
|
217 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
218 | - ['8am', 'ga'] |
|
219 | - ); |
|
220 | - /** |
|
221 | - * Filters the initial end time and format for the new EE_Datetime instance. |
|
222 | - * |
|
223 | - * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
224 | - * format |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - $end_time = apply_filters( |
|
228 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
229 | - ['5pm', 'ga'] |
|
230 | - ); |
|
231 | - $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
232 | - $blank_datetime->set_start_time( |
|
233 | - $this->convert_datetime_for_query( |
|
234 | - 'DTT_EVT_start', |
|
235 | - $start_time[0], |
|
236 | - $start_time[1], |
|
237 | - $timezone_string |
|
238 | - ) |
|
239 | - ); |
|
240 | - $blank_datetime->set_end_time( |
|
241 | - $this->convert_datetime_for_query( |
|
242 | - 'DTT_EVT_end', |
|
243 | - $end_time[0], |
|
244 | - $end_time[1], |
|
245 | - $timezone_string |
|
246 | - ) |
|
247 | - ); |
|
248 | - return [$blank_datetime]; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Validates whether the start_time and end_time are in the expected format. |
|
254 | - * |
|
255 | - * @param array $start_time |
|
256 | - * @param array $end_time |
|
257 | - * @throws InvalidArgumentException |
|
258 | - * @throws InvalidDataTypeException |
|
259 | - */ |
|
260 | - private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time) |
|
261 | - { |
|
262 | - if (! is_array($start_time)) { |
|
263 | - throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
264 | - } |
|
265 | - if (! is_array($end_time)) { |
|
266 | - throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
267 | - } |
|
268 | - if (count($start_time) !== 2) { |
|
269 | - throw new InvalidArgumentException( |
|
270 | - sprintf( |
|
271 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
272 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
273 | - '$start_time' |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - if (count($end_time) !== 2) { |
|
278 | - throw new InvalidArgumentException( |
|
279 | - sprintf( |
|
280 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
281 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
282 | - '$end_time' |
|
283 | - ) |
|
284 | - ); |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * get event start date from db |
|
291 | - * |
|
292 | - * @access public |
|
293 | - * @param int $EVT_ID |
|
294 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
295 | - * @throws EE_Error |
|
296 | - * @throws ReflectionException |
|
297 | - */ |
|
298 | - public function get_all_event_dates($EVT_ID = 0) |
|
299 | - { |
|
300 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
301 | - return $this->create_new_blank_datetime(); |
|
302 | - } |
|
303 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
304 | - if (empty($results)) { |
|
305 | - return $this->create_new_blank_datetime(); |
|
306 | - } |
|
307 | - return $results; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
313 | - * |
|
314 | - * @public |
|
315 | - * @param int $EVT_ID event id |
|
316 | - * @param boolean $include_expired |
|
317 | - * @param boolean $include_deleted |
|
318 | - * @param int $limit If included then limit the count of results by |
|
319 | - * the given number |
|
320 | - * @return EE_Datetime[] |
|
321 | - * @throws EE_Error |
|
322 | - */ |
|
323 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
324 | - int $EVT_ID, |
|
325 | - bool $include_expired = true, |
|
326 | - bool $include_deleted = true, |
|
327 | - $limit = 0 |
|
328 | - ) { |
|
329 | - $prev_data_prep_value = $this->prepModelForQuery(); |
|
330 | - $where_params = ['Event.EVT_ID' => absint($EVT_ID)]; |
|
331 | - $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
332 | - $query_params = $this->addDefaultWhereConditions($query_params); |
|
333 | - $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order'); |
|
334 | - return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
340 | - * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
341 | - * and then the earlier datetimes are the most important. |
|
342 | - * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
343 | - * |
|
344 | - * @param int $EVT_ID |
|
345 | - * @param int $limit |
|
346 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
347 | - * @throws EE_Error |
|
348 | - */ |
|
349 | - public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0) |
|
350 | - { |
|
351 | - $query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)]; |
|
352 | - $query_params = $this->addDefaultWhereConditions($query_params); |
|
353 | - $query_params = $this->addDefaultQueryParams($query_params, $limit); |
|
354 | - return $this->get_all($query_params); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @param int $EVT_ID |
|
360 | - * @param boolean $include_expired |
|
361 | - * @param boolean $include_deleted |
|
362 | - * @return EE_Datetime |
|
363 | - * @throws EE_Error |
|
364 | - */ |
|
365 | - public function get_oldest_datetime_for_event( |
|
366 | - int $EVT_ID, |
|
367 | - bool $include_expired = false, |
|
368 | - bool $include_deleted = false |
|
369 | - ) { |
|
370 | - $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
371 | - $EVT_ID, |
|
372 | - $include_expired, |
|
373 | - $include_deleted, |
|
374 | - 1 |
|
375 | - ); |
|
376 | - if ($results) { |
|
377 | - return array_shift($results); |
|
378 | - } |
|
379 | - return null; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Gets the 'primary' datetime for an event. |
|
385 | - * |
|
386 | - * @param int $EVT_ID |
|
387 | - * @param bool $try_to_exclude_expired |
|
388 | - * @param bool $try_to_exclude_deleted |
|
389 | - * @return EE_Datetime |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function get_primary_datetime_for_event( |
|
393 | - int $EVT_ID, |
|
394 | - bool $try_to_exclude_expired = true, |
|
395 | - bool $try_to_exclude_deleted = true |
|
396 | - ) { |
|
397 | - if ($try_to_exclude_expired) { |
|
398 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
399 | - if ($non_expired) { |
|
400 | - return $non_expired; |
|
401 | - } |
|
402 | - } |
|
403 | - if ($try_to_exclude_deleted) { |
|
404 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
405 | - if ($expired_even) { |
|
406 | - return $expired_even; |
|
407 | - } |
|
408 | - } |
|
409 | - return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
415 | - * only by start date |
|
416 | - * |
|
417 | - * @param int $EVT_ID |
|
418 | - * @param boolean $include_expired |
|
419 | - * @param boolean $include_deleted |
|
420 | - * @param int $limit |
|
421 | - * @return EE_Datetime[] |
|
422 | - * @throws EE_Error |
|
423 | - */ |
|
424 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
425 | - int $EVT_ID, |
|
426 | - bool $include_expired = true, |
|
427 | - bool $include_deleted = true, |
|
428 | - $limit = 0 |
|
429 | - ) { |
|
430 | - $prev_data_prep_value = $this->prepModelForQuery(); |
|
431 | - $where_params = ['Event.EVT_ID' => absint($EVT_ID)]; |
|
432 | - $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
433 | - $query_params = $this->addDefaultWhereConditions( |
|
434 | - $query_params, |
|
435 | - EEM_Base::default_where_conditions_this_only |
|
436 | - ); |
|
437 | - $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order'); |
|
438 | - return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
444 | - * only by start date |
|
445 | - * |
|
446 | - * @param int $TKT_ID |
|
447 | - * @param boolean $include_expired |
|
448 | - * @param boolean $include_deleted |
|
449 | - * @param int $limit |
|
450 | - * @return EE_Datetime[] |
|
451 | - * @throws EE_Error |
|
452 | - */ |
|
453 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
454 | - int $TKT_ID, |
|
455 | - bool $include_expired = true, |
|
456 | - bool $include_deleted = true, |
|
457 | - $limit = 0 |
|
458 | - ) { |
|
459 | - $prev_data_prep_value = $this->prepModelForQuery(); |
|
460 | - $where_params = ['Ticket.TKT_ID' => absint($TKT_ID)]; |
|
461 | - $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
462 | - $query_params = $this->addDefaultQueryParams($query_params, $limit); |
|
463 | - return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
469 | - * datetimes. |
|
470 | - * |
|
471 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
472 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
473 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
474 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
475 | - * that number |
|
476 | - * @return EE_Datetime[] |
|
477 | - * @throws EE_Error |
|
478 | - */ |
|
479 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
480 | - int $TKT_ID, |
|
481 | - bool $include_expired = true, |
|
482 | - bool $include_deleted = true, |
|
483 | - $limit = 0 |
|
484 | - ) { |
|
485 | - $prev_data_prep_value = $this->prepModelForQuery(); |
|
486 | - $where_params = ['Ticket.TKT_ID' => absint($TKT_ID)]; |
|
487 | - $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
488 | - $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order'); |
|
489 | - return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
495 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
496 | - * |
|
497 | - * @param int $EVT_ID |
|
498 | - * @return EE_Datetime |
|
499 | - * @throws EE_Error |
|
500 | - */ |
|
501 | - public function get_most_important_datetime_for_event(int $EVT_ID) |
|
502 | - { |
|
503 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
504 | - if ($results) { |
|
505 | - return array_shift($results); |
|
506 | - } |
|
507 | - return null; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
513 | - * grouped by month and year. |
|
514 | - * |
|
515 | - * @param array $where_params @see |
|
516 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
517 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
518 | - * Can be: |
|
519 | - * - '' = no filter |
|
520 | - * - upcoming = Published events with at least one upcoming datetime. |
|
521 | - * - expired = Events with all datetimes expired. |
|
522 | - * - active = Events that are published and have at least one datetime that |
|
523 | - * starts before now and ends after now. |
|
524 | - * - inactive = Events that are either not published. |
|
525 | - * @return EE_Base_Class[] |
|
526 | - * @throws EE_Error |
|
527 | - * @throws InvalidArgumentException |
|
528 | - * @throws InvalidArgumentException |
|
529 | - */ |
|
530 | - public function get_dtt_months_and_years(array $where_params, $evt_active_status = '') |
|
531 | - { |
|
532 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
533 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
534 | - switch ($evt_active_status) { |
|
535 | - case 'upcoming': |
|
536 | - $where_params['Event.status'] = 'publish'; |
|
537 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
538 | - if (isset($where_params['DTT_EVT_start'])) { |
|
539 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
540 | - } |
|
541 | - $where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start]; |
|
542 | - break; |
|
543 | - case 'expired': |
|
544 | - if (isset($where_params['Event.status'])) { |
|
545 | - unset($where_params['Event.status']); |
|
546 | - } |
|
547 | - // get events to exclude |
|
548 | - $exclude_query[0] = array_merge( |
|
549 | - $where_params, |
|
550 | - ['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]] |
|
551 | - ); |
|
552 | - // first get all events that have datetimes where its not expired. |
|
553 | - $event_ids = $this->_get_all_wpdb_results( |
|
554 | - $exclude_query, |
|
555 | - OBJECT_K, |
|
556 | - 'Datetime.EVT_ID' |
|
557 | - ); |
|
558 | - $event_ids = array_keys($event_ids); |
|
559 | - if (isset($where_params['DTT_EVT_end'])) { |
|
560 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
561 | - } |
|
562 | - $where_params['DTT_EVT_end'] = ['<', $current_time_for_DTT_EVT_end]; |
|
563 | - $where_params['Event.EVT_ID'] = ['NOT IN', $event_ids]; |
|
564 | - break; |
|
565 | - case 'active': |
|
566 | - $where_params['Event.status'] = 'publish'; |
|
567 | - if (isset($where_params['DTT_EVT_start'])) { |
|
568 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
569 | - } |
|
570 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
571 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
572 | - } |
|
573 | - $where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start]; |
|
574 | - $where_params['DTT_EVT_end'] = ['>', $current_time_for_DTT_EVT_end]; |
|
575 | - break; |
|
576 | - case 'inactive': |
|
577 | - if (isset($where_params['Event.status'])) { |
|
578 | - unset($where_params['Event.status']); |
|
579 | - } |
|
580 | - if (isset($where_params['OR'])) { |
|
581 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
582 | - } |
|
583 | - if (isset($where_params['DTT_EVT_end'])) { |
|
584 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
585 | - unset($where_params['DTT_EVT_end']); |
|
586 | - } |
|
587 | - if (isset($where_params['DTT_EVT_start'])) { |
|
588 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
589 | - unset($where_params['DTT_EVT_start']); |
|
590 | - } |
|
591 | - $where_params['AND']['Event.status'] = ['!=', 'publish']; |
|
592 | - break; |
|
593 | - } |
|
594 | - $query_params[0] = $where_params; |
|
595 | - $query_params['group_by'] = ['dtt_year', 'dtt_month']; |
|
596 | - $query_params = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC'); |
|
597 | - |
|
598 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
599 | - $this->get_timezone(), |
|
600 | - 'DTT_EVT_start' |
|
601 | - ); |
|
602 | - $columns_to_select = [ |
|
603 | - 'dtt_year' => ['YEAR(' . $query_interval . ')', '%s'], |
|
604 | - 'dtt_month' => ['MONTHNAME(' . $query_interval . ')', '%s'], |
|
605 | - 'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'], |
|
606 | - ]; |
|
607 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
613 | - * for the tickets for each datetime) |
|
614 | - * |
|
615 | - * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
616 | - * @throws EE_Error |
|
617 | - * @throws ReflectionException |
|
618 | - */ |
|
619 | - public function update_sold(array $datetimes) |
|
620 | - { |
|
621 | - EE_Error::doing_it_wrong( |
|
622 | - __FUNCTION__, |
|
623 | - esc_html__( |
|
624 | - 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
625 | - 'event_espresso' |
|
626 | - ), |
|
627 | - '4.9.32.rc.005' |
|
628 | - ); |
|
629 | - foreach ($datetimes as $datetime) { |
|
630 | - $datetime->update_sold(); |
|
631 | - } |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * Gets the total number of tickets available at a particular datetime |
|
637 | - * (does NOT take into account the datetime's spaces available) |
|
638 | - * |
|
639 | - * @param int $DTT_ID |
|
640 | - * @param array $query_params |
|
641 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
642 | - * tickets attached to datetime then FALSE is returned. |
|
643 | - * @throws EE_Error |
|
644 | - * @throws ReflectionException |
|
645 | - */ |
|
646 | - public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = []) |
|
647 | - { |
|
648 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
649 | - if ($datetime instanceof EE_Datetime) { |
|
650 | - return $datetime->tickets_remaining($query_params); |
|
651 | - } |
|
652 | - return 0; |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
658 | - * |
|
659 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
660 | - * stati you want counts for as values in the array. An empty array returns counts |
|
661 | - * for all valid stati. |
|
662 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
663 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
664 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
665 | - * @throws EE_Error |
|
666 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
667 | - * EE_Datetime::expired |
|
668 | - */ |
|
669 | - public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = []) |
|
670 | - { |
|
671 | - // only accept where conditions for this query. |
|
672 | - $_where = isset($query_params[0]) ? $query_params[0] : []; |
|
673 | - $status_query_args = [ |
|
674 | - EE_Datetime::active => array_merge( |
|
675 | - $_where, |
|
676 | - ['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]] |
|
677 | - ), |
|
678 | - EE_Datetime::upcoming => array_merge( |
|
679 | - $_where, |
|
680 | - ['DTT_EVT_start' => ['>', time()]] |
|
681 | - ), |
|
682 | - EE_Datetime::expired => array_merge( |
|
683 | - $_where, |
|
684 | - ['DTT_EVT_end' => ['<', time()]] |
|
685 | - ), |
|
686 | - ]; |
|
687 | - if (! empty($stati_to_include)) { |
|
688 | - foreach (array_keys($status_query_args) as $status) { |
|
689 | - if (! in_array($status, $stati_to_include, true)) { |
|
690 | - unset($status_query_args[ $status ]); |
|
691 | - } |
|
692 | - } |
|
693 | - } |
|
694 | - // loop through and query counts for each stati. |
|
695 | - $status_query_results = []; |
|
696 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
697 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
698 | - [$status_where_conditions], |
|
699 | - 'DTT_ID', |
|
700 | - true |
|
701 | - ); |
|
702 | - } |
|
703 | - return $status_query_results; |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - /** |
|
708 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
709 | - * |
|
710 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
711 | - * @param array $query_params |
|
712 | - * @return int |
|
713 | - * @throws EE_Error |
|
714 | - */ |
|
715 | - public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = []) |
|
716 | - { |
|
717 | - $count = $this->get_datetime_counts_by_status([$status], $query_params); |
|
718 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * @return bool|int |
|
724 | - * @since $VID:$ |
|
725 | - */ |
|
726 | - private function prepModelForQuery() |
|
727 | - { |
|
728 | - $prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
729 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
730 | - return $prev_data_prep_value; |
|
731 | - } |
|
732 | - |
|
733 | - |
|
734 | - /** |
|
735 | - * @param array $query_params |
|
736 | - * @param bool|int $prev_data_prep_value |
|
737 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
738 | - * @throws EE_Error |
|
739 | - * @since $VID:$ |
|
740 | - */ |
|
741 | - private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value) |
|
742 | - { |
|
743 | - $result = $this->get_all($query_params); |
|
744 | - $this->assume_values_already_prepared_by_model_object($prev_data_prep_value); |
|
745 | - return $result; |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * @param array $query_params |
|
751 | - * @param int $limit |
|
752 | - * @param string $order_by |
|
753 | - * @param string $order |
|
754 | - * @return array |
|
755 | - * @since $VID:$ |
|
756 | - */ |
|
757 | - private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC') |
|
758 | - { |
|
759 | - $query_params = $this->addOrderByQueryParams($query_params, $order_by, $order); |
|
760 | - $query_params = $this->addLimitQueryParams($query_params, $limit); |
|
761 | - return $query_params; |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - /** |
|
766 | - * @param array $query_params |
|
767 | - * @param string $default_where_conditions |
|
768 | - * @return array |
|
769 | - * @since $VID:$ |
|
770 | - */ |
|
771 | - private function addDefaultWhereConditions( |
|
772 | - array $query_params, |
|
773 | - $default_where_conditions = EEM_Base::default_where_conditions_none |
|
774 | - ) { |
|
775 | - $query_params['default_where_conditions'] = $default_where_conditions; |
|
776 | - return $query_params; |
|
777 | - } |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * @param array $where_params |
|
782 | - * @param bool $include_deleted |
|
783 | - * @param bool $include_expired |
|
784 | - * @return array |
|
785 | - * @since $VID:$ |
|
786 | - */ |
|
787 | - private function addDefaultWhereParams(array $where_params, bool $include_deleted = true, bool $include_expired = true) |
|
788 | - { |
|
789 | - $where_params = $this->addExpiredWhereParams($where_params, $include_expired); |
|
790 | - $where_params = $this->addDeletedWhereParams($where_params, $include_deleted); |
|
791 | - return $where_params; |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * @param array $where_params |
|
797 | - * @param bool $include_deleted |
|
798 | - * @return array |
|
799 | - * @since $VID:$ |
|
800 | - */ |
|
801 | - private function addDeletedWhereParams(array $where_params, bool $include_deleted = true) |
|
802 | - { |
|
803 | - $deleted = $include_deleted ? [true, false] : [false]; |
|
804 | - $where_params['DTT_deleted'] = ['IN', $deleted]; |
|
805 | - return $where_params; |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - /** |
|
810 | - * @param array $where_params |
|
811 | - * @param bool $include_expired |
|
812 | - * @return array |
|
813 | - * @since $VID:$ |
|
814 | - */ |
|
815 | - private function addExpiredWhereParams(array $where_params, bool $include_expired = true) |
|
816 | - { |
|
817 | - if (! $include_expired) { |
|
818 | - $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)]; |
|
819 | - } |
|
820 | - return $where_params; |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * @param array $query_params |
|
826 | - * @param int $limit |
|
827 | - * @return array |
|
828 | - * @since $VID:$ |
|
829 | - */ |
|
830 | - private function addLimitQueryParams(array $query_params, $limit = 0) |
|
831 | - { |
|
832 | - if ($limit) { |
|
833 | - $query_params['limit'] = $limit; |
|
834 | - } |
|
835 | - return $query_params; |
|
836 | - } |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * @param array $query_params |
|
841 | - * @param string $order_by |
|
842 | - * @param string $order |
|
843 | - * @return array |
|
844 | - * @since $VID:$ |
|
845 | - */ |
|
846 | - private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC') |
|
847 | - { |
|
848 | - $order = $order === 'ASC' ? 'ASC' : 'DESC'; |
|
849 | - $valid_order_columns = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order']; |
|
850 | - $order_by = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start'; |
|
851 | - $query_params['order_by'] = [$order_by => $order]; |
|
852 | - return $query_params; |
|
853 | - } |
|
16 | + /** |
|
17 | + * @var EEM_Datetime $_instance |
|
18 | + */ |
|
19 | + protected static $_instance; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * private constructor to prevent direct creation |
|
24 | + * |
|
25 | + * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
26 | + * (and any incoming timezone data that gets saved). |
|
27 | + * Note this just sends the timezone info to the date time model field objects. |
|
28 | + * Default is NULL |
|
29 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | + * @throws EE_Error |
|
31 | + * @throws InvalidArgumentException |
|
32 | + * @throws InvalidArgumentException |
|
33 | + */ |
|
34 | + protected function __construct($timezone) |
|
35 | + { |
|
36 | + $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
37 | + $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
38 | + $this->_tables = [ |
|
39 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
40 | + ]; |
|
41 | + $this->_fields = [ |
|
42 | + 'Datetime' => [ |
|
43 | + 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
44 | + 'DTT_ID', |
|
45 | + esc_html__('Datetime ID', 'event_espresso') |
|
46 | + ), |
|
47 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
48 | + 'EVT_ID', |
|
49 | + esc_html__('Event ID', 'event_espresso'), |
|
50 | + false, |
|
51 | + 0, |
|
52 | + 'Event' |
|
53 | + ), |
|
54 | + 'VNU_ID' => new EE_Foreign_Key_Int_Field( |
|
55 | + 'VNU_ID', |
|
56 | + __('Venue ID', 'event_espresso'), |
|
57 | + false, |
|
58 | + 0, |
|
59 | + 'Venue' |
|
60 | + ), |
|
61 | + 'DTT_name' => new EE_Plain_Text_Field( |
|
62 | + 'DTT_name', |
|
63 | + esc_html__('Datetime Name', 'event_espresso'), |
|
64 | + false, |
|
65 | + '' |
|
66 | + ), |
|
67 | + 'DTT_description' => new EE_Post_Content_Field( |
|
68 | + 'DTT_description', |
|
69 | + esc_html__('Description for Datetime', 'event_espresso'), |
|
70 | + false, |
|
71 | + '' |
|
72 | + ), |
|
73 | + 'DTT_EVT_start' => new EE_Datetime_Field( |
|
74 | + 'DTT_EVT_start', |
|
75 | + esc_html__('Start time/date of Event', 'event_espresso'), |
|
76 | + false, |
|
77 | + EE_Datetime_Field::now, |
|
78 | + $timezone |
|
79 | + ), |
|
80 | + 'DTT_EVT_end' => new EE_Datetime_Field( |
|
81 | + 'DTT_EVT_end', |
|
82 | + esc_html__('End time/date of Event', 'event_espresso'), |
|
83 | + false, |
|
84 | + EE_Datetime_Field::now, |
|
85 | + $timezone |
|
86 | + ), |
|
87 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
88 | + 'DTT_reg_limit', |
|
89 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
90 | + true, |
|
91 | + EE_INF |
|
92 | + ), |
|
93 | + 'DTT_sold' => new EE_Integer_Field( |
|
94 | + 'DTT_sold', |
|
95 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
96 | + true, |
|
97 | + 0 |
|
98 | + ), |
|
99 | + 'DTT_reserved' => new EE_Integer_Field( |
|
100 | + 'DTT_reserved', |
|
101 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
102 | + false, |
|
103 | + 0 |
|
104 | + ), |
|
105 | + 'DTT_is_primary' => new EE_Boolean_Field( |
|
106 | + 'DTT_is_primary', |
|
107 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
108 | + false, |
|
109 | + false |
|
110 | + ), |
|
111 | + 'DTT_order' => new EE_Integer_Field( |
|
112 | + 'DTT_order', |
|
113 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
114 | + false, |
|
115 | + 0 |
|
116 | + ), |
|
117 | + 'DTT_parent' => new EE_Integer_Field( |
|
118 | + 'DTT_parent', |
|
119 | + esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
120 | + true, |
|
121 | + 0 |
|
122 | + ), |
|
123 | + 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
124 | + 'DTT_deleted', |
|
125 | + esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
126 | + false, |
|
127 | + false |
|
128 | + ), |
|
129 | + ], |
|
130 | + ]; |
|
131 | + $this->_model_relations = [ |
|
132 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
133 | + 'Event' => new EE_Belongs_To_Relation(), |
|
134 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
135 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
136 | + 'Venue' => new EE_Belongs_To_Relation(), |
|
137 | + ]; |
|
138 | + $path_to_event_model = 'Event'; |
|
139 | + $this->model_chain_to_password = $path_to_event_model; |
|
140 | + $this->_model_chain_to_wp_user = $path_to_event_model; |
|
141 | + // this model is generally available for reading |
|
142 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
143 | + new EE_Restriction_Generator_Event_Related_Public( |
|
144 | + $path_to_event_model |
|
145 | + ); |
|
146 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
147 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
148 | + $path_to_event_model |
|
149 | + ); |
|
150 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
151 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
152 | + $path_to_event_model |
|
153 | + ); |
|
154 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
155 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
156 | + $path_to_event_model, |
|
157 | + EEM_Base::caps_edit |
|
158 | + ); |
|
159 | + parent::__construct($timezone); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * create new blank datetime |
|
165 | + * |
|
166 | + * @access public |
|
167 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
168 | + * @throws EE_Error |
|
169 | + * @throws InvalidArgumentException |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + * @throws ReflectionException |
|
172 | + * @throws InvalidInterfaceException |
|
173 | + */ |
|
174 | + public function create_new_blank_datetime() |
|
175 | + { |
|
176 | + // makes sure timezone is always set. |
|
177 | + $timezone_string = $this->get_timezone(); |
|
178 | + /** |
|
179 | + * Filters the initial start date for the new datetime. |
|
180 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
181 | + * |
|
182 | + * @param int $start_date Unix timestamp representing now + 30 days in seconds. |
|
183 | + * @return int Unix timestamp |
|
184 | + */ |
|
185 | + $start_date = apply_filters( |
|
186 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
187 | + $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
188 | + ); |
|
189 | + /** |
|
190 | + * Filters the initial end date for the new datetime. |
|
191 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
192 | + * |
|
193 | + * @param int $end_data Unix timestamp representing now + 30 days in seconds. |
|
194 | + * @return int Unix timestamp |
|
195 | + */ |
|
196 | + $end_date = apply_filters( |
|
197 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
198 | + $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
199 | + ); |
|
200 | + $blank_datetime = EE_Datetime::new_instance( |
|
201 | + [ |
|
202 | + 'DTT_EVT_start' => $start_date, |
|
203 | + 'DTT_EVT_end' => $end_date, |
|
204 | + 'DTT_order' => 1, |
|
205 | + 'DTT_reg_limit' => EE_INF, |
|
206 | + ], |
|
207 | + $timezone_string |
|
208 | + ); |
|
209 | + /** |
|
210 | + * Filters the initial start time and format for the new EE_Datetime instance. |
|
211 | + * |
|
212 | + * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
213 | + * format. |
|
214 | + * @return array |
|
215 | + */ |
|
216 | + $start_time = apply_filters( |
|
217 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
218 | + ['8am', 'ga'] |
|
219 | + ); |
|
220 | + /** |
|
221 | + * Filters the initial end time and format for the new EE_Datetime instance. |
|
222 | + * |
|
223 | + * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
224 | + * format |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + $end_time = apply_filters( |
|
228 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
229 | + ['5pm', 'ga'] |
|
230 | + ); |
|
231 | + $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
232 | + $blank_datetime->set_start_time( |
|
233 | + $this->convert_datetime_for_query( |
|
234 | + 'DTT_EVT_start', |
|
235 | + $start_time[0], |
|
236 | + $start_time[1], |
|
237 | + $timezone_string |
|
238 | + ) |
|
239 | + ); |
|
240 | + $blank_datetime->set_end_time( |
|
241 | + $this->convert_datetime_for_query( |
|
242 | + 'DTT_EVT_end', |
|
243 | + $end_time[0], |
|
244 | + $end_time[1], |
|
245 | + $timezone_string |
|
246 | + ) |
|
247 | + ); |
|
248 | + return [$blank_datetime]; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Validates whether the start_time and end_time are in the expected format. |
|
254 | + * |
|
255 | + * @param array $start_time |
|
256 | + * @param array $end_time |
|
257 | + * @throws InvalidArgumentException |
|
258 | + * @throws InvalidDataTypeException |
|
259 | + */ |
|
260 | + private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time) |
|
261 | + { |
|
262 | + if (! is_array($start_time)) { |
|
263 | + throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
264 | + } |
|
265 | + if (! is_array($end_time)) { |
|
266 | + throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
267 | + } |
|
268 | + if (count($start_time) !== 2) { |
|
269 | + throw new InvalidArgumentException( |
|
270 | + sprintf( |
|
271 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
272 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
273 | + '$start_time' |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + if (count($end_time) !== 2) { |
|
278 | + throw new InvalidArgumentException( |
|
279 | + sprintf( |
|
280 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
281 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
282 | + '$end_time' |
|
283 | + ) |
|
284 | + ); |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * get event start date from db |
|
291 | + * |
|
292 | + * @access public |
|
293 | + * @param int $EVT_ID |
|
294 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
295 | + * @throws EE_Error |
|
296 | + * @throws ReflectionException |
|
297 | + */ |
|
298 | + public function get_all_event_dates($EVT_ID = 0) |
|
299 | + { |
|
300 | + if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
301 | + return $this->create_new_blank_datetime(); |
|
302 | + } |
|
303 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
304 | + if (empty($results)) { |
|
305 | + return $this->create_new_blank_datetime(); |
|
306 | + } |
|
307 | + return $results; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
313 | + * |
|
314 | + * @public |
|
315 | + * @param int $EVT_ID event id |
|
316 | + * @param boolean $include_expired |
|
317 | + * @param boolean $include_deleted |
|
318 | + * @param int $limit If included then limit the count of results by |
|
319 | + * the given number |
|
320 | + * @return EE_Datetime[] |
|
321 | + * @throws EE_Error |
|
322 | + */ |
|
323 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
324 | + int $EVT_ID, |
|
325 | + bool $include_expired = true, |
|
326 | + bool $include_deleted = true, |
|
327 | + $limit = 0 |
|
328 | + ) { |
|
329 | + $prev_data_prep_value = $this->prepModelForQuery(); |
|
330 | + $where_params = ['Event.EVT_ID' => absint($EVT_ID)]; |
|
331 | + $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
332 | + $query_params = $this->addDefaultWhereConditions($query_params); |
|
333 | + $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order'); |
|
334 | + return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
340 | + * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
341 | + * and then the earlier datetimes are the most important. |
|
342 | + * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
343 | + * |
|
344 | + * @param int $EVT_ID |
|
345 | + * @param int $limit |
|
346 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
347 | + * @throws EE_Error |
|
348 | + */ |
|
349 | + public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0) |
|
350 | + { |
|
351 | + $query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)]; |
|
352 | + $query_params = $this->addDefaultWhereConditions($query_params); |
|
353 | + $query_params = $this->addDefaultQueryParams($query_params, $limit); |
|
354 | + return $this->get_all($query_params); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @param int $EVT_ID |
|
360 | + * @param boolean $include_expired |
|
361 | + * @param boolean $include_deleted |
|
362 | + * @return EE_Datetime |
|
363 | + * @throws EE_Error |
|
364 | + */ |
|
365 | + public function get_oldest_datetime_for_event( |
|
366 | + int $EVT_ID, |
|
367 | + bool $include_expired = false, |
|
368 | + bool $include_deleted = false |
|
369 | + ) { |
|
370 | + $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
371 | + $EVT_ID, |
|
372 | + $include_expired, |
|
373 | + $include_deleted, |
|
374 | + 1 |
|
375 | + ); |
|
376 | + if ($results) { |
|
377 | + return array_shift($results); |
|
378 | + } |
|
379 | + return null; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Gets the 'primary' datetime for an event. |
|
385 | + * |
|
386 | + * @param int $EVT_ID |
|
387 | + * @param bool $try_to_exclude_expired |
|
388 | + * @param bool $try_to_exclude_deleted |
|
389 | + * @return EE_Datetime |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function get_primary_datetime_for_event( |
|
393 | + int $EVT_ID, |
|
394 | + bool $try_to_exclude_expired = true, |
|
395 | + bool $try_to_exclude_deleted = true |
|
396 | + ) { |
|
397 | + if ($try_to_exclude_expired) { |
|
398 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
399 | + if ($non_expired) { |
|
400 | + return $non_expired; |
|
401 | + } |
|
402 | + } |
|
403 | + if ($try_to_exclude_deleted) { |
|
404 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
405 | + if ($expired_even) { |
|
406 | + return $expired_even; |
|
407 | + } |
|
408 | + } |
|
409 | + return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
415 | + * only by start date |
|
416 | + * |
|
417 | + * @param int $EVT_ID |
|
418 | + * @param boolean $include_expired |
|
419 | + * @param boolean $include_deleted |
|
420 | + * @param int $limit |
|
421 | + * @return EE_Datetime[] |
|
422 | + * @throws EE_Error |
|
423 | + */ |
|
424 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
425 | + int $EVT_ID, |
|
426 | + bool $include_expired = true, |
|
427 | + bool $include_deleted = true, |
|
428 | + $limit = 0 |
|
429 | + ) { |
|
430 | + $prev_data_prep_value = $this->prepModelForQuery(); |
|
431 | + $where_params = ['Event.EVT_ID' => absint($EVT_ID)]; |
|
432 | + $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
433 | + $query_params = $this->addDefaultWhereConditions( |
|
434 | + $query_params, |
|
435 | + EEM_Base::default_where_conditions_this_only |
|
436 | + ); |
|
437 | + $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order'); |
|
438 | + return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
444 | + * only by start date |
|
445 | + * |
|
446 | + * @param int $TKT_ID |
|
447 | + * @param boolean $include_expired |
|
448 | + * @param boolean $include_deleted |
|
449 | + * @param int $limit |
|
450 | + * @return EE_Datetime[] |
|
451 | + * @throws EE_Error |
|
452 | + */ |
|
453 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
454 | + int $TKT_ID, |
|
455 | + bool $include_expired = true, |
|
456 | + bool $include_deleted = true, |
|
457 | + $limit = 0 |
|
458 | + ) { |
|
459 | + $prev_data_prep_value = $this->prepModelForQuery(); |
|
460 | + $where_params = ['Ticket.TKT_ID' => absint($TKT_ID)]; |
|
461 | + $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
462 | + $query_params = $this->addDefaultQueryParams($query_params, $limit); |
|
463 | + return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
469 | + * datetimes. |
|
470 | + * |
|
471 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
472 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
473 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
474 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
475 | + * that number |
|
476 | + * @return EE_Datetime[] |
|
477 | + * @throws EE_Error |
|
478 | + */ |
|
479 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
480 | + int $TKT_ID, |
|
481 | + bool $include_expired = true, |
|
482 | + bool $include_deleted = true, |
|
483 | + $limit = 0 |
|
484 | + ) { |
|
485 | + $prev_data_prep_value = $this->prepModelForQuery(); |
|
486 | + $where_params = ['Ticket.TKT_ID' => absint($TKT_ID)]; |
|
487 | + $query_params[0] = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired); |
|
488 | + $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order'); |
|
489 | + return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value); |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
495 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
496 | + * |
|
497 | + * @param int $EVT_ID |
|
498 | + * @return EE_Datetime |
|
499 | + * @throws EE_Error |
|
500 | + */ |
|
501 | + public function get_most_important_datetime_for_event(int $EVT_ID) |
|
502 | + { |
|
503 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
504 | + if ($results) { |
|
505 | + return array_shift($results); |
|
506 | + } |
|
507 | + return null; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
513 | + * grouped by month and year. |
|
514 | + * |
|
515 | + * @param array $where_params @see |
|
516 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
517 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
518 | + * Can be: |
|
519 | + * - '' = no filter |
|
520 | + * - upcoming = Published events with at least one upcoming datetime. |
|
521 | + * - expired = Events with all datetimes expired. |
|
522 | + * - active = Events that are published and have at least one datetime that |
|
523 | + * starts before now and ends after now. |
|
524 | + * - inactive = Events that are either not published. |
|
525 | + * @return EE_Base_Class[] |
|
526 | + * @throws EE_Error |
|
527 | + * @throws InvalidArgumentException |
|
528 | + * @throws InvalidArgumentException |
|
529 | + */ |
|
530 | + public function get_dtt_months_and_years(array $where_params, $evt_active_status = '') |
|
531 | + { |
|
532 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
533 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
534 | + switch ($evt_active_status) { |
|
535 | + case 'upcoming': |
|
536 | + $where_params['Event.status'] = 'publish'; |
|
537 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
538 | + if (isset($where_params['DTT_EVT_start'])) { |
|
539 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
540 | + } |
|
541 | + $where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start]; |
|
542 | + break; |
|
543 | + case 'expired': |
|
544 | + if (isset($where_params['Event.status'])) { |
|
545 | + unset($where_params['Event.status']); |
|
546 | + } |
|
547 | + // get events to exclude |
|
548 | + $exclude_query[0] = array_merge( |
|
549 | + $where_params, |
|
550 | + ['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]] |
|
551 | + ); |
|
552 | + // first get all events that have datetimes where its not expired. |
|
553 | + $event_ids = $this->_get_all_wpdb_results( |
|
554 | + $exclude_query, |
|
555 | + OBJECT_K, |
|
556 | + 'Datetime.EVT_ID' |
|
557 | + ); |
|
558 | + $event_ids = array_keys($event_ids); |
|
559 | + if (isset($where_params['DTT_EVT_end'])) { |
|
560 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
561 | + } |
|
562 | + $where_params['DTT_EVT_end'] = ['<', $current_time_for_DTT_EVT_end]; |
|
563 | + $where_params['Event.EVT_ID'] = ['NOT IN', $event_ids]; |
|
564 | + break; |
|
565 | + case 'active': |
|
566 | + $where_params['Event.status'] = 'publish'; |
|
567 | + if (isset($where_params['DTT_EVT_start'])) { |
|
568 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
569 | + } |
|
570 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
571 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
572 | + } |
|
573 | + $where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start]; |
|
574 | + $where_params['DTT_EVT_end'] = ['>', $current_time_for_DTT_EVT_end]; |
|
575 | + break; |
|
576 | + case 'inactive': |
|
577 | + if (isset($where_params['Event.status'])) { |
|
578 | + unset($where_params['Event.status']); |
|
579 | + } |
|
580 | + if (isset($where_params['OR'])) { |
|
581 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
582 | + } |
|
583 | + if (isset($where_params['DTT_EVT_end'])) { |
|
584 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
585 | + unset($where_params['DTT_EVT_end']); |
|
586 | + } |
|
587 | + if (isset($where_params['DTT_EVT_start'])) { |
|
588 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
589 | + unset($where_params['DTT_EVT_start']); |
|
590 | + } |
|
591 | + $where_params['AND']['Event.status'] = ['!=', 'publish']; |
|
592 | + break; |
|
593 | + } |
|
594 | + $query_params[0] = $where_params; |
|
595 | + $query_params['group_by'] = ['dtt_year', 'dtt_month']; |
|
596 | + $query_params = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC'); |
|
597 | + |
|
598 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
599 | + $this->get_timezone(), |
|
600 | + 'DTT_EVT_start' |
|
601 | + ); |
|
602 | + $columns_to_select = [ |
|
603 | + 'dtt_year' => ['YEAR(' . $query_interval . ')', '%s'], |
|
604 | + 'dtt_month' => ['MONTHNAME(' . $query_interval . ')', '%s'], |
|
605 | + 'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'], |
|
606 | + ]; |
|
607 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
613 | + * for the tickets for each datetime) |
|
614 | + * |
|
615 | + * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
616 | + * @throws EE_Error |
|
617 | + * @throws ReflectionException |
|
618 | + */ |
|
619 | + public function update_sold(array $datetimes) |
|
620 | + { |
|
621 | + EE_Error::doing_it_wrong( |
|
622 | + __FUNCTION__, |
|
623 | + esc_html__( |
|
624 | + 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
625 | + 'event_espresso' |
|
626 | + ), |
|
627 | + '4.9.32.rc.005' |
|
628 | + ); |
|
629 | + foreach ($datetimes as $datetime) { |
|
630 | + $datetime->update_sold(); |
|
631 | + } |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * Gets the total number of tickets available at a particular datetime |
|
637 | + * (does NOT take into account the datetime's spaces available) |
|
638 | + * |
|
639 | + * @param int $DTT_ID |
|
640 | + * @param array $query_params |
|
641 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
642 | + * tickets attached to datetime then FALSE is returned. |
|
643 | + * @throws EE_Error |
|
644 | + * @throws ReflectionException |
|
645 | + */ |
|
646 | + public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = []) |
|
647 | + { |
|
648 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
649 | + if ($datetime instanceof EE_Datetime) { |
|
650 | + return $datetime->tickets_remaining($query_params); |
|
651 | + } |
|
652 | + return 0; |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
658 | + * |
|
659 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
660 | + * stati you want counts for as values in the array. An empty array returns counts |
|
661 | + * for all valid stati. |
|
662 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
663 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
664 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
665 | + * @throws EE_Error |
|
666 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
667 | + * EE_Datetime::expired |
|
668 | + */ |
|
669 | + public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = []) |
|
670 | + { |
|
671 | + // only accept where conditions for this query. |
|
672 | + $_where = isset($query_params[0]) ? $query_params[0] : []; |
|
673 | + $status_query_args = [ |
|
674 | + EE_Datetime::active => array_merge( |
|
675 | + $_where, |
|
676 | + ['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]] |
|
677 | + ), |
|
678 | + EE_Datetime::upcoming => array_merge( |
|
679 | + $_where, |
|
680 | + ['DTT_EVT_start' => ['>', time()]] |
|
681 | + ), |
|
682 | + EE_Datetime::expired => array_merge( |
|
683 | + $_where, |
|
684 | + ['DTT_EVT_end' => ['<', time()]] |
|
685 | + ), |
|
686 | + ]; |
|
687 | + if (! empty($stati_to_include)) { |
|
688 | + foreach (array_keys($status_query_args) as $status) { |
|
689 | + if (! in_array($status, $stati_to_include, true)) { |
|
690 | + unset($status_query_args[ $status ]); |
|
691 | + } |
|
692 | + } |
|
693 | + } |
|
694 | + // loop through and query counts for each stati. |
|
695 | + $status_query_results = []; |
|
696 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
697 | + $status_query_results[ $status ] = EEM_Datetime::count( |
|
698 | + [$status_where_conditions], |
|
699 | + 'DTT_ID', |
|
700 | + true |
|
701 | + ); |
|
702 | + } |
|
703 | + return $status_query_results; |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + /** |
|
708 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
709 | + * |
|
710 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
711 | + * @param array $query_params |
|
712 | + * @return int |
|
713 | + * @throws EE_Error |
|
714 | + */ |
|
715 | + public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = []) |
|
716 | + { |
|
717 | + $count = $this->get_datetime_counts_by_status([$status], $query_params); |
|
718 | + return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * @return bool|int |
|
724 | + * @since $VID:$ |
|
725 | + */ |
|
726 | + private function prepModelForQuery() |
|
727 | + { |
|
728 | + $prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
729 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
730 | + return $prev_data_prep_value; |
|
731 | + } |
|
732 | + |
|
733 | + |
|
734 | + /** |
|
735 | + * @param array $query_params |
|
736 | + * @param bool|int $prev_data_prep_value |
|
737 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
738 | + * @throws EE_Error |
|
739 | + * @since $VID:$ |
|
740 | + */ |
|
741 | + private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value) |
|
742 | + { |
|
743 | + $result = $this->get_all($query_params); |
|
744 | + $this->assume_values_already_prepared_by_model_object($prev_data_prep_value); |
|
745 | + return $result; |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * @param array $query_params |
|
751 | + * @param int $limit |
|
752 | + * @param string $order_by |
|
753 | + * @param string $order |
|
754 | + * @return array |
|
755 | + * @since $VID:$ |
|
756 | + */ |
|
757 | + private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC') |
|
758 | + { |
|
759 | + $query_params = $this->addOrderByQueryParams($query_params, $order_by, $order); |
|
760 | + $query_params = $this->addLimitQueryParams($query_params, $limit); |
|
761 | + return $query_params; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + /** |
|
766 | + * @param array $query_params |
|
767 | + * @param string $default_where_conditions |
|
768 | + * @return array |
|
769 | + * @since $VID:$ |
|
770 | + */ |
|
771 | + private function addDefaultWhereConditions( |
|
772 | + array $query_params, |
|
773 | + $default_where_conditions = EEM_Base::default_where_conditions_none |
|
774 | + ) { |
|
775 | + $query_params['default_where_conditions'] = $default_where_conditions; |
|
776 | + return $query_params; |
|
777 | + } |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * @param array $where_params |
|
782 | + * @param bool $include_deleted |
|
783 | + * @param bool $include_expired |
|
784 | + * @return array |
|
785 | + * @since $VID:$ |
|
786 | + */ |
|
787 | + private function addDefaultWhereParams(array $where_params, bool $include_deleted = true, bool $include_expired = true) |
|
788 | + { |
|
789 | + $where_params = $this->addExpiredWhereParams($where_params, $include_expired); |
|
790 | + $where_params = $this->addDeletedWhereParams($where_params, $include_deleted); |
|
791 | + return $where_params; |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * @param array $where_params |
|
797 | + * @param bool $include_deleted |
|
798 | + * @return array |
|
799 | + * @since $VID:$ |
|
800 | + */ |
|
801 | + private function addDeletedWhereParams(array $where_params, bool $include_deleted = true) |
|
802 | + { |
|
803 | + $deleted = $include_deleted ? [true, false] : [false]; |
|
804 | + $where_params['DTT_deleted'] = ['IN', $deleted]; |
|
805 | + return $where_params; |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + /** |
|
810 | + * @param array $where_params |
|
811 | + * @param bool $include_expired |
|
812 | + * @return array |
|
813 | + * @since $VID:$ |
|
814 | + */ |
|
815 | + private function addExpiredWhereParams(array $where_params, bool $include_expired = true) |
|
816 | + { |
|
817 | + if (! $include_expired) { |
|
818 | + $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)]; |
|
819 | + } |
|
820 | + return $where_params; |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * @param array $query_params |
|
826 | + * @param int $limit |
|
827 | + * @return array |
|
828 | + * @since $VID:$ |
|
829 | + */ |
|
830 | + private function addLimitQueryParams(array $query_params, $limit = 0) |
|
831 | + { |
|
832 | + if ($limit) { |
|
833 | + $query_params['limit'] = $limit; |
|
834 | + } |
|
835 | + return $query_params; |
|
836 | + } |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * @param array $query_params |
|
841 | + * @param string $order_by |
|
842 | + * @param string $order |
|
843 | + * @return array |
|
844 | + * @since $VID:$ |
|
845 | + */ |
|
846 | + private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC') |
|
847 | + { |
|
848 | + $order = $order === 'ASC' ? 'ASC' : 'DESC'; |
|
849 | + $valid_order_columns = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order']; |
|
850 | + $order_by = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start'; |
|
851 | + $query_params['order_by'] = [$order_by => $order]; |
|
852 | + return $query_params; |
|
853 | + } |
|
854 | 854 | } |
@@ -14,931 +14,931 @@ |
||
14 | 14 | class EEM_Event extends EEM_CPT_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
19 | - * event |
|
20 | - */ |
|
21 | - const sold_out = 'sold_out'; |
|
22 | - |
|
23 | - /** |
|
24 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
25 | - * date) |
|
26 | - */ |
|
27 | - const postponed = 'postponed'; |
|
28 | - |
|
29 | - /** |
|
30 | - * constant used by status(), indicating that the event will no longer occur |
|
31 | - */ |
|
32 | - const cancelled = 'cancelled'; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected static $_default_reg_status; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * This is the default for the additional limit field. |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected static $_default_additional_limit = 10; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * private instance of the Event object |
|
50 | - * |
|
51 | - * @var EEM_Event |
|
52 | - */ |
|
53 | - protected static $_instance; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
58 | - * |
|
59 | - * @param string $timezone |
|
60 | - * @throws EE_Error |
|
61 | - * @throws ReflectionException |
|
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 | - 'VNU_ID' => new EE_Foreign_Key_Int_Field( |
|
199 | - 'VNU_ID', |
|
200 | - __('Venue ID', 'event_espresso'), |
|
201 | - false, |
|
202 | - 0, |
|
203 | - 'Venue' |
|
204 | - ), |
|
205 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
206 | - 'EVT_display_desc', |
|
207 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
208 | - false, |
|
209 | - true |
|
210 | - ), |
|
211 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
212 | - 'EVT_display_ticket_selector', |
|
213 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
214 | - false, |
|
215 | - true |
|
216 | - ), |
|
217 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
218 | - 'EVT_visible_on', |
|
219 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
220 | - true, |
|
221 | - EE_Datetime_Field::now |
|
222 | - ), |
|
223 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
224 | - 'EVT_additional_limit', |
|
225 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
226 | - true, |
|
227 | - self::$_default_additional_limit |
|
228 | - ), |
|
229 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
230 | - 'EVT_default_registration_status', |
|
231 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
232 | - false, |
|
233 | - EEM_Event::$_default_reg_status, |
|
234 | - EEM_Registration::reg_status_array() |
|
235 | - ), |
|
236 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
237 | - 'EVT_member_only', |
|
238 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
239 | - false, |
|
240 | - false |
|
241 | - ), |
|
242 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
243 | - 'EVT_phone', |
|
244 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
245 | - false, |
|
246 | - '' |
|
247 | - ), |
|
248 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
249 | - 'EVT_allow_overflow', |
|
250 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
251 | - false, |
|
252 | - false |
|
253 | - ), |
|
254 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
255 | - 'EVT_timezone_string', |
|
256 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
257 | - false, |
|
258 | - '' |
|
259 | - ), |
|
260 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
261 | - 'EVT_external_URL', |
|
262 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
263 | - true |
|
264 | - ), |
|
265 | - 'EVT_donations' => new EE_Boolean_Field( |
|
266 | - 'EVT_donations', |
|
267 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
268 | - false, |
|
269 | - false |
|
270 | - ), |
|
271 | - 'FSC_UUID' => new EE_Foreign_Key_String_Field( |
|
272 | - 'FSC_UUID', |
|
273 | - esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'), |
|
274 | - true, |
|
275 | - null, |
|
276 | - 'Form_Section', |
|
277 | - false |
|
278 | - ), |
|
279 | - ), |
|
280 | - ); |
|
281 | - $this->_model_relations = array( |
|
282 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
283 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
284 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
285 | - 'Form_Section' => new EE_Belongs_To_Relation(), |
|
286 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
287 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
288 | - 'Registration' => new EE_Has_Many_Relation(), |
|
289 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
290 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
291 | - 'Venue' => new EE_Belongs_To_Relation(), |
|
292 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
293 | - ); |
|
294 | - // this model is generally available for reading |
|
295 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
296 | - $this->model_chain_to_password = ''; |
|
297 | - parent::__construct($timezone); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * @param string $default_reg_status |
|
303 | - * @throws EE_Error |
|
304 | - * @throws EE_Error |
|
305 | - */ |
|
306 | - public static function set_default_reg_status($default_reg_status) |
|
307 | - { |
|
308 | - self::$_default_reg_status = $default_reg_status; |
|
309 | - // if EEM_Event has already been instantiated, |
|
310 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
311 | - if (self::$_instance instanceof EEM_Event) { |
|
312 | - $default_reg_status = new EE_Enum_Text_Field( |
|
313 | - 'EVT_default_registration_status', |
|
314 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
315 | - false, |
|
316 | - $default_reg_status, |
|
317 | - EEM_Registration::reg_status_array() |
|
318 | - ); |
|
319 | - $default_reg_status->_construct_finalize( |
|
320 | - 'Event_Meta', |
|
321 | - 'EVT_default_registration_status', |
|
322 | - 'EEM_Event' |
|
323 | - ); |
|
324 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Used to override the default for the additional limit field. |
|
331 | - * @param $additional_limit |
|
332 | - */ |
|
333 | - public static function set_default_additional_limit($additional_limit) |
|
334 | - { |
|
335 | - self::$_default_additional_limit = (int) $additional_limit; |
|
336 | - if (self::$_instance instanceof EEM_Event) { |
|
337 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
338 | - 'EVT_additional_limit', |
|
339 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
340 | - true, |
|
341 | - self::$_default_additional_limit |
|
342 | - ); |
|
343 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
344 | - 'Event_Meta', |
|
345 | - 'EVT_additional_limit', |
|
346 | - 'EEM_Event' |
|
347 | - ); |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Return what is currently set as the default additional limit for the event. |
|
354 | - * @return int |
|
355 | - */ |
|
356 | - public static function get_default_additional_limit() |
|
357 | - { |
|
358 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * get_question_groups |
|
364 | - * |
|
365 | - * @return array |
|
366 | - * @throws EE_Error |
|
367 | - * @throws ReflectionException |
|
368 | - */ |
|
369 | - public function get_all_question_groups() |
|
370 | - { |
|
371 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
372 | - array( |
|
373 | - array('QSG_deleted' => false), |
|
374 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
375 | - ) |
|
376 | - ); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * get_question_groups |
|
382 | - * |
|
383 | - * @param int $EVT_ID |
|
384 | - * @return array|bool |
|
385 | - * @throws EE_Error |
|
386 | - * @throws ReflectionException |
|
387 | - */ |
|
388 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
389 | - { |
|
390 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
391 | - EE_Error::add_error( |
|
392 | - esc_html__( |
|
393 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
394 | - 'event_espresso' |
|
395 | - ), |
|
396 | - __FILE__, |
|
397 | - __FUNCTION__, |
|
398 | - __LINE__ |
|
399 | - ); |
|
400 | - return false; |
|
401 | - } |
|
402 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
403 | - array( |
|
404 | - array('EVT_ID' => $EVT_ID), |
|
405 | - ) |
|
406 | - ); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * get_question_groups |
|
412 | - * |
|
413 | - * @param int $EVT_ID |
|
414 | - * @param boolean $for_primary_attendee |
|
415 | - * @return array|bool |
|
416 | - * @throws EE_Error |
|
417 | - * @throws InvalidArgumentException |
|
418 | - * @throws ReflectionException |
|
419 | - * @throws InvalidDataTypeException |
|
420 | - * @throws InvalidInterfaceException |
|
421 | - */ |
|
422 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
423 | - { |
|
424 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
425 | - EE_Error::add_error( |
|
426 | - esc_html__( |
|
427 | - // @codingStandardsIgnoreStart |
|
428 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
429 | - // @codingStandardsIgnoreEnd |
|
430 | - 'event_espresso' |
|
431 | - ), |
|
432 | - __FILE__, |
|
433 | - __FUNCTION__, |
|
434 | - __LINE__ |
|
435 | - ); |
|
436 | - return false; |
|
437 | - } |
|
438 | - $query_params = [ |
|
439 | - [ |
|
440 | - 'EVT_ID' => $EVT_ID, |
|
441 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
442 | - ] |
|
443 | - ]; |
|
444 | - if ($for_primary_attendee) { |
|
445 | - $query_params[0]['EQG_primary'] = true; |
|
446 | - } else { |
|
447 | - $query_params[0]['EQG_additional'] = true; |
|
448 | - } |
|
449 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * get_question_groups |
|
455 | - * |
|
456 | - * @param int $EVT_ID |
|
457 | - * @param EE_Registration $registration |
|
458 | - * @return array|bool |
|
459 | - * @throws EE_Error |
|
460 | - * @throws InvalidArgumentException |
|
461 | - * @throws InvalidDataTypeException |
|
462 | - * @throws InvalidInterfaceException |
|
463 | - * @throws ReflectionException |
|
464 | - */ |
|
465 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
466 | - { |
|
467 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
468 | - EE_Error::add_error( |
|
469 | - esc_html__( |
|
470 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
471 | - 'event_espresso' |
|
472 | - ), |
|
473 | - __FILE__, |
|
474 | - __FUNCTION__, |
|
475 | - __LINE__ |
|
476 | - ); |
|
477 | - return false; |
|
478 | - } |
|
479 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
480 | - [ |
|
481 | - [ |
|
482 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
483 | - 'Event_Question_Group.' |
|
484 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
485 | - $registration->is_primary_registrant() |
|
486 | - ) => true |
|
487 | - ], |
|
488 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
489 | - ] |
|
490 | - ); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * get_question_target_db_column |
|
496 | - * |
|
497 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
498 | - * @return array|bool |
|
499 | - * @throws EE_Error |
|
500 | - * @throws ReflectionException |
|
501 | - */ |
|
502 | - public function get_questions_in_groups($QSG_IDs = '') |
|
503 | - { |
|
504 | - if (empty($QSG_IDs)) { |
|
505 | - EE_Error::add_error( |
|
506 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
507 | - __FILE__, |
|
508 | - __FUNCTION__, |
|
509 | - __LINE__ |
|
510 | - ); |
|
511 | - return false; |
|
512 | - } |
|
513 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
514 | - array( |
|
515 | - array( |
|
516 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
517 | - 'QST_deleted' => false, |
|
518 | - 'QST_admin_only' => is_admin(), |
|
519 | - ), |
|
520 | - 'order_by' => 'QST_order', |
|
521 | - ) |
|
522 | - ); |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * get_options_for_question |
|
528 | - * |
|
529 | - * @param string $QST_IDs csv list of $QST IDs |
|
530 | - * @return array|bool |
|
531 | - * @throws EE_Error |
|
532 | - * @throws ReflectionException |
|
533 | - */ |
|
534 | - public function get_options_for_question($QST_IDs) |
|
535 | - { |
|
536 | - if (empty($QST_IDs)) { |
|
537 | - EE_Error::add_error( |
|
538 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
539 | - __FILE__, |
|
540 | - __FUNCTION__, |
|
541 | - __LINE__ |
|
542 | - ); |
|
543 | - return false; |
|
544 | - } |
|
545 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
546 | - array( |
|
547 | - array( |
|
548 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
549 | - 'QSO_deleted' => false, |
|
550 | - ), |
|
551 | - 'order_by' => 'QSO_ID', |
|
552 | - ) |
|
553 | - ); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * Gets all events that are published |
|
559 | - * and have event start time earlier than now and an event end time later than now |
|
560 | - * |
|
561 | - * @param array $query_params An array of query params to further filter on |
|
562 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
563 | - * @param bool $count whether to return the count or not (default FALSE) |
|
564 | - * @return EE_Event[]|int |
|
565 | - * @throws EE_Error |
|
566 | - * @throws ReflectionException |
|
567 | - */ |
|
568 | - public function get_active_events($query_params, $count = false) |
|
569 | - { |
|
570 | - if (array_key_exists(0, $query_params)) { |
|
571 | - $where_params = $query_params[0]; |
|
572 | - unset($query_params[0]); |
|
573 | - } else { |
|
574 | - $where_params = array(); |
|
575 | - } |
|
576 | - // if we have count make sure we don't include group by |
|
577 | - if ($count && isset($query_params['group_by'])) { |
|
578 | - unset($query_params['group_by']); |
|
579 | - } |
|
580 | - // let's add specific query_params for active_events |
|
581 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
582 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
583 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
584 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
585 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
586 | - '<', |
|
587 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
588 | - ); |
|
589 | - } else { |
|
590 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
591 | - '<', |
|
592 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
593 | - ); |
|
594 | - } |
|
595 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
596 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
597 | - '>', |
|
598 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
599 | - ); |
|
600 | - } else { |
|
601 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
602 | - '>', |
|
603 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
604 | - ); |
|
605 | - } |
|
606 | - $query_params[0] = $where_params; |
|
607 | - // don't use $query_params with count() |
|
608 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
609 | - return $count |
|
610 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
611 | - : $this->get_all($query_params); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * get all events that are published and have an event start time later than now |
|
617 | - * |
|
618 | - * @param array $query_params An array of query params to further filter on |
|
619 | - * (Note that status and DTT_EVT_start will be overridden) |
|
620 | - * @param bool $count whether to return the count or not (default FALSE) |
|
621 | - * @return EE_Event[]|int |
|
622 | - * @throws EE_Error |
|
623 | - * @throws ReflectionException |
|
624 | - */ |
|
625 | - public function get_upcoming_events($query_params, $count = false) |
|
626 | - { |
|
627 | - if (array_key_exists(0, $query_params)) { |
|
628 | - $where_params = $query_params[0]; |
|
629 | - unset($query_params[0]); |
|
630 | - } else { |
|
631 | - $where_params = array(); |
|
632 | - } |
|
633 | - // if we have count make sure we don't include group by |
|
634 | - if ($count && isset($query_params['group_by'])) { |
|
635 | - unset($query_params['group_by']); |
|
636 | - } |
|
637 | - // let's add specific query_params for active_events |
|
638 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
639 | - // we need to pull events with a status of publish and sold_out |
|
640 | - $event_status = array('publish', EEM_Event::sold_out); |
|
641 | - // check if the user can read private events and if so add the 'private status to the were params' |
|
642 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
643 | - $event_status[] = 'private'; |
|
644 | - } |
|
645 | - $where_params['status'] = array('IN', $event_status); |
|
646 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
647 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
648 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
649 | - '>', |
|
650 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
651 | - ); |
|
652 | - } else { |
|
653 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
654 | - '>', |
|
655 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
656 | - ); |
|
657 | - } |
|
658 | - $query_params[0] = $where_params; |
|
659 | - // don't use $query_params with count() |
|
660 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
661 | - return $count |
|
662 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
663 | - : $this->get_all($query_params); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * Gets all events that are published |
|
669 | - * and have an event end time later than now |
|
670 | - * |
|
671 | - * @param array $query_params An array of query params to further filter on |
|
672 | - * (note that status and DTT_EVT_end will be overridden) |
|
673 | - * @param bool $count whether to return the count or not (default FALSE) |
|
674 | - * @return EE_Event[]|int |
|
675 | - * @throws EE_Error |
|
676 | - * @throws ReflectionException |
|
677 | - */ |
|
678 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
679 | - { |
|
680 | - if (array_key_exists(0, $query_params)) { |
|
681 | - $where_params = $query_params[0]; |
|
682 | - unset($query_params[0]); |
|
683 | - } else { |
|
684 | - $where_params = array(); |
|
685 | - } |
|
686 | - // if we have count make sure we don't include group by |
|
687 | - if ($count && isset($query_params['group_by'])) { |
|
688 | - unset($query_params['group_by']); |
|
689 | - } |
|
690 | - // let's add specific query_params for active_events |
|
691 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
692 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
693 | - // add where params for DTT_EVT_end |
|
694 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
695 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
696 | - '>', |
|
697 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
698 | - ); |
|
699 | - } else { |
|
700 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
701 | - '>', |
|
702 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
703 | - ); |
|
704 | - } |
|
705 | - $query_params[0] = $where_params; |
|
706 | - // don't use $query_params with count() |
|
707 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
708 | - return $count |
|
709 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
710 | - : $this->get_all($query_params); |
|
711 | - } |
|
712 | - |
|
713 | - |
|
714 | - /** |
|
715 | - * This only returns events that are expired. |
|
716 | - * They may still be published but all their datetimes have expired. |
|
717 | - * |
|
718 | - * @param array $query_params An array of query params to further filter on |
|
719 | - * (note that status and DTT_EVT_end will be overridden) |
|
720 | - * @param bool $count whether to return the count or not (default FALSE) |
|
721 | - * @return EE_Event[]|int |
|
722 | - * @throws EE_Error |
|
723 | - * @throws ReflectionException |
|
724 | - */ |
|
725 | - public function get_expired_events($query_params, $count = false) |
|
726 | - { |
|
727 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
728 | - // if we have count make sure we don't include group by |
|
729 | - if ($count && isset($query_params['group_by'])) { |
|
730 | - unset($query_params['group_by']); |
|
731 | - } |
|
732 | - // let's add specific query_params for active_events |
|
733 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
734 | - if (isset($where_params['status'])) { |
|
735 | - unset($where_params['status']); |
|
736 | - } |
|
737 | - $exclude_query = $query_params; |
|
738 | - if (isset($exclude_query[0])) { |
|
739 | - unset($exclude_query[0]); |
|
740 | - } |
|
741 | - $exclude_query[0] = array( |
|
742 | - 'Datetime.DTT_EVT_end' => array( |
|
743 | - '>', |
|
744 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
745 | - ), |
|
746 | - ); |
|
747 | - // first get all events that have datetimes where its not expired. |
|
748 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
749 | - $event_ids = array_keys($event_ids); |
|
750 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
751 | - $and_condition = array( |
|
752 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
753 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
754 | - ); |
|
755 | - if (isset($where_params['OR'])) { |
|
756 | - $and_condition['OR'] = $where_params['OR']; |
|
757 | - unset($where_params['OR']); |
|
758 | - } |
|
759 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
760 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
761 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
762 | - } |
|
763 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
764 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
765 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
766 | - } |
|
767 | - // merge remaining $where params with the and conditions. |
|
768 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
769 | - $query_params[0] = $where_params; |
|
770 | - // don't use $query_params with count() |
|
771 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
772 | - return $count |
|
773 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
774 | - : $this->get_all($query_params); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - |
|
779 | - /** |
|
780 | - * This basically just returns the events that do not have the publish status. |
|
781 | - * |
|
782 | - * @param array $query_params An array of query params to further filter on |
|
783 | - * (note that status will be overwritten) |
|
784 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
785 | - * @return EE_Event[]|int |
|
786 | - * @throws EE_Error |
|
787 | - */ |
|
788 | - public function get_inactive_events($query_params, $count = false) |
|
789 | - { |
|
790 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
791 | - // let's add in specific query_params for inactive events. |
|
792 | - if (isset($where_params['status'])) { |
|
793 | - unset($where_params['status']); |
|
794 | - } |
|
795 | - // if we have count make sure we don't include group by |
|
796 | - if ($count && isset($query_params['group_by'])) { |
|
797 | - unset($query_params['group_by']); |
|
798 | - } |
|
799 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
800 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
801 | - if (isset($where_params['OR'])) { |
|
802 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
803 | - unset($where_params['OR']); |
|
804 | - } |
|
805 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
806 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
807 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
808 | - } |
|
809 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
810 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
811 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
812 | - } |
|
813 | - $query_params[0] = $where_params; |
|
814 | - // don't use $query_params with count() |
|
815 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
816 | - return $count |
|
817 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
818 | - : $this->get_all($query_params); |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
824 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
825 | - * attached to the event. See parent for param descriptions |
|
826 | - * |
|
827 | - * @param $id_or_obj |
|
828 | - * @param $other_model_id_or_obj |
|
829 | - * @param string $relationName |
|
830 | - * @param array $where_query |
|
831 | - * @return EE_Base_Class |
|
832 | - * @throws EE_Error |
|
833 | - * @throws ReflectionException |
|
834 | - */ |
|
835 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
836 | - { |
|
837 | - if ($relationName === 'Price') { |
|
838 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
839 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
840 | - // if EVT_ID = 0, then this is a default |
|
841 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
842 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
843 | - $prc_chk->set('PRC_ID', 0); |
|
844 | - } |
|
845 | - // run parent |
|
846 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
847 | - } |
|
848 | - // otherwise carry on as normal |
|
849 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - |
|
854 | - /******************** DEPRECATED METHODS ********************/ |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * _get_question_target_db_column |
|
859 | - * |
|
860 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
861 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
862 | - * registration). |
|
863 | - * @return array |
|
864 | - * @throws ReflectionException |
|
865 | - * @throws EE_Error*@deprecated as of 4.8.32.rc.001. Instead consider using |
|
866 | - * EE_Registration_Custom_Questions_Form located in |
|
867 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
868 | - * @access public |
|
869 | - */ |
|
870 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
871 | - { |
|
872 | - if (empty($EVT_ID)) { |
|
873 | - throw new EE_Error(__( |
|
874 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
875 | - 'event_espresso' |
|
876 | - )); |
|
877 | - } |
|
878 | - $questions = array(); |
|
879 | - // get all question groups for event |
|
880 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
881 | - if (! empty($qgs)) { |
|
882 | - foreach ($qgs as $qg) { |
|
883 | - $qsts = $qg->questions(); |
|
884 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
885 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
886 | - foreach ($qsts as $qst) { |
|
887 | - if ($qst->is_system_question()) { |
|
888 | - continue; |
|
889 | - } |
|
890 | - $answer = EEM_Answer::instance()->get_one(array( |
|
891 | - array( |
|
892 | - 'QST_ID' => $qst->ID(), |
|
893 | - 'REG_ID' => $registration->ID(), |
|
894 | - ), |
|
895 | - )); |
|
896 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
897 | - $qst_name = $qstn_id = $qst->ID(); |
|
898 | - $ans_id = $answer->ID(); |
|
899 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
900 | - $input_name = ''; |
|
901 | - $input_id = sanitize_key($qst->display_text()); |
|
902 | - $input_class = ''; |
|
903 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
904 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
905 | - . $input_name |
|
906 | - . $qst_name; |
|
907 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
908 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
909 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
910 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
911 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
912 | - // leave responses as-is, don't convert stuff into html entities please! |
|
913 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
914 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
915 | - $QSOs = $qst->options(true, $answer->value()); |
|
916 | - if (is_array($QSOs)) { |
|
917 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
918 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
919 | - } |
|
920 | - } |
|
921 | - } |
|
922 | - } |
|
923 | - } |
|
924 | - } |
|
925 | - return $questions; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
931 | - * or an stdClass where each property is the name of a column, |
|
932 | - * @return EE_Base_Class |
|
933 | - * @throws EE_Error |
|
934 | - */ |
|
935 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
936 | - { |
|
937 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
938 | - if ($classInstance instanceof EE_Event) { |
|
939 | - // events have their timezone defined in the DB, so use it immediately |
|
940 | - $this->set_timezone($classInstance->get_timezone()); |
|
941 | - } |
|
942 | - return $classInstance; |
|
943 | - } |
|
17 | + /** |
|
18 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
19 | + * event |
|
20 | + */ |
|
21 | + const sold_out = 'sold_out'; |
|
22 | + |
|
23 | + /** |
|
24 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
25 | + * date) |
|
26 | + */ |
|
27 | + const postponed = 'postponed'; |
|
28 | + |
|
29 | + /** |
|
30 | + * constant used by status(), indicating that the event will no longer occur |
|
31 | + */ |
|
32 | + const cancelled = 'cancelled'; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected static $_default_reg_status; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * This is the default for the additional limit field. |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected static $_default_additional_limit = 10; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * private instance of the Event object |
|
50 | + * |
|
51 | + * @var EEM_Event |
|
52 | + */ |
|
53 | + protected static $_instance; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
58 | + * |
|
59 | + * @param string $timezone |
|
60 | + * @throws EE_Error |
|
61 | + * @throws ReflectionException |
|
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 | + 'VNU_ID' => new EE_Foreign_Key_Int_Field( |
|
199 | + 'VNU_ID', |
|
200 | + __('Venue ID', 'event_espresso'), |
|
201 | + false, |
|
202 | + 0, |
|
203 | + 'Venue' |
|
204 | + ), |
|
205 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
206 | + 'EVT_display_desc', |
|
207 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
208 | + false, |
|
209 | + true |
|
210 | + ), |
|
211 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
212 | + 'EVT_display_ticket_selector', |
|
213 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
214 | + false, |
|
215 | + true |
|
216 | + ), |
|
217 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
218 | + 'EVT_visible_on', |
|
219 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
220 | + true, |
|
221 | + EE_Datetime_Field::now |
|
222 | + ), |
|
223 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
224 | + 'EVT_additional_limit', |
|
225 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
226 | + true, |
|
227 | + self::$_default_additional_limit |
|
228 | + ), |
|
229 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
230 | + 'EVT_default_registration_status', |
|
231 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
232 | + false, |
|
233 | + EEM_Event::$_default_reg_status, |
|
234 | + EEM_Registration::reg_status_array() |
|
235 | + ), |
|
236 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
237 | + 'EVT_member_only', |
|
238 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
239 | + false, |
|
240 | + false |
|
241 | + ), |
|
242 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
243 | + 'EVT_phone', |
|
244 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
245 | + false, |
|
246 | + '' |
|
247 | + ), |
|
248 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
249 | + 'EVT_allow_overflow', |
|
250 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
251 | + false, |
|
252 | + false |
|
253 | + ), |
|
254 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
255 | + 'EVT_timezone_string', |
|
256 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
257 | + false, |
|
258 | + '' |
|
259 | + ), |
|
260 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
261 | + 'EVT_external_URL', |
|
262 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
263 | + true |
|
264 | + ), |
|
265 | + 'EVT_donations' => new EE_Boolean_Field( |
|
266 | + 'EVT_donations', |
|
267 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
268 | + false, |
|
269 | + false |
|
270 | + ), |
|
271 | + 'FSC_UUID' => new EE_Foreign_Key_String_Field( |
|
272 | + 'FSC_UUID', |
|
273 | + esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'), |
|
274 | + true, |
|
275 | + null, |
|
276 | + 'Form_Section', |
|
277 | + false |
|
278 | + ), |
|
279 | + ), |
|
280 | + ); |
|
281 | + $this->_model_relations = array( |
|
282 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
283 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
284 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
285 | + 'Form_Section' => new EE_Belongs_To_Relation(), |
|
286 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
287 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
288 | + 'Registration' => new EE_Has_Many_Relation(), |
|
289 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
290 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
291 | + 'Venue' => new EE_Belongs_To_Relation(), |
|
292 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
293 | + ); |
|
294 | + // this model is generally available for reading |
|
295 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
296 | + $this->model_chain_to_password = ''; |
|
297 | + parent::__construct($timezone); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * @param string $default_reg_status |
|
303 | + * @throws EE_Error |
|
304 | + * @throws EE_Error |
|
305 | + */ |
|
306 | + public static function set_default_reg_status($default_reg_status) |
|
307 | + { |
|
308 | + self::$_default_reg_status = $default_reg_status; |
|
309 | + // if EEM_Event has already been instantiated, |
|
310 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
311 | + if (self::$_instance instanceof EEM_Event) { |
|
312 | + $default_reg_status = new EE_Enum_Text_Field( |
|
313 | + 'EVT_default_registration_status', |
|
314 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
315 | + false, |
|
316 | + $default_reg_status, |
|
317 | + EEM_Registration::reg_status_array() |
|
318 | + ); |
|
319 | + $default_reg_status->_construct_finalize( |
|
320 | + 'Event_Meta', |
|
321 | + 'EVT_default_registration_status', |
|
322 | + 'EEM_Event' |
|
323 | + ); |
|
324 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Used to override the default for the additional limit field. |
|
331 | + * @param $additional_limit |
|
332 | + */ |
|
333 | + public static function set_default_additional_limit($additional_limit) |
|
334 | + { |
|
335 | + self::$_default_additional_limit = (int) $additional_limit; |
|
336 | + if (self::$_instance instanceof EEM_Event) { |
|
337 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
338 | + 'EVT_additional_limit', |
|
339 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
340 | + true, |
|
341 | + self::$_default_additional_limit |
|
342 | + ); |
|
343 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
344 | + 'Event_Meta', |
|
345 | + 'EVT_additional_limit', |
|
346 | + 'EEM_Event' |
|
347 | + ); |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Return what is currently set as the default additional limit for the event. |
|
354 | + * @return int |
|
355 | + */ |
|
356 | + public static function get_default_additional_limit() |
|
357 | + { |
|
358 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * get_question_groups |
|
364 | + * |
|
365 | + * @return array |
|
366 | + * @throws EE_Error |
|
367 | + * @throws ReflectionException |
|
368 | + */ |
|
369 | + public function get_all_question_groups() |
|
370 | + { |
|
371 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
372 | + array( |
|
373 | + array('QSG_deleted' => false), |
|
374 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
375 | + ) |
|
376 | + ); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * get_question_groups |
|
382 | + * |
|
383 | + * @param int $EVT_ID |
|
384 | + * @return array|bool |
|
385 | + * @throws EE_Error |
|
386 | + * @throws ReflectionException |
|
387 | + */ |
|
388 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
389 | + { |
|
390 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
391 | + EE_Error::add_error( |
|
392 | + esc_html__( |
|
393 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
394 | + 'event_espresso' |
|
395 | + ), |
|
396 | + __FILE__, |
|
397 | + __FUNCTION__, |
|
398 | + __LINE__ |
|
399 | + ); |
|
400 | + return false; |
|
401 | + } |
|
402 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
403 | + array( |
|
404 | + array('EVT_ID' => $EVT_ID), |
|
405 | + ) |
|
406 | + ); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * get_question_groups |
|
412 | + * |
|
413 | + * @param int $EVT_ID |
|
414 | + * @param boolean $for_primary_attendee |
|
415 | + * @return array|bool |
|
416 | + * @throws EE_Error |
|
417 | + * @throws InvalidArgumentException |
|
418 | + * @throws ReflectionException |
|
419 | + * @throws InvalidDataTypeException |
|
420 | + * @throws InvalidInterfaceException |
|
421 | + */ |
|
422 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
423 | + { |
|
424 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
425 | + EE_Error::add_error( |
|
426 | + esc_html__( |
|
427 | + // @codingStandardsIgnoreStart |
|
428 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
429 | + // @codingStandardsIgnoreEnd |
|
430 | + 'event_espresso' |
|
431 | + ), |
|
432 | + __FILE__, |
|
433 | + __FUNCTION__, |
|
434 | + __LINE__ |
|
435 | + ); |
|
436 | + return false; |
|
437 | + } |
|
438 | + $query_params = [ |
|
439 | + [ |
|
440 | + 'EVT_ID' => $EVT_ID, |
|
441 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
442 | + ] |
|
443 | + ]; |
|
444 | + if ($for_primary_attendee) { |
|
445 | + $query_params[0]['EQG_primary'] = true; |
|
446 | + } else { |
|
447 | + $query_params[0]['EQG_additional'] = true; |
|
448 | + } |
|
449 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * get_question_groups |
|
455 | + * |
|
456 | + * @param int $EVT_ID |
|
457 | + * @param EE_Registration $registration |
|
458 | + * @return array|bool |
|
459 | + * @throws EE_Error |
|
460 | + * @throws InvalidArgumentException |
|
461 | + * @throws InvalidDataTypeException |
|
462 | + * @throws InvalidInterfaceException |
|
463 | + * @throws ReflectionException |
|
464 | + */ |
|
465 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
466 | + { |
|
467 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
468 | + EE_Error::add_error( |
|
469 | + esc_html__( |
|
470 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
471 | + 'event_espresso' |
|
472 | + ), |
|
473 | + __FILE__, |
|
474 | + __FUNCTION__, |
|
475 | + __LINE__ |
|
476 | + ); |
|
477 | + return false; |
|
478 | + } |
|
479 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
480 | + [ |
|
481 | + [ |
|
482 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
483 | + 'Event_Question_Group.' |
|
484 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
485 | + $registration->is_primary_registrant() |
|
486 | + ) => true |
|
487 | + ], |
|
488 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
489 | + ] |
|
490 | + ); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * get_question_target_db_column |
|
496 | + * |
|
497 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
498 | + * @return array|bool |
|
499 | + * @throws EE_Error |
|
500 | + * @throws ReflectionException |
|
501 | + */ |
|
502 | + public function get_questions_in_groups($QSG_IDs = '') |
|
503 | + { |
|
504 | + if (empty($QSG_IDs)) { |
|
505 | + EE_Error::add_error( |
|
506 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
507 | + __FILE__, |
|
508 | + __FUNCTION__, |
|
509 | + __LINE__ |
|
510 | + ); |
|
511 | + return false; |
|
512 | + } |
|
513 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
514 | + array( |
|
515 | + array( |
|
516 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
517 | + 'QST_deleted' => false, |
|
518 | + 'QST_admin_only' => is_admin(), |
|
519 | + ), |
|
520 | + 'order_by' => 'QST_order', |
|
521 | + ) |
|
522 | + ); |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * get_options_for_question |
|
528 | + * |
|
529 | + * @param string $QST_IDs csv list of $QST IDs |
|
530 | + * @return array|bool |
|
531 | + * @throws EE_Error |
|
532 | + * @throws ReflectionException |
|
533 | + */ |
|
534 | + public function get_options_for_question($QST_IDs) |
|
535 | + { |
|
536 | + if (empty($QST_IDs)) { |
|
537 | + EE_Error::add_error( |
|
538 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
539 | + __FILE__, |
|
540 | + __FUNCTION__, |
|
541 | + __LINE__ |
|
542 | + ); |
|
543 | + return false; |
|
544 | + } |
|
545 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
546 | + array( |
|
547 | + array( |
|
548 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
549 | + 'QSO_deleted' => false, |
|
550 | + ), |
|
551 | + 'order_by' => 'QSO_ID', |
|
552 | + ) |
|
553 | + ); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * Gets all events that are published |
|
559 | + * and have event start time earlier than now and an event end time later than now |
|
560 | + * |
|
561 | + * @param array $query_params An array of query params to further filter on |
|
562 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
563 | + * @param bool $count whether to return the count or not (default FALSE) |
|
564 | + * @return EE_Event[]|int |
|
565 | + * @throws EE_Error |
|
566 | + * @throws ReflectionException |
|
567 | + */ |
|
568 | + public function get_active_events($query_params, $count = false) |
|
569 | + { |
|
570 | + if (array_key_exists(0, $query_params)) { |
|
571 | + $where_params = $query_params[0]; |
|
572 | + unset($query_params[0]); |
|
573 | + } else { |
|
574 | + $where_params = array(); |
|
575 | + } |
|
576 | + // if we have count make sure we don't include group by |
|
577 | + if ($count && isset($query_params['group_by'])) { |
|
578 | + unset($query_params['group_by']); |
|
579 | + } |
|
580 | + // let's add specific query_params for active_events |
|
581 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
582 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
583 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
584 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
585 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
586 | + '<', |
|
587 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
588 | + ); |
|
589 | + } else { |
|
590 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
591 | + '<', |
|
592 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
593 | + ); |
|
594 | + } |
|
595 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
596 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
597 | + '>', |
|
598 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
599 | + ); |
|
600 | + } else { |
|
601 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
602 | + '>', |
|
603 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
604 | + ); |
|
605 | + } |
|
606 | + $query_params[0] = $where_params; |
|
607 | + // don't use $query_params with count() |
|
608 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
609 | + return $count |
|
610 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
611 | + : $this->get_all($query_params); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * get all events that are published and have an event start time later than now |
|
617 | + * |
|
618 | + * @param array $query_params An array of query params to further filter on |
|
619 | + * (Note that status and DTT_EVT_start will be overridden) |
|
620 | + * @param bool $count whether to return the count or not (default FALSE) |
|
621 | + * @return EE_Event[]|int |
|
622 | + * @throws EE_Error |
|
623 | + * @throws ReflectionException |
|
624 | + */ |
|
625 | + public function get_upcoming_events($query_params, $count = false) |
|
626 | + { |
|
627 | + if (array_key_exists(0, $query_params)) { |
|
628 | + $where_params = $query_params[0]; |
|
629 | + unset($query_params[0]); |
|
630 | + } else { |
|
631 | + $where_params = array(); |
|
632 | + } |
|
633 | + // if we have count make sure we don't include group by |
|
634 | + if ($count && isset($query_params['group_by'])) { |
|
635 | + unset($query_params['group_by']); |
|
636 | + } |
|
637 | + // let's add specific query_params for active_events |
|
638 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
639 | + // we need to pull events with a status of publish and sold_out |
|
640 | + $event_status = array('publish', EEM_Event::sold_out); |
|
641 | + // check if the user can read private events and if so add the 'private status to the were params' |
|
642 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
643 | + $event_status[] = 'private'; |
|
644 | + } |
|
645 | + $where_params['status'] = array('IN', $event_status); |
|
646 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
647 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
648 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
649 | + '>', |
|
650 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
651 | + ); |
|
652 | + } else { |
|
653 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
654 | + '>', |
|
655 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
656 | + ); |
|
657 | + } |
|
658 | + $query_params[0] = $where_params; |
|
659 | + // don't use $query_params with count() |
|
660 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
661 | + return $count |
|
662 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
663 | + : $this->get_all($query_params); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * Gets all events that are published |
|
669 | + * and have an event end time later than now |
|
670 | + * |
|
671 | + * @param array $query_params An array of query params to further filter on |
|
672 | + * (note that status and DTT_EVT_end will be overridden) |
|
673 | + * @param bool $count whether to return the count or not (default FALSE) |
|
674 | + * @return EE_Event[]|int |
|
675 | + * @throws EE_Error |
|
676 | + * @throws ReflectionException |
|
677 | + */ |
|
678 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
679 | + { |
|
680 | + if (array_key_exists(0, $query_params)) { |
|
681 | + $where_params = $query_params[0]; |
|
682 | + unset($query_params[0]); |
|
683 | + } else { |
|
684 | + $where_params = array(); |
|
685 | + } |
|
686 | + // if we have count make sure we don't include group by |
|
687 | + if ($count && isset($query_params['group_by'])) { |
|
688 | + unset($query_params['group_by']); |
|
689 | + } |
|
690 | + // let's add specific query_params for active_events |
|
691 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
692 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
693 | + // add where params for DTT_EVT_end |
|
694 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
695 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
696 | + '>', |
|
697 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
698 | + ); |
|
699 | + } else { |
|
700 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
701 | + '>', |
|
702 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
703 | + ); |
|
704 | + } |
|
705 | + $query_params[0] = $where_params; |
|
706 | + // don't use $query_params with count() |
|
707 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
708 | + return $count |
|
709 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
710 | + : $this->get_all($query_params); |
|
711 | + } |
|
712 | + |
|
713 | + |
|
714 | + /** |
|
715 | + * This only returns events that are expired. |
|
716 | + * They may still be published but all their datetimes have expired. |
|
717 | + * |
|
718 | + * @param array $query_params An array of query params to further filter on |
|
719 | + * (note that status and DTT_EVT_end will be overridden) |
|
720 | + * @param bool $count whether to return the count or not (default FALSE) |
|
721 | + * @return EE_Event[]|int |
|
722 | + * @throws EE_Error |
|
723 | + * @throws ReflectionException |
|
724 | + */ |
|
725 | + public function get_expired_events($query_params, $count = false) |
|
726 | + { |
|
727 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
728 | + // if we have count make sure we don't include group by |
|
729 | + if ($count && isset($query_params['group_by'])) { |
|
730 | + unset($query_params['group_by']); |
|
731 | + } |
|
732 | + // let's add specific query_params for active_events |
|
733 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
734 | + if (isset($where_params['status'])) { |
|
735 | + unset($where_params['status']); |
|
736 | + } |
|
737 | + $exclude_query = $query_params; |
|
738 | + if (isset($exclude_query[0])) { |
|
739 | + unset($exclude_query[0]); |
|
740 | + } |
|
741 | + $exclude_query[0] = array( |
|
742 | + 'Datetime.DTT_EVT_end' => array( |
|
743 | + '>', |
|
744 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
745 | + ), |
|
746 | + ); |
|
747 | + // first get all events that have datetimes where its not expired. |
|
748 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
749 | + $event_ids = array_keys($event_ids); |
|
750 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
751 | + $and_condition = array( |
|
752 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
753 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
754 | + ); |
|
755 | + if (isset($where_params['OR'])) { |
|
756 | + $and_condition['OR'] = $where_params['OR']; |
|
757 | + unset($where_params['OR']); |
|
758 | + } |
|
759 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
760 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
761 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
762 | + } |
|
763 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
764 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
765 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
766 | + } |
|
767 | + // merge remaining $where params with the and conditions. |
|
768 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
769 | + $query_params[0] = $where_params; |
|
770 | + // don't use $query_params with count() |
|
771 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
772 | + return $count |
|
773 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
774 | + : $this->get_all($query_params); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + |
|
779 | + /** |
|
780 | + * This basically just returns the events that do not have the publish status. |
|
781 | + * |
|
782 | + * @param array $query_params An array of query params to further filter on |
|
783 | + * (note that status will be overwritten) |
|
784 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
785 | + * @return EE_Event[]|int |
|
786 | + * @throws EE_Error |
|
787 | + */ |
|
788 | + public function get_inactive_events($query_params, $count = false) |
|
789 | + { |
|
790 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
791 | + // let's add in specific query_params for inactive events. |
|
792 | + if (isset($where_params['status'])) { |
|
793 | + unset($where_params['status']); |
|
794 | + } |
|
795 | + // if we have count make sure we don't include group by |
|
796 | + if ($count && isset($query_params['group_by'])) { |
|
797 | + unset($query_params['group_by']); |
|
798 | + } |
|
799 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
800 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
801 | + if (isset($where_params['OR'])) { |
|
802 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
803 | + unset($where_params['OR']); |
|
804 | + } |
|
805 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
806 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
807 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
808 | + } |
|
809 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
810 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
811 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
812 | + } |
|
813 | + $query_params[0] = $where_params; |
|
814 | + // don't use $query_params with count() |
|
815 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
816 | + return $count |
|
817 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
818 | + : $this->get_all($query_params); |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
824 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
825 | + * attached to the event. See parent for param descriptions |
|
826 | + * |
|
827 | + * @param $id_or_obj |
|
828 | + * @param $other_model_id_or_obj |
|
829 | + * @param string $relationName |
|
830 | + * @param array $where_query |
|
831 | + * @return EE_Base_Class |
|
832 | + * @throws EE_Error |
|
833 | + * @throws ReflectionException |
|
834 | + */ |
|
835 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
836 | + { |
|
837 | + if ($relationName === 'Price') { |
|
838 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
839 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
840 | + // if EVT_ID = 0, then this is a default |
|
841 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
842 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
843 | + $prc_chk->set('PRC_ID', 0); |
|
844 | + } |
|
845 | + // run parent |
|
846 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
847 | + } |
|
848 | + // otherwise carry on as normal |
|
849 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + |
|
854 | + /******************** DEPRECATED METHODS ********************/ |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * _get_question_target_db_column |
|
859 | + * |
|
860 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
861 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
862 | + * registration). |
|
863 | + * @return array |
|
864 | + * @throws ReflectionException |
|
865 | + * @throws EE_Error*@deprecated as of 4.8.32.rc.001. Instead consider using |
|
866 | + * EE_Registration_Custom_Questions_Form located in |
|
867 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
868 | + * @access public |
|
869 | + */ |
|
870 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
871 | + { |
|
872 | + if (empty($EVT_ID)) { |
|
873 | + throw new EE_Error(__( |
|
874 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
875 | + 'event_espresso' |
|
876 | + )); |
|
877 | + } |
|
878 | + $questions = array(); |
|
879 | + // get all question groups for event |
|
880 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
881 | + if (! empty($qgs)) { |
|
882 | + foreach ($qgs as $qg) { |
|
883 | + $qsts = $qg->questions(); |
|
884 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
885 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
886 | + foreach ($qsts as $qst) { |
|
887 | + if ($qst->is_system_question()) { |
|
888 | + continue; |
|
889 | + } |
|
890 | + $answer = EEM_Answer::instance()->get_one(array( |
|
891 | + array( |
|
892 | + 'QST_ID' => $qst->ID(), |
|
893 | + 'REG_ID' => $registration->ID(), |
|
894 | + ), |
|
895 | + )); |
|
896 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
897 | + $qst_name = $qstn_id = $qst->ID(); |
|
898 | + $ans_id = $answer->ID(); |
|
899 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
900 | + $input_name = ''; |
|
901 | + $input_id = sanitize_key($qst->display_text()); |
|
902 | + $input_class = ''; |
|
903 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
904 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
905 | + . $input_name |
|
906 | + . $qst_name; |
|
907 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
908 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
909 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
910 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
911 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
912 | + // leave responses as-is, don't convert stuff into html entities please! |
|
913 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
914 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
915 | + $QSOs = $qst->options(true, $answer->value()); |
|
916 | + if (is_array($QSOs)) { |
|
917 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
918 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
919 | + } |
|
920 | + } |
|
921 | + } |
|
922 | + } |
|
923 | + } |
|
924 | + } |
|
925 | + return $questions; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
931 | + * or an stdClass where each property is the name of a column, |
|
932 | + * @return EE_Base_Class |
|
933 | + * @throws EE_Error |
|
934 | + */ |
|
935 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
936 | + { |
|
937 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
938 | + if ($classInstance instanceof EE_Event) { |
|
939 | + // events have their timezone defined in the DB, so use it immediately |
|
940 | + $this->set_timezone($classInstance->get_timezone()); |
|
941 | + } |
|
942 | + return $classInstance; |
|
943 | + } |
|
944 | 944 | } |