@@ -10,437 +10,437 @@ |
||
10 | 10 | class EEM_Question extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - // constant used to indicate that the question type is COUNTRY |
|
14 | - const QST_type_country = 'COUNTRY'; |
|
13 | + // constant used to indicate that the question type is COUNTRY |
|
14 | + const QST_type_country = 'COUNTRY'; |
|
15 | 15 | |
16 | - // constant used to indicate that the question type is DATE |
|
17 | - const QST_type_date = 'DATE'; |
|
18 | - |
|
19 | - // constant used to indicate that the question type is DROPDOWN |
|
20 | - const QST_type_dropdown = 'DROPDOWN'; |
|
21 | - |
|
22 | - // constant used to indicate that the question type is CHECKBOX |
|
23 | - const QST_type_checkbox = 'CHECKBOX'; |
|
24 | - |
|
25 | - // constant used to indicate that the question type is RADIO_BTN |
|
26 | - const QST_type_radio = 'RADIO_BTN'; |
|
27 | - |
|
28 | - // constant used to indicate that the question type is STATE |
|
29 | - const QST_type_state = 'STATE'; |
|
30 | - |
|
31 | - // constant used to indicate that the question type is TEXT |
|
32 | - const QST_type_text = 'TEXT'; |
|
33 | - |
|
34 | - // constant used to indicate that the question type is TEXTAREA |
|
35 | - const QST_type_textarea = 'TEXTAREA'; |
|
36 | - |
|
37 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
38 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
39 | - |
|
40 | - // constant used to indicate that the question type is an email input |
|
41 | - const QST_type_email = 'EMAIL'; |
|
42 | - |
|
43 | - // constant used to indicate that the question type is an email input |
|
44 | - const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
45 | - |
|
46 | - // constant used to indicate that the question type is a US-formatted phone number |
|
47 | - const QST_type_us_phone = 'US_PHONE'; |
|
48 | - |
|
49 | - // constant used to indicate that the question type is an integer (whole number) |
|
50 | - const QST_type_int = 'INTEGER'; |
|
51 | - |
|
52 | - // constant used to indicate that the question type is a decimal (float) |
|
53 | - const QST_type_decimal = 'DECIMAL'; |
|
54 | - |
|
55 | - // constant used to indicate that the question type is a valid URL |
|
56 | - const QST_type_url = 'URL'; |
|
57 | - |
|
58 | - // constant used to indicate that the question type is a YEAR |
|
59 | - const QST_type_year = 'YEAR'; |
|
60 | - |
|
61 | - // constant used to indicate that the question type is a multi-select |
|
62 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
66 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
67 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
68 | - * |
|
69 | - * @access protected |
|
70 | - * @var array $_question_type_categories { |
|
71 | - * @type string $text |
|
72 | - * @type string $single -answer-enum |
|
73 | - * @type string $multi -answer-enum |
|
74 | - * } |
|
75 | - */ |
|
76 | - protected $_question_type_categories = array(); |
|
77 | - |
|
78 | - /** |
|
79 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
80 | - * |
|
81 | - * @access protected |
|
82 | - * @var array $_allowed_question_types |
|
83 | - */ |
|
84 | - protected $_allowed_question_types = array(); |
|
85 | - |
|
86 | - /** |
|
87 | - * brief descriptions for all the question types |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @var EEM_Question $_instance |
|
91 | - */ |
|
92 | - protected $_question_descriptions; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Question types that should have an admin-defined max input length |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - protected $question_types_with_max_lengh; |
|
100 | - |
|
101 | - |
|
102 | - // private instance of the Attendee object |
|
103 | - protected static $_instance = null; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * EEM_Question constructor. |
|
108 | - * |
|
109 | - * @param null $timezone |
|
110 | - */ |
|
111 | - protected function __construct($timezone = null) |
|
112 | - { |
|
113 | - $this->singular_item = __('Question', 'event_espresso'); |
|
114 | - $this->plural_item = __('Questions', 'event_espresso'); |
|
115 | - $this->_allowed_question_types = apply_filters( |
|
116 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
117 | - array( |
|
118 | - EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
119 | - EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
120 | - EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
121 | - EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
122 | - EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
123 | - EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
124 | - EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
125 | - EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
126 | - EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
127 | - EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
128 | - EEM_Question::QST_type_email_confirm => __('Confirm Email', 'event_espresso'), |
|
129 | - EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
130 | - EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
131 | - EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
132 | - EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
133 | - EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
134 | - EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
135 | - ) |
|
136 | - ); |
|
137 | - $this->_question_descriptions = apply_filters( |
|
138 | - 'FHEE__EEM_Question__construct__question_descriptions', |
|
139 | - array( |
|
140 | - EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
141 | - EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
142 | - EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
143 | - EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
144 | - EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
145 | - EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
146 | - EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
147 | - EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
148 | - EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
149 | - EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
150 | - EEM_Question::QST_type_email_confirm => __('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'), |
|
151 | - EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
152 | - EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
153 | - EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
154 | - EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
155 | - EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
156 | - EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
157 | - ) |
|
158 | - ); |
|
159 | - $this->_question_type_categories = (array) apply_filters( |
|
160 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
161 | - array( |
|
162 | - 'text' => array( |
|
163 | - EEM_Question::QST_type_text, |
|
164 | - EEM_Question::QST_type_textarea, |
|
165 | - EEM_Question::QST_type_date, |
|
166 | - EEM_Question::QST_type_html_textarea, |
|
167 | - EEM_Question::QST_type_email, |
|
168 | - EEM_Question::QST_type_email_confirm, |
|
169 | - EEM_Question::QST_type_us_phone, |
|
170 | - EEM_Question::QST_type_decimal, |
|
171 | - EEM_Question::QST_type_int, |
|
172 | - EEM_Question::QST_type_url, |
|
173 | - EEM_Question::QST_type_year |
|
174 | - ), |
|
175 | - 'single-answer-enum' => array( |
|
176 | - EEM_Question::QST_type_radio, |
|
177 | - EEM_Question::QST_type_dropdown |
|
178 | - ), |
|
179 | - 'multi-answer-enum' => array( |
|
180 | - EEM_Question::QST_type_checkbox, |
|
181 | - EEM_Question::QST_type_multi_select |
|
182 | - ) |
|
183 | - ) |
|
184 | - ); |
|
185 | - $this->question_types_with_max_lengh = apply_filters( |
|
186 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | - array( |
|
188 | - EEM_Question::QST_type_text, |
|
189 | - EEM_Question::QST_type_textarea, |
|
190 | - EEM_Question::QST_type_html_textarea |
|
191 | - ) |
|
192 | - ); |
|
193 | - |
|
194 | - $this->_tables = array( |
|
195 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | - ); |
|
197 | - $this->_fields = array( |
|
198 | - 'Question' => array( |
|
199 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | - 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | - 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | - ) |
|
212 | - ); |
|
213 | - $this->_model_relations = array( |
|
214 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | - 'Answer' => new EE_Has_Many_Relation(), |
|
217 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | - // for QST_order column |
|
219 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | - ); |
|
221 | - // this model is generally available for reading |
|
222 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
223 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | - parent::__construct($timezone); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | - * but they can be extended |
|
232 | - * @return string[] |
|
233 | - */ |
|
234 | - public function allowed_question_types() |
|
235 | - { |
|
236 | - return $this->_allowed_question_types; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the question types in the same category |
|
241 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | - * @return string[] like EEM_Question::allowed_question_types() |
|
243 | - */ |
|
244 | - public function question_types_in_same_category($question_type) |
|
245 | - { |
|
246 | - $question_types = array($question_type); |
|
247 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | - if (in_array($question_type, $question_types_in_category)) { |
|
249 | - $question_types = $question_types_in_category; |
|
250 | - break; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Determines if the given question type is in the given question type category |
|
259 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | - * @return boolean |
|
262 | - */ |
|
263 | - public function question_type_is_in_category($question_type, $category) |
|
264 | - { |
|
265 | - if (!isset($this->_question_type_categories[ $category ])) { |
|
266 | - return false; |
|
267 | - } |
|
268 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Returns all the question types in the given category |
|
274 | - * @param string $category |
|
275 | - * @return array|mixed |
|
276 | - */ |
|
277 | - public function question_types_in_category($category) |
|
278 | - { |
|
279 | - if (isset($this->_question_type_categories[ $category ])) { |
|
280 | - return $this->_question_type_categories[ $category ]; |
|
281 | - } |
|
282 | - return array(); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Returns all the question types that should have question options |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function question_types_with_options() |
|
291 | - { |
|
292 | - return array_merge( |
|
293 | - $this->question_types_in_category('single-answer-enum'), |
|
294 | - $this->question_types_in_category('multi-answer-enum') |
|
295 | - ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the question type categories 2d array |
|
300 | - * @return array see EEM_Question::_question_type_categories |
|
301 | - */ |
|
302 | - public function question_type_categories() |
|
303 | - { |
|
304 | - return $this->_question_type_categories; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | - * identified by $system_question_group_id |
|
310 | - * @param string $system_question_group_id QSG_system |
|
311 | - * @return array of system question names (QST_system) |
|
312 | - */ |
|
313 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | - { |
|
315 | - $question_system_ids = array(); |
|
316 | - switch ($system_question_group_id) { |
|
317 | - case EEM_Question_Group::system_personal: |
|
318 | - $question_system_ids = array( |
|
319 | - EEM_Attendee::system_question_fname, |
|
320 | - EEM_Attendee::system_question_lname, |
|
321 | - EEM_Attendee::system_question_email, |
|
322 | - EEM_Attendee::system_question_email_confirm, |
|
323 | - EEM_Attendee::system_question_phone |
|
324 | - ); |
|
325 | - break; |
|
326 | - case EEM_Question_Group::system_address: |
|
327 | - $question_system_ids = array( |
|
328 | - EEM_Attendee::system_question_address, |
|
329 | - EEM_Attendee::system_question_address2, |
|
330 | - EEM_Attendee::system_question_city, |
|
331 | - EEM_Attendee::system_question_state, |
|
332 | - EEM_Attendee::system_question_country, |
|
333 | - EEM_Attendee::system_question_zip, |
|
334 | - EEM_Attendee::system_question_phone |
|
335 | - ); |
|
336 | - break; |
|
337 | - } |
|
338 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Returns an array of all the QST_system values that are required in the system question group |
|
343 | - * identified by $system_question_group_id |
|
344 | - * @param string $system_question_group_id QSG_system |
|
345 | - * @return array of system question names (QST_system) |
|
346 | - */ |
|
347 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
348 | - { |
|
349 | - $question_system_ids = null; |
|
350 | - switch ($system_question_group_id) { |
|
351 | - case EEM_Question_Group::system_personal: |
|
352 | - $question_system_ids = array( |
|
353 | - EEM_Attendee::system_question_fname, |
|
354 | - EEM_Attendee::system_question_email, |
|
355 | - ); |
|
356 | - break; |
|
357 | - default: |
|
358 | - $question_system_ids = array(); |
|
359 | - } |
|
360 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
366 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
367 | - * @param $QST_system |
|
368 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
369 | - */ |
|
370 | - public function get_Question_ID_from_system_string($QST_system) |
|
371 | - { |
|
372 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * searches the db for the question with the latest question order and returns that value. |
|
378 | - * @access public |
|
379 | - * @return int |
|
380 | - */ |
|
381 | - public function get_latest_question_order() |
|
382 | - { |
|
383 | - $columns_to_select = array( |
|
384 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
385 | - ); |
|
386 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
387 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns an array where keys are system question QST_system values, |
|
392 | - * and values are the highest question max the admin can set on the question |
|
393 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
394 | - * of 5, but no larger than 12) |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - public function system_question_maxes() |
|
398 | - { |
|
399 | - return array( |
|
400 | - 'fname' => 45, |
|
401 | - 'lname' => 45, |
|
402 | - 'address' => 255, |
|
403 | - 'address2' => 255, |
|
404 | - 'city' => 45, |
|
405 | - 'zip' => 12, |
|
406 | - 'email' => 255, |
|
407 | - 'email_confirm' => 255, |
|
408 | - 'phone' => 45, |
|
409 | - ); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
414 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
415 | - * @param string $system_question_value |
|
416 | - * @return int|float |
|
417 | - */ |
|
418 | - public function absolute_max_for_system_question($system_question_value) |
|
419 | - { |
|
420 | - $maxes = $this->system_question_maxes(); |
|
421 | - if (isset($maxes[ $system_question_value ])) { |
|
422 | - return $maxes[ $system_question_value ]; |
|
423 | - } else { |
|
424 | - return EE_INF; |
|
425 | - } |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @return array |
|
431 | - */ |
|
432 | - public function question_descriptions() |
|
433 | - { |
|
434 | - return $this->_question_descriptions; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * Returns all the question types that should have an admin-defined max input length |
|
440 | - * @return array |
|
441 | - */ |
|
442 | - public function questionTypesWithMaxLength() |
|
443 | - { |
|
444 | - return (array) $this->question_types_with_max_lengh; |
|
445 | - } |
|
16 | + // constant used to indicate that the question type is DATE |
|
17 | + const QST_type_date = 'DATE'; |
|
18 | + |
|
19 | + // constant used to indicate that the question type is DROPDOWN |
|
20 | + const QST_type_dropdown = 'DROPDOWN'; |
|
21 | + |
|
22 | + // constant used to indicate that the question type is CHECKBOX |
|
23 | + const QST_type_checkbox = 'CHECKBOX'; |
|
24 | + |
|
25 | + // constant used to indicate that the question type is RADIO_BTN |
|
26 | + const QST_type_radio = 'RADIO_BTN'; |
|
27 | + |
|
28 | + // constant used to indicate that the question type is STATE |
|
29 | + const QST_type_state = 'STATE'; |
|
30 | + |
|
31 | + // constant used to indicate that the question type is TEXT |
|
32 | + const QST_type_text = 'TEXT'; |
|
33 | + |
|
34 | + // constant used to indicate that the question type is TEXTAREA |
|
35 | + const QST_type_textarea = 'TEXTAREA'; |
|
36 | + |
|
37 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
38 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
39 | + |
|
40 | + // constant used to indicate that the question type is an email input |
|
41 | + const QST_type_email = 'EMAIL'; |
|
42 | + |
|
43 | + // constant used to indicate that the question type is an email input |
|
44 | + const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
45 | + |
|
46 | + // constant used to indicate that the question type is a US-formatted phone number |
|
47 | + const QST_type_us_phone = 'US_PHONE'; |
|
48 | + |
|
49 | + // constant used to indicate that the question type is an integer (whole number) |
|
50 | + const QST_type_int = 'INTEGER'; |
|
51 | + |
|
52 | + // constant used to indicate that the question type is a decimal (float) |
|
53 | + const QST_type_decimal = 'DECIMAL'; |
|
54 | + |
|
55 | + // constant used to indicate that the question type is a valid URL |
|
56 | + const QST_type_url = 'URL'; |
|
57 | + |
|
58 | + // constant used to indicate that the question type is a YEAR |
|
59 | + const QST_type_year = 'YEAR'; |
|
60 | + |
|
61 | + // constant used to indicate that the question type is a multi-select |
|
62 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
66 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
67 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
68 | + * |
|
69 | + * @access protected |
|
70 | + * @var array $_question_type_categories { |
|
71 | + * @type string $text |
|
72 | + * @type string $single -answer-enum |
|
73 | + * @type string $multi -answer-enum |
|
74 | + * } |
|
75 | + */ |
|
76 | + protected $_question_type_categories = array(); |
|
77 | + |
|
78 | + /** |
|
79 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
80 | + * |
|
81 | + * @access protected |
|
82 | + * @var array $_allowed_question_types |
|
83 | + */ |
|
84 | + protected $_allowed_question_types = array(); |
|
85 | + |
|
86 | + /** |
|
87 | + * brief descriptions for all the question types |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @var EEM_Question $_instance |
|
91 | + */ |
|
92 | + protected $_question_descriptions; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Question types that should have an admin-defined max input length |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + protected $question_types_with_max_lengh; |
|
100 | + |
|
101 | + |
|
102 | + // private instance of the Attendee object |
|
103 | + protected static $_instance = null; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * EEM_Question constructor. |
|
108 | + * |
|
109 | + * @param null $timezone |
|
110 | + */ |
|
111 | + protected function __construct($timezone = null) |
|
112 | + { |
|
113 | + $this->singular_item = __('Question', 'event_espresso'); |
|
114 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
115 | + $this->_allowed_question_types = apply_filters( |
|
116 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
117 | + array( |
|
118 | + EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
119 | + EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
120 | + EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
121 | + EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
122 | + EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
123 | + EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
124 | + EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
125 | + EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
126 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
127 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
128 | + EEM_Question::QST_type_email_confirm => __('Confirm Email', 'event_espresso'), |
|
129 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
130 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
131 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
132 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
133 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
134 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
135 | + ) |
|
136 | + ); |
|
137 | + $this->_question_descriptions = apply_filters( |
|
138 | + 'FHEE__EEM_Question__construct__question_descriptions', |
|
139 | + array( |
|
140 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
141 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
142 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
143 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
144 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
145 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
146 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
147 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
148 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
149 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
150 | + EEM_Question::QST_type_email_confirm => __('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'), |
|
151 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
152 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
153 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
154 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
155 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
156 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
157 | + ) |
|
158 | + ); |
|
159 | + $this->_question_type_categories = (array) apply_filters( |
|
160 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
161 | + array( |
|
162 | + 'text' => array( |
|
163 | + EEM_Question::QST_type_text, |
|
164 | + EEM_Question::QST_type_textarea, |
|
165 | + EEM_Question::QST_type_date, |
|
166 | + EEM_Question::QST_type_html_textarea, |
|
167 | + EEM_Question::QST_type_email, |
|
168 | + EEM_Question::QST_type_email_confirm, |
|
169 | + EEM_Question::QST_type_us_phone, |
|
170 | + EEM_Question::QST_type_decimal, |
|
171 | + EEM_Question::QST_type_int, |
|
172 | + EEM_Question::QST_type_url, |
|
173 | + EEM_Question::QST_type_year |
|
174 | + ), |
|
175 | + 'single-answer-enum' => array( |
|
176 | + EEM_Question::QST_type_radio, |
|
177 | + EEM_Question::QST_type_dropdown |
|
178 | + ), |
|
179 | + 'multi-answer-enum' => array( |
|
180 | + EEM_Question::QST_type_checkbox, |
|
181 | + EEM_Question::QST_type_multi_select |
|
182 | + ) |
|
183 | + ) |
|
184 | + ); |
|
185 | + $this->question_types_with_max_lengh = apply_filters( |
|
186 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | + array( |
|
188 | + EEM_Question::QST_type_text, |
|
189 | + EEM_Question::QST_type_textarea, |
|
190 | + EEM_Question::QST_type_html_textarea |
|
191 | + ) |
|
192 | + ); |
|
193 | + |
|
194 | + $this->_tables = array( |
|
195 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | + ); |
|
197 | + $this->_fields = array( |
|
198 | + 'Question' => array( |
|
199 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | + 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | + 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | + ) |
|
212 | + ); |
|
213 | + $this->_model_relations = array( |
|
214 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | + 'Answer' => new EE_Has_Many_Relation(), |
|
217 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | + // for QST_order column |
|
219 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | + ); |
|
221 | + // this model is generally available for reading |
|
222 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
223 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | + parent::__construct($timezone); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | + * but they can be extended |
|
232 | + * @return string[] |
|
233 | + */ |
|
234 | + public function allowed_question_types() |
|
235 | + { |
|
236 | + return $this->_allowed_question_types; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the question types in the same category |
|
241 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | + * @return string[] like EEM_Question::allowed_question_types() |
|
243 | + */ |
|
244 | + public function question_types_in_same_category($question_type) |
|
245 | + { |
|
246 | + $question_types = array($question_type); |
|
247 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | + if (in_array($question_type, $question_types_in_category)) { |
|
249 | + $question_types = $question_types_in_category; |
|
250 | + break; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Determines if the given question type is in the given question type category |
|
259 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | + * @return boolean |
|
262 | + */ |
|
263 | + public function question_type_is_in_category($question_type, $category) |
|
264 | + { |
|
265 | + if (!isset($this->_question_type_categories[ $category ])) { |
|
266 | + return false; |
|
267 | + } |
|
268 | + return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Returns all the question types in the given category |
|
274 | + * @param string $category |
|
275 | + * @return array|mixed |
|
276 | + */ |
|
277 | + public function question_types_in_category($category) |
|
278 | + { |
|
279 | + if (isset($this->_question_type_categories[ $category ])) { |
|
280 | + return $this->_question_type_categories[ $category ]; |
|
281 | + } |
|
282 | + return array(); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Returns all the question types that should have question options |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function question_types_with_options() |
|
291 | + { |
|
292 | + return array_merge( |
|
293 | + $this->question_types_in_category('single-answer-enum'), |
|
294 | + $this->question_types_in_category('multi-answer-enum') |
|
295 | + ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the question type categories 2d array |
|
300 | + * @return array see EEM_Question::_question_type_categories |
|
301 | + */ |
|
302 | + public function question_type_categories() |
|
303 | + { |
|
304 | + return $this->_question_type_categories; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | + * identified by $system_question_group_id |
|
310 | + * @param string $system_question_group_id QSG_system |
|
311 | + * @return array of system question names (QST_system) |
|
312 | + */ |
|
313 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | + { |
|
315 | + $question_system_ids = array(); |
|
316 | + switch ($system_question_group_id) { |
|
317 | + case EEM_Question_Group::system_personal: |
|
318 | + $question_system_ids = array( |
|
319 | + EEM_Attendee::system_question_fname, |
|
320 | + EEM_Attendee::system_question_lname, |
|
321 | + EEM_Attendee::system_question_email, |
|
322 | + EEM_Attendee::system_question_email_confirm, |
|
323 | + EEM_Attendee::system_question_phone |
|
324 | + ); |
|
325 | + break; |
|
326 | + case EEM_Question_Group::system_address: |
|
327 | + $question_system_ids = array( |
|
328 | + EEM_Attendee::system_question_address, |
|
329 | + EEM_Attendee::system_question_address2, |
|
330 | + EEM_Attendee::system_question_city, |
|
331 | + EEM_Attendee::system_question_state, |
|
332 | + EEM_Attendee::system_question_country, |
|
333 | + EEM_Attendee::system_question_zip, |
|
334 | + EEM_Attendee::system_question_phone |
|
335 | + ); |
|
336 | + break; |
|
337 | + } |
|
338 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Returns an array of all the QST_system values that are required in the system question group |
|
343 | + * identified by $system_question_group_id |
|
344 | + * @param string $system_question_group_id QSG_system |
|
345 | + * @return array of system question names (QST_system) |
|
346 | + */ |
|
347 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
348 | + { |
|
349 | + $question_system_ids = null; |
|
350 | + switch ($system_question_group_id) { |
|
351 | + case EEM_Question_Group::system_personal: |
|
352 | + $question_system_ids = array( |
|
353 | + EEM_Attendee::system_question_fname, |
|
354 | + EEM_Attendee::system_question_email, |
|
355 | + ); |
|
356 | + break; |
|
357 | + default: |
|
358 | + $question_system_ids = array(); |
|
359 | + } |
|
360 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
366 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
367 | + * @param $QST_system |
|
368 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
369 | + */ |
|
370 | + public function get_Question_ID_from_system_string($QST_system) |
|
371 | + { |
|
372 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * searches the db for the question with the latest question order and returns that value. |
|
378 | + * @access public |
|
379 | + * @return int |
|
380 | + */ |
|
381 | + public function get_latest_question_order() |
|
382 | + { |
|
383 | + $columns_to_select = array( |
|
384 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
385 | + ); |
|
386 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
387 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns an array where keys are system question QST_system values, |
|
392 | + * and values are the highest question max the admin can set on the question |
|
393 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
394 | + * of 5, but no larger than 12) |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + public function system_question_maxes() |
|
398 | + { |
|
399 | + return array( |
|
400 | + 'fname' => 45, |
|
401 | + 'lname' => 45, |
|
402 | + 'address' => 255, |
|
403 | + 'address2' => 255, |
|
404 | + 'city' => 45, |
|
405 | + 'zip' => 12, |
|
406 | + 'email' => 255, |
|
407 | + 'email_confirm' => 255, |
|
408 | + 'phone' => 45, |
|
409 | + ); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
414 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
415 | + * @param string $system_question_value |
|
416 | + * @return int|float |
|
417 | + */ |
|
418 | + public function absolute_max_for_system_question($system_question_value) |
|
419 | + { |
|
420 | + $maxes = $this->system_question_maxes(); |
|
421 | + if (isset($maxes[ $system_question_value ])) { |
|
422 | + return $maxes[ $system_question_value ]; |
|
423 | + } else { |
|
424 | + return EE_INF; |
|
425 | + } |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @return array |
|
431 | + */ |
|
432 | + public function question_descriptions() |
|
433 | + { |
|
434 | + return $this->_question_descriptions; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * Returns all the question types that should have an admin-defined max input length |
|
440 | + * @return array |
|
441 | + */ |
|
442 | + public function questionTypesWithMaxLength() |
|
443 | + { |
|
444 | + return (array) $this->question_types_with_max_lengh; |
|
445 | + } |
|
446 | 446 | } |
@@ -12,432 +12,432 @@ |
||
12 | 12 | class EEM_Attendee extends EEM_CPT_Base |
13 | 13 | { |
14 | 14 | |
15 | - // private instance of the Attendee object |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance of the Attendee object |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * QST_system for questions are strings not integers now, |
|
20 | - * so these constants are deprecated. |
|
21 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
22 | - * |
|
23 | - * @deprecated |
|
24 | - */ |
|
25 | - const fname_question_id = 1; |
|
18 | + /** |
|
19 | + * QST_system for questions are strings not integers now, |
|
20 | + * so these constants are deprecated. |
|
21 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
22 | + * |
|
23 | + * @deprecated |
|
24 | + */ |
|
25 | + const fname_question_id = 1; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @deprecated |
|
29 | - */ |
|
30 | - const lname_question_id = 2; |
|
27 | + /** |
|
28 | + * @deprecated |
|
29 | + */ |
|
30 | + const lname_question_id = 2; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @deprecated |
|
35 | - */ |
|
36 | - const email_question_id = 3; |
|
33 | + /** |
|
34 | + * @deprecated |
|
35 | + */ |
|
36 | + const email_question_id = 3; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @deprecated |
|
41 | - */ |
|
42 | - const address_question_id = 4; |
|
39 | + /** |
|
40 | + * @deprecated |
|
41 | + */ |
|
42 | + const address_question_id = 4; |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @deprecated |
|
47 | - */ |
|
48 | - const address2_question_id = 5; |
|
45 | + /** |
|
46 | + * @deprecated |
|
47 | + */ |
|
48 | + const address2_question_id = 5; |
|
49 | 49 | |
50 | - |
|
51 | - /** |
|
52 | - * @deprecated |
|
53 | - */ |
|
54 | - const city_question_id = 6; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @deprecated |
|
59 | - */ |
|
60 | - const state_question_id = 7; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @deprecated |
|
65 | - */ |
|
66 | - const country_question_id = 8; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @deprecated |
|
71 | - */ |
|
72 | - const zip_question_id = 9; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @deprecated |
|
77 | - */ |
|
78 | - const phone_question_id = 10; |
|
79 | - |
|
80 | - /** |
|
81 | - * When looking for questions that correspond to attendee fields, |
|
82 | - * look for the question with this QST_system value. |
|
83 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
84 | - */ |
|
85 | - const system_question_fname = 'fname'; |
|
86 | - |
|
87 | - const system_question_lname = 'lname'; |
|
88 | - |
|
89 | - const system_question_email = 'email'; |
|
90 | - |
|
91 | - const system_question_email_confirm = 'email_confirm'; |
|
92 | - |
|
93 | - const system_question_address = 'address'; |
|
94 | - |
|
95 | - const system_question_address2 = 'address2'; |
|
96 | - |
|
97 | - const system_question_city = 'city'; |
|
98 | - |
|
99 | - const system_question_state = 'state'; |
|
100 | - |
|
101 | - const system_question_country = 'country'; |
|
102 | - |
|
103 | - const system_question_zip = 'zip'; |
|
104 | - |
|
105 | - const system_question_phone = 'phone'; |
|
106 | - |
|
107 | - /** |
|
108 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
109 | - * also all the values of QST_system in the questions table, and values |
|
110 | - * are their corresponding Attendee field names |
|
111 | - * |
|
112 | - * @var array |
|
113 | - */ |
|
114 | - protected $_system_question_to_attendee_field_name = array( |
|
115 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
116 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
117 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
118 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
119 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
120 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
121 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
122 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
123 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
124 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
125 | - ); |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * EEM_Attendee constructor. |
|
131 | - * |
|
132 | - * @param null $timezone |
|
133 | - * @param ModelFieldFactory $model_field_factory |
|
134 | - * @throws EE_Error |
|
135 | - * @throws InvalidArgumentException |
|
136 | - */ |
|
137 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
138 | - { |
|
139 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
140 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
141 | - $this->_tables = array( |
|
142 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
143 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
144 | - 'esp_attendee_meta', |
|
145 | - 'ATTM_ID', |
|
146 | - 'ATT_ID' |
|
147 | - ), |
|
148 | - ); |
|
149 | - $this->_fields = array( |
|
150 | - 'Attendee_CPT' => array( |
|
151 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
152 | - 'ID', |
|
153 | - esc_html__('Attendee ID', 'event_espresso') |
|
154 | - ), |
|
155 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
156 | - 'post_title', |
|
157 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
158 | - false, |
|
159 | - esc_html__('Unknown', 'event_espresso') |
|
160 | - ), |
|
161 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
162 | - 'post_content', |
|
163 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
164 | - false, |
|
165 | - esc_html__('No Biography Provided', 'event_espresso') |
|
166 | - ), |
|
167 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
168 | - 'post_name', |
|
169 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
170 | - ), |
|
171 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
172 | - 'post_date', |
|
173 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
174 | - ), |
|
175 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
176 | - 'post_excerpt', |
|
177 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
178 | - true, |
|
179 | - esc_html__('No Biography Provided', 'event_espresso') |
|
180 | - ), |
|
181 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
182 | - 'post_modified', |
|
183 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
184 | - ), |
|
185 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
186 | - 'post_author', |
|
187 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
188 | - false |
|
189 | - ), |
|
190 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
191 | - 'post_parent', |
|
192 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
193 | - false, |
|
194 | - 0 |
|
195 | - ), |
|
196 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
197 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
198 | - 'post_status', |
|
199 | - esc_html__('Attendee Status', 'event_espresso'), |
|
200 | - false, |
|
201 | - 'publish' |
|
202 | - ), |
|
203 | - 'password' => new EE_Password_Field( |
|
204 | - 'post_password', |
|
205 | - __('Password', 'event_espresso'), |
|
206 | - false, |
|
207 | - '', |
|
208 | - array( |
|
209 | - 'ATT_bio', |
|
210 | - 'ATT_short_bio', |
|
211 | - 'ATT_address', |
|
212 | - 'ATT_address2', |
|
213 | - 'ATT_city', |
|
214 | - 'STA_ID', |
|
215 | - 'CNT_ISO', |
|
216 | - 'ATT_zip', |
|
217 | - 'ATT_email', |
|
218 | - 'ATT_phone' |
|
219 | - ) |
|
220 | - ) |
|
221 | - ), |
|
222 | - 'Attendee_Meta' => array( |
|
223 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
224 | - 'ATTM_ID', |
|
225 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
226 | - false |
|
227 | - ), |
|
228 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
229 | - 'ATT_ID', |
|
230 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
231 | - false |
|
232 | - ), |
|
233 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
234 | - 'ATT_fname', |
|
235 | - esc_html__('First Name', 'event_espresso') |
|
236 | - ), |
|
237 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
238 | - 'ATT_lname', |
|
239 | - esc_html__('Last Name', 'event_espresso') |
|
240 | - ), |
|
241 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
242 | - 'ATT_address', |
|
243 | - esc_html__('Address Part 1', 'event_espresso') |
|
244 | - ), |
|
245 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
246 | - 'ATT_address2', |
|
247 | - esc_html__('Address Part 2', 'event_espresso') |
|
248 | - ), |
|
249 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
250 | - 'ATT_city', |
|
251 | - esc_html__('City', 'event_espresso') |
|
252 | - ), |
|
253 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
254 | - 'STA_ID', |
|
255 | - esc_html__('State', 'event_espresso'), |
|
256 | - true, |
|
257 | - 0, |
|
258 | - 'State' |
|
259 | - ), |
|
260 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
261 | - 'CNT_ISO', |
|
262 | - esc_html__('Country', 'event_espresso'), |
|
263 | - true, |
|
264 | - '', |
|
265 | - 'Country' |
|
266 | - ), |
|
267 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
268 | - 'ATT_zip', |
|
269 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
270 | - ), |
|
271 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
272 | - 'ATT_email', |
|
273 | - esc_html__('Email Address', 'event_espresso') |
|
274 | - ), |
|
275 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
276 | - 'ATT_phone', |
|
277 | - esc_html__('Phone', 'event_espresso') |
|
278 | - ), |
|
279 | - ), |
|
280 | - ); |
|
281 | - $this->_model_relations = array( |
|
282 | - 'Registration' => new EE_Has_Many_Relation(), |
|
283 | - 'State' => new EE_Belongs_To_Relation(), |
|
284 | - 'Country' => new EE_Belongs_To_Relation(), |
|
285 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
286 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
287 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
288 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
289 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
290 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
291 | - ); |
|
292 | - $this->_caps_slug = 'contacts'; |
|
293 | - $this->model_chain_to_password = ''; |
|
294 | - parent::__construct($timezone); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
301 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
302 | - * |
|
303 | - * @param string $system_question_string |
|
304 | - * @return string|null if not found |
|
305 | - */ |
|
306 | - public function get_attendee_field_for_system_question($system_question_string) |
|
307 | - { |
|
308 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
309 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
310 | - : null; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
317 | - * |
|
318 | - * @return array |
|
319 | - */ |
|
320 | - public function system_question_to_attendee_field_mapping() |
|
321 | - { |
|
322 | - return $this->_system_question_to_attendee_field_name; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
329 | - * |
|
330 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
331 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
332 | - * @throws EE_Error |
|
333 | - */ |
|
334 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
335 | - { |
|
336 | - return $this->get_all( |
|
337 | - array( |
|
338 | - array( |
|
339 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
340 | - ? $transaction_id_or_obj->ID() |
|
341 | - : $transaction_id_or_obj, |
|
342 | - ), |
|
343 | - ) |
|
344 | - ); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * retrieve a single attendee from db via their ID |
|
351 | - * |
|
352 | - * @param $ATT_ID |
|
353 | - * @return mixed array on success, FALSE on fail |
|
354 | - * @deprecated |
|
355 | - */ |
|
356 | - public function get_attendee_by_ID($ATT_ID = false) |
|
357 | - { |
|
358 | - // retrieve a particular EE_Attendee |
|
359 | - return $this->get_one_by_ID($ATT_ID); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * retrieve a single attendee from db via their ID |
|
366 | - * |
|
367 | - * @param array $where_cols_n_values |
|
368 | - * @return mixed array on success, FALSE on fail |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - public function get_attendee($where_cols_n_values = array()) |
|
372 | - { |
|
373 | - if (empty($where_cols_n_values)) { |
|
374 | - return false; |
|
375 | - } |
|
376 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
377 | - if (! empty($attendee)) { |
|
378 | - return array_shift($attendee); |
|
379 | - } |
|
380 | - return false; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Search for an existing Attendee record in the DB |
|
387 | - * |
|
388 | - * @param array $where_cols_n_values |
|
389 | - * @return bool|mixed |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function find_existing_attendee($where_cols_n_values = null) |
|
393 | - { |
|
394 | - // search by combo of first and last names plus the email address |
|
395 | - $attendee_data_keys = array( |
|
396 | - 'ATT_fname' => $this->_ATT_fname, |
|
397 | - 'ATT_lname' => $this->_ATT_lname, |
|
398 | - 'ATT_email' => $this->_ATT_email, |
|
399 | - ); |
|
400 | - // no search params means attendee object already exists. |
|
401 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
402 | - ? $where_cols_n_values |
|
403 | - : $attendee_data_keys; |
|
404 | - $valid_data = true; |
|
405 | - // check for required values |
|
406 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
407 | - ? $valid_data |
|
408 | - : false; |
|
409 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
410 | - ? $valid_data |
|
411 | - : false; |
|
412 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
413 | - ? $valid_data |
|
414 | - : false; |
|
415 | - if ($valid_data) { |
|
416 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
417 | - if ($attendee instanceof EE_Attendee) { |
|
418 | - return $attendee; |
|
419 | - } |
|
420 | - } |
|
421 | - return false; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Takes an incoming array of EE_Registration ids |
|
428 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
429 | - * |
|
430 | - * @since 4.3.0 |
|
431 | - * @param array $ids array of EE_Registration ids |
|
432 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
433 | - * @throws EE_Error |
|
434 | - */ |
|
435 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
436 | - { |
|
437 | - $ids = (array) $ids; |
|
438 | - $_where = array( |
|
439 | - 'Registration.REG_ID' => array('in', $ids), |
|
440 | - ); |
|
441 | - return $this->get_all(array($_where)); |
|
442 | - } |
|
50 | + |
|
51 | + /** |
|
52 | + * @deprecated |
|
53 | + */ |
|
54 | + const city_question_id = 6; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @deprecated |
|
59 | + */ |
|
60 | + const state_question_id = 7; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @deprecated |
|
65 | + */ |
|
66 | + const country_question_id = 8; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @deprecated |
|
71 | + */ |
|
72 | + const zip_question_id = 9; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @deprecated |
|
77 | + */ |
|
78 | + const phone_question_id = 10; |
|
79 | + |
|
80 | + /** |
|
81 | + * When looking for questions that correspond to attendee fields, |
|
82 | + * look for the question with this QST_system value. |
|
83 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
84 | + */ |
|
85 | + const system_question_fname = 'fname'; |
|
86 | + |
|
87 | + const system_question_lname = 'lname'; |
|
88 | + |
|
89 | + const system_question_email = 'email'; |
|
90 | + |
|
91 | + const system_question_email_confirm = 'email_confirm'; |
|
92 | + |
|
93 | + const system_question_address = 'address'; |
|
94 | + |
|
95 | + const system_question_address2 = 'address2'; |
|
96 | + |
|
97 | + const system_question_city = 'city'; |
|
98 | + |
|
99 | + const system_question_state = 'state'; |
|
100 | + |
|
101 | + const system_question_country = 'country'; |
|
102 | + |
|
103 | + const system_question_zip = 'zip'; |
|
104 | + |
|
105 | + const system_question_phone = 'phone'; |
|
106 | + |
|
107 | + /** |
|
108 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
109 | + * also all the values of QST_system in the questions table, and values |
|
110 | + * are their corresponding Attendee field names |
|
111 | + * |
|
112 | + * @var array |
|
113 | + */ |
|
114 | + protected $_system_question_to_attendee_field_name = array( |
|
115 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
116 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
117 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
118 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
119 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
120 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
121 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
122 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
123 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
124 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
125 | + ); |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * EEM_Attendee constructor. |
|
131 | + * |
|
132 | + * @param null $timezone |
|
133 | + * @param ModelFieldFactory $model_field_factory |
|
134 | + * @throws EE_Error |
|
135 | + * @throws InvalidArgumentException |
|
136 | + */ |
|
137 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
138 | + { |
|
139 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
140 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
141 | + $this->_tables = array( |
|
142 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
143 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
144 | + 'esp_attendee_meta', |
|
145 | + 'ATTM_ID', |
|
146 | + 'ATT_ID' |
|
147 | + ), |
|
148 | + ); |
|
149 | + $this->_fields = array( |
|
150 | + 'Attendee_CPT' => array( |
|
151 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
152 | + 'ID', |
|
153 | + esc_html__('Attendee ID', 'event_espresso') |
|
154 | + ), |
|
155 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
156 | + 'post_title', |
|
157 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
158 | + false, |
|
159 | + esc_html__('Unknown', 'event_espresso') |
|
160 | + ), |
|
161 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
162 | + 'post_content', |
|
163 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
164 | + false, |
|
165 | + esc_html__('No Biography Provided', 'event_espresso') |
|
166 | + ), |
|
167 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
168 | + 'post_name', |
|
169 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
170 | + ), |
|
171 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
172 | + 'post_date', |
|
173 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
174 | + ), |
|
175 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
176 | + 'post_excerpt', |
|
177 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
178 | + true, |
|
179 | + esc_html__('No Biography Provided', 'event_espresso') |
|
180 | + ), |
|
181 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
182 | + 'post_modified', |
|
183 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
184 | + ), |
|
185 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
186 | + 'post_author', |
|
187 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
188 | + false |
|
189 | + ), |
|
190 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
191 | + 'post_parent', |
|
192 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
193 | + false, |
|
194 | + 0 |
|
195 | + ), |
|
196 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
197 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
198 | + 'post_status', |
|
199 | + esc_html__('Attendee Status', 'event_espresso'), |
|
200 | + false, |
|
201 | + 'publish' |
|
202 | + ), |
|
203 | + 'password' => new EE_Password_Field( |
|
204 | + 'post_password', |
|
205 | + __('Password', 'event_espresso'), |
|
206 | + false, |
|
207 | + '', |
|
208 | + array( |
|
209 | + 'ATT_bio', |
|
210 | + 'ATT_short_bio', |
|
211 | + 'ATT_address', |
|
212 | + 'ATT_address2', |
|
213 | + 'ATT_city', |
|
214 | + 'STA_ID', |
|
215 | + 'CNT_ISO', |
|
216 | + 'ATT_zip', |
|
217 | + 'ATT_email', |
|
218 | + 'ATT_phone' |
|
219 | + ) |
|
220 | + ) |
|
221 | + ), |
|
222 | + 'Attendee_Meta' => array( |
|
223 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
224 | + 'ATTM_ID', |
|
225 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
226 | + false |
|
227 | + ), |
|
228 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
229 | + 'ATT_ID', |
|
230 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
231 | + false |
|
232 | + ), |
|
233 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
234 | + 'ATT_fname', |
|
235 | + esc_html__('First Name', 'event_espresso') |
|
236 | + ), |
|
237 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
238 | + 'ATT_lname', |
|
239 | + esc_html__('Last Name', 'event_espresso') |
|
240 | + ), |
|
241 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
242 | + 'ATT_address', |
|
243 | + esc_html__('Address Part 1', 'event_espresso') |
|
244 | + ), |
|
245 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
246 | + 'ATT_address2', |
|
247 | + esc_html__('Address Part 2', 'event_espresso') |
|
248 | + ), |
|
249 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
250 | + 'ATT_city', |
|
251 | + esc_html__('City', 'event_espresso') |
|
252 | + ), |
|
253 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
254 | + 'STA_ID', |
|
255 | + esc_html__('State', 'event_espresso'), |
|
256 | + true, |
|
257 | + 0, |
|
258 | + 'State' |
|
259 | + ), |
|
260 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
261 | + 'CNT_ISO', |
|
262 | + esc_html__('Country', 'event_espresso'), |
|
263 | + true, |
|
264 | + '', |
|
265 | + 'Country' |
|
266 | + ), |
|
267 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
268 | + 'ATT_zip', |
|
269 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
270 | + ), |
|
271 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
272 | + 'ATT_email', |
|
273 | + esc_html__('Email Address', 'event_espresso') |
|
274 | + ), |
|
275 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
276 | + 'ATT_phone', |
|
277 | + esc_html__('Phone', 'event_espresso') |
|
278 | + ), |
|
279 | + ), |
|
280 | + ); |
|
281 | + $this->_model_relations = array( |
|
282 | + 'Registration' => new EE_Has_Many_Relation(), |
|
283 | + 'State' => new EE_Belongs_To_Relation(), |
|
284 | + 'Country' => new EE_Belongs_To_Relation(), |
|
285 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
286 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
287 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
288 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
289 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
290 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
291 | + ); |
|
292 | + $this->_caps_slug = 'contacts'; |
|
293 | + $this->model_chain_to_password = ''; |
|
294 | + parent::__construct($timezone); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
301 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
302 | + * |
|
303 | + * @param string $system_question_string |
|
304 | + * @return string|null if not found |
|
305 | + */ |
|
306 | + public function get_attendee_field_for_system_question($system_question_string) |
|
307 | + { |
|
308 | + return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
309 | + ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
310 | + : null; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
317 | + * |
|
318 | + * @return array |
|
319 | + */ |
|
320 | + public function system_question_to_attendee_field_mapping() |
|
321 | + { |
|
322 | + return $this->_system_question_to_attendee_field_name; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
329 | + * |
|
330 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
331 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
332 | + * @throws EE_Error |
|
333 | + */ |
|
334 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
335 | + { |
|
336 | + return $this->get_all( |
|
337 | + array( |
|
338 | + array( |
|
339 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
340 | + ? $transaction_id_or_obj->ID() |
|
341 | + : $transaction_id_or_obj, |
|
342 | + ), |
|
343 | + ) |
|
344 | + ); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * retrieve a single attendee from db via their ID |
|
351 | + * |
|
352 | + * @param $ATT_ID |
|
353 | + * @return mixed array on success, FALSE on fail |
|
354 | + * @deprecated |
|
355 | + */ |
|
356 | + public function get_attendee_by_ID($ATT_ID = false) |
|
357 | + { |
|
358 | + // retrieve a particular EE_Attendee |
|
359 | + return $this->get_one_by_ID($ATT_ID); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * retrieve a single attendee from db via their ID |
|
366 | + * |
|
367 | + * @param array $where_cols_n_values |
|
368 | + * @return mixed array on success, FALSE on fail |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + public function get_attendee($where_cols_n_values = array()) |
|
372 | + { |
|
373 | + if (empty($where_cols_n_values)) { |
|
374 | + return false; |
|
375 | + } |
|
376 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
377 | + if (! empty($attendee)) { |
|
378 | + return array_shift($attendee); |
|
379 | + } |
|
380 | + return false; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Search for an existing Attendee record in the DB |
|
387 | + * |
|
388 | + * @param array $where_cols_n_values |
|
389 | + * @return bool|mixed |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function find_existing_attendee($where_cols_n_values = null) |
|
393 | + { |
|
394 | + // search by combo of first and last names plus the email address |
|
395 | + $attendee_data_keys = array( |
|
396 | + 'ATT_fname' => $this->_ATT_fname, |
|
397 | + 'ATT_lname' => $this->_ATT_lname, |
|
398 | + 'ATT_email' => $this->_ATT_email, |
|
399 | + ); |
|
400 | + // no search params means attendee object already exists. |
|
401 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
402 | + ? $where_cols_n_values |
|
403 | + : $attendee_data_keys; |
|
404 | + $valid_data = true; |
|
405 | + // check for required values |
|
406 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
407 | + ? $valid_data |
|
408 | + : false; |
|
409 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
410 | + ? $valid_data |
|
411 | + : false; |
|
412 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
413 | + ? $valid_data |
|
414 | + : false; |
|
415 | + if ($valid_data) { |
|
416 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
417 | + if ($attendee instanceof EE_Attendee) { |
|
418 | + return $attendee; |
|
419 | + } |
|
420 | + } |
|
421 | + return false; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Takes an incoming array of EE_Registration ids |
|
428 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
429 | + * |
|
430 | + * @since 4.3.0 |
|
431 | + * @param array $ids array of EE_Registration ids |
|
432 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
433 | + * @throws EE_Error |
|
434 | + */ |
|
435 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
436 | + { |
|
437 | + $ids = (array) $ids; |
|
438 | + $_where = array( |
|
439 | + 'Registration.REG_ID' => array('in', $ids), |
|
440 | + ); |
|
441 | + return $this->get_all(array($_where)); |
|
442 | + } |
|
443 | 443 | } |
@@ -10,29 +10,29 @@ |
||
10 | 10 | class EE_Email_Confirm_Input extends EE_Form_Input_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - */ |
|
16 | - public function __construct($input_settings = array()) |
|
17 | - { |
|
18 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | - $this->_add_validation_strategy( |
|
21 | - new EE_Email_Validation_Strategy( |
|
22 | - isset($input_settings['validation_error_message']) |
|
23 | - ? $input_settings['validation_error_message'] |
|
24 | - : null |
|
25 | - ) |
|
26 | - ); |
|
27 | - $this->_add_validation_strategy( |
|
28 | - new EE_Equal_To_Validation_Strategy( |
|
29 | - isset($input_settings['validation_error_message']) |
|
30 | - ? $input_settings['validation_error_message'] |
|
31 | - : null, |
|
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | - ) |
|
34 | - ); |
|
35 | - parent::__construct($input_settings); |
|
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
37 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + */ |
|
16 | + public function __construct($input_settings = array()) |
|
17 | + { |
|
18 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | + $this->_add_validation_strategy( |
|
21 | + new EE_Email_Validation_Strategy( |
|
22 | + isset($input_settings['validation_error_message']) |
|
23 | + ? $input_settings['validation_error_message'] |
|
24 | + : null |
|
25 | + ) |
|
26 | + ); |
|
27 | + $this->_add_validation_strategy( |
|
28 | + new EE_Equal_To_Validation_Strategy( |
|
29 | + isset($input_settings['validation_error_message']) |
|
30 | + ? $input_settings['validation_error_message'] |
|
31 | + : null, |
|
32 | + '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | + ) |
|
34 | + ); |
|
35 | + parent::__construct($input_settings); |
|
36 | + $this->set_html_class($this->html_class() . ' email'); |
|
37 | + } |
|
38 | 38 | } |
@@ -29,10 +29,10 @@ |
||
29 | 29 | isset($input_settings['validation_error_message']) |
30 | 30 | ? $input_settings['validation_error_message'] |
31 | 31 | : null, |
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
32 | + '#'.str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | 33 | ) |
34 | 34 | ); |
35 | 35 | parent::__construct($input_settings); |
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
36 | + $this->set_html_class($this->html_class().' email'); |
|
37 | 37 | } |
38 | 38 | } |
@@ -15,49 +15,49 @@ |
||
15 | 15 | class EE_Equal_To_Validation_Strategy extends EE_Text_Validation_Strategy |
16 | 16 | { |
17 | 17 | |
18 | - protected $_compare_to = null; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * @param string $validation_error_message |
|
23 | - */ |
|
24 | - public function __construct($validation_error_message = '', $compare_to) |
|
25 | - { |
|
26 | - if (! $validation_error_message) { |
|
27 | - $validation_error_message = apply_filters( |
|
28 | - 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
29 | - esc_html__('Fields do not match.', 'event_espresso') |
|
30 | - ); |
|
31 | - } |
|
32 | - parent::__construct($validation_error_message); |
|
33 | - $this->_compare_to = $compare_to; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * just checks the field isn't blank |
|
40 | - * |
|
41 | - * @param $normalized_value |
|
42 | - * @return bool |
|
43 | - * @throws InvalidArgumentException |
|
44 | - * @throws InvalidInterfaceException |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - * @throws EE_Validation_Error |
|
47 | - */ |
|
48 | - public function validate($normalized_value) |
|
49 | - { |
|
50 | - // No need to be validated |
|
51 | - return true; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function get_jquery_validation_rule_array() |
|
60 | - { |
|
61 | - return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
62 | - } |
|
18 | + protected $_compare_to = null; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * @param string $validation_error_message |
|
23 | + */ |
|
24 | + public function __construct($validation_error_message = '', $compare_to) |
|
25 | + { |
|
26 | + if (! $validation_error_message) { |
|
27 | + $validation_error_message = apply_filters( |
|
28 | + 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
29 | + esc_html__('Fields do not match.', 'event_espresso') |
|
30 | + ); |
|
31 | + } |
|
32 | + parent::__construct($validation_error_message); |
|
33 | + $this->_compare_to = $compare_to; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * just checks the field isn't blank |
|
40 | + * |
|
41 | + * @param $normalized_value |
|
42 | + * @return bool |
|
43 | + * @throws InvalidArgumentException |
|
44 | + * @throws InvalidInterfaceException |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + * @throws EE_Validation_Error |
|
47 | + */ |
|
48 | + public function validate($normalized_value) |
|
49 | + { |
|
50 | + // No need to be validated |
|
51 | + return true; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function get_jquery_validation_rule_array() |
|
60 | + { |
|
61 | + return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
62 | + } |
|
63 | 63 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct($validation_error_message = '', $compare_to) |
25 | 25 | { |
26 | - if (! $validation_error_message) { |
|
26 | + if ( ! $validation_error_message) { |
|
27 | 27 | $validation_error_message = apply_filters( |
28 | 28 | 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
29 | 29 | esc_html__('Fields do not match.', 'event_espresso') |
@@ -14,665 +14,665 @@ |
||
14 | 14 | class EE_Question extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * |
|
19 | - * @param array $props_n_values incoming values |
|
20 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
21 | - * used.) |
|
22 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
23 | - * date_format and the second value is the time format |
|
24 | - * @return EE_Question |
|
25 | - */ |
|
26 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
27 | - { |
|
28 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
29 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @param array $props_n_values incoming values from the database |
|
35 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
36 | - * the website will be used. |
|
37 | - * @return EE_Question |
|
38 | - */ |
|
39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
40 | - { |
|
41 | - return new self($props_n_values, true, $timezone); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Set Question display text |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @param string $QST_display_text |
|
50 | - */ |
|
51 | - public function set_display_text($QST_display_text = '') |
|
52 | - { |
|
53 | - $this->set('QST_display_text', $QST_display_text); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Set Question admin text |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @param string $QST_admin_label |
|
62 | - */ |
|
63 | - public function set_admin_label($QST_admin_label = '') |
|
64 | - { |
|
65 | - $this->set('QST_admin_label', $QST_admin_label); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Set system name |
|
71 | - * |
|
72 | - * @access public |
|
73 | - * @param mixed $QST_system |
|
74 | - */ |
|
75 | - public function set_system_ID($QST_system = '') |
|
76 | - { |
|
77 | - $this->set('QST_system', $QST_system); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Set question's type |
|
83 | - * |
|
84 | - * @access public |
|
85 | - * @param string $QST_type |
|
86 | - */ |
|
87 | - public function set_question_type($QST_type = '') |
|
88 | - { |
|
89 | - $this->set('QST_type', $QST_type); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets whether this question must be answered when presented in a form |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @param bool $QST_required |
|
98 | - */ |
|
99 | - public function set_required($QST_required = false) |
|
100 | - { |
|
101 | - $this->set('QST_required', $QST_required); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Set Question display text |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * @param string $QST_required_text |
|
110 | - */ |
|
111 | - public function set_required_text($QST_required_text = '') |
|
112 | - { |
|
113 | - $this->set('QST_required_text', $QST_required_text); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Sets the order of this question when placed in a sequence of questions |
|
119 | - * |
|
120 | - * @access public |
|
121 | - * @param int $QST_order |
|
122 | - */ |
|
123 | - public function set_order($QST_order = 0) |
|
124 | - { |
|
125 | - $this->set('QST_order', $QST_order); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Sets whether the question is admin-only |
|
131 | - * |
|
132 | - * @access public |
|
133 | - * @param bool $QST_admin_only |
|
134 | - */ |
|
135 | - public function set_admin_only($QST_admin_only = false) |
|
136 | - { |
|
137 | - $this->set('QST_admin_only', $QST_admin_only); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Sets the wordpress user ID on the question |
|
143 | - * |
|
144 | - * @access public |
|
145 | - * @param int $QST_wp_user |
|
146 | - */ |
|
147 | - public function set_wp_user($QST_wp_user = 1) |
|
148 | - { |
|
149 | - $this->set('QST_wp_user', $QST_wp_user); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * Sets whether the question has been deleted |
|
155 | - * (we use this boolean instead of actually |
|
156 | - * deleting it because when users delete this question |
|
157 | - * they really want to remove the question from future |
|
158 | - * forms, BUT keep their old answers which depend |
|
159 | - * on this record actually existing. |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @param bool $QST_deleted |
|
163 | - */ |
|
164 | - public function set_deleted($QST_deleted = false) |
|
165 | - { |
|
166 | - $this->set('QST_deleted', $QST_deleted); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * returns the text for displaying the question to users |
|
172 | - * |
|
173 | - * @access public |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function display_text() |
|
177 | - { |
|
178 | - return $this->get('QST_display_text'); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * returns the text for the administrative label |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function admin_label() |
|
189 | - { |
|
190 | - return $this->get('QST_admin_label'); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * returns the attendee column name for this question |
|
196 | - * |
|
197 | - * @access public |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - public function system_ID() |
|
201 | - { |
|
202 | - return $this->get('QST_system'); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * returns either a string of 'text', 'textfield', etc. |
|
208 | - * |
|
209 | - * @access public |
|
210 | - * @return boolean |
|
211 | - */ |
|
212 | - public function required() |
|
213 | - { |
|
214 | - return $this->get('QST_required'); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * returns the text which should be displayed when a user |
|
220 | - * doesn't answer this question in a form |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function required_text() |
|
226 | - { |
|
227 | - return $this->get('QST_required_text'); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * returns the type of this question |
|
233 | - * |
|
234 | - * @access public |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public function type() |
|
238 | - { |
|
239 | - return $this->get('QST_type'); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * returns an integer showing where this question should |
|
245 | - * be placed in a sequence of questions |
|
246 | - * |
|
247 | - * @access public |
|
248 | - * @return int |
|
249 | - */ |
|
250 | - public function order() |
|
251 | - { |
|
252 | - return $this->get('QST_order'); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * returns whether this question should only appears to admins, |
|
258 | - * or to everyone |
|
259 | - * |
|
260 | - * @access public |
|
261 | - * @return boolean |
|
262 | - */ |
|
263 | - public function admin_only() |
|
264 | - { |
|
265 | - return $this->get('QST_admin_only'); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * returns the id the wordpress user who created this question |
|
271 | - * |
|
272 | - * @access public |
|
273 | - * @return int |
|
274 | - */ |
|
275 | - public function wp_user() |
|
276 | - { |
|
277 | - return $this->get('QST_wp_user'); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * returns whether this question has been marked as 'deleted' |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @return boolean |
|
286 | - */ |
|
287 | - public function deleted() |
|
288 | - { |
|
289 | - return $this->get('QST_deleted'); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Gets an array of related EE_Answer to this EE_Question |
|
295 | - * |
|
296 | - * @return EE_Answer[] |
|
297 | - */ |
|
298 | - public function answers() |
|
299 | - { |
|
300 | - return $this->get_many_related('Answer'); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Boolean check for if there are answers on this question in th db |
|
306 | - * |
|
307 | - * @return boolean true = has answers, false = no answers. |
|
308 | - */ |
|
309 | - public function has_answers() |
|
310 | - { |
|
311 | - return $this->count_related('Answer') > 0 ? true : false; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * gets an array of EE_Question_Group which relate to this question |
|
317 | - * |
|
318 | - * @return EE_Question_Group[] |
|
319 | - */ |
|
320 | - public function question_groups() |
|
321 | - { |
|
322 | - return $this->get_many_related('Question_Group'); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Returns all the options for this question. By default, it returns only the not-yet-deleted ones. |
|
328 | - * |
|
329 | - * @param boolean $notDeletedOptionsOnly 1 |
|
330 | - * whether to return ALL options, or only the ones which have |
|
331 | - * not yet been deleleted |
|
332 | - * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question, |
|
333 | - * we want to usually only show non-deleted options AND the |
|
334 | - * value that was selected for the answer, whether it was |
|
335 | - * trashed or not. |
|
336 | - * @return EE_Question_Option[] |
|
337 | - */ |
|
338 | - public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
|
339 | - { |
|
340 | - if (! $this->ID()) { |
|
341 | - return array(); |
|
342 | - } |
|
343 | - $query_params = array(); |
|
344 | - if ($selected_value_to_always_include) { |
|
345 | - if (is_array($selected_value_to_always_include)) { |
|
346 | - $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
347 | - } else { |
|
348 | - $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
349 | - } |
|
350 | - } |
|
351 | - if ($notDeletedOptionsOnly) { |
|
352 | - $query_params[0]['OR*options-query']['QSO_deleted'] = false; |
|
353 | - } |
|
354 | - // order by QSO_order |
|
355 | - $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
356 | - return $this->get_many_related('Question_Option', $query_params); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * returns an array of EE_Question_Options which relate to this question |
|
362 | - * |
|
363 | - * @return \EE_Question_Option[] |
|
364 | - */ |
|
365 | - public function temp_options() |
|
366 | - { |
|
367 | - return $this->_model_relations['Question_Option']; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * Adds an option for this question. Note: if the option were previously associated with a different |
|
373 | - * Question, that relationship will be overwritten. |
|
374 | - * |
|
375 | - * @param EE_Question_Option $option |
|
376 | - * @return boolean success |
|
377 | - */ |
|
378 | - public function add_option(EE_Question_Option $option) |
|
379 | - { |
|
380 | - return $this->_add_relation_to($option, 'Question_Option'); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * Adds an option directly to this question without saving to the db |
|
386 | - * |
|
387 | - * @param EE_Question_Option $option |
|
388 | - * @return boolean success |
|
389 | - */ |
|
390 | - public function add_temp_option(EE_Question_Option $option) |
|
391 | - { |
|
392 | - $this->_model_relations['Question_Option'][] = $option; |
|
393 | - return true; |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * Marks the option as deleted. |
|
399 | - * |
|
400 | - * @param EE_Question_Option $option |
|
401 | - * @return boolean success |
|
402 | - */ |
|
403 | - public function remove_option(EE_Question_Option $option) |
|
404 | - { |
|
405 | - return $this->_remove_relation_to($option, 'Question_Option'); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * @return bool |
|
411 | - */ |
|
412 | - public function is_system_question() |
|
413 | - { |
|
414 | - $system_ID = $this->get('QST_system'); |
|
415 | - return ! empty($system_ID) ? true : false; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * The purpose of this method is set the question order this question order to be the max out of all questions |
|
421 | - * |
|
422 | - * @access public |
|
423 | - * @return void |
|
424 | - */ |
|
425 | - public function set_order_to_latest() |
|
426 | - { |
|
427 | - $latest_order = $this->get_model()->get_latest_question_order(); |
|
428 | - $latest_order++; |
|
429 | - $this->set('QST_order', $latest_order); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Retrieves the list of allowed question types from the model. |
|
435 | - * |
|
436 | - * @return string[] |
|
437 | - */ |
|
438 | - private function _allowed_question_types() |
|
439 | - { |
|
440 | - $questionModel = $this->get_model(); |
|
441 | - /* @var $questionModel EEM_Question */ |
|
442 | - return $questionModel->allowed_question_types(); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Duplicates this question and its question options |
|
447 | - * |
|
448 | - * @return \EE_Question |
|
449 | - */ |
|
450 | - public function duplicate($options = array()) |
|
451 | - { |
|
452 | - $new_question = clone $this; |
|
453 | - $new_question->set('QST_ID', null); |
|
454 | - $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
455 | - $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
456 | - $new_question->set_system_ID(null); |
|
457 | - $new_question->set_wp_user(get_current_user_id()); |
|
458 | - // if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
459 | - $new_question->set_deleted(false); |
|
460 | - $success = $new_question->save(); |
|
461 | - if ($success) { |
|
462 | - // we don't totally want to duplicate the question options, because we want them to be for the NEW question |
|
463 | - foreach ($this->options() as $question_option) { |
|
464 | - $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
465 | - } |
|
466 | - return $new_question; |
|
467 | - } else { |
|
468 | - return null; |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Returns the question's maximum allowed response size |
|
474 | - * |
|
475 | - * @return int|float |
|
476 | - */ |
|
477 | - public function max() |
|
478 | - { |
|
479 | - return $this->get('QST_max'); |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Sets the question's maximum allowed response size |
|
484 | - * |
|
485 | - * @param int|float $new_max |
|
486 | - * @return void |
|
487 | - */ |
|
488 | - public function set_max($new_max) |
|
489 | - { |
|
490 | - $this->set('QST_max', $new_max); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Creates a form input from this question which can be used in HTML forms |
|
496 | - * |
|
497 | - * @param EE_Registration $registration |
|
498 | - * @param EE_Answer $answer |
|
499 | - * @param array $input_constructor_args |
|
500 | - * @return EE_Form_Input_Base |
|
501 | - */ |
|
502 | - public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) |
|
503 | - { |
|
504 | - $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
|
505 | - |
|
506 | - $input_constructor_args = array_merge( |
|
507 | - array( |
|
508 | - 'required' => $this->required() ? true : false, |
|
509 | - 'html_label_text' => $this->display_text(), |
|
510 | - 'required_validation_error_message' => $this->required_text(), |
|
511 | - ), |
|
512 | - $input_constructor_args |
|
513 | - ); |
|
514 | - if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
515 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
516 | - } |
|
517 | - // has this question been answered ? |
|
518 | - if ($answer instanceof EE_Answer |
|
519 | - && $answer->value() !== '' |
|
520 | - ) { |
|
521 | - // answer gets htmlspecialchars called on it, undo that please |
|
522 | - // because the form input's display strategy may call esc_attr too |
|
523 | - // which also does html special characters |
|
524 | - $values_with_html_special_chars = $answer->value(); |
|
525 | - if (is_array($values_with_html_special_chars)) { |
|
526 | - $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
527 | - } else { |
|
528 | - $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
529 | - } |
|
530 | - $input_constructor_args['default'] = $default_value; |
|
531 | - } |
|
532 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
533 | - if (in_array( |
|
534 | - $this->type(), |
|
535 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
536 | - true |
|
537 | - )) { |
|
538 | - $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
539 | - null, |
|
540 | - min($max_max_for_question, $this->max()) |
|
541 | - ); |
|
542 | - } |
|
543 | - $input_constructor_args = apply_filters( |
|
544 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args', |
|
545 | - $input_constructor_args, |
|
546 | - $registration, |
|
547 | - $this, |
|
548 | - $answer |
|
549 | - ); |
|
550 | - |
|
551 | - $result = null; |
|
552 | - switch ($this->type()) { |
|
553 | - // Text |
|
554 | - case EEM_Question::QST_type_text: |
|
555 | - $result = new EE_Text_Input($input_constructor_args); |
|
556 | - break; |
|
557 | - // Textarea |
|
558 | - case EEM_Question::QST_type_textarea: |
|
559 | - $result = new EE_Text_Area_Input($input_constructor_args); |
|
560 | - break; |
|
561 | - // Radio Buttons |
|
562 | - case EEM_Question::QST_type_radio: |
|
563 | - $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
564 | - break; |
|
565 | - // Dropdown |
|
566 | - case EEM_Question::QST_type_dropdown: |
|
567 | - $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
568 | - break; |
|
569 | - // State Dropdown |
|
570 | - case EEM_Question::QST_type_state: |
|
571 | - $state_options = apply_filters( |
|
572 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
573 | - null, |
|
574 | - $this, |
|
575 | - $registration, |
|
576 | - $answer |
|
577 | - ); |
|
578 | - $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
579 | - break; |
|
580 | - // Country Dropdown |
|
581 | - case EEM_Question::QST_type_country: |
|
582 | - $country_options = apply_filters( |
|
583 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
584 | - null, |
|
585 | - $this, |
|
586 | - $registration, |
|
587 | - $answer |
|
588 | - ); |
|
589 | - $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
590 | - break; |
|
591 | - // Checkboxes |
|
592 | - case EEM_Question::QST_type_checkbox: |
|
593 | - $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
594 | - break; |
|
595 | - // Date |
|
596 | - case EEM_Question::QST_type_date: |
|
597 | - $result = new EE_Datepicker_Input($input_constructor_args); |
|
598 | - break; |
|
599 | - case EEM_Question::QST_type_html_textarea: |
|
600 | - $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
601 | - $result = new EE_Text_Area_Input($input_constructor_args); |
|
602 | - $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
603 | - break; |
|
604 | - case EEM_Question::QST_type_email: |
|
605 | - $result = new EE_Email_Input($input_constructor_args); |
|
606 | - break; |
|
607 | - // Email confirm |
|
608 | - case EEM_Question::QST_type_email_confirm: |
|
609 | - $result = new EE_Email_Confirm_Input($input_constructor_args); |
|
610 | - break; |
|
611 | - case EEM_Question::QST_type_us_phone: |
|
612 | - $result = new EE_Phone_Input($input_constructor_args); |
|
613 | - break; |
|
614 | - case EEM_Question::QST_type_int: |
|
615 | - $result = new EE_Integer_Input($input_constructor_args); |
|
616 | - break; |
|
617 | - case EEM_Question::QST_type_decimal: |
|
618 | - $result = new EE_Float_Input($input_constructor_args); |
|
619 | - break; |
|
620 | - case EEM_Question::QST_type_url: |
|
621 | - $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy'); |
|
622 | - $result = new EE_Text_Input($input_constructor_args); |
|
623 | - break; |
|
624 | - case EEM_Question::QST_type_year: |
|
625 | - $result = new EE_Year_Input( |
|
626 | - $input_constructor_args, |
|
627 | - apply_filters( |
|
628 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', |
|
629 | - true, |
|
630 | - $this |
|
631 | - ), |
|
632 | - apply_filters( |
|
633 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', |
|
634 | - 100, |
|
635 | - $this |
|
636 | - ), |
|
637 | - apply_filters( |
|
638 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', |
|
639 | - 100, |
|
640 | - $this |
|
641 | - ) |
|
642 | - ); |
|
643 | - break; |
|
644 | - case EEM_Question::QST_type_multi_select: |
|
645 | - $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
646 | - break; |
|
647 | - // fallback |
|
648 | - default: |
|
649 | - $default_input = apply_filters( |
|
650 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', |
|
651 | - null, |
|
652 | - $this->type(), |
|
653 | - $this, |
|
654 | - $input_constructor_args |
|
655 | - ); |
|
656 | - if (! $default_input) { |
|
657 | - $default_input = new EE_Text_Input($input_constructor_args); |
|
658 | - } |
|
659 | - $result = $default_input; |
|
660 | - } |
|
661 | - return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * Returns whether or not this question type should have question option entries |
|
667 | - * |
|
668 | - * @return bool |
|
669 | - */ |
|
670 | - public function should_have_question_options() |
|
671 | - { |
|
672 | - return in_array( |
|
673 | - $this->type(), |
|
674 | - $this->_model->question_types_with_options(), |
|
675 | - true |
|
676 | - ); |
|
677 | - } |
|
17 | + /** |
|
18 | + * |
|
19 | + * @param array $props_n_values incoming values |
|
20 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
21 | + * used.) |
|
22 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
23 | + * date_format and the second value is the time format |
|
24 | + * @return EE_Question |
|
25 | + */ |
|
26 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
27 | + { |
|
28 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
29 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @param array $props_n_values incoming values from the database |
|
35 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
36 | + * the website will be used. |
|
37 | + * @return EE_Question |
|
38 | + */ |
|
39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
40 | + { |
|
41 | + return new self($props_n_values, true, $timezone); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Set Question display text |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @param string $QST_display_text |
|
50 | + */ |
|
51 | + public function set_display_text($QST_display_text = '') |
|
52 | + { |
|
53 | + $this->set('QST_display_text', $QST_display_text); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Set Question admin text |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @param string $QST_admin_label |
|
62 | + */ |
|
63 | + public function set_admin_label($QST_admin_label = '') |
|
64 | + { |
|
65 | + $this->set('QST_admin_label', $QST_admin_label); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Set system name |
|
71 | + * |
|
72 | + * @access public |
|
73 | + * @param mixed $QST_system |
|
74 | + */ |
|
75 | + public function set_system_ID($QST_system = '') |
|
76 | + { |
|
77 | + $this->set('QST_system', $QST_system); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Set question's type |
|
83 | + * |
|
84 | + * @access public |
|
85 | + * @param string $QST_type |
|
86 | + */ |
|
87 | + public function set_question_type($QST_type = '') |
|
88 | + { |
|
89 | + $this->set('QST_type', $QST_type); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Sets whether this question must be answered when presented in a form |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @param bool $QST_required |
|
98 | + */ |
|
99 | + public function set_required($QST_required = false) |
|
100 | + { |
|
101 | + $this->set('QST_required', $QST_required); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Set Question display text |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * @param string $QST_required_text |
|
110 | + */ |
|
111 | + public function set_required_text($QST_required_text = '') |
|
112 | + { |
|
113 | + $this->set('QST_required_text', $QST_required_text); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Sets the order of this question when placed in a sequence of questions |
|
119 | + * |
|
120 | + * @access public |
|
121 | + * @param int $QST_order |
|
122 | + */ |
|
123 | + public function set_order($QST_order = 0) |
|
124 | + { |
|
125 | + $this->set('QST_order', $QST_order); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Sets whether the question is admin-only |
|
131 | + * |
|
132 | + * @access public |
|
133 | + * @param bool $QST_admin_only |
|
134 | + */ |
|
135 | + public function set_admin_only($QST_admin_only = false) |
|
136 | + { |
|
137 | + $this->set('QST_admin_only', $QST_admin_only); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Sets the wordpress user ID on the question |
|
143 | + * |
|
144 | + * @access public |
|
145 | + * @param int $QST_wp_user |
|
146 | + */ |
|
147 | + public function set_wp_user($QST_wp_user = 1) |
|
148 | + { |
|
149 | + $this->set('QST_wp_user', $QST_wp_user); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * Sets whether the question has been deleted |
|
155 | + * (we use this boolean instead of actually |
|
156 | + * deleting it because when users delete this question |
|
157 | + * they really want to remove the question from future |
|
158 | + * forms, BUT keep their old answers which depend |
|
159 | + * on this record actually existing. |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @param bool $QST_deleted |
|
163 | + */ |
|
164 | + public function set_deleted($QST_deleted = false) |
|
165 | + { |
|
166 | + $this->set('QST_deleted', $QST_deleted); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * returns the text for displaying the question to users |
|
172 | + * |
|
173 | + * @access public |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function display_text() |
|
177 | + { |
|
178 | + return $this->get('QST_display_text'); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * returns the text for the administrative label |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function admin_label() |
|
189 | + { |
|
190 | + return $this->get('QST_admin_label'); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * returns the attendee column name for this question |
|
196 | + * |
|
197 | + * @access public |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + public function system_ID() |
|
201 | + { |
|
202 | + return $this->get('QST_system'); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * returns either a string of 'text', 'textfield', etc. |
|
208 | + * |
|
209 | + * @access public |
|
210 | + * @return boolean |
|
211 | + */ |
|
212 | + public function required() |
|
213 | + { |
|
214 | + return $this->get('QST_required'); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * returns the text which should be displayed when a user |
|
220 | + * doesn't answer this question in a form |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function required_text() |
|
226 | + { |
|
227 | + return $this->get('QST_required_text'); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * returns the type of this question |
|
233 | + * |
|
234 | + * @access public |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public function type() |
|
238 | + { |
|
239 | + return $this->get('QST_type'); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * returns an integer showing where this question should |
|
245 | + * be placed in a sequence of questions |
|
246 | + * |
|
247 | + * @access public |
|
248 | + * @return int |
|
249 | + */ |
|
250 | + public function order() |
|
251 | + { |
|
252 | + return $this->get('QST_order'); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * returns whether this question should only appears to admins, |
|
258 | + * or to everyone |
|
259 | + * |
|
260 | + * @access public |
|
261 | + * @return boolean |
|
262 | + */ |
|
263 | + public function admin_only() |
|
264 | + { |
|
265 | + return $this->get('QST_admin_only'); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * returns the id the wordpress user who created this question |
|
271 | + * |
|
272 | + * @access public |
|
273 | + * @return int |
|
274 | + */ |
|
275 | + public function wp_user() |
|
276 | + { |
|
277 | + return $this->get('QST_wp_user'); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * returns whether this question has been marked as 'deleted' |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @return boolean |
|
286 | + */ |
|
287 | + public function deleted() |
|
288 | + { |
|
289 | + return $this->get('QST_deleted'); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Gets an array of related EE_Answer to this EE_Question |
|
295 | + * |
|
296 | + * @return EE_Answer[] |
|
297 | + */ |
|
298 | + public function answers() |
|
299 | + { |
|
300 | + return $this->get_many_related('Answer'); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Boolean check for if there are answers on this question in th db |
|
306 | + * |
|
307 | + * @return boolean true = has answers, false = no answers. |
|
308 | + */ |
|
309 | + public function has_answers() |
|
310 | + { |
|
311 | + return $this->count_related('Answer') > 0 ? true : false; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * gets an array of EE_Question_Group which relate to this question |
|
317 | + * |
|
318 | + * @return EE_Question_Group[] |
|
319 | + */ |
|
320 | + public function question_groups() |
|
321 | + { |
|
322 | + return $this->get_many_related('Question_Group'); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Returns all the options for this question. By default, it returns only the not-yet-deleted ones. |
|
328 | + * |
|
329 | + * @param boolean $notDeletedOptionsOnly 1 |
|
330 | + * whether to return ALL options, or only the ones which have |
|
331 | + * not yet been deleleted |
|
332 | + * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question, |
|
333 | + * we want to usually only show non-deleted options AND the |
|
334 | + * value that was selected for the answer, whether it was |
|
335 | + * trashed or not. |
|
336 | + * @return EE_Question_Option[] |
|
337 | + */ |
|
338 | + public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
|
339 | + { |
|
340 | + if (! $this->ID()) { |
|
341 | + return array(); |
|
342 | + } |
|
343 | + $query_params = array(); |
|
344 | + if ($selected_value_to_always_include) { |
|
345 | + if (is_array($selected_value_to_always_include)) { |
|
346 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
347 | + } else { |
|
348 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
349 | + } |
|
350 | + } |
|
351 | + if ($notDeletedOptionsOnly) { |
|
352 | + $query_params[0]['OR*options-query']['QSO_deleted'] = false; |
|
353 | + } |
|
354 | + // order by QSO_order |
|
355 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
356 | + return $this->get_many_related('Question_Option', $query_params); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * returns an array of EE_Question_Options which relate to this question |
|
362 | + * |
|
363 | + * @return \EE_Question_Option[] |
|
364 | + */ |
|
365 | + public function temp_options() |
|
366 | + { |
|
367 | + return $this->_model_relations['Question_Option']; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * Adds an option for this question. Note: if the option were previously associated with a different |
|
373 | + * Question, that relationship will be overwritten. |
|
374 | + * |
|
375 | + * @param EE_Question_Option $option |
|
376 | + * @return boolean success |
|
377 | + */ |
|
378 | + public function add_option(EE_Question_Option $option) |
|
379 | + { |
|
380 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * Adds an option directly to this question without saving to the db |
|
386 | + * |
|
387 | + * @param EE_Question_Option $option |
|
388 | + * @return boolean success |
|
389 | + */ |
|
390 | + public function add_temp_option(EE_Question_Option $option) |
|
391 | + { |
|
392 | + $this->_model_relations['Question_Option'][] = $option; |
|
393 | + return true; |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * Marks the option as deleted. |
|
399 | + * |
|
400 | + * @param EE_Question_Option $option |
|
401 | + * @return boolean success |
|
402 | + */ |
|
403 | + public function remove_option(EE_Question_Option $option) |
|
404 | + { |
|
405 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * @return bool |
|
411 | + */ |
|
412 | + public function is_system_question() |
|
413 | + { |
|
414 | + $system_ID = $this->get('QST_system'); |
|
415 | + return ! empty($system_ID) ? true : false; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * The purpose of this method is set the question order this question order to be the max out of all questions |
|
421 | + * |
|
422 | + * @access public |
|
423 | + * @return void |
|
424 | + */ |
|
425 | + public function set_order_to_latest() |
|
426 | + { |
|
427 | + $latest_order = $this->get_model()->get_latest_question_order(); |
|
428 | + $latest_order++; |
|
429 | + $this->set('QST_order', $latest_order); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Retrieves the list of allowed question types from the model. |
|
435 | + * |
|
436 | + * @return string[] |
|
437 | + */ |
|
438 | + private function _allowed_question_types() |
|
439 | + { |
|
440 | + $questionModel = $this->get_model(); |
|
441 | + /* @var $questionModel EEM_Question */ |
|
442 | + return $questionModel->allowed_question_types(); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Duplicates this question and its question options |
|
447 | + * |
|
448 | + * @return \EE_Question |
|
449 | + */ |
|
450 | + public function duplicate($options = array()) |
|
451 | + { |
|
452 | + $new_question = clone $this; |
|
453 | + $new_question->set('QST_ID', null); |
|
454 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
455 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
456 | + $new_question->set_system_ID(null); |
|
457 | + $new_question->set_wp_user(get_current_user_id()); |
|
458 | + // if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
459 | + $new_question->set_deleted(false); |
|
460 | + $success = $new_question->save(); |
|
461 | + if ($success) { |
|
462 | + // we don't totally want to duplicate the question options, because we want them to be for the NEW question |
|
463 | + foreach ($this->options() as $question_option) { |
|
464 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
465 | + } |
|
466 | + return $new_question; |
|
467 | + } else { |
|
468 | + return null; |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Returns the question's maximum allowed response size |
|
474 | + * |
|
475 | + * @return int|float |
|
476 | + */ |
|
477 | + public function max() |
|
478 | + { |
|
479 | + return $this->get('QST_max'); |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Sets the question's maximum allowed response size |
|
484 | + * |
|
485 | + * @param int|float $new_max |
|
486 | + * @return void |
|
487 | + */ |
|
488 | + public function set_max($new_max) |
|
489 | + { |
|
490 | + $this->set('QST_max', $new_max); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Creates a form input from this question which can be used in HTML forms |
|
496 | + * |
|
497 | + * @param EE_Registration $registration |
|
498 | + * @param EE_Answer $answer |
|
499 | + * @param array $input_constructor_args |
|
500 | + * @return EE_Form_Input_Base |
|
501 | + */ |
|
502 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) |
|
503 | + { |
|
504 | + $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
|
505 | + |
|
506 | + $input_constructor_args = array_merge( |
|
507 | + array( |
|
508 | + 'required' => $this->required() ? true : false, |
|
509 | + 'html_label_text' => $this->display_text(), |
|
510 | + 'required_validation_error_message' => $this->required_text(), |
|
511 | + ), |
|
512 | + $input_constructor_args |
|
513 | + ); |
|
514 | + if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
515 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
516 | + } |
|
517 | + // has this question been answered ? |
|
518 | + if ($answer instanceof EE_Answer |
|
519 | + && $answer->value() !== '' |
|
520 | + ) { |
|
521 | + // answer gets htmlspecialchars called on it, undo that please |
|
522 | + // because the form input's display strategy may call esc_attr too |
|
523 | + // which also does html special characters |
|
524 | + $values_with_html_special_chars = $answer->value(); |
|
525 | + if (is_array($values_with_html_special_chars)) { |
|
526 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
527 | + } else { |
|
528 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
529 | + } |
|
530 | + $input_constructor_args['default'] = $default_value; |
|
531 | + } |
|
532 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
533 | + if (in_array( |
|
534 | + $this->type(), |
|
535 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
536 | + true |
|
537 | + )) { |
|
538 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
539 | + null, |
|
540 | + min($max_max_for_question, $this->max()) |
|
541 | + ); |
|
542 | + } |
|
543 | + $input_constructor_args = apply_filters( |
|
544 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args', |
|
545 | + $input_constructor_args, |
|
546 | + $registration, |
|
547 | + $this, |
|
548 | + $answer |
|
549 | + ); |
|
550 | + |
|
551 | + $result = null; |
|
552 | + switch ($this->type()) { |
|
553 | + // Text |
|
554 | + case EEM_Question::QST_type_text: |
|
555 | + $result = new EE_Text_Input($input_constructor_args); |
|
556 | + break; |
|
557 | + // Textarea |
|
558 | + case EEM_Question::QST_type_textarea: |
|
559 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
560 | + break; |
|
561 | + // Radio Buttons |
|
562 | + case EEM_Question::QST_type_radio: |
|
563 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
564 | + break; |
|
565 | + // Dropdown |
|
566 | + case EEM_Question::QST_type_dropdown: |
|
567 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
568 | + break; |
|
569 | + // State Dropdown |
|
570 | + case EEM_Question::QST_type_state: |
|
571 | + $state_options = apply_filters( |
|
572 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
573 | + null, |
|
574 | + $this, |
|
575 | + $registration, |
|
576 | + $answer |
|
577 | + ); |
|
578 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
579 | + break; |
|
580 | + // Country Dropdown |
|
581 | + case EEM_Question::QST_type_country: |
|
582 | + $country_options = apply_filters( |
|
583 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
584 | + null, |
|
585 | + $this, |
|
586 | + $registration, |
|
587 | + $answer |
|
588 | + ); |
|
589 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
590 | + break; |
|
591 | + // Checkboxes |
|
592 | + case EEM_Question::QST_type_checkbox: |
|
593 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
594 | + break; |
|
595 | + // Date |
|
596 | + case EEM_Question::QST_type_date: |
|
597 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
598 | + break; |
|
599 | + case EEM_Question::QST_type_html_textarea: |
|
600 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
601 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
602 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
603 | + break; |
|
604 | + case EEM_Question::QST_type_email: |
|
605 | + $result = new EE_Email_Input($input_constructor_args); |
|
606 | + break; |
|
607 | + // Email confirm |
|
608 | + case EEM_Question::QST_type_email_confirm: |
|
609 | + $result = new EE_Email_Confirm_Input($input_constructor_args); |
|
610 | + break; |
|
611 | + case EEM_Question::QST_type_us_phone: |
|
612 | + $result = new EE_Phone_Input($input_constructor_args); |
|
613 | + break; |
|
614 | + case EEM_Question::QST_type_int: |
|
615 | + $result = new EE_Integer_Input($input_constructor_args); |
|
616 | + break; |
|
617 | + case EEM_Question::QST_type_decimal: |
|
618 | + $result = new EE_Float_Input($input_constructor_args); |
|
619 | + break; |
|
620 | + case EEM_Question::QST_type_url: |
|
621 | + $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy'); |
|
622 | + $result = new EE_Text_Input($input_constructor_args); |
|
623 | + break; |
|
624 | + case EEM_Question::QST_type_year: |
|
625 | + $result = new EE_Year_Input( |
|
626 | + $input_constructor_args, |
|
627 | + apply_filters( |
|
628 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', |
|
629 | + true, |
|
630 | + $this |
|
631 | + ), |
|
632 | + apply_filters( |
|
633 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', |
|
634 | + 100, |
|
635 | + $this |
|
636 | + ), |
|
637 | + apply_filters( |
|
638 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', |
|
639 | + 100, |
|
640 | + $this |
|
641 | + ) |
|
642 | + ); |
|
643 | + break; |
|
644 | + case EEM_Question::QST_type_multi_select: |
|
645 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
646 | + break; |
|
647 | + // fallback |
|
648 | + default: |
|
649 | + $default_input = apply_filters( |
|
650 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', |
|
651 | + null, |
|
652 | + $this->type(), |
|
653 | + $this, |
|
654 | + $input_constructor_args |
|
655 | + ); |
|
656 | + if (! $default_input) { |
|
657 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
658 | + } |
|
659 | + $result = $default_input; |
|
660 | + } |
|
661 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * Returns whether or not this question type should have question option entries |
|
667 | + * |
|
668 | + * @return bool |
|
669 | + */ |
|
670 | + public function should_have_question_options() |
|
671 | + { |
|
672 | + return in_array( |
|
673 | + $this->type(), |
|
674 | + $this->_model->question_types_with_options(), |
|
675 | + true |
|
676 | + ); |
|
677 | + } |
|
678 | 678 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | <?php esc_html_e('URL of Event:', 'event_espresso'); ?> |
8 | 8 | </label> |
9 | 9 | <?php //phpcs:disable Generic.Files.LineLength.TooLong |
10 | - // no new lines within <textarea> here because they'll output whitespace ?> |
|
10 | + // no new lines within <textarea> here because they'll output whitespace ?> |
|
11 | 11 | <textarea id="url-event" cols="30" rows="4" tabindex="112" name="vnu_virtual_url"><?php $_venue->f('VNU_virtual_url'); ?></textarea> |
12 | 12 | <?php //phpcs:enable ?> |
13 | 13 | </p> |
@@ -12,566 +12,566 @@ |
||
12 | 12 | class EE_Event_Registrations_List_Table extends EE_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * This property will hold the related Datetimes on an event IF the event id is included in the request. |
|
17 | - * |
|
18 | - * @var EE_Datetime[] |
|
19 | - */ |
|
20 | - protected $_dtts_for_event = array(); |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * The event if one is specified in the request |
|
25 | - * |
|
26 | - * @var EE_Event |
|
27 | - */ |
|
28 | - protected $_evt = null; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * The DTT_ID if the current view has a specified datetime. |
|
33 | - * |
|
34 | - * @var int $_cur_dtt_id |
|
35 | - */ |
|
36 | - protected $_cur_dtt_id = 0; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * EE_Event_Registrations_List_Table constructor. |
|
41 | - * |
|
42 | - * @param \Registrations_Admin_Page $admin_page |
|
43 | - */ |
|
44 | - public function __construct($admin_page) |
|
45 | - { |
|
46 | - parent::__construct($admin_page); |
|
47 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - protected function _setup_data() |
|
52 | - { |
|
53 | - $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
54 | - : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
55 | - $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
|
56 | - $this->_per_page, |
|
57 | - true |
|
58 | - ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - protected function _set_properties() |
|
63 | - { |
|
64 | - $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
65 | - $this->_wp_list_args = array( |
|
66 | - 'singular' => __('registrant', 'event_espresso'), |
|
67 | - 'plural' => __('registrants', 'event_espresso'), |
|
68 | - 'ajax' => true, |
|
69 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
70 | - ); |
|
71 | - $columns = array(); |
|
72 | - // $columns['_Reg_Status'] = ''; |
|
73 | - $this->_columns = array( |
|
74 | - '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
|
75 | - 'ATT_name' => __('Registrant', 'event_espresso'), |
|
76 | - 'ATT_email' => __('Email Address', 'event_espresso'), |
|
77 | - 'Event' => __('Event', 'event_espresso'), |
|
78 | - 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
79 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
80 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
81 | - 'TXN_total' => __('Total', 'event_espresso'), |
|
82 | - ); |
|
83 | - // Add/remove columns when an event has been selected |
|
84 | - if (! empty($evt_id)) { |
|
85 | - // Render a checkbox column |
|
86 | - $columns['cb'] = '<input type="checkbox" />'; |
|
87 | - $this->_has_checkbox_column = true; |
|
88 | - // Remove the 'Event' column |
|
89 | - unset($this->_columns['Event']); |
|
90 | - } |
|
91 | - $this->_columns = array_merge($columns, $this->_columns); |
|
92 | - $this->_primary_column = '_REG_att_checked_in'; |
|
93 | - if (! empty($evt_id) |
|
94 | - && EE_Registry::instance()->CAP->current_user_can( |
|
95 | - 'ee_read_registrations', |
|
96 | - 'espresso_registrations_registrations_reports', |
|
97 | - $evt_id |
|
98 | - ) |
|
99 | - ) { |
|
100 | - $this->_bottom_buttons = array( |
|
101 | - 'report' => array( |
|
102 | - 'route' => 'registrations_report', |
|
103 | - 'extra_request' => |
|
104 | - array( |
|
105 | - 'EVT_ID' => $evt_id, |
|
106 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
107 | - ), |
|
108 | - ), |
|
109 | - ); |
|
110 | - } |
|
111 | - $this->_bottom_buttons['report_filtered'] = array( |
|
112 | - 'route' => 'registrations_checkin_report', |
|
113 | - 'extra_request' => array( |
|
114 | - 'use_filters' => true, |
|
115 | - 'filters' => array_merge( |
|
116 | - array( |
|
117 | - 'EVT_ID' => $evt_id, |
|
118 | - ), |
|
119 | - array_diff_key( |
|
120 | - $this->_req_data, |
|
121 | - array_flip( |
|
122 | - array( |
|
123 | - 'page', |
|
124 | - 'action', |
|
125 | - 'default_nonce', |
|
126 | - ) |
|
127 | - ) |
|
128 | - ) |
|
129 | - ), |
|
130 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
131 | - ), |
|
132 | - ); |
|
133 | - $this->_sortable_columns = array( |
|
134 | - /** |
|
135 | - * Allows users to change the default sort if they wish. |
|
136 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
137 | - * |
|
138 | - * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
139 | - * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
140 | - * for a specific list table you can use the provided reference to this object instance. |
|
141 | - */ |
|
142 | - 'ATT_name' => array( |
|
143 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
144 | - true, |
|
145 | - $this, |
|
146 | - ) |
|
147 | - ? array('ATT_lname' => true) |
|
148 | - : array('ATT_fname' => true), |
|
149 | - 'Event' => array('Event.EVT_name' => false), |
|
150 | - ); |
|
151 | - $this->_hidden_columns = array(); |
|
152 | - $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
153 | - $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param \EE_Registration $item |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - protected function _get_row_class($item) |
|
162 | - { |
|
163 | - $class = parent::_get_row_class($item); |
|
164 | - // add status class |
|
165 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
166 | - if ($this->_has_checkbox_column) { |
|
167 | - $class .= ' has-checkbox-column'; |
|
168 | - } |
|
169 | - return $class; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @return array |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - protected function _get_table_filters() |
|
178 | - { |
|
179 | - $filters = $where = array(); |
|
180 | - $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
181 | - if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
182 | - // this means we don't have an event so let's setup a filter dropdown for all the events to select |
|
183 | - // note possible capability restrictions |
|
184 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
185 | - $where['status**'] = array('!=', 'private'); |
|
186 | - } |
|
187 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
188 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
189 | - } |
|
190 | - $events = EEM_Event::instance()->get_all( |
|
191 | - array( |
|
192 | - $where, |
|
193 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
194 | - ) |
|
195 | - ); |
|
196 | - $evts[] = array( |
|
197 | - 'id' => 0, |
|
198 | - 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
199 | - ); |
|
200 | - $checked = 'checked'; |
|
201 | - /** @var EE_Event $evt */ |
|
202 | - foreach ($events as $evt) { |
|
203 | - // any registrations for this event? |
|
204 | - if (! $evt->get_count_of_all_registrations()) { |
|
205 | - continue; |
|
206 | - } |
|
207 | - $evts[] = array( |
|
208 | - 'id' => $evt->ID(), |
|
209 | - 'text' => apply_filters( |
|
210 | - 'FHEE__EE_Event_Registrations___get_table_filters__event_name', |
|
211 | - $evt->get('EVT_name'), |
|
212 | - $evt |
|
213 | - ), |
|
214 | - 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
|
215 | - ); |
|
216 | - if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
217 | - $checked = ''; |
|
218 | - } |
|
219 | - } |
|
220 | - $event_filter = '<div class="ee-event-filter">'; |
|
221 | - $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
222 | - $event_filter .= '<span class="ee-event-filter-toggle">'; |
|
223 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
224 | - $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
225 | - $event_filter .= '</span>'; |
|
226 | - $event_filter .= '</div>'; |
|
227 | - $filters[] = $event_filter; |
|
228 | - } |
|
229 | - if (! empty($this->_dtts_for_event)) { |
|
230 | - // DTT datetimes filter |
|
231 | - $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
232 | - if (count($this->_dtts_for_event) > 1) { |
|
233 | - $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
234 | - foreach ($this->_dtts_for_event as $dtt) { |
|
235 | - $datetime_string = $dtt->name(); |
|
236 | - $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
237 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
238 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
239 | - } |
|
240 | - $input = new EE_Select_Input( |
|
241 | - $dtts, |
|
242 | - array( |
|
243 | - 'html_name' => 'DTT_ID', |
|
244 | - 'html_id' => 'DTT_ID', |
|
245 | - 'default' => $this->_cur_dtt_id, |
|
246 | - ) |
|
247 | - ); |
|
248 | - $filters[] = $input->get_html_for_input(); |
|
249 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
250 | - } |
|
251 | - } |
|
252 | - return $filters; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - protected function _add_view_counts() |
|
257 | - { |
|
258 | - $this->_views['all']['count'] = $this->_get_total_event_attendees(); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return int |
|
264 | - * @throws \EE_Error |
|
265 | - */ |
|
266 | - protected function _get_total_event_attendees() |
|
267 | - { |
|
268 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
269 | - $DTT_ID = $this->_cur_dtt_id; |
|
270 | - $query_params = array(); |
|
271 | - if ($EVT_ID) { |
|
272 | - $query_params[0]['EVT_ID'] = $EVT_ID; |
|
273 | - } |
|
274 | - // if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
|
275 | - if ($DTT_ID) { |
|
276 | - $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
277 | - } |
|
278 | - $status_ids_array = apply_filters( |
|
279 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
280 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
281 | - ); |
|
282 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
283 | - return EEM_Registration::instance()->count($query_params); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @param \EE_Registration $item |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function column__Reg_Status(EE_Registration $item) |
|
292 | - { |
|
293 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @param \EE_Registration $item |
|
299 | - * @return string |
|
300 | - * @throws \EE_Error |
|
301 | - */ |
|
302 | - public function column_cb($item) |
|
303 | - { |
|
304 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * column_REG_att_checked_in |
|
310 | - * |
|
311 | - * @param EE_Registration $item |
|
312 | - * @return string |
|
313 | - * @throws EE_Error |
|
314 | - * @throws InvalidArgumentException |
|
315 | - * @throws InvalidDataTypeException |
|
316 | - * @throws InvalidInterfaceException |
|
317 | - */ |
|
318 | - public function column__REG_att_checked_in(EE_Registration $item) |
|
319 | - { |
|
320 | - $attendee = $item->attendee(); |
|
321 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
322 | - |
|
323 | - if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
324 | - $latest_related_datetime = $item->get_latest_related_datetime(); |
|
325 | - if ($latest_related_datetime instanceof EE_Datetime) { |
|
326 | - $this->_cur_dtt_id = $latest_related_datetime->ID(); |
|
327 | - } |
|
328 | - } |
|
329 | - $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
330 | - $item, |
|
331 | - $this->_cur_dtt_id |
|
332 | - ); |
|
333 | - $nonce = wp_create_nonce('checkin_nonce'); |
|
334 | - $toggle_active = ! empty($this->_cur_dtt_id) |
|
335 | - && EE_Registry::instance()->CAP->current_user_can( |
|
336 | - 'ee_edit_checkin', |
|
337 | - 'espresso_registrations_toggle_checkin_status', |
|
338 | - $item->ID() |
|
339 | - ) |
|
340 | - ? ' clickable trigger-checkin' |
|
341 | - : ''; |
|
342 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
343 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
344 | - . ' data-_regid="' . $item->ID() . '"' |
|
345 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
346 | - . ' data-nonce="' . $nonce . '">' |
|
347 | - . '</span>' |
|
348 | - . $mobile_view_content; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @param \EE_Registration $item |
|
354 | - * @return mixed|string|void |
|
355 | - * @throws \EE_Error |
|
356 | - */ |
|
357 | - public function column_ATT_name(EE_Registration $item) |
|
358 | - { |
|
359 | - $attendee = $item->attendee(); |
|
360 | - if (! $attendee instanceof EE_Attendee) { |
|
361 | - return __('No contact record for this registration.', 'event_espresso'); |
|
362 | - } |
|
363 | - // edit attendee link |
|
364 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
365 | - array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
366 | - REG_ADMIN_URL |
|
367 | - ); |
|
368 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
369 | - 'ee_edit_contacts', |
|
370 | - 'espresso_registrations_edit_attendee' |
|
371 | - ) |
|
372 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
373 | - . $item->attendee()->full_name() |
|
374 | - . '</a>' |
|
375 | - : $item->attendee()->full_name(); |
|
376 | - $name_link .= $item->count() === 1 |
|
377 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
|
378 | - : ''; |
|
379 | - // add group details |
|
380 | - $name_link .= ' ' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
381 | - // add regcode |
|
382 | - $link = EE_Admin_Page::add_query_args_and_nonce( |
|
383 | - array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
384 | - REG_ADMIN_URL |
|
385 | - ); |
|
386 | - $name_link .= '<br>'; |
|
387 | - $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can( |
|
388 | - 'ee_read_registration', |
|
389 | - 'view_registration', |
|
390 | - $item->ID() |
|
391 | - ) |
|
392 | - ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
393 | - . $item->reg_code() |
|
394 | - . '</a>' |
|
395 | - : $item->reg_code(); |
|
396 | - // status |
|
397 | - $name_link .= '<br><span class="ee-status-text-small">'; |
|
398 | - $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
399 | - $name_link .= '</span>'; |
|
400 | - $actions = array(); |
|
401 | - $DTT_ID = $this->_cur_dtt_id; |
|
402 | - $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
403 | - ? $item->get_latest_related_datetime() |
|
404 | - : null; |
|
405 | - $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
406 | - ? $latest_related_datetime->ID() |
|
407 | - : $DTT_ID; |
|
408 | - if (! empty($DTT_ID) |
|
409 | - && EE_Registry::instance()->CAP->current_user_can( |
|
410 | - 'ee_read_checkins', |
|
411 | - 'espresso_registrations_registration_checkins' |
|
412 | - ) |
|
413 | - ) { |
|
414 | - $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
415 | - array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID), |
|
416 | - REG_ADMIN_URL |
|
417 | - ); |
|
418 | - // get the timestamps for this registration's checkins, related to the selected datetime |
|
419 | - $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
420 | - if (! empty($timestamps)) { |
|
421 | - // get the last timestamp |
|
422 | - $last_timestamp = end($timestamps); |
|
423 | - // checked in or checked out? |
|
424 | - $checkin_status = $last_timestamp->get('CHK_in') |
|
425 | - ? esc_html__('Checked In', 'event_espresso') |
|
426 | - : esc_html__('Checked Out', 'event_espresso'); |
|
427 | - // get timestamp string |
|
428 | - $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
429 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' |
|
430 | - . esc_attr__( |
|
431 | - 'View this registrant\'s check-ins/checkouts for the datetime', |
|
432 | - 'event_espresso' |
|
433 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
434 | - } |
|
435 | - } |
|
436 | - return (! empty($DTT_ID) && ! empty($timestamps)) |
|
437 | - ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
438 | - : $name_link; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * @param \EE_Registration $item |
|
444 | - * @return string |
|
445 | - */ |
|
446 | - public function column_ATT_email(EE_Registration $item) |
|
447 | - { |
|
448 | - $attendee = $item->attendee(); |
|
449 | - return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * @param \EE_Registration $item |
|
455 | - * @return bool|string |
|
456 | - * @throws \EE_Error |
|
457 | - */ |
|
458 | - public function column_Event(EE_Registration $item) |
|
459 | - { |
|
460 | - try { |
|
461 | - $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
|
462 | - $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
463 | - array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
464 | - REG_ADMIN_URL |
|
465 | - ); |
|
466 | - $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
467 | - 'ee_read_checkins', |
|
468 | - 'espresso_registrations_registration_checkins' |
|
469 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' |
|
470 | - . esc_attr__( |
|
471 | - 'View Checkins for this Event', |
|
472 | - 'event_espresso' |
|
473 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
474 | - } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
475 | - $event_label = esc_html__('Unknown', 'event_espresso'); |
|
476 | - } |
|
477 | - return $event_label; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @param \EE_Registration $item |
|
483 | - * @return mixed|string|void |
|
484 | - */ |
|
485 | - public function column_PRC_name(EE_Registration $item) |
|
486 | - { |
|
487 | - return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * column_REG_final_price |
|
493 | - * |
|
494 | - * @param \EE_Registration $item |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - public function column__REG_final_price(EE_Registration $item) |
|
498 | - { |
|
499 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * column_TXN_paid |
|
505 | - * |
|
506 | - * @param \EE_Registration $item |
|
507 | - * @return string |
|
508 | - * @throws \EE_Error |
|
509 | - */ |
|
510 | - public function column_TXN_paid(EE_Registration $item) |
|
511 | - { |
|
512 | - if ($item->count() === 1) { |
|
513 | - if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
514 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
515 | - } else { |
|
516 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
517 | - array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
518 | - TXN_ADMIN_URL |
|
519 | - ); |
|
520 | - return EE_Registry::instance()->CAP->current_user_can( |
|
521 | - 'ee_read_transaction', |
|
522 | - 'espresso_transactions_view_transaction' |
|
523 | - ) ? ' |
|
15 | + /** |
|
16 | + * This property will hold the related Datetimes on an event IF the event id is included in the request. |
|
17 | + * |
|
18 | + * @var EE_Datetime[] |
|
19 | + */ |
|
20 | + protected $_dtts_for_event = array(); |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * The event if one is specified in the request |
|
25 | + * |
|
26 | + * @var EE_Event |
|
27 | + */ |
|
28 | + protected $_evt = null; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * The DTT_ID if the current view has a specified datetime. |
|
33 | + * |
|
34 | + * @var int $_cur_dtt_id |
|
35 | + */ |
|
36 | + protected $_cur_dtt_id = 0; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * EE_Event_Registrations_List_Table constructor. |
|
41 | + * |
|
42 | + * @param \Registrations_Admin_Page $admin_page |
|
43 | + */ |
|
44 | + public function __construct($admin_page) |
|
45 | + { |
|
46 | + parent::__construct($admin_page); |
|
47 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + protected function _setup_data() |
|
52 | + { |
|
53 | + $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
54 | + : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
55 | + $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
|
56 | + $this->_per_page, |
|
57 | + true |
|
58 | + ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + protected function _set_properties() |
|
63 | + { |
|
64 | + $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
65 | + $this->_wp_list_args = array( |
|
66 | + 'singular' => __('registrant', 'event_espresso'), |
|
67 | + 'plural' => __('registrants', 'event_espresso'), |
|
68 | + 'ajax' => true, |
|
69 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
70 | + ); |
|
71 | + $columns = array(); |
|
72 | + // $columns['_Reg_Status'] = ''; |
|
73 | + $this->_columns = array( |
|
74 | + '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
|
75 | + 'ATT_name' => __('Registrant', 'event_espresso'), |
|
76 | + 'ATT_email' => __('Email Address', 'event_espresso'), |
|
77 | + 'Event' => __('Event', 'event_espresso'), |
|
78 | + 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
79 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
80 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
81 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
82 | + ); |
|
83 | + // Add/remove columns when an event has been selected |
|
84 | + if (! empty($evt_id)) { |
|
85 | + // Render a checkbox column |
|
86 | + $columns['cb'] = '<input type="checkbox" />'; |
|
87 | + $this->_has_checkbox_column = true; |
|
88 | + // Remove the 'Event' column |
|
89 | + unset($this->_columns['Event']); |
|
90 | + } |
|
91 | + $this->_columns = array_merge($columns, $this->_columns); |
|
92 | + $this->_primary_column = '_REG_att_checked_in'; |
|
93 | + if (! empty($evt_id) |
|
94 | + && EE_Registry::instance()->CAP->current_user_can( |
|
95 | + 'ee_read_registrations', |
|
96 | + 'espresso_registrations_registrations_reports', |
|
97 | + $evt_id |
|
98 | + ) |
|
99 | + ) { |
|
100 | + $this->_bottom_buttons = array( |
|
101 | + 'report' => array( |
|
102 | + 'route' => 'registrations_report', |
|
103 | + 'extra_request' => |
|
104 | + array( |
|
105 | + 'EVT_ID' => $evt_id, |
|
106 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
107 | + ), |
|
108 | + ), |
|
109 | + ); |
|
110 | + } |
|
111 | + $this->_bottom_buttons['report_filtered'] = array( |
|
112 | + 'route' => 'registrations_checkin_report', |
|
113 | + 'extra_request' => array( |
|
114 | + 'use_filters' => true, |
|
115 | + 'filters' => array_merge( |
|
116 | + array( |
|
117 | + 'EVT_ID' => $evt_id, |
|
118 | + ), |
|
119 | + array_diff_key( |
|
120 | + $this->_req_data, |
|
121 | + array_flip( |
|
122 | + array( |
|
123 | + 'page', |
|
124 | + 'action', |
|
125 | + 'default_nonce', |
|
126 | + ) |
|
127 | + ) |
|
128 | + ) |
|
129 | + ), |
|
130 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
131 | + ), |
|
132 | + ); |
|
133 | + $this->_sortable_columns = array( |
|
134 | + /** |
|
135 | + * Allows users to change the default sort if they wish. |
|
136 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
137 | + * |
|
138 | + * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
139 | + * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
140 | + * for a specific list table you can use the provided reference to this object instance. |
|
141 | + */ |
|
142 | + 'ATT_name' => array( |
|
143 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
144 | + true, |
|
145 | + $this, |
|
146 | + ) |
|
147 | + ? array('ATT_lname' => true) |
|
148 | + : array('ATT_fname' => true), |
|
149 | + 'Event' => array('Event.EVT_name' => false), |
|
150 | + ); |
|
151 | + $this->_hidden_columns = array(); |
|
152 | + $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
153 | + $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param \EE_Registration $item |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + protected function _get_row_class($item) |
|
162 | + { |
|
163 | + $class = parent::_get_row_class($item); |
|
164 | + // add status class |
|
165 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
166 | + if ($this->_has_checkbox_column) { |
|
167 | + $class .= ' has-checkbox-column'; |
|
168 | + } |
|
169 | + return $class; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @return array |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + protected function _get_table_filters() |
|
178 | + { |
|
179 | + $filters = $where = array(); |
|
180 | + $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
181 | + if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
182 | + // this means we don't have an event so let's setup a filter dropdown for all the events to select |
|
183 | + // note possible capability restrictions |
|
184 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
185 | + $where['status**'] = array('!=', 'private'); |
|
186 | + } |
|
187 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
188 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
189 | + } |
|
190 | + $events = EEM_Event::instance()->get_all( |
|
191 | + array( |
|
192 | + $where, |
|
193 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
194 | + ) |
|
195 | + ); |
|
196 | + $evts[] = array( |
|
197 | + 'id' => 0, |
|
198 | + 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
199 | + ); |
|
200 | + $checked = 'checked'; |
|
201 | + /** @var EE_Event $evt */ |
|
202 | + foreach ($events as $evt) { |
|
203 | + // any registrations for this event? |
|
204 | + if (! $evt->get_count_of_all_registrations()) { |
|
205 | + continue; |
|
206 | + } |
|
207 | + $evts[] = array( |
|
208 | + 'id' => $evt->ID(), |
|
209 | + 'text' => apply_filters( |
|
210 | + 'FHEE__EE_Event_Registrations___get_table_filters__event_name', |
|
211 | + $evt->get('EVT_name'), |
|
212 | + $evt |
|
213 | + ), |
|
214 | + 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
|
215 | + ); |
|
216 | + if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
217 | + $checked = ''; |
|
218 | + } |
|
219 | + } |
|
220 | + $event_filter = '<div class="ee-event-filter">'; |
|
221 | + $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
222 | + $event_filter .= '<span class="ee-event-filter-toggle">'; |
|
223 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
224 | + $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
225 | + $event_filter .= '</span>'; |
|
226 | + $event_filter .= '</div>'; |
|
227 | + $filters[] = $event_filter; |
|
228 | + } |
|
229 | + if (! empty($this->_dtts_for_event)) { |
|
230 | + // DTT datetimes filter |
|
231 | + $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
232 | + if (count($this->_dtts_for_event) > 1) { |
|
233 | + $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
234 | + foreach ($this->_dtts_for_event as $dtt) { |
|
235 | + $datetime_string = $dtt->name(); |
|
236 | + $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
237 | + $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
238 | + $dtts[ $dtt->ID() ] = $datetime_string; |
|
239 | + } |
|
240 | + $input = new EE_Select_Input( |
|
241 | + $dtts, |
|
242 | + array( |
|
243 | + 'html_name' => 'DTT_ID', |
|
244 | + 'html_id' => 'DTT_ID', |
|
245 | + 'default' => $this->_cur_dtt_id, |
|
246 | + ) |
|
247 | + ); |
|
248 | + $filters[] = $input->get_html_for_input(); |
|
249 | + $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
250 | + } |
|
251 | + } |
|
252 | + return $filters; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + protected function _add_view_counts() |
|
257 | + { |
|
258 | + $this->_views['all']['count'] = $this->_get_total_event_attendees(); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return int |
|
264 | + * @throws \EE_Error |
|
265 | + */ |
|
266 | + protected function _get_total_event_attendees() |
|
267 | + { |
|
268 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
269 | + $DTT_ID = $this->_cur_dtt_id; |
|
270 | + $query_params = array(); |
|
271 | + if ($EVT_ID) { |
|
272 | + $query_params[0]['EVT_ID'] = $EVT_ID; |
|
273 | + } |
|
274 | + // if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
|
275 | + if ($DTT_ID) { |
|
276 | + $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
277 | + } |
|
278 | + $status_ids_array = apply_filters( |
|
279 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
280 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
281 | + ); |
|
282 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
283 | + return EEM_Registration::instance()->count($query_params); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @param \EE_Registration $item |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function column__Reg_Status(EE_Registration $item) |
|
292 | + { |
|
293 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @param \EE_Registration $item |
|
299 | + * @return string |
|
300 | + * @throws \EE_Error |
|
301 | + */ |
|
302 | + public function column_cb($item) |
|
303 | + { |
|
304 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * column_REG_att_checked_in |
|
310 | + * |
|
311 | + * @param EE_Registration $item |
|
312 | + * @return string |
|
313 | + * @throws EE_Error |
|
314 | + * @throws InvalidArgumentException |
|
315 | + * @throws InvalidDataTypeException |
|
316 | + * @throws InvalidInterfaceException |
|
317 | + */ |
|
318 | + public function column__REG_att_checked_in(EE_Registration $item) |
|
319 | + { |
|
320 | + $attendee = $item->attendee(); |
|
321 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
322 | + |
|
323 | + if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
324 | + $latest_related_datetime = $item->get_latest_related_datetime(); |
|
325 | + if ($latest_related_datetime instanceof EE_Datetime) { |
|
326 | + $this->_cur_dtt_id = $latest_related_datetime->ID(); |
|
327 | + } |
|
328 | + } |
|
329 | + $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
330 | + $item, |
|
331 | + $this->_cur_dtt_id |
|
332 | + ); |
|
333 | + $nonce = wp_create_nonce('checkin_nonce'); |
|
334 | + $toggle_active = ! empty($this->_cur_dtt_id) |
|
335 | + && EE_Registry::instance()->CAP->current_user_can( |
|
336 | + 'ee_edit_checkin', |
|
337 | + 'espresso_registrations_toggle_checkin_status', |
|
338 | + $item->ID() |
|
339 | + ) |
|
340 | + ? ' clickable trigger-checkin' |
|
341 | + : ''; |
|
342 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
343 | + return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
344 | + . ' data-_regid="' . $item->ID() . '"' |
|
345 | + . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
346 | + . ' data-nonce="' . $nonce . '">' |
|
347 | + . '</span>' |
|
348 | + . $mobile_view_content; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @param \EE_Registration $item |
|
354 | + * @return mixed|string|void |
|
355 | + * @throws \EE_Error |
|
356 | + */ |
|
357 | + public function column_ATT_name(EE_Registration $item) |
|
358 | + { |
|
359 | + $attendee = $item->attendee(); |
|
360 | + if (! $attendee instanceof EE_Attendee) { |
|
361 | + return __('No contact record for this registration.', 'event_espresso'); |
|
362 | + } |
|
363 | + // edit attendee link |
|
364 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
365 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
366 | + REG_ADMIN_URL |
|
367 | + ); |
|
368 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
369 | + 'ee_edit_contacts', |
|
370 | + 'espresso_registrations_edit_attendee' |
|
371 | + ) |
|
372 | + ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
373 | + . $item->attendee()->full_name() |
|
374 | + . '</a>' |
|
375 | + : $item->attendee()->full_name(); |
|
376 | + $name_link .= $item->count() === 1 |
|
377 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
|
378 | + : ''; |
|
379 | + // add group details |
|
380 | + $name_link .= ' ' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
381 | + // add regcode |
|
382 | + $link = EE_Admin_Page::add_query_args_and_nonce( |
|
383 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
384 | + REG_ADMIN_URL |
|
385 | + ); |
|
386 | + $name_link .= '<br>'; |
|
387 | + $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can( |
|
388 | + 'ee_read_registration', |
|
389 | + 'view_registration', |
|
390 | + $item->ID() |
|
391 | + ) |
|
392 | + ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
393 | + . $item->reg_code() |
|
394 | + . '</a>' |
|
395 | + : $item->reg_code(); |
|
396 | + // status |
|
397 | + $name_link .= '<br><span class="ee-status-text-small">'; |
|
398 | + $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
399 | + $name_link .= '</span>'; |
|
400 | + $actions = array(); |
|
401 | + $DTT_ID = $this->_cur_dtt_id; |
|
402 | + $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
403 | + ? $item->get_latest_related_datetime() |
|
404 | + : null; |
|
405 | + $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
406 | + ? $latest_related_datetime->ID() |
|
407 | + : $DTT_ID; |
|
408 | + if (! empty($DTT_ID) |
|
409 | + && EE_Registry::instance()->CAP->current_user_can( |
|
410 | + 'ee_read_checkins', |
|
411 | + 'espresso_registrations_registration_checkins' |
|
412 | + ) |
|
413 | + ) { |
|
414 | + $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
415 | + array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID), |
|
416 | + REG_ADMIN_URL |
|
417 | + ); |
|
418 | + // get the timestamps for this registration's checkins, related to the selected datetime |
|
419 | + $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
420 | + if (! empty($timestamps)) { |
|
421 | + // get the last timestamp |
|
422 | + $last_timestamp = end($timestamps); |
|
423 | + // checked in or checked out? |
|
424 | + $checkin_status = $last_timestamp->get('CHK_in') |
|
425 | + ? esc_html__('Checked In', 'event_espresso') |
|
426 | + : esc_html__('Checked Out', 'event_espresso'); |
|
427 | + // get timestamp string |
|
428 | + $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
429 | + $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' |
|
430 | + . esc_attr__( |
|
431 | + 'View this registrant\'s check-ins/checkouts for the datetime', |
|
432 | + 'event_espresso' |
|
433 | + ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
434 | + } |
|
435 | + } |
|
436 | + return (! empty($DTT_ID) && ! empty($timestamps)) |
|
437 | + ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
438 | + : $name_link; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * @param \EE_Registration $item |
|
444 | + * @return string |
|
445 | + */ |
|
446 | + public function column_ATT_email(EE_Registration $item) |
|
447 | + { |
|
448 | + $attendee = $item->attendee(); |
|
449 | + return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * @param \EE_Registration $item |
|
455 | + * @return bool|string |
|
456 | + * @throws \EE_Error |
|
457 | + */ |
|
458 | + public function column_Event(EE_Registration $item) |
|
459 | + { |
|
460 | + try { |
|
461 | + $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
|
462 | + $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
463 | + array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
464 | + REG_ADMIN_URL |
|
465 | + ); |
|
466 | + $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
467 | + 'ee_read_checkins', |
|
468 | + 'espresso_registrations_registration_checkins' |
|
469 | + ) ? '<a href="' . $chkin_lnk_url . '" title="' |
|
470 | + . esc_attr__( |
|
471 | + 'View Checkins for this Event', |
|
472 | + 'event_espresso' |
|
473 | + ) . '">' . $event->name() . '</a>' : $event->name(); |
|
474 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
475 | + $event_label = esc_html__('Unknown', 'event_espresso'); |
|
476 | + } |
|
477 | + return $event_label; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @param \EE_Registration $item |
|
483 | + * @return mixed|string|void |
|
484 | + */ |
|
485 | + public function column_PRC_name(EE_Registration $item) |
|
486 | + { |
|
487 | + return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * column_REG_final_price |
|
493 | + * |
|
494 | + * @param \EE_Registration $item |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + public function column__REG_final_price(EE_Registration $item) |
|
498 | + { |
|
499 | + return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * column_TXN_paid |
|
505 | + * |
|
506 | + * @param \EE_Registration $item |
|
507 | + * @return string |
|
508 | + * @throws \EE_Error |
|
509 | + */ |
|
510 | + public function column_TXN_paid(EE_Registration $item) |
|
511 | + { |
|
512 | + if ($item->count() === 1) { |
|
513 | + if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
514 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
515 | + } else { |
|
516 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
517 | + array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
518 | + TXN_ADMIN_URL |
|
519 | + ); |
|
520 | + return EE_Registry::instance()->CAP->current_user_can( |
|
521 | + 'ee_read_transaction', |
|
522 | + 'espresso_transactions_view_transaction' |
|
523 | + ) ? ' |
|
524 | 524 | <span class="reg-pad-rght"> |
525 | 525 | <a class="status-' |
526 | - . $item->transaction()->status_ID() |
|
527 | - . '" href="' |
|
528 | - . $view_txn_lnk_url |
|
529 | - . '" title="' |
|
530 | - . esc_attr__('View Transaction', 'event_espresso') |
|
531 | - . '"> |
|
526 | + . $item->transaction()->status_ID() |
|
527 | + . '" href="' |
|
528 | + . $view_txn_lnk_url |
|
529 | + . '" title="' |
|
530 | + . esc_attr__('View Transaction', 'event_espresso') |
|
531 | + . '"> |
|
532 | 532 | ' |
533 | - . $item->transaction()->pretty_paid() |
|
534 | - . ' |
|
533 | + . $item->transaction()->pretty_paid() |
|
534 | + . ' |
|
535 | 535 | </a> |
536 | 536 | <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
537 | - } |
|
538 | - } else { |
|
539 | - return '<span class="reg-pad-rght"></span>'; |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * column_TXN_total |
|
546 | - * |
|
547 | - * @param \EE_Registration $item |
|
548 | - * @return string |
|
549 | - * @throws \EE_Error |
|
550 | - */ |
|
551 | - public function column_TXN_total(EE_Registration $item) |
|
552 | - { |
|
553 | - $txn = $item->transaction(); |
|
554 | - $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
555 | - if ($item->get('REG_count') === 1) { |
|
556 | - $line_total_obj = $txn->total_line_item(); |
|
557 | - $txn_total = $line_total_obj instanceof EE_Line_Item |
|
558 | - ? $line_total_obj->get_pretty('LIN_total') |
|
559 | - : __( |
|
560 | - 'View Transaction', |
|
561 | - 'event_espresso' |
|
562 | - ); |
|
563 | - return EE_Registry::instance()->CAP->current_user_can( |
|
564 | - 'ee_read_transaction', |
|
565 | - 'espresso_transactions_view_transaction' |
|
566 | - ) ? '<a href="' |
|
567 | - . $view_txn_url |
|
568 | - . '" title="' |
|
569 | - . esc_attr__('View Transaction', 'event_espresso') |
|
570 | - . '"><span class="reg-pad-rght">' |
|
571 | - . $txn_total |
|
572 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
573 | - } else { |
|
574 | - return '<span class="reg-pad-rght"></span>'; |
|
575 | - } |
|
576 | - } |
|
537 | + } |
|
538 | + } else { |
|
539 | + return '<span class="reg-pad-rght"></span>'; |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * column_TXN_total |
|
546 | + * |
|
547 | + * @param \EE_Registration $item |
|
548 | + * @return string |
|
549 | + * @throws \EE_Error |
|
550 | + */ |
|
551 | + public function column_TXN_total(EE_Registration $item) |
|
552 | + { |
|
553 | + $txn = $item->transaction(); |
|
554 | + $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
555 | + if ($item->get('REG_count') === 1) { |
|
556 | + $line_total_obj = $txn->total_line_item(); |
|
557 | + $txn_total = $line_total_obj instanceof EE_Line_Item |
|
558 | + ? $line_total_obj->get_pretty('LIN_total') |
|
559 | + : __( |
|
560 | + 'View Transaction', |
|
561 | + 'event_espresso' |
|
562 | + ); |
|
563 | + return EE_Registry::instance()->CAP->current_user_can( |
|
564 | + 'ee_read_transaction', |
|
565 | + 'espresso_transactions_view_transaction' |
|
566 | + ) ? '<a href="' |
|
567 | + . $view_txn_url |
|
568 | + . '" title="' |
|
569 | + . esc_attr__('View Transaction', 'event_espresso') |
|
570 | + . '"><span class="reg-pad-rght">' |
|
571 | + . $txn_total |
|
572 | + . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
573 | + } else { |
|
574 | + return '<span class="reg-pad-rght"></span>'; |
|
575 | + } |
|
576 | + } |
|
577 | 577 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'TXN_total' => __('Total', 'event_espresso'), |
82 | 82 | ); |
83 | 83 | // Add/remove columns when an event has been selected |
84 | - if (! empty($evt_id)) { |
|
84 | + if ( ! empty($evt_id)) { |
|
85 | 85 | // Render a checkbox column |
86 | 86 | $columns['cb'] = '<input type="checkbox" />'; |
87 | 87 | $this->_has_checkbox_column = true; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | $this->_columns = array_merge($columns, $this->_columns); |
92 | 92 | $this->_primary_column = '_REG_att_checked_in'; |
93 | - if (! empty($evt_id) |
|
93 | + if ( ! empty($evt_id) |
|
94 | 94 | && EE_Registry::instance()->CAP->current_user_can( |
95 | 95 | 'ee_read_registrations', |
96 | 96 | 'espresso_registrations_registrations_reports', |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | { |
163 | 163 | $class = parent::_get_row_class($item); |
164 | 164 | // add status class |
165 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
165 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
166 | 166 | if ($this->_has_checkbox_column) { |
167 | 167 | $class .= ' has-checkbox-column'; |
168 | 168 | } |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
182 | 182 | // this means we don't have an event so let's setup a filter dropdown for all the events to select |
183 | 183 | // note possible capability restrictions |
184 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
184 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
185 | 185 | $where['status**'] = array('!=', 'private'); |
186 | 186 | } |
187 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
187 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
188 | 188 | $where['EVT_wp_user'] = get_current_user_id(); |
189 | 189 | } |
190 | 190 | $events = EEM_Event::instance()->get_all( |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | /** @var EE_Event $evt */ |
202 | 202 | foreach ($events as $evt) { |
203 | 203 | // any registrations for this event? |
204 | - if (! $evt->get_count_of_all_registrations()) { |
|
204 | + if ( ! $evt->get_count_of_all_registrations()) { |
|
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | $evts[] = array( |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | $event_filter = '<div class="ee-event-filter">'; |
221 | 221 | $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
222 | 222 | $event_filter .= '<span class="ee-event-filter-toggle">'; |
223 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
223 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> '; |
|
224 | 224 | $event_filter .= __('Hide Expired Events', 'event_espresso'); |
225 | 225 | $event_filter .= '</span>'; |
226 | 226 | $event_filter .= '</div>'; |
227 | 227 | $filters[] = $event_filter; |
228 | 228 | } |
229 | - if (! empty($this->_dtts_for_event)) { |
|
229 | + if ( ! empty($this->_dtts_for_event)) { |
|
230 | 230 | // DTT datetimes filter |
231 | 231 | $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
232 | 232 | if (count($this->_dtts_for_event) > 1) { |
233 | 233 | $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
234 | 234 | foreach ($this->_dtts_for_event as $dtt) { |
235 | 235 | $datetime_string = $dtt->name(); |
236 | - $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
237 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
238 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
236 | + $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : ''; |
|
237 | + $datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string; |
|
238 | + $dtts[$dtt->ID()] = $datetime_string; |
|
239 | 239 | } |
240 | 240 | $input = new EE_Select_Input( |
241 | 241 | $dtts, |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | ) |
247 | 247 | ); |
248 | 248 | $filters[] = $input->get_html_for_input(); |
249 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
249 | + $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">'; |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | return $filters; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function column__Reg_Status(EE_Registration $item) |
292 | 292 | { |
293 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
293 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>'; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | ) |
340 | 340 | ? ' clickable trigger-checkin' |
341 | 341 | : ''; |
342 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
343 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
344 | - . ' data-_regid="' . $item->ID() . '"' |
|
345 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
346 | - . ' data-nonce="' . $nonce . '">' |
|
342 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
343 | + return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"' |
|
344 | + . ' data-_regid="'.$item->ID().'"' |
|
345 | + . ' data-dttid="'.$this->_cur_dtt_id.'"' |
|
346 | + . ' data-nonce="'.$nonce.'">' |
|
347 | 347 | . '</span>' |
348 | 348 | . $mobile_view_content; |
349 | 349 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | public function column_ATT_name(EE_Registration $item) |
358 | 358 | { |
359 | 359 | $attendee = $item->attendee(); |
360 | - if (! $attendee instanceof EE_Attendee) { |
|
360 | + if ( ! $attendee instanceof EE_Attendee) { |
|
361 | 361 | return __('No contact record for this registration.', 'event_espresso'); |
362 | 362 | } |
363 | 363 | // edit attendee link |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | 'ee_edit_contacts', |
370 | 370 | 'espresso_registrations_edit_attendee' |
371 | 371 | ) |
372 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
372 | + ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
373 | 373 | . $item->attendee()->full_name() |
374 | 374 | . '</a>' |
375 | 375 | : $item->attendee()->full_name(); |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
378 | 378 | : ''; |
379 | 379 | // add group details |
380 | - $name_link .= ' ' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
380 | + $name_link .= ' '.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
381 | 381 | // add regcode |
382 | 382 | $link = EE_Admin_Page::add_query_args_and_nonce( |
383 | 383 | array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | 'view_registration', |
390 | 390 | $item->ID() |
391 | 391 | ) |
392 | - ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
392 | + ? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
393 | 393 | . $item->reg_code() |
394 | 394 | . '</a>' |
395 | 395 | : $item->reg_code(); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
406 | 406 | ? $latest_related_datetime->ID() |
407 | 407 | : $DTT_ID; |
408 | - if (! empty($DTT_ID) |
|
408 | + if ( ! empty($DTT_ID) |
|
409 | 409 | && EE_Registry::instance()->CAP->current_user_can( |
410 | 410 | 'ee_read_checkins', |
411 | 411 | 'espresso_registrations_registration_checkins' |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | ); |
418 | 418 | // get the timestamps for this registration's checkins, related to the selected datetime |
419 | 419 | $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
420 | - if (! empty($timestamps)) { |
|
420 | + if ( ! empty($timestamps)) { |
|
421 | 421 | // get the last timestamp |
422 | 422 | $last_timestamp = end($timestamps); |
423 | 423 | // checked in or checked out? |
@@ -426,14 +426,14 @@ discard block |
||
426 | 426 | : esc_html__('Checked Out', 'event_espresso'); |
427 | 427 | // get timestamp string |
428 | 428 | $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
429 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' |
|
429 | + $actions['checkin'] = '<a href="'.$checkin_list_url.'" title="' |
|
430 | 430 | . esc_attr__( |
431 | 431 | 'View this registrant\'s check-ins/checkouts for the datetime', |
432 | 432 | 'event_espresso' |
433 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
433 | + ).'">'.$checkin_status.': '.$timestamp_string.'</a>'; |
|
434 | 434 | } |
435 | 435 | } |
436 | - return (! empty($DTT_ID) && ! empty($timestamps)) |
|
436 | + return ( ! empty($DTT_ID) && ! empty($timestamps)) |
|
437 | 437 | ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
438 | 438 | : $name_link; |
439 | 439 | } |
@@ -466,11 +466,11 @@ discard block |
||
466 | 466 | $event_label = EE_Registry::instance()->CAP->current_user_can( |
467 | 467 | 'ee_read_checkins', |
468 | 468 | 'espresso_registrations_registration_checkins' |
469 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' |
|
469 | + ) ? '<a href="'.$chkin_lnk_url.'" title="' |
|
470 | 470 | . esc_attr__( |
471 | 471 | 'View Checkins for this Event', |
472 | 472 | 'event_espresso' |
473 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
473 | + ).'">'.$event->name().'</a>' : $event->name(); |
|
474 | 474 | } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
475 | 475 | $event_label = esc_html__('Unknown', 'event_espresso'); |
476 | 476 | } |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | */ |
497 | 497 | public function column__REG_final_price(EE_Registration $item) |
498 | 498 | { |
499 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
499 | + return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>'; |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | . $item->transaction()->pretty_paid() |
534 | 534 | . ' |
535 | 535 | </a> |
536 | - <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
536 | + <span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
537 | 537 | } |
538 | 538 | } else { |
539 | 539 | return '<span class="reg-pad-rght"></span>'; |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | . esc_attr__('View Transaction', 'event_espresso') |
570 | 570 | . '"><span class="reg-pad-rght">' |
571 | 571 | . $txn_total |
572 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
572 | + . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>'; |
|
573 | 573 | } else { |
574 | 574 | return '<span class="reg-pad-rght"></span>'; |
575 | 575 | } |
@@ -15,233 +15,233 @@ discard block |
||
15 | 15 | class EEH_Activation implements ResettableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * constant used to indicate a cron task is no longer in use |
|
20 | - */ |
|
21 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
22 | - |
|
23 | - /** |
|
24 | - * WP_User->ID |
|
25 | - * |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - private static $_default_creator_id; |
|
29 | - |
|
30 | - /** |
|
31 | - * indicates whether or not we've already verified core's default data during this request, |
|
32 | - * because after migrations are done, any addons activated while in maintenance mode |
|
33 | - * will want to setup their own default data, and they might hook into core's default data |
|
34 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
35 | - * This prevents doing that for EVERY single addon. |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
43 | - */ |
|
44 | - private static $table_analysis; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
48 | - */ |
|
49 | - private static $table_manager; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
54 | - */ |
|
55 | - public static function getTableAnalysis() |
|
56 | - { |
|
57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | - } |
|
60 | - return self::$table_analysis; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return \EventEspresso\core\services\database\TableManager |
|
66 | - */ |
|
67 | - public static function getTableManager() |
|
68 | - { |
|
69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | - } |
|
72 | - return self::$table_manager; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * _ensure_table_name_has_prefix |
|
78 | - * |
|
79 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
80 | - * @access public |
|
81 | - * @static |
|
82 | - * @param $table_name |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public static function ensure_table_name_has_prefix($table_name) |
|
86 | - { |
|
87 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * system_initialization |
|
93 | - * ensures the EE configuration settings are loaded with at least default options set |
|
94 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @static |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public static function system_initialization() |
|
101 | - { |
|
102 | - EEH_Activation::reset_and_update_config(); |
|
103 | - // which is fired BEFORE activation of plugin anyways |
|
104 | - EEH_Activation::verify_default_pages_exist(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sets the database schema and creates folders. This should |
|
110 | - * be called on plugin activation and reactivation |
|
111 | - * |
|
112 | - * @return boolean success, whether the database and folders are setup properly |
|
113 | - * @throws \EE_Error |
|
114 | - */ |
|
115 | - public static function initialize_db_and_folders() |
|
116 | - { |
|
117 | - return EEH_Activation::create_database_tables(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * assuming we have an up-to-date database schema, this will populate it |
|
123 | - * with default and initial data. This should be called |
|
124 | - * upon activation of a new plugin, reactivation, and at the end |
|
125 | - * of running migration scripts |
|
126 | - * |
|
127 | - * @throws \EE_Error |
|
128 | - */ |
|
129 | - public static function initialize_db_content() |
|
130 | - { |
|
131 | - // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
132 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | - return; |
|
134 | - } |
|
135 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
136 | - |
|
137 | - EEH_Activation::initialize_system_questions(); |
|
138 | - EEH_Activation::insert_default_status_codes(); |
|
139 | - EEH_Activation::generate_default_message_templates(); |
|
140 | - EEH_Activation::create_no_ticket_prices_array(); |
|
141 | - EEH_Activation::removeEmailConfirmFromAddressGroup(); |
|
142 | - |
|
143 | - EEH_Activation::validate_messages_system(); |
|
144 | - EEH_Activation::insert_default_payment_methods(); |
|
145 | - // in case we've |
|
146 | - EEH_Activation::remove_cron_tasks(); |
|
147 | - EEH_Activation::create_cron_tasks(); |
|
148 | - // remove all TXN locks since that is being done via extra meta now |
|
149 | - delete_option('ee_locked_transactions'); |
|
150 | - // also, check for CAF default db content |
|
151 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
152 | - // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
153 | - // which users really won't care about on initial activation |
|
154 | - EE_Error::overwrite_success(); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
160 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
161 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
162 | - * (null) |
|
163 | - * |
|
164 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
165 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
166 | - * @return array |
|
167 | - * @throws \EE_Error |
|
168 | - */ |
|
169 | - public static function get_cron_tasks($which_to_include) |
|
170 | - { |
|
171 | - $cron_tasks = apply_filters( |
|
172 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
173 | - array( |
|
174 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
175 | - // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
176 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
177 | - // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
178 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
179 | - ) |
|
180 | - ); |
|
181 | - if ($which_to_include === 'old') { |
|
182 | - $cron_tasks = array_filter( |
|
183 | - $cron_tasks, |
|
184 | - function ($value) { |
|
185 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
186 | - } |
|
187 | - ); |
|
188 | - } elseif ($which_to_include === 'current') { |
|
189 | - $cron_tasks = array_filter($cron_tasks); |
|
190 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
191 | - throw new EE_Error( |
|
192 | - sprintf( |
|
193 | - __( |
|
194 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $which_to_include |
|
198 | - ) |
|
199 | - ); |
|
200 | - } |
|
201 | - return $cron_tasks; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
207 | - * |
|
208 | - * @throws \EE_Error |
|
209 | - */ |
|
210 | - public static function create_cron_tasks() |
|
211 | - { |
|
212 | - |
|
213 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
214 | - if (! wp_next_scheduled($hook_name)) { |
|
215 | - /** |
|
216 | - * This allows client code to define the initial start timestamp for this schedule. |
|
217 | - */ |
|
218 | - if (is_array($frequency) |
|
219 | - && count($frequency) === 2 |
|
220 | - && isset($frequency[0], $frequency[1]) |
|
221 | - ) { |
|
222 | - $start_timestamp = $frequency[0]; |
|
223 | - $frequency = $frequency[1]; |
|
224 | - } else { |
|
225 | - $start_timestamp = time(); |
|
226 | - } |
|
227 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * Remove the currently-existing and now-removed cron tasks. |
|
235 | - * |
|
236 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
237 | - * @throws \EE_Error |
|
238 | - */ |
|
239 | - public static function remove_cron_tasks($remove_all = true) |
|
240 | - { |
|
241 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
242 | - $crons = _get_cron_array(); |
|
243 | - $crons = is_array($crons) ? $crons : array(); |
|
244 | - /* reminder of what $crons look like: |
|
18 | + /** |
|
19 | + * constant used to indicate a cron task is no longer in use |
|
20 | + */ |
|
21 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
22 | + |
|
23 | + /** |
|
24 | + * WP_User->ID |
|
25 | + * |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + private static $_default_creator_id; |
|
29 | + |
|
30 | + /** |
|
31 | + * indicates whether or not we've already verified core's default data during this request, |
|
32 | + * because after migrations are done, any addons activated while in maintenance mode |
|
33 | + * will want to setup their own default data, and they might hook into core's default data |
|
34 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
35 | + * This prevents doing that for EVERY single addon. |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
43 | + */ |
|
44 | + private static $table_analysis; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
48 | + */ |
|
49 | + private static $table_manager; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
54 | + */ |
|
55 | + public static function getTableAnalysis() |
|
56 | + { |
|
57 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | + } |
|
60 | + return self::$table_analysis; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return \EventEspresso\core\services\database\TableManager |
|
66 | + */ |
|
67 | + public static function getTableManager() |
|
68 | + { |
|
69 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | + } |
|
72 | + return self::$table_manager; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * _ensure_table_name_has_prefix |
|
78 | + * |
|
79 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
80 | + * @access public |
|
81 | + * @static |
|
82 | + * @param $table_name |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public static function ensure_table_name_has_prefix($table_name) |
|
86 | + { |
|
87 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * system_initialization |
|
93 | + * ensures the EE configuration settings are loaded with at least default options set |
|
94 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @static |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public static function system_initialization() |
|
101 | + { |
|
102 | + EEH_Activation::reset_and_update_config(); |
|
103 | + // which is fired BEFORE activation of plugin anyways |
|
104 | + EEH_Activation::verify_default_pages_exist(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sets the database schema and creates folders. This should |
|
110 | + * be called on plugin activation and reactivation |
|
111 | + * |
|
112 | + * @return boolean success, whether the database and folders are setup properly |
|
113 | + * @throws \EE_Error |
|
114 | + */ |
|
115 | + public static function initialize_db_and_folders() |
|
116 | + { |
|
117 | + return EEH_Activation::create_database_tables(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * assuming we have an up-to-date database schema, this will populate it |
|
123 | + * with default and initial data. This should be called |
|
124 | + * upon activation of a new plugin, reactivation, and at the end |
|
125 | + * of running migration scripts |
|
126 | + * |
|
127 | + * @throws \EE_Error |
|
128 | + */ |
|
129 | + public static function initialize_db_content() |
|
130 | + { |
|
131 | + // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
132 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | + return; |
|
134 | + } |
|
135 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
136 | + |
|
137 | + EEH_Activation::initialize_system_questions(); |
|
138 | + EEH_Activation::insert_default_status_codes(); |
|
139 | + EEH_Activation::generate_default_message_templates(); |
|
140 | + EEH_Activation::create_no_ticket_prices_array(); |
|
141 | + EEH_Activation::removeEmailConfirmFromAddressGroup(); |
|
142 | + |
|
143 | + EEH_Activation::validate_messages_system(); |
|
144 | + EEH_Activation::insert_default_payment_methods(); |
|
145 | + // in case we've |
|
146 | + EEH_Activation::remove_cron_tasks(); |
|
147 | + EEH_Activation::create_cron_tasks(); |
|
148 | + // remove all TXN locks since that is being done via extra meta now |
|
149 | + delete_option('ee_locked_transactions'); |
|
150 | + // also, check for CAF default db content |
|
151 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
152 | + // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
153 | + // which users really won't care about on initial activation |
|
154 | + EE_Error::overwrite_success(); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
160 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
161 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
162 | + * (null) |
|
163 | + * |
|
164 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
165 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
166 | + * @return array |
|
167 | + * @throws \EE_Error |
|
168 | + */ |
|
169 | + public static function get_cron_tasks($which_to_include) |
|
170 | + { |
|
171 | + $cron_tasks = apply_filters( |
|
172 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
173 | + array( |
|
174 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
175 | + // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
176 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
177 | + // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
178 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
179 | + ) |
|
180 | + ); |
|
181 | + if ($which_to_include === 'old') { |
|
182 | + $cron_tasks = array_filter( |
|
183 | + $cron_tasks, |
|
184 | + function ($value) { |
|
185 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
186 | + } |
|
187 | + ); |
|
188 | + } elseif ($which_to_include === 'current') { |
|
189 | + $cron_tasks = array_filter($cron_tasks); |
|
190 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
191 | + throw new EE_Error( |
|
192 | + sprintf( |
|
193 | + __( |
|
194 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $which_to_include |
|
198 | + ) |
|
199 | + ); |
|
200 | + } |
|
201 | + return $cron_tasks; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
207 | + * |
|
208 | + * @throws \EE_Error |
|
209 | + */ |
|
210 | + public static function create_cron_tasks() |
|
211 | + { |
|
212 | + |
|
213 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
214 | + if (! wp_next_scheduled($hook_name)) { |
|
215 | + /** |
|
216 | + * This allows client code to define the initial start timestamp for this schedule. |
|
217 | + */ |
|
218 | + if (is_array($frequency) |
|
219 | + && count($frequency) === 2 |
|
220 | + && isset($frequency[0], $frequency[1]) |
|
221 | + ) { |
|
222 | + $start_timestamp = $frequency[0]; |
|
223 | + $frequency = $frequency[1]; |
|
224 | + } else { |
|
225 | + $start_timestamp = time(); |
|
226 | + } |
|
227 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * Remove the currently-existing and now-removed cron tasks. |
|
235 | + * |
|
236 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
237 | + * @throws \EE_Error |
|
238 | + */ |
|
239 | + public static function remove_cron_tasks($remove_all = true) |
|
240 | + { |
|
241 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
242 | + $crons = _get_cron_array(); |
|
243 | + $crons = is_array($crons) ? $crons : array(); |
|
244 | + /* reminder of what $crons look like: |
|
245 | 245 | * Top-level keys are timestamps, and their values are arrays. |
246 | 246 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
247 | 247 | * and their values are arrays. |
@@ -258,925 +258,925 @@ discard block |
||
258 | 258 | * ... |
259 | 259 | * ... |
260 | 260 | */ |
261 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
262 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
263 | - if (is_array($hooks_to_fire_at_time)) { |
|
264 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
265 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
267 | - ) { |
|
268 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
269 | - } |
|
270 | - } |
|
271 | - // also take care of any empty cron timestamps. |
|
272 | - if (empty($hooks_to_fire_at_time)) { |
|
273 | - unset($crons[ $timestamp ]); |
|
274 | - } |
|
275 | - } |
|
276 | - } |
|
277 | - _set_cron_array($crons); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * CPT_initialization |
|
283 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
284 | - * |
|
285 | - * @access public |
|
286 | - * @static |
|
287 | - * @return void |
|
288 | - */ |
|
289 | - public static function CPT_initialization() |
|
290 | - { |
|
291 | - // register Custom Post Types |
|
292 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
293 | - flush_rewrite_rules(); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * reset_and_update_config |
|
300 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
301 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
302 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
303 | - * |
|
304 | - * @access public |
|
305 | - * @static |
|
306 | - * @return void |
|
307 | - */ |
|
308 | - public static function reset_and_update_config() |
|
309 | - { |
|
310 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
311 | - add_filter( |
|
312 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
313 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
314 | - 10, |
|
315 | - 3 |
|
316 | - ); |
|
317 | - // EE_Config::reset(); |
|
318 | - if (! EE_Config::logging_enabled()) { |
|
319 | - delete_option(EE_Config::LOG_NAME); |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * load_calendar_config |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @return void |
|
329 | - */ |
|
330 | - public static function load_calendar_config() |
|
331 | - { |
|
332 | - // grab array of all plugin folders and loop thru it |
|
333 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
334 | - if (empty($plugins)) { |
|
335 | - return; |
|
336 | - } |
|
337 | - foreach ($plugins as $plugin_path) { |
|
338 | - // grab plugin folder name from path |
|
339 | - $plugin = basename($plugin_path); |
|
340 | - // drill down to Espresso plugins |
|
341 | - // then to calendar related plugins |
|
342 | - if (strpos($plugin, 'espresso') !== false |
|
343 | - || strpos($plugin, 'Espresso') !== false |
|
344 | - || strpos($plugin, 'ee4') !== false |
|
345 | - || strpos($plugin, 'EE4') !== false |
|
346 | - || strpos($plugin, 'calendar') !== false |
|
347 | - ) { |
|
348 | - // this is what we are looking for |
|
349 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
350 | - // does it exist in this folder ? |
|
351 | - if (is_readable($calendar_config)) { |
|
352 | - // YEAH! let's load it |
|
353 | - require_once($calendar_config); |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * _migrate_old_config_data |
|
363 | - * |
|
364 | - * @access public |
|
365 | - * @param array|stdClass $settings |
|
366 | - * @param string $config |
|
367 | - * @param \EE_Config $EE_Config |
|
368 | - * @return \stdClass |
|
369 | - */ |
|
370 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
371 | - { |
|
372 | - $convert_from_array = array('addons'); |
|
373 | - // in case old settings were saved as an array |
|
374 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
375 | - // convert existing settings to an object |
|
376 | - $config_array = $settings; |
|
377 | - $settings = new stdClass(); |
|
378 | - foreach ($config_array as $key => $value) { |
|
379 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
380 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
381 | - } else { |
|
382 | - $settings->{$key} = $value; |
|
383 | - } |
|
384 | - } |
|
385 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
386 | - } |
|
387 | - return $settings; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * deactivate_event_espresso |
|
393 | - * |
|
394 | - * @access public |
|
395 | - * @static |
|
396 | - * @return void |
|
397 | - */ |
|
398 | - public static function deactivate_event_espresso() |
|
399 | - { |
|
400 | - // check permissions |
|
401 | - if (current_user_can('activate_plugins')) { |
|
402 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * verify_default_pages_exist |
|
410 | - * |
|
411 | - * @access public |
|
412 | - * @static |
|
413 | - * @return void |
|
414 | - * @throws InvalidDataTypeException |
|
415 | - */ |
|
416 | - public static function verify_default_pages_exist() |
|
417 | - { |
|
418 | - $critical_page_problem = false; |
|
419 | - $critical_pages = array( |
|
420 | - array( |
|
421 | - 'id' => 'reg_page_id', |
|
422 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
423 | - 'post' => null, |
|
424 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
425 | - ), |
|
426 | - array( |
|
427 | - 'id' => 'txn_page_id', |
|
428 | - 'name' => __('Transactions', 'event_espresso'), |
|
429 | - 'post' => null, |
|
430 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
431 | - ), |
|
432 | - array( |
|
433 | - 'id' => 'thank_you_page_id', |
|
434 | - 'name' => __('Thank You', 'event_espresso'), |
|
435 | - 'post' => null, |
|
436 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
437 | - ), |
|
438 | - array( |
|
439 | - 'id' => 'cancel_page_id', |
|
440 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
441 | - 'post' => null, |
|
442 | - 'code' => 'ESPRESSO_CANCELLED', |
|
443 | - ), |
|
444 | - ); |
|
445 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
446 | - foreach ($critical_pages as $critical_page) { |
|
447 | - // is critical page ID set in config ? |
|
448 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
449 | - // attempt to find post by ID |
|
450 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
451 | - } |
|
452 | - // no dice? |
|
453 | - if ($critical_page['post'] === null) { |
|
454 | - // attempt to find post by title |
|
455 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
456 | - // still nothing? |
|
457 | - if ($critical_page['post'] === null) { |
|
458 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
459 | - // REALLY? Still nothing ??!?!? |
|
460 | - if ($critical_page['post'] === null) { |
|
461 | - $msg = __( |
|
462 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
463 | - 'event_espresso' |
|
464 | - ); |
|
465 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
466 | - break; |
|
467 | - } |
|
468 | - } |
|
469 | - } |
|
470 | - // check that Post ID matches critical page ID in config |
|
471 | - if (isset($critical_page['post']->ID) |
|
472 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
473 | - ) { |
|
474 | - // update Config with post ID |
|
475 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
476 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
477 | - $msg = __( |
|
478 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
479 | - 'event_espresso' |
|
480 | - ); |
|
481 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
482 | - } |
|
483 | - } |
|
484 | - $critical_page_problem = |
|
485 | - ! isset($critical_page['post']->post_status) |
|
486 | - || $critical_page['post']->post_status !== 'publish' |
|
487 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
488 | - ? true |
|
489 | - : $critical_page_problem; |
|
490 | - } |
|
491 | - if ($critical_page_problem) { |
|
492 | - new PersistentAdminNotice( |
|
493 | - 'critical_page_problem', |
|
494 | - sprintf( |
|
495 | - esc_html__( |
|
496 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
497 | - 'event_espresso' |
|
498 | - ), |
|
499 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
500 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
501 | - . '</a>' |
|
502 | - ) |
|
503 | - ); |
|
504 | - } |
|
505 | - if (EE_Error::has_notices()) { |
|
506 | - EE_Error::get_notices(false, true, true); |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Returns the first post which uses the specified shortcode |
|
514 | - * |
|
515 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
516 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
517 | - * "[ESPRESSO_THANK_YOU" |
|
518 | - * (we don't search for the closing shortcode bracket because they might have added |
|
519 | - * parameter to the shortcode |
|
520 | - * @return WP_Post or NULl |
|
521 | - */ |
|
522 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
523 | - { |
|
524 | - global $wpdb; |
|
525 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
526 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
527 | - if ($post_id) { |
|
528 | - return get_post($post_id); |
|
529 | - } else { |
|
530 | - return null; |
|
531 | - } |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - /** |
|
536 | - * This function generates a post for critical espresso pages |
|
537 | - * |
|
538 | - * @access public |
|
539 | - * @static |
|
540 | - * @param array $critical_page |
|
541 | - * @return array |
|
542 | - */ |
|
543 | - public static function create_critical_page($critical_page) |
|
544 | - { |
|
545 | - |
|
546 | - $post_args = array( |
|
547 | - 'post_title' => $critical_page['name'], |
|
548 | - 'post_status' => 'publish', |
|
549 | - 'post_type' => 'page', |
|
550 | - 'comment_status' => 'closed', |
|
551 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
552 | - ); |
|
553 | - |
|
554 | - $post_id = wp_insert_post($post_args); |
|
555 | - if (! $post_id) { |
|
556 | - $msg = sprintf( |
|
557 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
558 | - $critical_page['name'] |
|
559 | - ); |
|
560 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
561 | - return $critical_page; |
|
562 | - } |
|
563 | - // get newly created post's details |
|
564 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
565 | - $msg = sprintf( |
|
566 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
567 | - $critical_page['name'] |
|
568 | - ); |
|
569 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
570 | - } |
|
571 | - |
|
572 | - return $critical_page; |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
580 | - * The role being used to check is filterable. |
|
581 | - * |
|
582 | - * @since 4.6.0 |
|
583 | - * @global WPDB $wpdb |
|
584 | - * @return mixed null|int WP_user ID or NULL |
|
585 | - */ |
|
586 | - public static function get_default_creator_id() |
|
587 | - { |
|
588 | - global $wpdb; |
|
589 | - if (! empty(self::$_default_creator_id)) { |
|
590 | - return self::$_default_creator_id; |
|
591 | - }/**/ |
|
592 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
593 | - // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
594 | - $pre_filtered_id = apply_filters( |
|
595 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
596 | - false, |
|
597 | - $role_to_check |
|
598 | - ); |
|
599 | - if ($pre_filtered_id !== false) { |
|
600 | - return (int) $pre_filtered_id; |
|
601 | - } |
|
602 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
603 | - $query = $wpdb->prepare( |
|
604 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
605 | - '%' . $role_to_check . '%' |
|
606 | - ); |
|
607 | - $user_id = $wpdb->get_var($query); |
|
608 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
609 | - if ($user_id && (int) $user_id) { |
|
610 | - self::$_default_creator_id = (int) $user_id; |
|
611 | - return self::$_default_creator_id; |
|
612 | - } else { |
|
613 | - return null; |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * used by EE and EE addons during plugin activation to create tables. |
|
621 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
622 | - * but includes extra logic regarding activations. |
|
623 | - * |
|
624 | - * @access public |
|
625 | - * @static |
|
626 | - * @param string $table_name without the $wpdb->prefix |
|
627 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
628 | - * table query) |
|
629 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
630 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
631 | - * and new once this function is done (ie, you really do want to CREATE a |
|
632 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
633 | - * you just want to verify the table exists and matches this definition |
|
634 | - * (and if it HAS data in it you want to leave it be) |
|
635 | - * @return void |
|
636 | - * @throws EE_Error if there are database errors |
|
637 | - */ |
|
638 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
639 | - { |
|
640 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
641 | - return; |
|
642 | - } |
|
643 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
644 | - if (! function_exists('dbDelta')) { |
|
645 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
646 | - } |
|
647 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
648 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
649 | - // do we need to first delete an existing version of this table ? |
|
650 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
651 | - // ok, delete the table... but ONLY if it's empty |
|
652 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
653 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
654 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
655 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
656 | - } elseif (! $deleted_safely) { |
|
657 | - // so we should be more cautious rather than just dropping tables so easily |
|
658 | - error_log( |
|
659 | - sprintf( |
|
660 | - __( |
|
661 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
662 | - 'event_espresso' |
|
663 | - ), |
|
664 | - $wp_table_name, |
|
665 | - '<br/>', |
|
666 | - 'espresso_db_update' |
|
667 | - ) |
|
668 | - ); |
|
669 | - } |
|
670 | - } |
|
671 | - $engine = str_replace('ENGINE=', '', $engine); |
|
672 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * add_column_if_it_doesn't_exist |
|
679 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
680 | - * |
|
681 | - * @access public |
|
682 | - * @static |
|
683 | - * @deprecated instead use TableManager::addColumn() |
|
684 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
685 | - * @param string $column_name |
|
686 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
687 | - * 'VARCHAR(10)' |
|
688 | - * @return bool|int |
|
689 | - */ |
|
690 | - public static function add_column_if_it_doesnt_exist( |
|
691 | - $table_name, |
|
692 | - $column_name, |
|
693 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
694 | - ) { |
|
695 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * get_fields_on_table |
|
701 | - * Gets all the fields on the database table. |
|
702 | - * |
|
703 | - * @access public |
|
704 | - * @deprecated instead use TableManager::getTableColumns() |
|
705 | - * @static |
|
706 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
707 | - * @return array of database column names |
|
708 | - */ |
|
709 | - public static function get_fields_on_table($table_name = null) |
|
710 | - { |
|
711 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * db_table_is_empty |
|
717 | - * |
|
718 | - * @access public\ |
|
719 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
720 | - * @static |
|
721 | - * @param string $table_name |
|
722 | - * @return bool |
|
723 | - */ |
|
724 | - public static function db_table_is_empty($table_name) |
|
725 | - { |
|
726 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * delete_db_table_if_empty |
|
732 | - * |
|
733 | - * @access public |
|
734 | - * @static |
|
735 | - * @param string $table_name |
|
736 | - * @return bool | int |
|
737 | - */ |
|
738 | - public static function delete_db_table_if_empty($table_name) |
|
739 | - { |
|
740 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
741 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
742 | - } |
|
743 | - return false; |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * delete_unused_db_table |
|
749 | - * |
|
750 | - * @access public |
|
751 | - * @static |
|
752 | - * @deprecated instead use TableManager::dropTable() |
|
753 | - * @param string $table_name |
|
754 | - * @return bool | int |
|
755 | - */ |
|
756 | - public static function delete_unused_db_table($table_name) |
|
757 | - { |
|
758 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * drop_index |
|
764 | - * |
|
765 | - * @access public |
|
766 | - * @static |
|
767 | - * @deprecated instead use TableManager::dropIndex() |
|
768 | - * @param string $table_name |
|
769 | - * @param string $index_name |
|
770 | - * @return bool | int |
|
771 | - */ |
|
772 | - public static function drop_index($table_name, $index_name) |
|
773 | - { |
|
774 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - |
|
779 | - /** |
|
780 | - * create_database_tables |
|
781 | - * |
|
782 | - * @access public |
|
783 | - * @static |
|
784 | - * @throws EE_Error |
|
785 | - * @return boolean success (whether database is setup properly or not) |
|
786 | - */ |
|
787 | - public static function create_database_tables() |
|
788 | - { |
|
789 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
790 | - // find the migration script that sets the database to be compatible with the code |
|
791 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
792 | - if ($dms_name) { |
|
793 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
794 | - $current_data_migration_script->set_migrating(false); |
|
795 | - $current_data_migration_script->schema_changes_before_migration(); |
|
796 | - $current_data_migration_script->schema_changes_after_migration(); |
|
797 | - if ($current_data_migration_script->get_errors()) { |
|
798 | - if (WP_DEBUG) { |
|
799 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
800 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
801 | - } |
|
802 | - } else { |
|
803 | - EE_Error::add_error( |
|
804 | - __( |
|
805 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
261 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
262 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
263 | + if (is_array($hooks_to_fire_at_time)) { |
|
264 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
265 | + if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | + && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
267 | + ) { |
|
268 | + unset($crons[ $timestamp ][ $hook_name ]); |
|
269 | + } |
|
270 | + } |
|
271 | + // also take care of any empty cron timestamps. |
|
272 | + if (empty($hooks_to_fire_at_time)) { |
|
273 | + unset($crons[ $timestamp ]); |
|
274 | + } |
|
275 | + } |
|
276 | + } |
|
277 | + _set_cron_array($crons); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * CPT_initialization |
|
283 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
284 | + * |
|
285 | + * @access public |
|
286 | + * @static |
|
287 | + * @return void |
|
288 | + */ |
|
289 | + public static function CPT_initialization() |
|
290 | + { |
|
291 | + // register Custom Post Types |
|
292 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
293 | + flush_rewrite_rules(); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * reset_and_update_config |
|
300 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
301 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
302 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
303 | + * |
|
304 | + * @access public |
|
305 | + * @static |
|
306 | + * @return void |
|
307 | + */ |
|
308 | + public static function reset_and_update_config() |
|
309 | + { |
|
310 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
311 | + add_filter( |
|
312 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
313 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
314 | + 10, |
|
315 | + 3 |
|
316 | + ); |
|
317 | + // EE_Config::reset(); |
|
318 | + if (! EE_Config::logging_enabled()) { |
|
319 | + delete_option(EE_Config::LOG_NAME); |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * load_calendar_config |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @return void |
|
329 | + */ |
|
330 | + public static function load_calendar_config() |
|
331 | + { |
|
332 | + // grab array of all plugin folders and loop thru it |
|
333 | + $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
334 | + if (empty($plugins)) { |
|
335 | + return; |
|
336 | + } |
|
337 | + foreach ($plugins as $plugin_path) { |
|
338 | + // grab plugin folder name from path |
|
339 | + $plugin = basename($plugin_path); |
|
340 | + // drill down to Espresso plugins |
|
341 | + // then to calendar related plugins |
|
342 | + if (strpos($plugin, 'espresso') !== false |
|
343 | + || strpos($plugin, 'Espresso') !== false |
|
344 | + || strpos($plugin, 'ee4') !== false |
|
345 | + || strpos($plugin, 'EE4') !== false |
|
346 | + || strpos($plugin, 'calendar') !== false |
|
347 | + ) { |
|
348 | + // this is what we are looking for |
|
349 | + $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
350 | + // does it exist in this folder ? |
|
351 | + if (is_readable($calendar_config)) { |
|
352 | + // YEAH! let's load it |
|
353 | + require_once($calendar_config); |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * _migrate_old_config_data |
|
363 | + * |
|
364 | + * @access public |
|
365 | + * @param array|stdClass $settings |
|
366 | + * @param string $config |
|
367 | + * @param \EE_Config $EE_Config |
|
368 | + * @return \stdClass |
|
369 | + */ |
|
370 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
371 | + { |
|
372 | + $convert_from_array = array('addons'); |
|
373 | + // in case old settings were saved as an array |
|
374 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
375 | + // convert existing settings to an object |
|
376 | + $config_array = $settings; |
|
377 | + $settings = new stdClass(); |
|
378 | + foreach ($config_array as $key => $value) { |
|
379 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
380 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
381 | + } else { |
|
382 | + $settings->{$key} = $value; |
|
383 | + } |
|
384 | + } |
|
385 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
386 | + } |
|
387 | + return $settings; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * deactivate_event_espresso |
|
393 | + * |
|
394 | + * @access public |
|
395 | + * @static |
|
396 | + * @return void |
|
397 | + */ |
|
398 | + public static function deactivate_event_espresso() |
|
399 | + { |
|
400 | + // check permissions |
|
401 | + if (current_user_can('activate_plugins')) { |
|
402 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * verify_default_pages_exist |
|
410 | + * |
|
411 | + * @access public |
|
412 | + * @static |
|
413 | + * @return void |
|
414 | + * @throws InvalidDataTypeException |
|
415 | + */ |
|
416 | + public static function verify_default_pages_exist() |
|
417 | + { |
|
418 | + $critical_page_problem = false; |
|
419 | + $critical_pages = array( |
|
420 | + array( |
|
421 | + 'id' => 'reg_page_id', |
|
422 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
423 | + 'post' => null, |
|
424 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
425 | + ), |
|
426 | + array( |
|
427 | + 'id' => 'txn_page_id', |
|
428 | + 'name' => __('Transactions', 'event_espresso'), |
|
429 | + 'post' => null, |
|
430 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
431 | + ), |
|
432 | + array( |
|
433 | + 'id' => 'thank_you_page_id', |
|
434 | + 'name' => __('Thank You', 'event_espresso'), |
|
435 | + 'post' => null, |
|
436 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
437 | + ), |
|
438 | + array( |
|
439 | + 'id' => 'cancel_page_id', |
|
440 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
441 | + 'post' => null, |
|
442 | + 'code' => 'ESPRESSO_CANCELLED', |
|
443 | + ), |
|
444 | + ); |
|
445 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
446 | + foreach ($critical_pages as $critical_page) { |
|
447 | + // is critical page ID set in config ? |
|
448 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
449 | + // attempt to find post by ID |
|
450 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
451 | + } |
|
452 | + // no dice? |
|
453 | + if ($critical_page['post'] === null) { |
|
454 | + // attempt to find post by title |
|
455 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
456 | + // still nothing? |
|
457 | + if ($critical_page['post'] === null) { |
|
458 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
459 | + // REALLY? Still nothing ??!?!? |
|
460 | + if ($critical_page['post'] === null) { |
|
461 | + $msg = __( |
|
462 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
463 | + 'event_espresso' |
|
464 | + ); |
|
465 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
466 | + break; |
|
467 | + } |
|
468 | + } |
|
469 | + } |
|
470 | + // check that Post ID matches critical page ID in config |
|
471 | + if (isset($critical_page['post']->ID) |
|
472 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
473 | + ) { |
|
474 | + // update Config with post ID |
|
475 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
476 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
477 | + $msg = __( |
|
478 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
479 | + 'event_espresso' |
|
480 | + ); |
|
481 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
482 | + } |
|
483 | + } |
|
484 | + $critical_page_problem = |
|
485 | + ! isset($critical_page['post']->post_status) |
|
486 | + || $critical_page['post']->post_status !== 'publish' |
|
487 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
488 | + ? true |
|
489 | + : $critical_page_problem; |
|
490 | + } |
|
491 | + if ($critical_page_problem) { |
|
492 | + new PersistentAdminNotice( |
|
493 | + 'critical_page_problem', |
|
494 | + sprintf( |
|
495 | + esc_html__( |
|
496 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
497 | + 'event_espresso' |
|
498 | + ), |
|
499 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
500 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
501 | + . '</a>' |
|
502 | + ) |
|
503 | + ); |
|
504 | + } |
|
505 | + if (EE_Error::has_notices()) { |
|
506 | + EE_Error::get_notices(false, true, true); |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Returns the first post which uses the specified shortcode |
|
514 | + * |
|
515 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
516 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
517 | + * "[ESPRESSO_THANK_YOU" |
|
518 | + * (we don't search for the closing shortcode bracket because they might have added |
|
519 | + * parameter to the shortcode |
|
520 | + * @return WP_Post or NULl |
|
521 | + */ |
|
522 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
523 | + { |
|
524 | + global $wpdb; |
|
525 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
526 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
527 | + if ($post_id) { |
|
528 | + return get_post($post_id); |
|
529 | + } else { |
|
530 | + return null; |
|
531 | + } |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + /** |
|
536 | + * This function generates a post for critical espresso pages |
|
537 | + * |
|
538 | + * @access public |
|
539 | + * @static |
|
540 | + * @param array $critical_page |
|
541 | + * @return array |
|
542 | + */ |
|
543 | + public static function create_critical_page($critical_page) |
|
544 | + { |
|
545 | + |
|
546 | + $post_args = array( |
|
547 | + 'post_title' => $critical_page['name'], |
|
548 | + 'post_status' => 'publish', |
|
549 | + 'post_type' => 'page', |
|
550 | + 'comment_status' => 'closed', |
|
551 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
552 | + ); |
|
553 | + |
|
554 | + $post_id = wp_insert_post($post_args); |
|
555 | + if (! $post_id) { |
|
556 | + $msg = sprintf( |
|
557 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
558 | + $critical_page['name'] |
|
559 | + ); |
|
560 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
561 | + return $critical_page; |
|
562 | + } |
|
563 | + // get newly created post's details |
|
564 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
565 | + $msg = sprintf( |
|
566 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
567 | + $critical_page['name'] |
|
568 | + ); |
|
569 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
570 | + } |
|
571 | + |
|
572 | + return $critical_page; |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
580 | + * The role being used to check is filterable. |
|
581 | + * |
|
582 | + * @since 4.6.0 |
|
583 | + * @global WPDB $wpdb |
|
584 | + * @return mixed null|int WP_user ID or NULL |
|
585 | + */ |
|
586 | + public static function get_default_creator_id() |
|
587 | + { |
|
588 | + global $wpdb; |
|
589 | + if (! empty(self::$_default_creator_id)) { |
|
590 | + return self::$_default_creator_id; |
|
591 | + }/**/ |
|
592 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
593 | + // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
594 | + $pre_filtered_id = apply_filters( |
|
595 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
596 | + false, |
|
597 | + $role_to_check |
|
598 | + ); |
|
599 | + if ($pre_filtered_id !== false) { |
|
600 | + return (int) $pre_filtered_id; |
|
601 | + } |
|
602 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
603 | + $query = $wpdb->prepare( |
|
604 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
605 | + '%' . $role_to_check . '%' |
|
606 | + ); |
|
607 | + $user_id = $wpdb->get_var($query); |
|
608 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
609 | + if ($user_id && (int) $user_id) { |
|
610 | + self::$_default_creator_id = (int) $user_id; |
|
611 | + return self::$_default_creator_id; |
|
612 | + } else { |
|
613 | + return null; |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * used by EE and EE addons during plugin activation to create tables. |
|
621 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
622 | + * but includes extra logic regarding activations. |
|
623 | + * |
|
624 | + * @access public |
|
625 | + * @static |
|
626 | + * @param string $table_name without the $wpdb->prefix |
|
627 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
628 | + * table query) |
|
629 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
630 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
631 | + * and new once this function is done (ie, you really do want to CREATE a |
|
632 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
633 | + * you just want to verify the table exists and matches this definition |
|
634 | + * (and if it HAS data in it you want to leave it be) |
|
635 | + * @return void |
|
636 | + * @throws EE_Error if there are database errors |
|
637 | + */ |
|
638 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
639 | + { |
|
640 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
641 | + return; |
|
642 | + } |
|
643 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
644 | + if (! function_exists('dbDelta')) { |
|
645 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
646 | + } |
|
647 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
648 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
649 | + // do we need to first delete an existing version of this table ? |
|
650 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
651 | + // ok, delete the table... but ONLY if it's empty |
|
652 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
653 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
654 | + if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
655 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
656 | + } elseif (! $deleted_safely) { |
|
657 | + // so we should be more cautious rather than just dropping tables so easily |
|
658 | + error_log( |
|
659 | + sprintf( |
|
660 | + __( |
|
661 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
662 | + 'event_espresso' |
|
663 | + ), |
|
664 | + $wp_table_name, |
|
665 | + '<br/>', |
|
666 | + 'espresso_db_update' |
|
667 | + ) |
|
668 | + ); |
|
669 | + } |
|
670 | + } |
|
671 | + $engine = str_replace('ENGINE=', '', $engine); |
|
672 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * add_column_if_it_doesn't_exist |
|
679 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
680 | + * |
|
681 | + * @access public |
|
682 | + * @static |
|
683 | + * @deprecated instead use TableManager::addColumn() |
|
684 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
685 | + * @param string $column_name |
|
686 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
687 | + * 'VARCHAR(10)' |
|
688 | + * @return bool|int |
|
689 | + */ |
|
690 | + public static function add_column_if_it_doesnt_exist( |
|
691 | + $table_name, |
|
692 | + $column_name, |
|
693 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
694 | + ) { |
|
695 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * get_fields_on_table |
|
701 | + * Gets all the fields on the database table. |
|
702 | + * |
|
703 | + * @access public |
|
704 | + * @deprecated instead use TableManager::getTableColumns() |
|
705 | + * @static |
|
706 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
707 | + * @return array of database column names |
|
708 | + */ |
|
709 | + public static function get_fields_on_table($table_name = null) |
|
710 | + { |
|
711 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * db_table_is_empty |
|
717 | + * |
|
718 | + * @access public\ |
|
719 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
720 | + * @static |
|
721 | + * @param string $table_name |
|
722 | + * @return bool |
|
723 | + */ |
|
724 | + public static function db_table_is_empty($table_name) |
|
725 | + { |
|
726 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * delete_db_table_if_empty |
|
732 | + * |
|
733 | + * @access public |
|
734 | + * @static |
|
735 | + * @param string $table_name |
|
736 | + * @return bool | int |
|
737 | + */ |
|
738 | + public static function delete_db_table_if_empty($table_name) |
|
739 | + { |
|
740 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
741 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
742 | + } |
|
743 | + return false; |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * delete_unused_db_table |
|
749 | + * |
|
750 | + * @access public |
|
751 | + * @static |
|
752 | + * @deprecated instead use TableManager::dropTable() |
|
753 | + * @param string $table_name |
|
754 | + * @return bool | int |
|
755 | + */ |
|
756 | + public static function delete_unused_db_table($table_name) |
|
757 | + { |
|
758 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * drop_index |
|
764 | + * |
|
765 | + * @access public |
|
766 | + * @static |
|
767 | + * @deprecated instead use TableManager::dropIndex() |
|
768 | + * @param string $table_name |
|
769 | + * @param string $index_name |
|
770 | + * @return bool | int |
|
771 | + */ |
|
772 | + public static function drop_index($table_name, $index_name) |
|
773 | + { |
|
774 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + |
|
779 | + /** |
|
780 | + * create_database_tables |
|
781 | + * |
|
782 | + * @access public |
|
783 | + * @static |
|
784 | + * @throws EE_Error |
|
785 | + * @return boolean success (whether database is setup properly or not) |
|
786 | + */ |
|
787 | + public static function create_database_tables() |
|
788 | + { |
|
789 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
790 | + // find the migration script that sets the database to be compatible with the code |
|
791 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
792 | + if ($dms_name) { |
|
793 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
794 | + $current_data_migration_script->set_migrating(false); |
|
795 | + $current_data_migration_script->schema_changes_before_migration(); |
|
796 | + $current_data_migration_script->schema_changes_after_migration(); |
|
797 | + if ($current_data_migration_script->get_errors()) { |
|
798 | + if (WP_DEBUG) { |
|
799 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
800 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
801 | + } |
|
802 | + } else { |
|
803 | + EE_Error::add_error( |
|
804 | + __( |
|
805 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
806 | 806 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
807 | - 'event_espresso' |
|
808 | - ) |
|
809 | - ); |
|
810 | - } |
|
811 | - return false; |
|
812 | - } |
|
813 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
814 | - } else { |
|
815 | - EE_Error::add_error( |
|
816 | - __( |
|
817 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
807 | + 'event_espresso' |
|
808 | + ) |
|
809 | + ); |
|
810 | + } |
|
811 | + return false; |
|
812 | + } |
|
813 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
814 | + } else { |
|
815 | + EE_Error::add_error( |
|
816 | + __( |
|
817 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
818 | 818 | structure. So database is probably not setup properly', |
819 | - 'event_espresso' |
|
820 | - ), |
|
821 | - __FILE__, |
|
822 | - __FUNCTION__, |
|
823 | - __LINE__ |
|
824 | - ); |
|
825 | - return false; |
|
826 | - } |
|
827 | - return true; |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * initialize_system_questions |
|
834 | - * |
|
835 | - * @access public |
|
836 | - * @static |
|
837 | - * @return void |
|
838 | - */ |
|
839 | - public static function initialize_system_questions() |
|
840 | - { |
|
841 | - // QUESTION GROUPS |
|
842 | - global $wpdb; |
|
843 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
844 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
845 | - // what we have |
|
846 | - $question_groups = $wpdb->get_col($SQL); |
|
847 | - // check the response |
|
848 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
849 | - // what we should have |
|
850 | - $QSG_systems = array(1, 2); |
|
851 | - // loop thru what we should have and compare to what we have |
|
852 | - foreach ($QSG_systems as $QSG_system) { |
|
853 | - // reset values array |
|
854 | - $QSG_values = array(); |
|
855 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
856 | - if (! in_array("$QSG_system", $question_groups)) { |
|
857 | - // add it |
|
858 | - switch ($QSG_system) { |
|
859 | - case 1: |
|
860 | - $QSG_values = array( |
|
861 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
862 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
863 | - 'QSG_desc' => '', |
|
864 | - 'QSG_order' => 1, |
|
865 | - 'QSG_show_group_name' => 1, |
|
866 | - 'QSG_show_group_desc' => 1, |
|
867 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
868 | - 'QSG_deleted' => 0, |
|
869 | - ); |
|
870 | - break; |
|
871 | - case 2: |
|
872 | - $QSG_values = array( |
|
873 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
874 | - 'QSG_identifier' => 'address-information-' . time(), |
|
875 | - 'QSG_desc' => '', |
|
876 | - 'QSG_order' => 2, |
|
877 | - 'QSG_show_group_name' => 1, |
|
878 | - 'QSG_show_group_desc' => 1, |
|
879 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
880 | - 'QSG_deleted' => 0, |
|
881 | - ); |
|
882 | - break; |
|
883 | - } |
|
884 | - // make sure we have some values before inserting them |
|
885 | - if (! empty($QSG_values)) { |
|
886 | - // insert system question |
|
887 | - $wpdb->insert( |
|
888 | - $table_name, |
|
889 | - $QSG_values, |
|
890 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
891 | - ); |
|
892 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
893 | - } |
|
894 | - } |
|
895 | - } |
|
896 | - // QUESTIONS |
|
897 | - global $wpdb; |
|
898 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
899 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
900 | - // what we have |
|
901 | - $questions = $wpdb->get_col($SQL); |
|
902 | - // all system questions |
|
903 | - $personal_system_group_questions = ['fname', 'lname', 'email']; |
|
904 | - $address_system_group_questions = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone']; |
|
905 | - $system_questions_not_in_group = ['email_confirm']; |
|
906 | - // merge all of the system questions we should have |
|
907 | - $QST_systems = array_merge( |
|
908 | - $personal_system_group_questions, |
|
909 | - $address_system_group_questions, |
|
910 | - $system_questions_not_in_group |
|
911 | - ); |
|
912 | - $order_for_group_1 = 1; |
|
913 | - $order_for_group_2 = 1; |
|
914 | - // loop thru what we should have and compare to what we have |
|
915 | - foreach ($QST_systems as $QST_system) { |
|
916 | - // reset values array |
|
917 | - $QST_values = array(); |
|
918 | - // if we don't have what we should have |
|
919 | - if (! in_array($QST_system, $questions)) { |
|
920 | - // add it |
|
921 | - switch ($QST_system) { |
|
922 | - case 'fname': |
|
923 | - $QST_values = array( |
|
924 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
925 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
926 | - 'QST_system' => 'fname', |
|
927 | - 'QST_type' => 'TEXT', |
|
928 | - 'QST_required' => 1, |
|
929 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
930 | - 'QST_order' => 1, |
|
931 | - 'QST_admin_only' => 0, |
|
932 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
933 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
934 | - 'QST_deleted' => 0, |
|
935 | - ); |
|
936 | - break; |
|
937 | - case 'lname': |
|
938 | - $QST_values = array( |
|
939 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
940 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
941 | - 'QST_system' => 'lname', |
|
942 | - 'QST_type' => 'TEXT', |
|
943 | - 'QST_required' => 1, |
|
944 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
945 | - 'QST_order' => 2, |
|
946 | - 'QST_admin_only' => 0, |
|
947 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
948 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
949 | - 'QST_deleted' => 0, |
|
950 | - ); |
|
951 | - break; |
|
952 | - case 'email': |
|
953 | - $QST_values = array( |
|
954 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
955 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
956 | - 'QST_system' => 'email', |
|
957 | - 'QST_type' => 'EMAIL', |
|
958 | - 'QST_required' => 1, |
|
959 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
960 | - 'QST_order' => 3, |
|
961 | - 'QST_admin_only' => 0, |
|
962 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
963 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
964 | - 'QST_deleted' => 0, |
|
965 | - ); |
|
966 | - break; |
|
967 | - case 'email_confirm': |
|
968 | - $QST_values = array( |
|
969 | - 'QST_display_text' => __('Confirm Email Address', 'event_espresso'), |
|
970 | - 'QST_admin_label' => __('Confirm Email Address - System Question', 'event_espresso'), |
|
971 | - 'QST_system' => 'email_confirm', |
|
972 | - 'QST_type' => 'EMAIL_CONFIRM', |
|
973 | - 'QST_required' => 1, |
|
974 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
975 | - 'QST_order' => 4, |
|
976 | - 'QST_admin_only' => 0, |
|
977 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
978 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
979 | - 'QST_deleted' => 0, |
|
980 | - ); |
|
981 | - break; |
|
982 | - case 'address': |
|
983 | - $QST_values = array( |
|
984 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
985 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
986 | - 'QST_system' => 'address', |
|
987 | - 'QST_type' => 'TEXT', |
|
988 | - 'QST_required' => 0, |
|
989 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
990 | - 'QST_order' => 5, |
|
991 | - 'QST_admin_only' => 0, |
|
992 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
993 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
994 | - 'QST_deleted' => 0, |
|
995 | - ); |
|
996 | - break; |
|
997 | - case 'address2': |
|
998 | - $QST_values = array( |
|
999 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1000 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1001 | - 'QST_system' => 'address2', |
|
1002 | - 'QST_type' => 'TEXT', |
|
1003 | - 'QST_required' => 0, |
|
1004 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1005 | - 'QST_order' => 6, |
|
1006 | - 'QST_admin_only' => 0, |
|
1007 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1008 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1009 | - 'QST_deleted' => 0, |
|
1010 | - ); |
|
1011 | - break; |
|
1012 | - case 'city': |
|
1013 | - $QST_values = array( |
|
1014 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1015 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1016 | - 'QST_system' => 'city', |
|
1017 | - 'QST_type' => 'TEXT', |
|
1018 | - 'QST_required' => 0, |
|
1019 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1020 | - 'QST_order' => 7, |
|
1021 | - 'QST_admin_only' => 0, |
|
1022 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1023 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1024 | - 'QST_deleted' => 0, |
|
1025 | - ); |
|
1026 | - break; |
|
1027 | - case 'country': |
|
1028 | - $QST_values = array( |
|
1029 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1030 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1031 | - 'QST_system' => 'country', |
|
1032 | - 'QST_type' => 'COUNTRY', |
|
1033 | - 'QST_required' => 0, |
|
1034 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1035 | - 'QST_order' => 8, |
|
1036 | - 'QST_admin_only' => 0, |
|
1037 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1038 | - 'QST_deleted' => 0, |
|
1039 | - ); |
|
1040 | - break; |
|
1041 | - case 'state': |
|
1042 | - $QST_values = array( |
|
1043 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1044 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1045 | - 'QST_system' => 'state', |
|
1046 | - 'QST_type' => 'STATE', |
|
1047 | - 'QST_required' => 0, |
|
1048 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1049 | - 'QST_order' => 9, |
|
1050 | - 'QST_admin_only' => 0, |
|
1051 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1052 | - 'QST_deleted' => 0, |
|
1053 | - ); |
|
1054 | - break; |
|
1055 | - case 'zip': |
|
1056 | - $QST_values = array( |
|
1057 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1058 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1059 | - 'QST_system' => 'zip', |
|
1060 | - 'QST_type' => 'TEXT', |
|
1061 | - 'QST_required' => 0, |
|
1062 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1063 | - 'QST_order' => 10, |
|
1064 | - 'QST_admin_only' => 0, |
|
1065 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1066 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1067 | - 'QST_deleted' => 0, |
|
1068 | - ); |
|
1069 | - break; |
|
1070 | - case 'phone': |
|
1071 | - $QST_values = array( |
|
1072 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1073 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1074 | - 'QST_system' => 'phone', |
|
1075 | - 'QST_type' => 'TEXT', |
|
1076 | - 'QST_required' => 0, |
|
1077 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1078 | - 'QST_order' => 11, |
|
1079 | - 'QST_admin_only' => 0, |
|
1080 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1081 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1082 | - 'QST_deleted' => 0, |
|
1083 | - ); |
|
1084 | - break; |
|
1085 | - } |
|
1086 | - if (! empty($QST_values)) { |
|
1087 | - // insert system question |
|
1088 | - $wpdb->insert( |
|
1089 | - $table_name, |
|
1090 | - $QST_values, |
|
1091 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1092 | - ); |
|
1093 | - $QST_ID = $wpdb->insert_id; |
|
1094 | - |
|
1095 | - // QUESTION GROUP QUESTIONS |
|
1096 | - if (in_array($QST_system, $personal_system_group_questions)) { |
|
1097 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1098 | - } elseif (in_array($QST_system, $address_system_group_questions)) { |
|
1099 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1100 | - } else { |
|
1101 | - // QST_system should not be assigned to any group |
|
1102 | - continue; |
|
1103 | - } |
|
1104 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1105 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1106 | - } else { |
|
1107 | - $id_col = EEM_Question_Group::instance() |
|
1108 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | - if (is_array($id_col)) { |
|
1110 | - $QSG_ID = reset($id_col); |
|
1111 | - } else { |
|
1112 | - // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | - EE_Log::instance()->log( |
|
1114 | - __FILE__, |
|
1115 | - __FUNCTION__, |
|
1116 | - sprintf( |
|
1117 | - __( |
|
1118 | - 'Could not associate question %1$s to a question group because no system question |
|
819 | + 'event_espresso' |
|
820 | + ), |
|
821 | + __FILE__, |
|
822 | + __FUNCTION__, |
|
823 | + __LINE__ |
|
824 | + ); |
|
825 | + return false; |
|
826 | + } |
|
827 | + return true; |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * initialize_system_questions |
|
834 | + * |
|
835 | + * @access public |
|
836 | + * @static |
|
837 | + * @return void |
|
838 | + */ |
|
839 | + public static function initialize_system_questions() |
|
840 | + { |
|
841 | + // QUESTION GROUPS |
|
842 | + global $wpdb; |
|
843 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
844 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
845 | + // what we have |
|
846 | + $question_groups = $wpdb->get_col($SQL); |
|
847 | + // check the response |
|
848 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
849 | + // what we should have |
|
850 | + $QSG_systems = array(1, 2); |
|
851 | + // loop thru what we should have and compare to what we have |
|
852 | + foreach ($QSG_systems as $QSG_system) { |
|
853 | + // reset values array |
|
854 | + $QSG_values = array(); |
|
855 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
856 | + if (! in_array("$QSG_system", $question_groups)) { |
|
857 | + // add it |
|
858 | + switch ($QSG_system) { |
|
859 | + case 1: |
|
860 | + $QSG_values = array( |
|
861 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
862 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
863 | + 'QSG_desc' => '', |
|
864 | + 'QSG_order' => 1, |
|
865 | + 'QSG_show_group_name' => 1, |
|
866 | + 'QSG_show_group_desc' => 1, |
|
867 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
868 | + 'QSG_deleted' => 0, |
|
869 | + ); |
|
870 | + break; |
|
871 | + case 2: |
|
872 | + $QSG_values = array( |
|
873 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
874 | + 'QSG_identifier' => 'address-information-' . time(), |
|
875 | + 'QSG_desc' => '', |
|
876 | + 'QSG_order' => 2, |
|
877 | + 'QSG_show_group_name' => 1, |
|
878 | + 'QSG_show_group_desc' => 1, |
|
879 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
880 | + 'QSG_deleted' => 0, |
|
881 | + ); |
|
882 | + break; |
|
883 | + } |
|
884 | + // make sure we have some values before inserting them |
|
885 | + if (! empty($QSG_values)) { |
|
886 | + // insert system question |
|
887 | + $wpdb->insert( |
|
888 | + $table_name, |
|
889 | + $QSG_values, |
|
890 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
891 | + ); |
|
892 | + $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
893 | + } |
|
894 | + } |
|
895 | + } |
|
896 | + // QUESTIONS |
|
897 | + global $wpdb; |
|
898 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
899 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
900 | + // what we have |
|
901 | + $questions = $wpdb->get_col($SQL); |
|
902 | + // all system questions |
|
903 | + $personal_system_group_questions = ['fname', 'lname', 'email']; |
|
904 | + $address_system_group_questions = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone']; |
|
905 | + $system_questions_not_in_group = ['email_confirm']; |
|
906 | + // merge all of the system questions we should have |
|
907 | + $QST_systems = array_merge( |
|
908 | + $personal_system_group_questions, |
|
909 | + $address_system_group_questions, |
|
910 | + $system_questions_not_in_group |
|
911 | + ); |
|
912 | + $order_for_group_1 = 1; |
|
913 | + $order_for_group_2 = 1; |
|
914 | + // loop thru what we should have and compare to what we have |
|
915 | + foreach ($QST_systems as $QST_system) { |
|
916 | + // reset values array |
|
917 | + $QST_values = array(); |
|
918 | + // if we don't have what we should have |
|
919 | + if (! in_array($QST_system, $questions)) { |
|
920 | + // add it |
|
921 | + switch ($QST_system) { |
|
922 | + case 'fname': |
|
923 | + $QST_values = array( |
|
924 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
925 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
926 | + 'QST_system' => 'fname', |
|
927 | + 'QST_type' => 'TEXT', |
|
928 | + 'QST_required' => 1, |
|
929 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
930 | + 'QST_order' => 1, |
|
931 | + 'QST_admin_only' => 0, |
|
932 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
933 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
934 | + 'QST_deleted' => 0, |
|
935 | + ); |
|
936 | + break; |
|
937 | + case 'lname': |
|
938 | + $QST_values = array( |
|
939 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
940 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
941 | + 'QST_system' => 'lname', |
|
942 | + 'QST_type' => 'TEXT', |
|
943 | + 'QST_required' => 1, |
|
944 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
945 | + 'QST_order' => 2, |
|
946 | + 'QST_admin_only' => 0, |
|
947 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
948 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
949 | + 'QST_deleted' => 0, |
|
950 | + ); |
|
951 | + break; |
|
952 | + case 'email': |
|
953 | + $QST_values = array( |
|
954 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
955 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
956 | + 'QST_system' => 'email', |
|
957 | + 'QST_type' => 'EMAIL', |
|
958 | + 'QST_required' => 1, |
|
959 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
960 | + 'QST_order' => 3, |
|
961 | + 'QST_admin_only' => 0, |
|
962 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
963 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
964 | + 'QST_deleted' => 0, |
|
965 | + ); |
|
966 | + break; |
|
967 | + case 'email_confirm': |
|
968 | + $QST_values = array( |
|
969 | + 'QST_display_text' => __('Confirm Email Address', 'event_espresso'), |
|
970 | + 'QST_admin_label' => __('Confirm Email Address - System Question', 'event_espresso'), |
|
971 | + 'QST_system' => 'email_confirm', |
|
972 | + 'QST_type' => 'EMAIL_CONFIRM', |
|
973 | + 'QST_required' => 1, |
|
974 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
975 | + 'QST_order' => 4, |
|
976 | + 'QST_admin_only' => 0, |
|
977 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
978 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
979 | + 'QST_deleted' => 0, |
|
980 | + ); |
|
981 | + break; |
|
982 | + case 'address': |
|
983 | + $QST_values = array( |
|
984 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
985 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
986 | + 'QST_system' => 'address', |
|
987 | + 'QST_type' => 'TEXT', |
|
988 | + 'QST_required' => 0, |
|
989 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
990 | + 'QST_order' => 5, |
|
991 | + 'QST_admin_only' => 0, |
|
992 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
993 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
994 | + 'QST_deleted' => 0, |
|
995 | + ); |
|
996 | + break; |
|
997 | + case 'address2': |
|
998 | + $QST_values = array( |
|
999 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1000 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1001 | + 'QST_system' => 'address2', |
|
1002 | + 'QST_type' => 'TEXT', |
|
1003 | + 'QST_required' => 0, |
|
1004 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1005 | + 'QST_order' => 6, |
|
1006 | + 'QST_admin_only' => 0, |
|
1007 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1008 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1009 | + 'QST_deleted' => 0, |
|
1010 | + ); |
|
1011 | + break; |
|
1012 | + case 'city': |
|
1013 | + $QST_values = array( |
|
1014 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1015 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1016 | + 'QST_system' => 'city', |
|
1017 | + 'QST_type' => 'TEXT', |
|
1018 | + 'QST_required' => 0, |
|
1019 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1020 | + 'QST_order' => 7, |
|
1021 | + 'QST_admin_only' => 0, |
|
1022 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1023 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1024 | + 'QST_deleted' => 0, |
|
1025 | + ); |
|
1026 | + break; |
|
1027 | + case 'country': |
|
1028 | + $QST_values = array( |
|
1029 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1030 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1031 | + 'QST_system' => 'country', |
|
1032 | + 'QST_type' => 'COUNTRY', |
|
1033 | + 'QST_required' => 0, |
|
1034 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1035 | + 'QST_order' => 8, |
|
1036 | + 'QST_admin_only' => 0, |
|
1037 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1038 | + 'QST_deleted' => 0, |
|
1039 | + ); |
|
1040 | + break; |
|
1041 | + case 'state': |
|
1042 | + $QST_values = array( |
|
1043 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1044 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1045 | + 'QST_system' => 'state', |
|
1046 | + 'QST_type' => 'STATE', |
|
1047 | + 'QST_required' => 0, |
|
1048 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1049 | + 'QST_order' => 9, |
|
1050 | + 'QST_admin_only' => 0, |
|
1051 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1052 | + 'QST_deleted' => 0, |
|
1053 | + ); |
|
1054 | + break; |
|
1055 | + case 'zip': |
|
1056 | + $QST_values = array( |
|
1057 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1058 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1059 | + 'QST_system' => 'zip', |
|
1060 | + 'QST_type' => 'TEXT', |
|
1061 | + 'QST_required' => 0, |
|
1062 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1063 | + 'QST_order' => 10, |
|
1064 | + 'QST_admin_only' => 0, |
|
1065 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1066 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1067 | + 'QST_deleted' => 0, |
|
1068 | + ); |
|
1069 | + break; |
|
1070 | + case 'phone': |
|
1071 | + $QST_values = array( |
|
1072 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1073 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1074 | + 'QST_system' => 'phone', |
|
1075 | + 'QST_type' => 'TEXT', |
|
1076 | + 'QST_required' => 0, |
|
1077 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1078 | + 'QST_order' => 11, |
|
1079 | + 'QST_admin_only' => 0, |
|
1080 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1081 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1082 | + 'QST_deleted' => 0, |
|
1083 | + ); |
|
1084 | + break; |
|
1085 | + } |
|
1086 | + if (! empty($QST_values)) { |
|
1087 | + // insert system question |
|
1088 | + $wpdb->insert( |
|
1089 | + $table_name, |
|
1090 | + $QST_values, |
|
1091 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1092 | + ); |
|
1093 | + $QST_ID = $wpdb->insert_id; |
|
1094 | + |
|
1095 | + // QUESTION GROUP QUESTIONS |
|
1096 | + if (in_array($QST_system, $personal_system_group_questions)) { |
|
1097 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1098 | + } elseif (in_array($QST_system, $address_system_group_questions)) { |
|
1099 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1100 | + } else { |
|
1101 | + // QST_system should not be assigned to any group |
|
1102 | + continue; |
|
1103 | + } |
|
1104 | + if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1105 | + $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1106 | + } else { |
|
1107 | + $id_col = EEM_Question_Group::instance() |
|
1108 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | + if (is_array($id_col)) { |
|
1110 | + $QSG_ID = reset($id_col); |
|
1111 | + } else { |
|
1112 | + // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | + EE_Log::instance()->log( |
|
1114 | + __FILE__, |
|
1115 | + __FUNCTION__, |
|
1116 | + sprintf( |
|
1117 | + __( |
|
1118 | + 'Could not associate question %1$s to a question group because no system question |
|
1119 | 1119 | group existed', |
1120 | - 'event_espresso' |
|
1121 | - ), |
|
1122 | - $QST_ID |
|
1123 | - ), |
|
1124 | - 'error' |
|
1125 | - ); |
|
1126 | - continue; |
|
1127 | - } |
|
1128 | - } |
|
1129 | - // add system questions to groups |
|
1130 | - $wpdb->insert( |
|
1131 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1132 | - array( |
|
1133 | - 'QSG_ID' => $QSG_ID, |
|
1134 | - 'QST_ID' => $QST_ID, |
|
1135 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1136 | - ), |
|
1137 | - array('%d', '%d', '%d') |
|
1138 | - ); |
|
1139 | - } |
|
1140 | - } |
|
1141 | - } |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * Makes sure the default payment method (Invoice) is active. |
|
1147 | - * This used to be done automatically as part of constructing the old gateways config |
|
1148 | - * |
|
1149 | - * @throws \EE_Error |
|
1150 | - */ |
|
1151 | - public static function insert_default_payment_methods() |
|
1152 | - { |
|
1153 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1154 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1155 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1156 | - } else { |
|
1157 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1158 | - } |
|
1159 | - } |
|
1160 | - |
|
1161 | - /** |
|
1162 | - * insert_default_status_codes |
|
1163 | - * |
|
1164 | - * @access public |
|
1165 | - * @static |
|
1166 | - * @return void |
|
1167 | - */ |
|
1168 | - public static function insert_default_status_codes() |
|
1169 | - { |
|
1170 | - |
|
1171 | - global $wpdb; |
|
1172 | - |
|
1173 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1174 | - $table_name = EEM_Status::instance()->table(); |
|
1175 | - |
|
1176 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1177 | - $wpdb->query($SQL); |
|
1178 | - |
|
1179 | - $SQL = "INSERT INTO $table_name |
|
1120 | + 'event_espresso' |
|
1121 | + ), |
|
1122 | + $QST_ID |
|
1123 | + ), |
|
1124 | + 'error' |
|
1125 | + ); |
|
1126 | + continue; |
|
1127 | + } |
|
1128 | + } |
|
1129 | + // add system questions to groups |
|
1130 | + $wpdb->insert( |
|
1131 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1132 | + array( |
|
1133 | + 'QSG_ID' => $QSG_ID, |
|
1134 | + 'QST_ID' => $QST_ID, |
|
1135 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1136 | + ), |
|
1137 | + array('%d', '%d', '%d') |
|
1138 | + ); |
|
1139 | + } |
|
1140 | + } |
|
1141 | + } |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * Makes sure the default payment method (Invoice) is active. |
|
1147 | + * This used to be done automatically as part of constructing the old gateways config |
|
1148 | + * |
|
1149 | + * @throws \EE_Error |
|
1150 | + */ |
|
1151 | + public static function insert_default_payment_methods() |
|
1152 | + { |
|
1153 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1154 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1155 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1156 | + } else { |
|
1157 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1158 | + } |
|
1159 | + } |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * insert_default_status_codes |
|
1163 | + * |
|
1164 | + * @access public |
|
1165 | + * @static |
|
1166 | + * @return void |
|
1167 | + */ |
|
1168 | + public static function insert_default_status_codes() |
|
1169 | + { |
|
1170 | + |
|
1171 | + global $wpdb; |
|
1172 | + |
|
1173 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1174 | + $table_name = EEM_Status::instance()->table(); |
|
1175 | + |
|
1176 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1177 | + $wpdb->query($SQL); |
|
1178 | + |
|
1179 | + $SQL = "INSERT INTO $table_name |
|
1180 | 1180 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1181 | 1181 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1182 | 1182 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1216,479 +1216,479 @@ discard block |
||
1216 | 1216 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1217 | 1217 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1218 | 1218 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1219 | - $wpdb->query($SQL); |
|
1220 | - } |
|
1221 | - } |
|
1222 | - |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * generate_default_message_templates |
|
1226 | - * |
|
1227 | - * @static |
|
1228 | - * @throws EE_Error |
|
1229 | - * @return bool true means new templates were created. |
|
1230 | - * false means no templates were created. |
|
1231 | - * This is NOT an error flag. To check for errors you will want |
|
1232 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1233 | - */ |
|
1234 | - public static function generate_default_message_templates() |
|
1235 | - { |
|
1236 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1237 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1238 | - /* |
|
1219 | + $wpdb->query($SQL); |
|
1220 | + } |
|
1221 | + } |
|
1222 | + |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * generate_default_message_templates |
|
1226 | + * |
|
1227 | + * @static |
|
1228 | + * @throws EE_Error |
|
1229 | + * @return bool true means new templates were created. |
|
1230 | + * false means no templates were created. |
|
1231 | + * This is NOT an error flag. To check for errors you will want |
|
1232 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1233 | + */ |
|
1234 | + public static function generate_default_message_templates() |
|
1235 | + { |
|
1236 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1237 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1238 | + /* |
|
1239 | 1239 | * This first method is taking care of ensuring any default messengers |
1240 | 1240 | * that should be made active and have templates generated are done. |
1241 | 1241 | */ |
1242 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1243 | - $message_resource_manager |
|
1244 | - ); |
|
1245 | - /** |
|
1246 | - * This method is verifying there are no NEW default message types |
|
1247 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1248 | - */ |
|
1249 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1250 | - $message_resource_manager |
|
1251 | - ); |
|
1252 | - // after all is done, let's persist these changes to the db. |
|
1253 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1254 | - $message_resource_manager->update_active_messengers_option(); |
|
1255 | - // will return true if either of these are true. Otherwise will return false. |
|
1256 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1257 | - } |
|
1258 | - |
|
1259 | - |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1263 | - * @return array|bool |
|
1264 | - * @throws \EE_Error |
|
1265 | - */ |
|
1266 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1267 | - EE_Message_Resource_Manager $message_resource_manager |
|
1268 | - ) { |
|
1269 | - /** @type EE_messenger[] $active_messengers */ |
|
1270 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1271 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1272 | - $templates_created = false; |
|
1273 | - foreach ($active_messengers as $active_messenger) { |
|
1274 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1275 | - $default_message_type_names_to_activate = array(); |
|
1276 | - // looping through each default message type reported by the messenger |
|
1277 | - // and setup the actual message types to activate. |
|
1278 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1279 | - // if already active or has already been activated before we skip |
|
1280 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1281 | - // we also skip if the message type is not installed. |
|
1282 | - if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1283 | - $default_message_type_name_for_messenger, |
|
1284 | - $active_messenger->name |
|
1285 | - ) |
|
1286 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1287 | - $active_messenger->name, |
|
1288 | - $default_message_type_name_for_messenger |
|
1289 | - ) |
|
1290 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1291 | - ) { |
|
1292 | - continue; |
|
1293 | - } |
|
1294 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1295 | - } |
|
1296 | - // let's activate! |
|
1297 | - $message_resource_manager->ensure_message_types_are_active( |
|
1298 | - $default_message_type_names_to_activate, |
|
1299 | - $active_messenger->name, |
|
1300 | - false |
|
1301 | - ); |
|
1302 | - // activate the templates for these message types |
|
1303 | - if (! empty($default_message_type_names_to_activate)) { |
|
1304 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1305 | - $active_messenger->name, |
|
1306 | - $default_message_type_names_for_messenger, |
|
1307 | - '', |
|
1308 | - true |
|
1309 | - ); |
|
1310 | - } |
|
1311 | - } |
|
1312 | - return $templates_created; |
|
1313 | - } |
|
1314 | - |
|
1315 | - |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1319 | - * |
|
1320 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1321 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1322 | - * False means that there were no templates generated |
|
1323 | - * (which could simply mean there are no default message types for a messenger). |
|
1324 | - * @throws EE_Error |
|
1325 | - */ |
|
1326 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1327 | - EE_Message_Resource_Manager $message_resource_manager |
|
1328 | - ) { |
|
1329 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1330 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1331 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | - $templates_generated = false; |
|
1333 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1334 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1335 | - // verify the default message types match an installed message type. |
|
1336 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1337 | - if (! isset($installed_message_types[ $name ]) |
|
1338 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1339 | - $name, |
|
1340 | - $messenger_to_generate->name |
|
1341 | - ) |
|
1342 | - ) { |
|
1343 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1344 | - } |
|
1345 | - } |
|
1346 | - // in previous iterations, the active_messengers option in the db |
|
1347 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1348 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1349 | - // passing off to create templates (after the refactor is done). |
|
1350 | - // @todo remove this comment when determined not necessary. |
|
1351 | - $message_resource_manager->activate_messenger( |
|
1352 | - $messenger_to_generate->name, |
|
1353 | - $default_message_type_names_for_messenger, |
|
1354 | - false |
|
1355 | - ); |
|
1356 | - // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1357 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1358 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1359 | - $messenger_to_generate->name, |
|
1360 | - $default_message_type_names_for_messenger, |
|
1361 | - '', |
|
1362 | - true |
|
1363 | - ); |
|
1364 | - } |
|
1365 | - } |
|
1366 | - return $templates_generated; |
|
1367 | - } |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1372 | - * It considers: |
|
1373 | - * - whether a messenger is already active in the db. |
|
1374 | - * - whether a messenger has been made active at any time in the past. |
|
1375 | - * |
|
1376 | - * @static |
|
1377 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1378 | - * @return EE_messenger[] |
|
1379 | - */ |
|
1380 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1381 | - EE_Message_Resource_Manager $message_resource_manager |
|
1382 | - ) { |
|
1383 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1384 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1385 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1386 | - |
|
1387 | - $messengers_to_generate = array(); |
|
1388 | - foreach ($installed_messengers as $installed_messenger) { |
|
1389 | - // if installed messenger is a messenger that should be activated on install |
|
1390 | - // and is not already active |
|
1391 | - // and has never been activated |
|
1392 | - if (! $installed_messenger->activate_on_install |
|
1393 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1394 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1395 | - ) { |
|
1396 | - continue; |
|
1397 | - } |
|
1398 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1399 | - } |
|
1400 | - return $messengers_to_generate; |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - /** |
|
1405 | - * This simply validates active message types to ensure they actually match installed |
|
1406 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1407 | - * rows are set inactive. |
|
1408 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1409 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1410 | - * are still handled in here. |
|
1411 | - * |
|
1412 | - * @since 4.3.1 |
|
1413 | - * @return void |
|
1414 | - */ |
|
1415 | - public static function validate_messages_system() |
|
1416 | - { |
|
1417 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1418 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1419 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1420 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1421 | - } |
|
1422 | - |
|
1423 | - |
|
1424 | - /** |
|
1425 | - * create_no_ticket_prices_array |
|
1426 | - * |
|
1427 | - * @access public |
|
1428 | - * @static |
|
1429 | - * @return void |
|
1430 | - */ |
|
1431 | - public static function create_no_ticket_prices_array() |
|
1432 | - { |
|
1433 | - // this creates an array for tracking events that have no active ticket prices created |
|
1434 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1435 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1436 | - if (! $espresso_no_ticket_prices) { |
|
1437 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1438 | - } |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * plugin_deactivation |
|
1444 | - * |
|
1445 | - * @access public |
|
1446 | - * @static |
|
1447 | - * @return void |
|
1448 | - */ |
|
1449 | - public static function plugin_deactivation() |
|
1450 | - { |
|
1451 | - } |
|
1452 | - |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1456 | - * (like post meta or term relations) |
|
1457 | - * |
|
1458 | - * @global wpdb $wpdb |
|
1459 | - * @throws \EE_Error |
|
1460 | - */ |
|
1461 | - public static function delete_all_espresso_cpt_data() |
|
1462 | - { |
|
1463 | - global $wpdb; |
|
1464 | - // get all the CPT post_types |
|
1465 | - $ee_post_types = array(); |
|
1466 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1467 | - if (method_exists($model_name, 'instance')) { |
|
1468 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1469 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1470 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1471 | - } |
|
1472 | - } |
|
1473 | - } |
|
1474 | - // get all our CPTs |
|
1475 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1476 | - $cpt_ids = $wpdb->get_col($query); |
|
1477 | - // delete each post meta and term relations too |
|
1478 | - foreach ($cpt_ids as $post_id) { |
|
1479 | - wp_delete_post($post_id, true); |
|
1480 | - } |
|
1481 | - } |
|
1482 | - |
|
1483 | - /** |
|
1484 | - * Deletes all EE custom tables |
|
1485 | - * |
|
1486 | - * @return array |
|
1487 | - */ |
|
1488 | - public static function drop_espresso_tables() |
|
1489 | - { |
|
1490 | - $tables = array(); |
|
1491 | - // load registry |
|
1492 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1493 | - if (method_exists($model_name, 'instance')) { |
|
1494 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1495 | - if ($model_obj instanceof EEM_Base) { |
|
1496 | - foreach ($model_obj->get_tables() as $table) { |
|
1497 | - if (strpos($table->get_table_name(), 'esp_') |
|
1498 | - && |
|
1499 | - ( |
|
1500 | - is_main_site()// main site? nuke them all |
|
1501 | - || ! $table->is_global()// not main site,but not global either. nuke it |
|
1502 | - ) |
|
1503 | - ) { |
|
1504 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1505 | - } |
|
1506 | - } |
|
1507 | - } |
|
1508 | - } |
|
1509 | - } |
|
1510 | - |
|
1511 | - // there are some tables whose models were removed. |
|
1512 | - // they should be removed when removing all EE core's data |
|
1513 | - $tables_without_models = array( |
|
1514 | - 'esp_promotion', |
|
1515 | - 'esp_promotion_applied', |
|
1516 | - 'esp_promotion_object', |
|
1517 | - 'esp_promotion_rule', |
|
1518 | - 'esp_rule', |
|
1519 | - ); |
|
1520 | - foreach ($tables_without_models as $table) { |
|
1521 | - $tables[ $table ] = $table; |
|
1522 | - } |
|
1523 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1524 | - } |
|
1525 | - |
|
1526 | - |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1530 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1531 | - * Returns the list actually deleted |
|
1532 | - * |
|
1533 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1534 | - * @global WPDB $wpdb |
|
1535 | - * @param array $table_names |
|
1536 | - * @return array of table names which we deleted |
|
1537 | - */ |
|
1538 | - public static function drop_tables($table_names) |
|
1539 | - { |
|
1540 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1541 | - } |
|
1542 | - |
|
1543 | - |
|
1544 | - |
|
1545 | - /** |
|
1546 | - * plugin_uninstall |
|
1547 | - * |
|
1548 | - * @access public |
|
1549 | - * @static |
|
1550 | - * @param bool $remove_all |
|
1551 | - * @return void |
|
1552 | - */ |
|
1553 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1554 | - { |
|
1555 | - global $wpdb; |
|
1556 | - self::drop_espresso_tables(); |
|
1557 | - $wp_options_to_delete = array( |
|
1558 | - 'ee_no_ticket_prices' => true, |
|
1559 | - 'ee_active_messengers' => true, |
|
1560 | - 'ee_has_activated_messenger' => true, |
|
1561 | - RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1562 | - 'ee_config' => false, |
|
1563 | - 'ee_data_migration_current_db_state' => true, |
|
1564 | - 'ee_data_migration_mapping_' => false, |
|
1565 | - 'ee_data_migration_script_' => false, |
|
1566 | - 'ee_data_migrations' => true, |
|
1567 | - 'ee_dms_map' => false, |
|
1568 | - 'ee_notices' => true, |
|
1569 | - 'lang_file_check_' => false, |
|
1570 | - 'ee_maintenance_mode' => true, |
|
1571 | - 'ee_ueip_optin' => true, |
|
1572 | - 'ee_ueip_has_notified' => true, |
|
1573 | - 'ee_plugin_activation_errors' => true, |
|
1574 | - 'ee_id_mapping_from' => false, |
|
1575 | - 'espresso_persistent_admin_notices' => true, |
|
1576 | - 'ee_encryption_key' => true, |
|
1577 | - 'pue_force_upgrade_' => false, |
|
1578 | - 'pue_json_error_' => false, |
|
1579 | - 'pue_install_key_' => false, |
|
1580 | - 'pue_verification_error_' => false, |
|
1581 | - 'pu_dismissed_upgrade_' => false, |
|
1582 | - 'external_updates-' => false, |
|
1583 | - 'ee_extra_data' => true, |
|
1584 | - 'ee_ssn_' => false, |
|
1585 | - 'ee_rss_' => false, |
|
1586 | - 'ee_rte_n_tx_' => false, |
|
1587 | - 'ee_pers_admin_notices' => true, |
|
1588 | - 'ee_job_parameters_' => false, |
|
1589 | - 'ee_upload_directories_incomplete' => true, |
|
1590 | - 'ee_verified_db_collations' => true, |
|
1591 | - ); |
|
1592 | - if (is_main_site()) { |
|
1593 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1594 | - } |
|
1595 | - $undeleted_options = array(); |
|
1596 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1597 | - if ($no_wildcard) { |
|
1598 | - if (! delete_option($option_name)) { |
|
1599 | - $undeleted_options[] = $option_name; |
|
1600 | - } |
|
1601 | - } else { |
|
1602 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1603 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1604 | - if (! delete_option($option_name_from_wildcard)) { |
|
1605 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1606 | - } |
|
1607 | - } |
|
1608 | - } |
|
1609 | - } |
|
1610 | - // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1611 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1612 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1613 | - $db_update_sans_ee4 = array(); |
|
1614 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1615 | - if ((string) $version[0] === '3') {// if its NON EE4 |
|
1616 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1617 | - } |
|
1618 | - } |
|
1619 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1620 | - } |
|
1621 | - $errors = ''; |
|
1622 | - if (! empty($undeleted_options)) { |
|
1623 | - $errors .= sprintf( |
|
1624 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1625 | - '<br/>', |
|
1626 | - implode(',<br/>', $undeleted_options) |
|
1627 | - ); |
|
1628 | - } |
|
1629 | - if (! empty($errors)) { |
|
1630 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1631 | - } |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Gets the mysql error code from the last used query by wpdb |
|
1636 | - * |
|
1637 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1638 | - */ |
|
1639 | - public static function last_wpdb_error_code() |
|
1640 | - { |
|
1641 | - // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
1642 | - global $wpdb; |
|
1643 | - if ($wpdb->use_mysqli) { |
|
1644 | - return mysqli_errno($wpdb->dbh); |
|
1645 | - } else { |
|
1646 | - return mysql_errno($wpdb->dbh); |
|
1647 | - } |
|
1648 | - // phpcs:enable |
|
1649 | - } |
|
1650 | - |
|
1651 | - /** |
|
1652 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1653 | - * |
|
1654 | - * @global wpdb $wpdb |
|
1655 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1656 | - * @param string $table_name with or without $wpdb->prefix |
|
1657 | - * @return boolean |
|
1658 | - */ |
|
1659 | - public static function table_exists($table_name) |
|
1660 | - { |
|
1661 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1662 | - } |
|
1663 | - |
|
1664 | - /** |
|
1665 | - * Resets the cache on EEH_Activation |
|
1666 | - */ |
|
1667 | - public static function reset() |
|
1668 | - { |
|
1669 | - self::$_default_creator_id = null; |
|
1670 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1671 | - } |
|
1672 | - |
|
1673 | - /** |
|
1674 | - * Removes 'email_confirm' from the Address info question group on activation |
|
1675 | - * @return void |
|
1676 | - */ |
|
1677 | - public static function removeEmailConfirmFromAddressGroup() |
|
1678 | - { |
|
1679 | - |
|
1680 | - // Pull the email_confirm question ID. |
|
1681 | - $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
1682 | - EEM_Attendee::system_question_email_confirm |
|
1683 | - ); |
|
1684 | - // Remove the email_confirm question group from the address group questions. |
|
1685 | - EEM_Question_Group_Question::instance()->delete( |
|
1686 | - array( |
|
1687 | - array( |
|
1688 | - 'QST_ID' => $email_confirm_question_id, |
|
1689 | - 'Question_Group.QSG_system' => EEM_Question_Group::system_address, |
|
1690 | - ), |
|
1691 | - ) |
|
1692 | - ); |
|
1693 | - } |
|
1242 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1243 | + $message_resource_manager |
|
1244 | + ); |
|
1245 | + /** |
|
1246 | + * This method is verifying there are no NEW default message types |
|
1247 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1248 | + */ |
|
1249 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1250 | + $message_resource_manager |
|
1251 | + ); |
|
1252 | + // after all is done, let's persist these changes to the db. |
|
1253 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1254 | + $message_resource_manager->update_active_messengers_option(); |
|
1255 | + // will return true if either of these are true. Otherwise will return false. |
|
1256 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1257 | + } |
|
1258 | + |
|
1259 | + |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1263 | + * @return array|bool |
|
1264 | + * @throws \EE_Error |
|
1265 | + */ |
|
1266 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1267 | + EE_Message_Resource_Manager $message_resource_manager |
|
1268 | + ) { |
|
1269 | + /** @type EE_messenger[] $active_messengers */ |
|
1270 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1271 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1272 | + $templates_created = false; |
|
1273 | + foreach ($active_messengers as $active_messenger) { |
|
1274 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1275 | + $default_message_type_names_to_activate = array(); |
|
1276 | + // looping through each default message type reported by the messenger |
|
1277 | + // and setup the actual message types to activate. |
|
1278 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1279 | + // if already active or has already been activated before we skip |
|
1280 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1281 | + // we also skip if the message type is not installed. |
|
1282 | + if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1283 | + $default_message_type_name_for_messenger, |
|
1284 | + $active_messenger->name |
|
1285 | + ) |
|
1286 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1287 | + $active_messenger->name, |
|
1288 | + $default_message_type_name_for_messenger |
|
1289 | + ) |
|
1290 | + || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1291 | + ) { |
|
1292 | + continue; |
|
1293 | + } |
|
1294 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1295 | + } |
|
1296 | + // let's activate! |
|
1297 | + $message_resource_manager->ensure_message_types_are_active( |
|
1298 | + $default_message_type_names_to_activate, |
|
1299 | + $active_messenger->name, |
|
1300 | + false |
|
1301 | + ); |
|
1302 | + // activate the templates for these message types |
|
1303 | + if (! empty($default_message_type_names_to_activate)) { |
|
1304 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1305 | + $active_messenger->name, |
|
1306 | + $default_message_type_names_for_messenger, |
|
1307 | + '', |
|
1308 | + true |
|
1309 | + ); |
|
1310 | + } |
|
1311 | + } |
|
1312 | + return $templates_created; |
|
1313 | + } |
|
1314 | + |
|
1315 | + |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1319 | + * |
|
1320 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1321 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1322 | + * False means that there were no templates generated |
|
1323 | + * (which could simply mean there are no default message types for a messenger). |
|
1324 | + * @throws EE_Error |
|
1325 | + */ |
|
1326 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1327 | + EE_Message_Resource_Manager $message_resource_manager |
|
1328 | + ) { |
|
1329 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1330 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1331 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | + $templates_generated = false; |
|
1333 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1334 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1335 | + // verify the default message types match an installed message type. |
|
1336 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1337 | + if (! isset($installed_message_types[ $name ]) |
|
1338 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1339 | + $name, |
|
1340 | + $messenger_to_generate->name |
|
1341 | + ) |
|
1342 | + ) { |
|
1343 | + unset($default_message_type_names_for_messenger[ $key ]); |
|
1344 | + } |
|
1345 | + } |
|
1346 | + // in previous iterations, the active_messengers option in the db |
|
1347 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1348 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1349 | + // passing off to create templates (after the refactor is done). |
|
1350 | + // @todo remove this comment when determined not necessary. |
|
1351 | + $message_resource_manager->activate_messenger( |
|
1352 | + $messenger_to_generate->name, |
|
1353 | + $default_message_type_names_for_messenger, |
|
1354 | + false |
|
1355 | + ); |
|
1356 | + // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1357 | + if (! empty($default_message_type_names_for_messenger)) { |
|
1358 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1359 | + $messenger_to_generate->name, |
|
1360 | + $default_message_type_names_for_messenger, |
|
1361 | + '', |
|
1362 | + true |
|
1363 | + ); |
|
1364 | + } |
|
1365 | + } |
|
1366 | + return $templates_generated; |
|
1367 | + } |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1372 | + * It considers: |
|
1373 | + * - whether a messenger is already active in the db. |
|
1374 | + * - whether a messenger has been made active at any time in the past. |
|
1375 | + * |
|
1376 | + * @static |
|
1377 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1378 | + * @return EE_messenger[] |
|
1379 | + */ |
|
1380 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1381 | + EE_Message_Resource_Manager $message_resource_manager |
|
1382 | + ) { |
|
1383 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1384 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1385 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1386 | + |
|
1387 | + $messengers_to_generate = array(); |
|
1388 | + foreach ($installed_messengers as $installed_messenger) { |
|
1389 | + // if installed messenger is a messenger that should be activated on install |
|
1390 | + // and is not already active |
|
1391 | + // and has never been activated |
|
1392 | + if (! $installed_messenger->activate_on_install |
|
1393 | + || isset($active_messengers[ $installed_messenger->name ]) |
|
1394 | + || isset($has_activated[ $installed_messenger->name ]) |
|
1395 | + ) { |
|
1396 | + continue; |
|
1397 | + } |
|
1398 | + $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1399 | + } |
|
1400 | + return $messengers_to_generate; |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + /** |
|
1405 | + * This simply validates active message types to ensure they actually match installed |
|
1406 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1407 | + * rows are set inactive. |
|
1408 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1409 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1410 | + * are still handled in here. |
|
1411 | + * |
|
1412 | + * @since 4.3.1 |
|
1413 | + * @return void |
|
1414 | + */ |
|
1415 | + public static function validate_messages_system() |
|
1416 | + { |
|
1417 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1418 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1419 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1420 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1421 | + } |
|
1422 | + |
|
1423 | + |
|
1424 | + /** |
|
1425 | + * create_no_ticket_prices_array |
|
1426 | + * |
|
1427 | + * @access public |
|
1428 | + * @static |
|
1429 | + * @return void |
|
1430 | + */ |
|
1431 | + public static function create_no_ticket_prices_array() |
|
1432 | + { |
|
1433 | + // this creates an array for tracking events that have no active ticket prices created |
|
1434 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1435 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1436 | + if (! $espresso_no_ticket_prices) { |
|
1437 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1438 | + } |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * plugin_deactivation |
|
1444 | + * |
|
1445 | + * @access public |
|
1446 | + * @static |
|
1447 | + * @return void |
|
1448 | + */ |
|
1449 | + public static function plugin_deactivation() |
|
1450 | + { |
|
1451 | + } |
|
1452 | + |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1456 | + * (like post meta or term relations) |
|
1457 | + * |
|
1458 | + * @global wpdb $wpdb |
|
1459 | + * @throws \EE_Error |
|
1460 | + */ |
|
1461 | + public static function delete_all_espresso_cpt_data() |
|
1462 | + { |
|
1463 | + global $wpdb; |
|
1464 | + // get all the CPT post_types |
|
1465 | + $ee_post_types = array(); |
|
1466 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1467 | + if (method_exists($model_name, 'instance')) { |
|
1468 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1469 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1470 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1471 | + } |
|
1472 | + } |
|
1473 | + } |
|
1474 | + // get all our CPTs |
|
1475 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1476 | + $cpt_ids = $wpdb->get_col($query); |
|
1477 | + // delete each post meta and term relations too |
|
1478 | + foreach ($cpt_ids as $post_id) { |
|
1479 | + wp_delete_post($post_id, true); |
|
1480 | + } |
|
1481 | + } |
|
1482 | + |
|
1483 | + /** |
|
1484 | + * Deletes all EE custom tables |
|
1485 | + * |
|
1486 | + * @return array |
|
1487 | + */ |
|
1488 | + public static function drop_espresso_tables() |
|
1489 | + { |
|
1490 | + $tables = array(); |
|
1491 | + // load registry |
|
1492 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1493 | + if (method_exists($model_name, 'instance')) { |
|
1494 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1495 | + if ($model_obj instanceof EEM_Base) { |
|
1496 | + foreach ($model_obj->get_tables() as $table) { |
|
1497 | + if (strpos($table->get_table_name(), 'esp_') |
|
1498 | + && |
|
1499 | + ( |
|
1500 | + is_main_site()// main site? nuke them all |
|
1501 | + || ! $table->is_global()// not main site,but not global either. nuke it |
|
1502 | + ) |
|
1503 | + ) { |
|
1504 | + $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1505 | + } |
|
1506 | + } |
|
1507 | + } |
|
1508 | + } |
|
1509 | + } |
|
1510 | + |
|
1511 | + // there are some tables whose models were removed. |
|
1512 | + // they should be removed when removing all EE core's data |
|
1513 | + $tables_without_models = array( |
|
1514 | + 'esp_promotion', |
|
1515 | + 'esp_promotion_applied', |
|
1516 | + 'esp_promotion_object', |
|
1517 | + 'esp_promotion_rule', |
|
1518 | + 'esp_rule', |
|
1519 | + ); |
|
1520 | + foreach ($tables_without_models as $table) { |
|
1521 | + $tables[ $table ] = $table; |
|
1522 | + } |
|
1523 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1524 | + } |
|
1525 | + |
|
1526 | + |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1530 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1531 | + * Returns the list actually deleted |
|
1532 | + * |
|
1533 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1534 | + * @global WPDB $wpdb |
|
1535 | + * @param array $table_names |
|
1536 | + * @return array of table names which we deleted |
|
1537 | + */ |
|
1538 | + public static function drop_tables($table_names) |
|
1539 | + { |
|
1540 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1541 | + } |
|
1542 | + |
|
1543 | + |
|
1544 | + |
|
1545 | + /** |
|
1546 | + * plugin_uninstall |
|
1547 | + * |
|
1548 | + * @access public |
|
1549 | + * @static |
|
1550 | + * @param bool $remove_all |
|
1551 | + * @return void |
|
1552 | + */ |
|
1553 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1554 | + { |
|
1555 | + global $wpdb; |
|
1556 | + self::drop_espresso_tables(); |
|
1557 | + $wp_options_to_delete = array( |
|
1558 | + 'ee_no_ticket_prices' => true, |
|
1559 | + 'ee_active_messengers' => true, |
|
1560 | + 'ee_has_activated_messenger' => true, |
|
1561 | + RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1562 | + 'ee_config' => false, |
|
1563 | + 'ee_data_migration_current_db_state' => true, |
|
1564 | + 'ee_data_migration_mapping_' => false, |
|
1565 | + 'ee_data_migration_script_' => false, |
|
1566 | + 'ee_data_migrations' => true, |
|
1567 | + 'ee_dms_map' => false, |
|
1568 | + 'ee_notices' => true, |
|
1569 | + 'lang_file_check_' => false, |
|
1570 | + 'ee_maintenance_mode' => true, |
|
1571 | + 'ee_ueip_optin' => true, |
|
1572 | + 'ee_ueip_has_notified' => true, |
|
1573 | + 'ee_plugin_activation_errors' => true, |
|
1574 | + 'ee_id_mapping_from' => false, |
|
1575 | + 'espresso_persistent_admin_notices' => true, |
|
1576 | + 'ee_encryption_key' => true, |
|
1577 | + 'pue_force_upgrade_' => false, |
|
1578 | + 'pue_json_error_' => false, |
|
1579 | + 'pue_install_key_' => false, |
|
1580 | + 'pue_verification_error_' => false, |
|
1581 | + 'pu_dismissed_upgrade_' => false, |
|
1582 | + 'external_updates-' => false, |
|
1583 | + 'ee_extra_data' => true, |
|
1584 | + 'ee_ssn_' => false, |
|
1585 | + 'ee_rss_' => false, |
|
1586 | + 'ee_rte_n_tx_' => false, |
|
1587 | + 'ee_pers_admin_notices' => true, |
|
1588 | + 'ee_job_parameters_' => false, |
|
1589 | + 'ee_upload_directories_incomplete' => true, |
|
1590 | + 'ee_verified_db_collations' => true, |
|
1591 | + ); |
|
1592 | + if (is_main_site()) { |
|
1593 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1594 | + } |
|
1595 | + $undeleted_options = array(); |
|
1596 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1597 | + if ($no_wildcard) { |
|
1598 | + if (! delete_option($option_name)) { |
|
1599 | + $undeleted_options[] = $option_name; |
|
1600 | + } |
|
1601 | + } else { |
|
1602 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1603 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1604 | + if (! delete_option($option_name_from_wildcard)) { |
|
1605 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1606 | + } |
|
1607 | + } |
|
1608 | + } |
|
1609 | + } |
|
1610 | + // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1611 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1612 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1613 | + $db_update_sans_ee4 = array(); |
|
1614 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1615 | + if ((string) $version[0] === '3') {// if its NON EE4 |
|
1616 | + $db_update_sans_ee4[ $version ] = $times_activated; |
|
1617 | + } |
|
1618 | + } |
|
1619 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1620 | + } |
|
1621 | + $errors = ''; |
|
1622 | + if (! empty($undeleted_options)) { |
|
1623 | + $errors .= sprintf( |
|
1624 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1625 | + '<br/>', |
|
1626 | + implode(',<br/>', $undeleted_options) |
|
1627 | + ); |
|
1628 | + } |
|
1629 | + if (! empty($errors)) { |
|
1630 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1631 | + } |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Gets the mysql error code from the last used query by wpdb |
|
1636 | + * |
|
1637 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1638 | + */ |
|
1639 | + public static function last_wpdb_error_code() |
|
1640 | + { |
|
1641 | + // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
1642 | + global $wpdb; |
|
1643 | + if ($wpdb->use_mysqli) { |
|
1644 | + return mysqli_errno($wpdb->dbh); |
|
1645 | + } else { |
|
1646 | + return mysql_errno($wpdb->dbh); |
|
1647 | + } |
|
1648 | + // phpcs:enable |
|
1649 | + } |
|
1650 | + |
|
1651 | + /** |
|
1652 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1653 | + * |
|
1654 | + * @global wpdb $wpdb |
|
1655 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1656 | + * @param string $table_name with or without $wpdb->prefix |
|
1657 | + * @return boolean |
|
1658 | + */ |
|
1659 | + public static function table_exists($table_name) |
|
1660 | + { |
|
1661 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1662 | + } |
|
1663 | + |
|
1664 | + /** |
|
1665 | + * Resets the cache on EEH_Activation |
|
1666 | + */ |
|
1667 | + public static function reset() |
|
1668 | + { |
|
1669 | + self::$_default_creator_id = null; |
|
1670 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1671 | + } |
|
1672 | + |
|
1673 | + /** |
|
1674 | + * Removes 'email_confirm' from the Address info question group on activation |
|
1675 | + * @return void |
|
1676 | + */ |
|
1677 | + public static function removeEmailConfirmFromAddressGroup() |
|
1678 | + { |
|
1679 | + |
|
1680 | + // Pull the email_confirm question ID. |
|
1681 | + $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
1682 | + EEM_Attendee::system_question_email_confirm |
|
1683 | + ); |
|
1684 | + // Remove the email_confirm question group from the address group questions. |
|
1685 | + EEM_Question_Group_Question::instance()->delete( |
|
1686 | + array( |
|
1687 | + array( |
|
1688 | + 'QST_ID' => $email_confirm_question_id, |
|
1689 | + 'Question_Group.QSG_system' => EEM_Question_Group::system_address, |
|
1690 | + ), |
|
1691 | + ) |
|
1692 | + ); |
|
1693 | + } |
|
1694 | 1694 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function getTableAnalysis() |
56 | 56 | { |
57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
57 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | 58 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
59 | 59 | } |
60 | 60 | return self::$table_analysis; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function getTableManager() |
68 | 68 | { |
69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
69 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | 70 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
71 | 71 | } |
72 | 72 | return self::$table_manager; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | if ($which_to_include === 'old') { |
182 | 182 | $cron_tasks = array_filter( |
183 | 183 | $cron_tasks, |
184 | - function ($value) { |
|
184 | + function($value) { |
|
185 | 185 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
186 | 186 | } |
187 | 187 | ); |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | { |
212 | 212 | |
213 | 213 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
214 | - if (! wp_next_scheduled($hook_name)) { |
|
214 | + if ( ! wp_next_scheduled($hook_name)) { |
|
215 | 215 | /** |
216 | 216 | * This allows client code to define the initial start timestamp for this schedule. |
217 | 217 | */ |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
263 | 263 | if (is_array($hooks_to_fire_at_time)) { |
264 | 264 | foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
265 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
266 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
267 | 267 | ) { |
268 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
268 | + unset($crons[$timestamp][$hook_name]); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | // also take care of any empty cron timestamps. |
272 | 272 | if (empty($hooks_to_fire_at_time)) { |
273 | - unset($crons[ $timestamp ]); |
|
273 | + unset($crons[$timestamp]); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | 3 |
316 | 316 | ); |
317 | 317 | // EE_Config::reset(); |
318 | - if (! EE_Config::logging_enabled()) { |
|
318 | + if ( ! EE_Config::logging_enabled()) { |
|
319 | 319 | delete_option(EE_Config::LOG_NAME); |
320 | 320 | } |
321 | 321 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | public static function load_calendar_config() |
331 | 331 | { |
332 | 332 | // grab array of all plugin folders and loop thru it |
333 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
333 | + $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR); |
|
334 | 334 | if (empty($plugins)) { |
335 | 335 | return; |
336 | 336 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | || strpos($plugin, 'calendar') !== false |
347 | 347 | ) { |
348 | 348 | // this is what we are looking for |
349 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
349 | + $calendar_config = $plugin_path.'/EE_Calendar_Config.php'; |
|
350 | 350 | // does it exist in this folder ? |
351 | 351 | if (is_readable($calendar_config)) { |
352 | 352 | // YEAH! let's load it |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | ) { |
474 | 474 | // update Config with post ID |
475 | 475 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
476 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
477 | 477 | $msg = __( |
478 | 478 | 'The Event Espresso critical page configuration settings could not be updated.', |
479 | 479 | 'event_espresso' |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
497 | 497 | 'event_espresso' |
498 | 498 | ), |
499 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
499 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
500 | 500 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
501 | 501 | . '</a>' |
502 | 502 | ) |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | public static function get_page_by_ee_shortcode($ee_shortcode) |
523 | 523 | { |
524 | 524 | global $wpdb; |
525 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
525 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
526 | 526 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
527 | 527 | if ($post_id) { |
528 | 528 | return get_post($post_id); |
@@ -548,11 +548,11 @@ discard block |
||
548 | 548 | 'post_status' => 'publish', |
549 | 549 | 'post_type' => 'page', |
550 | 550 | 'comment_status' => 'closed', |
551 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
551 | + 'post_content' => '['.$critical_page['code'].']', |
|
552 | 552 | ); |
553 | 553 | |
554 | 554 | $post_id = wp_insert_post($post_args); |
555 | - if (! $post_id) { |
|
555 | + if ( ! $post_id) { |
|
556 | 556 | $msg = sprintf( |
557 | 557 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
558 | 558 | $critical_page['name'] |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | return $critical_page; |
562 | 562 | } |
563 | 563 | // get newly created post's details |
564 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
564 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
565 | 565 | $msg = sprintf( |
566 | 566 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
567 | 567 | $critical_page['name'] |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | public static function get_default_creator_id() |
587 | 587 | { |
588 | 588 | global $wpdb; |
589 | - if (! empty(self::$_default_creator_id)) { |
|
589 | + if ( ! empty(self::$_default_creator_id)) { |
|
590 | 590 | return self::$_default_creator_id; |
591 | 591 | }/**/ |
592 | 592 | $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
603 | 603 | $query = $wpdb->prepare( |
604 | 604 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
605 | - '%' . $role_to_check . '%' |
|
605 | + '%'.$role_to_check.'%' |
|
606 | 606 | ); |
607 | 607 | $user_id = $wpdb->get_var($query); |
608 | 608 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
@@ -641,8 +641,8 @@ discard block |
||
641 | 641 | return; |
642 | 642 | } |
643 | 643 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
644 | - if (! function_exists('dbDelta')) { |
|
645 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
644 | + if ( ! function_exists('dbDelta')) { |
|
645 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
646 | 646 | } |
647 | 647 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
648 | 648 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -651,9 +651,9 @@ discard block |
||
651 | 651 | // ok, delete the table... but ONLY if it's empty |
652 | 652 | $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
653 | 653 | // table is NOT empty, are you SURE you want to delete this table ??? |
654 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
655 | 655 | \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
656 | - } elseif (! $deleted_safely) { |
|
656 | + } elseif ( ! $deleted_safely) { |
|
657 | 657 | // so we should be more cautious rather than just dropping tables so easily |
658 | 658 | error_log( |
659 | 659 | sprintf( |
@@ -853,13 +853,13 @@ discard block |
||
853 | 853 | // reset values array |
854 | 854 | $QSG_values = array(); |
855 | 855 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
856 | - if (! in_array("$QSG_system", $question_groups)) { |
|
856 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
857 | 857 | // add it |
858 | 858 | switch ($QSG_system) { |
859 | 859 | case 1: |
860 | 860 | $QSG_values = array( |
861 | 861 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
862 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
862 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
863 | 863 | 'QSG_desc' => '', |
864 | 864 | 'QSG_order' => 1, |
865 | 865 | 'QSG_show_group_name' => 1, |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | case 2: |
872 | 872 | $QSG_values = array( |
873 | 873 | 'QSG_name' => __('Address Information', 'event_espresso'), |
874 | - 'QSG_identifier' => 'address-information-' . time(), |
|
874 | + 'QSG_identifier' => 'address-information-'.time(), |
|
875 | 875 | 'QSG_desc' => '', |
876 | 876 | 'QSG_order' => 2, |
877 | 877 | 'QSG_show_group_name' => 1, |
@@ -882,14 +882,14 @@ discard block |
||
882 | 882 | break; |
883 | 883 | } |
884 | 884 | // make sure we have some values before inserting them |
885 | - if (! empty($QSG_values)) { |
|
885 | + if ( ! empty($QSG_values)) { |
|
886 | 886 | // insert system question |
887 | 887 | $wpdb->insert( |
888 | 888 | $table_name, |
889 | 889 | $QSG_values, |
890 | 890 | array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
891 | 891 | ); |
892 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
892 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
893 | 893 | } |
894 | 894 | } |
895 | 895 | } |
@@ -916,7 +916,7 @@ discard block |
||
916 | 916 | // reset values array |
917 | 917 | $QST_values = array(); |
918 | 918 | // if we don't have what we should have |
919 | - if (! in_array($QST_system, $questions)) { |
|
919 | + if ( ! in_array($QST_system, $questions)) { |
|
920 | 920 | // add it |
921 | 921 | switch ($QST_system) { |
922 | 922 | case 'fname': |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | ); |
1084 | 1084 | break; |
1085 | 1085 | } |
1086 | - if (! empty($QST_values)) { |
|
1086 | + if ( ! empty($QST_values)) { |
|
1087 | 1087 | // insert system question |
1088 | 1088 | $wpdb->insert( |
1089 | 1089 | $table_name, |
@@ -1101,8 +1101,8 @@ discard block |
||
1101 | 1101 | // QST_system should not be assigned to any group |
1102 | 1102 | continue; |
1103 | 1103 | } |
1104 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1105 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1104 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | 1106 | } else { |
1107 | 1107 | $id_col = EEM_Question_Group::instance() |
1108 | 1108 | ->get_col(array(array('QSG_system' => $system_question_we_want))); |
@@ -1150,7 +1150,7 @@ discard block |
||
1150 | 1150 | */ |
1151 | 1151 | public static function insert_default_payment_methods() |
1152 | 1152 | { |
1153 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1153 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1154 | 1154 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1155 | 1155 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1156 | 1156 | } else { |
@@ -1287,7 +1287,7 @@ discard block |
||
1287 | 1287 | $active_messenger->name, |
1288 | 1288 | $default_message_type_name_for_messenger |
1289 | 1289 | ) |
1290 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1290 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1291 | 1291 | ) { |
1292 | 1292 | continue; |
1293 | 1293 | } |
@@ -1300,7 +1300,7 @@ discard block |
||
1300 | 1300 | false |
1301 | 1301 | ); |
1302 | 1302 | // activate the templates for these message types |
1303 | - if (! empty($default_message_type_names_to_activate)) { |
|
1303 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1304 | 1304 | $templates_created = EEH_MSG_Template::generate_new_templates( |
1305 | 1305 | $active_messenger->name, |
1306 | 1306 | $default_message_type_names_for_messenger, |
@@ -1334,13 +1334,13 @@ discard block |
||
1334 | 1334 | $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
1335 | 1335 | // verify the default message types match an installed message type. |
1336 | 1336 | foreach ($default_message_type_names_for_messenger as $key => $name) { |
1337 | - if (! isset($installed_message_types[ $name ]) |
|
1337 | + if ( ! isset($installed_message_types[$name]) |
|
1338 | 1338 | || $message_resource_manager->has_message_type_been_activated_for_messenger( |
1339 | 1339 | $name, |
1340 | 1340 | $messenger_to_generate->name |
1341 | 1341 | ) |
1342 | 1342 | ) { |
1343 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1343 | + unset($default_message_type_names_for_messenger[$key]); |
|
1344 | 1344 | } |
1345 | 1345 | } |
1346 | 1346 | // in previous iterations, the active_messengers option in the db |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | false |
1355 | 1355 | ); |
1356 | 1356 | // create any templates needing created (or will reactivate templates already generated as necessary). |
1357 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1357 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1358 | 1358 | $templates_generated = EEH_MSG_Template::generate_new_templates( |
1359 | 1359 | $messenger_to_generate->name, |
1360 | 1360 | $default_message_type_names_for_messenger, |
@@ -1389,13 +1389,13 @@ discard block |
||
1389 | 1389 | // if installed messenger is a messenger that should be activated on install |
1390 | 1390 | // and is not already active |
1391 | 1391 | // and has never been activated |
1392 | - if (! $installed_messenger->activate_on_install |
|
1393 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1394 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1392 | + if ( ! $installed_messenger->activate_on_install |
|
1393 | + || isset($active_messengers[$installed_messenger->name]) |
|
1394 | + || isset($has_activated[$installed_messenger->name]) |
|
1395 | 1395 | ) { |
1396 | 1396 | continue; |
1397 | 1397 | } |
1398 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1398 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1399 | 1399 | } |
1400 | 1400 | return $messengers_to_generate; |
1401 | 1401 | } |
@@ -1433,7 +1433,7 @@ discard block |
||
1433 | 1433 | // this creates an array for tracking events that have no active ticket prices created |
1434 | 1434 | // this allows us to warn admins of the situation so that it can be corrected |
1435 | 1435 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1436 | - if (! $espresso_no_ticket_prices) { |
|
1436 | + if ( ! $espresso_no_ticket_prices) { |
|
1437 | 1437 | add_option('ee_no_ticket_prices', array(), '', false); |
1438 | 1438 | } |
1439 | 1439 | } |
@@ -1472,7 +1472,7 @@ discard block |
||
1472 | 1472 | } |
1473 | 1473 | } |
1474 | 1474 | // get all our CPTs |
1475 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1475 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1476 | 1476 | $cpt_ids = $wpdb->get_col($query); |
1477 | 1477 | // delete each post meta and term relations too |
1478 | 1478 | foreach ($cpt_ids as $post_id) { |
@@ -1501,7 +1501,7 @@ discard block |
||
1501 | 1501 | || ! $table->is_global()// not main site,but not global either. nuke it |
1502 | 1502 | ) |
1503 | 1503 | ) { |
1504 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1504 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1505 | 1505 | } |
1506 | 1506 | } |
1507 | 1507 | } |
@@ -1518,7 +1518,7 @@ discard block |
||
1518 | 1518 | 'esp_rule', |
1519 | 1519 | ); |
1520 | 1520 | foreach ($tables_without_models as $table) { |
1521 | - $tables[ $table ] = $table; |
|
1521 | + $tables[$table] = $table; |
|
1522 | 1522 | } |
1523 | 1523 | return \EEH_Activation::getTableManager()->dropTables($tables); |
1524 | 1524 | } |
@@ -1595,13 +1595,13 @@ discard block |
||
1595 | 1595 | $undeleted_options = array(); |
1596 | 1596 | foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
1597 | 1597 | if ($no_wildcard) { |
1598 | - if (! delete_option($option_name)) { |
|
1598 | + if ( ! delete_option($option_name)) { |
|
1599 | 1599 | $undeleted_options[] = $option_name; |
1600 | 1600 | } |
1601 | 1601 | } else { |
1602 | 1602 | $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
1603 | 1603 | foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
1604 | - if (! delete_option($option_name_from_wildcard)) { |
|
1604 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1605 | 1605 | $undeleted_options[] = $option_name_from_wildcard; |
1606 | 1606 | } |
1607 | 1607 | } |
@@ -1613,20 +1613,20 @@ discard block |
||
1613 | 1613 | $db_update_sans_ee4 = array(); |
1614 | 1614 | foreach ($espresso_db_update as $version => $times_activated) { |
1615 | 1615 | if ((string) $version[0] === '3') {// if its NON EE4 |
1616 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1616 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1617 | 1617 | } |
1618 | 1618 | } |
1619 | 1619 | update_option('espresso_db_update', $db_update_sans_ee4); |
1620 | 1620 | } |
1621 | 1621 | $errors = ''; |
1622 | - if (! empty($undeleted_options)) { |
|
1622 | + if ( ! empty($undeleted_options)) { |
|
1623 | 1623 | $errors .= sprintf( |
1624 | 1624 | __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
1625 | 1625 | '<br/>', |
1626 | 1626 | implode(',<br/>', $undeleted_options) |
1627 | 1627 | ); |
1628 | 1628 | } |
1629 | - if (! empty($errors)) { |
|
1629 | + if ( ! empty($errors)) { |
|
1630 | 1630 | EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
1631 | 1631 | } |
1632 | 1632 | } |
@@ -12,296 +12,296 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | - { |
|
23 | - // Check we have a valid datetime for the event |
|
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | - return; |
|
26 | - } |
|
27 | - |
|
28 | - $template_args = array( |
|
29 | - 'event_permalink' => '', |
|
30 | - 'event_name' => '', |
|
31 | - 'event_description' => '', |
|
32 | - 'event_start' => '', |
|
33 | - 'event_end' => '', |
|
34 | - 'event_attendance_mode' => '', |
|
35 | - 'event_status' => '', |
|
36 | - 'currency' => '', |
|
37 | - 'event_tickets' => array(), |
|
38 | - 'venue_name' => '', |
|
39 | - 'venue_url' => '', |
|
40 | - 'venue_locality' => '', |
|
41 | - 'venue_region' => '', |
|
42 | - 'venue_address' => '', |
|
43 | - 'event_image' => '', |
|
44 | - ); |
|
45 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
46 | - $template_args['event_name'] = $event->name(); |
|
47 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
48 | - // clone datetime so that date formats don't override those for the original datetime |
|
49 | - $primary_datetime = clone $event->primary_datetime(); |
|
50 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
51 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
52 | - unset($primary_datetime); |
|
53 | - switch ($event->status()) { |
|
54 | - case EEM_Event::cancelled: |
|
55 | - $event_status = 'EventCancelled'; |
|
56 | - break; |
|
57 | - case EEM_Event::postponed: |
|
58 | - $event_status = 'EventPostponed'; |
|
59 | - break; |
|
60 | - default: |
|
61 | - $event_status = 'EventScheduled'; |
|
62 | - } |
|
63 | - $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
|
64 | - $template_args['event_status'] = '"https://schema.org/' . $event_status . '"'; |
|
65 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
66 | - foreach ($event->tickets() as $original_ticket) { |
|
67 | - // clone tickets so that date formats don't override those for the original ticket |
|
68 | - $ticket= clone $original_ticket; |
|
69 | - $ID = $ticket->ID(); |
|
70 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
73 | - $ticket->price(), |
|
74 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
75 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
76 | - '' |
|
77 | - ); |
|
78 | - switch ($ticket->ticket_status()) { |
|
79 | - case 'TKO': |
|
80 | - $availability = 'InStock'; |
|
81 | - break; |
|
82 | - case 'TKS': |
|
83 | - $availability = 'SoldOut'; |
|
84 | - break; |
|
85 | - default: |
|
86 | - $availability = null; |
|
87 | - break; |
|
88 | - } |
|
89 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
90 | - unset($ticket); |
|
91 | - } |
|
92 | - $VNU_ID = espresso_venue_id(); |
|
93 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
94 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
95 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
96 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
97 | - $template_args['venue_locality'] = $venue->city(); |
|
98 | - $template_args['venue_region'] = $venue->state_name(); |
|
99 | - $template_args['venue_address'] = $venue->address(); |
|
100 | - if ($venue->virtual_url() !== '') { |
|
101 | - $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode'; |
|
102 | - } |
|
103 | - if ($venue->virtual_url() !== '' && $venue->address() !== '') { |
|
104 | - $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode'; |
|
105 | - } |
|
106 | - } |
|
107 | - $template_args['event_image'] = $event->feature_image_url(); |
|
108 | - $template_args = apply_filters( |
|
109 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
110 | - $template_args, |
|
111 | - $event, |
|
112 | - $VNU_ID |
|
113 | - ); |
|
114 | - extract($template_args, EXTR_OVERWRITE); |
|
115 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * location |
|
121 | - * The location of the event, organization or action. |
|
122 | - * Should include the Venue name AND schema formatted address info |
|
123 | - * |
|
124 | - * @access public |
|
125 | - * @param string $location |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public static function location($location = null) |
|
129 | - { |
|
130 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
131 | - . $location |
|
132 | - . '</div>' : ''; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * name |
|
139 | - * The name of the Event or Venue. |
|
140 | - * |
|
141 | - * @access public |
|
142 | - * @param string $name |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public static function name($name = null) |
|
146 | - { |
|
147 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * streetAddress |
|
154 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
155 | - * |
|
156 | - * @access public |
|
157 | - * @param EEI_Address $obj_with_address |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public static function streetAddress(EEI_Address $obj_with_address = null) |
|
161 | - { |
|
162 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
163 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * postOfficeBoxNumber |
|
170 | - * The post office box number for PO box addresses. |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param EEI_Address $obj_with_address |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
177 | - { |
|
178 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
179 | - if (preg_match( |
|
180 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
181 | - $obj_with_address->address2() |
|
182 | - ) ) { |
|
183 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
184 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
185 | - } else { |
|
186 | - return $obj_with_address->address2(); |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * addressLocality |
|
194 | - * The locality (city, town, etc). For example, Mountain View. |
|
195 | - * |
|
196 | - * @access public |
|
197 | - * @param EEI_Address $obj_with_address |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - public static function addressLocality(EEI_Address $obj_with_address = null) |
|
201 | - { |
|
202 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
203 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * addressRegion |
|
210 | - * The region (state, province, etc). For example, CA. |
|
211 | - * |
|
212 | - * @access public |
|
213 | - * @param EEI_Address $obj_with_address |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public static function addressRegion(EEI_Address $obj_with_address = null) |
|
217 | - { |
|
218 | - $state = $obj_with_address->state_name(); |
|
219 | - if (! empty($state)) { |
|
220 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
221 | - } else { |
|
222 | - return ''; |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * addressCountry |
|
230 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
231 | - * |
|
232 | - * @access public |
|
233 | - * @param EEI_Address $obj_with_address |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public static function addressCountry(EEI_Address $obj_with_address = null) |
|
237 | - { |
|
238 | - $country = $obj_with_address->country_name(); |
|
239 | - if (! empty($country)) { |
|
240 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
241 | - } else { |
|
242 | - return ''; |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * postalCode |
|
250 | - * The postal code. For example, 94043. |
|
251 | - * |
|
252 | - * @access public |
|
253 | - * @param EEI_Address $obj_with_address |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public static function postalCode(EEI_Address $obj_with_address = null) |
|
257 | - { |
|
258 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
259 | - . $obj_with_address->zip() |
|
260 | - . '</span>' : ''; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * telephone |
|
267 | - * The telephone number. |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @param string $phone_nmbr |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - public static function telephone($phone_nmbr = null) |
|
274 | - { |
|
275 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
276 | - : ''; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * URL |
|
283 | - * URL of the item as a clickable link |
|
284 | - * |
|
285 | - * @access public |
|
286 | - * @param string $url - the URL that the link will resolve to |
|
287 | - * @param string $text - the text that will be used for the visible link |
|
288 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
289 | - * @return string (link) |
|
290 | - */ |
|
291 | - public static function url($url = null, $text = null, $attributes = array()) |
|
292 | - { |
|
293 | - // Check the URL includes a scheme |
|
294 | - $parsed_url = parse_url($url); |
|
295 | - if (empty($parsed_url['scheme'])) { |
|
296 | - $url = 'http://' . ltrim($url, '/'); |
|
297 | - } |
|
298 | - |
|
299 | - $atts = ''; |
|
300 | - foreach ($attributes as $attribute => $value) { |
|
301 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
302 | - } |
|
303 | - $text = $text !== null && $text !== '' ? $text : $url; |
|
304 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
305 | - : ''; |
|
306 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | + { |
|
23 | + // Check we have a valid datetime for the event |
|
24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | + return; |
|
26 | + } |
|
27 | + |
|
28 | + $template_args = array( |
|
29 | + 'event_permalink' => '', |
|
30 | + 'event_name' => '', |
|
31 | + 'event_description' => '', |
|
32 | + 'event_start' => '', |
|
33 | + 'event_end' => '', |
|
34 | + 'event_attendance_mode' => '', |
|
35 | + 'event_status' => '', |
|
36 | + 'currency' => '', |
|
37 | + 'event_tickets' => array(), |
|
38 | + 'venue_name' => '', |
|
39 | + 'venue_url' => '', |
|
40 | + 'venue_locality' => '', |
|
41 | + 'venue_region' => '', |
|
42 | + 'venue_address' => '', |
|
43 | + 'event_image' => '', |
|
44 | + ); |
|
45 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
46 | + $template_args['event_name'] = $event->name(); |
|
47 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
48 | + // clone datetime so that date formats don't override those for the original datetime |
|
49 | + $primary_datetime = clone $event->primary_datetime(); |
|
50 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
51 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
52 | + unset($primary_datetime); |
|
53 | + switch ($event->status()) { |
|
54 | + case EEM_Event::cancelled: |
|
55 | + $event_status = 'EventCancelled'; |
|
56 | + break; |
|
57 | + case EEM_Event::postponed: |
|
58 | + $event_status = 'EventPostponed'; |
|
59 | + break; |
|
60 | + default: |
|
61 | + $event_status = 'EventScheduled'; |
|
62 | + } |
|
63 | + $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
|
64 | + $template_args['event_status'] = '"https://schema.org/' . $event_status . '"'; |
|
65 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
66 | + foreach ($event->tickets() as $original_ticket) { |
|
67 | + // clone tickets so that date formats don't override those for the original ticket |
|
68 | + $ticket= clone $original_ticket; |
|
69 | + $ID = $ticket->ID(); |
|
70 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
73 | + $ticket->price(), |
|
74 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
75 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
76 | + '' |
|
77 | + ); |
|
78 | + switch ($ticket->ticket_status()) { |
|
79 | + case 'TKO': |
|
80 | + $availability = 'InStock'; |
|
81 | + break; |
|
82 | + case 'TKS': |
|
83 | + $availability = 'SoldOut'; |
|
84 | + break; |
|
85 | + default: |
|
86 | + $availability = null; |
|
87 | + break; |
|
88 | + } |
|
89 | + $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
90 | + unset($ticket); |
|
91 | + } |
|
92 | + $VNU_ID = espresso_venue_id(); |
|
93 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
94 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
95 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
96 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
97 | + $template_args['venue_locality'] = $venue->city(); |
|
98 | + $template_args['venue_region'] = $venue->state_name(); |
|
99 | + $template_args['venue_address'] = $venue->address(); |
|
100 | + if ($venue->virtual_url() !== '') { |
|
101 | + $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode'; |
|
102 | + } |
|
103 | + if ($venue->virtual_url() !== '' && $venue->address() !== '') { |
|
104 | + $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode'; |
|
105 | + } |
|
106 | + } |
|
107 | + $template_args['event_image'] = $event->feature_image_url(); |
|
108 | + $template_args = apply_filters( |
|
109 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
110 | + $template_args, |
|
111 | + $event, |
|
112 | + $VNU_ID |
|
113 | + ); |
|
114 | + extract($template_args, EXTR_OVERWRITE); |
|
115 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * location |
|
121 | + * The location of the event, organization or action. |
|
122 | + * Should include the Venue name AND schema formatted address info |
|
123 | + * |
|
124 | + * @access public |
|
125 | + * @param string $location |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public static function location($location = null) |
|
129 | + { |
|
130 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
131 | + . $location |
|
132 | + . '</div>' : ''; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * name |
|
139 | + * The name of the Event or Venue. |
|
140 | + * |
|
141 | + * @access public |
|
142 | + * @param string $name |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public static function name($name = null) |
|
146 | + { |
|
147 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * streetAddress |
|
154 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
155 | + * |
|
156 | + * @access public |
|
157 | + * @param EEI_Address $obj_with_address |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public static function streetAddress(EEI_Address $obj_with_address = null) |
|
161 | + { |
|
162 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
163 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * postOfficeBoxNumber |
|
170 | + * The post office box number for PO box addresses. |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param EEI_Address $obj_with_address |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
177 | + { |
|
178 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
179 | + if (preg_match( |
|
180 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
181 | + $obj_with_address->address2() |
|
182 | + ) ) { |
|
183 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
184 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
185 | + } else { |
|
186 | + return $obj_with_address->address2(); |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * addressLocality |
|
194 | + * The locality (city, town, etc). For example, Mountain View. |
|
195 | + * |
|
196 | + * @access public |
|
197 | + * @param EEI_Address $obj_with_address |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + public static function addressLocality(EEI_Address $obj_with_address = null) |
|
201 | + { |
|
202 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
203 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * addressRegion |
|
210 | + * The region (state, province, etc). For example, CA. |
|
211 | + * |
|
212 | + * @access public |
|
213 | + * @param EEI_Address $obj_with_address |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public static function addressRegion(EEI_Address $obj_with_address = null) |
|
217 | + { |
|
218 | + $state = $obj_with_address->state_name(); |
|
219 | + if (! empty($state)) { |
|
220 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
221 | + } else { |
|
222 | + return ''; |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * addressCountry |
|
230 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
231 | + * |
|
232 | + * @access public |
|
233 | + * @param EEI_Address $obj_with_address |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public static function addressCountry(EEI_Address $obj_with_address = null) |
|
237 | + { |
|
238 | + $country = $obj_with_address->country_name(); |
|
239 | + if (! empty($country)) { |
|
240 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
241 | + } else { |
|
242 | + return ''; |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * postalCode |
|
250 | + * The postal code. For example, 94043. |
|
251 | + * |
|
252 | + * @access public |
|
253 | + * @param EEI_Address $obj_with_address |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public static function postalCode(EEI_Address $obj_with_address = null) |
|
257 | + { |
|
258 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
259 | + . $obj_with_address->zip() |
|
260 | + . '</span>' : ''; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * telephone |
|
267 | + * The telephone number. |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @param string $phone_nmbr |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + public static function telephone($phone_nmbr = null) |
|
274 | + { |
|
275 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
276 | + : ''; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * URL |
|
283 | + * URL of the item as a clickable link |
|
284 | + * |
|
285 | + * @access public |
|
286 | + * @param string $url - the URL that the link will resolve to |
|
287 | + * @param string $text - the text that will be used for the visible link |
|
288 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
289 | + * @return string (link) |
|
290 | + */ |
|
291 | + public static function url($url = null, $text = null, $attributes = array()) |
|
292 | + { |
|
293 | + // Check the URL includes a scheme |
|
294 | + $parsed_url = parse_url($url); |
|
295 | + if (empty($parsed_url['scheme'])) { |
|
296 | + $url = 'http://' . ltrim($url, '/'); |
|
297 | + } |
|
298 | + |
|
299 | + $atts = ''; |
|
300 | + foreach ($attributes as $attribute => $value) { |
|
301 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
302 | + } |
|
303 | + $text = $text !== null && $text !== '' ? $text : $url; |
|
304 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
305 | + : ''; |
|
306 | + } |
|
307 | 307 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public static function add_json_linked_data_for_event(EE_Event $event) |
22 | 22 | { |
23 | 23 | // Check we have a valid datetime for the event |
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
24 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | $event_status = 'EventScheduled'; |
62 | 62 | } |
63 | 63 | $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
64 | - $template_args['event_status'] = '"https://schema.org/' . $event_status . '"'; |
|
64 | + $template_args['event_status'] = '"https://schema.org/'.$event_status.'"'; |
|
65 | 65 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
66 | 66 | foreach ($event->tickets() as $original_ticket) { |
67 | 67 | // clone tickets so that date formats don't override those for the original ticket |
68 | - $ticket= clone $original_ticket; |
|
68 | + $ticket = clone $original_ticket; |
|
69 | 69 | $ID = $ticket->ID(); |
70 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
70 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
73 | 73 | $ticket->price(), |
74 | 74 | EE_Registry::instance()->CFG->currency->dec_plc, |
75 | 75 | EE_Registry::instance()->CFG->currency->dec_mrk, |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | $availability = null; |
87 | 87 | break; |
88 | 88 | } |
89 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
89 | + $template_args['event_tickets'][$ID]['availability'] = $availability; |
|
90 | 90 | unset($ticket); |
91 | 91 | } |
92 | 92 | $VNU_ID = espresso_venue_id(); |
93 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
93 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
94 | 94 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
95 | 95 | $template_args['venue_name'] = get_the_title($VNU_ID); |
96 | 96 | $template_args['venue_url'] = get_permalink($VNU_ID); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $VNU_ID |
113 | 113 | ); |
114 | 114 | extract($template_args, EXTR_OVERWRITE); |
115 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
115 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public static function name($name = null) |
146 | 146 | { |
147 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
147 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | public static function streetAddress(EEI_Address $obj_with_address = null) |
161 | 161 | { |
162 | 162 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
163 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
163 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | if (preg_match( |
180 | 180 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
181 | 181 | $obj_with_address->address2() |
182 | - ) ) { |
|
182 | + )) { |
|
183 | 183 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
184 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
184 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
185 | 185 | } else { |
186 | 186 | return $obj_with_address->address2(); |
187 | 187 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | public static function addressLocality(EEI_Address $obj_with_address = null) |
201 | 201 | { |
202 | 202 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
203 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
203 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | public static function addressRegion(EEI_Address $obj_with_address = null) |
217 | 217 | { |
218 | 218 | $state = $obj_with_address->state_name(); |
219 | - if (! empty($state)) { |
|
220 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
219 | + if ( ! empty($state)) { |
|
220 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
221 | 221 | } else { |
222 | 222 | return ''; |
223 | 223 | } |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | public static function addressCountry(EEI_Address $obj_with_address = null) |
237 | 237 | { |
238 | 238 | $country = $obj_with_address->country_name(); |
239 | - if (! empty($country)) { |
|
240 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
239 | + if ( ! empty($country)) { |
|
240 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
241 | 241 | } else { |
242 | 242 | return ''; |
243 | 243 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public static function telephone($phone_nmbr = null) |
274 | 274 | { |
275 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
275 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
276 | 276 | : ''; |
277 | 277 | } |
278 | 278 | |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | // Check the URL includes a scheme |
294 | 294 | $parsed_url = parse_url($url); |
295 | 295 | if (empty($parsed_url['scheme'])) { |
296 | - $url = 'http://' . ltrim($url, '/'); |
|
296 | + $url = 'http://'.ltrim($url, '/'); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | $atts = ''; |
300 | 300 | foreach ($attributes as $attribute => $value) { |
301 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
301 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
302 | 302 | } |
303 | 303 | $text = $text !== null && $text !== '' ? $text : $url; |
304 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
304 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
305 | 305 | : ''; |
306 | 306 | } |
307 | 307 | } |