@@ -18,72 +18,72 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @param string $validation_error_message |
|
23 | - */ |
|
24 | - public function __construct($validation_error_message = '') |
|
25 | - { |
|
26 | - if (! $validation_error_message) { |
|
27 | - $validation_error_message = esc_html__('Please enter a valid email address.', 'event_espresso'); |
|
28 | - } |
|
29 | - parent::__construct($validation_error_message); |
|
30 | - } |
|
21 | + /** |
|
22 | + * @param string $validation_error_message |
|
23 | + */ |
|
24 | + public function __construct($validation_error_message = '') |
|
25 | + { |
|
26 | + if (! $validation_error_message) { |
|
27 | + $validation_error_message = esc_html__('Please enter a valid email address.', 'event_espresso'); |
|
28 | + } |
|
29 | + parent::__construct($validation_error_message); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * just checks the field isn't blank |
|
36 | - * |
|
37 | - * @param $normalized_value |
|
38 | - * @return bool |
|
39 | - * @throws InvalidArgumentException |
|
40 | - * @throws InvalidInterfaceException |
|
41 | - * @throws InvalidDataTypeException |
|
42 | - * @throws EE_Validation_Error |
|
43 | - */ |
|
44 | - public function validate($normalized_value) |
|
45 | - { |
|
46 | - if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
47 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
48 | - } |
|
49 | - return true; |
|
50 | - } |
|
34 | + /** |
|
35 | + * just checks the field isn't blank |
|
36 | + * |
|
37 | + * @param $normalized_value |
|
38 | + * @return bool |
|
39 | + * @throws InvalidArgumentException |
|
40 | + * @throws InvalidInterfaceException |
|
41 | + * @throws InvalidDataTypeException |
|
42 | + * @throws EE_Validation_Error |
|
43 | + */ |
|
44 | + public function validate($normalized_value) |
|
45 | + { |
|
46 | + if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
47 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
48 | + } |
|
49 | + return true; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function get_jquery_validation_rule_array() |
|
58 | - { |
|
59 | - return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function get_jquery_validation_rule_array() |
|
58 | + { |
|
59 | + return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * Validate an email address. |
|
66 | - * Provide email address (raw input) |
|
67 | - * |
|
68 | - * @param $email |
|
69 | - * @return bool of whether the email is valid or not |
|
70 | - * @throws InvalidArgumentException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - * @throws InvalidDataTypeException |
|
73 | - * @throws EE_Validation_Error |
|
74 | - */ |
|
75 | - private function _validate_email($email) |
|
76 | - { |
|
77 | - try { |
|
78 | - EmailAddressFactory::create($email); |
|
79 | - } catch (EmailValidationException $e) { |
|
80 | - throw new EE_Validation_Error( |
|
81 | - $e->getMessage(), |
|
82 | - 'invalid_email', |
|
83 | - $this->_input, |
|
84 | - $e |
|
85 | - ); |
|
86 | - } |
|
87 | - return true; |
|
88 | - } |
|
64 | + /** |
|
65 | + * Validate an email address. |
|
66 | + * Provide email address (raw input) |
|
67 | + * |
|
68 | + * @param $email |
|
69 | + * @return bool of whether the email is valid or not |
|
70 | + * @throws InvalidArgumentException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + * @throws InvalidDataTypeException |
|
73 | + * @throws EE_Validation_Error |
|
74 | + */ |
|
75 | + private function _validate_email($email) |
|
76 | + { |
|
77 | + try { |
|
78 | + EmailAddressFactory::create($email); |
|
79 | + } catch (EmailValidationException $e) { |
|
80 | + throw new EE_Validation_Error( |
|
81 | + $e->getMessage(), |
|
82 | + 'invalid_email', |
|
83 | + $this->_input, |
|
84 | + $e |
|
85 | + ); |
|
86 | + } |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct($validation_error_message = '') |
25 | 25 | { |
26 | - if (! $validation_error_message) { |
|
26 | + if ( ! $validation_error_message) { |
|
27 | 27 | $validation_error_message = esc_html__('Please enter a valid email address.', 'event_espresso'); |
28 | 28 | } |
29 | 29 | parent::__construct($validation_error_message); |
@@ -351,7 +351,7 @@ |
||
351 | 351 | * retrieve a single attendee from db via their ID |
352 | 352 | * |
353 | 353 | * @param $ATT_ID |
354 | - * @return mixed array on success, FALSE on fail |
|
354 | + * @return EE_Base_Class|null array on success, FALSE on fail |
|
355 | 355 | * @deprecated |
356 | 356 | */ |
357 | 357 | public function get_attendee_by_ID($ATT_ID = false) |
@@ -1,5 +1,4 @@ |
||
1 | 1 | <?php |
2 | -use EventEspresso\core\services\loaders\Loader; |
|
3 | 2 | use EventEspresso\core\services\orm\ModelFieldFactory; |
4 | 3 | |
5 | 4 | /** |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function get_attendee_field_for_system_question($system_question_string) |
286 | 286 | { |
287 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
288 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
287 | + return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
|
288 | + ? $this->_system_question_to_attendee_field_name[$system_question_string] |
|
289 | 289 | : null; |
290 | 290 | } |
291 | 291 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | $attendee = $this->get_all(array($where_cols_n_values)); |
356 | - if (! empty($attendee)) { |
|
356 | + if ( ! empty($attendee)) { |
|
357 | 357 | return array_shift($attendee); |
358 | 358 | } |
359 | 359 | return false; |
@@ -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 | } |
@@ -456,7 +456,7 @@ |
||
456 | 456 | * be empty |
457 | 457 | * |
458 | 458 | * @since 4.3.1 |
459 | - * @return array |
|
459 | + * @return string[] |
|
460 | 460 | */ |
461 | 461 | private function _parse_from() |
462 | 462 | { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | ), |
57 | 57 | '<code>wp_mail</code>' |
58 | 58 | ); |
59 | - $this->label = array( |
|
59 | + $this->label = array( |
|
60 | 60 | 'singular' => esc_html__('email', 'event_espresso'), |
61 | 61 | 'plural' => esc_html__('emails', 'event_espresso'), |
62 | 62 | ); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | $this->_body(), |
439 | 439 | $this->_headers() |
440 | 440 | ); |
441 | - if (! $success) { |
|
441 | + if ( ! $success) { |
|
442 | 442 | EE_Error::add_error( |
443 | 443 | sprintf( |
444 | 444 | esc_html__( |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | $this->_ensure_has_from_email_address(); |
483 | 483 | $from = $this->_from; |
484 | 484 | $headers = array( |
485 | - 'From:' . $from, |
|
486 | - 'Reply-To:' . $from, |
|
485 | + 'From:'.$from, |
|
486 | + 'Reply-To:'.$from, |
|
487 | 487 | 'Content-Type:text/html; charset=utf-8', |
488 | 488 | ); |
489 | 489 | |
@@ -492,8 +492,8 @@ discard block |
||
492 | 492 | * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
493 | 493 | * type which they are no longer able to change. |
494 | 494 | */ |
495 | - if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
496 | - $headers[] = 'cc: ' . $this->_cc; |
|
495 | + if ( ! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
496 | + $headers[] = 'cc: '.$this->_cc; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | // but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | 'from' => $this->_from, |
601 | 601 | 'main_body' => wpautop($this->_content), |
602 | 602 | ); |
603 | - $body = $this->_get_main_template($preview); |
|
603 | + $body = $this->_get_main_template($preview); |
|
604 | 604 | |
605 | 605 | /** |
606 | 606 | * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
@@ -610,10 +610,10 @@ discard block |
||
610 | 610 | */ |
611 | 611 | if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
612 | 612 | // require CssToInlineStyles library and its dependencies via composer autoloader |
613 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
613 | + require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php'; |
|
614 | 614 | |
615 | 615 | // now if this isn't a preview, let's setup the body so it has inline styles |
616 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
616 | + if ( ! $preview || ($preview && defined('DOING_AJAX'))) { |
|
617 | 617 | $style = file_get_contents( |
618 | 618 | $this->get_variation( |
619 | 619 | $this->_tmp_pack, |
@@ -6,648 +6,648 @@ |
||
6 | 6 | class EE_Email_messenger extends EE_messenger |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * To field for email |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - protected $_to = ''; |
|
14 | - |
|
15 | - |
|
16 | - /** |
|
17 | - * CC field for email. |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $_cc = ''; |
|
21 | - |
|
22 | - /** |
|
23 | - * From field for email |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $_from = ''; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Subject field for email |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $_subject = ''; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * Content field for email |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $_content = ''; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * constructor |
|
45 | - * |
|
46 | - * @access public |
|
47 | - */ |
|
48 | - public function __construct() |
|
49 | - { |
|
50 | - // set name and description properties |
|
51 | - $this->name = 'email'; |
|
52 | - $this->description = sprintf( |
|
53 | - esc_html__( |
|
54 | - 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
55 | - 'event_espresso' |
|
56 | - ), |
|
57 | - '<code>wp_mail</code>' |
|
58 | - ); |
|
59 | - $this->label = array( |
|
60 | - 'singular' => esc_html__('email', 'event_espresso'), |
|
61 | - 'plural' => esc_html__('emails', 'event_espresso'), |
|
62 | - ); |
|
63 | - $this->activate_on_install = true; |
|
64 | - |
|
65 | - // we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
66 | - // properties |
|
67 | - parent::__construct(); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * see abstract declaration in parent class for details. |
|
73 | - */ |
|
74 | - protected function _set_admin_pages() |
|
75 | - { |
|
76 | - $this->admin_registered_pages = array( |
|
77 | - 'events_edit' => true, |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * see abstract declaration in parent class for details |
|
84 | - */ |
|
85 | - protected function _set_valid_shortcodes() |
|
86 | - { |
|
87 | - // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
88 | - // message type. |
|
89 | - $this->_valid_shortcodes = array( |
|
90 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
91 | - 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
92 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * see abstract declaration in parent class for details |
|
99 | - * |
|
100 | - * @access protected |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - protected function _set_validator_config() |
|
104 | - { |
|
105 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
106 | - |
|
107 | - $this->_validator_config = array( |
|
108 | - 'to' => array( |
|
109 | - 'shortcodes' => $valid_shortcodes['to'], |
|
110 | - 'type' => 'email', |
|
111 | - ), |
|
112 | - 'cc' => array( |
|
113 | - 'shortcodes' => $valid_shortcodes['to'], |
|
114 | - 'type' => 'email', |
|
115 | - ), |
|
116 | - 'from' => array( |
|
117 | - 'shortcodes' => $valid_shortcodes['from'], |
|
118 | - 'type' => 'email', |
|
119 | - ), |
|
120 | - 'subject' => array( |
|
121 | - 'shortcodes' => array( |
|
122 | - 'organization', |
|
123 | - 'primary_registration_details', |
|
124 | - 'event_author', |
|
125 | - 'primary_registration_details', |
|
126 | - 'recipient_details', |
|
127 | - ), |
|
128 | - ), |
|
129 | - 'content' => array( |
|
130 | - 'shortcodes' => array( |
|
131 | - 'event_list', |
|
132 | - 'attendee_list', |
|
133 | - 'ticket_list', |
|
134 | - 'organization', |
|
135 | - 'primary_registration_details', |
|
136 | - 'primary_registration_list', |
|
137 | - 'event_author', |
|
138 | - 'recipient_details', |
|
139 | - 'recipient_list', |
|
140 | - 'transaction', |
|
141 | - 'messenger', |
|
142 | - ), |
|
143 | - ), |
|
144 | - 'attendee_list' => array( |
|
145 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
146 | - 'required' => array('[ATTENDEE_LIST]'), |
|
147 | - ), |
|
148 | - 'event_list' => array( |
|
149 | - 'shortcodes' => array( |
|
150 | - 'event', |
|
151 | - 'attendee_list', |
|
152 | - 'ticket_list', |
|
153 | - 'venue', |
|
154 | - 'datetime_list', |
|
155 | - 'attendee', |
|
156 | - 'primary_registration_details', |
|
157 | - 'primary_registration_list', |
|
158 | - 'event_author', |
|
159 | - 'recipient_details', |
|
160 | - 'recipient_list', |
|
161 | - ), |
|
162 | - 'required' => array('[EVENT_LIST]'), |
|
163 | - ), |
|
164 | - 'ticket_list' => array( |
|
165 | - 'shortcodes' => array( |
|
166 | - 'event_list', |
|
167 | - 'attendee_list', |
|
168 | - 'ticket', |
|
169 | - 'datetime_list', |
|
170 | - 'primary_registration_details', |
|
171 | - 'recipient_details', |
|
172 | - ), |
|
173 | - 'required' => array('[TICKET_LIST]'), |
|
174 | - ), |
|
175 | - 'datetime_list' => array( |
|
176 | - 'shortcodes' => array('datetime'), |
|
177 | - 'required' => array('[DATETIME_LIST]'), |
|
178 | - ), |
|
179 | - ); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @see parent EE_messenger class for docs |
|
185 | - * @since 4.5.0 |
|
186 | - */ |
|
187 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
188 | - { |
|
189 | - if ($sending_messenger_name === 'html') { |
|
190 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - public function add_email_css( |
|
196 | - $variation_path, |
|
197 | - $messenger, |
|
198 | - $message_type, |
|
199 | - $type, |
|
200 | - $variation, |
|
201 | - $file_extension, |
|
202 | - $url, |
|
203 | - EE_Messages_Template_Pack $template_pack |
|
204 | - ) { |
|
205 | - // prevent recursion on this callback. |
|
206 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
207 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
208 | - |
|
209 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
210 | - return $variation; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * See parent for details |
|
216 | - * |
|
217 | - * @access protected |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - protected function _set_test_settings_fields() |
|
221 | - { |
|
222 | - $this->_test_settings_fields = array( |
|
223 | - 'to' => array( |
|
224 | - 'input' => 'text', |
|
225 | - 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
226 | - 'type' => 'email', |
|
227 | - 'required' => true, |
|
228 | - 'validation' => true, |
|
229 | - 'css_class' => 'large-text', |
|
230 | - 'format' => '%s', |
|
231 | - 'default' => get_bloginfo('admin_email'), |
|
232 | - ), |
|
233 | - 'subject' => array( |
|
234 | - 'input' => 'hidden', |
|
235 | - 'label' => '', |
|
236 | - 'type' => 'string', |
|
237 | - 'required' => false, |
|
238 | - 'validation' => false, |
|
239 | - 'format' => '%s', |
|
240 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
241 | - 'default' => '', |
|
242 | - 'css_class' => '', |
|
243 | - ), |
|
244 | - ); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * _set_template_fields |
|
250 | - * This sets up the fields that a messenger requires for the message to go out. |
|
251 | - * |
|
252 | - * @access protected |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - protected function _set_template_fields() |
|
256 | - { |
|
257 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
258 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
259 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
260 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
261 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
262 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
263 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
264 | - // will not be displayed/parsed. |
|
265 | - $this->_template_fields = array( |
|
266 | - 'to' => array( |
|
267 | - 'input' => 'text', |
|
268 | - 'label' => esc_html_x( |
|
269 | - 'To', |
|
270 | - 'Label for the "To" field for email addresses', |
|
271 | - 'event_espresso' |
|
272 | - ), |
|
273 | - 'type' => 'string', |
|
274 | - 'required' => true, |
|
275 | - 'validation' => true, |
|
276 | - 'css_class' => 'large-text', |
|
277 | - 'format' => '%s', |
|
278 | - ), |
|
279 | - 'cc' => array( |
|
280 | - 'input' => 'text', |
|
281 | - 'label' => esc_html_x( |
|
282 | - 'CC', |
|
283 | - 'Label for the "Carbon Copy" field used for additional email addresses', |
|
284 | - 'event_espresso' |
|
285 | - ), |
|
286 | - 'type' => 'string', |
|
287 | - 'required' => false, |
|
288 | - 'validation' => true, |
|
289 | - 'css_class' => 'large-text', |
|
290 | - 'format' => '%s', |
|
291 | - ), |
|
292 | - 'from' => array( |
|
293 | - 'input' => 'text', |
|
294 | - 'label' => esc_html_x( |
|
295 | - 'From', |
|
296 | - 'Label for the "From" field for email addresses.', |
|
297 | - 'event_espresso' |
|
298 | - ), |
|
299 | - 'type' => 'string', |
|
300 | - 'required' => true, |
|
301 | - 'validation' => true, |
|
302 | - 'css_class' => 'large-text', |
|
303 | - 'format' => '%s', |
|
304 | - ), |
|
305 | - 'subject' => array( |
|
306 | - 'input' => 'text', |
|
307 | - 'label' => esc_html_x( |
|
308 | - 'Subject', |
|
309 | - 'Label for the "Subject" field (short description of contents) for emails.', |
|
310 | - 'event_espresso' |
|
311 | - ), |
|
312 | - 'type' => 'string', |
|
313 | - 'required' => true, |
|
314 | - 'validation' => true, |
|
315 | - 'css_class' => 'large-text', |
|
316 | - 'format' => '%s', |
|
317 | - ), |
|
318 | - 'content' => '', |
|
319 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
320 | - 'extra' => array( |
|
321 | - 'content' => array( |
|
322 | - 'main' => array( |
|
323 | - 'input' => 'wp_editor', |
|
324 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
325 | - 'type' => 'string', |
|
326 | - 'required' => true, |
|
327 | - 'validation' => true, |
|
328 | - 'format' => '%s', |
|
329 | - 'rows' => '15', |
|
330 | - ), |
|
331 | - 'event_list' => array( |
|
332 | - 'input' => 'wp_editor', |
|
333 | - 'label' => '[EVENT_LIST]', |
|
334 | - 'type' => 'string', |
|
335 | - 'required' => true, |
|
336 | - 'validation' => true, |
|
337 | - 'format' => '%s', |
|
338 | - 'rows' => '15', |
|
339 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
340 | - ), |
|
341 | - 'attendee_list' => array( |
|
342 | - 'input' => 'textarea', |
|
343 | - 'label' => '[ATTENDEE_LIST]', |
|
344 | - 'type' => 'string', |
|
345 | - 'required' => true, |
|
346 | - 'validation' => true, |
|
347 | - 'format' => '%s', |
|
348 | - 'css_class' => 'large-text', |
|
349 | - 'rows' => '5', |
|
350 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
351 | - ), |
|
352 | - 'ticket_list' => array( |
|
353 | - 'input' => 'textarea', |
|
354 | - 'label' => '[TICKET_LIST]', |
|
355 | - 'type' => 'string', |
|
356 | - 'required' => true, |
|
357 | - 'validation' => true, |
|
358 | - 'format' => '%s', |
|
359 | - 'css_class' => 'large-text', |
|
360 | - 'rows' => '10', |
|
361 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
362 | - ), |
|
363 | - 'datetime_list' => array( |
|
364 | - 'input' => 'textarea', |
|
365 | - 'label' => '[DATETIME_LIST]', |
|
366 | - 'type' => 'string', |
|
367 | - 'required' => true, |
|
368 | - 'validation' => true, |
|
369 | - 'format' => '%s', |
|
370 | - 'css_class' => 'large-text', |
|
371 | - 'rows' => '10', |
|
372 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
373 | - ), |
|
374 | - ), |
|
375 | - ), |
|
376 | - ); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * See definition of this class in parent |
|
382 | - */ |
|
383 | - protected function _set_default_message_types() |
|
384 | - { |
|
385 | - $this->_default_message_types = array( |
|
386 | - 'payment', |
|
387 | - 'payment_refund', |
|
388 | - 'registration', |
|
389 | - 'not_approved_registration', |
|
390 | - 'pending_approval', |
|
391 | - ); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * @see definition of this class in parent |
|
397 | - * @since 4.5.0 |
|
398 | - */ |
|
399 | - protected function _set_valid_message_types() |
|
400 | - { |
|
401 | - $this->_valid_message_types = array( |
|
402 | - 'payment', |
|
403 | - 'registration', |
|
404 | - 'not_approved_registration', |
|
405 | - 'declined_registration', |
|
406 | - 'cancelled_registration', |
|
407 | - 'pending_approval', |
|
408 | - 'registration_summary', |
|
409 | - 'payment_reminder', |
|
410 | - 'payment_declined', |
|
411 | - 'payment_refund', |
|
412 | - ); |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * setting up admin_settings_fields for messenger. |
|
418 | - */ |
|
419 | - protected function _set_admin_settings_fields() |
|
420 | - { |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * We just deliver the messages don't kill us!! |
|
425 | - * |
|
426 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
427 | - * present. |
|
428 | - * @throws EE_Error |
|
429 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
430 | - */ |
|
431 | - protected function _send_message() |
|
432 | - { |
|
433 | - $success = wp_mail( |
|
434 | - $this->_to, |
|
435 | - // some old values for subject may be expecting HTML entities to be decoded in the subject |
|
436 | - // and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
437 | - wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
438 | - $this->_body(), |
|
439 | - $this->_headers() |
|
440 | - ); |
|
441 | - if (! $success) { |
|
442 | - EE_Error::add_error( |
|
443 | - sprintf( |
|
444 | - esc_html__( |
|
445 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
446 | - 'event_espresso' |
|
447 | - ), |
|
448 | - $this->_to, |
|
449 | - $this->_from, |
|
450 | - '<br />' |
|
451 | - ), |
|
452 | - __FILE__, |
|
453 | - __FUNCTION__, |
|
454 | - __LINE__ |
|
455 | - ); |
|
456 | - } |
|
457 | - return $success; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * see parent for definition |
|
463 | - * |
|
464 | - * @return string html body of the message content and the related css. |
|
465 | - * @throws EE_Error |
|
466 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
467 | - */ |
|
468 | - protected function _preview() |
|
469 | - { |
|
470 | - return $this->_body(true); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Setup headers for email |
|
476 | - * |
|
477 | - * @access protected |
|
478 | - * @return string formatted header for email |
|
479 | - */ |
|
480 | - protected function _headers() |
|
481 | - { |
|
482 | - $this->_ensure_has_from_email_address(); |
|
483 | - $from = $this->_from; |
|
484 | - $headers = array( |
|
485 | - 'From:' . $from, |
|
486 | - 'Reply-To:' . $from, |
|
487 | - 'Content-Type:text/html; charset=utf-8', |
|
488 | - ); |
|
489 | - |
|
490 | - /** |
|
491 | - * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to |
|
492 | - * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
|
493 | - * type which they are no longer able to change. |
|
494 | - */ |
|
495 | - if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
496 | - $headers[] = 'cc: ' . $this->_cc; |
|
497 | - } |
|
498 | - |
|
499 | - // but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
500 | - // header. |
|
501 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
502 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
503 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
509 | - * address for the from address to avoid problems with sending emails. |
|
510 | - */ |
|
511 | - protected function _ensure_has_from_email_address() |
|
512 | - { |
|
513 | - if (empty($this->_from)) { |
|
514 | - $this->_from = get_bloginfo('admin_email'); |
|
515 | - } |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
521 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
522 | - * be empty |
|
523 | - * |
|
524 | - * @since 4.3.1 |
|
525 | - * @return array |
|
526 | - */ |
|
527 | - private function _parse_from() |
|
528 | - { |
|
529 | - if (strpos($this->_from, '<') !== false) { |
|
530 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
531 | - $from_name = str_replace('"', '', $from_name); |
|
532 | - $from_name = trim($from_name); |
|
533 | - |
|
534 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
535 | - $from_email = str_replace('>', '', $from_email); |
|
536 | - $from_email = trim($from_email); |
|
537 | - } elseif (trim($this->_from) !== '') { |
|
538 | - $from_name = ''; |
|
539 | - $from_email = trim($this->_from); |
|
540 | - } else { |
|
541 | - $from_name = $from_email = ''; |
|
542 | - } |
|
543 | - return array($from_name, $from_email); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * Callback for the wp_mail_from filter. |
|
549 | - * |
|
550 | - * @since 4.3.1 |
|
551 | - * @param string $from_email What the original from_email is. |
|
552 | - * @return string |
|
553 | - */ |
|
554 | - public function set_from_address($from_email) |
|
555 | - { |
|
556 | - $parsed_from = $this->_parse_from(); |
|
557 | - // includes fallback if the parsing failed. |
|
558 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
559 | - ? $parsed_from[1] |
|
560 | - : get_bloginfo('admin_email'); |
|
561 | - return $from_email; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * Callback fro the wp_mail_from_name filter. |
|
567 | - * |
|
568 | - * @since 4.3.1 |
|
569 | - * @param string $from_name The original from_name. |
|
570 | - * @return string |
|
571 | - */ |
|
572 | - public function set_from_name($from_name) |
|
573 | - { |
|
574 | - $parsed_from = $this->_parse_from(); |
|
575 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
576 | - $from_name = $parsed_from[0]; |
|
577 | - } |
|
578 | - |
|
579 | - // if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
580 | - // but realize the default name is HTML entity-encoded |
|
581 | - $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
582 | - |
|
583 | - return $from_name; |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * setup body for email |
|
589 | - * |
|
590 | - * @param bool $preview will determine whether this is preview template or not. |
|
591 | - * @return string formatted body for email. |
|
592 | - * @throws EE_Error |
|
593 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
594 | - */ |
|
595 | - protected function _body($preview = false) |
|
596 | - { |
|
597 | - // setup template args! |
|
598 | - $this->_template_args = array( |
|
599 | - 'subject' => $this->_subject, |
|
600 | - 'from' => $this->_from, |
|
601 | - 'main_body' => wpautop($this->_content), |
|
602 | - ); |
|
603 | - $body = $this->_get_main_template($preview); |
|
604 | - |
|
605 | - /** |
|
606 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
607 | - * |
|
608 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
609 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
610 | - */ |
|
611 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
612 | - // require CssToInlineStyles library and its dependencies via composer autoloader |
|
613 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
614 | - |
|
615 | - // now if this isn't a preview, let's setup the body so it has inline styles |
|
616 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
617 | - $style = file_get_contents( |
|
618 | - $this->get_variation( |
|
619 | - $this->_tmp_pack, |
|
620 | - $this->_incoming_message_type->name, |
|
621 | - false, |
|
622 | - 'main', |
|
623 | - $this->_variation |
|
624 | - ), |
|
625 | - true |
|
626 | - ); |
|
627 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
628 | - // for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
629 | - $body = ltrim($CSS->convert(true), ">\n"); |
|
630 | - // see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
631 | - $body = ltrim($body, "<?"); |
|
632 | - } |
|
633 | - } |
|
634 | - return $body; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * This just returns any existing test settings that might be saved in the database |
|
640 | - * |
|
641 | - * @access public |
|
642 | - * @return array |
|
643 | - */ |
|
644 | - public function get_existing_test_settings() |
|
645 | - { |
|
646 | - $settings = parent::get_existing_test_settings(); |
|
647 | - // override subject if present because we always want it to be fresh. |
|
648 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
649 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
650 | - } |
|
651 | - return $settings; |
|
652 | - } |
|
9 | + /** |
|
10 | + * To field for email |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + protected $_to = ''; |
|
14 | + |
|
15 | + |
|
16 | + /** |
|
17 | + * CC field for email. |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $_cc = ''; |
|
21 | + |
|
22 | + /** |
|
23 | + * From field for email |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $_from = ''; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Subject field for email |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $_subject = ''; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * Content field for email |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $_content = ''; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * constructor |
|
45 | + * |
|
46 | + * @access public |
|
47 | + */ |
|
48 | + public function __construct() |
|
49 | + { |
|
50 | + // set name and description properties |
|
51 | + $this->name = 'email'; |
|
52 | + $this->description = sprintf( |
|
53 | + esc_html__( |
|
54 | + 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
55 | + 'event_espresso' |
|
56 | + ), |
|
57 | + '<code>wp_mail</code>' |
|
58 | + ); |
|
59 | + $this->label = array( |
|
60 | + 'singular' => esc_html__('email', 'event_espresso'), |
|
61 | + 'plural' => esc_html__('emails', 'event_espresso'), |
|
62 | + ); |
|
63 | + $this->activate_on_install = true; |
|
64 | + |
|
65 | + // we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
66 | + // properties |
|
67 | + parent::__construct(); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * see abstract declaration in parent class for details. |
|
73 | + */ |
|
74 | + protected function _set_admin_pages() |
|
75 | + { |
|
76 | + $this->admin_registered_pages = array( |
|
77 | + 'events_edit' => true, |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * see abstract declaration in parent class for details |
|
84 | + */ |
|
85 | + protected function _set_valid_shortcodes() |
|
86 | + { |
|
87 | + // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
88 | + // message type. |
|
89 | + $this->_valid_shortcodes = array( |
|
90 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
91 | + 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
92 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * see abstract declaration in parent class for details |
|
99 | + * |
|
100 | + * @access protected |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + protected function _set_validator_config() |
|
104 | + { |
|
105 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
106 | + |
|
107 | + $this->_validator_config = array( |
|
108 | + 'to' => array( |
|
109 | + 'shortcodes' => $valid_shortcodes['to'], |
|
110 | + 'type' => 'email', |
|
111 | + ), |
|
112 | + 'cc' => array( |
|
113 | + 'shortcodes' => $valid_shortcodes['to'], |
|
114 | + 'type' => 'email', |
|
115 | + ), |
|
116 | + 'from' => array( |
|
117 | + 'shortcodes' => $valid_shortcodes['from'], |
|
118 | + 'type' => 'email', |
|
119 | + ), |
|
120 | + 'subject' => array( |
|
121 | + 'shortcodes' => array( |
|
122 | + 'organization', |
|
123 | + 'primary_registration_details', |
|
124 | + 'event_author', |
|
125 | + 'primary_registration_details', |
|
126 | + 'recipient_details', |
|
127 | + ), |
|
128 | + ), |
|
129 | + 'content' => array( |
|
130 | + 'shortcodes' => array( |
|
131 | + 'event_list', |
|
132 | + 'attendee_list', |
|
133 | + 'ticket_list', |
|
134 | + 'organization', |
|
135 | + 'primary_registration_details', |
|
136 | + 'primary_registration_list', |
|
137 | + 'event_author', |
|
138 | + 'recipient_details', |
|
139 | + 'recipient_list', |
|
140 | + 'transaction', |
|
141 | + 'messenger', |
|
142 | + ), |
|
143 | + ), |
|
144 | + 'attendee_list' => array( |
|
145 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
146 | + 'required' => array('[ATTENDEE_LIST]'), |
|
147 | + ), |
|
148 | + 'event_list' => array( |
|
149 | + 'shortcodes' => array( |
|
150 | + 'event', |
|
151 | + 'attendee_list', |
|
152 | + 'ticket_list', |
|
153 | + 'venue', |
|
154 | + 'datetime_list', |
|
155 | + 'attendee', |
|
156 | + 'primary_registration_details', |
|
157 | + 'primary_registration_list', |
|
158 | + 'event_author', |
|
159 | + 'recipient_details', |
|
160 | + 'recipient_list', |
|
161 | + ), |
|
162 | + 'required' => array('[EVENT_LIST]'), |
|
163 | + ), |
|
164 | + 'ticket_list' => array( |
|
165 | + 'shortcodes' => array( |
|
166 | + 'event_list', |
|
167 | + 'attendee_list', |
|
168 | + 'ticket', |
|
169 | + 'datetime_list', |
|
170 | + 'primary_registration_details', |
|
171 | + 'recipient_details', |
|
172 | + ), |
|
173 | + 'required' => array('[TICKET_LIST]'), |
|
174 | + ), |
|
175 | + 'datetime_list' => array( |
|
176 | + 'shortcodes' => array('datetime'), |
|
177 | + 'required' => array('[DATETIME_LIST]'), |
|
178 | + ), |
|
179 | + ); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @see parent EE_messenger class for docs |
|
185 | + * @since 4.5.0 |
|
186 | + */ |
|
187 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
188 | + { |
|
189 | + if ($sending_messenger_name === 'html') { |
|
190 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + public function add_email_css( |
|
196 | + $variation_path, |
|
197 | + $messenger, |
|
198 | + $message_type, |
|
199 | + $type, |
|
200 | + $variation, |
|
201 | + $file_extension, |
|
202 | + $url, |
|
203 | + EE_Messages_Template_Pack $template_pack |
|
204 | + ) { |
|
205 | + // prevent recursion on this callback. |
|
206 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
207 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
208 | + |
|
209 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
210 | + return $variation; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * See parent for details |
|
216 | + * |
|
217 | + * @access protected |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + protected function _set_test_settings_fields() |
|
221 | + { |
|
222 | + $this->_test_settings_fields = array( |
|
223 | + 'to' => array( |
|
224 | + 'input' => 'text', |
|
225 | + 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
226 | + 'type' => 'email', |
|
227 | + 'required' => true, |
|
228 | + 'validation' => true, |
|
229 | + 'css_class' => 'large-text', |
|
230 | + 'format' => '%s', |
|
231 | + 'default' => get_bloginfo('admin_email'), |
|
232 | + ), |
|
233 | + 'subject' => array( |
|
234 | + 'input' => 'hidden', |
|
235 | + 'label' => '', |
|
236 | + 'type' => 'string', |
|
237 | + 'required' => false, |
|
238 | + 'validation' => false, |
|
239 | + 'format' => '%s', |
|
240 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
241 | + 'default' => '', |
|
242 | + 'css_class' => '', |
|
243 | + ), |
|
244 | + ); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * _set_template_fields |
|
250 | + * This sets up the fields that a messenger requires for the message to go out. |
|
251 | + * |
|
252 | + * @access protected |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + protected function _set_template_fields() |
|
256 | + { |
|
257 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
258 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
259 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
260 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
261 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
262 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
263 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
264 | + // will not be displayed/parsed. |
|
265 | + $this->_template_fields = array( |
|
266 | + 'to' => array( |
|
267 | + 'input' => 'text', |
|
268 | + 'label' => esc_html_x( |
|
269 | + 'To', |
|
270 | + 'Label for the "To" field for email addresses', |
|
271 | + 'event_espresso' |
|
272 | + ), |
|
273 | + 'type' => 'string', |
|
274 | + 'required' => true, |
|
275 | + 'validation' => true, |
|
276 | + 'css_class' => 'large-text', |
|
277 | + 'format' => '%s', |
|
278 | + ), |
|
279 | + 'cc' => array( |
|
280 | + 'input' => 'text', |
|
281 | + 'label' => esc_html_x( |
|
282 | + 'CC', |
|
283 | + 'Label for the "Carbon Copy" field used for additional email addresses', |
|
284 | + 'event_espresso' |
|
285 | + ), |
|
286 | + 'type' => 'string', |
|
287 | + 'required' => false, |
|
288 | + 'validation' => true, |
|
289 | + 'css_class' => 'large-text', |
|
290 | + 'format' => '%s', |
|
291 | + ), |
|
292 | + 'from' => array( |
|
293 | + 'input' => 'text', |
|
294 | + 'label' => esc_html_x( |
|
295 | + 'From', |
|
296 | + 'Label for the "From" field for email addresses.', |
|
297 | + 'event_espresso' |
|
298 | + ), |
|
299 | + 'type' => 'string', |
|
300 | + 'required' => true, |
|
301 | + 'validation' => true, |
|
302 | + 'css_class' => 'large-text', |
|
303 | + 'format' => '%s', |
|
304 | + ), |
|
305 | + 'subject' => array( |
|
306 | + 'input' => 'text', |
|
307 | + 'label' => esc_html_x( |
|
308 | + 'Subject', |
|
309 | + 'Label for the "Subject" field (short description of contents) for emails.', |
|
310 | + 'event_espresso' |
|
311 | + ), |
|
312 | + 'type' => 'string', |
|
313 | + 'required' => true, |
|
314 | + 'validation' => true, |
|
315 | + 'css_class' => 'large-text', |
|
316 | + 'format' => '%s', |
|
317 | + ), |
|
318 | + 'content' => '', |
|
319 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
320 | + 'extra' => array( |
|
321 | + 'content' => array( |
|
322 | + 'main' => array( |
|
323 | + 'input' => 'wp_editor', |
|
324 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
325 | + 'type' => 'string', |
|
326 | + 'required' => true, |
|
327 | + 'validation' => true, |
|
328 | + 'format' => '%s', |
|
329 | + 'rows' => '15', |
|
330 | + ), |
|
331 | + 'event_list' => array( |
|
332 | + 'input' => 'wp_editor', |
|
333 | + 'label' => '[EVENT_LIST]', |
|
334 | + 'type' => 'string', |
|
335 | + 'required' => true, |
|
336 | + 'validation' => true, |
|
337 | + 'format' => '%s', |
|
338 | + 'rows' => '15', |
|
339 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
340 | + ), |
|
341 | + 'attendee_list' => array( |
|
342 | + 'input' => 'textarea', |
|
343 | + 'label' => '[ATTENDEE_LIST]', |
|
344 | + 'type' => 'string', |
|
345 | + 'required' => true, |
|
346 | + 'validation' => true, |
|
347 | + 'format' => '%s', |
|
348 | + 'css_class' => 'large-text', |
|
349 | + 'rows' => '5', |
|
350 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
351 | + ), |
|
352 | + 'ticket_list' => array( |
|
353 | + 'input' => 'textarea', |
|
354 | + 'label' => '[TICKET_LIST]', |
|
355 | + 'type' => 'string', |
|
356 | + 'required' => true, |
|
357 | + 'validation' => true, |
|
358 | + 'format' => '%s', |
|
359 | + 'css_class' => 'large-text', |
|
360 | + 'rows' => '10', |
|
361 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
362 | + ), |
|
363 | + 'datetime_list' => array( |
|
364 | + 'input' => 'textarea', |
|
365 | + 'label' => '[DATETIME_LIST]', |
|
366 | + 'type' => 'string', |
|
367 | + 'required' => true, |
|
368 | + 'validation' => true, |
|
369 | + 'format' => '%s', |
|
370 | + 'css_class' => 'large-text', |
|
371 | + 'rows' => '10', |
|
372 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
373 | + ), |
|
374 | + ), |
|
375 | + ), |
|
376 | + ); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * See definition of this class in parent |
|
382 | + */ |
|
383 | + protected function _set_default_message_types() |
|
384 | + { |
|
385 | + $this->_default_message_types = array( |
|
386 | + 'payment', |
|
387 | + 'payment_refund', |
|
388 | + 'registration', |
|
389 | + 'not_approved_registration', |
|
390 | + 'pending_approval', |
|
391 | + ); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * @see definition of this class in parent |
|
397 | + * @since 4.5.0 |
|
398 | + */ |
|
399 | + protected function _set_valid_message_types() |
|
400 | + { |
|
401 | + $this->_valid_message_types = array( |
|
402 | + 'payment', |
|
403 | + 'registration', |
|
404 | + 'not_approved_registration', |
|
405 | + 'declined_registration', |
|
406 | + 'cancelled_registration', |
|
407 | + 'pending_approval', |
|
408 | + 'registration_summary', |
|
409 | + 'payment_reminder', |
|
410 | + 'payment_declined', |
|
411 | + 'payment_refund', |
|
412 | + ); |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * setting up admin_settings_fields for messenger. |
|
418 | + */ |
|
419 | + protected function _set_admin_settings_fields() |
|
420 | + { |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * We just deliver the messages don't kill us!! |
|
425 | + * |
|
426 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
427 | + * present. |
|
428 | + * @throws EE_Error |
|
429 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
430 | + */ |
|
431 | + protected function _send_message() |
|
432 | + { |
|
433 | + $success = wp_mail( |
|
434 | + $this->_to, |
|
435 | + // some old values for subject may be expecting HTML entities to be decoded in the subject |
|
436 | + // and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
437 | + wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
438 | + $this->_body(), |
|
439 | + $this->_headers() |
|
440 | + ); |
|
441 | + if (! $success) { |
|
442 | + EE_Error::add_error( |
|
443 | + sprintf( |
|
444 | + esc_html__( |
|
445 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
446 | + 'event_espresso' |
|
447 | + ), |
|
448 | + $this->_to, |
|
449 | + $this->_from, |
|
450 | + '<br />' |
|
451 | + ), |
|
452 | + __FILE__, |
|
453 | + __FUNCTION__, |
|
454 | + __LINE__ |
|
455 | + ); |
|
456 | + } |
|
457 | + return $success; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * see parent for definition |
|
463 | + * |
|
464 | + * @return string html body of the message content and the related css. |
|
465 | + * @throws EE_Error |
|
466 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
467 | + */ |
|
468 | + protected function _preview() |
|
469 | + { |
|
470 | + return $this->_body(true); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Setup headers for email |
|
476 | + * |
|
477 | + * @access protected |
|
478 | + * @return string formatted header for email |
|
479 | + */ |
|
480 | + protected function _headers() |
|
481 | + { |
|
482 | + $this->_ensure_has_from_email_address(); |
|
483 | + $from = $this->_from; |
|
484 | + $headers = array( |
|
485 | + 'From:' . $from, |
|
486 | + 'Reply-To:' . $from, |
|
487 | + 'Content-Type:text/html; charset=utf-8', |
|
488 | + ); |
|
489 | + |
|
490 | + /** |
|
491 | + * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to |
|
492 | + * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
|
493 | + * type which they are no longer able to change. |
|
494 | + */ |
|
495 | + if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
496 | + $headers[] = 'cc: ' . $this->_cc; |
|
497 | + } |
|
498 | + |
|
499 | + // but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
500 | + // header. |
|
501 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
502 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
503 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
509 | + * address for the from address to avoid problems with sending emails. |
|
510 | + */ |
|
511 | + protected function _ensure_has_from_email_address() |
|
512 | + { |
|
513 | + if (empty($this->_from)) { |
|
514 | + $this->_from = get_bloginfo('admin_email'); |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
521 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
522 | + * be empty |
|
523 | + * |
|
524 | + * @since 4.3.1 |
|
525 | + * @return array |
|
526 | + */ |
|
527 | + private function _parse_from() |
|
528 | + { |
|
529 | + if (strpos($this->_from, '<') !== false) { |
|
530 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
531 | + $from_name = str_replace('"', '', $from_name); |
|
532 | + $from_name = trim($from_name); |
|
533 | + |
|
534 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
535 | + $from_email = str_replace('>', '', $from_email); |
|
536 | + $from_email = trim($from_email); |
|
537 | + } elseif (trim($this->_from) !== '') { |
|
538 | + $from_name = ''; |
|
539 | + $from_email = trim($this->_from); |
|
540 | + } else { |
|
541 | + $from_name = $from_email = ''; |
|
542 | + } |
|
543 | + return array($from_name, $from_email); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * Callback for the wp_mail_from filter. |
|
549 | + * |
|
550 | + * @since 4.3.1 |
|
551 | + * @param string $from_email What the original from_email is. |
|
552 | + * @return string |
|
553 | + */ |
|
554 | + public function set_from_address($from_email) |
|
555 | + { |
|
556 | + $parsed_from = $this->_parse_from(); |
|
557 | + // includes fallback if the parsing failed. |
|
558 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
559 | + ? $parsed_from[1] |
|
560 | + : get_bloginfo('admin_email'); |
|
561 | + return $from_email; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * Callback fro the wp_mail_from_name filter. |
|
567 | + * |
|
568 | + * @since 4.3.1 |
|
569 | + * @param string $from_name The original from_name. |
|
570 | + * @return string |
|
571 | + */ |
|
572 | + public function set_from_name($from_name) |
|
573 | + { |
|
574 | + $parsed_from = $this->_parse_from(); |
|
575 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
576 | + $from_name = $parsed_from[0]; |
|
577 | + } |
|
578 | + |
|
579 | + // if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
580 | + // but realize the default name is HTML entity-encoded |
|
581 | + $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
582 | + |
|
583 | + return $from_name; |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * setup body for email |
|
589 | + * |
|
590 | + * @param bool $preview will determine whether this is preview template or not. |
|
591 | + * @return string formatted body for email. |
|
592 | + * @throws EE_Error |
|
593 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
594 | + */ |
|
595 | + protected function _body($preview = false) |
|
596 | + { |
|
597 | + // setup template args! |
|
598 | + $this->_template_args = array( |
|
599 | + 'subject' => $this->_subject, |
|
600 | + 'from' => $this->_from, |
|
601 | + 'main_body' => wpautop($this->_content), |
|
602 | + ); |
|
603 | + $body = $this->_get_main_template($preview); |
|
604 | + |
|
605 | + /** |
|
606 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
607 | + * |
|
608 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
609 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
610 | + */ |
|
611 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
612 | + // require CssToInlineStyles library and its dependencies via composer autoloader |
|
613 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
614 | + |
|
615 | + // now if this isn't a preview, let's setup the body so it has inline styles |
|
616 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
617 | + $style = file_get_contents( |
|
618 | + $this->get_variation( |
|
619 | + $this->_tmp_pack, |
|
620 | + $this->_incoming_message_type->name, |
|
621 | + false, |
|
622 | + 'main', |
|
623 | + $this->_variation |
|
624 | + ), |
|
625 | + true |
|
626 | + ); |
|
627 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
628 | + // for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
629 | + $body = ltrim($CSS->convert(true), ">\n"); |
|
630 | + // see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
631 | + $body = ltrim($body, "<?"); |
|
632 | + } |
|
633 | + } |
|
634 | + return $body; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * This just returns any existing test settings that might be saved in the database |
|
640 | + * |
|
641 | + * @access public |
|
642 | + * @return array |
|
643 | + */ |
|
644 | + public function get_existing_test_settings() |
|
645 | + { |
|
646 | + $settings = parent::get_existing_test_settings(); |
|
647 | + // override subject if present because we always want it to be fresh. |
|
648 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
649 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
650 | + } |
|
651 | + return $settings; |
|
652 | + } |
|
653 | 653 | } |
@@ -164,7 +164,7 @@ |
||
164 | 164 | |
165 | 165 | |
166 | 166 | /** |
167 | - * @param $ticket |
|
167 | + * @param \EE_Base_Class $ticket |
|
168 | 168 | * @throws DomainException |
169 | 169 | * @throws EE_Error |
170 | 170 | * @throws UnexpectedEntityException |
@@ -26,719 +26,719 @@ |
||
26 | 26 | class EventSpacesCalculator |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Event $event |
|
31 | - */ |
|
32 | - private $event; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array $datetime_query_params |
|
36 | - */ |
|
37 | - private $datetime_query_params; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_Ticket[] $active_tickets |
|
41 | - */ |
|
42 | - private $active_tickets = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EE_Datetime[] $datetimes |
|
46 | - */ |
|
47 | - private $datetimes = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * Array of Ticket IDs grouped by Datetime |
|
51 | - * |
|
52 | - * @var array $datetimes |
|
53 | - */ |
|
54 | - private $datetime_tickets = array(); |
|
55 | - |
|
56 | - /** |
|
57 | - * Max spaces for each Datetime (reg limit - previous sold) |
|
58 | - * |
|
59 | - * @var array $datetime_spaces |
|
60 | - */ |
|
61 | - private $datetime_spaces = array(); |
|
62 | - |
|
63 | - /** |
|
64 | - * Array of Datetime IDs grouped by Ticket |
|
65 | - * |
|
66 | - * @var array[] $ticket_datetimes |
|
67 | - */ |
|
68 | - private $ticket_datetimes = array(); |
|
69 | - |
|
70 | - /** |
|
71 | - * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
72 | - * |
|
73 | - * @var array $ticket_quantities |
|
74 | - */ |
|
75 | - private $ticket_quantities = array(); |
|
76 | - |
|
77 | - /** |
|
78 | - * total quantity of sold and reserved for each ticket |
|
79 | - * |
|
80 | - * @var array $tickets_sold |
|
81 | - */ |
|
82 | - private $tickets_sold = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * total spaces available across all datetimes |
|
86 | - * |
|
87 | - * @var array $total_spaces |
|
88 | - */ |
|
89 | - private $total_spaces = array(); |
|
90 | - |
|
91 | - /** |
|
92 | - * @var boolean $debug |
|
93 | - */ |
|
94 | - private $debug = false; // true false |
|
95 | - |
|
96 | - /** |
|
97 | - * @var null|int $spaces_remaining |
|
98 | - */ |
|
99 | - private $spaces_remaining; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var null|int $total_spaces_available |
|
103 | - */ |
|
104 | - private $total_spaces_available; |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * EventSpacesCalculator constructor. |
|
109 | - * |
|
110 | - * @param EE_Event $event |
|
111 | - * @param array $datetime_query_params |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
115 | - { |
|
116 | - if ($this->debug) { |
|
117 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1); |
|
118 | - \EEH_Debug_Tools::printr((string) $event->ID(), 'For event', __FILE__, __LINE__); |
|
119 | - } |
|
120 | - $this->event = $event; |
|
121 | - $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
122 | - $this->setHooks(); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - private function setHooks() |
|
130 | - { |
|
131 | - add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
132 | - add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
133 | - add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
134 | - add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
135 | - add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
136 | - add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
137 | - add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
138 | - add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public function clearResults() |
|
146 | - { |
|
147 | - if ($this->debug) { |
|
148 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1); |
|
149 | - } |
|
150 | - $this->spaces_remaining = null; |
|
151 | - $this->total_spaces_available = null; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return EE_Ticket[] |
|
157 | - * @throws EE_Error |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws InvalidInterfaceException |
|
160 | - * @throws InvalidArgumentException |
|
161 | - */ |
|
162 | - public function getActiveTickets() |
|
163 | - { |
|
164 | - if (empty($this->active_tickets)) { |
|
165 | - $this->active_tickets = $this->event->tickets( |
|
166 | - array( |
|
167 | - array('TKT_deleted' => false), |
|
168 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - return $this->active_tickets; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param EE_Ticket[] $active_tickets |
|
178 | - * @throws EE_Error |
|
179 | - * @throws DomainException |
|
180 | - * @throws UnexpectedEntityException |
|
181 | - */ |
|
182 | - public function setActiveTickets(array $active_tickets = array()) |
|
183 | - { |
|
184 | - if (! empty($active_tickets)) { |
|
185 | - foreach ($active_tickets as $active_ticket) { |
|
186 | - $this->validateTicket($active_ticket); |
|
187 | - } |
|
188 | - // sort incoming array by ticket quantity (asc) |
|
189 | - usort( |
|
190 | - $active_tickets, |
|
191 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
192 | - if ($a->qty() === $b->qty()) { |
|
193 | - return 0; |
|
194 | - } |
|
195 | - return ($a->qty() < $b->qty()) |
|
196 | - ? -1 |
|
197 | - : 1; |
|
198 | - } |
|
199 | - ); |
|
200 | - } |
|
201 | - $this->active_tickets = $active_tickets; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @param $ticket |
|
207 | - * @throws DomainException |
|
208 | - * @throws EE_Error |
|
209 | - * @throws UnexpectedEntityException |
|
210 | - */ |
|
211 | - private function validateTicket($ticket) |
|
212 | - { |
|
213 | - if (! $ticket instanceof EE_Ticket) { |
|
214 | - throw new DomainException( |
|
215 | - esc_html__( |
|
216 | - 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
217 | - 'event_espresso' |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
221 | - if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
222 | - throw new DomainException( |
|
223 | - sprintf( |
|
224 | - esc_html__( |
|
225 | - 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
226 | - 'event_espresso' |
|
227 | - ), |
|
228 | - $ticket->get_event_ID(), |
|
229 | - $this->event->ID() |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @return EE_Datetime[] |
|
238 | - */ |
|
239 | - public function getDatetimes() |
|
240 | - { |
|
241 | - return $this->datetimes; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @param EE_Datetime $datetime |
|
247 | - * @throws EE_Error |
|
248 | - * @throws DomainException |
|
249 | - */ |
|
250 | - public function setDatetime(EE_Datetime $datetime) |
|
251 | - { |
|
252 | - if ($datetime->event()->ID() !== $this->event->ID()) { |
|
253 | - throw new DomainException( |
|
254 | - sprintf( |
|
255 | - esc_html__( |
|
256 | - 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
257 | - 'event_espresso' |
|
258 | - ), |
|
259 | - $datetime->event()->ID(), |
|
260 | - $this->event->ID() |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * calculate spaces remaining based on "saleable" tickets |
|
270 | - * |
|
271 | - * @return float|int |
|
272 | - * @throws EE_Error |
|
273 | - * @throws DomainException |
|
274 | - * @throws UnexpectedEntityException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - * @throws InvalidArgumentException |
|
278 | - */ |
|
279 | - public function spacesRemaining() |
|
280 | - { |
|
281 | - if ($this->debug) { |
|
282 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
283 | - } |
|
284 | - if ($this->spaces_remaining === null) { |
|
285 | - $this->initialize(); |
|
286 | - $this->spaces_remaining = $this->calculate(); |
|
287 | - } |
|
288 | - return $this->spaces_remaining; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * calculates total available spaces for an event with no regard for sold tickets |
|
294 | - * |
|
295 | - * @return int|float |
|
296 | - * @throws EE_Error |
|
297 | - * @throws DomainException |
|
298 | - * @throws UnexpectedEntityException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - * @throws InvalidArgumentException |
|
302 | - */ |
|
303 | - public function totalSpacesAvailable() |
|
304 | - { |
|
305 | - if ($this->debug) { |
|
306 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
307 | - } |
|
308 | - if ($this->total_spaces_available === null) { |
|
309 | - $this->initialize(); |
|
310 | - $this->total_spaces_available = $this->calculate(false); |
|
311 | - } |
|
312 | - return $this->total_spaces_available; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Loops through the active tickets for the event |
|
318 | - * and builds a series of data arrays that will be used for calculating |
|
319 | - * the total maximum available spaces, as well as the spaces remaining. |
|
320 | - * Because ticket quantities affect datetime spaces and vice versa, |
|
321 | - * we need to be constantly updating these data arrays as things change, |
|
322 | - * which is the entire reason for their existence. |
|
323 | - * |
|
324 | - * @throws EE_Error |
|
325 | - * @throws DomainException |
|
326 | - * @throws UnexpectedEntityException |
|
327 | - * @throws InvalidDataTypeException |
|
328 | - * @throws InvalidInterfaceException |
|
329 | - * @throws InvalidArgumentException |
|
330 | - */ |
|
331 | - private function initialize() |
|
332 | - { |
|
333 | - if ($this->debug) { |
|
334 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
335 | - } |
|
336 | - $this->datetime_tickets = array(); |
|
337 | - $this->datetime_spaces = array(); |
|
338 | - $this->ticket_datetimes = array(); |
|
339 | - $this->ticket_quantities = array(); |
|
340 | - $this->tickets_sold = array(); |
|
341 | - $this->total_spaces = array(); |
|
342 | - $active_tickets = $this->getActiveTickets(); |
|
343 | - if (! empty($active_tickets)) { |
|
344 | - foreach ($active_tickets as $ticket) { |
|
345 | - $this->validateTicket($ticket); |
|
346 | - // we need to index our data arrays using strings for the purpose of sorting, |
|
347 | - // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
348 | - $ticket_identifier = "T{$ticket->ID()}"; |
|
349 | - // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
350 | - // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
351 | - $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
352 | - // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
353 | - $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
354 | - foreach ($ticket_datetimes as $datetime) { |
|
355 | - // save all datetimes |
|
356 | - $this->setDatetime($datetime); |
|
357 | - $datetime_identifier = "D{$datetime->ID()}"; |
|
358 | - $reg_limit = $datetime->reg_limit(); |
|
359 | - // ticket quantity can not exceed datetime reg limit |
|
360 | - $max_tickets = min($max_tickets, $reg_limit); |
|
361 | - // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
362 | - // we are going to move all of our data into the following arrays: |
|
363 | - // datetime spaces initially represents the reg limit for each datetime, |
|
364 | - // but this will get adjusted as tickets are accounted for |
|
365 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
366 | - // just an array of ticket IDs grouped by datetime |
|
367 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
368 | - // and an array of datetime IDs grouped by ticket |
|
369 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
370 | - } |
|
371 | - // total quantity of sold and reserved for each ticket |
|
372 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
373 | - // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
374 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
375 | - } |
|
376 | - } |
|
377 | - // sort datetime spaces by reg limit, but maintain our string indexes |
|
378 | - asort($this->datetime_spaces, SORT_NUMERIC); |
|
379 | - // datetime tickets need to be sorted in the SAME order as the above array... |
|
380 | - // so we'll just use array_merge() to take the structure of datetime_spaces |
|
381 | - // but overwrite all of the data with that from datetime_tickets |
|
382 | - $this->datetime_tickets = array_merge( |
|
383 | - $this->datetime_spaces, |
|
384 | - $this->datetime_tickets |
|
385 | - ); |
|
386 | - if ($this->debug) { |
|
387 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
388 | - \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
389 | - \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * performs calculations on initialized data |
|
396 | - * |
|
397 | - * @param bool $consider_sold |
|
398 | - * @return int|float |
|
399 | - */ |
|
400 | - private function calculate($consider_sold = true) |
|
401 | - { |
|
402 | - if ($this->debug) { |
|
403 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
404 | - \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
405 | - } |
|
406 | - if ($consider_sold) { |
|
407 | - // subtract amounts sold from all ticket quantities and datetime spaces |
|
408 | - $this->adjustTicketQuantitiesDueToSales(); |
|
409 | - } |
|
410 | - foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
411 | - $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
412 | - } |
|
413 | - // total spaces available is just the sum of the spaces available for each datetime |
|
414 | - $spaces_remaining = array_sum($this->total_spaces); |
|
415 | - if ($this->debug) { |
|
416 | - \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
417 | - \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
418 | - \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
419 | - } |
|
420 | - return $spaces_remaining; |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
426 | - */ |
|
427 | - private function adjustTicketQuantitiesDueToSales() |
|
428 | - { |
|
429 | - if ($this->debug) { |
|
430 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
431 | - } |
|
432 | - foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
433 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
434 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
435 | - // don't let values go below zero |
|
436 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
437 | - $this->ticket_quantities[ $ticket_identifier ], |
|
438 | - 0 |
|
439 | - ); |
|
440 | - if ($this->debug) { |
|
441 | - \EEH_Debug_Tools::printr( |
|
442 | - "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
443 | - 'subtracting', |
|
444 | - __FILE__, |
|
445 | - __LINE__ |
|
446 | - ); |
|
447 | - } |
|
448 | - } |
|
449 | - if ( |
|
450 | - isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
451 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
452 | - ) { |
|
453 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
454 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
455 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
456 | - // don't let values go below zero |
|
457 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
458 | - $this->datetime_spaces[ $ticket_datetime ], |
|
459 | - 0 |
|
460 | - ); |
|
461 | - if ($this->debug) { |
|
462 | - \EEH_Debug_Tools::printr( |
|
463 | - "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
464 | - 'subtracting', |
|
465 | - __FILE__, |
|
466 | - __LINE__ |
|
467 | - ); |
|
468 | - } |
|
469 | - } |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * @param string $datetime_identifier |
|
478 | - * @param array $tickets |
|
479 | - */ |
|
480 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
481 | - { |
|
482 | - // make sure a reg limit is set for the datetime |
|
483 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
484 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
485 | - : 0; |
|
486 | - // and bail if it is not |
|
487 | - if (! $reg_limit) { |
|
488 | - if ($this->debug) { |
|
489 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
490 | - } |
|
491 | - return; |
|
492 | - } |
|
493 | - if ($this->debug) { |
|
494 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
495 | - \EEH_Debug_Tools::printr( |
|
496 | - "{$reg_limit}", |
|
497 | - 'REG LIMIT', |
|
498 | - __FILE__, |
|
499 | - __LINE__ |
|
500 | - ); |
|
501 | - } |
|
502 | - // number of allocated spaces always starts at zero |
|
503 | - $spaces_allocated = 0; |
|
504 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
505 | - foreach ($tickets as $ticket_identifier) { |
|
506 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
507 | - $datetime_identifier, |
|
508 | - $reg_limit, |
|
509 | - $ticket_identifier, |
|
510 | - $spaces_allocated |
|
511 | - ); |
|
512 | - } |
|
513 | - // spaces can't be negative |
|
514 | - $spaces_allocated = max($spaces_allocated, 0); |
|
515 | - if ($spaces_allocated) { |
|
516 | - // track any non-zero values |
|
517 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
518 | - if ($this->debug) { |
|
519 | - \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
520 | - } |
|
521 | - } else { |
|
522 | - if ($this->debug) { |
|
523 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
524 | - } |
|
525 | - } |
|
526 | - if ($this->debug) { |
|
527 | - \EEH_Debug_Tools::printr( |
|
528 | - $this->total_spaces[ $datetime_identifier ], |
|
529 | - '$total_spaces', |
|
530 | - __FILE__, |
|
531 | - __LINE__ |
|
532 | - ); |
|
533 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
534 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * @param string $datetime_identifier |
|
541 | - * @param int $reg_limit |
|
542 | - * @param string $ticket_identifier |
|
543 | - * @param int $spaces_allocated |
|
544 | - * @return int |
|
545 | - */ |
|
546 | - private function calculateAvailableSpacesForTicket( |
|
547 | - $datetime_identifier, |
|
548 | - $reg_limit, |
|
549 | - $ticket_identifier, |
|
550 | - $spaces_allocated |
|
551 | - ) { |
|
552 | - // make sure ticket quantity is set |
|
553 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
554 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
555 | - : 0; |
|
556 | - if ($this->debug) { |
|
557 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
558 | - \EEH_Debug_Tools::printr( |
|
559 | - "{$ticket_quantity}", |
|
560 | - "ticket $ticket_identifier quantity: ", |
|
561 | - __FILE__, |
|
562 | - __LINE__, |
|
563 | - 2 |
|
564 | - ); |
|
565 | - } |
|
566 | - if ($ticket_quantity) { |
|
567 | - if ($this->debug) { |
|
568 | - \EEH_Debug_Tools::printr( |
|
569 | - ($spaces_allocated <= $reg_limit) |
|
570 | - ? 'true' |
|
571 | - : 'false', |
|
572 | - ' . spaces_allocated <= reg_limit = ', |
|
573 | - __FILE__, |
|
574 | - __LINE__ |
|
575 | - ); |
|
576 | - } |
|
577 | - // if the datetime is NOT at full capacity yet |
|
578 | - if ($spaces_allocated <= $reg_limit) { |
|
579 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
580 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
581 | - // or the maximum ticket quantity |
|
582 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
583 | - // adjust the available quantity in our tracking array |
|
584 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
585 | - // and increment spaces allocated for this datetime |
|
586 | - $spaces_allocated += $ticket_quantity; |
|
587 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
588 | - if ($this->debug) { |
|
589 | - \EEH_Debug_Tools::printr( |
|
590 | - "{$ticket_quantity} {$ticket_identifier} tickets", |
|
591 | - ' > > allocate ', |
|
592 | - __FILE__, |
|
593 | - __LINE__, |
|
594 | - 3 |
|
595 | - ); |
|
596 | - if ($at_capacity) { |
|
597 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
598 | - } |
|
599 | - } |
|
600 | - // now adjust all other datetimes that allow access to this ticket |
|
601 | - $this->adjustDatetimes( |
|
602 | - $datetime_identifier, |
|
603 | - $ticket_identifier, |
|
604 | - $ticket_quantity, |
|
605 | - $at_capacity |
|
606 | - ); |
|
607 | - } |
|
608 | - } |
|
609 | - return $spaces_allocated; |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * subtracts ticket amounts from all datetime reg limits |
|
615 | - * that allow access to the ticket specified, |
|
616 | - * because that ticket could be used |
|
617 | - * to attend any of the datetimes it has access to |
|
618 | - * |
|
619 | - * @param string $datetime_identifier |
|
620 | - * @param string $ticket_identifier |
|
621 | - * @param bool $at_capacity |
|
622 | - * @param int $ticket_quantity |
|
623 | - */ |
|
624 | - private function adjustDatetimes( |
|
625 | - $datetime_identifier, |
|
626 | - $ticket_identifier, |
|
627 | - $ticket_quantity, |
|
628 | - $at_capacity |
|
629 | - ) { |
|
630 | - /** @var array $datetime_tickets */ |
|
631 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
632 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
633 | - continue; |
|
634 | - } |
|
635 | - $adjusted = $this->adjustDatetimeSpaces( |
|
636 | - $datetime_ID, |
|
637 | - $ticket_identifier, |
|
638 | - $ticket_quantity |
|
639 | - ); |
|
640 | - // skip to next ticket if nothing changed |
|
641 | - if (! ($adjusted || $at_capacity)) { |
|
642 | - continue; |
|
643 | - } |
|
644 | - // then all of it's tickets are now unavailable |
|
645 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
646 | - if ( |
|
647 | - ($ticket_identifier === $datetime_ticket || $at_capacity) |
|
648 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
649 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
650 | - ) { |
|
651 | - if ($this->debug) { |
|
652 | - \EEH_Debug_Tools::printr( |
|
653 | - $datetime_ticket, |
|
654 | - ' . . . adjust ticket quantities for', |
|
655 | - __FILE__, |
|
656 | - __LINE__ |
|
657 | - ); |
|
658 | - } |
|
659 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
660 | - // otherwise just subtract the ticket quantity |
|
661 | - $new_quantity = $at_capacity |
|
662 | - ? 0 |
|
663 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
664 | - // don't let ticket quantity go below zero |
|
665 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
666 | - if ($this->debug) { |
|
667 | - \EEH_Debug_Tools::printr( |
|
668 | - $at_capacity |
|
669 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
670 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
671 | - " . . . . {$datetime_ticket} quantity set to ", |
|
672 | - __FILE__, |
|
673 | - __LINE__ |
|
674 | - ); |
|
675 | - } |
|
676 | - } |
|
677 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
678 | - if ($datetime_ticket === $ticket_identifier) { |
|
679 | - if ( |
|
680 | - isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
681 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
682 | - ) { |
|
683 | - if ($this->debug) { |
|
684 | - \EEH_Debug_Tools::printr( |
|
685 | - $datetime_ticket, |
|
686 | - ' . . adjust other Datetimes for', |
|
687 | - __FILE__, |
|
688 | - __LINE__ |
|
689 | - ); |
|
690 | - } |
|
691 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
692 | - // don't adjust the current datetime twice |
|
693 | - if ($datetime !== $datetime_identifier) { |
|
694 | - $this->adjustDatetimeSpaces( |
|
695 | - $datetime, |
|
696 | - $datetime_ticket, |
|
697 | - $ticket_quantity |
|
698 | - ); |
|
699 | - } |
|
700 | - } |
|
701 | - } |
|
702 | - } |
|
703 | - } |
|
704 | - } |
|
705 | - } |
|
706 | - |
|
707 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
708 | - { |
|
709 | - // does datetime have spaces available? |
|
710 | - // and does the supplied ticket have access to this datetime ? |
|
711 | - if ( |
|
712 | - $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
713 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
714 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
715 | - ) { |
|
716 | - if ($this->debug) { |
|
717 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
718 | - \EEH_Debug_Tools::printr( |
|
719 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
720 | - " . . current {$datetime_identifier} spaces available", |
|
721 | - __FILE__, |
|
722 | - __LINE__ |
|
723 | - ); |
|
724 | - } |
|
725 | - // then decrement the available spaces for the datetime |
|
726 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
727 | - // but don't let quantities go below zero |
|
728 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
729 | - $this->datetime_spaces[ $datetime_identifier ], |
|
730 | - 0 |
|
731 | - ); |
|
732 | - if ($this->debug) { |
|
733 | - \EEH_Debug_Tools::printr( |
|
734 | - "{$ticket_quantity}", |
|
735 | - " . . . {$datetime_identifier} capacity reduced by", |
|
736 | - __FILE__, |
|
737 | - __LINE__ |
|
738 | - ); |
|
739 | - } |
|
740 | - return true; |
|
741 | - } |
|
742 | - return false; |
|
743 | - } |
|
29 | + /** |
|
30 | + * @var EE_Event $event |
|
31 | + */ |
|
32 | + private $event; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array $datetime_query_params |
|
36 | + */ |
|
37 | + private $datetime_query_params; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_Ticket[] $active_tickets |
|
41 | + */ |
|
42 | + private $active_tickets = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EE_Datetime[] $datetimes |
|
46 | + */ |
|
47 | + private $datetimes = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * Array of Ticket IDs grouped by Datetime |
|
51 | + * |
|
52 | + * @var array $datetimes |
|
53 | + */ |
|
54 | + private $datetime_tickets = array(); |
|
55 | + |
|
56 | + /** |
|
57 | + * Max spaces for each Datetime (reg limit - previous sold) |
|
58 | + * |
|
59 | + * @var array $datetime_spaces |
|
60 | + */ |
|
61 | + private $datetime_spaces = array(); |
|
62 | + |
|
63 | + /** |
|
64 | + * Array of Datetime IDs grouped by Ticket |
|
65 | + * |
|
66 | + * @var array[] $ticket_datetimes |
|
67 | + */ |
|
68 | + private $ticket_datetimes = array(); |
|
69 | + |
|
70 | + /** |
|
71 | + * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
72 | + * |
|
73 | + * @var array $ticket_quantities |
|
74 | + */ |
|
75 | + private $ticket_quantities = array(); |
|
76 | + |
|
77 | + /** |
|
78 | + * total quantity of sold and reserved for each ticket |
|
79 | + * |
|
80 | + * @var array $tickets_sold |
|
81 | + */ |
|
82 | + private $tickets_sold = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * total spaces available across all datetimes |
|
86 | + * |
|
87 | + * @var array $total_spaces |
|
88 | + */ |
|
89 | + private $total_spaces = array(); |
|
90 | + |
|
91 | + /** |
|
92 | + * @var boolean $debug |
|
93 | + */ |
|
94 | + private $debug = false; // true false |
|
95 | + |
|
96 | + /** |
|
97 | + * @var null|int $spaces_remaining |
|
98 | + */ |
|
99 | + private $spaces_remaining; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var null|int $total_spaces_available |
|
103 | + */ |
|
104 | + private $total_spaces_available; |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * EventSpacesCalculator constructor. |
|
109 | + * |
|
110 | + * @param EE_Event $event |
|
111 | + * @param array $datetime_query_params |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
115 | + { |
|
116 | + if ($this->debug) { |
|
117 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1); |
|
118 | + \EEH_Debug_Tools::printr((string) $event->ID(), 'For event', __FILE__, __LINE__); |
|
119 | + } |
|
120 | + $this->event = $event; |
|
121 | + $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
122 | + $this->setHooks(); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + private function setHooks() |
|
130 | + { |
|
131 | + add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
132 | + add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
133 | + add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
134 | + add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
135 | + add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
136 | + add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
137 | + add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
138 | + add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public function clearResults() |
|
146 | + { |
|
147 | + if ($this->debug) { |
|
148 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1); |
|
149 | + } |
|
150 | + $this->spaces_remaining = null; |
|
151 | + $this->total_spaces_available = null; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return EE_Ticket[] |
|
157 | + * @throws EE_Error |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws InvalidInterfaceException |
|
160 | + * @throws InvalidArgumentException |
|
161 | + */ |
|
162 | + public function getActiveTickets() |
|
163 | + { |
|
164 | + if (empty($this->active_tickets)) { |
|
165 | + $this->active_tickets = $this->event->tickets( |
|
166 | + array( |
|
167 | + array('TKT_deleted' => false), |
|
168 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + return $this->active_tickets; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param EE_Ticket[] $active_tickets |
|
178 | + * @throws EE_Error |
|
179 | + * @throws DomainException |
|
180 | + * @throws UnexpectedEntityException |
|
181 | + */ |
|
182 | + public function setActiveTickets(array $active_tickets = array()) |
|
183 | + { |
|
184 | + if (! empty($active_tickets)) { |
|
185 | + foreach ($active_tickets as $active_ticket) { |
|
186 | + $this->validateTicket($active_ticket); |
|
187 | + } |
|
188 | + // sort incoming array by ticket quantity (asc) |
|
189 | + usort( |
|
190 | + $active_tickets, |
|
191 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
192 | + if ($a->qty() === $b->qty()) { |
|
193 | + return 0; |
|
194 | + } |
|
195 | + return ($a->qty() < $b->qty()) |
|
196 | + ? -1 |
|
197 | + : 1; |
|
198 | + } |
|
199 | + ); |
|
200 | + } |
|
201 | + $this->active_tickets = $active_tickets; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @param $ticket |
|
207 | + * @throws DomainException |
|
208 | + * @throws EE_Error |
|
209 | + * @throws UnexpectedEntityException |
|
210 | + */ |
|
211 | + private function validateTicket($ticket) |
|
212 | + { |
|
213 | + if (! $ticket instanceof EE_Ticket) { |
|
214 | + throw new DomainException( |
|
215 | + esc_html__( |
|
216 | + 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
217 | + 'event_espresso' |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | + if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
222 | + throw new DomainException( |
|
223 | + sprintf( |
|
224 | + esc_html__( |
|
225 | + 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
226 | + 'event_espresso' |
|
227 | + ), |
|
228 | + $ticket->get_event_ID(), |
|
229 | + $this->event->ID() |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @return EE_Datetime[] |
|
238 | + */ |
|
239 | + public function getDatetimes() |
|
240 | + { |
|
241 | + return $this->datetimes; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @param EE_Datetime $datetime |
|
247 | + * @throws EE_Error |
|
248 | + * @throws DomainException |
|
249 | + */ |
|
250 | + public function setDatetime(EE_Datetime $datetime) |
|
251 | + { |
|
252 | + if ($datetime->event()->ID() !== $this->event->ID()) { |
|
253 | + throw new DomainException( |
|
254 | + sprintf( |
|
255 | + esc_html__( |
|
256 | + 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
257 | + 'event_espresso' |
|
258 | + ), |
|
259 | + $datetime->event()->ID(), |
|
260 | + $this->event->ID() |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + $this->datetimes[ $datetime->ID() ] = $datetime; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * calculate spaces remaining based on "saleable" tickets |
|
270 | + * |
|
271 | + * @return float|int |
|
272 | + * @throws EE_Error |
|
273 | + * @throws DomainException |
|
274 | + * @throws UnexpectedEntityException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + * @throws InvalidArgumentException |
|
278 | + */ |
|
279 | + public function spacesRemaining() |
|
280 | + { |
|
281 | + if ($this->debug) { |
|
282 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
283 | + } |
|
284 | + if ($this->spaces_remaining === null) { |
|
285 | + $this->initialize(); |
|
286 | + $this->spaces_remaining = $this->calculate(); |
|
287 | + } |
|
288 | + return $this->spaces_remaining; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * calculates total available spaces for an event with no regard for sold tickets |
|
294 | + * |
|
295 | + * @return int|float |
|
296 | + * @throws EE_Error |
|
297 | + * @throws DomainException |
|
298 | + * @throws UnexpectedEntityException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + * @throws InvalidArgumentException |
|
302 | + */ |
|
303 | + public function totalSpacesAvailable() |
|
304 | + { |
|
305 | + if ($this->debug) { |
|
306 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
307 | + } |
|
308 | + if ($this->total_spaces_available === null) { |
|
309 | + $this->initialize(); |
|
310 | + $this->total_spaces_available = $this->calculate(false); |
|
311 | + } |
|
312 | + return $this->total_spaces_available; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Loops through the active tickets for the event |
|
318 | + * and builds a series of data arrays that will be used for calculating |
|
319 | + * the total maximum available spaces, as well as the spaces remaining. |
|
320 | + * Because ticket quantities affect datetime spaces and vice versa, |
|
321 | + * we need to be constantly updating these data arrays as things change, |
|
322 | + * which is the entire reason for their existence. |
|
323 | + * |
|
324 | + * @throws EE_Error |
|
325 | + * @throws DomainException |
|
326 | + * @throws UnexpectedEntityException |
|
327 | + * @throws InvalidDataTypeException |
|
328 | + * @throws InvalidInterfaceException |
|
329 | + * @throws InvalidArgumentException |
|
330 | + */ |
|
331 | + private function initialize() |
|
332 | + { |
|
333 | + if ($this->debug) { |
|
334 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
335 | + } |
|
336 | + $this->datetime_tickets = array(); |
|
337 | + $this->datetime_spaces = array(); |
|
338 | + $this->ticket_datetimes = array(); |
|
339 | + $this->ticket_quantities = array(); |
|
340 | + $this->tickets_sold = array(); |
|
341 | + $this->total_spaces = array(); |
|
342 | + $active_tickets = $this->getActiveTickets(); |
|
343 | + if (! empty($active_tickets)) { |
|
344 | + foreach ($active_tickets as $ticket) { |
|
345 | + $this->validateTicket($ticket); |
|
346 | + // we need to index our data arrays using strings for the purpose of sorting, |
|
347 | + // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
348 | + $ticket_identifier = "T{$ticket->ID()}"; |
|
349 | + // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
350 | + // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
351 | + $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
352 | + // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
353 | + $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
354 | + foreach ($ticket_datetimes as $datetime) { |
|
355 | + // save all datetimes |
|
356 | + $this->setDatetime($datetime); |
|
357 | + $datetime_identifier = "D{$datetime->ID()}"; |
|
358 | + $reg_limit = $datetime->reg_limit(); |
|
359 | + // ticket quantity can not exceed datetime reg limit |
|
360 | + $max_tickets = min($max_tickets, $reg_limit); |
|
361 | + // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
362 | + // we are going to move all of our data into the following arrays: |
|
363 | + // datetime spaces initially represents the reg limit for each datetime, |
|
364 | + // but this will get adjusted as tickets are accounted for |
|
365 | + $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
366 | + // just an array of ticket IDs grouped by datetime |
|
367 | + $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
368 | + // and an array of datetime IDs grouped by ticket |
|
369 | + $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
370 | + } |
|
371 | + // total quantity of sold and reserved for each ticket |
|
372 | + $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
373 | + // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
374 | + $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
375 | + } |
|
376 | + } |
|
377 | + // sort datetime spaces by reg limit, but maintain our string indexes |
|
378 | + asort($this->datetime_spaces, SORT_NUMERIC); |
|
379 | + // datetime tickets need to be sorted in the SAME order as the above array... |
|
380 | + // so we'll just use array_merge() to take the structure of datetime_spaces |
|
381 | + // but overwrite all of the data with that from datetime_tickets |
|
382 | + $this->datetime_tickets = array_merge( |
|
383 | + $this->datetime_spaces, |
|
384 | + $this->datetime_tickets |
|
385 | + ); |
|
386 | + if ($this->debug) { |
|
387 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
388 | + \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
389 | + \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * performs calculations on initialized data |
|
396 | + * |
|
397 | + * @param bool $consider_sold |
|
398 | + * @return int|float |
|
399 | + */ |
|
400 | + private function calculate($consider_sold = true) |
|
401 | + { |
|
402 | + if ($this->debug) { |
|
403 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
404 | + \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
405 | + } |
|
406 | + if ($consider_sold) { |
|
407 | + // subtract amounts sold from all ticket quantities and datetime spaces |
|
408 | + $this->adjustTicketQuantitiesDueToSales(); |
|
409 | + } |
|
410 | + foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
411 | + $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
412 | + } |
|
413 | + // total spaces available is just the sum of the spaces available for each datetime |
|
414 | + $spaces_remaining = array_sum($this->total_spaces); |
|
415 | + if ($this->debug) { |
|
416 | + \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
417 | + \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
418 | + \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
419 | + } |
|
420 | + return $spaces_remaining; |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
426 | + */ |
|
427 | + private function adjustTicketQuantitiesDueToSales() |
|
428 | + { |
|
429 | + if ($this->debug) { |
|
430 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
431 | + } |
|
432 | + foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
433 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
434 | + $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
435 | + // don't let values go below zero |
|
436 | + $this->ticket_quantities[ $ticket_identifier ] = max( |
|
437 | + $this->ticket_quantities[ $ticket_identifier ], |
|
438 | + 0 |
|
439 | + ); |
|
440 | + if ($this->debug) { |
|
441 | + \EEH_Debug_Tools::printr( |
|
442 | + "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
443 | + 'subtracting', |
|
444 | + __FILE__, |
|
445 | + __LINE__ |
|
446 | + ); |
|
447 | + } |
|
448 | + } |
|
449 | + if ( |
|
450 | + isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
451 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
452 | + ) { |
|
453 | + foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
454 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
455 | + $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
456 | + // don't let values go below zero |
|
457 | + $this->datetime_spaces[ $ticket_datetime ] = max( |
|
458 | + $this->datetime_spaces[ $ticket_datetime ], |
|
459 | + 0 |
|
460 | + ); |
|
461 | + if ($this->debug) { |
|
462 | + \EEH_Debug_Tools::printr( |
|
463 | + "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
464 | + 'subtracting', |
|
465 | + __FILE__, |
|
466 | + __LINE__ |
|
467 | + ); |
|
468 | + } |
|
469 | + } |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * @param string $datetime_identifier |
|
478 | + * @param array $tickets |
|
479 | + */ |
|
480 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
481 | + { |
|
482 | + // make sure a reg limit is set for the datetime |
|
483 | + $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
484 | + ? $this->datetime_spaces[ $datetime_identifier ] |
|
485 | + : 0; |
|
486 | + // and bail if it is not |
|
487 | + if (! $reg_limit) { |
|
488 | + if ($this->debug) { |
|
489 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
490 | + } |
|
491 | + return; |
|
492 | + } |
|
493 | + if ($this->debug) { |
|
494 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
495 | + \EEH_Debug_Tools::printr( |
|
496 | + "{$reg_limit}", |
|
497 | + 'REG LIMIT', |
|
498 | + __FILE__, |
|
499 | + __LINE__ |
|
500 | + ); |
|
501 | + } |
|
502 | + // number of allocated spaces always starts at zero |
|
503 | + $spaces_allocated = 0; |
|
504 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
505 | + foreach ($tickets as $ticket_identifier) { |
|
506 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
507 | + $datetime_identifier, |
|
508 | + $reg_limit, |
|
509 | + $ticket_identifier, |
|
510 | + $spaces_allocated |
|
511 | + ); |
|
512 | + } |
|
513 | + // spaces can't be negative |
|
514 | + $spaces_allocated = max($spaces_allocated, 0); |
|
515 | + if ($spaces_allocated) { |
|
516 | + // track any non-zero values |
|
517 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
518 | + if ($this->debug) { |
|
519 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
520 | + } |
|
521 | + } else { |
|
522 | + if ($this->debug) { |
|
523 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
524 | + } |
|
525 | + } |
|
526 | + if ($this->debug) { |
|
527 | + \EEH_Debug_Tools::printr( |
|
528 | + $this->total_spaces[ $datetime_identifier ], |
|
529 | + '$total_spaces', |
|
530 | + __FILE__, |
|
531 | + __LINE__ |
|
532 | + ); |
|
533 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
534 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * @param string $datetime_identifier |
|
541 | + * @param int $reg_limit |
|
542 | + * @param string $ticket_identifier |
|
543 | + * @param int $spaces_allocated |
|
544 | + * @return int |
|
545 | + */ |
|
546 | + private function calculateAvailableSpacesForTicket( |
|
547 | + $datetime_identifier, |
|
548 | + $reg_limit, |
|
549 | + $ticket_identifier, |
|
550 | + $spaces_allocated |
|
551 | + ) { |
|
552 | + // make sure ticket quantity is set |
|
553 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
554 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
555 | + : 0; |
|
556 | + if ($this->debug) { |
|
557 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
558 | + \EEH_Debug_Tools::printr( |
|
559 | + "{$ticket_quantity}", |
|
560 | + "ticket $ticket_identifier quantity: ", |
|
561 | + __FILE__, |
|
562 | + __LINE__, |
|
563 | + 2 |
|
564 | + ); |
|
565 | + } |
|
566 | + if ($ticket_quantity) { |
|
567 | + if ($this->debug) { |
|
568 | + \EEH_Debug_Tools::printr( |
|
569 | + ($spaces_allocated <= $reg_limit) |
|
570 | + ? 'true' |
|
571 | + : 'false', |
|
572 | + ' . spaces_allocated <= reg_limit = ', |
|
573 | + __FILE__, |
|
574 | + __LINE__ |
|
575 | + ); |
|
576 | + } |
|
577 | + // if the datetime is NOT at full capacity yet |
|
578 | + if ($spaces_allocated <= $reg_limit) { |
|
579 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
580 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
581 | + // or the maximum ticket quantity |
|
582 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
583 | + // adjust the available quantity in our tracking array |
|
584 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
585 | + // and increment spaces allocated for this datetime |
|
586 | + $spaces_allocated += $ticket_quantity; |
|
587 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
588 | + if ($this->debug) { |
|
589 | + \EEH_Debug_Tools::printr( |
|
590 | + "{$ticket_quantity} {$ticket_identifier} tickets", |
|
591 | + ' > > allocate ', |
|
592 | + __FILE__, |
|
593 | + __LINE__, |
|
594 | + 3 |
|
595 | + ); |
|
596 | + if ($at_capacity) { |
|
597 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
598 | + } |
|
599 | + } |
|
600 | + // now adjust all other datetimes that allow access to this ticket |
|
601 | + $this->adjustDatetimes( |
|
602 | + $datetime_identifier, |
|
603 | + $ticket_identifier, |
|
604 | + $ticket_quantity, |
|
605 | + $at_capacity |
|
606 | + ); |
|
607 | + } |
|
608 | + } |
|
609 | + return $spaces_allocated; |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * subtracts ticket amounts from all datetime reg limits |
|
615 | + * that allow access to the ticket specified, |
|
616 | + * because that ticket could be used |
|
617 | + * to attend any of the datetimes it has access to |
|
618 | + * |
|
619 | + * @param string $datetime_identifier |
|
620 | + * @param string $ticket_identifier |
|
621 | + * @param bool $at_capacity |
|
622 | + * @param int $ticket_quantity |
|
623 | + */ |
|
624 | + private function adjustDatetimes( |
|
625 | + $datetime_identifier, |
|
626 | + $ticket_identifier, |
|
627 | + $ticket_quantity, |
|
628 | + $at_capacity |
|
629 | + ) { |
|
630 | + /** @var array $datetime_tickets */ |
|
631 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
632 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
633 | + continue; |
|
634 | + } |
|
635 | + $adjusted = $this->adjustDatetimeSpaces( |
|
636 | + $datetime_ID, |
|
637 | + $ticket_identifier, |
|
638 | + $ticket_quantity |
|
639 | + ); |
|
640 | + // skip to next ticket if nothing changed |
|
641 | + if (! ($adjusted || $at_capacity)) { |
|
642 | + continue; |
|
643 | + } |
|
644 | + // then all of it's tickets are now unavailable |
|
645 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
646 | + if ( |
|
647 | + ($ticket_identifier === $datetime_ticket || $at_capacity) |
|
648 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
649 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
650 | + ) { |
|
651 | + if ($this->debug) { |
|
652 | + \EEH_Debug_Tools::printr( |
|
653 | + $datetime_ticket, |
|
654 | + ' . . . adjust ticket quantities for', |
|
655 | + __FILE__, |
|
656 | + __LINE__ |
|
657 | + ); |
|
658 | + } |
|
659 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
660 | + // otherwise just subtract the ticket quantity |
|
661 | + $new_quantity = $at_capacity |
|
662 | + ? 0 |
|
663 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
664 | + // don't let ticket quantity go below zero |
|
665 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
666 | + if ($this->debug) { |
|
667 | + \EEH_Debug_Tools::printr( |
|
668 | + $at_capacity |
|
669 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
670 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
671 | + " . . . . {$datetime_ticket} quantity set to ", |
|
672 | + __FILE__, |
|
673 | + __LINE__ |
|
674 | + ); |
|
675 | + } |
|
676 | + } |
|
677 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
678 | + if ($datetime_ticket === $ticket_identifier) { |
|
679 | + if ( |
|
680 | + isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
681 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
682 | + ) { |
|
683 | + if ($this->debug) { |
|
684 | + \EEH_Debug_Tools::printr( |
|
685 | + $datetime_ticket, |
|
686 | + ' . . adjust other Datetimes for', |
|
687 | + __FILE__, |
|
688 | + __LINE__ |
|
689 | + ); |
|
690 | + } |
|
691 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
692 | + // don't adjust the current datetime twice |
|
693 | + if ($datetime !== $datetime_identifier) { |
|
694 | + $this->adjustDatetimeSpaces( |
|
695 | + $datetime, |
|
696 | + $datetime_ticket, |
|
697 | + $ticket_quantity |
|
698 | + ); |
|
699 | + } |
|
700 | + } |
|
701 | + } |
|
702 | + } |
|
703 | + } |
|
704 | + } |
|
705 | + } |
|
706 | + |
|
707 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
708 | + { |
|
709 | + // does datetime have spaces available? |
|
710 | + // and does the supplied ticket have access to this datetime ? |
|
711 | + if ( |
|
712 | + $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
713 | + && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
714 | + && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
715 | + ) { |
|
716 | + if ($this->debug) { |
|
717 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
718 | + \EEH_Debug_Tools::printr( |
|
719 | + "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
720 | + " . . current {$datetime_identifier} spaces available", |
|
721 | + __FILE__, |
|
722 | + __LINE__ |
|
723 | + ); |
|
724 | + } |
|
725 | + // then decrement the available spaces for the datetime |
|
726 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
727 | + // but don't let quantities go below zero |
|
728 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
729 | + $this->datetime_spaces[ $datetime_identifier ], |
|
730 | + 0 |
|
731 | + ); |
|
732 | + if ($this->debug) { |
|
733 | + \EEH_Debug_Tools::printr( |
|
734 | + "{$ticket_quantity}", |
|
735 | + " . . . {$datetime_identifier} capacity reduced by", |
|
736 | + __FILE__, |
|
737 | + __LINE__ |
|
738 | + ); |
|
739 | + } |
|
740 | + return true; |
|
741 | + } |
|
742 | + return false; |
|
743 | + } |
|
744 | 744 | } |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function setActiveTickets(array $active_tickets = array()) |
183 | 183 | { |
184 | - if (! empty($active_tickets)) { |
|
184 | + if ( ! empty($active_tickets)) { |
|
185 | 185 | foreach ($active_tickets as $active_ticket) { |
186 | 186 | $this->validateTicket($active_ticket); |
187 | 187 | } |
188 | 188 | // sort incoming array by ticket quantity (asc) |
189 | 189 | usort( |
190 | 190 | $active_tickets, |
191 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
191 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
192 | 192 | if ($a->qty() === $b->qty()) { |
193 | 193 | return 0; |
194 | 194 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | private function validateTicket($ticket) |
212 | 212 | { |
213 | - if (! $ticket instanceof EE_Ticket) { |
|
213 | + if ( ! $ticket instanceof EE_Ticket) { |
|
214 | 214 | throw new DomainException( |
215 | 215 | esc_html__( |
216 | 216 | 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | ) |
262 | 262 | ); |
263 | 263 | } |
264 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
264 | + $this->datetimes[$datetime->ID()] = $datetime; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | $this->tickets_sold = array(); |
341 | 341 | $this->total_spaces = array(); |
342 | 342 | $active_tickets = $this->getActiveTickets(); |
343 | - if (! empty($active_tickets)) { |
|
343 | + if ( ! empty($active_tickets)) { |
|
344 | 344 | foreach ($active_tickets as $ticket) { |
345 | 345 | $this->validateTicket($ticket); |
346 | 346 | // we need to index our data arrays using strings for the purpose of sorting, |
@@ -362,16 +362,16 @@ discard block |
||
362 | 362 | // we are going to move all of our data into the following arrays: |
363 | 363 | // datetime spaces initially represents the reg limit for each datetime, |
364 | 364 | // but this will get adjusted as tickets are accounted for |
365 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
365 | + $this->datetime_spaces[$datetime_identifier] = $reg_limit; |
|
366 | 366 | // just an array of ticket IDs grouped by datetime |
367 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
367 | + $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier; |
|
368 | 368 | // and an array of datetime IDs grouped by ticket |
369 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
369 | + $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier; |
|
370 | 370 | } |
371 | 371 | // total quantity of sold and reserved for each ticket |
372 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
372 | + $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved(); |
|
373 | 373 | // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
374 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
374 | + $this->ticket_quantities[$ticket_identifier] = $max_tickets; |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | // sort datetime spaces by reg limit, but maintain our string indexes |
@@ -430,11 +430,11 @@ discard block |
||
430 | 430 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
431 | 431 | } |
432 | 432 | foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
433 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
434 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
433 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
434 | + $this->ticket_quantities[$ticket_identifier] -= $tickets_sold; |
|
435 | 435 | // don't let values go below zero |
436 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
437 | - $this->ticket_quantities[ $ticket_identifier ], |
|
436 | + $this->ticket_quantities[$ticket_identifier] = max( |
|
437 | + $this->ticket_quantities[$ticket_identifier], |
|
438 | 438 | 0 |
439 | 439 | ); |
440 | 440 | if ($this->debug) { |
@@ -447,15 +447,15 @@ discard block |
||
447 | 447 | } |
448 | 448 | } |
449 | 449 | if ( |
450 | - isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
451 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
450 | + isset($this->ticket_datetimes[$ticket_identifier]) |
|
451 | + && is_array($this->ticket_datetimes[$ticket_identifier]) |
|
452 | 452 | ) { |
453 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
454 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
455 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
453 | + foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) { |
|
454 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
455 | + $this->datetime_spaces[$ticket_datetime] -= $tickets_sold; |
|
456 | 456 | // don't let values go below zero |
457 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
458 | - $this->datetime_spaces[ $ticket_datetime ], |
|
457 | + $this->datetime_spaces[$ticket_datetime] = max( |
|
458 | + $this->datetime_spaces[$ticket_datetime], |
|
459 | 459 | 0 |
460 | 460 | ); |
461 | 461 | if ($this->debug) { |
@@ -480,11 +480,11 @@ discard block |
||
480 | 480 | private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
481 | 481 | { |
482 | 482 | // make sure a reg limit is set for the datetime |
483 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
484 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
483 | + $reg_limit = isset($this->datetime_spaces[$datetime_identifier]) |
|
484 | + ? $this->datetime_spaces[$datetime_identifier] |
|
485 | 485 | : 0; |
486 | 486 | // and bail if it is not |
487 | - if (! $reg_limit) { |
|
487 | + if ( ! $reg_limit) { |
|
488 | 488 | if ($this->debug) { |
489 | 489 | \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
490 | 490 | } |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | } |
502 | 502 | // number of allocated spaces always starts at zero |
503 | 503 | $spaces_allocated = 0; |
504 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
504 | + $this->total_spaces[$datetime_identifier] = 0; |
|
505 | 505 | foreach ($tickets as $ticket_identifier) { |
506 | 506 | $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
507 | 507 | $datetime_identifier, |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | $spaces_allocated = max($spaces_allocated, 0); |
515 | 515 | if ($spaces_allocated) { |
516 | 516 | // track any non-zero values |
517 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
517 | + $this->total_spaces[$datetime_identifier] += $spaces_allocated; |
|
518 | 518 | if ($this->debug) { |
519 | 519 | \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
520 | 520 | } |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | } |
526 | 526 | if ($this->debug) { |
527 | 527 | \EEH_Debug_Tools::printr( |
528 | - $this->total_spaces[ $datetime_identifier ], |
|
528 | + $this->total_spaces[$datetime_identifier], |
|
529 | 529 | '$total_spaces', |
530 | 530 | __FILE__, |
531 | 531 | __LINE__ |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | $spaces_allocated |
551 | 551 | ) { |
552 | 552 | // make sure ticket quantity is set |
553 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
554 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
553 | + $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier]) |
|
554 | + ? $this->ticket_quantities[$ticket_identifier] |
|
555 | 555 | : 0; |
556 | 556 | if ($this->debug) { |
557 | 557 | \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | // or the maximum ticket quantity |
582 | 582 | $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
583 | 583 | // adjust the available quantity in our tracking array |
584 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
584 | + $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity; |
|
585 | 585 | // and increment spaces allocated for this datetime |
586 | 586 | $spaces_allocated += $ticket_quantity; |
587 | 587 | $at_capacity = $spaces_allocated >= $reg_limit; |
@@ -638,15 +638,15 @@ discard block |
||
638 | 638 | $ticket_quantity |
639 | 639 | ); |
640 | 640 | // skip to next ticket if nothing changed |
641 | - if (! ($adjusted || $at_capacity)) { |
|
641 | + if ( ! ($adjusted || $at_capacity)) { |
|
642 | 642 | continue; |
643 | 643 | } |
644 | 644 | // then all of it's tickets are now unavailable |
645 | 645 | foreach ($datetime_tickets as $datetime_ticket) { |
646 | 646 | if ( |
647 | 647 | ($ticket_identifier === $datetime_ticket || $at_capacity) |
648 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
649 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
648 | + && isset($this->ticket_quantities[$datetime_ticket]) |
|
649 | + && $this->ticket_quantities[$datetime_ticket] > 0 |
|
650 | 650 | ) { |
651 | 651 | if ($this->debug) { |
652 | 652 | \EEH_Debug_Tools::printr( |
@@ -660,14 +660,14 @@ discard block |
||
660 | 660 | // otherwise just subtract the ticket quantity |
661 | 661 | $new_quantity = $at_capacity |
662 | 662 | ? 0 |
663 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
663 | + : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity; |
|
664 | 664 | // don't let ticket quantity go below zero |
665 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
665 | + $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0); |
|
666 | 666 | if ($this->debug) { |
667 | 667 | \EEH_Debug_Tools::printr( |
668 | 668 | $at_capacity |
669 | 669 | ? "0 because Datetime {$datetime_identifier} is at capacity" |
670 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
670 | + : "{$this->ticket_quantities[$datetime_ticket]}", |
|
671 | 671 | " . . . . {$datetime_ticket} quantity set to ", |
672 | 672 | __FILE__, |
673 | 673 | __LINE__ |
@@ -677,8 +677,8 @@ discard block |
||
677 | 677 | // but we also need to adjust spaces for any other datetimes this ticket has access to |
678 | 678 | if ($datetime_ticket === $ticket_identifier) { |
679 | 679 | if ( |
680 | - isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
681 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
680 | + isset($this->ticket_datetimes[$datetime_ticket]) |
|
681 | + && is_array($this->ticket_datetimes[$datetime_ticket]) |
|
682 | 682 | ) { |
683 | 683 | if ($this->debug) { |
684 | 684 | \EEH_Debug_Tools::printr( |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | __LINE__ |
689 | 689 | ); |
690 | 690 | } |
691 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
691 | + foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) { |
|
692 | 692 | // don't adjust the current datetime twice |
693 | 693 | if ($datetime !== $datetime_identifier) { |
694 | 694 | $this->adjustDatetimeSpaces( |
@@ -709,24 +709,24 @@ discard block |
||
709 | 709 | // does datetime have spaces available? |
710 | 710 | // and does the supplied ticket have access to this datetime ? |
711 | 711 | if ( |
712 | - $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
713 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
714 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
712 | + $this->datetime_spaces[$datetime_identifier] > 0 |
|
713 | + && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier]) |
|
714 | + && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true) |
|
715 | 715 | ) { |
716 | 716 | if ($this->debug) { |
717 | 717 | \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
718 | 718 | \EEH_Debug_Tools::printr( |
719 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
719 | + "{$this->datetime_spaces[$datetime_identifier]}", |
|
720 | 720 | " . . current {$datetime_identifier} spaces available", |
721 | 721 | __FILE__, |
722 | 722 | __LINE__ |
723 | 723 | ); |
724 | 724 | } |
725 | 725 | // then decrement the available spaces for the datetime |
726 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
726 | + $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity; |
|
727 | 727 | // but don't let quantities go below zero |
728 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
729 | - $this->datetime_spaces[ $datetime_identifier ], |
|
728 | + $this->datetime_spaces[$datetime_identifier] = max( |
|
729 | + $this->datetime_spaces[$datetime_identifier], |
|
730 | 730 | 0 |
731 | 731 | ); |
732 | 732 | if ($this->debug) { |
@@ -64,6 +64,9 @@ |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | |
67 | + /** |
|
68 | + * @param string $argument_label |
|
69 | + */ |
|
67 | 70 | private function throwValidationException($argument_label, $argument_value) |
68 | 71 | { |
69 | 72 | throw new InvalidArgumentException( |
@@ -11,109 +11,109 @@ |
||
11 | 11 | class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * minimum value for number field |
|
16 | - * |
|
17 | - * @var int|null $min |
|
18 | - */ |
|
19 | - protected $min; |
|
14 | + /** |
|
15 | + * minimum value for number field |
|
16 | + * |
|
17 | + * @var int|null $min |
|
18 | + */ |
|
19 | + protected $min; |
|
20 | 20 | |
21 | - /** |
|
22 | - * maximum value for number field |
|
23 | - * |
|
24 | - * @var int|null $max |
|
25 | - */ |
|
26 | - protected $max; |
|
21 | + /** |
|
22 | + * maximum value for number field |
|
23 | + * |
|
24 | + * @var int|null $max |
|
25 | + */ |
|
26 | + protected $max; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * This is used to set the "step" attribute for the html5 number input. |
|
31 | - * Controls the increments on the input when incrementing or decrementing the value. |
|
32 | - * Note: Although the step attribute allows for the string "any" to be used, Firefox and Chrome will interpret that |
|
33 | - * to increment by 1. So although "any" is accepted as a value, it is converted to 1. |
|
34 | - * @var float |
|
35 | - */ |
|
36 | - protected $step; |
|
29 | + /** |
|
30 | + * This is used to set the "step" attribute for the html5 number input. |
|
31 | + * Controls the increments on the input when incrementing or decrementing the value. |
|
32 | + * Note: Although the step attribute allows for the string "any" to be used, Firefox and Chrome will interpret that |
|
33 | + * to increment by 1. So although "any" is accepted as a value, it is converted to 1. |
|
34 | + * @var float |
|
35 | + */ |
|
36 | + protected $step; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * EE_Number_Input_Display_Strategy constructor. |
|
41 | - * Null is the default value for the incoming arguments because 0 is a valid value. So we use null |
|
42 | - * to indicate NOT setting this attribute. |
|
43 | - * |
|
44 | - * @param int|null $min |
|
45 | - * @param int|null $max |
|
46 | - * @param int|null $step |
|
47 | - * @throws InvalidArgumentException |
|
48 | - */ |
|
49 | - public function __construct($min = null, $max = null, $step = null) |
|
50 | - { |
|
51 | - $this->min = is_numeric($min) || $min === null |
|
52 | - ? $min |
|
53 | - : $this->throwValidationException('min', $min); |
|
54 | - $this->max = is_numeric($max) || $max === null |
|
55 | - ? $max |
|
56 | - : $this->throwValidationException('max', $max); |
|
57 | - $step = $step === 'any' ? 1 : $step; |
|
58 | - $this->step = is_numeric($step) || $step === null |
|
59 | - ? $step |
|
60 | - : $this->throwValidationException('step', $step); |
|
61 | - } |
|
39 | + /** |
|
40 | + * EE_Number_Input_Display_Strategy constructor. |
|
41 | + * Null is the default value for the incoming arguments because 0 is a valid value. So we use null |
|
42 | + * to indicate NOT setting this attribute. |
|
43 | + * |
|
44 | + * @param int|null $min |
|
45 | + * @param int|null $max |
|
46 | + * @param int|null $step |
|
47 | + * @throws InvalidArgumentException |
|
48 | + */ |
|
49 | + public function __construct($min = null, $max = null, $step = null) |
|
50 | + { |
|
51 | + $this->min = is_numeric($min) || $min === null |
|
52 | + ? $min |
|
53 | + : $this->throwValidationException('min', $min); |
|
54 | + $this->max = is_numeric($max) || $max === null |
|
55 | + ? $max |
|
56 | + : $this->throwValidationException('max', $max); |
|
57 | + $step = $step === 'any' ? 1 : $step; |
|
58 | + $this->step = is_numeric($step) || $step === null |
|
59 | + ? $step |
|
60 | + : $this->throwValidationException('step', $step); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - private function throwValidationException($argument_label, $argument_value) |
|
65 | - { |
|
66 | - throw new InvalidArgumentException( |
|
67 | - sprintf( |
|
68 | - esc_html__( |
|
69 | - 'The %1$s parameter value for %2$s must be numeric or null, %3$s was passed into the constructor.', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - $argument_label, |
|
73 | - __CLASS__, |
|
74 | - $argument_value |
|
75 | - ) |
|
76 | - ); |
|
77 | - } |
|
64 | + private function throwValidationException($argument_label, $argument_value) |
|
65 | + { |
|
66 | + throw new InvalidArgumentException( |
|
67 | + sprintf( |
|
68 | + esc_html__( |
|
69 | + 'The %1$s parameter value for %2$s must be numeric or null, %3$s was passed into the constructor.', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + $argument_label, |
|
73 | + __CLASS__, |
|
74 | + $argument_value |
|
75 | + ) |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * @return string of html to display the field |
|
83 | - */ |
|
84 | - public function display() |
|
85 | - { |
|
86 | - $input = $this->_opening_tag('input'); |
|
87 | - $input .= $this->_attributes_string( |
|
88 | - array_merge( |
|
89 | - $this->_standard_attributes_array(), |
|
90 | - $this->getNumberInputAttributes() |
|
91 | - ) |
|
92 | - ); |
|
93 | - $input .= $this->_close_tag(); |
|
94 | - return $input; |
|
95 | - } |
|
81 | + /** |
|
82 | + * @return string of html to display the field |
|
83 | + */ |
|
84 | + public function display() |
|
85 | + { |
|
86 | + $input = $this->_opening_tag('input'); |
|
87 | + $input .= $this->_attributes_string( |
|
88 | + array_merge( |
|
89 | + $this->_standard_attributes_array(), |
|
90 | + $this->getNumberInputAttributes() |
|
91 | + ) |
|
92 | + ); |
|
93 | + $input .= $this->_close_tag(); |
|
94 | + return $input; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Return the attributes specific to this display strategy |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - private function getNumberInputAttributes() |
|
103 | - { |
|
104 | - $attributes = array( |
|
105 | - 'type' => 'number', |
|
106 | - 'value' => $this->_input->raw_value_in_form() |
|
107 | - ); |
|
108 | - if ($this->min !== null) { |
|
109 | - $attributes['min'] = $this->min; |
|
110 | - } |
|
111 | - if ($this->max !== null) { |
|
112 | - $attributes['max'] = $this->max; |
|
113 | - } |
|
114 | - if ($this->step !== null) { |
|
115 | - $attributes['step'] = $this->step; |
|
116 | - } |
|
117 | - return $attributes; |
|
118 | - } |
|
98 | + /** |
|
99 | + * Return the attributes specific to this display strategy |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + private function getNumberInputAttributes() |
|
103 | + { |
|
104 | + $attributes = array( |
|
105 | + 'type' => 'number', |
|
106 | + 'value' => $this->_input->raw_value_in_form() |
|
107 | + ); |
|
108 | + if ($this->min !== null) { |
|
109 | + $attributes['min'] = $this->min; |
|
110 | + } |
|
111 | + if ($this->max !== null) { |
|
112 | + $attributes['max'] = $this->max; |
|
113 | + } |
|
114 | + if ($this->step !== null) { |
|
115 | + $attributes['step'] = $this->step; |
|
116 | + } |
|
117 | + return $attributes; |
|
118 | + } |
|
119 | 119 | } |
@@ -11,33 +11,33 @@ |
||
11 | 11 | class EE_Float_Input extends EE_Form_Input_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $input_settings |
|
16 | - * @throws InvalidArgumentException |
|
17 | - */ |
|
18 | - public function __construct($input_settings = array()) |
|
19 | - { |
|
20 | - $this->_set_display_strategy( |
|
21 | - new EE_Number_Input_Display_Strategy( |
|
22 | - isset($input_settings['min_value']) |
|
23 | - ? $input_settings['min_value'] |
|
24 | - : null, |
|
25 | - isset($input_settings['max_value']) |
|
26 | - ? $input_settings['max_value'] |
|
27 | - : null, |
|
28 | - isset($input_settings['step_value']) |
|
29 | - ? $input_settings['step_value'] |
|
30 | - : null |
|
31 | - ) |
|
32 | - ); |
|
33 | - $this->_set_normalization_strategy(new EE_Float_Normalization()); |
|
34 | - $this->_add_validation_strategy( |
|
35 | - new EE_Float_Validation_Strategy( |
|
36 | - isset($input_settings['validation_error_message']) |
|
37 | - ? $input_settings['validation_error_message'] |
|
38 | - : null |
|
39 | - ) |
|
40 | - ); |
|
41 | - parent::__construct($input_settings); |
|
42 | - } |
|
14 | + /** |
|
15 | + * @param array $input_settings |
|
16 | + * @throws InvalidArgumentException |
|
17 | + */ |
|
18 | + public function __construct($input_settings = array()) |
|
19 | + { |
|
20 | + $this->_set_display_strategy( |
|
21 | + new EE_Number_Input_Display_Strategy( |
|
22 | + isset($input_settings['min_value']) |
|
23 | + ? $input_settings['min_value'] |
|
24 | + : null, |
|
25 | + isset($input_settings['max_value']) |
|
26 | + ? $input_settings['max_value'] |
|
27 | + : null, |
|
28 | + isset($input_settings['step_value']) |
|
29 | + ? $input_settings['step_value'] |
|
30 | + : null |
|
31 | + ) |
|
32 | + ); |
|
33 | + $this->_set_normalization_strategy(new EE_Float_Normalization()); |
|
34 | + $this->_add_validation_strategy( |
|
35 | + new EE_Float_Validation_Strategy( |
|
36 | + isset($input_settings['validation_error_message']) |
|
37 | + ? $input_settings['validation_error_message'] |
|
38 | + : null |
|
39 | + ) |
|
40 | + ); |
|
41 | + parent::__construct($input_settings); |
|
42 | + } |
|
43 | 43 | } |
@@ -152,7 +152,7 @@ |
||
152 | 152 | |
153 | 153 | /** |
154 | 154 | * @param EE_Event $item |
155 | - * @return mixed|string |
|
155 | + * @return string |
|
156 | 156 | * @throws EE_Error |
157 | 157 | */ |
158 | 158 | public function column_id(EE_Event $item) |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $class = parent::_get_row_class($item); |
115 | 115 | // add status class |
116 | 116 | $class .= $item instanceof EE_Event |
117 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
117 | + ? ' ee-status-strip event-status-'.$item->get_active_status() |
|
118 | 118 | : ''; |
119 | 119 | if ($this->_has_checkbox_column) { |
120 | 120 | $class .= ' has-checkbox-column'; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function column_cb($item) |
145 | 145 | { |
146 | - if (! $item instanceof EE_Event) { |
|
146 | + if ( ! $item instanceof EE_Event) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public function column_id(EE_Event $item) |
167 | 167 | { |
168 | 168 | $content = $item->ID(); |
169 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
169 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
170 | 170 | return $content; |
171 | 171 | } |
172 | 172 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $actions = $this->_column_name_action_setup($item); |
190 | 190 | $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
191 | 191 | $content = '<strong><a class="row-title" href="' |
192 | - . $edit_link . '">' |
|
192 | + . $edit_link.'">' |
|
193 | 193 | . $item->name() |
194 | 194 | . '</a></strong>' |
195 | 195 | . $status; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | protected function _column_name_action_setup(EE_Event $item) |
219 | 219 | { |
220 | 220 | // todo: remove when attendees is active |
221 | - if (! defined('REG_ADMIN_URL')) { |
|
221 | + if ( ! defined('REG_ADMIN_URL')) { |
|
222 | 222 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
223 | 223 | } |
224 | 224 | $actions = array(); |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | 'post' => $item->ID(), |
238 | 238 | ); |
239 | 239 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
240 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
241 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
240 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
241 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
242 | 242 | . esc_html__('Edit', 'event_espresso') |
243 | 243 | . '</a>'; |
244 | 244 | } |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | 'event_id' => $item->ID(), |
259 | 259 | ); |
260 | 260 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
261 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
262 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
261 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
262 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
263 | 263 | . esc_html__('Registrations', 'event_espresso') |
264 | 264 | . '</a>'; |
265 | 265 | } |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | ); |
313 | 313 | } |
314 | 314 | $view_link = get_permalink($item->ID()); |
315 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
316 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
315 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
316 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
317 | 317 | . esc_html__('View', 'event_espresso') |
318 | 318 | . '</a>'; |
319 | 319 | if ($item->get('status') === 'trash') { |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | $item->ID() |
325 | 325 | ) |
326 | 326 | ) { |
327 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
328 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
327 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
328 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
329 | 329 | . '">' |
330 | 330 | . esc_html__('Restore from Trash', 'event_espresso') |
331 | 331 | . '</a>'; |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | $item->ID() |
339 | 339 | ) |
340 | 340 | ) { |
341 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
342 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
341 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
342 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
343 | 343 | . esc_html__('Delete Permanently', 'event_espresso') |
344 | 344 | . '</a>'; |
345 | 345 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | $item->ID() |
352 | 352 | ) |
353 | 353 | ) { |
354 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
355 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
354 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
355 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
356 | 356 | . esc_html__('Trash', 'event_espresso') |
357 | 357 | . '</a>'; |
358 | 358 | } |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | 'EVT_wp_user' => $item->wp_user(), |
378 | 378 | ); |
379 | 379 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
380 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
381 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
380 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
381 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
382 | 382 | . $event_author->display_name |
383 | 383 | . '</a>'; |
384 | 384 | } |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | return implode( |
396 | 396 | ', ', |
397 | 397 | array_map( |
398 | - function (EE_Term $category) { |
|
398 | + function(EE_Term $category) { |
|
399 | 399 | return $category->name(); |
400 | 400 | }, |
401 | 401 | $event_categories |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | 'ee_read_registrations', |
471 | 471 | 'espresso_registrations_view_registration' |
472 | 472 | ) |
473 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
473 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
474 | 474 | : $registered_attendees; |
475 | 475 | } |
476 | 476 | |
@@ -500,13 +500,13 @@ discard block |
||
500 | 500 | public function column_actions(EE_Event $item) |
501 | 501 | { |
502 | 502 | // todo: remove when attendees is active |
503 | - if (! defined('REG_ADMIN_URL')) { |
|
503 | + if ( ! defined('REG_ADMIN_URL')) { |
|
504 | 504 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
505 | 505 | } |
506 | 506 | $action_links = array(); |
507 | 507 | $view_link = get_permalink($item->ID()); |
508 | - $action_links[] = '<a href="' . $view_link . '"' |
|
509 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
508 | + $action_links[] = '<a href="'.$view_link.'"' |
|
509 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
510 | 510 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
511 | 511 | if ( |
512 | 512 | EE_Registry::instance()->CAP->current_user_can( |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | 'post' => $item->ID(), |
521 | 521 | ); |
522 | 522 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
523 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
524 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
523 | + $action_links[] = '<a href="'.$edit_link.'"' |
|
524 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
525 | 525 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
526 | 526 | . '</a>'; |
527 | 527 | } |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | 'event_id' => $item->ID(), |
541 | 541 | ); |
542 | 542 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
543 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
544 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
543 | + $action_links[] = '<a href="'.$attendees_link.'"' |
|
544 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
545 | 545 | . '<div class="dashicons dashicons-groups"></div>' |
546 | 546 | . '</a>'; |
547 | 547 | } |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | } |
577 | 577 | $column_array = []; |
578 | 578 | foreach ($this->_columns as $column => $column_label) { |
579 | - $column_array[ $column ] = $column_label; |
|
579 | + $column_array[$column] = $column_label; |
|
580 | 580 | if ($column === 'venue') { |
581 | 581 | $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
582 | 582 | } |
@@ -15,567 +15,567 @@ |
||
15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EE_Datetime |
|
20 | - */ |
|
21 | - private $_dtt; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Initial setup of data properties for the list table. |
|
26 | - */ |
|
27 | - protected function _setup_data() |
|
28 | - { |
|
29 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
30 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Set up of additional properties for the list table. |
|
36 | - */ |
|
37 | - protected function _set_properties() |
|
38 | - { |
|
39 | - $this->_wp_list_args = array( |
|
40 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
41 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
42 | - 'ajax' => true, // for now |
|
43 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
44 | - ); |
|
45 | - $this->_columns = array( |
|
46 | - 'cb' => '<input type="checkbox" />', |
|
47 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
48 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
49 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
50 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
51 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
52 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
53 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
54 | - . '<span class="screen-reader-text">' |
|
55 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
56 | - . '</span>' |
|
57 | - . '</span>', |
|
58 | - // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
59 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
60 | - ); |
|
61 | - $this->addConditionalColumns(); |
|
62 | - $this->_sortable_columns = array( |
|
63 | - 'id' => array('EVT_ID' => true), |
|
64 | - 'name' => array('EVT_name' => false), |
|
65 | - 'author' => array('EVT_wp_user' => false), |
|
66 | - 'venue' => array('Venue.VNU_name' => false), |
|
67 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
68 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
69 | - ); |
|
70 | - |
|
71 | - $this->_primary_column = 'id'; |
|
72 | - $this->_hidden_columns = array('author', 'event_category'); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - protected function _get_table_filters() |
|
80 | - { |
|
81 | - return array(); // no filters with decaf |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Setup of views properties. |
|
87 | - * |
|
88 | - * @throws InvalidDataTypeException |
|
89 | - * @throws InvalidInterfaceException |
|
90 | - * @throws InvalidArgumentException |
|
91 | - */ |
|
92 | - protected function _add_view_counts() |
|
93 | - { |
|
94 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
95 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
96 | - if ( |
|
97 | - EE_Registry::instance()->CAP->current_user_can( |
|
98 | - 'ee_delete_events', |
|
99 | - 'espresso_events_trash_events' |
|
100 | - ) |
|
101 | - ) { |
|
102 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param EE_Event $item |
|
109 | - * @return string |
|
110 | - * @throws EE_Error |
|
111 | - */ |
|
112 | - protected function _get_row_class($item) |
|
113 | - { |
|
114 | - $class = parent::_get_row_class($item); |
|
115 | - // add status class |
|
116 | - $class .= $item instanceof EE_Event |
|
117 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
118 | - : ''; |
|
119 | - if ($this->_has_checkbox_column) { |
|
120 | - $class .= ' has-checkbox-column'; |
|
121 | - } |
|
122 | - return $class; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param EE_Event $item |
|
128 | - * @return string |
|
129 | - * @throws EE_Error |
|
130 | - */ |
|
131 | - public function column_status(EE_Event $item) |
|
132 | - { |
|
133 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
134 | - . $item->get_active_status() |
|
135 | - . '"></span>'; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param EE_Event $item |
|
141 | - * @return string |
|
142 | - * @throws EE_Error |
|
143 | - */ |
|
144 | - public function column_cb($item) |
|
145 | - { |
|
146 | - if (! $item instanceof EE_Event) { |
|
147 | - return ''; |
|
148 | - } |
|
149 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
150 | - return sprintf( |
|
151 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
152 | - $item->ID() |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param EE_Event $item |
|
159 | - * @return mixed|string |
|
160 | - * @throws EE_Error |
|
161 | - */ |
|
162 | - public function column_id(EE_Event $item) |
|
163 | - { |
|
164 | - $content = $item->ID(); |
|
165 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
166 | - return $content; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param EE_Event $item |
|
172 | - * @return string |
|
173 | - * @throws EE_Error |
|
174 | - * @throws InvalidArgumentException |
|
175 | - * @throws InvalidDataTypeException |
|
176 | - * @throws InvalidInterfaceException |
|
177 | - */ |
|
178 | - public function column_name(EE_Event $item) |
|
179 | - { |
|
180 | - $edit_query_args = array( |
|
181 | - 'action' => 'edit', |
|
182 | - 'post' => $item->ID(), |
|
183 | - ); |
|
184 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
185 | - $actions = $this->_column_name_action_setup($item); |
|
186 | - $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
187 | - $content = '<strong><a class="row-title" href="' |
|
188 | - . $edit_link . '">' |
|
189 | - . $item->name() |
|
190 | - . '</a></strong>' |
|
191 | - . $status; |
|
192 | - $content .= '<br><span class="ee-status-text-small">' |
|
193 | - . EEH_Template::pretty_status( |
|
194 | - $item->get_active_status(), |
|
195 | - false, |
|
196 | - 'sentence' |
|
197 | - ) |
|
198 | - . '</span>'; |
|
199 | - $content .= $this->row_actions($actions); |
|
200 | - return $content; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Just a method for setting up the actions for the name column |
|
206 | - * |
|
207 | - * @param EE_Event $item |
|
208 | - * @return array array of actions |
|
209 | - * @throws EE_Error |
|
210 | - * @throws InvalidArgumentException |
|
211 | - * @throws InvalidDataTypeException |
|
212 | - * @throws InvalidInterfaceException |
|
213 | - */ |
|
214 | - protected function _column_name_action_setup(EE_Event $item) |
|
215 | - { |
|
216 | - // todo: remove when attendees is active |
|
217 | - if (! defined('REG_ADMIN_URL')) { |
|
218 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
219 | - } |
|
220 | - $actions = array(); |
|
221 | - $restore_event_link = ''; |
|
222 | - $delete_event_link = ''; |
|
223 | - $trash_event_link = ''; |
|
224 | - if ( |
|
225 | - EE_Registry::instance()->CAP->current_user_can( |
|
226 | - 'ee_edit_event', |
|
227 | - 'espresso_events_edit', |
|
228 | - $item->ID() |
|
229 | - ) |
|
230 | - ) { |
|
231 | - $edit_query_args = array( |
|
232 | - 'action' => 'edit', |
|
233 | - 'post' => $item->ID(), |
|
234 | - ); |
|
235 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
236 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
237 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
238 | - . esc_html__('Edit', 'event_espresso') |
|
239 | - . '</a>'; |
|
240 | - } |
|
241 | - if ( |
|
242 | - EE_Registry::instance()->CAP->current_user_can( |
|
243 | - 'ee_read_registrations', |
|
244 | - 'espresso_registrations_view_registration' |
|
245 | - ) |
|
246 | - && EE_Registry::instance()->CAP->current_user_can( |
|
247 | - 'ee_read_event', |
|
248 | - 'espresso_registrations_view_registration', |
|
249 | - $item->ID() |
|
250 | - ) |
|
251 | - ) { |
|
252 | - $attendees_query_args = array( |
|
253 | - 'action' => 'default', |
|
254 | - 'event_id' => $item->ID(), |
|
255 | - ); |
|
256 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
257 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
258 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
259 | - . esc_html__('Registrations', 'event_espresso') |
|
260 | - . '</a>'; |
|
261 | - } |
|
262 | - if ( |
|
263 | - EE_Registry::instance()->CAP->current_user_can( |
|
264 | - 'ee_delete_event', |
|
265 | - 'espresso_events_trash_event', |
|
266 | - $item->ID() |
|
267 | - ) |
|
268 | - ) { |
|
269 | - $trash_event_query_args = array( |
|
270 | - 'action' => 'trash_event', |
|
271 | - 'EVT_ID' => $item->ID(), |
|
272 | - ); |
|
273 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
274 | - $trash_event_query_args, |
|
275 | - EVENTS_ADMIN_URL |
|
276 | - ); |
|
277 | - } |
|
278 | - if ( |
|
279 | - EE_Registry::instance()->CAP->current_user_can( |
|
280 | - 'ee_delete_event', |
|
281 | - 'espresso_events_restore_event', |
|
282 | - $item->ID() |
|
283 | - ) |
|
284 | - ) { |
|
285 | - $restore_event_query_args = array( |
|
286 | - 'action' => 'restore_event', |
|
287 | - 'EVT_ID' => $item->ID(), |
|
288 | - ); |
|
289 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
290 | - $restore_event_query_args, |
|
291 | - EVENTS_ADMIN_URL |
|
292 | - ); |
|
293 | - } |
|
294 | - if ( |
|
295 | - EE_Registry::instance()->CAP->current_user_can( |
|
296 | - 'ee_delete_event', |
|
297 | - 'espresso_events_delete_event', |
|
298 | - $item->ID() |
|
299 | - ) |
|
300 | - ) { |
|
301 | - $delete_event_query_args = array( |
|
302 | - 'action' => 'delete_event', |
|
303 | - 'EVT_ID' => $item->ID(), |
|
304 | - ); |
|
305 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
306 | - $delete_event_query_args, |
|
307 | - EVENTS_ADMIN_URL |
|
308 | - ); |
|
309 | - } |
|
310 | - $view_link = get_permalink($item->ID()); |
|
311 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
312 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
313 | - . esc_html__('View', 'event_espresso') |
|
314 | - . '</a>'; |
|
315 | - if ($item->get('status') === 'trash') { |
|
316 | - if ( |
|
317 | - EE_Registry::instance()->CAP->current_user_can( |
|
318 | - 'ee_delete_event', |
|
319 | - 'espresso_events_restore_event', |
|
320 | - $item->ID() |
|
321 | - ) |
|
322 | - ) { |
|
323 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
324 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
325 | - . '">' |
|
326 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
327 | - . '</a>'; |
|
328 | - } |
|
329 | - if ( |
|
330 | - EE_Registry::instance()->CAP->current_user_can( |
|
331 | - 'ee_delete_event', |
|
332 | - 'espresso_events_delete_event', |
|
333 | - $item->ID() |
|
334 | - ) |
|
335 | - ) { |
|
336 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
337 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
338 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
339 | - . '</a>'; |
|
340 | - } |
|
341 | - } else { |
|
342 | - if ( |
|
343 | - EE_Registry::instance()->CAP->current_user_can( |
|
344 | - 'ee_delete_event', |
|
345 | - 'espresso_events_trash_event', |
|
346 | - $item->ID() |
|
347 | - ) |
|
348 | - ) { |
|
349 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
350 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
351 | - . esc_html__('Trash', 'event_espresso') |
|
352 | - . '</a>'; |
|
353 | - } |
|
354 | - } |
|
355 | - return $actions; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @param EE_Event $item |
|
361 | - * @return string |
|
362 | - * @throws EE_Error |
|
363 | - */ |
|
364 | - public function column_author(EE_Event $item) |
|
365 | - { |
|
366 | - // user author info |
|
367 | - $event_author = get_userdata($item->wp_user()); |
|
368 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
369 | - // filter link |
|
370 | - $query_args = array( |
|
371 | - 'action' => 'default', |
|
372 | - 'EVT_wp_user' => $item->wp_user(), |
|
373 | - ); |
|
374 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
375 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
376 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
377 | - . $event_author->display_name |
|
378 | - . '</a>'; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * @param EE_Event $event |
|
384 | - * @return string |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - public function column_event_category(EE_Event $event) |
|
388 | - { |
|
389 | - $event_categories = $event->get_all_event_categories(); |
|
390 | - return implode( |
|
391 | - ', ', |
|
392 | - array_map( |
|
393 | - function (EE_Term $category) { |
|
394 | - return $category->name(); |
|
395 | - }, |
|
396 | - $event_categories |
|
397 | - ) |
|
398 | - ); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @param EE_Event $item |
|
404 | - * @return string |
|
405 | - * @throws EE_Error |
|
406 | - */ |
|
407 | - public function column_venue(EE_Event $item) |
|
408 | - { |
|
409 | - $venue = $item->get_first_related('Venue'); |
|
410 | - return ! empty($venue) |
|
411 | - ? $venue->name() |
|
412 | - : ''; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * @param EE_Event $item |
|
418 | - * @return string |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - public function column_start_date_time(EE_Event $item) |
|
422 | - { |
|
423 | - return $this->_dtt instanceof EE_Datetime |
|
424 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
425 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @param EE_Event $item |
|
431 | - * @return string |
|
432 | - * @throws EE_Error |
|
433 | - */ |
|
434 | - public function column_reg_begins(EE_Event $item) |
|
435 | - { |
|
436 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
437 | - return $reg_start instanceof EE_Ticket |
|
438 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
439 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @param EE_Event $item |
|
445 | - * @return int|string |
|
446 | - * @throws EE_Error |
|
447 | - * @throws InvalidArgumentException |
|
448 | - * @throws InvalidDataTypeException |
|
449 | - * @throws InvalidInterfaceException |
|
450 | - */ |
|
451 | - public function column_attendees(EE_Event $item) |
|
452 | - { |
|
453 | - $attendees_query_args = array( |
|
454 | - 'action' => 'default', |
|
455 | - 'event_id' => $item->ID(), |
|
456 | - ); |
|
457 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
458 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
459 | - return EE_Registry::instance()->CAP->current_user_can( |
|
460 | - 'ee_read_event', |
|
461 | - 'espresso_registrations_view_registration', |
|
462 | - $item->ID() |
|
463 | - ) |
|
464 | - && EE_Registry::instance()->CAP->current_user_can( |
|
465 | - 'ee_read_registrations', |
|
466 | - 'espresso_registrations_view_registration' |
|
467 | - ) |
|
468 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
469 | - : $registered_attendees; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @param EE_Event $item |
|
475 | - * @return float |
|
476 | - * @throws EE_Error |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidDataTypeException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - */ |
|
481 | - public function column_tkts_sold(EE_Event $item) |
|
482 | - { |
|
483 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @param EE_Event $item |
|
489 | - * @return string |
|
490 | - * @throws EE_Error |
|
491 | - * @throws InvalidArgumentException |
|
492 | - * @throws InvalidDataTypeException |
|
493 | - * @throws InvalidInterfaceException |
|
494 | - */ |
|
495 | - public function column_actions(EE_Event $item) |
|
496 | - { |
|
497 | - // todo: remove when attendees is active |
|
498 | - if (! defined('REG_ADMIN_URL')) { |
|
499 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
500 | - } |
|
501 | - $action_links = array(); |
|
502 | - $view_link = get_permalink($item->ID()); |
|
503 | - $action_links[] = '<a href="' . $view_link . '"' |
|
504 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
505 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
506 | - if ( |
|
507 | - EE_Registry::instance()->CAP->current_user_can( |
|
508 | - 'ee_edit_event', |
|
509 | - 'espresso_events_edit', |
|
510 | - $item->ID() |
|
511 | - ) |
|
512 | - ) { |
|
513 | - $edit_query_args = array( |
|
514 | - 'action' => 'edit', |
|
515 | - 'post' => $item->ID(), |
|
516 | - ); |
|
517 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
518 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
519 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
520 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
521 | - . '</a>'; |
|
522 | - } |
|
523 | - if ( |
|
524 | - EE_Registry::instance()->CAP->current_user_can( |
|
525 | - 'ee_read_registrations', |
|
526 | - 'espresso_registrations_view_registration' |
|
527 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
528 | - 'ee_read_event', |
|
529 | - 'espresso_registrations_view_registration', |
|
530 | - $item->ID() |
|
531 | - ) |
|
532 | - ) { |
|
533 | - $attendees_query_args = array( |
|
534 | - 'action' => 'default', |
|
535 | - 'event_id' => $item->ID(), |
|
536 | - ); |
|
537 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
538 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
539 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
540 | - . '<div class="dashicons dashicons-groups"></div>' |
|
541 | - . '</a>'; |
|
542 | - } |
|
543 | - $action_links = apply_filters( |
|
544 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
545 | - $action_links, |
|
546 | - $item |
|
547 | - ); |
|
548 | - return $this->_action_string( |
|
549 | - implode("\n\t", $action_links), |
|
550 | - $item, |
|
551 | - 'div' |
|
552 | - ); |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Helper for adding columns conditionally |
|
558 | - * |
|
559 | - * @throws EE_Error |
|
560 | - * @throws InvalidArgumentException |
|
561 | - * @throws InvalidDataTypeException |
|
562 | - * @throws InvalidInterfaceException |
|
563 | - */ |
|
564 | - private function addConditionalColumns() |
|
565 | - { |
|
566 | - $event_category_count = EEM_Term::instance()->count( |
|
567 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
568 | - ); |
|
569 | - if ($event_category_count === 0) { |
|
570 | - return; |
|
571 | - } |
|
572 | - $column_array = []; |
|
573 | - foreach ($this->_columns as $column => $column_label) { |
|
574 | - $column_array[ $column ] = $column_label; |
|
575 | - if ($column === 'venue') { |
|
576 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
577 | - } |
|
578 | - } |
|
579 | - $this->_columns = $column_array; |
|
580 | - } |
|
18 | + /** |
|
19 | + * @var EE_Datetime |
|
20 | + */ |
|
21 | + private $_dtt; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Initial setup of data properties for the list table. |
|
26 | + */ |
|
27 | + protected function _setup_data() |
|
28 | + { |
|
29 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
30 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Set up of additional properties for the list table. |
|
36 | + */ |
|
37 | + protected function _set_properties() |
|
38 | + { |
|
39 | + $this->_wp_list_args = array( |
|
40 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
41 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
42 | + 'ajax' => true, // for now |
|
43 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
44 | + ); |
|
45 | + $this->_columns = array( |
|
46 | + 'cb' => '<input type="checkbox" />', |
|
47 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
48 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
49 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
50 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
51 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
52 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
53 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
54 | + . '<span class="screen-reader-text">' |
|
55 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
56 | + . '</span>' |
|
57 | + . '</span>', |
|
58 | + // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
59 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
60 | + ); |
|
61 | + $this->addConditionalColumns(); |
|
62 | + $this->_sortable_columns = array( |
|
63 | + 'id' => array('EVT_ID' => true), |
|
64 | + 'name' => array('EVT_name' => false), |
|
65 | + 'author' => array('EVT_wp_user' => false), |
|
66 | + 'venue' => array('Venue.VNU_name' => false), |
|
67 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
68 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
69 | + ); |
|
70 | + |
|
71 | + $this->_primary_column = 'id'; |
|
72 | + $this->_hidden_columns = array('author', 'event_category'); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + protected function _get_table_filters() |
|
80 | + { |
|
81 | + return array(); // no filters with decaf |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Setup of views properties. |
|
87 | + * |
|
88 | + * @throws InvalidDataTypeException |
|
89 | + * @throws InvalidInterfaceException |
|
90 | + * @throws InvalidArgumentException |
|
91 | + */ |
|
92 | + protected function _add_view_counts() |
|
93 | + { |
|
94 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
95 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
96 | + if ( |
|
97 | + EE_Registry::instance()->CAP->current_user_can( |
|
98 | + 'ee_delete_events', |
|
99 | + 'espresso_events_trash_events' |
|
100 | + ) |
|
101 | + ) { |
|
102 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param EE_Event $item |
|
109 | + * @return string |
|
110 | + * @throws EE_Error |
|
111 | + */ |
|
112 | + protected function _get_row_class($item) |
|
113 | + { |
|
114 | + $class = parent::_get_row_class($item); |
|
115 | + // add status class |
|
116 | + $class .= $item instanceof EE_Event |
|
117 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
118 | + : ''; |
|
119 | + if ($this->_has_checkbox_column) { |
|
120 | + $class .= ' has-checkbox-column'; |
|
121 | + } |
|
122 | + return $class; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param EE_Event $item |
|
128 | + * @return string |
|
129 | + * @throws EE_Error |
|
130 | + */ |
|
131 | + public function column_status(EE_Event $item) |
|
132 | + { |
|
133 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
134 | + . $item->get_active_status() |
|
135 | + . '"></span>'; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param EE_Event $item |
|
141 | + * @return string |
|
142 | + * @throws EE_Error |
|
143 | + */ |
|
144 | + public function column_cb($item) |
|
145 | + { |
|
146 | + if (! $item instanceof EE_Event) { |
|
147 | + return ''; |
|
148 | + } |
|
149 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
150 | + return sprintf( |
|
151 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
152 | + $item->ID() |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param EE_Event $item |
|
159 | + * @return mixed|string |
|
160 | + * @throws EE_Error |
|
161 | + */ |
|
162 | + public function column_id(EE_Event $item) |
|
163 | + { |
|
164 | + $content = $item->ID(); |
|
165 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
166 | + return $content; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param EE_Event $item |
|
172 | + * @return string |
|
173 | + * @throws EE_Error |
|
174 | + * @throws InvalidArgumentException |
|
175 | + * @throws InvalidDataTypeException |
|
176 | + * @throws InvalidInterfaceException |
|
177 | + */ |
|
178 | + public function column_name(EE_Event $item) |
|
179 | + { |
|
180 | + $edit_query_args = array( |
|
181 | + 'action' => 'edit', |
|
182 | + 'post' => $item->ID(), |
|
183 | + ); |
|
184 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
185 | + $actions = $this->_column_name_action_setup($item); |
|
186 | + $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
187 | + $content = '<strong><a class="row-title" href="' |
|
188 | + . $edit_link . '">' |
|
189 | + . $item->name() |
|
190 | + . '</a></strong>' |
|
191 | + . $status; |
|
192 | + $content .= '<br><span class="ee-status-text-small">' |
|
193 | + . EEH_Template::pretty_status( |
|
194 | + $item->get_active_status(), |
|
195 | + false, |
|
196 | + 'sentence' |
|
197 | + ) |
|
198 | + . '</span>'; |
|
199 | + $content .= $this->row_actions($actions); |
|
200 | + return $content; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Just a method for setting up the actions for the name column |
|
206 | + * |
|
207 | + * @param EE_Event $item |
|
208 | + * @return array array of actions |
|
209 | + * @throws EE_Error |
|
210 | + * @throws InvalidArgumentException |
|
211 | + * @throws InvalidDataTypeException |
|
212 | + * @throws InvalidInterfaceException |
|
213 | + */ |
|
214 | + protected function _column_name_action_setup(EE_Event $item) |
|
215 | + { |
|
216 | + // todo: remove when attendees is active |
|
217 | + if (! defined('REG_ADMIN_URL')) { |
|
218 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
219 | + } |
|
220 | + $actions = array(); |
|
221 | + $restore_event_link = ''; |
|
222 | + $delete_event_link = ''; |
|
223 | + $trash_event_link = ''; |
|
224 | + if ( |
|
225 | + EE_Registry::instance()->CAP->current_user_can( |
|
226 | + 'ee_edit_event', |
|
227 | + 'espresso_events_edit', |
|
228 | + $item->ID() |
|
229 | + ) |
|
230 | + ) { |
|
231 | + $edit_query_args = array( |
|
232 | + 'action' => 'edit', |
|
233 | + 'post' => $item->ID(), |
|
234 | + ); |
|
235 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
236 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
237 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
238 | + . esc_html__('Edit', 'event_espresso') |
|
239 | + . '</a>'; |
|
240 | + } |
|
241 | + if ( |
|
242 | + EE_Registry::instance()->CAP->current_user_can( |
|
243 | + 'ee_read_registrations', |
|
244 | + 'espresso_registrations_view_registration' |
|
245 | + ) |
|
246 | + && EE_Registry::instance()->CAP->current_user_can( |
|
247 | + 'ee_read_event', |
|
248 | + 'espresso_registrations_view_registration', |
|
249 | + $item->ID() |
|
250 | + ) |
|
251 | + ) { |
|
252 | + $attendees_query_args = array( |
|
253 | + 'action' => 'default', |
|
254 | + 'event_id' => $item->ID(), |
|
255 | + ); |
|
256 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
257 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
258 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
259 | + . esc_html__('Registrations', 'event_espresso') |
|
260 | + . '</a>'; |
|
261 | + } |
|
262 | + if ( |
|
263 | + EE_Registry::instance()->CAP->current_user_can( |
|
264 | + 'ee_delete_event', |
|
265 | + 'espresso_events_trash_event', |
|
266 | + $item->ID() |
|
267 | + ) |
|
268 | + ) { |
|
269 | + $trash_event_query_args = array( |
|
270 | + 'action' => 'trash_event', |
|
271 | + 'EVT_ID' => $item->ID(), |
|
272 | + ); |
|
273 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
274 | + $trash_event_query_args, |
|
275 | + EVENTS_ADMIN_URL |
|
276 | + ); |
|
277 | + } |
|
278 | + if ( |
|
279 | + EE_Registry::instance()->CAP->current_user_can( |
|
280 | + 'ee_delete_event', |
|
281 | + 'espresso_events_restore_event', |
|
282 | + $item->ID() |
|
283 | + ) |
|
284 | + ) { |
|
285 | + $restore_event_query_args = array( |
|
286 | + 'action' => 'restore_event', |
|
287 | + 'EVT_ID' => $item->ID(), |
|
288 | + ); |
|
289 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
290 | + $restore_event_query_args, |
|
291 | + EVENTS_ADMIN_URL |
|
292 | + ); |
|
293 | + } |
|
294 | + if ( |
|
295 | + EE_Registry::instance()->CAP->current_user_can( |
|
296 | + 'ee_delete_event', |
|
297 | + 'espresso_events_delete_event', |
|
298 | + $item->ID() |
|
299 | + ) |
|
300 | + ) { |
|
301 | + $delete_event_query_args = array( |
|
302 | + 'action' => 'delete_event', |
|
303 | + 'EVT_ID' => $item->ID(), |
|
304 | + ); |
|
305 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
306 | + $delete_event_query_args, |
|
307 | + EVENTS_ADMIN_URL |
|
308 | + ); |
|
309 | + } |
|
310 | + $view_link = get_permalink($item->ID()); |
|
311 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
312 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
313 | + . esc_html__('View', 'event_espresso') |
|
314 | + . '</a>'; |
|
315 | + if ($item->get('status') === 'trash') { |
|
316 | + if ( |
|
317 | + EE_Registry::instance()->CAP->current_user_can( |
|
318 | + 'ee_delete_event', |
|
319 | + 'espresso_events_restore_event', |
|
320 | + $item->ID() |
|
321 | + ) |
|
322 | + ) { |
|
323 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
324 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
325 | + . '">' |
|
326 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
327 | + . '</a>'; |
|
328 | + } |
|
329 | + if ( |
|
330 | + EE_Registry::instance()->CAP->current_user_can( |
|
331 | + 'ee_delete_event', |
|
332 | + 'espresso_events_delete_event', |
|
333 | + $item->ID() |
|
334 | + ) |
|
335 | + ) { |
|
336 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
337 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
338 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
339 | + . '</a>'; |
|
340 | + } |
|
341 | + } else { |
|
342 | + if ( |
|
343 | + EE_Registry::instance()->CAP->current_user_can( |
|
344 | + 'ee_delete_event', |
|
345 | + 'espresso_events_trash_event', |
|
346 | + $item->ID() |
|
347 | + ) |
|
348 | + ) { |
|
349 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
350 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
351 | + . esc_html__('Trash', 'event_espresso') |
|
352 | + . '</a>'; |
|
353 | + } |
|
354 | + } |
|
355 | + return $actions; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @param EE_Event $item |
|
361 | + * @return string |
|
362 | + * @throws EE_Error |
|
363 | + */ |
|
364 | + public function column_author(EE_Event $item) |
|
365 | + { |
|
366 | + // user author info |
|
367 | + $event_author = get_userdata($item->wp_user()); |
|
368 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
369 | + // filter link |
|
370 | + $query_args = array( |
|
371 | + 'action' => 'default', |
|
372 | + 'EVT_wp_user' => $item->wp_user(), |
|
373 | + ); |
|
374 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
375 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
376 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
377 | + . $event_author->display_name |
|
378 | + . '</a>'; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * @param EE_Event $event |
|
384 | + * @return string |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + public function column_event_category(EE_Event $event) |
|
388 | + { |
|
389 | + $event_categories = $event->get_all_event_categories(); |
|
390 | + return implode( |
|
391 | + ', ', |
|
392 | + array_map( |
|
393 | + function (EE_Term $category) { |
|
394 | + return $category->name(); |
|
395 | + }, |
|
396 | + $event_categories |
|
397 | + ) |
|
398 | + ); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @param EE_Event $item |
|
404 | + * @return string |
|
405 | + * @throws EE_Error |
|
406 | + */ |
|
407 | + public function column_venue(EE_Event $item) |
|
408 | + { |
|
409 | + $venue = $item->get_first_related('Venue'); |
|
410 | + return ! empty($venue) |
|
411 | + ? $venue->name() |
|
412 | + : ''; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * @param EE_Event $item |
|
418 | + * @return string |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + public function column_start_date_time(EE_Event $item) |
|
422 | + { |
|
423 | + return $this->_dtt instanceof EE_Datetime |
|
424 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
425 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @param EE_Event $item |
|
431 | + * @return string |
|
432 | + * @throws EE_Error |
|
433 | + */ |
|
434 | + public function column_reg_begins(EE_Event $item) |
|
435 | + { |
|
436 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
437 | + return $reg_start instanceof EE_Ticket |
|
438 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
439 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @param EE_Event $item |
|
445 | + * @return int|string |
|
446 | + * @throws EE_Error |
|
447 | + * @throws InvalidArgumentException |
|
448 | + * @throws InvalidDataTypeException |
|
449 | + * @throws InvalidInterfaceException |
|
450 | + */ |
|
451 | + public function column_attendees(EE_Event $item) |
|
452 | + { |
|
453 | + $attendees_query_args = array( |
|
454 | + 'action' => 'default', |
|
455 | + 'event_id' => $item->ID(), |
|
456 | + ); |
|
457 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
458 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
459 | + return EE_Registry::instance()->CAP->current_user_can( |
|
460 | + 'ee_read_event', |
|
461 | + 'espresso_registrations_view_registration', |
|
462 | + $item->ID() |
|
463 | + ) |
|
464 | + && EE_Registry::instance()->CAP->current_user_can( |
|
465 | + 'ee_read_registrations', |
|
466 | + 'espresso_registrations_view_registration' |
|
467 | + ) |
|
468 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
469 | + : $registered_attendees; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @param EE_Event $item |
|
475 | + * @return float |
|
476 | + * @throws EE_Error |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidDataTypeException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + */ |
|
481 | + public function column_tkts_sold(EE_Event $item) |
|
482 | + { |
|
483 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @param EE_Event $item |
|
489 | + * @return string |
|
490 | + * @throws EE_Error |
|
491 | + * @throws InvalidArgumentException |
|
492 | + * @throws InvalidDataTypeException |
|
493 | + * @throws InvalidInterfaceException |
|
494 | + */ |
|
495 | + public function column_actions(EE_Event $item) |
|
496 | + { |
|
497 | + // todo: remove when attendees is active |
|
498 | + if (! defined('REG_ADMIN_URL')) { |
|
499 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
500 | + } |
|
501 | + $action_links = array(); |
|
502 | + $view_link = get_permalink($item->ID()); |
|
503 | + $action_links[] = '<a href="' . $view_link . '"' |
|
504 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
505 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
506 | + if ( |
|
507 | + EE_Registry::instance()->CAP->current_user_can( |
|
508 | + 'ee_edit_event', |
|
509 | + 'espresso_events_edit', |
|
510 | + $item->ID() |
|
511 | + ) |
|
512 | + ) { |
|
513 | + $edit_query_args = array( |
|
514 | + 'action' => 'edit', |
|
515 | + 'post' => $item->ID(), |
|
516 | + ); |
|
517 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
518 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
519 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
520 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
521 | + . '</a>'; |
|
522 | + } |
|
523 | + if ( |
|
524 | + EE_Registry::instance()->CAP->current_user_can( |
|
525 | + 'ee_read_registrations', |
|
526 | + 'espresso_registrations_view_registration' |
|
527 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
528 | + 'ee_read_event', |
|
529 | + 'espresso_registrations_view_registration', |
|
530 | + $item->ID() |
|
531 | + ) |
|
532 | + ) { |
|
533 | + $attendees_query_args = array( |
|
534 | + 'action' => 'default', |
|
535 | + 'event_id' => $item->ID(), |
|
536 | + ); |
|
537 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
538 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
539 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
540 | + . '<div class="dashicons dashicons-groups"></div>' |
|
541 | + . '</a>'; |
|
542 | + } |
|
543 | + $action_links = apply_filters( |
|
544 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
545 | + $action_links, |
|
546 | + $item |
|
547 | + ); |
|
548 | + return $this->_action_string( |
|
549 | + implode("\n\t", $action_links), |
|
550 | + $item, |
|
551 | + 'div' |
|
552 | + ); |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Helper for adding columns conditionally |
|
558 | + * |
|
559 | + * @throws EE_Error |
|
560 | + * @throws InvalidArgumentException |
|
561 | + * @throws InvalidDataTypeException |
|
562 | + * @throws InvalidInterfaceException |
|
563 | + */ |
|
564 | + private function addConditionalColumns() |
|
565 | + { |
|
566 | + $event_category_count = EEM_Term::instance()->count( |
|
567 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
568 | + ); |
|
569 | + if ($event_category_count === 0) { |
|
570 | + return; |
|
571 | + } |
|
572 | + $column_array = []; |
|
573 | + foreach ($this->_columns as $column => $column_label) { |
|
574 | + $column_array[ $column ] = $column_label; |
|
575 | + if ($column === 'venue') { |
|
576 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
577 | + } |
|
578 | + } |
|
579 | + $this->_columns = $column_array; |
|
580 | + } |
|
581 | 581 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | |
277 | 277 | /** |
278 | - * @param $string |
|
278 | + * @param string $string |
|
279 | 279 | * @return void |
280 | 280 | */ |
281 | 281 | public function add_output($string) |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | |
329 | 329 | /** |
330 | - * @return mixed |
|
330 | + * @return boolean |
|
331 | 331 | */ |
332 | 332 | public function is_espresso_page() |
333 | 333 | { |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | /** |
390 | 390 | * remove param |
391 | 391 | * |
392 | - * @param $key |
|
392 | + * @param string $key |
|
393 | 393 | * @return void |
394 | 394 | */ |
395 | 395 | public function un_set($key) |
@@ -12,369 +12,369 @@ |
||
12 | 12 | final class EE_Request_Handler implements InterminableInterface |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @var EE_Request $request |
|
17 | - */ |
|
18 | - private $request; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var array $_notice |
|
22 | - */ |
|
23 | - private $_notice = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * rendered output to be returned to WP |
|
27 | - * |
|
28 | - * @var string $_output |
|
29 | - */ |
|
30 | - private $_output = ''; |
|
31 | - |
|
32 | - /** |
|
33 | - * whether current request is via AJAX |
|
34 | - * |
|
35 | - * @var boolean $ajax |
|
36 | - */ |
|
37 | - public $ajax = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * whether current request is via AJAX from the frontend of the site |
|
41 | - * |
|
42 | - * @var boolean $front_ajax |
|
43 | - */ |
|
44 | - public $front_ajax = false; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param EE_Request $request |
|
49 | - */ |
|
50 | - public function __construct(EE_Request $request) |
|
51 | - { |
|
52 | - $this->request = $request; |
|
53 | - $this->ajax = $this->request->ajax; |
|
54 | - $this->front_ajax = $this->request->front_ajax; |
|
55 | - do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param WP $wp |
|
61 | - * @return void |
|
62 | - * @throws EE_Error |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public function parse_request($wp = null) |
|
66 | - { |
|
67 | - // if somebody forgot to provide us with WP, that's ok because its global |
|
68 | - if (! $wp instanceof WP) { |
|
69 | - global $wp; |
|
70 | - } |
|
71 | - $this->set_request_vars($wp); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @param WP $wp |
|
77 | - * @return void |
|
78 | - * @throws EE_Error |
|
79 | - * @throws ReflectionException |
|
80 | - */ |
|
81 | - public function set_request_vars($wp = null) |
|
82 | - { |
|
83 | - if (! is_admin()) { |
|
84 | - // set request post_id |
|
85 | - $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
|
86 | - // set request post name |
|
87 | - $this->request->set('post_name', $this->get_post_name_from_request($wp)); |
|
88 | - // set request post_type |
|
89 | - $this->request->set('post_type', $this->get_post_type_from_request($wp)); |
|
90 | - // true or false ? is this page being used by EE ? |
|
91 | - $this->set_espresso_page(); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param WP $wp |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - public function get_post_id_from_request($wp = null) |
|
101 | - { |
|
102 | - if (! $wp instanceof WP) { |
|
103 | - global $wp; |
|
104 | - } |
|
105 | - $post_id = null; |
|
106 | - if (isset($wp->query_vars['p'])) { |
|
107 | - $post_id = $wp->query_vars['p']; |
|
108 | - } |
|
109 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
110 | - $post_id = $wp->query_vars['page_id']; |
|
111 | - } |
|
112 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
113 | - $post_id = basename($wp->request); |
|
114 | - } |
|
115 | - return $post_id; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param WP $wp |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_post_name_from_request($wp = null) |
|
124 | - { |
|
125 | - if (! $wp instanceof WP) { |
|
126 | - global $wp; |
|
127 | - } |
|
128 | - $post_name = null; |
|
129 | - if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
130 | - $post_name = $wp->query_vars['name']; |
|
131 | - } |
|
132 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
133 | - $post_name = $wp->query_vars['pagename']; |
|
134 | - } |
|
135 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
136 | - $possible_post_name = basename($wp->request); |
|
137 | - if (! is_numeric($possible_post_name)) { |
|
138 | - /** @type WPDB $wpdb */ |
|
139 | - global $wpdb; |
|
140 | - $SQL = |
|
141 | - "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s"; |
|
142 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
143 | - if ($possible_post_name) { |
|
144 | - $post_name = $possible_post_name; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - if (! $post_name && $this->get('post_id')) { |
|
149 | - /** @type WPDB $wpdb */ |
|
150 | - global $wpdb; |
|
151 | - $SQL = |
|
152 | - "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d"; |
|
153 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
154 | - if ($possible_post_name) { |
|
155 | - $post_name = $possible_post_name; |
|
156 | - } |
|
157 | - } |
|
158 | - return $post_name; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param WP $wp |
|
164 | - * @return mixed |
|
165 | - */ |
|
166 | - public function get_post_type_from_request($wp = null) |
|
167 | - { |
|
168 | - if (! $wp instanceof WP) { |
|
169 | - global $wp; |
|
170 | - } |
|
171 | - return isset($wp->query_vars['post_type']) |
|
172 | - ? $wp->query_vars['post_type'] |
|
173 | - : null; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Just a helper method for getting the url for the displayed page. |
|
179 | - * |
|
180 | - * @param WP $wp |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public function get_current_page_permalink($wp = null) |
|
184 | - { |
|
185 | - $post_id = $this->get_post_id_from_request($wp); |
|
186 | - if ($post_id) { |
|
187 | - $current_page_permalink = get_permalink($post_id); |
|
188 | - } else { |
|
189 | - if (! $wp instanceof WP) { |
|
190 | - global $wp; |
|
191 | - } |
|
192 | - if ($wp->request) { |
|
193 | - $current_page_permalink = site_url($wp->request); |
|
194 | - } else { |
|
195 | - $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
196 | - } |
|
197 | - } |
|
198 | - return $current_page_permalink; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @return bool |
|
204 | - * @throws EE_Error |
|
205 | - * @throws ReflectionException |
|
206 | - */ |
|
207 | - public function test_for_espresso_page() |
|
208 | - { |
|
209 | - global $wp; |
|
210 | - /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
211 | - $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
212 | - $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
213 | - if (is_array($espresso_CPT_taxonomies)) { |
|
214 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
215 | - if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
216 | - return true; |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
220 | - // load espresso CPT endpoints |
|
221 | - $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
222 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
223 | - $post_types = (array) $this->get('post_type'); |
|
224 | - foreach ($post_types as $post_type) { |
|
225 | - // was a post name passed ? |
|
226 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
227 | - // kk we know this is an espresso page, but is it a specific post ? |
|
228 | - if (! $this->get('post_name')) { |
|
229 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
230 | - $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
231 | - ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
232 | - : ''; |
|
233 | - // if the post type matches on of our then set the endpoint |
|
234 | - if ($post_name) { |
|
235 | - $this->set('post_name', $post_name); |
|
236 | - } |
|
237 | - } |
|
238 | - return true; |
|
239 | - } |
|
240 | - } |
|
241 | - return false; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @param $key |
|
246 | - * @param $value |
|
247 | - * @return void |
|
248 | - */ |
|
249 | - public function set_notice($key, $value) |
|
250 | - { |
|
251 | - $this->_notice[ $key ] = $value; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param $key |
|
257 | - * @return mixed |
|
258 | - */ |
|
259 | - public function get_notice($key) |
|
260 | - { |
|
261 | - return isset($this->_notice[ $key ]) |
|
262 | - ? $this->_notice[ $key ] |
|
263 | - : null; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @param $string |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - public function add_output($string) |
|
272 | - { |
|
273 | - $this->_output .= $string; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function get_output() |
|
281 | - { |
|
282 | - return $this->_output; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param $item |
|
288 | - * @param $key |
|
289 | - */ |
|
290 | - public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
291 | - { |
|
292 | - $item = strpos($item, 'email') !== false |
|
293 | - ? sanitize_email($item) |
|
294 | - : sanitize_text_field($item); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @param null|bool $value |
|
300 | - * @return void |
|
301 | - * @throws EE_Error |
|
302 | - * @throws ReflectionException |
|
303 | - */ |
|
304 | - public function set_espresso_page($value = null) |
|
305 | - { |
|
306 | - $this->request->set( |
|
307 | - 'is_espresso_page', |
|
308 | - ! empty($value) |
|
309 | - ? $value |
|
310 | - : $this->test_for_espresso_page() |
|
311 | - ); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * @return mixed |
|
317 | - */ |
|
318 | - public function is_espresso_page() |
|
319 | - { |
|
320 | - return $this->request->is_set('is_espresso_page'); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * returns contents of $_REQUEST |
|
326 | - * |
|
327 | - * @return array |
|
328 | - */ |
|
329 | - public function params() |
|
330 | - { |
|
331 | - return $this->request->params(); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param $key |
|
337 | - * @param $value |
|
338 | - * @param bool $override_ee |
|
339 | - * @return void |
|
340 | - */ |
|
341 | - public function set($key, $value, $override_ee = false) |
|
342 | - { |
|
343 | - $this->request->set($key, $value, $override_ee); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @param $key |
|
349 | - * @param null $default |
|
350 | - * @return mixed |
|
351 | - */ |
|
352 | - public function get($key, $default = null) |
|
353 | - { |
|
354 | - return $this->request->get($key, $default); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * check if param exists |
|
360 | - * |
|
361 | - * @param $key |
|
362 | - * @return boolean |
|
363 | - */ |
|
364 | - public function is_set($key) |
|
365 | - { |
|
366 | - return $this->request->is_set($key); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * remove param |
|
372 | - * |
|
373 | - * @param $key |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function un_set($key) |
|
377 | - { |
|
378 | - $this->request->un_set($key); |
|
379 | - } |
|
15 | + /** |
|
16 | + * @var EE_Request $request |
|
17 | + */ |
|
18 | + private $request; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var array $_notice |
|
22 | + */ |
|
23 | + private $_notice = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * rendered output to be returned to WP |
|
27 | + * |
|
28 | + * @var string $_output |
|
29 | + */ |
|
30 | + private $_output = ''; |
|
31 | + |
|
32 | + /** |
|
33 | + * whether current request is via AJAX |
|
34 | + * |
|
35 | + * @var boolean $ajax |
|
36 | + */ |
|
37 | + public $ajax = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * whether current request is via AJAX from the frontend of the site |
|
41 | + * |
|
42 | + * @var boolean $front_ajax |
|
43 | + */ |
|
44 | + public $front_ajax = false; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param EE_Request $request |
|
49 | + */ |
|
50 | + public function __construct(EE_Request $request) |
|
51 | + { |
|
52 | + $this->request = $request; |
|
53 | + $this->ajax = $this->request->ajax; |
|
54 | + $this->front_ajax = $this->request->front_ajax; |
|
55 | + do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param WP $wp |
|
61 | + * @return void |
|
62 | + * @throws EE_Error |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public function parse_request($wp = null) |
|
66 | + { |
|
67 | + // if somebody forgot to provide us with WP, that's ok because its global |
|
68 | + if (! $wp instanceof WP) { |
|
69 | + global $wp; |
|
70 | + } |
|
71 | + $this->set_request_vars($wp); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @param WP $wp |
|
77 | + * @return void |
|
78 | + * @throws EE_Error |
|
79 | + * @throws ReflectionException |
|
80 | + */ |
|
81 | + public function set_request_vars($wp = null) |
|
82 | + { |
|
83 | + if (! is_admin()) { |
|
84 | + // set request post_id |
|
85 | + $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
|
86 | + // set request post name |
|
87 | + $this->request->set('post_name', $this->get_post_name_from_request($wp)); |
|
88 | + // set request post_type |
|
89 | + $this->request->set('post_type', $this->get_post_type_from_request($wp)); |
|
90 | + // true or false ? is this page being used by EE ? |
|
91 | + $this->set_espresso_page(); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param WP $wp |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + public function get_post_id_from_request($wp = null) |
|
101 | + { |
|
102 | + if (! $wp instanceof WP) { |
|
103 | + global $wp; |
|
104 | + } |
|
105 | + $post_id = null; |
|
106 | + if (isset($wp->query_vars['p'])) { |
|
107 | + $post_id = $wp->query_vars['p']; |
|
108 | + } |
|
109 | + if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
110 | + $post_id = $wp->query_vars['page_id']; |
|
111 | + } |
|
112 | + if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
113 | + $post_id = basename($wp->request); |
|
114 | + } |
|
115 | + return $post_id; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param WP $wp |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_post_name_from_request($wp = null) |
|
124 | + { |
|
125 | + if (! $wp instanceof WP) { |
|
126 | + global $wp; |
|
127 | + } |
|
128 | + $post_name = null; |
|
129 | + if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
130 | + $post_name = $wp->query_vars['name']; |
|
131 | + } |
|
132 | + if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
133 | + $post_name = $wp->query_vars['pagename']; |
|
134 | + } |
|
135 | + if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
136 | + $possible_post_name = basename($wp->request); |
|
137 | + if (! is_numeric($possible_post_name)) { |
|
138 | + /** @type WPDB $wpdb */ |
|
139 | + global $wpdb; |
|
140 | + $SQL = |
|
141 | + "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s"; |
|
142 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
143 | + if ($possible_post_name) { |
|
144 | + $post_name = $possible_post_name; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + if (! $post_name && $this->get('post_id')) { |
|
149 | + /** @type WPDB $wpdb */ |
|
150 | + global $wpdb; |
|
151 | + $SQL = |
|
152 | + "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d"; |
|
153 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
154 | + if ($possible_post_name) { |
|
155 | + $post_name = $possible_post_name; |
|
156 | + } |
|
157 | + } |
|
158 | + return $post_name; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param WP $wp |
|
164 | + * @return mixed |
|
165 | + */ |
|
166 | + public function get_post_type_from_request($wp = null) |
|
167 | + { |
|
168 | + if (! $wp instanceof WP) { |
|
169 | + global $wp; |
|
170 | + } |
|
171 | + return isset($wp->query_vars['post_type']) |
|
172 | + ? $wp->query_vars['post_type'] |
|
173 | + : null; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Just a helper method for getting the url for the displayed page. |
|
179 | + * |
|
180 | + * @param WP $wp |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function get_current_page_permalink($wp = null) |
|
184 | + { |
|
185 | + $post_id = $this->get_post_id_from_request($wp); |
|
186 | + if ($post_id) { |
|
187 | + $current_page_permalink = get_permalink($post_id); |
|
188 | + } else { |
|
189 | + if (! $wp instanceof WP) { |
|
190 | + global $wp; |
|
191 | + } |
|
192 | + if ($wp->request) { |
|
193 | + $current_page_permalink = site_url($wp->request); |
|
194 | + } else { |
|
195 | + $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
196 | + } |
|
197 | + } |
|
198 | + return $current_page_permalink; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @return bool |
|
204 | + * @throws EE_Error |
|
205 | + * @throws ReflectionException |
|
206 | + */ |
|
207 | + public function test_for_espresso_page() |
|
208 | + { |
|
209 | + global $wp; |
|
210 | + /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
211 | + $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
212 | + $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
213 | + if (is_array($espresso_CPT_taxonomies)) { |
|
214 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
215 | + if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
216 | + return true; |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | + // load espresso CPT endpoints |
|
221 | + $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
222 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
223 | + $post_types = (array) $this->get('post_type'); |
|
224 | + foreach ($post_types as $post_type) { |
|
225 | + // was a post name passed ? |
|
226 | + if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
227 | + // kk we know this is an espresso page, but is it a specific post ? |
|
228 | + if (! $this->get('post_name')) { |
|
229 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
230 | + $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
231 | + ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
232 | + : ''; |
|
233 | + // if the post type matches on of our then set the endpoint |
|
234 | + if ($post_name) { |
|
235 | + $this->set('post_name', $post_name); |
|
236 | + } |
|
237 | + } |
|
238 | + return true; |
|
239 | + } |
|
240 | + } |
|
241 | + return false; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @param $key |
|
246 | + * @param $value |
|
247 | + * @return void |
|
248 | + */ |
|
249 | + public function set_notice($key, $value) |
|
250 | + { |
|
251 | + $this->_notice[ $key ] = $value; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param $key |
|
257 | + * @return mixed |
|
258 | + */ |
|
259 | + public function get_notice($key) |
|
260 | + { |
|
261 | + return isset($this->_notice[ $key ]) |
|
262 | + ? $this->_notice[ $key ] |
|
263 | + : null; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @param $string |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + public function add_output($string) |
|
272 | + { |
|
273 | + $this->_output .= $string; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function get_output() |
|
281 | + { |
|
282 | + return $this->_output; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param $item |
|
288 | + * @param $key |
|
289 | + */ |
|
290 | + public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
291 | + { |
|
292 | + $item = strpos($item, 'email') !== false |
|
293 | + ? sanitize_email($item) |
|
294 | + : sanitize_text_field($item); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @param null|bool $value |
|
300 | + * @return void |
|
301 | + * @throws EE_Error |
|
302 | + * @throws ReflectionException |
|
303 | + */ |
|
304 | + public function set_espresso_page($value = null) |
|
305 | + { |
|
306 | + $this->request->set( |
|
307 | + 'is_espresso_page', |
|
308 | + ! empty($value) |
|
309 | + ? $value |
|
310 | + : $this->test_for_espresso_page() |
|
311 | + ); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * @return mixed |
|
317 | + */ |
|
318 | + public function is_espresso_page() |
|
319 | + { |
|
320 | + return $this->request->is_set('is_espresso_page'); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * returns contents of $_REQUEST |
|
326 | + * |
|
327 | + * @return array |
|
328 | + */ |
|
329 | + public function params() |
|
330 | + { |
|
331 | + return $this->request->params(); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param $key |
|
337 | + * @param $value |
|
338 | + * @param bool $override_ee |
|
339 | + * @return void |
|
340 | + */ |
|
341 | + public function set($key, $value, $override_ee = false) |
|
342 | + { |
|
343 | + $this->request->set($key, $value, $override_ee); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @param $key |
|
349 | + * @param null $default |
|
350 | + * @return mixed |
|
351 | + */ |
|
352 | + public function get($key, $default = null) |
|
353 | + { |
|
354 | + return $this->request->get($key, $default); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * check if param exists |
|
360 | + * |
|
361 | + * @param $key |
|
362 | + * @return boolean |
|
363 | + */ |
|
364 | + public function is_set($key) |
|
365 | + { |
|
366 | + return $this->request->is_set($key); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * remove param |
|
372 | + * |
|
373 | + * @param $key |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function un_set($key) |
|
377 | + { |
|
378 | + $this->request->un_set($key); |
|
379 | + } |
|
380 | 380 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public function parse_request($wp = null) |
66 | 66 | { |
67 | 67 | // if somebody forgot to provide us with WP, that's ok because its global |
68 | - if (! $wp instanceof WP) { |
|
68 | + if ( ! $wp instanceof WP) { |
|
69 | 69 | global $wp; |
70 | 70 | } |
71 | 71 | $this->set_request_vars($wp); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function set_request_vars($wp = null) |
82 | 82 | { |
83 | - if (! is_admin()) { |
|
83 | + if ( ! is_admin()) { |
|
84 | 84 | // set request post_id |
85 | 85 | $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
86 | 86 | // set request post name |
@@ -99,17 +99,17 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function get_post_id_from_request($wp = null) |
101 | 101 | { |
102 | - if (! $wp instanceof WP) { |
|
102 | + if ( ! $wp instanceof WP) { |
|
103 | 103 | global $wp; |
104 | 104 | } |
105 | 105 | $post_id = null; |
106 | 106 | if (isset($wp->query_vars['p'])) { |
107 | 107 | $post_id = $wp->query_vars['p']; |
108 | 108 | } |
109 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
109 | + if ( ! $post_id && isset($wp->query_vars['page_id'])) { |
|
110 | 110 | $post_id = $wp->query_vars['page_id']; |
111 | 111 | } |
112 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
112 | + if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
113 | 113 | $post_id = basename($wp->request); |
114 | 114 | } |
115 | 115 | return $post_id; |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function get_post_name_from_request($wp = null) |
124 | 124 | { |
125 | - if (! $wp instanceof WP) { |
|
125 | + if ( ! $wp instanceof WP) { |
|
126 | 126 | global $wp; |
127 | 127 | } |
128 | 128 | $post_name = null; |
129 | 129 | if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
130 | 130 | $post_name = $wp->query_vars['name']; |
131 | 131 | } |
132 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
132 | + if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
133 | 133 | $post_name = $wp->query_vars['pagename']; |
134 | 134 | } |
135 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
135 | + if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
136 | 136 | $possible_post_name = basename($wp->request); |
137 | - if (! is_numeric($possible_post_name)) { |
|
137 | + if ( ! is_numeric($possible_post_name)) { |
|
138 | 138 | /** @type WPDB $wpdb */ |
139 | 139 | global $wpdb; |
140 | 140 | $SQL = |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
148 | - if (! $post_name && $this->get('post_id')) { |
|
148 | + if ( ! $post_name && $this->get('post_id')) { |
|
149 | 149 | /** @type WPDB $wpdb */ |
150 | 150 | global $wpdb; |
151 | 151 | $SQL = |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function get_post_type_from_request($wp = null) |
167 | 167 | { |
168 | - if (! $wp instanceof WP) { |
|
168 | + if ( ! $wp instanceof WP) { |
|
169 | 169 | global $wp; |
170 | 170 | } |
171 | 171 | return isset($wp->query_vars['post_type']) |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | if ($post_id) { |
187 | 187 | $current_page_permalink = get_permalink($post_id); |
188 | 188 | } else { |
189 | - if (! $wp instanceof WP) { |
|
189 | + if ( ! $wp instanceof WP) { |
|
190 | 190 | global $wp; |
191 | 191 | } |
192 | 192 | if ($wp->request) { |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
213 | 213 | if (is_array($espresso_CPT_taxonomies)) { |
214 | 214 | foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
215 | - if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
215 | + if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) { |
|
216 | 216 | return true; |
217 | 217 | } |
218 | 218 | } |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | $post_types = (array) $this->get('post_type'); |
224 | 224 | foreach ($post_types as $post_type) { |
225 | 225 | // was a post name passed ? |
226 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
226 | + if (isset($post_type_CPT_endpoints[$post_type])) { |
|
227 | 227 | // kk we know this is an espresso page, but is it a specific post ? |
228 | - if (! $this->get('post_name')) { |
|
228 | + if ( ! $this->get('post_name')) { |
|
229 | 229 | // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
230 | - $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
231 | - ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
230 | + $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')]) |
|
231 | + ? $post_type_CPT_endpoints[$this->get('post_type')] |
|
232 | 232 | : ''; |
233 | 233 | // if the post type matches on of our then set the endpoint |
234 | 234 | if ($post_name) { |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function set_notice($key, $value) |
250 | 250 | { |
251 | - $this->_notice[ $key ] = $value; |
|
251 | + $this->_notice[$key] = $value; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function get_notice($key) |
260 | 260 | { |
261 | - return isset($this->_notice[ $key ]) |
|
262 | - ? $this->_notice[ $key ] |
|
261 | + return isset($this->_notice[$key]) |
|
262 | + ? $this->_notice[$key] |
|
263 | 263 | : null; |
264 | 264 | } |
265 | 265 |
@@ -1164,7 +1164,7 @@ discard block |
||
1164 | 1164 | * Sets deleted |
1165 | 1165 | * |
1166 | 1166 | * @param boolean $deleted |
1167 | - * @return bool |
|
1167 | + * @return boolean|null |
|
1168 | 1168 | * @throws EE_Error |
1169 | 1169 | * @throws RuntimeException |
1170 | 1170 | */ |
@@ -1222,6 +1222,7 @@ discard block |
||
1222 | 1222 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
1223 | 1223 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
1224 | 1224 | * consider registration status as well as datetime access. |
1225 | + * @param integer $DTT_OR_ID |
|
1225 | 1226 | * @return bool |
1226 | 1227 | * @throws EE_Error |
1227 | 1228 | */ |
@@ -1392,7 +1393,7 @@ discard block |
||
1392 | 1393 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
1393 | 1394 | * "Latest" is defined by the `DTT_EVT_start` column. |
1394 | 1395 | * |
1395 | - * @return EE_Datetime|null |
|
1396 | + * @return null|EE_Base_Class |
|
1396 | 1397 | * @throws EE_Error |
1397 | 1398 | */ |
1398 | 1399 | public function get_latest_related_datetime() |
@@ -1688,7 +1689,7 @@ discard block |
||
1688 | 1689 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
1689 | 1690 | * Note: if there are no payments on the registration there will be no payment method returned. |
1690 | 1691 | * |
1691 | - * @return EE_Payment_Method|null |
|
1692 | + * @return null|EE_Base_Class |
|
1692 | 1693 | */ |
1693 | 1694 | public function payment_method() |
1694 | 1695 | { |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | { |
120 | 120 | switch ($field_name) { |
121 | 121 | case 'REG_code': |
122 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
122 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
123 | 123 | $this->set_reg_code($field_value, $use_default); |
124 | 124 | } |
125 | 125 | break; |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | public function event() |
407 | 407 | { |
408 | 408 | $event = $this->get_first_related('Event'); |
409 | - if (! $event instanceof \EE_Event) { |
|
409 | + if ( ! $event instanceof \EE_Event) { |
|
410 | 410 | throw new EntityNotFoundException('Event ID', $this->event_ID()); |
411 | 411 | } |
412 | 412 | return $event; |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | { |
450 | 450 | // reserved ticket and datetime counts will be decremented as sold counts are incremented |
451 | 451 | // so stop tracking that this reg has a ticket reserved |
452 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
452 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
453 | 453 | $ticket = $this->ticket(); |
454 | 454 | $ticket->increaseSold(); |
455 | 455 | // possibly set event status to sold out |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | && $update_ticket |
505 | 505 | ) { |
506 | 506 | $ticket = $this->ticket(); |
507 | - $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
507 | + $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
508 | 508 | $ticket->save(); |
509 | 509 | } |
510 | 510 | } |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | && $update_ticket |
537 | 537 | ) { |
538 | 538 | $ticket = $this->ticket(); |
539 | - $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
539 | + $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
540 | 540 | } |
541 | 541 | } |
542 | 542 | } |
@@ -1211,7 +1211,7 @@ discard block |
||
1211 | 1211 | : ''; |
1212 | 1212 | break; |
1213 | 1213 | } |
1214 | - return $icon . $status[ $this->status_ID() ]; |
|
1214 | + return $icon.$status[$this->status_ID()]; |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | { |
1456 | 1456 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
1457 | 1457 | |
1458 | - if (! $DTT_ID) { |
|
1458 | + if ( ! $DTT_ID) { |
|
1459 | 1459 | return false; |
1460 | 1460 | } |
1461 | 1461 | |
@@ -1463,7 +1463,7 @@ discard block |
||
1463 | 1463 | |
1464 | 1464 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
1465 | 1465 | // check-in or not. |
1466 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1466 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
1467 | 1467 | return true; |
1468 | 1468 | } |
1469 | 1469 | |
@@ -1523,7 +1523,7 @@ discard block |
||
1523 | 1523 | $datetime = $this->get_latest_related_datetime(); |
1524 | 1524 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
1525 | 1525 | // verify the registration can checkin for the given DTT_ID |
1526 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1526 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
1527 | 1527 | EE_Error::add_error( |
1528 | 1528 | sprintf( |
1529 | 1529 | esc_html__( |
@@ -1546,7 +1546,7 @@ discard block |
||
1546 | 1546 | ); |
1547 | 1547 | // start by getting the current status so we know what status we'll be changing to. |
1548 | 1548 | $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
1549 | - $status_to = $status_paths[ $cur_status ]; |
|
1549 | + $status_to = $status_paths[$cur_status]; |
|
1550 | 1550 | // database only records true for checked IN or false for checked OUT |
1551 | 1551 | // no record ( null ) means checked in NEVER, but we obviously don't save that |
1552 | 1552 | $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
@@ -1714,7 +1714,7 @@ discard block |
||
1714 | 1714 | public function transaction() |
1715 | 1715 | { |
1716 | 1716 | $transaction = $this->get_first_related('Transaction'); |
1717 | - if (! $transaction instanceof \EE_Transaction) { |
|
1717 | + if ( ! $transaction instanceof \EE_Transaction) { |
|
1718 | 1718 | throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
1719 | 1719 | } |
1720 | 1720 | return $transaction; |
@@ -1768,11 +1768,11 @@ discard block |
||
1768 | 1768 | ); |
1769 | 1769 | return; |
1770 | 1770 | } |
1771 | - if (! $this->reg_code()) { |
|
1771 | + if ( ! $this->reg_code()) { |
|
1772 | 1772 | parent::set('REG_code', $REG_code, $use_default); |
1773 | 1773 | } else { |
1774 | 1774 | EE_Error::doing_it_wrong( |
1775 | - __CLASS__ . '::' . __FUNCTION__, |
|
1775 | + __CLASS__.'::'.__FUNCTION__, |
|
1776 | 1776 | esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
1777 | 1777 | '4.6.0' |
1778 | 1778 | ); |
@@ -1924,7 +1924,7 @@ discard block |
||
1924 | 1924 | break; |
1925 | 1925 | } |
1926 | 1926 | } |
1927 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1927 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1928 | 1928 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
1929 | 1929 | } |
1930 | 1930 | return $line_item; |
@@ -17,2117 +17,2117 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Used to reference when a registration has never been checked in. |
|
22 | - * |
|
23 | - * @deprecated use \EE_Checkin::status_checked_never instead |
|
24 | - * @type int |
|
25 | - */ |
|
26 | - const checkin_status_never = 2; |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to reference when a registration has been checked in. |
|
30 | - * |
|
31 | - * @deprecated use \EE_Checkin::status_checked_in instead |
|
32 | - * @type int |
|
33 | - */ |
|
34 | - const checkin_status_in = 1; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Used to reference when a registration has been checked out. |
|
39 | - * |
|
40 | - * @deprecated use \EE_Checkin::status_checked_out instead |
|
41 | - * @type int |
|
42 | - */ |
|
43 | - const checkin_status_out = 0; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * extra meta key for tracking reg status os trashed registrations |
|
48 | - * |
|
49 | - * @type string |
|
50 | - */ |
|
51 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * extra meta key for tracking if registration has reserved ticket |
|
56 | - * |
|
57 | - * @type string |
|
58 | - */ |
|
59 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param array $props_n_values incoming values |
|
64 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
65 | - * used.) |
|
66 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
67 | - * date_format and the second value is the time format |
|
68 | - * @return EE_Registration |
|
69 | - * @throws EE_Error |
|
70 | - */ |
|
71 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
72 | - { |
|
73 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
74 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param array $props_n_values incoming values from the database |
|
80 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
81 | - * the website will be used. |
|
82 | - * @return EE_Registration |
|
83 | - */ |
|
84 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
85 | - { |
|
86 | - return new self($props_n_values, true, $timezone); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Set Event ID |
|
92 | - * |
|
93 | - * @param int $EVT_ID Event ID |
|
94 | - * @throws EE_Error |
|
95 | - * @throws RuntimeException |
|
96 | - */ |
|
97 | - public function set_event($EVT_ID = 0) |
|
98 | - { |
|
99 | - $this->set('EVT_ID', $EVT_ID); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
105 | - * be routed to internal methods |
|
106 | - * |
|
107 | - * @param string $field_name |
|
108 | - * @param mixed $field_value |
|
109 | - * @param bool $use_default |
|
110 | - * @throws EE_Error |
|
111 | - * @throws EntityNotFoundException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws ReflectionException |
|
116 | - * @throws RuntimeException |
|
117 | - */ |
|
118 | - public function set($field_name, $field_value, $use_default = false) |
|
119 | - { |
|
120 | - switch ($field_name) { |
|
121 | - case 'REG_code': |
|
122 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
123 | - $this->set_reg_code($field_value, $use_default); |
|
124 | - } |
|
125 | - break; |
|
126 | - case 'STS_ID': |
|
127 | - $this->set_status($field_value, $use_default); |
|
128 | - break; |
|
129 | - default: |
|
130 | - parent::set($field_name, $field_value, $use_default); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Set Status ID |
|
137 | - * updates the registration status and ALSO... |
|
138 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
139 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
140 | - * |
|
141 | - * @param string $new_STS_ID |
|
142 | - * @param boolean $use_default |
|
143 | - * @param ContextInterface|null $context |
|
144 | - * @return bool |
|
145 | - * @throws DomainException |
|
146 | - * @throws EE_Error |
|
147 | - * @throws EntityNotFoundException |
|
148 | - * @throws InvalidArgumentException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidInterfaceException |
|
151 | - * @throws ReflectionException |
|
152 | - * @throws RuntimeException |
|
153 | - * @throws UnexpectedEntityException |
|
154 | - */ |
|
155 | - public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
156 | - { |
|
157 | - // get current REG_Status |
|
158 | - $old_STS_ID = $this->status_ID(); |
|
159 | - // if status has changed |
|
160 | - if ( |
|
161 | - $old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
162 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
163 | - && ! empty($new_STS_ID) // as well as the new status |
|
164 | - && $this->ID() // ensure registration is in the db |
|
165 | - ) { |
|
166 | - // update internal status first |
|
167 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
168 | - // THEN handle other changes that occur when reg status changes |
|
169 | - // TO approved |
|
170 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
171 | - // reserve a space by incrementing ticket and datetime sold values |
|
172 | - $this->reserveRegistrationSpace(); |
|
173 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
174 | - // OR FROM approved |
|
175 | - } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
176 | - // release a space by decrementing ticket and datetime sold values |
|
177 | - $this->releaseRegistrationSpace(); |
|
178 | - do_action( |
|
179 | - 'AHEE__EE_Registration__set_status__from_approved', |
|
180 | - $this, |
|
181 | - $old_STS_ID, |
|
182 | - $new_STS_ID, |
|
183 | - $context |
|
184 | - ); |
|
185 | - } |
|
186 | - // update status |
|
187 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
188 | - $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context); |
|
189 | - if ($this->statusChangeUpdatesTransaction($context)) { |
|
190 | - $this->updateTransactionAfterStatusChange(); |
|
191 | - } |
|
192 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
193 | - return true; |
|
194 | - } |
|
195 | - // even though the old value matches the new value, it's still good to |
|
196 | - // allow the parent set method to have a say |
|
197 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
198 | - return true; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * update REGs and TXN when cancelled or declined registrations involved |
|
204 | - * |
|
205 | - * @param string $new_STS_ID |
|
206 | - * @param string $old_STS_ID |
|
207 | - * @param ContextInterface|null $context |
|
208 | - * @throws EE_Error |
|
209 | - * @throws InvalidArgumentException |
|
210 | - * @throws InvalidDataTypeException |
|
211 | - * @throws InvalidInterfaceException |
|
212 | - * @throws ReflectionException |
|
213 | - * @throws RuntimeException |
|
214 | - */ |
|
215 | - private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
216 | - { |
|
217 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
218 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
219 | - // true if registration has been cancelled or declined |
|
220 | - $this->updateIfCanceled( |
|
221 | - $closed_reg_statuses, |
|
222 | - $new_STS_ID, |
|
223 | - $old_STS_ID, |
|
224 | - $context |
|
225 | - ); |
|
226 | - $this->updateIfReinstated( |
|
227 | - $closed_reg_statuses, |
|
228 | - $new_STS_ID, |
|
229 | - $old_STS_ID, |
|
230 | - $context |
|
231 | - ); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * update REGs and TXN when cancelled or declined registrations involved |
|
237 | - * |
|
238 | - * @param array $closed_reg_statuses |
|
239 | - * @param string $new_STS_ID |
|
240 | - * @param string $old_STS_ID |
|
241 | - * @param ContextInterface|null $context |
|
242 | - * @throws EE_Error |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - * @throws ReflectionException |
|
247 | - * @throws RuntimeException |
|
248 | - */ |
|
249 | - private function updateIfCanceled( |
|
250 | - array $closed_reg_statuses, |
|
251 | - $new_STS_ID, |
|
252 | - $old_STS_ID, |
|
253 | - ContextInterface $context = null |
|
254 | - ) { |
|
255 | - // true if registration has been cancelled or declined |
|
256 | - if ( |
|
257 | - in_array($new_STS_ID, $closed_reg_statuses, true) |
|
258 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
259 | - ) { |
|
260 | - /** @type EE_Registration_Processor $registration_processor */ |
|
261 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
262 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
263 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
264 | - // cancelled or declined registration |
|
265 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
266 | - $this, |
|
267 | - $closed_reg_statuses |
|
268 | - ); |
|
269 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
270 | - $this, |
|
271 | - $closed_reg_statuses, |
|
272 | - false |
|
273 | - ); |
|
274 | - do_action( |
|
275 | - 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
276 | - $this, |
|
277 | - $old_STS_ID, |
|
278 | - $new_STS_ID, |
|
279 | - $context |
|
280 | - ); |
|
281 | - return; |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * update REGs and TXN when cancelled or declined registrations involved |
|
288 | - * |
|
289 | - * @param array $closed_reg_statuses |
|
290 | - * @param string $new_STS_ID |
|
291 | - * @param string $old_STS_ID |
|
292 | - * @param ContextInterface|null $context |
|
293 | - * @throws EE_Error |
|
294 | - * @throws InvalidArgumentException |
|
295 | - * @throws InvalidDataTypeException |
|
296 | - * @throws InvalidInterfaceException |
|
297 | - * @throws ReflectionException |
|
298 | - */ |
|
299 | - private function updateIfReinstated( |
|
300 | - array $closed_reg_statuses, |
|
301 | - $new_STS_ID, |
|
302 | - $old_STS_ID, |
|
303 | - ContextInterface $context = null |
|
304 | - ) { |
|
305 | - // true if reinstating cancelled or declined registration |
|
306 | - if ( |
|
307 | - in_array($old_STS_ID, $closed_reg_statuses, true) |
|
308 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
309 | - ) { |
|
310 | - /** @type EE_Registration_Processor $registration_processor */ |
|
311 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
312 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
313 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
314 | - // reinstating cancelled or declined registration |
|
315 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
316 | - $this, |
|
317 | - $closed_reg_statuses |
|
318 | - ); |
|
319 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
320 | - $this, |
|
321 | - $closed_reg_statuses, |
|
322 | - false |
|
323 | - ); |
|
324 | - do_action( |
|
325 | - 'AHEE__EE_Registration__set_status__after_reinstated', |
|
326 | - $this, |
|
327 | - $old_STS_ID, |
|
328 | - $new_STS_ID, |
|
329 | - $context |
|
330 | - ); |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param ContextInterface|null $context |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
340 | - { |
|
341 | - $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
342 | - 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
343 | - array('spco_reg_step_attendee_information_process_registrations'), |
|
344 | - $context, |
|
345 | - $this |
|
346 | - ); |
|
347 | - return ! ( |
|
348 | - $context instanceof ContextInterface |
|
349 | - && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
350 | - ); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @throws EE_Error |
|
356 | - * @throws EntityNotFoundException |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidDataTypeException |
|
359 | - * @throws InvalidInterfaceException |
|
360 | - * @throws ReflectionException |
|
361 | - * @throws RuntimeException |
|
362 | - */ |
|
363 | - private function updateTransactionAfterStatusChange() |
|
364 | - { |
|
365 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
366 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
367 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
368 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * get Status ID |
|
374 | - */ |
|
375 | - public function status_ID() |
|
376 | - { |
|
377 | - return $this->get('STS_ID'); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Gets the ticket this registration is for |
|
383 | - * |
|
384 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
385 | - * |
|
386 | - * @return EE_Ticket|EE_Base_Class |
|
387 | - * @throws EE_Error |
|
388 | - */ |
|
389 | - public function ticket($include_archived = true) |
|
390 | - { |
|
391 | - $query_params = array(); |
|
392 | - if ($include_archived) { |
|
393 | - $query_params['default_where_conditions'] = 'none'; |
|
394 | - } |
|
395 | - return $this->get_first_related('Ticket', $query_params); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * Gets the event this registration is for |
|
401 | - * |
|
402 | - * @return EE_Event |
|
403 | - * @throws EE_Error |
|
404 | - * @throws EntityNotFoundException |
|
405 | - */ |
|
406 | - public function event() |
|
407 | - { |
|
408 | - $event = $this->get_first_related('Event'); |
|
409 | - if (! $event instanceof \EE_Event) { |
|
410 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
411 | - } |
|
412 | - return $event; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
418 | - * with the author of the event this registration is for. |
|
419 | - * |
|
420 | - * @since 4.5.0 |
|
421 | - * @return int |
|
422 | - * @throws EE_Error |
|
423 | - * @throws EntityNotFoundException |
|
424 | - */ |
|
425 | - public function wp_user() |
|
426 | - { |
|
427 | - $event = $this->event(); |
|
428 | - if ($event instanceof EE_Event) { |
|
429 | - return $event->wp_user(); |
|
430 | - } |
|
431 | - return 0; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
437 | - * |
|
438 | - * @return void |
|
439 | - * @throws DomainException |
|
440 | - * @throws EE_Error |
|
441 | - * @throws EntityNotFoundException |
|
442 | - * @throws InvalidArgumentException |
|
443 | - * @throws InvalidDataTypeException |
|
444 | - * @throws InvalidInterfaceException |
|
445 | - * @throws ReflectionException |
|
446 | - * @throws UnexpectedEntityException |
|
447 | - */ |
|
448 | - private function reserveRegistrationSpace() |
|
449 | - { |
|
450 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
451 | - // so stop tracking that this reg has a ticket reserved |
|
452 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
453 | - $ticket = $this->ticket(); |
|
454 | - $ticket->increaseSold(); |
|
455 | - // possibly set event status to sold out |
|
456 | - $this->event()->perform_sold_out_status_check(); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
462 | - * |
|
463 | - * @return void |
|
464 | - * @throws DomainException |
|
465 | - * @throws EE_Error |
|
466 | - * @throws EntityNotFoundException |
|
467 | - * @throws InvalidArgumentException |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - * @throws ReflectionException |
|
471 | - * @throws UnexpectedEntityException |
|
472 | - */ |
|
473 | - private function releaseRegistrationSpace() |
|
474 | - { |
|
475 | - $ticket = $this->ticket(); |
|
476 | - $ticket->decreaseSold(); |
|
477 | - // possibly change event status from sold out back to previous status |
|
478 | - $this->event()->perform_sold_out_status_check(); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * tracks this registration's ticket reservation in extra meta |
|
484 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
485 | - * |
|
486 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
487 | - * @return void |
|
488 | - * @throws EE_Error |
|
489 | - * @throws InvalidArgumentException |
|
490 | - * @throws InvalidDataTypeException |
|
491 | - * @throws InvalidInterfaceException |
|
492 | - * @throws ReflectionException |
|
493 | - */ |
|
494 | - public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
495 | - { |
|
496 | - // only reserve ticket if space is not currently reserved |
|
497 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
498 | - $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
499 | - // IMPORTANT !!! |
|
500 | - // although checking $update_ticket first would be more efficient, |
|
501 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
502 | - if ( |
|
503 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
504 | - && $update_ticket |
|
505 | - ) { |
|
506 | - $ticket = $this->ticket(); |
|
507 | - $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
508 | - $ticket->save(); |
|
509 | - } |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * stops tracking this registration's ticket reservation in extra meta |
|
516 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
517 | - * |
|
518 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
519 | - * @return void |
|
520 | - * @throws EE_Error |
|
521 | - * @throws InvalidArgumentException |
|
522 | - * @throws InvalidDataTypeException |
|
523 | - * @throws InvalidInterfaceException |
|
524 | - * @throws ReflectionException |
|
525 | - */ |
|
526 | - public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
527 | - { |
|
528 | - // only release ticket if space is currently reserved |
|
529 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
530 | - $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
531 | - // IMPORTANT !!! |
|
532 | - // although checking $update_ticket first would be more efficient, |
|
533 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
534 | - if ( |
|
535 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
536 | - && $update_ticket |
|
537 | - ) { |
|
538 | - $ticket = $this->ticket(); |
|
539 | - $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Set Attendee ID |
|
547 | - * |
|
548 | - * @param int $ATT_ID Attendee ID |
|
549 | - * @throws EE_Error |
|
550 | - * @throws RuntimeException |
|
551 | - */ |
|
552 | - public function set_attendee_id($ATT_ID = 0) |
|
553 | - { |
|
554 | - $this->set('ATT_ID', $ATT_ID); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Set Transaction ID |
|
560 | - * |
|
561 | - * @param int $TXN_ID Transaction ID |
|
562 | - * @throws EE_Error |
|
563 | - * @throws RuntimeException |
|
564 | - */ |
|
565 | - public function set_transaction_id($TXN_ID = 0) |
|
566 | - { |
|
567 | - $this->set('TXN_ID', $TXN_ID); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Set Session |
|
573 | - * |
|
574 | - * @param string $REG_session PHP Session ID |
|
575 | - * @throws EE_Error |
|
576 | - * @throws RuntimeException |
|
577 | - */ |
|
578 | - public function set_session($REG_session = '') |
|
579 | - { |
|
580 | - $this->set('REG_session', $REG_session); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Set Registration URL Link |
|
586 | - * |
|
587 | - * @param string $REG_url_link Registration URL Link |
|
588 | - * @throws EE_Error |
|
589 | - * @throws RuntimeException |
|
590 | - */ |
|
591 | - public function set_reg_url_link($REG_url_link = '') |
|
592 | - { |
|
593 | - $this->set('REG_url_link', $REG_url_link); |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Set Attendee Counter |
|
599 | - * |
|
600 | - * @param int $REG_count Primary Attendee |
|
601 | - * @throws EE_Error |
|
602 | - * @throws RuntimeException |
|
603 | - */ |
|
604 | - public function set_count($REG_count = 1) |
|
605 | - { |
|
606 | - $this->set('REG_count', $REG_count); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Set Group Size |
|
612 | - * |
|
613 | - * @param boolean $REG_group_size Group Registration |
|
614 | - * @throws EE_Error |
|
615 | - * @throws RuntimeException |
|
616 | - */ |
|
617 | - public function set_group_size($REG_group_size = false) |
|
618 | - { |
|
619 | - $this->set('REG_group_size', $REG_group_size); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - /** |
|
624 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
625 | - * EEM_Registration::status_id_not_approved |
|
626 | - * |
|
627 | - * @return boolean |
|
628 | - */ |
|
629 | - public function is_not_approved() |
|
630 | - { |
|
631 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
637 | - * EEM_Registration::status_id_pending_payment |
|
638 | - * |
|
639 | - * @return boolean |
|
640 | - */ |
|
641 | - public function is_pending_payment() |
|
642 | - { |
|
643 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
649 | - * |
|
650 | - * @return boolean |
|
651 | - */ |
|
652 | - public function is_approved() |
|
653 | - { |
|
654 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
660 | - * |
|
661 | - * @return boolean |
|
662 | - */ |
|
663 | - public function is_cancelled() |
|
664 | - { |
|
665 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
671 | - * |
|
672 | - * @return boolean |
|
673 | - */ |
|
674 | - public function is_declined() |
|
675 | - { |
|
676 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
682 | - * EEM_Registration::status_id_incomplete |
|
683 | - * |
|
684 | - * @return boolean |
|
685 | - */ |
|
686 | - public function is_incomplete() |
|
687 | - { |
|
688 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * Set Registration Date |
|
694 | - * |
|
695 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
696 | - * Date |
|
697 | - * @throws EE_Error |
|
698 | - * @throws RuntimeException |
|
699 | - */ |
|
700 | - public function set_reg_date($REG_date = false) |
|
701 | - { |
|
702 | - $this->set('REG_date', $REG_date); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * Set final price owing for this registration after all ticket/price modifications |
|
708 | - * |
|
709 | - * @access public |
|
710 | - * @param float $REG_final_price |
|
711 | - * @throws EE_Error |
|
712 | - * @throws RuntimeException |
|
713 | - */ |
|
714 | - public function set_final_price($REG_final_price = 0.00) |
|
715 | - { |
|
716 | - $this->set('REG_final_price', $REG_final_price); |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Set amount paid towards this registration's final price |
|
722 | - * |
|
723 | - * @access public |
|
724 | - * @param float $REG_paid |
|
725 | - * @throws EE_Error |
|
726 | - * @throws RuntimeException |
|
727 | - */ |
|
728 | - public function set_paid($REG_paid = 0.00) |
|
729 | - { |
|
730 | - $this->set('REG_paid', $REG_paid); |
|
731 | - } |
|
732 | - |
|
733 | - |
|
734 | - /** |
|
735 | - * Attendee Is Going |
|
736 | - * |
|
737 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
738 | - * @throws EE_Error |
|
739 | - * @throws RuntimeException |
|
740 | - */ |
|
741 | - public function set_att_is_going($REG_att_is_going = false) |
|
742 | - { |
|
743 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * Gets the related attendee |
|
749 | - * |
|
750 | - * @return EE_Attendee |
|
751 | - * @throws EE_Error |
|
752 | - */ |
|
753 | - public function attendee() |
|
754 | - { |
|
755 | - return $this->get_first_related('Attendee'); |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * Gets the name of the attendee. |
|
760 | - * @since $VID:$ |
|
761 | - * @param bool $apply_html_entities set to true if you want to use HTML entities. |
|
762 | - * @return string |
|
763 | - * @throws EE_Error |
|
764 | - * @throws InvalidArgumentException |
|
765 | - * @throws InvalidDataTypeException |
|
766 | - * @throws InvalidInterfaceException |
|
767 | - * @throws ReflectionException |
|
768 | - */ |
|
769 | - public function attendeeName($apply_html_entities = false) |
|
770 | - { |
|
771 | - $attendee = $this->get_first_related('Attendee'); |
|
772 | - if ($attendee instanceof EE_Attendee) { |
|
773 | - $attendee_name = $attendee->full_name($apply_html_entities); |
|
774 | - } else { |
|
775 | - $attendee_name = esc_html__('Unknown', 'event_espresso'); |
|
776 | - } |
|
777 | - return $attendee_name; |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - /** |
|
782 | - * get Event ID |
|
783 | - */ |
|
784 | - public function event_ID() |
|
785 | - { |
|
786 | - return $this->get('EVT_ID'); |
|
787 | - } |
|
788 | - |
|
789 | - |
|
790 | - /** |
|
791 | - * get Event ID |
|
792 | - */ |
|
793 | - public function event_name() |
|
794 | - { |
|
795 | - $event = $this->event_obj(); |
|
796 | - if ($event) { |
|
797 | - return $event->name(); |
|
798 | - } else { |
|
799 | - return null; |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * Fetches the event this registration is for |
|
806 | - * |
|
807 | - * @return EE_Event |
|
808 | - * @throws EE_Error |
|
809 | - */ |
|
810 | - public function event_obj() |
|
811 | - { |
|
812 | - return $this->get_first_related('Event'); |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * get Attendee ID |
|
818 | - */ |
|
819 | - public function attendee_ID() |
|
820 | - { |
|
821 | - return $this->get('ATT_ID'); |
|
822 | - } |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * get PHP Session ID |
|
827 | - */ |
|
828 | - public function session_ID() |
|
829 | - { |
|
830 | - return $this->get('REG_session'); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - /** |
|
835 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
836 | - * |
|
837 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
838 | - * @return string |
|
839 | - */ |
|
840 | - public function receipt_url($messenger = 'html') |
|
841 | - { |
|
842 | - |
|
843 | - /** |
|
844 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
845 | - * already in use on old system. If there is then we just return the standard url for it. |
|
846 | - * |
|
847 | - * @since 4.5.0 |
|
848 | - */ |
|
849 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
850 | - $has_custom = EEH_Template::locate_template( |
|
851 | - $template_relative_path, |
|
852 | - array(), |
|
853 | - true, |
|
854 | - true, |
|
855 | - true |
|
856 | - ); |
|
857 | - |
|
858 | - if ($has_custom) { |
|
859 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
860 | - } |
|
861 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
867 | - * |
|
868 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
869 | - * @return string |
|
870 | - * @throws EE_Error |
|
871 | - */ |
|
872 | - public function invoice_url($messenger = 'html') |
|
873 | - { |
|
874 | - /** |
|
875 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
876 | - * already in use on old system. If there is then we just return the standard url for it. |
|
877 | - * |
|
878 | - * @since 4.5.0 |
|
879 | - */ |
|
880 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
881 | - $has_custom = EEH_Template::locate_template( |
|
882 | - $template_relative_path, |
|
883 | - array(), |
|
884 | - true, |
|
885 | - true, |
|
886 | - true |
|
887 | - ); |
|
888 | - |
|
889 | - if ($has_custom) { |
|
890 | - if ($messenger == 'html') { |
|
891 | - return $this->invoice_url('launch'); |
|
892 | - } |
|
893 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
894 | - |
|
895 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
896 | - if ($messenger == 'html') { |
|
897 | - $query_args['html'] = true; |
|
898 | - } |
|
899 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
900 | - } |
|
901 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * get Registration URL Link |
|
907 | - * |
|
908 | - * @access public |
|
909 | - * @return string |
|
910 | - * @throws EE_Error |
|
911 | - */ |
|
912 | - public function reg_url_link() |
|
913 | - { |
|
914 | - return (string) $this->get('REG_url_link'); |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * Echoes out invoice_url() |
|
920 | - * |
|
921 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
922 | - * @return void |
|
923 | - * @throws EE_Error |
|
924 | - */ |
|
925 | - public function e_invoice_url($type = 'launch') |
|
926 | - { |
|
927 | - echo $this->invoice_url($type); |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * Echoes out payment_overview_url |
|
933 | - */ |
|
934 | - public function e_payment_overview_url() |
|
935 | - { |
|
936 | - echo $this->payment_overview_url(); |
|
937 | - } |
|
938 | - |
|
939 | - |
|
940 | - /** |
|
941 | - * Gets the URL for the checkout payment options reg step |
|
942 | - * with this registration's REG_url_link added as a query parameter |
|
943 | - * |
|
944 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
945 | - * payment overview url. |
|
946 | - * @return string |
|
947 | - * @throws InvalidInterfaceException |
|
948 | - * @throws InvalidDataTypeException |
|
949 | - * @throws EE_Error |
|
950 | - * @throws InvalidArgumentException |
|
951 | - */ |
|
952 | - public function payment_overview_url($clear_session = false) |
|
953 | - { |
|
954 | - return add_query_arg( |
|
955 | - (array) apply_filters( |
|
956 | - 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
957 | - array( |
|
958 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
959 | - 'step' => 'payment_options', |
|
960 | - 'revisit' => true, |
|
961 | - 'clear_session' => (bool) $clear_session, |
|
962 | - ), |
|
963 | - $this |
|
964 | - ), |
|
965 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
966 | - ); |
|
967 | - } |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * Gets the URL for the checkout attendee information reg step |
|
972 | - * with this registration's REG_url_link added as a query parameter |
|
973 | - * |
|
974 | - * @return string |
|
975 | - * @throws InvalidInterfaceException |
|
976 | - * @throws InvalidDataTypeException |
|
977 | - * @throws EE_Error |
|
978 | - * @throws InvalidArgumentException |
|
979 | - */ |
|
980 | - public function edit_attendee_information_url() |
|
981 | - { |
|
982 | - return add_query_arg( |
|
983 | - (array) apply_filters( |
|
984 | - 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
985 | - array( |
|
986 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
987 | - 'step' => 'attendee_information', |
|
988 | - 'revisit' => true, |
|
989 | - ), |
|
990 | - $this |
|
991 | - ), |
|
992 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
993 | - ); |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - /** |
|
998 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
999 | - * |
|
1000 | - * @return string |
|
1001 | - * @throws EE_Error |
|
1002 | - */ |
|
1003 | - public function get_admin_edit_url() |
|
1004 | - { |
|
1005 | - return EEH_URL::add_query_args_and_nonce( |
|
1006 | - array( |
|
1007 | - 'page' => 'espresso_registrations', |
|
1008 | - 'action' => 'view_registration', |
|
1009 | - '_REG_ID' => $this->ID(), |
|
1010 | - ), |
|
1011 | - admin_url('admin.php') |
|
1012 | - ); |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * is_primary_registrant? |
|
1018 | - */ |
|
1019 | - public function is_primary_registrant() |
|
1020 | - { |
|
1021 | - return $this->get('REG_count') === 1 ? true : false; |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * This returns the primary registration object for this registration group (which may be this object). |
|
1027 | - * |
|
1028 | - * @return EE_Registration |
|
1029 | - * @throws EE_Error |
|
1030 | - */ |
|
1031 | - public function get_primary_registration() |
|
1032 | - { |
|
1033 | - if ($this->is_primary_registrant()) { |
|
1034 | - return $this; |
|
1035 | - } |
|
1036 | - |
|
1037 | - // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
1038 | - /** @var EE_Registration $primary_registrant */ |
|
1039 | - $primary_registrant = EEM_Registration::instance()->get_one( |
|
1040 | - array( |
|
1041 | - array( |
|
1042 | - 'TXN_ID' => $this->transaction_ID(), |
|
1043 | - 'REG_count' => 1, |
|
1044 | - ), |
|
1045 | - ) |
|
1046 | - ); |
|
1047 | - return $primary_registrant; |
|
1048 | - } |
|
1049 | - |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * get Attendee Number |
|
1053 | - * |
|
1054 | - * @access public |
|
1055 | - */ |
|
1056 | - public function count() |
|
1057 | - { |
|
1058 | - return $this->get('REG_count'); |
|
1059 | - } |
|
1060 | - |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * get Group Size |
|
1064 | - */ |
|
1065 | - public function group_size() |
|
1066 | - { |
|
1067 | - return $this->get('REG_group_size'); |
|
1068 | - } |
|
1069 | - |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * get Registration Date |
|
1073 | - */ |
|
1074 | - public function date() |
|
1075 | - { |
|
1076 | - return $this->get('REG_date'); |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * gets a pretty date |
|
1082 | - * |
|
1083 | - * @param string $date_format |
|
1084 | - * @param string $time_format |
|
1085 | - * @return string |
|
1086 | - * @throws EE_Error |
|
1087 | - */ |
|
1088 | - public function pretty_date($date_format = null, $time_format = null) |
|
1089 | - { |
|
1090 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * final_price |
|
1096 | - * the registration's share of the transaction total, so that the |
|
1097 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
1098 | - * |
|
1099 | - * @return float |
|
1100 | - * @throws EE_Error |
|
1101 | - */ |
|
1102 | - public function final_price() |
|
1103 | - { |
|
1104 | - return $this->get('REG_final_price'); |
|
1105 | - } |
|
1106 | - |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * pretty_final_price |
|
1110 | - * final price as formatted string, with correct decimal places and currency symbol |
|
1111 | - * |
|
1112 | - * @return string |
|
1113 | - * @throws EE_Error |
|
1114 | - */ |
|
1115 | - public function pretty_final_price() |
|
1116 | - { |
|
1117 | - return $this->get_pretty('REG_final_price'); |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * get paid (yeah) |
|
1123 | - * |
|
1124 | - * @return float |
|
1125 | - * @throws EE_Error |
|
1126 | - */ |
|
1127 | - public function paid() |
|
1128 | - { |
|
1129 | - return $this->get('REG_paid'); |
|
1130 | - } |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * pretty_paid |
|
1135 | - * |
|
1136 | - * @return float |
|
1137 | - * @throws EE_Error |
|
1138 | - */ |
|
1139 | - public function pretty_paid() |
|
1140 | - { |
|
1141 | - return $this->get_pretty('REG_paid'); |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * owes_monies_and_can_pay |
|
1147 | - * whether or not this registration has monies owing and it's' status allows payment |
|
1148 | - * |
|
1149 | - * @param array $requires_payment |
|
1150 | - * @return bool |
|
1151 | - * @throws EE_Error |
|
1152 | - */ |
|
1153 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
1154 | - { |
|
1155 | - // these reg statuses require payment (if event is not free) |
|
1156 | - $requires_payment = ! empty($requires_payment) |
|
1157 | - ? $requires_payment |
|
1158 | - : EEM_Registration::reg_statuses_that_allow_payment(); |
|
1159 | - if ( |
|
1160 | - in_array($this->status_ID(), $requires_payment) && |
|
1161 | - $this->final_price() != 0 && |
|
1162 | - $this->final_price() != $this->paid() |
|
1163 | - ) { |
|
1164 | - return true; |
|
1165 | - } else { |
|
1166 | - return false; |
|
1167 | - } |
|
1168 | - } |
|
1169 | - |
|
1170 | - |
|
1171 | - /** |
|
1172 | - * Prints out the return value of $this->pretty_status() |
|
1173 | - * |
|
1174 | - * @param bool $show_icons |
|
1175 | - * @return void |
|
1176 | - * @throws EE_Error |
|
1177 | - */ |
|
1178 | - public function e_pretty_status($show_icons = false) |
|
1179 | - { |
|
1180 | - echo $this->pretty_status($show_icons); |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Returns a nice version of the status for displaying to customers |
|
1186 | - * |
|
1187 | - * @param bool $show_icons |
|
1188 | - * @return string |
|
1189 | - * @throws EE_Error |
|
1190 | - */ |
|
1191 | - public function pretty_status($show_icons = false) |
|
1192 | - { |
|
1193 | - $status = EEM_Status::instance()->localized_status( |
|
1194 | - array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
1195 | - false, |
|
1196 | - 'sentence' |
|
1197 | - ); |
|
1198 | - $icon = ''; |
|
1199 | - switch ($this->status_ID()) { |
|
1200 | - case EEM_Registration::status_id_approved: |
|
1201 | - $icon = $show_icons |
|
1202 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
1203 | - : ''; |
|
1204 | - break; |
|
1205 | - case EEM_Registration::status_id_pending_payment: |
|
1206 | - $icon = $show_icons |
|
1207 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
1208 | - : ''; |
|
1209 | - break; |
|
1210 | - case EEM_Registration::status_id_not_approved: |
|
1211 | - $icon = $show_icons |
|
1212 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
1213 | - : ''; |
|
1214 | - break; |
|
1215 | - case EEM_Registration::status_id_cancelled: |
|
1216 | - $icon = $show_icons |
|
1217 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
1218 | - : ''; |
|
1219 | - break; |
|
1220 | - case EEM_Registration::status_id_incomplete: |
|
1221 | - $icon = $show_icons |
|
1222 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
1223 | - : ''; |
|
1224 | - break; |
|
1225 | - case EEM_Registration::status_id_declined: |
|
1226 | - $icon = $show_icons |
|
1227 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
1228 | - : ''; |
|
1229 | - break; |
|
1230 | - case EEM_Registration::status_id_wait_list: |
|
1231 | - $icon = $show_icons |
|
1232 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
1233 | - : ''; |
|
1234 | - break; |
|
1235 | - } |
|
1236 | - return $icon . $status[ $this->status_ID() ]; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * get Attendee Is Going |
|
1242 | - */ |
|
1243 | - public function att_is_going() |
|
1244 | - { |
|
1245 | - return $this->get('REG_att_is_going'); |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Gets related answers |
|
1251 | - * |
|
1252 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1253 | - * @return EE_Answer[] |
|
1254 | - * @throws EE_Error |
|
1255 | - */ |
|
1256 | - public function answers($query_params = null) |
|
1257 | - { |
|
1258 | - return $this->get_many_related('Answer', $query_params); |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Gets the registration's answer value to the specified question |
|
1264 | - * (either the question's ID or a question object) |
|
1265 | - * |
|
1266 | - * @param EE_Question|int $question |
|
1267 | - * @param bool $pretty_value |
|
1268 | - * @return array|string if pretty_value= true, the result will always be a string |
|
1269 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
1270 | - * will convert it into some kind of string) |
|
1271 | - * @throws EE_Error |
|
1272 | - */ |
|
1273 | - public function answer_value_to_question($question, $pretty_value = true) |
|
1274 | - { |
|
1275 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
1276 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
1277 | - } |
|
1278 | - |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * question_groups |
|
1282 | - * returns an array of EE_Question_Group objects for this registration |
|
1283 | - * |
|
1284 | - * @return EE_Question_Group[] |
|
1285 | - * @throws EE_Error |
|
1286 | - * @throws InvalidArgumentException |
|
1287 | - * @throws InvalidDataTypeException |
|
1288 | - * @throws InvalidInterfaceException |
|
1289 | - * @throws ReflectionException |
|
1290 | - */ |
|
1291 | - public function question_groups() |
|
1292 | - { |
|
1293 | - return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this); |
|
1294 | - } |
|
1295 | - |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * count_question_groups |
|
1299 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
1300 | - * |
|
1301 | - * @return int |
|
1302 | - * @throws EE_Error |
|
1303 | - * @throws EntityNotFoundException |
|
1304 | - * @throws InvalidArgumentException |
|
1305 | - * @throws InvalidDataTypeException |
|
1306 | - * @throws InvalidInterfaceException |
|
1307 | - * @throws ReflectionException |
|
1308 | - */ |
|
1309 | - public function count_question_groups() |
|
1310 | - { |
|
1311 | - return EEM_Event::instance()->count_related( |
|
1312 | - $this->event_ID(), |
|
1313 | - 'Question_Group', |
|
1314 | - [ |
|
1315 | - [ |
|
1316 | - 'Event_Question_Group.' |
|
1317 | - . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true, |
|
1318 | - ] |
|
1319 | - ] |
|
1320 | - ); |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * Returns the registration date in the 'standard' string format |
|
1326 | - * (function may be improved in the future to allow for different formats and timezones) |
|
1327 | - * |
|
1328 | - * @return string |
|
1329 | - * @throws EE_Error |
|
1330 | - */ |
|
1331 | - public function reg_date() |
|
1332 | - { |
|
1333 | - return $this->get_datetime('REG_date'); |
|
1334 | - } |
|
1335 | - |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1339 | - * the ticket this registration purchased, or the datetime they have registered |
|
1340 | - * to attend) |
|
1341 | - * |
|
1342 | - * @return EE_Datetime_Ticket |
|
1343 | - * @throws EE_Error |
|
1344 | - */ |
|
1345 | - public function datetime_ticket() |
|
1346 | - { |
|
1347 | - return $this->get_first_related('Datetime_Ticket'); |
|
1348 | - } |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Sets the registration's datetime_ticket. |
|
1353 | - * |
|
1354 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
1355 | - * @return EE_Datetime_Ticket |
|
1356 | - * @throws EE_Error |
|
1357 | - */ |
|
1358 | - public function set_datetime_ticket($datetime_ticket) |
|
1359 | - { |
|
1360 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1361 | - } |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Gets deleted |
|
1365 | - * |
|
1366 | - * @return bool |
|
1367 | - * @throws EE_Error |
|
1368 | - */ |
|
1369 | - public function deleted() |
|
1370 | - { |
|
1371 | - return $this->get('REG_deleted'); |
|
1372 | - } |
|
1373 | - |
|
1374 | - /** |
|
1375 | - * Sets deleted |
|
1376 | - * |
|
1377 | - * @param boolean $deleted |
|
1378 | - * @return bool |
|
1379 | - * @throws EE_Error |
|
1380 | - * @throws RuntimeException |
|
1381 | - */ |
|
1382 | - public function set_deleted($deleted) |
|
1383 | - { |
|
1384 | - if ($deleted) { |
|
1385 | - $this->delete(); |
|
1386 | - } else { |
|
1387 | - $this->restore(); |
|
1388 | - } |
|
1389 | - } |
|
1390 | - |
|
1391 | - |
|
1392 | - /** |
|
1393 | - * Get the status object of this object |
|
1394 | - * |
|
1395 | - * @return EE_Status |
|
1396 | - * @throws EE_Error |
|
1397 | - */ |
|
1398 | - public function status_obj() |
|
1399 | - { |
|
1400 | - return $this->get_first_related('Status'); |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - /** |
|
1405 | - * Returns the number of times this registration has checked into any of the datetimes |
|
1406 | - * its available for |
|
1407 | - * |
|
1408 | - * @return int |
|
1409 | - * @throws EE_Error |
|
1410 | - */ |
|
1411 | - public function count_checkins() |
|
1412 | - { |
|
1413 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
1414 | - } |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1419 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1420 | - * |
|
1421 | - * @return int |
|
1422 | - * @throws EE_Error |
|
1423 | - */ |
|
1424 | - public function count_checkins_not_checkedout() |
|
1425 | - { |
|
1426 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1427 | - } |
|
1428 | - |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1432 | - * |
|
1433 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1434 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1435 | - * consider registration status as well as datetime access. |
|
1436 | - * @return bool |
|
1437 | - * @throws EE_Error |
|
1438 | - */ |
|
1439 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1440 | - { |
|
1441 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1442 | - |
|
1443 | - // first check registration status |
|
1444 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1445 | - return false; |
|
1446 | - } |
|
1447 | - // is there a datetime ticket that matches this dtt_ID? |
|
1448 | - if ( |
|
1449 | - ! (EEM_Datetime_Ticket::instance()->exists( |
|
1450 | - array( |
|
1451 | - array( |
|
1452 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
1453 | - 'DTT_ID' => $DTT_ID, |
|
1454 | - ), |
|
1455 | - ) |
|
1456 | - )) |
|
1457 | - ) { |
|
1458 | - return false; |
|
1459 | - } |
|
1460 | - |
|
1461 | - // final check is against TKT_uses |
|
1462 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1463 | - } |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1468 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1469 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1470 | - * then return false. Otherwise return true. |
|
1471 | - * |
|
1472 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1473 | - * @return bool true means can checkin. false means cannot checkin. |
|
1474 | - * @throws EE_Error |
|
1475 | - */ |
|
1476 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1477 | - { |
|
1478 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1479 | - |
|
1480 | - if (! $DTT_ID) { |
|
1481 | - return false; |
|
1482 | - } |
|
1483 | - |
|
1484 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1485 | - |
|
1486 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
1487 | - // check-in or not. |
|
1488 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1489 | - return true; |
|
1490 | - } |
|
1491 | - |
|
1492 | - // does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1493 | - // go ahead and toggle. |
|
1494 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1495 | - return true; |
|
1496 | - } |
|
1497 | - |
|
1498 | - // made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1499 | - // disallows further check-ins. |
|
1500 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count( |
|
1501 | - array( |
|
1502 | - array( |
|
1503 | - 'REG_ID' => $this->ID(), |
|
1504 | - 'CHK_in' => true, |
|
1505 | - ), |
|
1506 | - ), |
|
1507 | - 'DTT_ID', |
|
1508 | - true |
|
1509 | - ); |
|
1510 | - // checkins have already reached their max number of uses |
|
1511 | - // so registrant can NOT checkin |
|
1512 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
1513 | - EE_Error::add_error( |
|
1514 | - esc_html__( |
|
1515 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1516 | - 'event_espresso' |
|
1517 | - ), |
|
1518 | - __FILE__, |
|
1519 | - __FUNCTION__, |
|
1520 | - __LINE__ |
|
1521 | - ); |
|
1522 | - return false; |
|
1523 | - } |
|
1524 | - return true; |
|
1525 | - } |
|
1526 | - |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * toggle Check-in status for this registration |
|
1530 | - * Check-ins are toggled in the following order: |
|
1531 | - * never checked in -> checked in |
|
1532 | - * checked in -> checked out |
|
1533 | - * checked out -> checked in |
|
1534 | - * |
|
1535 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1536 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
1537 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1538 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
1539 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1540 | - * @throws EE_Error |
|
1541 | - */ |
|
1542 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1543 | - { |
|
1544 | - if (empty($DTT_ID)) { |
|
1545 | - $datetime = $this->get_latest_related_datetime(); |
|
1546 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1547 | - // verify the registration can checkin for the given DTT_ID |
|
1548 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1549 | - EE_Error::add_error( |
|
1550 | - sprintf( |
|
1551 | - esc_html__( |
|
1552 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1553 | - 'event_espresso' |
|
1554 | - ), |
|
1555 | - $this->ID(), |
|
1556 | - $DTT_ID |
|
1557 | - ), |
|
1558 | - __FILE__, |
|
1559 | - __FUNCTION__, |
|
1560 | - __LINE__ |
|
1561 | - ); |
|
1562 | - return false; |
|
1563 | - } |
|
1564 | - $status_paths = array( |
|
1565 | - EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
1566 | - EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
1567 | - EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
1568 | - ); |
|
1569 | - // start by getting the current status so we know what status we'll be changing to. |
|
1570 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1571 | - $status_to = $status_paths[ $cur_status ]; |
|
1572 | - // database only records true for checked IN or false for checked OUT |
|
1573 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1574 | - $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
1575 | - // add relation - note Check-ins are always creating new rows |
|
1576 | - // because we are keeping track of Check-ins over time. |
|
1577 | - // Eventually we'll probably want to show a list table |
|
1578 | - // for the individual Check-ins so that they can be managed. |
|
1579 | - $checkin = EE_Checkin::new_instance( |
|
1580 | - array( |
|
1581 | - 'REG_ID' => $this->ID(), |
|
1582 | - 'DTT_ID' => $DTT_ID, |
|
1583 | - 'CHK_in' => $new_status, |
|
1584 | - ) |
|
1585 | - ); |
|
1586 | - // if the record could not be saved then return false |
|
1587 | - if ($checkin->save() === 0) { |
|
1588 | - if (WP_DEBUG) { |
|
1589 | - global $wpdb; |
|
1590 | - $error = sprintf( |
|
1591 | - esc_html__( |
|
1592 | - 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
1593 | - 'event_espresso' |
|
1594 | - ), |
|
1595 | - '<br />', |
|
1596 | - $wpdb->last_error |
|
1597 | - ); |
|
1598 | - } else { |
|
1599 | - $error = esc_html__( |
|
1600 | - 'Registration check in update failed because of an unknown database error', |
|
1601 | - 'event_espresso' |
|
1602 | - ); |
|
1603 | - } |
|
1604 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1605 | - return false; |
|
1606 | - } |
|
1607 | - // Fire a checked_in and checkout_out action. |
|
1608 | - $checked_status = $status_to === EE_Checkin::status_checked_in ? 'checked_in' : 'checked_out'; |
|
1609 | - do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID); |
|
1610 | - return $status_to; |
|
1611 | - } |
|
1612 | - |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1616 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
1617 | - * |
|
1618 | - * @return EE_Datetime|null |
|
1619 | - * @throws EE_Error |
|
1620 | - */ |
|
1621 | - public function get_latest_related_datetime() |
|
1622 | - { |
|
1623 | - return EEM_Datetime::instance()->get_one( |
|
1624 | - array( |
|
1625 | - array( |
|
1626 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1627 | - ), |
|
1628 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1629 | - ) |
|
1630 | - ); |
|
1631 | - } |
|
1632 | - |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1636 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1637 | - * |
|
1638 | - * @throws EE_Error |
|
1639 | - */ |
|
1640 | - public function get_earliest_related_datetime() |
|
1641 | - { |
|
1642 | - return EEM_Datetime::instance()->get_one( |
|
1643 | - array( |
|
1644 | - array( |
|
1645 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1646 | - ), |
|
1647 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1648 | - ) |
|
1649 | - ); |
|
1650 | - } |
|
1651 | - |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
1655 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
1656 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1657 | - * |
|
1658 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
1659 | - * (if empty we'll get the primary datetime for |
|
1660 | - * this registration (via event) and use it's ID); |
|
1661 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1662 | - * |
|
1663 | - * @return int Integer representing Check-in status. |
|
1664 | - * @throws EE_Error |
|
1665 | - */ |
|
1666 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1667 | - { |
|
1668 | - $checkin_query_params = array( |
|
1669 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1670 | - ); |
|
1671 | - |
|
1672 | - if ($DTT_ID > 0) { |
|
1673 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1674 | - } |
|
1675 | - |
|
1676 | - // get checkin object (if exists) |
|
1677 | - $checkin = $checkin instanceof EE_Checkin |
|
1678 | - ? $checkin |
|
1679 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
1680 | - if ($checkin instanceof EE_Checkin) { |
|
1681 | - if ($checkin->get('CHK_in')) { |
|
1682 | - return EE_Checkin::status_checked_in; // checked in |
|
1683 | - } |
|
1684 | - return EE_Checkin::status_checked_out; // had checked in but is now checked out. |
|
1685 | - } |
|
1686 | - return EE_Checkin::status_checked_never; // never been checked in |
|
1687 | - } |
|
1688 | - |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * This method returns a localized message for the toggled Check-in message. |
|
1692 | - * |
|
1693 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1694 | - * then it is assumed Check-in for primary datetime was toggled. |
|
1695 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1696 | - * message can be customized with the attendee name. |
|
1697 | - * @return string internationalized message |
|
1698 | - * @throws EE_Error |
|
1699 | - */ |
|
1700 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
1701 | - { |
|
1702 | - // let's get the attendee first so we can include the name of the attendee |
|
1703 | - $attendee = $this->get_first_related('Attendee'); |
|
1704 | - if ($attendee instanceof EE_Attendee) { |
|
1705 | - if ($error) { |
|
1706 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1707 | - } |
|
1708 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1709 | - // what is the status message going to be? |
|
1710 | - switch ($cur_status) { |
|
1711 | - case EE_Checkin::status_checked_never: |
|
1712 | - return sprintf( |
|
1713 | - __("%s has been removed from Check-in records", "event_espresso"), |
|
1714 | - $attendee->full_name() |
|
1715 | - ); |
|
1716 | - break; |
|
1717 | - case EE_Checkin::status_checked_in: |
|
1718 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1719 | - break; |
|
1720 | - case EE_Checkin::status_checked_out: |
|
1721 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1722 | - break; |
|
1723 | - } |
|
1724 | - } |
|
1725 | - return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
1726 | - } |
|
1727 | - |
|
1728 | - |
|
1729 | - /** |
|
1730 | - * Returns the related EE_Transaction to this registration |
|
1731 | - * |
|
1732 | - * @return EE_Transaction |
|
1733 | - * @throws EE_Error |
|
1734 | - * @throws EntityNotFoundException |
|
1735 | - */ |
|
1736 | - public function transaction() |
|
1737 | - { |
|
1738 | - $transaction = $this->get_first_related('Transaction'); |
|
1739 | - if (! $transaction instanceof \EE_Transaction) { |
|
1740 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1741 | - } |
|
1742 | - return $transaction; |
|
1743 | - } |
|
1744 | - |
|
1745 | - |
|
1746 | - /** |
|
1747 | - * get Registration Code |
|
1748 | - */ |
|
1749 | - public function reg_code() |
|
1750 | - { |
|
1751 | - return $this->get('REG_code'); |
|
1752 | - } |
|
1753 | - |
|
1754 | - |
|
1755 | - /** |
|
1756 | - * get Transaction ID |
|
1757 | - */ |
|
1758 | - public function transaction_ID() |
|
1759 | - { |
|
1760 | - return $this->get('TXN_ID'); |
|
1761 | - } |
|
1762 | - |
|
1763 | - |
|
1764 | - /** |
|
1765 | - * @return int |
|
1766 | - * @throws EE_Error |
|
1767 | - */ |
|
1768 | - public function ticket_ID() |
|
1769 | - { |
|
1770 | - return $this->get('TKT_ID'); |
|
1771 | - } |
|
1772 | - |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Set Registration Code |
|
1776 | - * |
|
1777 | - * @access public |
|
1778 | - * @param string $REG_code Registration Code |
|
1779 | - * @param boolean $use_default |
|
1780 | - * @throws EE_Error |
|
1781 | - */ |
|
1782 | - public function set_reg_code($REG_code, $use_default = false) |
|
1783 | - { |
|
1784 | - if (empty($REG_code)) { |
|
1785 | - EE_Error::add_error( |
|
1786 | - esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
1787 | - __FILE__, |
|
1788 | - __FUNCTION__, |
|
1789 | - __LINE__ |
|
1790 | - ); |
|
1791 | - return; |
|
1792 | - } |
|
1793 | - if (! $this->reg_code()) { |
|
1794 | - parent::set('REG_code', $REG_code, $use_default); |
|
1795 | - } else { |
|
1796 | - EE_Error::doing_it_wrong( |
|
1797 | - __CLASS__ . '::' . __FUNCTION__, |
|
1798 | - esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1799 | - '4.6.0' |
|
1800 | - ); |
|
1801 | - } |
|
1802 | - } |
|
1803 | - |
|
1804 | - |
|
1805 | - /** |
|
1806 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1807 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1808 | - * $registration->transaction()->registrations(); |
|
1809 | - * |
|
1810 | - * @since 4.5.0 |
|
1811 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1812 | - * @throws EE_Error |
|
1813 | - */ |
|
1814 | - public function get_all_other_registrations_in_group() |
|
1815 | - { |
|
1816 | - if ($this->group_size() < 2) { |
|
1817 | - return array(); |
|
1818 | - } |
|
1819 | - |
|
1820 | - $query[0] = array( |
|
1821 | - 'TXN_ID' => $this->transaction_ID(), |
|
1822 | - 'REG_ID' => array('!=', $this->ID()), |
|
1823 | - 'TKT_ID' => $this->ticket_ID(), |
|
1824 | - ); |
|
1825 | - /** @var EE_Registration[] $registrations */ |
|
1826 | - $registrations = $this->get_model()->get_all($query); |
|
1827 | - return $registrations; |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * Return the link to the admin details for the object. |
|
1832 | - * |
|
1833 | - * @return string |
|
1834 | - * @throws EE_Error |
|
1835 | - */ |
|
1836 | - public function get_admin_details_link() |
|
1837 | - { |
|
1838 | - EE_Registry::instance()->load_helper('URL'); |
|
1839 | - return EEH_URL::add_query_args_and_nonce( |
|
1840 | - array( |
|
1841 | - 'page' => 'espresso_registrations', |
|
1842 | - 'action' => 'view_registration', |
|
1843 | - '_REG_ID' => $this->ID(), |
|
1844 | - ), |
|
1845 | - admin_url('admin.php') |
|
1846 | - ); |
|
1847 | - } |
|
1848 | - |
|
1849 | - /** |
|
1850 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1851 | - * |
|
1852 | - * @return string |
|
1853 | - * @throws EE_Error |
|
1854 | - */ |
|
1855 | - public function get_admin_edit_link() |
|
1856 | - { |
|
1857 | - return $this->get_admin_details_link(); |
|
1858 | - } |
|
1859 | - |
|
1860 | - /** |
|
1861 | - * Returns the link to a settings page for the object. |
|
1862 | - * |
|
1863 | - * @return string |
|
1864 | - * @throws EE_Error |
|
1865 | - */ |
|
1866 | - public function get_admin_settings_link() |
|
1867 | - { |
|
1868 | - return $this->get_admin_details_link(); |
|
1869 | - } |
|
1870 | - |
|
1871 | - /** |
|
1872 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1873 | - * |
|
1874 | - * @return string |
|
1875 | - */ |
|
1876 | - public function get_admin_overview_link() |
|
1877 | - { |
|
1878 | - EE_Registry::instance()->load_helper('URL'); |
|
1879 | - return EEH_URL::add_query_args_and_nonce( |
|
1880 | - array( |
|
1881 | - 'page' => 'espresso_registrations', |
|
1882 | - ), |
|
1883 | - admin_url('admin.php') |
|
1884 | - ); |
|
1885 | - } |
|
1886 | - |
|
1887 | - |
|
1888 | - /** |
|
1889 | - * @param array $query_params |
|
1890 | - * |
|
1891 | - * @return \EE_Registration[] |
|
1892 | - * @throws EE_Error |
|
1893 | - */ |
|
1894 | - public function payments($query_params = array()) |
|
1895 | - { |
|
1896 | - return $this->get_many_related('Payment', $query_params); |
|
1897 | - } |
|
1898 | - |
|
1899 | - |
|
1900 | - /** |
|
1901 | - * @param array $query_params |
|
1902 | - * |
|
1903 | - * @return \EE_Registration_Payment[] |
|
1904 | - * @throws EE_Error |
|
1905 | - */ |
|
1906 | - public function registration_payments($query_params = array()) |
|
1907 | - { |
|
1908 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
1909 | - } |
|
1910 | - |
|
1911 | - |
|
1912 | - /** |
|
1913 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1914 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
1915 | - * |
|
1916 | - * @return EE_Payment_Method|null |
|
1917 | - */ |
|
1918 | - public function payment_method() |
|
1919 | - { |
|
1920 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1921 | - } |
|
1922 | - |
|
1923 | - |
|
1924 | - /** |
|
1925 | - * @return \EE_Line_Item |
|
1926 | - * @throws EntityNotFoundException |
|
1927 | - * @throws EE_Error |
|
1928 | - */ |
|
1929 | - public function ticket_line_item() |
|
1930 | - { |
|
1931 | - $ticket = $this->ticket(); |
|
1932 | - $transaction = $this->transaction(); |
|
1933 | - $line_item = null; |
|
1934 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1935 | - $transaction->total_line_item(), |
|
1936 | - 'Ticket', |
|
1937 | - array($ticket->ID()) |
|
1938 | - ); |
|
1939 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
1940 | - if ( |
|
1941 | - $ticket_line_item instanceof \EE_Line_Item |
|
1942 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1943 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1944 | - ) { |
|
1945 | - $line_item = $ticket_line_item; |
|
1946 | - break; |
|
1947 | - } |
|
1948 | - } |
|
1949 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1950 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1951 | - } |
|
1952 | - return $line_item; |
|
1953 | - } |
|
1954 | - |
|
1955 | - |
|
1956 | - /** |
|
1957 | - * Soft Deletes this model object. |
|
1958 | - * |
|
1959 | - * @return boolean | int |
|
1960 | - * @throws RuntimeException |
|
1961 | - * @throws EE_Error |
|
1962 | - */ |
|
1963 | - public function delete() |
|
1964 | - { |
|
1965 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1966 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
1967 | - } |
|
1968 | - return parent::delete(); |
|
1969 | - } |
|
1970 | - |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1974 | - * |
|
1975 | - * @throws EE_Error |
|
1976 | - * @throws RuntimeException |
|
1977 | - */ |
|
1978 | - public function restore() |
|
1979 | - { |
|
1980 | - $previous_status = $this->get_extra_meta( |
|
1981 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1982 | - true, |
|
1983 | - EEM_Registration::status_id_cancelled |
|
1984 | - ); |
|
1985 | - if ($previous_status) { |
|
1986 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1987 | - $this->set_status($previous_status); |
|
1988 | - } |
|
1989 | - return parent::restore(); |
|
1990 | - } |
|
1991 | - |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
1995 | - * |
|
1996 | - * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
1997 | - * depending on whether the reg status changes to or from "Approved" |
|
1998 | - * @return boolean whether the Registration status was updated |
|
1999 | - * @throws EE_Error |
|
2000 | - * @throws RuntimeException |
|
2001 | - */ |
|
2002 | - public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
2003 | - { |
|
2004 | - $paid = $this->paid(); |
|
2005 | - $price = $this->final_price(); |
|
2006 | - switch (true) { |
|
2007 | - // overpaid or paid |
|
2008 | - case EEH_Money::compare_floats($paid, $price, '>'): |
|
2009 | - case EEH_Money::compare_floats($paid, $price): |
|
2010 | - $new_status = EEM_Registration::status_id_approved; |
|
2011 | - break; |
|
2012 | - // underpaid |
|
2013 | - case EEH_Money::compare_floats($paid, $price, '<'): |
|
2014 | - $new_status = EEM_Registration::status_id_pending_payment; |
|
2015 | - break; |
|
2016 | - // uhhh Houston... |
|
2017 | - default: |
|
2018 | - throw new RuntimeException( |
|
2019 | - esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
2020 | - ); |
|
2021 | - } |
|
2022 | - if ($new_status !== $this->status_ID()) { |
|
2023 | - if ($trigger_set_status_logic) { |
|
2024 | - return $this->set_status($new_status); |
|
2025 | - } |
|
2026 | - parent::set('STS_ID', $new_status); |
|
2027 | - return true; |
|
2028 | - } |
|
2029 | - return false; |
|
2030 | - } |
|
2031 | - |
|
2032 | - |
|
2033 | - /*************************** DEPRECATED ***************************/ |
|
2034 | - |
|
2035 | - |
|
2036 | - /** |
|
2037 | - * @deprecated |
|
2038 | - * @since 4.7.0 |
|
2039 | - * @access public |
|
2040 | - */ |
|
2041 | - public function price_paid() |
|
2042 | - { |
|
2043 | - EE_Error::doing_it_wrong( |
|
2044 | - 'EE_Registration::price_paid()', |
|
2045 | - esc_html__( |
|
2046 | - 'This method is deprecated, please use EE_Registration::final_price() instead.', |
|
2047 | - 'event_espresso' |
|
2048 | - ), |
|
2049 | - '4.7.0' |
|
2050 | - ); |
|
2051 | - return $this->final_price(); |
|
2052 | - } |
|
2053 | - |
|
2054 | - |
|
2055 | - /** |
|
2056 | - * @deprecated |
|
2057 | - * @since 4.7.0 |
|
2058 | - * @access public |
|
2059 | - * @param float $REG_final_price |
|
2060 | - * @throws EE_Error |
|
2061 | - * @throws RuntimeException |
|
2062 | - */ |
|
2063 | - public function set_price_paid($REG_final_price = 0.00) |
|
2064 | - { |
|
2065 | - EE_Error::doing_it_wrong( |
|
2066 | - 'EE_Registration::set_price_paid()', |
|
2067 | - esc_html__( |
|
2068 | - 'This method is deprecated, please use EE_Registration::set_final_price() instead.', |
|
2069 | - 'event_espresso' |
|
2070 | - ), |
|
2071 | - '4.7.0' |
|
2072 | - ); |
|
2073 | - $this->set_final_price($REG_final_price); |
|
2074 | - } |
|
2075 | - |
|
2076 | - |
|
2077 | - /** |
|
2078 | - * @deprecated |
|
2079 | - * @since 4.7.0 |
|
2080 | - * @return string |
|
2081 | - * @throws EE_Error |
|
2082 | - */ |
|
2083 | - public function pretty_price_paid() |
|
2084 | - { |
|
2085 | - EE_Error::doing_it_wrong( |
|
2086 | - 'EE_Registration::pretty_price_paid()', |
|
2087 | - esc_html__( |
|
2088 | - 'This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
2089 | - 'event_espresso' |
|
2090 | - ), |
|
2091 | - '4.7.0' |
|
2092 | - ); |
|
2093 | - return $this->pretty_final_price(); |
|
2094 | - } |
|
2095 | - |
|
2096 | - |
|
2097 | - /** |
|
2098 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
2099 | - * |
|
2100 | - * @deprecated 4.9.17 |
|
2101 | - * @return EE_Datetime |
|
2102 | - * @throws EE_Error |
|
2103 | - * @throws EntityNotFoundException |
|
2104 | - */ |
|
2105 | - public function get_related_primary_datetime() |
|
2106 | - { |
|
2107 | - EE_Error::doing_it_wrong( |
|
2108 | - __METHOD__, |
|
2109 | - esc_html__( |
|
2110 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
2111 | - 'event_espresso' |
|
2112 | - ), |
|
2113 | - '4.9.17', |
|
2114 | - '5.0.0' |
|
2115 | - ); |
|
2116 | - return $this->event()->primary_datetime(); |
|
2117 | - } |
|
2118 | - |
|
2119 | - /** |
|
2120 | - * Returns the contact's name (or "Unknown" if there is no contact.) |
|
2121 | - * @since $VID:$ |
|
2122 | - * @return string |
|
2123 | - * @throws EE_Error |
|
2124 | - * @throws InvalidArgumentException |
|
2125 | - * @throws InvalidDataTypeException |
|
2126 | - * @throws InvalidInterfaceException |
|
2127 | - * @throws ReflectionException |
|
2128 | - */ |
|
2129 | - public function name() |
|
2130 | - { |
|
2131 | - return $this->attendeeName(); |
|
2132 | - } |
|
20 | + /** |
|
21 | + * Used to reference when a registration has never been checked in. |
|
22 | + * |
|
23 | + * @deprecated use \EE_Checkin::status_checked_never instead |
|
24 | + * @type int |
|
25 | + */ |
|
26 | + const checkin_status_never = 2; |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to reference when a registration has been checked in. |
|
30 | + * |
|
31 | + * @deprecated use \EE_Checkin::status_checked_in instead |
|
32 | + * @type int |
|
33 | + */ |
|
34 | + const checkin_status_in = 1; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Used to reference when a registration has been checked out. |
|
39 | + * |
|
40 | + * @deprecated use \EE_Checkin::status_checked_out instead |
|
41 | + * @type int |
|
42 | + */ |
|
43 | + const checkin_status_out = 0; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * extra meta key for tracking reg status os trashed registrations |
|
48 | + * |
|
49 | + * @type string |
|
50 | + */ |
|
51 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * extra meta key for tracking if registration has reserved ticket |
|
56 | + * |
|
57 | + * @type string |
|
58 | + */ |
|
59 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param array $props_n_values incoming values |
|
64 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
65 | + * used.) |
|
66 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
67 | + * date_format and the second value is the time format |
|
68 | + * @return EE_Registration |
|
69 | + * @throws EE_Error |
|
70 | + */ |
|
71 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
72 | + { |
|
73 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
74 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param array $props_n_values incoming values from the database |
|
80 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
81 | + * the website will be used. |
|
82 | + * @return EE_Registration |
|
83 | + */ |
|
84 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
85 | + { |
|
86 | + return new self($props_n_values, true, $timezone); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Set Event ID |
|
92 | + * |
|
93 | + * @param int $EVT_ID Event ID |
|
94 | + * @throws EE_Error |
|
95 | + * @throws RuntimeException |
|
96 | + */ |
|
97 | + public function set_event($EVT_ID = 0) |
|
98 | + { |
|
99 | + $this->set('EVT_ID', $EVT_ID); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
105 | + * be routed to internal methods |
|
106 | + * |
|
107 | + * @param string $field_name |
|
108 | + * @param mixed $field_value |
|
109 | + * @param bool $use_default |
|
110 | + * @throws EE_Error |
|
111 | + * @throws EntityNotFoundException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws ReflectionException |
|
116 | + * @throws RuntimeException |
|
117 | + */ |
|
118 | + public function set($field_name, $field_value, $use_default = false) |
|
119 | + { |
|
120 | + switch ($field_name) { |
|
121 | + case 'REG_code': |
|
122 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
123 | + $this->set_reg_code($field_value, $use_default); |
|
124 | + } |
|
125 | + break; |
|
126 | + case 'STS_ID': |
|
127 | + $this->set_status($field_value, $use_default); |
|
128 | + break; |
|
129 | + default: |
|
130 | + parent::set($field_name, $field_value, $use_default); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Set Status ID |
|
137 | + * updates the registration status and ALSO... |
|
138 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
139 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
140 | + * |
|
141 | + * @param string $new_STS_ID |
|
142 | + * @param boolean $use_default |
|
143 | + * @param ContextInterface|null $context |
|
144 | + * @return bool |
|
145 | + * @throws DomainException |
|
146 | + * @throws EE_Error |
|
147 | + * @throws EntityNotFoundException |
|
148 | + * @throws InvalidArgumentException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidInterfaceException |
|
151 | + * @throws ReflectionException |
|
152 | + * @throws RuntimeException |
|
153 | + * @throws UnexpectedEntityException |
|
154 | + */ |
|
155 | + public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
156 | + { |
|
157 | + // get current REG_Status |
|
158 | + $old_STS_ID = $this->status_ID(); |
|
159 | + // if status has changed |
|
160 | + if ( |
|
161 | + $old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
162 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
163 | + && ! empty($new_STS_ID) // as well as the new status |
|
164 | + && $this->ID() // ensure registration is in the db |
|
165 | + ) { |
|
166 | + // update internal status first |
|
167 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
168 | + // THEN handle other changes that occur when reg status changes |
|
169 | + // TO approved |
|
170 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
171 | + // reserve a space by incrementing ticket and datetime sold values |
|
172 | + $this->reserveRegistrationSpace(); |
|
173 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
174 | + // OR FROM approved |
|
175 | + } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
176 | + // release a space by decrementing ticket and datetime sold values |
|
177 | + $this->releaseRegistrationSpace(); |
|
178 | + do_action( |
|
179 | + 'AHEE__EE_Registration__set_status__from_approved', |
|
180 | + $this, |
|
181 | + $old_STS_ID, |
|
182 | + $new_STS_ID, |
|
183 | + $context |
|
184 | + ); |
|
185 | + } |
|
186 | + // update status |
|
187 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
188 | + $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context); |
|
189 | + if ($this->statusChangeUpdatesTransaction($context)) { |
|
190 | + $this->updateTransactionAfterStatusChange(); |
|
191 | + } |
|
192 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
193 | + return true; |
|
194 | + } |
|
195 | + // even though the old value matches the new value, it's still good to |
|
196 | + // allow the parent set method to have a say |
|
197 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
198 | + return true; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * update REGs and TXN when cancelled or declined registrations involved |
|
204 | + * |
|
205 | + * @param string $new_STS_ID |
|
206 | + * @param string $old_STS_ID |
|
207 | + * @param ContextInterface|null $context |
|
208 | + * @throws EE_Error |
|
209 | + * @throws InvalidArgumentException |
|
210 | + * @throws InvalidDataTypeException |
|
211 | + * @throws InvalidInterfaceException |
|
212 | + * @throws ReflectionException |
|
213 | + * @throws RuntimeException |
|
214 | + */ |
|
215 | + private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
216 | + { |
|
217 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
218 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
219 | + // true if registration has been cancelled or declined |
|
220 | + $this->updateIfCanceled( |
|
221 | + $closed_reg_statuses, |
|
222 | + $new_STS_ID, |
|
223 | + $old_STS_ID, |
|
224 | + $context |
|
225 | + ); |
|
226 | + $this->updateIfReinstated( |
|
227 | + $closed_reg_statuses, |
|
228 | + $new_STS_ID, |
|
229 | + $old_STS_ID, |
|
230 | + $context |
|
231 | + ); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * update REGs and TXN when cancelled or declined registrations involved |
|
237 | + * |
|
238 | + * @param array $closed_reg_statuses |
|
239 | + * @param string $new_STS_ID |
|
240 | + * @param string $old_STS_ID |
|
241 | + * @param ContextInterface|null $context |
|
242 | + * @throws EE_Error |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + * @throws ReflectionException |
|
247 | + * @throws RuntimeException |
|
248 | + */ |
|
249 | + private function updateIfCanceled( |
|
250 | + array $closed_reg_statuses, |
|
251 | + $new_STS_ID, |
|
252 | + $old_STS_ID, |
|
253 | + ContextInterface $context = null |
|
254 | + ) { |
|
255 | + // true if registration has been cancelled or declined |
|
256 | + if ( |
|
257 | + in_array($new_STS_ID, $closed_reg_statuses, true) |
|
258 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
259 | + ) { |
|
260 | + /** @type EE_Registration_Processor $registration_processor */ |
|
261 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
262 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
263 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
264 | + // cancelled or declined registration |
|
265 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
266 | + $this, |
|
267 | + $closed_reg_statuses |
|
268 | + ); |
|
269 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
270 | + $this, |
|
271 | + $closed_reg_statuses, |
|
272 | + false |
|
273 | + ); |
|
274 | + do_action( |
|
275 | + 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
276 | + $this, |
|
277 | + $old_STS_ID, |
|
278 | + $new_STS_ID, |
|
279 | + $context |
|
280 | + ); |
|
281 | + return; |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * update REGs and TXN when cancelled or declined registrations involved |
|
288 | + * |
|
289 | + * @param array $closed_reg_statuses |
|
290 | + * @param string $new_STS_ID |
|
291 | + * @param string $old_STS_ID |
|
292 | + * @param ContextInterface|null $context |
|
293 | + * @throws EE_Error |
|
294 | + * @throws InvalidArgumentException |
|
295 | + * @throws InvalidDataTypeException |
|
296 | + * @throws InvalidInterfaceException |
|
297 | + * @throws ReflectionException |
|
298 | + */ |
|
299 | + private function updateIfReinstated( |
|
300 | + array $closed_reg_statuses, |
|
301 | + $new_STS_ID, |
|
302 | + $old_STS_ID, |
|
303 | + ContextInterface $context = null |
|
304 | + ) { |
|
305 | + // true if reinstating cancelled or declined registration |
|
306 | + if ( |
|
307 | + in_array($old_STS_ID, $closed_reg_statuses, true) |
|
308 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
309 | + ) { |
|
310 | + /** @type EE_Registration_Processor $registration_processor */ |
|
311 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
312 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
313 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
314 | + // reinstating cancelled or declined registration |
|
315 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
316 | + $this, |
|
317 | + $closed_reg_statuses |
|
318 | + ); |
|
319 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
320 | + $this, |
|
321 | + $closed_reg_statuses, |
|
322 | + false |
|
323 | + ); |
|
324 | + do_action( |
|
325 | + 'AHEE__EE_Registration__set_status__after_reinstated', |
|
326 | + $this, |
|
327 | + $old_STS_ID, |
|
328 | + $new_STS_ID, |
|
329 | + $context |
|
330 | + ); |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param ContextInterface|null $context |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
340 | + { |
|
341 | + $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
342 | + 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
343 | + array('spco_reg_step_attendee_information_process_registrations'), |
|
344 | + $context, |
|
345 | + $this |
|
346 | + ); |
|
347 | + return ! ( |
|
348 | + $context instanceof ContextInterface |
|
349 | + && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
350 | + ); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @throws EE_Error |
|
356 | + * @throws EntityNotFoundException |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidDataTypeException |
|
359 | + * @throws InvalidInterfaceException |
|
360 | + * @throws ReflectionException |
|
361 | + * @throws RuntimeException |
|
362 | + */ |
|
363 | + private function updateTransactionAfterStatusChange() |
|
364 | + { |
|
365 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
366 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
367 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
368 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * get Status ID |
|
374 | + */ |
|
375 | + public function status_ID() |
|
376 | + { |
|
377 | + return $this->get('STS_ID'); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Gets the ticket this registration is for |
|
383 | + * |
|
384 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
385 | + * |
|
386 | + * @return EE_Ticket|EE_Base_Class |
|
387 | + * @throws EE_Error |
|
388 | + */ |
|
389 | + public function ticket($include_archived = true) |
|
390 | + { |
|
391 | + $query_params = array(); |
|
392 | + if ($include_archived) { |
|
393 | + $query_params['default_where_conditions'] = 'none'; |
|
394 | + } |
|
395 | + return $this->get_first_related('Ticket', $query_params); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * Gets the event this registration is for |
|
401 | + * |
|
402 | + * @return EE_Event |
|
403 | + * @throws EE_Error |
|
404 | + * @throws EntityNotFoundException |
|
405 | + */ |
|
406 | + public function event() |
|
407 | + { |
|
408 | + $event = $this->get_first_related('Event'); |
|
409 | + if (! $event instanceof \EE_Event) { |
|
410 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
411 | + } |
|
412 | + return $event; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
418 | + * with the author of the event this registration is for. |
|
419 | + * |
|
420 | + * @since 4.5.0 |
|
421 | + * @return int |
|
422 | + * @throws EE_Error |
|
423 | + * @throws EntityNotFoundException |
|
424 | + */ |
|
425 | + public function wp_user() |
|
426 | + { |
|
427 | + $event = $this->event(); |
|
428 | + if ($event instanceof EE_Event) { |
|
429 | + return $event->wp_user(); |
|
430 | + } |
|
431 | + return 0; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
437 | + * |
|
438 | + * @return void |
|
439 | + * @throws DomainException |
|
440 | + * @throws EE_Error |
|
441 | + * @throws EntityNotFoundException |
|
442 | + * @throws InvalidArgumentException |
|
443 | + * @throws InvalidDataTypeException |
|
444 | + * @throws InvalidInterfaceException |
|
445 | + * @throws ReflectionException |
|
446 | + * @throws UnexpectedEntityException |
|
447 | + */ |
|
448 | + private function reserveRegistrationSpace() |
|
449 | + { |
|
450 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
451 | + // so stop tracking that this reg has a ticket reserved |
|
452 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
453 | + $ticket = $this->ticket(); |
|
454 | + $ticket->increaseSold(); |
|
455 | + // possibly set event status to sold out |
|
456 | + $this->event()->perform_sold_out_status_check(); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
462 | + * |
|
463 | + * @return void |
|
464 | + * @throws DomainException |
|
465 | + * @throws EE_Error |
|
466 | + * @throws EntityNotFoundException |
|
467 | + * @throws InvalidArgumentException |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + * @throws ReflectionException |
|
471 | + * @throws UnexpectedEntityException |
|
472 | + */ |
|
473 | + private function releaseRegistrationSpace() |
|
474 | + { |
|
475 | + $ticket = $this->ticket(); |
|
476 | + $ticket->decreaseSold(); |
|
477 | + // possibly change event status from sold out back to previous status |
|
478 | + $this->event()->perform_sold_out_status_check(); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * tracks this registration's ticket reservation in extra meta |
|
484 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
485 | + * |
|
486 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
487 | + * @return void |
|
488 | + * @throws EE_Error |
|
489 | + * @throws InvalidArgumentException |
|
490 | + * @throws InvalidDataTypeException |
|
491 | + * @throws InvalidInterfaceException |
|
492 | + * @throws ReflectionException |
|
493 | + */ |
|
494 | + public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
495 | + { |
|
496 | + // only reserve ticket if space is not currently reserved |
|
497 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
498 | + $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
499 | + // IMPORTANT !!! |
|
500 | + // although checking $update_ticket first would be more efficient, |
|
501 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
502 | + if ( |
|
503 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
504 | + && $update_ticket |
|
505 | + ) { |
|
506 | + $ticket = $this->ticket(); |
|
507 | + $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
508 | + $ticket->save(); |
|
509 | + } |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * stops tracking this registration's ticket reservation in extra meta |
|
516 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
517 | + * |
|
518 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
519 | + * @return void |
|
520 | + * @throws EE_Error |
|
521 | + * @throws InvalidArgumentException |
|
522 | + * @throws InvalidDataTypeException |
|
523 | + * @throws InvalidInterfaceException |
|
524 | + * @throws ReflectionException |
|
525 | + */ |
|
526 | + public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
527 | + { |
|
528 | + // only release ticket if space is currently reserved |
|
529 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
530 | + $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
531 | + // IMPORTANT !!! |
|
532 | + // although checking $update_ticket first would be more efficient, |
|
533 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
534 | + if ( |
|
535 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
536 | + && $update_ticket |
|
537 | + ) { |
|
538 | + $ticket = $this->ticket(); |
|
539 | + $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Set Attendee ID |
|
547 | + * |
|
548 | + * @param int $ATT_ID Attendee ID |
|
549 | + * @throws EE_Error |
|
550 | + * @throws RuntimeException |
|
551 | + */ |
|
552 | + public function set_attendee_id($ATT_ID = 0) |
|
553 | + { |
|
554 | + $this->set('ATT_ID', $ATT_ID); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Set Transaction ID |
|
560 | + * |
|
561 | + * @param int $TXN_ID Transaction ID |
|
562 | + * @throws EE_Error |
|
563 | + * @throws RuntimeException |
|
564 | + */ |
|
565 | + public function set_transaction_id($TXN_ID = 0) |
|
566 | + { |
|
567 | + $this->set('TXN_ID', $TXN_ID); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Set Session |
|
573 | + * |
|
574 | + * @param string $REG_session PHP Session ID |
|
575 | + * @throws EE_Error |
|
576 | + * @throws RuntimeException |
|
577 | + */ |
|
578 | + public function set_session($REG_session = '') |
|
579 | + { |
|
580 | + $this->set('REG_session', $REG_session); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Set Registration URL Link |
|
586 | + * |
|
587 | + * @param string $REG_url_link Registration URL Link |
|
588 | + * @throws EE_Error |
|
589 | + * @throws RuntimeException |
|
590 | + */ |
|
591 | + public function set_reg_url_link($REG_url_link = '') |
|
592 | + { |
|
593 | + $this->set('REG_url_link', $REG_url_link); |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Set Attendee Counter |
|
599 | + * |
|
600 | + * @param int $REG_count Primary Attendee |
|
601 | + * @throws EE_Error |
|
602 | + * @throws RuntimeException |
|
603 | + */ |
|
604 | + public function set_count($REG_count = 1) |
|
605 | + { |
|
606 | + $this->set('REG_count', $REG_count); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Set Group Size |
|
612 | + * |
|
613 | + * @param boolean $REG_group_size Group Registration |
|
614 | + * @throws EE_Error |
|
615 | + * @throws RuntimeException |
|
616 | + */ |
|
617 | + public function set_group_size($REG_group_size = false) |
|
618 | + { |
|
619 | + $this->set('REG_group_size', $REG_group_size); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + /** |
|
624 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
625 | + * EEM_Registration::status_id_not_approved |
|
626 | + * |
|
627 | + * @return boolean |
|
628 | + */ |
|
629 | + public function is_not_approved() |
|
630 | + { |
|
631 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
637 | + * EEM_Registration::status_id_pending_payment |
|
638 | + * |
|
639 | + * @return boolean |
|
640 | + */ |
|
641 | + public function is_pending_payment() |
|
642 | + { |
|
643 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
649 | + * |
|
650 | + * @return boolean |
|
651 | + */ |
|
652 | + public function is_approved() |
|
653 | + { |
|
654 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
660 | + * |
|
661 | + * @return boolean |
|
662 | + */ |
|
663 | + public function is_cancelled() |
|
664 | + { |
|
665 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
671 | + * |
|
672 | + * @return boolean |
|
673 | + */ |
|
674 | + public function is_declined() |
|
675 | + { |
|
676 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
682 | + * EEM_Registration::status_id_incomplete |
|
683 | + * |
|
684 | + * @return boolean |
|
685 | + */ |
|
686 | + public function is_incomplete() |
|
687 | + { |
|
688 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * Set Registration Date |
|
694 | + * |
|
695 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
696 | + * Date |
|
697 | + * @throws EE_Error |
|
698 | + * @throws RuntimeException |
|
699 | + */ |
|
700 | + public function set_reg_date($REG_date = false) |
|
701 | + { |
|
702 | + $this->set('REG_date', $REG_date); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * Set final price owing for this registration after all ticket/price modifications |
|
708 | + * |
|
709 | + * @access public |
|
710 | + * @param float $REG_final_price |
|
711 | + * @throws EE_Error |
|
712 | + * @throws RuntimeException |
|
713 | + */ |
|
714 | + public function set_final_price($REG_final_price = 0.00) |
|
715 | + { |
|
716 | + $this->set('REG_final_price', $REG_final_price); |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Set amount paid towards this registration's final price |
|
722 | + * |
|
723 | + * @access public |
|
724 | + * @param float $REG_paid |
|
725 | + * @throws EE_Error |
|
726 | + * @throws RuntimeException |
|
727 | + */ |
|
728 | + public function set_paid($REG_paid = 0.00) |
|
729 | + { |
|
730 | + $this->set('REG_paid', $REG_paid); |
|
731 | + } |
|
732 | + |
|
733 | + |
|
734 | + /** |
|
735 | + * Attendee Is Going |
|
736 | + * |
|
737 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
738 | + * @throws EE_Error |
|
739 | + * @throws RuntimeException |
|
740 | + */ |
|
741 | + public function set_att_is_going($REG_att_is_going = false) |
|
742 | + { |
|
743 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * Gets the related attendee |
|
749 | + * |
|
750 | + * @return EE_Attendee |
|
751 | + * @throws EE_Error |
|
752 | + */ |
|
753 | + public function attendee() |
|
754 | + { |
|
755 | + return $this->get_first_related('Attendee'); |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * Gets the name of the attendee. |
|
760 | + * @since $VID:$ |
|
761 | + * @param bool $apply_html_entities set to true if you want to use HTML entities. |
|
762 | + * @return string |
|
763 | + * @throws EE_Error |
|
764 | + * @throws InvalidArgumentException |
|
765 | + * @throws InvalidDataTypeException |
|
766 | + * @throws InvalidInterfaceException |
|
767 | + * @throws ReflectionException |
|
768 | + */ |
|
769 | + public function attendeeName($apply_html_entities = false) |
|
770 | + { |
|
771 | + $attendee = $this->get_first_related('Attendee'); |
|
772 | + if ($attendee instanceof EE_Attendee) { |
|
773 | + $attendee_name = $attendee->full_name($apply_html_entities); |
|
774 | + } else { |
|
775 | + $attendee_name = esc_html__('Unknown', 'event_espresso'); |
|
776 | + } |
|
777 | + return $attendee_name; |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + /** |
|
782 | + * get Event ID |
|
783 | + */ |
|
784 | + public function event_ID() |
|
785 | + { |
|
786 | + return $this->get('EVT_ID'); |
|
787 | + } |
|
788 | + |
|
789 | + |
|
790 | + /** |
|
791 | + * get Event ID |
|
792 | + */ |
|
793 | + public function event_name() |
|
794 | + { |
|
795 | + $event = $this->event_obj(); |
|
796 | + if ($event) { |
|
797 | + return $event->name(); |
|
798 | + } else { |
|
799 | + return null; |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * Fetches the event this registration is for |
|
806 | + * |
|
807 | + * @return EE_Event |
|
808 | + * @throws EE_Error |
|
809 | + */ |
|
810 | + public function event_obj() |
|
811 | + { |
|
812 | + return $this->get_first_related('Event'); |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * get Attendee ID |
|
818 | + */ |
|
819 | + public function attendee_ID() |
|
820 | + { |
|
821 | + return $this->get('ATT_ID'); |
|
822 | + } |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * get PHP Session ID |
|
827 | + */ |
|
828 | + public function session_ID() |
|
829 | + { |
|
830 | + return $this->get('REG_session'); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + /** |
|
835 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
836 | + * |
|
837 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
838 | + * @return string |
|
839 | + */ |
|
840 | + public function receipt_url($messenger = 'html') |
|
841 | + { |
|
842 | + |
|
843 | + /** |
|
844 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
845 | + * already in use on old system. If there is then we just return the standard url for it. |
|
846 | + * |
|
847 | + * @since 4.5.0 |
|
848 | + */ |
|
849 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
850 | + $has_custom = EEH_Template::locate_template( |
|
851 | + $template_relative_path, |
|
852 | + array(), |
|
853 | + true, |
|
854 | + true, |
|
855 | + true |
|
856 | + ); |
|
857 | + |
|
858 | + if ($has_custom) { |
|
859 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
860 | + } |
|
861 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
867 | + * |
|
868 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
869 | + * @return string |
|
870 | + * @throws EE_Error |
|
871 | + */ |
|
872 | + public function invoice_url($messenger = 'html') |
|
873 | + { |
|
874 | + /** |
|
875 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
876 | + * already in use on old system. If there is then we just return the standard url for it. |
|
877 | + * |
|
878 | + * @since 4.5.0 |
|
879 | + */ |
|
880 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
881 | + $has_custom = EEH_Template::locate_template( |
|
882 | + $template_relative_path, |
|
883 | + array(), |
|
884 | + true, |
|
885 | + true, |
|
886 | + true |
|
887 | + ); |
|
888 | + |
|
889 | + if ($has_custom) { |
|
890 | + if ($messenger == 'html') { |
|
891 | + return $this->invoice_url('launch'); |
|
892 | + } |
|
893 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
894 | + |
|
895 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
896 | + if ($messenger == 'html') { |
|
897 | + $query_args['html'] = true; |
|
898 | + } |
|
899 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
900 | + } |
|
901 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * get Registration URL Link |
|
907 | + * |
|
908 | + * @access public |
|
909 | + * @return string |
|
910 | + * @throws EE_Error |
|
911 | + */ |
|
912 | + public function reg_url_link() |
|
913 | + { |
|
914 | + return (string) $this->get('REG_url_link'); |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * Echoes out invoice_url() |
|
920 | + * |
|
921 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
922 | + * @return void |
|
923 | + * @throws EE_Error |
|
924 | + */ |
|
925 | + public function e_invoice_url($type = 'launch') |
|
926 | + { |
|
927 | + echo $this->invoice_url($type); |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * Echoes out payment_overview_url |
|
933 | + */ |
|
934 | + public function e_payment_overview_url() |
|
935 | + { |
|
936 | + echo $this->payment_overview_url(); |
|
937 | + } |
|
938 | + |
|
939 | + |
|
940 | + /** |
|
941 | + * Gets the URL for the checkout payment options reg step |
|
942 | + * with this registration's REG_url_link added as a query parameter |
|
943 | + * |
|
944 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
945 | + * payment overview url. |
|
946 | + * @return string |
|
947 | + * @throws InvalidInterfaceException |
|
948 | + * @throws InvalidDataTypeException |
|
949 | + * @throws EE_Error |
|
950 | + * @throws InvalidArgumentException |
|
951 | + */ |
|
952 | + public function payment_overview_url($clear_session = false) |
|
953 | + { |
|
954 | + return add_query_arg( |
|
955 | + (array) apply_filters( |
|
956 | + 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
957 | + array( |
|
958 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
959 | + 'step' => 'payment_options', |
|
960 | + 'revisit' => true, |
|
961 | + 'clear_session' => (bool) $clear_session, |
|
962 | + ), |
|
963 | + $this |
|
964 | + ), |
|
965 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
966 | + ); |
|
967 | + } |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * Gets the URL for the checkout attendee information reg step |
|
972 | + * with this registration's REG_url_link added as a query parameter |
|
973 | + * |
|
974 | + * @return string |
|
975 | + * @throws InvalidInterfaceException |
|
976 | + * @throws InvalidDataTypeException |
|
977 | + * @throws EE_Error |
|
978 | + * @throws InvalidArgumentException |
|
979 | + */ |
|
980 | + public function edit_attendee_information_url() |
|
981 | + { |
|
982 | + return add_query_arg( |
|
983 | + (array) apply_filters( |
|
984 | + 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
985 | + array( |
|
986 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
987 | + 'step' => 'attendee_information', |
|
988 | + 'revisit' => true, |
|
989 | + ), |
|
990 | + $this |
|
991 | + ), |
|
992 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
993 | + ); |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + /** |
|
998 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
999 | + * |
|
1000 | + * @return string |
|
1001 | + * @throws EE_Error |
|
1002 | + */ |
|
1003 | + public function get_admin_edit_url() |
|
1004 | + { |
|
1005 | + return EEH_URL::add_query_args_and_nonce( |
|
1006 | + array( |
|
1007 | + 'page' => 'espresso_registrations', |
|
1008 | + 'action' => 'view_registration', |
|
1009 | + '_REG_ID' => $this->ID(), |
|
1010 | + ), |
|
1011 | + admin_url('admin.php') |
|
1012 | + ); |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * is_primary_registrant? |
|
1018 | + */ |
|
1019 | + public function is_primary_registrant() |
|
1020 | + { |
|
1021 | + return $this->get('REG_count') === 1 ? true : false; |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * This returns the primary registration object for this registration group (which may be this object). |
|
1027 | + * |
|
1028 | + * @return EE_Registration |
|
1029 | + * @throws EE_Error |
|
1030 | + */ |
|
1031 | + public function get_primary_registration() |
|
1032 | + { |
|
1033 | + if ($this->is_primary_registrant()) { |
|
1034 | + return $this; |
|
1035 | + } |
|
1036 | + |
|
1037 | + // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
1038 | + /** @var EE_Registration $primary_registrant */ |
|
1039 | + $primary_registrant = EEM_Registration::instance()->get_one( |
|
1040 | + array( |
|
1041 | + array( |
|
1042 | + 'TXN_ID' => $this->transaction_ID(), |
|
1043 | + 'REG_count' => 1, |
|
1044 | + ), |
|
1045 | + ) |
|
1046 | + ); |
|
1047 | + return $primary_registrant; |
|
1048 | + } |
|
1049 | + |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * get Attendee Number |
|
1053 | + * |
|
1054 | + * @access public |
|
1055 | + */ |
|
1056 | + public function count() |
|
1057 | + { |
|
1058 | + return $this->get('REG_count'); |
|
1059 | + } |
|
1060 | + |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * get Group Size |
|
1064 | + */ |
|
1065 | + public function group_size() |
|
1066 | + { |
|
1067 | + return $this->get('REG_group_size'); |
|
1068 | + } |
|
1069 | + |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * get Registration Date |
|
1073 | + */ |
|
1074 | + public function date() |
|
1075 | + { |
|
1076 | + return $this->get('REG_date'); |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * gets a pretty date |
|
1082 | + * |
|
1083 | + * @param string $date_format |
|
1084 | + * @param string $time_format |
|
1085 | + * @return string |
|
1086 | + * @throws EE_Error |
|
1087 | + */ |
|
1088 | + public function pretty_date($date_format = null, $time_format = null) |
|
1089 | + { |
|
1090 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * final_price |
|
1096 | + * the registration's share of the transaction total, so that the |
|
1097 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
1098 | + * |
|
1099 | + * @return float |
|
1100 | + * @throws EE_Error |
|
1101 | + */ |
|
1102 | + public function final_price() |
|
1103 | + { |
|
1104 | + return $this->get('REG_final_price'); |
|
1105 | + } |
|
1106 | + |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * pretty_final_price |
|
1110 | + * final price as formatted string, with correct decimal places and currency symbol |
|
1111 | + * |
|
1112 | + * @return string |
|
1113 | + * @throws EE_Error |
|
1114 | + */ |
|
1115 | + public function pretty_final_price() |
|
1116 | + { |
|
1117 | + return $this->get_pretty('REG_final_price'); |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * get paid (yeah) |
|
1123 | + * |
|
1124 | + * @return float |
|
1125 | + * @throws EE_Error |
|
1126 | + */ |
|
1127 | + public function paid() |
|
1128 | + { |
|
1129 | + return $this->get('REG_paid'); |
|
1130 | + } |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * pretty_paid |
|
1135 | + * |
|
1136 | + * @return float |
|
1137 | + * @throws EE_Error |
|
1138 | + */ |
|
1139 | + public function pretty_paid() |
|
1140 | + { |
|
1141 | + return $this->get_pretty('REG_paid'); |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * owes_monies_and_can_pay |
|
1147 | + * whether or not this registration has monies owing and it's' status allows payment |
|
1148 | + * |
|
1149 | + * @param array $requires_payment |
|
1150 | + * @return bool |
|
1151 | + * @throws EE_Error |
|
1152 | + */ |
|
1153 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
1154 | + { |
|
1155 | + // these reg statuses require payment (if event is not free) |
|
1156 | + $requires_payment = ! empty($requires_payment) |
|
1157 | + ? $requires_payment |
|
1158 | + : EEM_Registration::reg_statuses_that_allow_payment(); |
|
1159 | + if ( |
|
1160 | + in_array($this->status_ID(), $requires_payment) && |
|
1161 | + $this->final_price() != 0 && |
|
1162 | + $this->final_price() != $this->paid() |
|
1163 | + ) { |
|
1164 | + return true; |
|
1165 | + } else { |
|
1166 | + return false; |
|
1167 | + } |
|
1168 | + } |
|
1169 | + |
|
1170 | + |
|
1171 | + /** |
|
1172 | + * Prints out the return value of $this->pretty_status() |
|
1173 | + * |
|
1174 | + * @param bool $show_icons |
|
1175 | + * @return void |
|
1176 | + * @throws EE_Error |
|
1177 | + */ |
|
1178 | + public function e_pretty_status($show_icons = false) |
|
1179 | + { |
|
1180 | + echo $this->pretty_status($show_icons); |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Returns a nice version of the status for displaying to customers |
|
1186 | + * |
|
1187 | + * @param bool $show_icons |
|
1188 | + * @return string |
|
1189 | + * @throws EE_Error |
|
1190 | + */ |
|
1191 | + public function pretty_status($show_icons = false) |
|
1192 | + { |
|
1193 | + $status = EEM_Status::instance()->localized_status( |
|
1194 | + array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
1195 | + false, |
|
1196 | + 'sentence' |
|
1197 | + ); |
|
1198 | + $icon = ''; |
|
1199 | + switch ($this->status_ID()) { |
|
1200 | + case EEM_Registration::status_id_approved: |
|
1201 | + $icon = $show_icons |
|
1202 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
1203 | + : ''; |
|
1204 | + break; |
|
1205 | + case EEM_Registration::status_id_pending_payment: |
|
1206 | + $icon = $show_icons |
|
1207 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
1208 | + : ''; |
|
1209 | + break; |
|
1210 | + case EEM_Registration::status_id_not_approved: |
|
1211 | + $icon = $show_icons |
|
1212 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
1213 | + : ''; |
|
1214 | + break; |
|
1215 | + case EEM_Registration::status_id_cancelled: |
|
1216 | + $icon = $show_icons |
|
1217 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
1218 | + : ''; |
|
1219 | + break; |
|
1220 | + case EEM_Registration::status_id_incomplete: |
|
1221 | + $icon = $show_icons |
|
1222 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
1223 | + : ''; |
|
1224 | + break; |
|
1225 | + case EEM_Registration::status_id_declined: |
|
1226 | + $icon = $show_icons |
|
1227 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
1228 | + : ''; |
|
1229 | + break; |
|
1230 | + case EEM_Registration::status_id_wait_list: |
|
1231 | + $icon = $show_icons |
|
1232 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
1233 | + : ''; |
|
1234 | + break; |
|
1235 | + } |
|
1236 | + return $icon . $status[ $this->status_ID() ]; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * get Attendee Is Going |
|
1242 | + */ |
|
1243 | + public function att_is_going() |
|
1244 | + { |
|
1245 | + return $this->get('REG_att_is_going'); |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Gets related answers |
|
1251 | + * |
|
1252 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1253 | + * @return EE_Answer[] |
|
1254 | + * @throws EE_Error |
|
1255 | + */ |
|
1256 | + public function answers($query_params = null) |
|
1257 | + { |
|
1258 | + return $this->get_many_related('Answer', $query_params); |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Gets the registration's answer value to the specified question |
|
1264 | + * (either the question's ID or a question object) |
|
1265 | + * |
|
1266 | + * @param EE_Question|int $question |
|
1267 | + * @param bool $pretty_value |
|
1268 | + * @return array|string if pretty_value= true, the result will always be a string |
|
1269 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
1270 | + * will convert it into some kind of string) |
|
1271 | + * @throws EE_Error |
|
1272 | + */ |
|
1273 | + public function answer_value_to_question($question, $pretty_value = true) |
|
1274 | + { |
|
1275 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
1276 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
1277 | + } |
|
1278 | + |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * question_groups |
|
1282 | + * returns an array of EE_Question_Group objects for this registration |
|
1283 | + * |
|
1284 | + * @return EE_Question_Group[] |
|
1285 | + * @throws EE_Error |
|
1286 | + * @throws InvalidArgumentException |
|
1287 | + * @throws InvalidDataTypeException |
|
1288 | + * @throws InvalidInterfaceException |
|
1289 | + * @throws ReflectionException |
|
1290 | + */ |
|
1291 | + public function question_groups() |
|
1292 | + { |
|
1293 | + return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this); |
|
1294 | + } |
|
1295 | + |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * count_question_groups |
|
1299 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
1300 | + * |
|
1301 | + * @return int |
|
1302 | + * @throws EE_Error |
|
1303 | + * @throws EntityNotFoundException |
|
1304 | + * @throws InvalidArgumentException |
|
1305 | + * @throws InvalidDataTypeException |
|
1306 | + * @throws InvalidInterfaceException |
|
1307 | + * @throws ReflectionException |
|
1308 | + */ |
|
1309 | + public function count_question_groups() |
|
1310 | + { |
|
1311 | + return EEM_Event::instance()->count_related( |
|
1312 | + $this->event_ID(), |
|
1313 | + 'Question_Group', |
|
1314 | + [ |
|
1315 | + [ |
|
1316 | + 'Event_Question_Group.' |
|
1317 | + . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true, |
|
1318 | + ] |
|
1319 | + ] |
|
1320 | + ); |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * Returns the registration date in the 'standard' string format |
|
1326 | + * (function may be improved in the future to allow for different formats and timezones) |
|
1327 | + * |
|
1328 | + * @return string |
|
1329 | + * @throws EE_Error |
|
1330 | + */ |
|
1331 | + public function reg_date() |
|
1332 | + { |
|
1333 | + return $this->get_datetime('REG_date'); |
|
1334 | + } |
|
1335 | + |
|
1336 | + |
|
1337 | + /** |
|
1338 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1339 | + * the ticket this registration purchased, or the datetime they have registered |
|
1340 | + * to attend) |
|
1341 | + * |
|
1342 | + * @return EE_Datetime_Ticket |
|
1343 | + * @throws EE_Error |
|
1344 | + */ |
|
1345 | + public function datetime_ticket() |
|
1346 | + { |
|
1347 | + return $this->get_first_related('Datetime_Ticket'); |
|
1348 | + } |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Sets the registration's datetime_ticket. |
|
1353 | + * |
|
1354 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
1355 | + * @return EE_Datetime_Ticket |
|
1356 | + * @throws EE_Error |
|
1357 | + */ |
|
1358 | + public function set_datetime_ticket($datetime_ticket) |
|
1359 | + { |
|
1360 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1361 | + } |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Gets deleted |
|
1365 | + * |
|
1366 | + * @return bool |
|
1367 | + * @throws EE_Error |
|
1368 | + */ |
|
1369 | + public function deleted() |
|
1370 | + { |
|
1371 | + return $this->get('REG_deleted'); |
|
1372 | + } |
|
1373 | + |
|
1374 | + /** |
|
1375 | + * Sets deleted |
|
1376 | + * |
|
1377 | + * @param boolean $deleted |
|
1378 | + * @return bool |
|
1379 | + * @throws EE_Error |
|
1380 | + * @throws RuntimeException |
|
1381 | + */ |
|
1382 | + public function set_deleted($deleted) |
|
1383 | + { |
|
1384 | + if ($deleted) { |
|
1385 | + $this->delete(); |
|
1386 | + } else { |
|
1387 | + $this->restore(); |
|
1388 | + } |
|
1389 | + } |
|
1390 | + |
|
1391 | + |
|
1392 | + /** |
|
1393 | + * Get the status object of this object |
|
1394 | + * |
|
1395 | + * @return EE_Status |
|
1396 | + * @throws EE_Error |
|
1397 | + */ |
|
1398 | + public function status_obj() |
|
1399 | + { |
|
1400 | + return $this->get_first_related('Status'); |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + /** |
|
1405 | + * Returns the number of times this registration has checked into any of the datetimes |
|
1406 | + * its available for |
|
1407 | + * |
|
1408 | + * @return int |
|
1409 | + * @throws EE_Error |
|
1410 | + */ |
|
1411 | + public function count_checkins() |
|
1412 | + { |
|
1413 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
1414 | + } |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1419 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1420 | + * |
|
1421 | + * @return int |
|
1422 | + * @throws EE_Error |
|
1423 | + */ |
|
1424 | + public function count_checkins_not_checkedout() |
|
1425 | + { |
|
1426 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1427 | + } |
|
1428 | + |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1432 | + * |
|
1433 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1434 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1435 | + * consider registration status as well as datetime access. |
|
1436 | + * @return bool |
|
1437 | + * @throws EE_Error |
|
1438 | + */ |
|
1439 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1440 | + { |
|
1441 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1442 | + |
|
1443 | + // first check registration status |
|
1444 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1445 | + return false; |
|
1446 | + } |
|
1447 | + // is there a datetime ticket that matches this dtt_ID? |
|
1448 | + if ( |
|
1449 | + ! (EEM_Datetime_Ticket::instance()->exists( |
|
1450 | + array( |
|
1451 | + array( |
|
1452 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
1453 | + 'DTT_ID' => $DTT_ID, |
|
1454 | + ), |
|
1455 | + ) |
|
1456 | + )) |
|
1457 | + ) { |
|
1458 | + return false; |
|
1459 | + } |
|
1460 | + |
|
1461 | + // final check is against TKT_uses |
|
1462 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1463 | + } |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1468 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1469 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1470 | + * then return false. Otherwise return true. |
|
1471 | + * |
|
1472 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1473 | + * @return bool true means can checkin. false means cannot checkin. |
|
1474 | + * @throws EE_Error |
|
1475 | + */ |
|
1476 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1477 | + { |
|
1478 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1479 | + |
|
1480 | + if (! $DTT_ID) { |
|
1481 | + return false; |
|
1482 | + } |
|
1483 | + |
|
1484 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1485 | + |
|
1486 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
1487 | + // check-in or not. |
|
1488 | + if (! $max_uses || $max_uses === EE_INF) { |
|
1489 | + return true; |
|
1490 | + } |
|
1491 | + |
|
1492 | + // does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1493 | + // go ahead and toggle. |
|
1494 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1495 | + return true; |
|
1496 | + } |
|
1497 | + |
|
1498 | + // made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1499 | + // disallows further check-ins. |
|
1500 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count( |
|
1501 | + array( |
|
1502 | + array( |
|
1503 | + 'REG_ID' => $this->ID(), |
|
1504 | + 'CHK_in' => true, |
|
1505 | + ), |
|
1506 | + ), |
|
1507 | + 'DTT_ID', |
|
1508 | + true |
|
1509 | + ); |
|
1510 | + // checkins have already reached their max number of uses |
|
1511 | + // so registrant can NOT checkin |
|
1512 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
1513 | + EE_Error::add_error( |
|
1514 | + esc_html__( |
|
1515 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1516 | + 'event_espresso' |
|
1517 | + ), |
|
1518 | + __FILE__, |
|
1519 | + __FUNCTION__, |
|
1520 | + __LINE__ |
|
1521 | + ); |
|
1522 | + return false; |
|
1523 | + } |
|
1524 | + return true; |
|
1525 | + } |
|
1526 | + |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * toggle Check-in status for this registration |
|
1530 | + * Check-ins are toggled in the following order: |
|
1531 | + * never checked in -> checked in |
|
1532 | + * checked in -> checked out |
|
1533 | + * checked out -> checked in |
|
1534 | + * |
|
1535 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1536 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
1537 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1538 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
1539 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1540 | + * @throws EE_Error |
|
1541 | + */ |
|
1542 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1543 | + { |
|
1544 | + if (empty($DTT_ID)) { |
|
1545 | + $datetime = $this->get_latest_related_datetime(); |
|
1546 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1547 | + // verify the registration can checkin for the given DTT_ID |
|
1548 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1549 | + EE_Error::add_error( |
|
1550 | + sprintf( |
|
1551 | + esc_html__( |
|
1552 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1553 | + 'event_espresso' |
|
1554 | + ), |
|
1555 | + $this->ID(), |
|
1556 | + $DTT_ID |
|
1557 | + ), |
|
1558 | + __FILE__, |
|
1559 | + __FUNCTION__, |
|
1560 | + __LINE__ |
|
1561 | + ); |
|
1562 | + return false; |
|
1563 | + } |
|
1564 | + $status_paths = array( |
|
1565 | + EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
1566 | + EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
1567 | + EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
1568 | + ); |
|
1569 | + // start by getting the current status so we know what status we'll be changing to. |
|
1570 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1571 | + $status_to = $status_paths[ $cur_status ]; |
|
1572 | + // database only records true for checked IN or false for checked OUT |
|
1573 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1574 | + $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
1575 | + // add relation - note Check-ins are always creating new rows |
|
1576 | + // because we are keeping track of Check-ins over time. |
|
1577 | + // Eventually we'll probably want to show a list table |
|
1578 | + // for the individual Check-ins so that they can be managed. |
|
1579 | + $checkin = EE_Checkin::new_instance( |
|
1580 | + array( |
|
1581 | + 'REG_ID' => $this->ID(), |
|
1582 | + 'DTT_ID' => $DTT_ID, |
|
1583 | + 'CHK_in' => $new_status, |
|
1584 | + ) |
|
1585 | + ); |
|
1586 | + // if the record could not be saved then return false |
|
1587 | + if ($checkin->save() === 0) { |
|
1588 | + if (WP_DEBUG) { |
|
1589 | + global $wpdb; |
|
1590 | + $error = sprintf( |
|
1591 | + esc_html__( |
|
1592 | + 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
1593 | + 'event_espresso' |
|
1594 | + ), |
|
1595 | + '<br />', |
|
1596 | + $wpdb->last_error |
|
1597 | + ); |
|
1598 | + } else { |
|
1599 | + $error = esc_html__( |
|
1600 | + 'Registration check in update failed because of an unknown database error', |
|
1601 | + 'event_espresso' |
|
1602 | + ); |
|
1603 | + } |
|
1604 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1605 | + return false; |
|
1606 | + } |
|
1607 | + // Fire a checked_in and checkout_out action. |
|
1608 | + $checked_status = $status_to === EE_Checkin::status_checked_in ? 'checked_in' : 'checked_out'; |
|
1609 | + do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID); |
|
1610 | + return $status_to; |
|
1611 | + } |
|
1612 | + |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1616 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
1617 | + * |
|
1618 | + * @return EE_Datetime|null |
|
1619 | + * @throws EE_Error |
|
1620 | + */ |
|
1621 | + public function get_latest_related_datetime() |
|
1622 | + { |
|
1623 | + return EEM_Datetime::instance()->get_one( |
|
1624 | + array( |
|
1625 | + array( |
|
1626 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1627 | + ), |
|
1628 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1629 | + ) |
|
1630 | + ); |
|
1631 | + } |
|
1632 | + |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1636 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1637 | + * |
|
1638 | + * @throws EE_Error |
|
1639 | + */ |
|
1640 | + public function get_earliest_related_datetime() |
|
1641 | + { |
|
1642 | + return EEM_Datetime::instance()->get_one( |
|
1643 | + array( |
|
1644 | + array( |
|
1645 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1646 | + ), |
|
1647 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1648 | + ) |
|
1649 | + ); |
|
1650 | + } |
|
1651 | + |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
1655 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
1656 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1657 | + * |
|
1658 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
1659 | + * (if empty we'll get the primary datetime for |
|
1660 | + * this registration (via event) and use it's ID); |
|
1661 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1662 | + * |
|
1663 | + * @return int Integer representing Check-in status. |
|
1664 | + * @throws EE_Error |
|
1665 | + */ |
|
1666 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1667 | + { |
|
1668 | + $checkin_query_params = array( |
|
1669 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1670 | + ); |
|
1671 | + |
|
1672 | + if ($DTT_ID > 0) { |
|
1673 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1674 | + } |
|
1675 | + |
|
1676 | + // get checkin object (if exists) |
|
1677 | + $checkin = $checkin instanceof EE_Checkin |
|
1678 | + ? $checkin |
|
1679 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
1680 | + if ($checkin instanceof EE_Checkin) { |
|
1681 | + if ($checkin->get('CHK_in')) { |
|
1682 | + return EE_Checkin::status_checked_in; // checked in |
|
1683 | + } |
|
1684 | + return EE_Checkin::status_checked_out; // had checked in but is now checked out. |
|
1685 | + } |
|
1686 | + return EE_Checkin::status_checked_never; // never been checked in |
|
1687 | + } |
|
1688 | + |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * This method returns a localized message for the toggled Check-in message. |
|
1692 | + * |
|
1693 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1694 | + * then it is assumed Check-in for primary datetime was toggled. |
|
1695 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1696 | + * message can be customized with the attendee name. |
|
1697 | + * @return string internationalized message |
|
1698 | + * @throws EE_Error |
|
1699 | + */ |
|
1700 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
1701 | + { |
|
1702 | + // let's get the attendee first so we can include the name of the attendee |
|
1703 | + $attendee = $this->get_first_related('Attendee'); |
|
1704 | + if ($attendee instanceof EE_Attendee) { |
|
1705 | + if ($error) { |
|
1706 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1707 | + } |
|
1708 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1709 | + // what is the status message going to be? |
|
1710 | + switch ($cur_status) { |
|
1711 | + case EE_Checkin::status_checked_never: |
|
1712 | + return sprintf( |
|
1713 | + __("%s has been removed from Check-in records", "event_espresso"), |
|
1714 | + $attendee->full_name() |
|
1715 | + ); |
|
1716 | + break; |
|
1717 | + case EE_Checkin::status_checked_in: |
|
1718 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1719 | + break; |
|
1720 | + case EE_Checkin::status_checked_out: |
|
1721 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1722 | + break; |
|
1723 | + } |
|
1724 | + } |
|
1725 | + return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
1726 | + } |
|
1727 | + |
|
1728 | + |
|
1729 | + /** |
|
1730 | + * Returns the related EE_Transaction to this registration |
|
1731 | + * |
|
1732 | + * @return EE_Transaction |
|
1733 | + * @throws EE_Error |
|
1734 | + * @throws EntityNotFoundException |
|
1735 | + */ |
|
1736 | + public function transaction() |
|
1737 | + { |
|
1738 | + $transaction = $this->get_first_related('Transaction'); |
|
1739 | + if (! $transaction instanceof \EE_Transaction) { |
|
1740 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1741 | + } |
|
1742 | + return $transaction; |
|
1743 | + } |
|
1744 | + |
|
1745 | + |
|
1746 | + /** |
|
1747 | + * get Registration Code |
|
1748 | + */ |
|
1749 | + public function reg_code() |
|
1750 | + { |
|
1751 | + return $this->get('REG_code'); |
|
1752 | + } |
|
1753 | + |
|
1754 | + |
|
1755 | + /** |
|
1756 | + * get Transaction ID |
|
1757 | + */ |
|
1758 | + public function transaction_ID() |
|
1759 | + { |
|
1760 | + return $this->get('TXN_ID'); |
|
1761 | + } |
|
1762 | + |
|
1763 | + |
|
1764 | + /** |
|
1765 | + * @return int |
|
1766 | + * @throws EE_Error |
|
1767 | + */ |
|
1768 | + public function ticket_ID() |
|
1769 | + { |
|
1770 | + return $this->get('TKT_ID'); |
|
1771 | + } |
|
1772 | + |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Set Registration Code |
|
1776 | + * |
|
1777 | + * @access public |
|
1778 | + * @param string $REG_code Registration Code |
|
1779 | + * @param boolean $use_default |
|
1780 | + * @throws EE_Error |
|
1781 | + */ |
|
1782 | + public function set_reg_code($REG_code, $use_default = false) |
|
1783 | + { |
|
1784 | + if (empty($REG_code)) { |
|
1785 | + EE_Error::add_error( |
|
1786 | + esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
1787 | + __FILE__, |
|
1788 | + __FUNCTION__, |
|
1789 | + __LINE__ |
|
1790 | + ); |
|
1791 | + return; |
|
1792 | + } |
|
1793 | + if (! $this->reg_code()) { |
|
1794 | + parent::set('REG_code', $REG_code, $use_default); |
|
1795 | + } else { |
|
1796 | + EE_Error::doing_it_wrong( |
|
1797 | + __CLASS__ . '::' . __FUNCTION__, |
|
1798 | + esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1799 | + '4.6.0' |
|
1800 | + ); |
|
1801 | + } |
|
1802 | + } |
|
1803 | + |
|
1804 | + |
|
1805 | + /** |
|
1806 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1807 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1808 | + * $registration->transaction()->registrations(); |
|
1809 | + * |
|
1810 | + * @since 4.5.0 |
|
1811 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1812 | + * @throws EE_Error |
|
1813 | + */ |
|
1814 | + public function get_all_other_registrations_in_group() |
|
1815 | + { |
|
1816 | + if ($this->group_size() < 2) { |
|
1817 | + return array(); |
|
1818 | + } |
|
1819 | + |
|
1820 | + $query[0] = array( |
|
1821 | + 'TXN_ID' => $this->transaction_ID(), |
|
1822 | + 'REG_ID' => array('!=', $this->ID()), |
|
1823 | + 'TKT_ID' => $this->ticket_ID(), |
|
1824 | + ); |
|
1825 | + /** @var EE_Registration[] $registrations */ |
|
1826 | + $registrations = $this->get_model()->get_all($query); |
|
1827 | + return $registrations; |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * Return the link to the admin details for the object. |
|
1832 | + * |
|
1833 | + * @return string |
|
1834 | + * @throws EE_Error |
|
1835 | + */ |
|
1836 | + public function get_admin_details_link() |
|
1837 | + { |
|
1838 | + EE_Registry::instance()->load_helper('URL'); |
|
1839 | + return EEH_URL::add_query_args_and_nonce( |
|
1840 | + array( |
|
1841 | + 'page' => 'espresso_registrations', |
|
1842 | + 'action' => 'view_registration', |
|
1843 | + '_REG_ID' => $this->ID(), |
|
1844 | + ), |
|
1845 | + admin_url('admin.php') |
|
1846 | + ); |
|
1847 | + } |
|
1848 | + |
|
1849 | + /** |
|
1850 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1851 | + * |
|
1852 | + * @return string |
|
1853 | + * @throws EE_Error |
|
1854 | + */ |
|
1855 | + public function get_admin_edit_link() |
|
1856 | + { |
|
1857 | + return $this->get_admin_details_link(); |
|
1858 | + } |
|
1859 | + |
|
1860 | + /** |
|
1861 | + * Returns the link to a settings page for the object. |
|
1862 | + * |
|
1863 | + * @return string |
|
1864 | + * @throws EE_Error |
|
1865 | + */ |
|
1866 | + public function get_admin_settings_link() |
|
1867 | + { |
|
1868 | + return $this->get_admin_details_link(); |
|
1869 | + } |
|
1870 | + |
|
1871 | + /** |
|
1872 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1873 | + * |
|
1874 | + * @return string |
|
1875 | + */ |
|
1876 | + public function get_admin_overview_link() |
|
1877 | + { |
|
1878 | + EE_Registry::instance()->load_helper('URL'); |
|
1879 | + return EEH_URL::add_query_args_and_nonce( |
|
1880 | + array( |
|
1881 | + 'page' => 'espresso_registrations', |
|
1882 | + ), |
|
1883 | + admin_url('admin.php') |
|
1884 | + ); |
|
1885 | + } |
|
1886 | + |
|
1887 | + |
|
1888 | + /** |
|
1889 | + * @param array $query_params |
|
1890 | + * |
|
1891 | + * @return \EE_Registration[] |
|
1892 | + * @throws EE_Error |
|
1893 | + */ |
|
1894 | + public function payments($query_params = array()) |
|
1895 | + { |
|
1896 | + return $this->get_many_related('Payment', $query_params); |
|
1897 | + } |
|
1898 | + |
|
1899 | + |
|
1900 | + /** |
|
1901 | + * @param array $query_params |
|
1902 | + * |
|
1903 | + * @return \EE_Registration_Payment[] |
|
1904 | + * @throws EE_Error |
|
1905 | + */ |
|
1906 | + public function registration_payments($query_params = array()) |
|
1907 | + { |
|
1908 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
1909 | + } |
|
1910 | + |
|
1911 | + |
|
1912 | + /** |
|
1913 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1914 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
1915 | + * |
|
1916 | + * @return EE_Payment_Method|null |
|
1917 | + */ |
|
1918 | + public function payment_method() |
|
1919 | + { |
|
1920 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1921 | + } |
|
1922 | + |
|
1923 | + |
|
1924 | + /** |
|
1925 | + * @return \EE_Line_Item |
|
1926 | + * @throws EntityNotFoundException |
|
1927 | + * @throws EE_Error |
|
1928 | + */ |
|
1929 | + public function ticket_line_item() |
|
1930 | + { |
|
1931 | + $ticket = $this->ticket(); |
|
1932 | + $transaction = $this->transaction(); |
|
1933 | + $line_item = null; |
|
1934 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1935 | + $transaction->total_line_item(), |
|
1936 | + 'Ticket', |
|
1937 | + array($ticket->ID()) |
|
1938 | + ); |
|
1939 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
1940 | + if ( |
|
1941 | + $ticket_line_item instanceof \EE_Line_Item |
|
1942 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1943 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1944 | + ) { |
|
1945 | + $line_item = $ticket_line_item; |
|
1946 | + break; |
|
1947 | + } |
|
1948 | + } |
|
1949 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1950 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1951 | + } |
|
1952 | + return $line_item; |
|
1953 | + } |
|
1954 | + |
|
1955 | + |
|
1956 | + /** |
|
1957 | + * Soft Deletes this model object. |
|
1958 | + * |
|
1959 | + * @return boolean | int |
|
1960 | + * @throws RuntimeException |
|
1961 | + * @throws EE_Error |
|
1962 | + */ |
|
1963 | + public function delete() |
|
1964 | + { |
|
1965 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1966 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
1967 | + } |
|
1968 | + return parent::delete(); |
|
1969 | + } |
|
1970 | + |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1974 | + * |
|
1975 | + * @throws EE_Error |
|
1976 | + * @throws RuntimeException |
|
1977 | + */ |
|
1978 | + public function restore() |
|
1979 | + { |
|
1980 | + $previous_status = $this->get_extra_meta( |
|
1981 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1982 | + true, |
|
1983 | + EEM_Registration::status_id_cancelled |
|
1984 | + ); |
|
1985 | + if ($previous_status) { |
|
1986 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1987 | + $this->set_status($previous_status); |
|
1988 | + } |
|
1989 | + return parent::restore(); |
|
1990 | + } |
|
1991 | + |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
1995 | + * |
|
1996 | + * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
1997 | + * depending on whether the reg status changes to or from "Approved" |
|
1998 | + * @return boolean whether the Registration status was updated |
|
1999 | + * @throws EE_Error |
|
2000 | + * @throws RuntimeException |
|
2001 | + */ |
|
2002 | + public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
2003 | + { |
|
2004 | + $paid = $this->paid(); |
|
2005 | + $price = $this->final_price(); |
|
2006 | + switch (true) { |
|
2007 | + // overpaid or paid |
|
2008 | + case EEH_Money::compare_floats($paid, $price, '>'): |
|
2009 | + case EEH_Money::compare_floats($paid, $price): |
|
2010 | + $new_status = EEM_Registration::status_id_approved; |
|
2011 | + break; |
|
2012 | + // underpaid |
|
2013 | + case EEH_Money::compare_floats($paid, $price, '<'): |
|
2014 | + $new_status = EEM_Registration::status_id_pending_payment; |
|
2015 | + break; |
|
2016 | + // uhhh Houston... |
|
2017 | + default: |
|
2018 | + throw new RuntimeException( |
|
2019 | + esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
2020 | + ); |
|
2021 | + } |
|
2022 | + if ($new_status !== $this->status_ID()) { |
|
2023 | + if ($trigger_set_status_logic) { |
|
2024 | + return $this->set_status($new_status); |
|
2025 | + } |
|
2026 | + parent::set('STS_ID', $new_status); |
|
2027 | + return true; |
|
2028 | + } |
|
2029 | + return false; |
|
2030 | + } |
|
2031 | + |
|
2032 | + |
|
2033 | + /*************************** DEPRECATED ***************************/ |
|
2034 | + |
|
2035 | + |
|
2036 | + /** |
|
2037 | + * @deprecated |
|
2038 | + * @since 4.7.0 |
|
2039 | + * @access public |
|
2040 | + */ |
|
2041 | + public function price_paid() |
|
2042 | + { |
|
2043 | + EE_Error::doing_it_wrong( |
|
2044 | + 'EE_Registration::price_paid()', |
|
2045 | + esc_html__( |
|
2046 | + 'This method is deprecated, please use EE_Registration::final_price() instead.', |
|
2047 | + 'event_espresso' |
|
2048 | + ), |
|
2049 | + '4.7.0' |
|
2050 | + ); |
|
2051 | + return $this->final_price(); |
|
2052 | + } |
|
2053 | + |
|
2054 | + |
|
2055 | + /** |
|
2056 | + * @deprecated |
|
2057 | + * @since 4.7.0 |
|
2058 | + * @access public |
|
2059 | + * @param float $REG_final_price |
|
2060 | + * @throws EE_Error |
|
2061 | + * @throws RuntimeException |
|
2062 | + */ |
|
2063 | + public function set_price_paid($REG_final_price = 0.00) |
|
2064 | + { |
|
2065 | + EE_Error::doing_it_wrong( |
|
2066 | + 'EE_Registration::set_price_paid()', |
|
2067 | + esc_html__( |
|
2068 | + 'This method is deprecated, please use EE_Registration::set_final_price() instead.', |
|
2069 | + 'event_espresso' |
|
2070 | + ), |
|
2071 | + '4.7.0' |
|
2072 | + ); |
|
2073 | + $this->set_final_price($REG_final_price); |
|
2074 | + } |
|
2075 | + |
|
2076 | + |
|
2077 | + /** |
|
2078 | + * @deprecated |
|
2079 | + * @since 4.7.0 |
|
2080 | + * @return string |
|
2081 | + * @throws EE_Error |
|
2082 | + */ |
|
2083 | + public function pretty_price_paid() |
|
2084 | + { |
|
2085 | + EE_Error::doing_it_wrong( |
|
2086 | + 'EE_Registration::pretty_price_paid()', |
|
2087 | + esc_html__( |
|
2088 | + 'This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
2089 | + 'event_espresso' |
|
2090 | + ), |
|
2091 | + '4.7.0' |
|
2092 | + ); |
|
2093 | + return $this->pretty_final_price(); |
|
2094 | + } |
|
2095 | + |
|
2096 | + |
|
2097 | + /** |
|
2098 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
2099 | + * |
|
2100 | + * @deprecated 4.9.17 |
|
2101 | + * @return EE_Datetime |
|
2102 | + * @throws EE_Error |
|
2103 | + * @throws EntityNotFoundException |
|
2104 | + */ |
|
2105 | + public function get_related_primary_datetime() |
|
2106 | + { |
|
2107 | + EE_Error::doing_it_wrong( |
|
2108 | + __METHOD__, |
|
2109 | + esc_html__( |
|
2110 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
2111 | + 'event_espresso' |
|
2112 | + ), |
|
2113 | + '4.9.17', |
|
2114 | + '5.0.0' |
|
2115 | + ); |
|
2116 | + return $this->event()->primary_datetime(); |
|
2117 | + } |
|
2118 | + |
|
2119 | + /** |
|
2120 | + * Returns the contact's name (or "Unknown" if there is no contact.) |
|
2121 | + * @since $VID:$ |
|
2122 | + * @return string |
|
2123 | + * @throws EE_Error |
|
2124 | + * @throws InvalidArgumentException |
|
2125 | + * @throws InvalidDataTypeException |
|
2126 | + * @throws InvalidInterfaceException |
|
2127 | + * @throws ReflectionException |
|
2128 | + */ |
|
2129 | + public function name() |
|
2130 | + { |
|
2131 | + return $this->attendeeName(); |
|
2132 | + } |
|
2133 | 2133 | } |