@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $email_address, |
35 | 35 | $this->getAtIndex($email_address) |
36 | 36 | ); |
37 | - if (! checkdnsrr($domain, 'MX')) { |
|
37 | + if ( ! checkdnsrr($domain, 'MX')) { |
|
38 | 38 | // domain not found in MX records |
39 | 39 | throw new EmailValidationException( |
40 | 40 | __( |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ) |
46 | 46 | ); |
47 | 47 | } |
48 | - if (! checkdnsrr($domain, 'A')) { |
|
48 | + if ( ! checkdnsrr($domain, 'A')) { |
|
49 | 49 | // domain not found in A records |
50 | 50 | throw new EmailValidationException( |
51 | 51 | __( |
@@ -15,43 +15,43 @@ |
||
15 | 15 | class InternationalDNS extends International |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Validates the email in teh same way as the parent, but also |
|
20 | - * verifies the domain exists. |
|
21 | - * |
|
22 | - * @param string $email_address |
|
23 | - * @return bool |
|
24 | - * @throws EmailValidationException |
|
25 | - */ |
|
26 | - public function validate($email_address) |
|
27 | - { |
|
28 | - parent::validate($email_address); |
|
29 | - $domain = $this->getDomainPartOfEmail( |
|
30 | - $email_address, |
|
31 | - $this->getAtIndex($email_address) |
|
32 | - ); |
|
33 | - if (! checkdnsrr($domain, 'MX')) { |
|
34 | - // domain not found in MX records |
|
35 | - throw new EmailValidationException( |
|
36 | - __( |
|
37 | - // @codingStandardsIgnoreStart |
|
38 | - 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
39 | - // @codingStandardsIgnoreEnd |
|
40 | - 'event_espresso' |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - if (! checkdnsrr($domain, 'A')) { |
|
45 | - // domain not found in A records |
|
46 | - throw new EmailValidationException( |
|
47 | - __( |
|
48 | - // @codingStandardsIgnoreStart |
|
49 | - 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
50 | - // @codingStandardsIgnoreEnd |
|
51 | - 'event_espresso' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
55 | - return true; |
|
56 | - } |
|
18 | + /** |
|
19 | + * Validates the email in teh same way as the parent, but also |
|
20 | + * verifies the domain exists. |
|
21 | + * |
|
22 | + * @param string $email_address |
|
23 | + * @return bool |
|
24 | + * @throws EmailValidationException |
|
25 | + */ |
|
26 | + public function validate($email_address) |
|
27 | + { |
|
28 | + parent::validate($email_address); |
|
29 | + $domain = $this->getDomainPartOfEmail( |
|
30 | + $email_address, |
|
31 | + $this->getAtIndex($email_address) |
|
32 | + ); |
|
33 | + if (! checkdnsrr($domain, 'MX')) { |
|
34 | + // domain not found in MX records |
|
35 | + throw new EmailValidationException( |
|
36 | + __( |
|
37 | + // @codingStandardsIgnoreStart |
|
38 | + 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
39 | + // @codingStandardsIgnoreEnd |
|
40 | + 'event_espresso' |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + if (! checkdnsrr($domain, 'A')) { |
|
45 | + // domain not found in A records |
|
46 | + throw new EmailValidationException( |
|
47 | + __( |
|
48 | + // @codingStandardsIgnoreStart |
|
49 | + 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
50 | + // @codingStandardsIgnoreEnd |
|
51 | + 'event_espresso' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | + return true; |
|
56 | + } |
|
57 | 57 | } |
@@ -18,14 +18,14 @@ |
||
18 | 18 | interface EmailValidatorInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Validates the supplied email address. If it is invalid, throws EmailValidationException |
|
23 | - * |
|
24 | - * @param string $email_address |
|
25 | - * @return boolean |
|
26 | - * @throws EmailValidationException |
|
27 | - */ |
|
28 | - public function validate($email_address); |
|
21 | + /** |
|
22 | + * Validates the supplied email address. If it is invalid, throws EmailValidationException |
|
23 | + * |
|
24 | + * @param string $email_address |
|
25 | + * @return boolean |
|
26 | + * @throws EmailValidationException |
|
27 | + */ |
|
28 | + public function validate($email_address); |
|
29 | 29 | |
30 | 30 | |
31 | 31 | } |
@@ -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,430 +12,430 @@ |
||
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; |
|
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_address = 'address'; |
|
92 | - |
|
93 | - const system_question_address2 = 'address2'; |
|
94 | - |
|
95 | - const system_question_city = 'city'; |
|
96 | - |
|
97 | - const system_question_state = 'state'; |
|
98 | - |
|
99 | - const system_question_country = 'country'; |
|
100 | - |
|
101 | - const system_question_zip = 'zip'; |
|
102 | - |
|
103 | - const system_question_phone = 'phone'; |
|
104 | - |
|
105 | - /** |
|
106 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
107 | - * also all the values of QST_system in the questions table, and values |
|
108 | - * are their corresponding Attendee field names |
|
109 | - * |
|
110 | - * @var array |
|
111 | - */ |
|
112 | - protected $_system_question_to_attendee_field_name = array( |
|
113 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
114 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
115 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
116 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
117 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
118 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
119 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
120 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
121 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
122 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
123 | - ); |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * EEM_Attendee constructor. |
|
129 | - * |
|
130 | - * @param null $timezone |
|
131 | - * @param ModelFieldFactory $model_field_factory |
|
132 | - * @throws EE_Error |
|
133 | - * @throws InvalidArgumentException |
|
134 | - */ |
|
135 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
136 | - { |
|
137 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
138 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
139 | - $this->_tables = array( |
|
140 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
141 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
142 | - 'esp_attendee_meta', |
|
143 | - 'ATTM_ID', |
|
144 | - 'ATT_ID' |
|
145 | - ), |
|
146 | - ); |
|
147 | - $this->_fields = array( |
|
148 | - 'Attendee_CPT' => array( |
|
149 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
150 | - 'ID', |
|
151 | - esc_html__('Attendee ID', 'event_espresso') |
|
152 | - ), |
|
153 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
154 | - 'post_title', |
|
155 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
156 | - false, |
|
157 | - esc_html__('Unknown', 'event_espresso') |
|
158 | - ), |
|
159 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
160 | - 'post_content', |
|
161 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
162 | - false, |
|
163 | - esc_html__('No Biography Provided', 'event_espresso') |
|
164 | - ), |
|
165 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
166 | - 'post_name', |
|
167 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
168 | - ), |
|
169 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
170 | - 'post_date', |
|
171 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
172 | - ), |
|
173 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
174 | - 'post_excerpt', |
|
175 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
176 | - true, |
|
177 | - esc_html__('No Biography Provided', 'event_espresso') |
|
178 | - ), |
|
179 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
180 | - 'post_modified', |
|
181 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
182 | - ), |
|
183 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
184 | - 'post_author', |
|
185 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
186 | - false |
|
187 | - ), |
|
188 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
189 | - 'post_parent', |
|
190 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
191 | - false, |
|
192 | - 0 |
|
193 | - ), |
|
194 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
195 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
196 | - 'post_status', |
|
197 | - esc_html__('Attendee Status', 'event_espresso'), |
|
198 | - false, |
|
199 | - 'publish' |
|
200 | - ), |
|
201 | - 'password' => new EE_Password_Field( |
|
202 | - 'post_password', |
|
203 | - __('Password', 'event_espresso'), |
|
204 | - false, |
|
205 | - '', |
|
206 | - array( |
|
207 | - 'ATT_bio', |
|
208 | - 'ATT_short_bio', |
|
209 | - 'ATT_address', |
|
210 | - 'ATT_address2', |
|
211 | - 'ATT_city', |
|
212 | - 'STA_ID', |
|
213 | - 'CNT_ISO', |
|
214 | - 'ATT_zip', |
|
215 | - 'ATT_email', |
|
216 | - 'ATT_phone' |
|
217 | - ) |
|
218 | - ) |
|
219 | - ), |
|
220 | - 'Attendee_Meta' => array( |
|
221 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
222 | - 'ATTM_ID', |
|
223 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
224 | - false |
|
225 | - ), |
|
226 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
227 | - 'ATT_ID', |
|
228 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
229 | - false |
|
230 | - ), |
|
231 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
232 | - 'ATT_fname', |
|
233 | - esc_html__('First Name', 'event_espresso') |
|
234 | - ), |
|
235 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
236 | - 'ATT_lname', |
|
237 | - esc_html__('Last Name', 'event_espresso') |
|
238 | - ), |
|
239 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
240 | - 'ATT_address', |
|
241 | - esc_html__('Address Part 1', 'event_espresso') |
|
242 | - ), |
|
243 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
244 | - 'ATT_address2', |
|
245 | - esc_html__('Address Part 2', 'event_espresso') |
|
246 | - ), |
|
247 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
248 | - 'ATT_city', |
|
249 | - esc_html__('City', 'event_espresso') |
|
250 | - ), |
|
251 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
252 | - 'STA_ID', |
|
253 | - esc_html__('State', 'event_espresso'), |
|
254 | - true, |
|
255 | - 0, |
|
256 | - 'State' |
|
257 | - ), |
|
258 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
259 | - 'CNT_ISO', |
|
260 | - esc_html__('Country', 'event_espresso'), |
|
261 | - true, |
|
262 | - '', |
|
263 | - 'Country' |
|
264 | - ), |
|
265 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
266 | - 'ATT_zip', |
|
267 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
268 | - ), |
|
269 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
270 | - 'ATT_email', |
|
271 | - esc_html__('Email Address', 'event_espresso') |
|
272 | - ), |
|
273 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
274 | - 'ATT_phone', |
|
275 | - esc_html__('Phone', 'event_espresso') |
|
276 | - ), |
|
277 | - ), |
|
278 | - ); |
|
279 | - $this->_model_relations = array( |
|
280 | - 'Registration' => new EE_Has_Many_Relation(), |
|
281 | - 'State' => new EE_Belongs_To_Relation(), |
|
282 | - 'Country' => new EE_Belongs_To_Relation(), |
|
283 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
284 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
285 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
286 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
287 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
288 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
289 | - ); |
|
290 | - $this->_caps_slug = 'contacts'; |
|
291 | - $this->model_chain_to_password = ''; |
|
292 | - parent::__construct($timezone); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
299 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
300 | - * |
|
301 | - * @param string $system_question_string |
|
302 | - * @return string|null if not found |
|
303 | - */ |
|
304 | - public function get_attendee_field_for_system_question($system_question_string) |
|
305 | - { |
|
306 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
307 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
308 | - : null; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
315 | - * |
|
316 | - * @return array |
|
317 | - */ |
|
318 | - public function system_question_to_attendee_field_mapping() |
|
319 | - { |
|
320 | - return $this->_system_question_to_attendee_field_name; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
327 | - * |
|
328 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
329 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
330 | - * @throws EE_Error |
|
331 | - */ |
|
332 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
333 | - { |
|
334 | - return $this->get_all( |
|
335 | - array( |
|
336 | - array( |
|
337 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
338 | - ? $transaction_id_or_obj->ID() |
|
339 | - : $transaction_id_or_obj, |
|
340 | - ), |
|
341 | - ) |
|
342 | - ); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * retrieve a single attendee from db via their ID |
|
349 | - * |
|
350 | - * @param $ATT_ID |
|
351 | - * @return mixed array on success, FALSE on fail |
|
352 | - * @deprecated |
|
353 | - */ |
|
354 | - public function get_attendee_by_ID($ATT_ID = false) |
|
355 | - { |
|
356 | - // retrieve a particular EE_Attendee |
|
357 | - return $this->get_one_by_ID($ATT_ID); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * retrieve a single attendee from db via their ID |
|
364 | - * |
|
365 | - * @param array $where_cols_n_values |
|
366 | - * @return mixed array on success, FALSE on fail |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - public function get_attendee($where_cols_n_values = array()) |
|
370 | - { |
|
371 | - if (empty($where_cols_n_values)) { |
|
372 | - return false; |
|
373 | - } |
|
374 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
375 | - if (! empty($attendee)) { |
|
376 | - return array_shift($attendee); |
|
377 | - } |
|
378 | - return false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Search for an existing Attendee record in the DB |
|
385 | - * |
|
386 | - * @param array $where_cols_n_values |
|
387 | - * @return bool|mixed |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - public function find_existing_attendee($where_cols_n_values = null) |
|
391 | - { |
|
392 | - // search by combo of first and last names plus the email address |
|
393 | - $attendee_data_keys = array( |
|
394 | - 'ATT_fname' => $this->_ATT_fname, |
|
395 | - 'ATT_lname' => $this->_ATT_lname, |
|
396 | - 'ATT_email' => $this->_ATT_email, |
|
397 | - ); |
|
398 | - // no search params means attendee object already exists. |
|
399 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
400 | - ? $where_cols_n_values |
|
401 | - : $attendee_data_keys; |
|
402 | - $valid_data = true; |
|
403 | - // check for required values |
|
404 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
405 | - ? $valid_data |
|
406 | - : false; |
|
407 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
408 | - ? $valid_data |
|
409 | - : false; |
|
410 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
411 | - ? $valid_data |
|
412 | - : false; |
|
413 | - if ($valid_data) { |
|
414 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
415 | - if ($attendee instanceof EE_Attendee) { |
|
416 | - return $attendee; |
|
417 | - } |
|
418 | - } |
|
419 | - return false; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Takes an incoming array of EE_Registration ids |
|
426 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
427 | - * |
|
428 | - * @since 4.3.0 |
|
429 | - * @param array $ids array of EE_Registration ids |
|
430 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
431 | - * @throws EE_Error |
|
432 | - */ |
|
433 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
434 | - { |
|
435 | - $ids = (array) $ids; |
|
436 | - $_where = array( |
|
437 | - 'Registration.REG_ID' => array('in', $ids), |
|
438 | - ); |
|
439 | - return $this->get_all(array($_where)); |
|
440 | - } |
|
45 | + /** |
|
46 | + * @deprecated |
|
47 | + */ |
|
48 | + const address2_question_id = 5; |
|
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_address = 'address'; |
|
92 | + |
|
93 | + const system_question_address2 = 'address2'; |
|
94 | + |
|
95 | + const system_question_city = 'city'; |
|
96 | + |
|
97 | + const system_question_state = 'state'; |
|
98 | + |
|
99 | + const system_question_country = 'country'; |
|
100 | + |
|
101 | + const system_question_zip = 'zip'; |
|
102 | + |
|
103 | + const system_question_phone = 'phone'; |
|
104 | + |
|
105 | + /** |
|
106 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
107 | + * also all the values of QST_system in the questions table, and values |
|
108 | + * are their corresponding Attendee field names |
|
109 | + * |
|
110 | + * @var array |
|
111 | + */ |
|
112 | + protected $_system_question_to_attendee_field_name = array( |
|
113 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
114 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
115 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
116 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
117 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
118 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
119 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
120 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
121 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
122 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
123 | + ); |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * EEM_Attendee constructor. |
|
129 | + * |
|
130 | + * @param null $timezone |
|
131 | + * @param ModelFieldFactory $model_field_factory |
|
132 | + * @throws EE_Error |
|
133 | + * @throws InvalidArgumentException |
|
134 | + */ |
|
135 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
136 | + { |
|
137 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
138 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
139 | + $this->_tables = array( |
|
140 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
141 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
142 | + 'esp_attendee_meta', |
|
143 | + 'ATTM_ID', |
|
144 | + 'ATT_ID' |
|
145 | + ), |
|
146 | + ); |
|
147 | + $this->_fields = array( |
|
148 | + 'Attendee_CPT' => array( |
|
149 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
150 | + 'ID', |
|
151 | + esc_html__('Attendee ID', 'event_espresso') |
|
152 | + ), |
|
153 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
154 | + 'post_title', |
|
155 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
156 | + false, |
|
157 | + esc_html__('Unknown', 'event_espresso') |
|
158 | + ), |
|
159 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
160 | + 'post_content', |
|
161 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
162 | + false, |
|
163 | + esc_html__('No Biography Provided', 'event_espresso') |
|
164 | + ), |
|
165 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
166 | + 'post_name', |
|
167 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
168 | + ), |
|
169 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
170 | + 'post_date', |
|
171 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
172 | + ), |
|
173 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
174 | + 'post_excerpt', |
|
175 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
176 | + true, |
|
177 | + esc_html__('No Biography Provided', 'event_espresso') |
|
178 | + ), |
|
179 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
180 | + 'post_modified', |
|
181 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
182 | + ), |
|
183 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
184 | + 'post_author', |
|
185 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
186 | + false |
|
187 | + ), |
|
188 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
189 | + 'post_parent', |
|
190 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
191 | + false, |
|
192 | + 0 |
|
193 | + ), |
|
194 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
195 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
196 | + 'post_status', |
|
197 | + esc_html__('Attendee Status', 'event_espresso'), |
|
198 | + false, |
|
199 | + 'publish' |
|
200 | + ), |
|
201 | + 'password' => new EE_Password_Field( |
|
202 | + 'post_password', |
|
203 | + __('Password', 'event_espresso'), |
|
204 | + false, |
|
205 | + '', |
|
206 | + array( |
|
207 | + 'ATT_bio', |
|
208 | + 'ATT_short_bio', |
|
209 | + 'ATT_address', |
|
210 | + 'ATT_address2', |
|
211 | + 'ATT_city', |
|
212 | + 'STA_ID', |
|
213 | + 'CNT_ISO', |
|
214 | + 'ATT_zip', |
|
215 | + 'ATT_email', |
|
216 | + 'ATT_phone' |
|
217 | + ) |
|
218 | + ) |
|
219 | + ), |
|
220 | + 'Attendee_Meta' => array( |
|
221 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
222 | + 'ATTM_ID', |
|
223 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
224 | + false |
|
225 | + ), |
|
226 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
227 | + 'ATT_ID', |
|
228 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
229 | + false |
|
230 | + ), |
|
231 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
232 | + 'ATT_fname', |
|
233 | + esc_html__('First Name', 'event_espresso') |
|
234 | + ), |
|
235 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
236 | + 'ATT_lname', |
|
237 | + esc_html__('Last Name', 'event_espresso') |
|
238 | + ), |
|
239 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
240 | + 'ATT_address', |
|
241 | + esc_html__('Address Part 1', 'event_espresso') |
|
242 | + ), |
|
243 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
244 | + 'ATT_address2', |
|
245 | + esc_html__('Address Part 2', 'event_espresso') |
|
246 | + ), |
|
247 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
248 | + 'ATT_city', |
|
249 | + esc_html__('City', 'event_espresso') |
|
250 | + ), |
|
251 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
252 | + 'STA_ID', |
|
253 | + esc_html__('State', 'event_espresso'), |
|
254 | + true, |
|
255 | + 0, |
|
256 | + 'State' |
|
257 | + ), |
|
258 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
259 | + 'CNT_ISO', |
|
260 | + esc_html__('Country', 'event_espresso'), |
|
261 | + true, |
|
262 | + '', |
|
263 | + 'Country' |
|
264 | + ), |
|
265 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
266 | + 'ATT_zip', |
|
267 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
268 | + ), |
|
269 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
270 | + 'ATT_email', |
|
271 | + esc_html__('Email Address', 'event_espresso') |
|
272 | + ), |
|
273 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
274 | + 'ATT_phone', |
|
275 | + esc_html__('Phone', 'event_espresso') |
|
276 | + ), |
|
277 | + ), |
|
278 | + ); |
|
279 | + $this->_model_relations = array( |
|
280 | + 'Registration' => new EE_Has_Many_Relation(), |
|
281 | + 'State' => new EE_Belongs_To_Relation(), |
|
282 | + 'Country' => new EE_Belongs_To_Relation(), |
|
283 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
284 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
285 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
286 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
287 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
288 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
289 | + ); |
|
290 | + $this->_caps_slug = 'contacts'; |
|
291 | + $this->model_chain_to_password = ''; |
|
292 | + parent::__construct($timezone); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
299 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
300 | + * |
|
301 | + * @param string $system_question_string |
|
302 | + * @return string|null if not found |
|
303 | + */ |
|
304 | + public function get_attendee_field_for_system_question($system_question_string) |
|
305 | + { |
|
306 | + return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
307 | + ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
308 | + : null; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
315 | + * |
|
316 | + * @return array |
|
317 | + */ |
|
318 | + public function system_question_to_attendee_field_mapping() |
|
319 | + { |
|
320 | + return $this->_system_question_to_attendee_field_name; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
327 | + * |
|
328 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
329 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
330 | + * @throws EE_Error |
|
331 | + */ |
|
332 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
333 | + { |
|
334 | + return $this->get_all( |
|
335 | + array( |
|
336 | + array( |
|
337 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
338 | + ? $transaction_id_or_obj->ID() |
|
339 | + : $transaction_id_or_obj, |
|
340 | + ), |
|
341 | + ) |
|
342 | + ); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * retrieve a single attendee from db via their ID |
|
349 | + * |
|
350 | + * @param $ATT_ID |
|
351 | + * @return mixed array on success, FALSE on fail |
|
352 | + * @deprecated |
|
353 | + */ |
|
354 | + public function get_attendee_by_ID($ATT_ID = false) |
|
355 | + { |
|
356 | + // retrieve a particular EE_Attendee |
|
357 | + return $this->get_one_by_ID($ATT_ID); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * retrieve a single attendee from db via their ID |
|
364 | + * |
|
365 | + * @param array $where_cols_n_values |
|
366 | + * @return mixed array on success, FALSE on fail |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + public function get_attendee($where_cols_n_values = array()) |
|
370 | + { |
|
371 | + if (empty($where_cols_n_values)) { |
|
372 | + return false; |
|
373 | + } |
|
374 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
375 | + if (! empty($attendee)) { |
|
376 | + return array_shift($attendee); |
|
377 | + } |
|
378 | + return false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Search for an existing Attendee record in the DB |
|
385 | + * |
|
386 | + * @param array $where_cols_n_values |
|
387 | + * @return bool|mixed |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + public function find_existing_attendee($where_cols_n_values = null) |
|
391 | + { |
|
392 | + // search by combo of first and last names plus the email address |
|
393 | + $attendee_data_keys = array( |
|
394 | + 'ATT_fname' => $this->_ATT_fname, |
|
395 | + 'ATT_lname' => $this->_ATT_lname, |
|
396 | + 'ATT_email' => $this->_ATT_email, |
|
397 | + ); |
|
398 | + // no search params means attendee object already exists. |
|
399 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
400 | + ? $where_cols_n_values |
|
401 | + : $attendee_data_keys; |
|
402 | + $valid_data = true; |
|
403 | + // check for required values |
|
404 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
405 | + ? $valid_data |
|
406 | + : false; |
|
407 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
408 | + ? $valid_data |
|
409 | + : false; |
|
410 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
411 | + ? $valid_data |
|
412 | + : false; |
|
413 | + if ($valid_data) { |
|
414 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
415 | + if ($attendee instanceof EE_Attendee) { |
|
416 | + return $attendee; |
|
417 | + } |
|
418 | + } |
|
419 | + return false; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Takes an incoming array of EE_Registration ids |
|
426 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
427 | + * |
|
428 | + * @since 4.3.0 |
|
429 | + * @param array $ids array of EE_Registration ids |
|
430 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
431 | + * @throws EE_Error |
|
432 | + */ |
|
433 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
434 | + { |
|
435 | + $ids = (array) $ids; |
|
436 | + $_where = array( |
|
437 | + 'Registration.REG_ID' => array('in', $ids), |
|
438 | + ); |
|
439 | + return $this->get_all(array($_where)); |
|
440 | + } |
|
441 | 441 | } |
@@ -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 |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function setActiveTickets(array $active_tickets = array()) |
176 | 176 | { |
177 | - if (! empty($active_tickets)) { |
|
177 | + if ( ! empty($active_tickets)) { |
|
178 | 178 | foreach ($active_tickets as $active_ticket) { |
179 | 179 | $this->validateTicket($active_ticket); |
180 | 180 | } |
181 | 181 | // sort incoming array by ticket quantity (asc) |
182 | 182 | usort( |
183 | 183 | $active_tickets, |
184 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
184 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
185 | 185 | if ($a->qty() === $b->qty()) { |
186 | 186 | return 0; |
187 | 187 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | private function validateTicket($ticket) |
205 | 205 | { |
206 | - if (! $ticket instanceof EE_Ticket) { |
|
206 | + if ( ! $ticket instanceof EE_Ticket) { |
|
207 | 207 | throw new DomainException( |
208 | 208 | esc_html__( |
209 | 209 | 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | ) |
255 | 255 | ); |
256 | 256 | } |
257 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
257 | + $this->datetimes[$datetime->ID()] = $datetime; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $this->tickets_sold = array(); |
328 | 328 | $this->total_spaces = array(); |
329 | 329 | $active_tickets = $this->getActiveTickets(); |
330 | - if (! empty($active_tickets)) { |
|
330 | + if ( ! empty($active_tickets)) { |
|
331 | 331 | foreach ($active_tickets as $ticket) { |
332 | 332 | $this->validateTicket($ticket); |
333 | 333 | // we need to index our data arrays using strings for the purpose of sorting, |
@@ -349,16 +349,16 @@ discard block |
||
349 | 349 | // we are going to move all of our data into the following arrays: |
350 | 350 | // datetime spaces initially represents the reg limit for each datetime, |
351 | 351 | // but this will get adjusted as tickets are accounted for |
352 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
352 | + $this->datetime_spaces[$datetime_identifier] = $reg_limit; |
|
353 | 353 | // just an array of ticket IDs grouped by datetime |
354 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
354 | + $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier; |
|
355 | 355 | // and an array of datetime IDs grouped by ticket |
356 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
356 | + $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier; |
|
357 | 357 | } |
358 | 358 | // total quantity of sold and reserved for each ticket |
359 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
359 | + $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved(); |
|
360 | 360 | // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
361 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
361 | + $this->ticket_quantities[$ticket_identifier] = $max_tickets; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | // sort datetime spaces by reg limit, but maintain our string indexes |
@@ -417,11 +417,11 @@ discard block |
||
417 | 417 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
418 | 418 | } |
419 | 419 | foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
420 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
421 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
420 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
421 | + $this->ticket_quantities[$ticket_identifier] -= $tickets_sold; |
|
422 | 422 | // don't let values go below zero |
423 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
424 | - $this->ticket_quantities[ $ticket_identifier ], |
|
423 | + $this->ticket_quantities[$ticket_identifier] = max( |
|
424 | + $this->ticket_quantities[$ticket_identifier], |
|
425 | 425 | 0 |
426 | 426 | ); |
427 | 427 | if ($this->debug) { |
@@ -433,15 +433,15 @@ discard block |
||
433 | 433 | ); |
434 | 434 | } |
435 | 435 | } |
436 | - if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
437 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
436 | + if (isset($this->ticket_datetimes[$ticket_identifier]) |
|
437 | + && is_array($this->ticket_datetimes[$ticket_identifier]) |
|
438 | 438 | ) { |
439 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
440 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
441 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
439 | + foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) { |
|
440 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
441 | + $this->datetime_spaces[$ticket_datetime] -= $tickets_sold; |
|
442 | 442 | // don't let values go below zero |
443 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
444 | - $this->datetime_spaces[ $ticket_datetime ], |
|
443 | + $this->datetime_spaces[$ticket_datetime] = max( |
|
444 | + $this->datetime_spaces[$ticket_datetime], |
|
445 | 445 | 0 |
446 | 446 | ); |
447 | 447 | if ($this->debug) { |
@@ -466,11 +466,11 @@ discard block |
||
466 | 466 | private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
467 | 467 | { |
468 | 468 | // make sure a reg limit is set for the datetime |
469 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
470 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
469 | + $reg_limit = isset($this->datetime_spaces[$datetime_identifier]) |
|
470 | + ? $this->datetime_spaces[$datetime_identifier] |
|
471 | 471 | : 0; |
472 | 472 | // and bail if it is not |
473 | - if (! $reg_limit) { |
|
473 | + if ( ! $reg_limit) { |
|
474 | 474 | if ($this->debug) { |
475 | 475 | \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
476 | 476 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | } |
488 | 488 | // number of allocated spaces always starts at zero |
489 | 489 | $spaces_allocated = 0; |
490 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
490 | + $this->total_spaces[$datetime_identifier] = 0; |
|
491 | 491 | foreach ($tickets as $ticket_identifier) { |
492 | 492 | $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
493 | 493 | $datetime_identifier, |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $spaces_allocated = max($spaces_allocated, 0); |
501 | 501 | if ($spaces_allocated) { |
502 | 502 | // track any non-zero values |
503 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
503 | + $this->total_spaces[$datetime_identifier] += $spaces_allocated; |
|
504 | 504 | if ($this->debug) { |
505 | 505 | \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
506 | 506 | } |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | } |
512 | 512 | if ($this->debug) { |
513 | 513 | \EEH_Debug_Tools::printr( |
514 | - $this->total_spaces[ $datetime_identifier ], |
|
514 | + $this->total_spaces[$datetime_identifier], |
|
515 | 515 | '$total_spaces', |
516 | 516 | __FILE__, |
517 | 517 | __LINE__ |
@@ -536,8 +536,8 @@ discard block |
||
536 | 536 | $spaces_allocated |
537 | 537 | ) { |
538 | 538 | // make sure ticket quantity is set |
539 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
540 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
539 | + $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier]) |
|
540 | + ? $this->ticket_quantities[$ticket_identifier] |
|
541 | 541 | : 0; |
542 | 542 | if ($this->debug) { |
543 | 543 | \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | // or the maximum ticket quantity |
568 | 568 | $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
569 | 569 | // adjust the available quantity in our tracking array |
570 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
570 | + $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity; |
|
571 | 571 | // and increment spaces allocated for this datetime |
572 | 572 | $spaces_allocated += $ticket_quantity; |
573 | 573 | $at_capacity = $spaces_allocated >= $reg_limit; |
@@ -624,14 +624,14 @@ discard block |
||
624 | 624 | $ticket_quantity |
625 | 625 | ); |
626 | 626 | // skip to next ticket if nothing changed |
627 | - if (! ($adjusted || $at_capacity)) { |
|
627 | + if ( ! ($adjusted || $at_capacity)) { |
|
628 | 628 | continue; |
629 | 629 | } |
630 | 630 | // then all of it's tickets are now unavailable |
631 | 631 | foreach ($datetime_tickets as $datetime_ticket) { |
632 | 632 | if (($ticket_identifier === $datetime_ticket || $at_capacity) |
633 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
634 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
633 | + && isset($this->ticket_quantities[$datetime_ticket]) |
|
634 | + && $this->ticket_quantities[$datetime_ticket] > 0 |
|
635 | 635 | ) { |
636 | 636 | if ($this->debug) { |
637 | 637 | \EEH_Debug_Tools::printr( |
@@ -645,14 +645,14 @@ discard block |
||
645 | 645 | // otherwise just subtract the ticket quantity |
646 | 646 | $new_quantity = $at_capacity |
647 | 647 | ? 0 |
648 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
648 | + : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity; |
|
649 | 649 | // don't let ticket quantity go below zero |
650 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
650 | + $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0); |
|
651 | 651 | if ($this->debug) { |
652 | 652 | \EEH_Debug_Tools::printr( |
653 | 653 | $at_capacity |
654 | 654 | ? "0 because Datetime {$datetime_identifier} is at capacity" |
655 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
655 | + : "{$this->ticket_quantities[$datetime_ticket]}", |
|
656 | 656 | " . . . . {$datetime_ticket} quantity set to ", |
657 | 657 | __FILE__, |
658 | 658 | __LINE__ |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | } |
662 | 662 | // but we also need to adjust spaces for any other datetimes this ticket has access to |
663 | 663 | if ($datetime_ticket === $ticket_identifier) { |
664 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
665 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
664 | + if (isset($this->ticket_datetimes[$datetime_ticket]) |
|
665 | + && is_array($this->ticket_datetimes[$datetime_ticket]) |
|
666 | 666 | ) { |
667 | 667 | if ($this->debug) { |
668 | 668 | \EEH_Debug_Tools::printr( |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | __LINE__ |
673 | 673 | ); |
674 | 674 | } |
675 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
675 | + foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) { |
|
676 | 676 | // don't adjust the current datetime twice |
677 | 677 | if ($datetime !== $datetime_identifier) { |
678 | 678 | $this->adjustDatetimeSpaces( |
@@ -692,24 +692,24 @@ discard block |
||
692 | 692 | { |
693 | 693 | // does datetime have spaces available? |
694 | 694 | // and does the supplied ticket have access to this datetime ? |
695 | - if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
696 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
697 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
695 | + if ($this->datetime_spaces[$datetime_identifier] > 0 |
|
696 | + && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier]) |
|
697 | + && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true) |
|
698 | 698 | ) { |
699 | 699 | if ($this->debug) { |
700 | 700 | \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
701 | 701 | \EEH_Debug_Tools::printr( |
702 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
702 | + "{$this->datetime_spaces[$datetime_identifier]}", |
|
703 | 703 | " . . current {$datetime_identifier} spaces available", |
704 | 704 | __FILE__, |
705 | 705 | __LINE__ |
706 | 706 | ); |
707 | 707 | } |
708 | 708 | // then decrement the available spaces for the datetime |
709 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
709 | + $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity; |
|
710 | 710 | // but don't let quantities go below zero |
711 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
712 | - $this->datetime_spaces[ $datetime_identifier ], |
|
711 | + $this->datetime_spaces[$datetime_identifier] = max( |
|
712 | + $this->datetime_spaces[$datetime_identifier], |
|
713 | 713 | 0 |
714 | 714 | ); |
715 | 715 | if ($this->debug) { |
@@ -26,715 +26,715 @@ |
||
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 (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
450 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
451 | - ) { |
|
452 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
453 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
454 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
455 | - // don't let values go below zero |
|
456 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
457 | - $this->datetime_spaces[ $ticket_datetime ], |
|
458 | - 0 |
|
459 | - ); |
|
460 | - if ($this->debug) { |
|
461 | - \EEH_Debug_Tools::printr( |
|
462 | - "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
463 | - 'subtracting', |
|
464 | - __FILE__, |
|
465 | - __LINE__ |
|
466 | - ); |
|
467 | - } |
|
468 | - } |
|
469 | - } |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * @param string $datetime_identifier |
|
477 | - * @param array $tickets |
|
478 | - */ |
|
479 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
480 | - { |
|
481 | - // make sure a reg limit is set for the datetime |
|
482 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
483 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
484 | - : 0; |
|
485 | - // and bail if it is not |
|
486 | - if (! $reg_limit) { |
|
487 | - if ($this->debug) { |
|
488 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
489 | - } |
|
490 | - return; |
|
491 | - } |
|
492 | - if ($this->debug) { |
|
493 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
494 | - \EEH_Debug_Tools::printr( |
|
495 | - "{$reg_limit}", |
|
496 | - 'REG LIMIT', |
|
497 | - __FILE__, |
|
498 | - __LINE__ |
|
499 | - ); |
|
500 | - } |
|
501 | - // number of allocated spaces always starts at zero |
|
502 | - $spaces_allocated = 0; |
|
503 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
504 | - foreach ($tickets as $ticket_identifier) { |
|
505 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
506 | - $datetime_identifier, |
|
507 | - $reg_limit, |
|
508 | - $ticket_identifier, |
|
509 | - $spaces_allocated |
|
510 | - ); |
|
511 | - } |
|
512 | - // spaces can't be negative |
|
513 | - $spaces_allocated = max($spaces_allocated, 0); |
|
514 | - if ($spaces_allocated) { |
|
515 | - // track any non-zero values |
|
516 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
517 | - if ($this->debug) { |
|
518 | - \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
519 | - } |
|
520 | - } else { |
|
521 | - if ($this->debug) { |
|
522 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
523 | - } |
|
524 | - } |
|
525 | - if ($this->debug) { |
|
526 | - \EEH_Debug_Tools::printr( |
|
527 | - $this->total_spaces[ $datetime_identifier ], |
|
528 | - '$total_spaces', |
|
529 | - __FILE__, |
|
530 | - __LINE__ |
|
531 | - ); |
|
532 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
533 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
534 | - } |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * @param string $datetime_identifier |
|
540 | - * @param int $reg_limit |
|
541 | - * @param string $ticket_identifier |
|
542 | - * @param int $spaces_allocated |
|
543 | - * @return int |
|
544 | - */ |
|
545 | - private function calculateAvailableSpacesForTicket( |
|
546 | - $datetime_identifier, |
|
547 | - $reg_limit, |
|
548 | - $ticket_identifier, |
|
549 | - $spaces_allocated |
|
550 | - ) { |
|
551 | - // make sure ticket quantity is set |
|
552 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
553 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
554 | - : 0; |
|
555 | - if ($this->debug) { |
|
556 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
557 | - \EEH_Debug_Tools::printr( |
|
558 | - "{$ticket_quantity}", |
|
559 | - "ticket $ticket_identifier quantity: ", |
|
560 | - __FILE__, |
|
561 | - __LINE__, |
|
562 | - 2 |
|
563 | - ); |
|
564 | - } |
|
565 | - if ($ticket_quantity) { |
|
566 | - if ($this->debug) { |
|
567 | - \EEH_Debug_Tools::printr( |
|
568 | - ($spaces_allocated <= $reg_limit) |
|
569 | - ? 'true' |
|
570 | - : 'false', |
|
571 | - ' . spaces_allocated <= reg_limit = ', |
|
572 | - __FILE__, |
|
573 | - __LINE__ |
|
574 | - ); |
|
575 | - } |
|
576 | - // if the datetime is NOT at full capacity yet |
|
577 | - if ($spaces_allocated <= $reg_limit) { |
|
578 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
579 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
580 | - // or the maximum ticket quantity |
|
581 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
582 | - // adjust the available quantity in our tracking array |
|
583 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
584 | - // and increment spaces allocated for this datetime |
|
585 | - $spaces_allocated += $ticket_quantity; |
|
586 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
587 | - if ($this->debug) { |
|
588 | - \EEH_Debug_Tools::printr( |
|
589 | - "{$ticket_quantity} {$ticket_identifier} tickets", |
|
590 | - ' > > allocate ', |
|
591 | - __FILE__, |
|
592 | - __LINE__, |
|
593 | - 3 |
|
594 | - ); |
|
595 | - if ($at_capacity) { |
|
596 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
597 | - } |
|
598 | - } |
|
599 | - // now adjust all other datetimes that allow access to this ticket |
|
600 | - $this->adjustDatetimes( |
|
601 | - $datetime_identifier, |
|
602 | - $ticket_identifier, |
|
603 | - $ticket_quantity, |
|
604 | - $at_capacity |
|
605 | - ); |
|
606 | - } |
|
607 | - } |
|
608 | - return $spaces_allocated; |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * subtracts ticket amounts from all datetime reg limits |
|
614 | - * that allow access to the ticket specified, |
|
615 | - * because that ticket could be used |
|
616 | - * to attend any of the datetimes it has access to |
|
617 | - * |
|
618 | - * @param string $datetime_identifier |
|
619 | - * @param string $ticket_identifier |
|
620 | - * @param bool $at_capacity |
|
621 | - * @param int $ticket_quantity |
|
622 | - */ |
|
623 | - private function adjustDatetimes( |
|
624 | - $datetime_identifier, |
|
625 | - $ticket_identifier, |
|
626 | - $ticket_quantity, |
|
627 | - $at_capacity |
|
628 | - ) { |
|
629 | - /** @var array $datetime_tickets */ |
|
630 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
631 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
632 | - continue; |
|
633 | - } |
|
634 | - $adjusted = $this->adjustDatetimeSpaces( |
|
635 | - $datetime_ID, |
|
636 | - $ticket_identifier, |
|
637 | - $ticket_quantity |
|
638 | - ); |
|
639 | - // skip to next ticket if nothing changed |
|
640 | - if (! ($adjusted || $at_capacity)) { |
|
641 | - continue; |
|
642 | - } |
|
643 | - // then all of it's tickets are now unavailable |
|
644 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
645 | - if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
646 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
647 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
648 | - ) { |
|
649 | - if ($this->debug) { |
|
650 | - \EEH_Debug_Tools::printr( |
|
651 | - $datetime_ticket, |
|
652 | - ' . . . adjust ticket quantities for', |
|
653 | - __FILE__, |
|
654 | - __LINE__ |
|
655 | - ); |
|
656 | - } |
|
657 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
658 | - // otherwise just subtract the ticket quantity |
|
659 | - $new_quantity = $at_capacity |
|
660 | - ? 0 |
|
661 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
662 | - // don't let ticket quantity go below zero |
|
663 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
664 | - if ($this->debug) { |
|
665 | - \EEH_Debug_Tools::printr( |
|
666 | - $at_capacity |
|
667 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
668 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
669 | - " . . . . {$datetime_ticket} quantity set to ", |
|
670 | - __FILE__, |
|
671 | - __LINE__ |
|
672 | - ); |
|
673 | - } |
|
674 | - } |
|
675 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
676 | - if ($datetime_ticket === $ticket_identifier) { |
|
677 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
678 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
679 | - ) { |
|
680 | - if ($this->debug) { |
|
681 | - \EEH_Debug_Tools::printr( |
|
682 | - $datetime_ticket, |
|
683 | - ' . . adjust other Datetimes for', |
|
684 | - __FILE__, |
|
685 | - __LINE__ |
|
686 | - ); |
|
687 | - } |
|
688 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
689 | - // don't adjust the current datetime twice |
|
690 | - if ($datetime !== $datetime_identifier) { |
|
691 | - $this->adjustDatetimeSpaces( |
|
692 | - $datetime, |
|
693 | - $datetime_ticket, |
|
694 | - $ticket_quantity |
|
695 | - ); |
|
696 | - } |
|
697 | - } |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
701 | - } |
|
702 | - } |
|
703 | - |
|
704 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
705 | - { |
|
706 | - // does datetime have spaces available? |
|
707 | - // and does the supplied ticket have access to this datetime ? |
|
708 | - if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
709 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
710 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
711 | - ) { |
|
712 | - if ($this->debug) { |
|
713 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
714 | - \EEH_Debug_Tools::printr( |
|
715 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
716 | - " . . current {$datetime_identifier} spaces available", |
|
717 | - __FILE__, |
|
718 | - __LINE__ |
|
719 | - ); |
|
720 | - } |
|
721 | - // then decrement the available spaces for the datetime |
|
722 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
723 | - // but don't let quantities go below zero |
|
724 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
725 | - $this->datetime_spaces[ $datetime_identifier ], |
|
726 | - 0 |
|
727 | - ); |
|
728 | - if ($this->debug) { |
|
729 | - \EEH_Debug_Tools::printr( |
|
730 | - "{$ticket_quantity}", |
|
731 | - " . . . {$datetime_identifier} capacity reduced by", |
|
732 | - __FILE__, |
|
733 | - __LINE__ |
|
734 | - ); |
|
735 | - } |
|
736 | - return true; |
|
737 | - } |
|
738 | - return false; |
|
739 | - } |
|
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 (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
450 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
451 | + ) { |
|
452 | + foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
453 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
454 | + $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
455 | + // don't let values go below zero |
|
456 | + $this->datetime_spaces[ $ticket_datetime ] = max( |
|
457 | + $this->datetime_spaces[ $ticket_datetime ], |
|
458 | + 0 |
|
459 | + ); |
|
460 | + if ($this->debug) { |
|
461 | + \EEH_Debug_Tools::printr( |
|
462 | + "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
463 | + 'subtracting', |
|
464 | + __FILE__, |
|
465 | + __LINE__ |
|
466 | + ); |
|
467 | + } |
|
468 | + } |
|
469 | + } |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * @param string $datetime_identifier |
|
477 | + * @param array $tickets |
|
478 | + */ |
|
479 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
480 | + { |
|
481 | + // make sure a reg limit is set for the datetime |
|
482 | + $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
483 | + ? $this->datetime_spaces[ $datetime_identifier ] |
|
484 | + : 0; |
|
485 | + // and bail if it is not |
|
486 | + if (! $reg_limit) { |
|
487 | + if ($this->debug) { |
|
488 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
489 | + } |
|
490 | + return; |
|
491 | + } |
|
492 | + if ($this->debug) { |
|
493 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
494 | + \EEH_Debug_Tools::printr( |
|
495 | + "{$reg_limit}", |
|
496 | + 'REG LIMIT', |
|
497 | + __FILE__, |
|
498 | + __LINE__ |
|
499 | + ); |
|
500 | + } |
|
501 | + // number of allocated spaces always starts at zero |
|
502 | + $spaces_allocated = 0; |
|
503 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
504 | + foreach ($tickets as $ticket_identifier) { |
|
505 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
506 | + $datetime_identifier, |
|
507 | + $reg_limit, |
|
508 | + $ticket_identifier, |
|
509 | + $spaces_allocated |
|
510 | + ); |
|
511 | + } |
|
512 | + // spaces can't be negative |
|
513 | + $spaces_allocated = max($spaces_allocated, 0); |
|
514 | + if ($spaces_allocated) { |
|
515 | + // track any non-zero values |
|
516 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
517 | + if ($this->debug) { |
|
518 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
519 | + } |
|
520 | + } else { |
|
521 | + if ($this->debug) { |
|
522 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
523 | + } |
|
524 | + } |
|
525 | + if ($this->debug) { |
|
526 | + \EEH_Debug_Tools::printr( |
|
527 | + $this->total_spaces[ $datetime_identifier ], |
|
528 | + '$total_spaces', |
|
529 | + __FILE__, |
|
530 | + __LINE__ |
|
531 | + ); |
|
532 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
533 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
534 | + } |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * @param string $datetime_identifier |
|
540 | + * @param int $reg_limit |
|
541 | + * @param string $ticket_identifier |
|
542 | + * @param int $spaces_allocated |
|
543 | + * @return int |
|
544 | + */ |
|
545 | + private function calculateAvailableSpacesForTicket( |
|
546 | + $datetime_identifier, |
|
547 | + $reg_limit, |
|
548 | + $ticket_identifier, |
|
549 | + $spaces_allocated |
|
550 | + ) { |
|
551 | + // make sure ticket quantity is set |
|
552 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
553 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
554 | + : 0; |
|
555 | + if ($this->debug) { |
|
556 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
557 | + \EEH_Debug_Tools::printr( |
|
558 | + "{$ticket_quantity}", |
|
559 | + "ticket $ticket_identifier quantity: ", |
|
560 | + __FILE__, |
|
561 | + __LINE__, |
|
562 | + 2 |
|
563 | + ); |
|
564 | + } |
|
565 | + if ($ticket_quantity) { |
|
566 | + if ($this->debug) { |
|
567 | + \EEH_Debug_Tools::printr( |
|
568 | + ($spaces_allocated <= $reg_limit) |
|
569 | + ? 'true' |
|
570 | + : 'false', |
|
571 | + ' . spaces_allocated <= reg_limit = ', |
|
572 | + __FILE__, |
|
573 | + __LINE__ |
|
574 | + ); |
|
575 | + } |
|
576 | + // if the datetime is NOT at full capacity yet |
|
577 | + if ($spaces_allocated <= $reg_limit) { |
|
578 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
579 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
580 | + // or the maximum ticket quantity |
|
581 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
582 | + // adjust the available quantity in our tracking array |
|
583 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
584 | + // and increment spaces allocated for this datetime |
|
585 | + $spaces_allocated += $ticket_quantity; |
|
586 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
587 | + if ($this->debug) { |
|
588 | + \EEH_Debug_Tools::printr( |
|
589 | + "{$ticket_quantity} {$ticket_identifier} tickets", |
|
590 | + ' > > allocate ', |
|
591 | + __FILE__, |
|
592 | + __LINE__, |
|
593 | + 3 |
|
594 | + ); |
|
595 | + if ($at_capacity) { |
|
596 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
597 | + } |
|
598 | + } |
|
599 | + // now adjust all other datetimes that allow access to this ticket |
|
600 | + $this->adjustDatetimes( |
|
601 | + $datetime_identifier, |
|
602 | + $ticket_identifier, |
|
603 | + $ticket_quantity, |
|
604 | + $at_capacity |
|
605 | + ); |
|
606 | + } |
|
607 | + } |
|
608 | + return $spaces_allocated; |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * subtracts ticket amounts from all datetime reg limits |
|
614 | + * that allow access to the ticket specified, |
|
615 | + * because that ticket could be used |
|
616 | + * to attend any of the datetimes it has access to |
|
617 | + * |
|
618 | + * @param string $datetime_identifier |
|
619 | + * @param string $ticket_identifier |
|
620 | + * @param bool $at_capacity |
|
621 | + * @param int $ticket_quantity |
|
622 | + */ |
|
623 | + private function adjustDatetimes( |
|
624 | + $datetime_identifier, |
|
625 | + $ticket_identifier, |
|
626 | + $ticket_quantity, |
|
627 | + $at_capacity |
|
628 | + ) { |
|
629 | + /** @var array $datetime_tickets */ |
|
630 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
631 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
632 | + continue; |
|
633 | + } |
|
634 | + $adjusted = $this->adjustDatetimeSpaces( |
|
635 | + $datetime_ID, |
|
636 | + $ticket_identifier, |
|
637 | + $ticket_quantity |
|
638 | + ); |
|
639 | + // skip to next ticket if nothing changed |
|
640 | + if (! ($adjusted || $at_capacity)) { |
|
641 | + continue; |
|
642 | + } |
|
643 | + // then all of it's tickets are now unavailable |
|
644 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
645 | + if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
646 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
647 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
648 | + ) { |
|
649 | + if ($this->debug) { |
|
650 | + \EEH_Debug_Tools::printr( |
|
651 | + $datetime_ticket, |
|
652 | + ' . . . adjust ticket quantities for', |
|
653 | + __FILE__, |
|
654 | + __LINE__ |
|
655 | + ); |
|
656 | + } |
|
657 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
658 | + // otherwise just subtract the ticket quantity |
|
659 | + $new_quantity = $at_capacity |
|
660 | + ? 0 |
|
661 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
662 | + // don't let ticket quantity go below zero |
|
663 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
664 | + if ($this->debug) { |
|
665 | + \EEH_Debug_Tools::printr( |
|
666 | + $at_capacity |
|
667 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
668 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
669 | + " . . . . {$datetime_ticket} quantity set to ", |
|
670 | + __FILE__, |
|
671 | + __LINE__ |
|
672 | + ); |
|
673 | + } |
|
674 | + } |
|
675 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
676 | + if ($datetime_ticket === $ticket_identifier) { |
|
677 | + if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
678 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
679 | + ) { |
|
680 | + if ($this->debug) { |
|
681 | + \EEH_Debug_Tools::printr( |
|
682 | + $datetime_ticket, |
|
683 | + ' . . adjust other Datetimes for', |
|
684 | + __FILE__, |
|
685 | + __LINE__ |
|
686 | + ); |
|
687 | + } |
|
688 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
689 | + // don't adjust the current datetime twice |
|
690 | + if ($datetime !== $datetime_identifier) { |
|
691 | + $this->adjustDatetimeSpaces( |
|
692 | + $datetime, |
|
693 | + $datetime_ticket, |
|
694 | + $ticket_quantity |
|
695 | + ); |
|
696 | + } |
|
697 | + } |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | + } |
|
702 | + } |
|
703 | + |
|
704 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
705 | + { |
|
706 | + // does datetime have spaces available? |
|
707 | + // and does the supplied ticket have access to this datetime ? |
|
708 | + if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
709 | + && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
710 | + && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
711 | + ) { |
|
712 | + if ($this->debug) { |
|
713 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
714 | + \EEH_Debug_Tools::printr( |
|
715 | + "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
716 | + " . . current {$datetime_identifier} spaces available", |
|
717 | + __FILE__, |
|
718 | + __LINE__ |
|
719 | + ); |
|
720 | + } |
|
721 | + // then decrement the available spaces for the datetime |
|
722 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
723 | + // but don't let quantities go below zero |
|
724 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
725 | + $this->datetime_spaces[ $datetime_identifier ], |
|
726 | + 0 |
|
727 | + ); |
|
728 | + if ($this->debug) { |
|
729 | + \EEH_Debug_Tools::printr( |
|
730 | + "{$ticket_quantity}", |
|
731 | + " . . . {$datetime_identifier} capacity reduced by", |
|
732 | + __FILE__, |
|
733 | + __LINE__ |
|
734 | + ); |
|
735 | + } |
|
736 | + return true; |
|
737 | + } |
|
738 | + return false; |
|
739 | + } |
|
740 | 740 | } |
@@ -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) |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $class = parent::_get_row_class($item); |
113 | 113 | // add status class |
114 | 114 | $class .= $item instanceof EE_Event |
115 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
115 | + ? ' ee-status-strip event-status-'.$item->get_active_status() |
|
116 | 116 | : ''; |
117 | 117 | if ($this->_has_checkbox_column) { |
118 | 118 | $class .= ' has-checkbox-column'; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function column_cb($item) |
143 | 143 | { |
144 | - if (! $item instanceof EE_Event) { |
|
144 | + if ( ! $item instanceof EE_Event) { |
|
145 | 145 | return ''; |
146 | 146 | } |
147 | 147 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | public function column_id(EE_Event $item) |
165 | 165 | { |
166 | 166 | $content = $item->ID(); |
167 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
167 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
168 | 168 | return $content; |
169 | 169 | } |
170 | 170 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $actions = $this->_column_name_action_setup($item); |
188 | 188 | $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
189 | 189 | $content = '<strong><a class="row-title" href="' |
190 | - . $edit_link . '">' |
|
190 | + . $edit_link.'">' |
|
191 | 191 | . $item->name() |
192 | 192 | . '</a></strong>' |
193 | 193 | . $status; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | protected function _column_name_action_setup(EE_Event $item) |
217 | 217 | { |
218 | 218 | // todo: remove when attendees is active |
219 | - if (! defined('REG_ADMIN_URL')) { |
|
219 | + if ( ! defined('REG_ADMIN_URL')) { |
|
220 | 220 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
221 | 221 | } |
222 | 222 | $actions = array(); |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | 'post' => $item->ID(), |
234 | 234 | ); |
235 | 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') . '">' |
|
236 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
237 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
238 | 238 | . esc_html__('Edit', 'event_espresso') |
239 | 239 | . '</a>'; |
240 | 240 | } |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | 'event_id' => $item->ID(), |
254 | 254 | ); |
255 | 255 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
256 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
257 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
256 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
257 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
258 | 258 | . esc_html__('Registrations', 'event_espresso') |
259 | 259 | . '</a>'; |
260 | 260 | } |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | ); |
302 | 302 | } |
303 | 303 | $view_link = get_permalink($item->ID()); |
304 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
305 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
304 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
305 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
306 | 306 | . esc_html__('View', 'event_espresso') |
307 | 307 | . '</a>'; |
308 | 308 | if ($item->get('status') === 'trash') { |
@@ -311,8 +311,8 @@ discard block |
||
311 | 311 | 'espresso_events_restore_event', |
312 | 312 | $item->ID() |
313 | 313 | )) { |
314 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
315 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
314 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
315 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
316 | 316 | . '">' |
317 | 317 | . esc_html__('Restore from Trash', 'event_espresso') |
318 | 318 | . '</a>'; |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | $item->ID() |
325 | 325 | ) |
326 | 326 | ) { |
327 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
328 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
327 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
328 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
329 | 329 | . esc_html__('Delete Permanently', 'event_espresso') |
330 | 330 | . '</a>'; |
331 | 331 | } |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | 'espresso_events_trash_event', |
336 | 336 | $item->ID() |
337 | 337 | )) { |
338 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
339 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
338 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
339 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
340 | 340 | . esc_html__('Trash', 'event_espresso') |
341 | 341 | . '</a>'; |
342 | 342 | } |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | 'EVT_wp_user' => $item->wp_user(), |
362 | 362 | ); |
363 | 363 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
364 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
365 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
364 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
365 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
366 | 366 | . $event_author->display_name |
367 | 367 | . '</a>'; |
368 | 368 | } |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | return implode( |
380 | 380 | ', ', |
381 | 381 | array_map( |
382 | - function (EE_Term $category) { |
|
382 | + function(EE_Term $category) { |
|
383 | 383 | return $category->name(); |
384 | 384 | }, |
385 | 385 | $event_categories |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | 'ee_read_registrations', |
455 | 455 | 'espresso_registrations_view_registration' |
456 | 456 | ) |
457 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
457 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
458 | 458 | : $registered_attendees; |
459 | 459 | } |
460 | 460 | |
@@ -484,13 +484,13 @@ discard block |
||
484 | 484 | public function column_actions(EE_Event $item) |
485 | 485 | { |
486 | 486 | // todo: remove when attendees is active |
487 | - if (! defined('REG_ADMIN_URL')) { |
|
487 | + if ( ! defined('REG_ADMIN_URL')) { |
|
488 | 488 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
489 | 489 | } |
490 | 490 | $action_links = array(); |
491 | 491 | $view_link = get_permalink($item->ID()); |
492 | - $action_links[] = '<a href="' . $view_link . '"' |
|
493 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
492 | + $action_links[] = '<a href="'.$view_link.'"' |
|
493 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
494 | 494 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
495 | 495 | if (EE_Registry::instance()->CAP->current_user_can( |
496 | 496 | 'ee_edit_event', |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | 'post' => $item->ID(), |
503 | 503 | ); |
504 | 504 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
505 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
506 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
505 | + $action_links[] = '<a href="'.$edit_link.'"' |
|
506 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
507 | 507 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
508 | 508 | . '</a>'; |
509 | 509 | } |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | 'event_id' => $item->ID(), |
522 | 522 | ); |
523 | 523 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
524 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
525 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
524 | + $action_links[] = '<a href="'.$attendees_link.'"' |
|
525 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
526 | 526 | . '<div class="dashicons dashicons-groups"></div>' |
527 | 527 | . '</a>'; |
528 | 528 | } |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | } |
558 | 558 | $column_array = []; |
559 | 559 | foreach ($this->_columns as $column => $column_label) { |
560 | - $column_array[ $column ] = $column_label; |
|
560 | + $column_array[$column] = $column_label; |
|
561 | 561 | if ($column === 'venue') { |
562 | 562 | $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
563 | 563 | } |
@@ -15,553 +15,553 @@ |
||
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 (EE_Registry::instance()->CAP->current_user_can( |
|
97 | - 'ee_delete_events', |
|
98 | - 'espresso_events_trash_events' |
|
99 | - )) { |
|
100 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param EE_Event $item |
|
107 | - * @return string |
|
108 | - * @throws EE_Error |
|
109 | - */ |
|
110 | - protected function _get_row_class($item) |
|
111 | - { |
|
112 | - $class = parent::_get_row_class($item); |
|
113 | - // add status class |
|
114 | - $class .= $item instanceof EE_Event |
|
115 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
116 | - : ''; |
|
117 | - if ($this->_has_checkbox_column) { |
|
118 | - $class .= ' has-checkbox-column'; |
|
119 | - } |
|
120 | - return $class; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @param EE_Event $item |
|
126 | - * @return string |
|
127 | - * @throws EE_Error |
|
128 | - */ |
|
129 | - public function column_status(EE_Event $item) |
|
130 | - { |
|
131 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
132 | - . $item->get_active_status() |
|
133 | - . '"></span>'; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param EE_Event $item |
|
139 | - * @return string |
|
140 | - * @throws EE_Error |
|
141 | - */ |
|
142 | - public function column_cb($item) |
|
143 | - { |
|
144 | - if (! $item instanceof EE_Event) { |
|
145 | - return ''; |
|
146 | - } |
|
147 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
148 | - // does event have any attached registrations? |
|
149 | - $regs = $item->count_related('Registration'); |
|
150 | - return $regs > 0 && $this->_view === 'trash' |
|
151 | - ? '<span class="ee-lock-icon"></span>' |
|
152 | - : sprintf( |
|
153 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
154 | - $item->ID() |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param EE_Event $item |
|
161 | - * @return mixed|string |
|
162 | - * @throws EE_Error |
|
163 | - */ |
|
164 | - public function column_id(EE_Event $item) |
|
165 | - { |
|
166 | - $content = $item->ID(); |
|
167 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
168 | - return $content; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param EE_Event $item |
|
174 | - * @return string |
|
175 | - * @throws EE_Error |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws InvalidDataTypeException |
|
178 | - * @throws InvalidInterfaceException |
|
179 | - */ |
|
180 | - public function column_name(EE_Event $item) |
|
181 | - { |
|
182 | - $edit_query_args = array( |
|
183 | - 'action' => 'edit', |
|
184 | - 'post' => $item->ID(), |
|
185 | - ); |
|
186 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
187 | - $actions = $this->_column_name_action_setup($item); |
|
188 | - $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
189 | - $content = '<strong><a class="row-title" href="' |
|
190 | - . $edit_link . '">' |
|
191 | - . $item->name() |
|
192 | - . '</a></strong>' |
|
193 | - . $status; |
|
194 | - $content .= '<br><span class="ee-status-text-small">' |
|
195 | - . EEH_Template::pretty_status( |
|
196 | - $item->get_active_status(), |
|
197 | - false, |
|
198 | - 'sentence' |
|
199 | - ) |
|
200 | - . '</span>'; |
|
201 | - $content .= $this->row_actions($actions); |
|
202 | - return $content; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Just a method for setting up the actions for the name column |
|
208 | - * |
|
209 | - * @param EE_Event $item |
|
210 | - * @return array array of actions |
|
211 | - * @throws EE_Error |
|
212 | - * @throws InvalidArgumentException |
|
213 | - * @throws InvalidDataTypeException |
|
214 | - * @throws InvalidInterfaceException |
|
215 | - */ |
|
216 | - protected function _column_name_action_setup(EE_Event $item) |
|
217 | - { |
|
218 | - // todo: remove when attendees is active |
|
219 | - if (! defined('REG_ADMIN_URL')) { |
|
220 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
221 | - } |
|
222 | - $actions = array(); |
|
223 | - $restore_event_link = ''; |
|
224 | - $delete_event_link = ''; |
|
225 | - $trash_event_link = ''; |
|
226 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
227 | - 'ee_edit_event', |
|
228 | - 'espresso_events_edit', |
|
229 | - $item->ID() |
|
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 (EE_Registry::instance()->CAP->current_user_can( |
|
242 | - 'ee_read_registrations', |
|
243 | - 'espresso_registrations_view_registration' |
|
244 | - ) |
|
245 | - && EE_Registry::instance()->CAP->current_user_can( |
|
246 | - 'ee_read_event', |
|
247 | - 'espresso_registrations_view_registration', |
|
248 | - $item->ID() |
|
249 | - ) |
|
250 | - ) { |
|
251 | - $attendees_query_args = array( |
|
252 | - 'action' => 'default', |
|
253 | - 'event_id' => $item->ID(), |
|
254 | - ); |
|
255 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
256 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
257 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
258 | - . esc_html__('Registrations', 'event_espresso') |
|
259 | - . '</a>'; |
|
260 | - } |
|
261 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
262 | - 'ee_delete_event', |
|
263 | - 'espresso_events_trash_event', |
|
264 | - $item->ID() |
|
265 | - )) { |
|
266 | - $trash_event_query_args = array( |
|
267 | - 'action' => 'trash_event', |
|
268 | - 'EVT_ID' => $item->ID(), |
|
269 | - ); |
|
270 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
271 | - $trash_event_query_args, |
|
272 | - EVENTS_ADMIN_URL |
|
273 | - ); |
|
274 | - } |
|
275 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
276 | - 'ee_delete_event', |
|
277 | - 'espresso_events_restore_event', |
|
278 | - $item->ID() |
|
279 | - )) { |
|
280 | - $restore_event_query_args = array( |
|
281 | - 'action' => 'restore_event', |
|
282 | - 'EVT_ID' => $item->ID(), |
|
283 | - ); |
|
284 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
285 | - $restore_event_query_args, |
|
286 | - EVENTS_ADMIN_URL |
|
287 | - ); |
|
288 | - } |
|
289 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
290 | - 'ee_delete_event', |
|
291 | - 'espresso_events_delete_event', |
|
292 | - $item->ID() |
|
293 | - )) { |
|
294 | - $delete_event_query_args = array( |
|
295 | - 'action' => 'delete_event', |
|
296 | - 'EVT_ID' => $item->ID(), |
|
297 | - ); |
|
298 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
299 | - $delete_event_query_args, |
|
300 | - EVENTS_ADMIN_URL |
|
301 | - ); |
|
302 | - } |
|
303 | - $view_link = get_permalink($item->ID()); |
|
304 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
305 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
306 | - . esc_html__('View', 'event_espresso') |
|
307 | - . '</a>'; |
|
308 | - if ($item->get('status') === 'trash') { |
|
309 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
310 | - 'ee_delete_event', |
|
311 | - 'espresso_events_restore_event', |
|
312 | - $item->ID() |
|
313 | - )) { |
|
314 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
315 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
316 | - . '">' |
|
317 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
318 | - . '</a>'; |
|
319 | - } |
|
320 | - if ($item->count_related('Registration') === 0 |
|
321 | - && EE_Registry::instance()->CAP->current_user_can( |
|
322 | - 'ee_delete_event', |
|
323 | - 'espresso_events_delete_event', |
|
324 | - $item->ID() |
|
325 | - ) |
|
326 | - ) { |
|
327 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
328 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
329 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
330 | - . '</a>'; |
|
331 | - } |
|
332 | - } else { |
|
333 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
334 | - 'ee_delete_event', |
|
335 | - 'espresso_events_trash_event', |
|
336 | - $item->ID() |
|
337 | - )) { |
|
338 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
339 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
340 | - . esc_html__('Trash', 'event_espresso') |
|
341 | - . '</a>'; |
|
342 | - } |
|
343 | - } |
|
344 | - return $actions; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @param EE_Event $item |
|
350 | - * @return string |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function column_author(EE_Event $item) |
|
354 | - { |
|
355 | - // user author info |
|
356 | - $event_author = get_userdata($item->wp_user()); |
|
357 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
358 | - // filter link |
|
359 | - $query_args = array( |
|
360 | - 'action' => 'default', |
|
361 | - 'EVT_wp_user' => $item->wp_user(), |
|
362 | - ); |
|
363 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
364 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
365 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
366 | - . $event_author->display_name |
|
367 | - . '</a>'; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * @param EE_Event $event |
|
373 | - * @return string |
|
374 | - * @throws EE_Error |
|
375 | - */ |
|
376 | - public function column_event_category(EE_Event $event) |
|
377 | - { |
|
378 | - $event_categories = $event->get_all_event_categories(); |
|
379 | - return implode( |
|
380 | - ', ', |
|
381 | - array_map( |
|
382 | - function (EE_Term $category) { |
|
383 | - return $category->name(); |
|
384 | - }, |
|
385 | - $event_categories |
|
386 | - ) |
|
387 | - ); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * @param EE_Event $item |
|
393 | - * @return string |
|
394 | - * @throws EE_Error |
|
395 | - */ |
|
396 | - public function column_venue(EE_Event $item) |
|
397 | - { |
|
398 | - $venue = $item->get_first_related('Venue'); |
|
399 | - return ! empty($venue) |
|
400 | - ? $venue->name() |
|
401 | - : ''; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @param EE_Event $item |
|
407 | - * @return string |
|
408 | - * @throws EE_Error |
|
409 | - */ |
|
410 | - public function column_start_date_time(EE_Event $item) |
|
411 | - { |
|
412 | - return $this->_dtt instanceof EE_Datetime |
|
413 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
414 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * @param EE_Event $item |
|
420 | - * @return string |
|
421 | - * @throws EE_Error |
|
422 | - */ |
|
423 | - public function column_reg_begins(EE_Event $item) |
|
424 | - { |
|
425 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
426 | - return $reg_start instanceof EE_Ticket |
|
427 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
428 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @param EE_Event $item |
|
434 | - * @return int|string |
|
435 | - * @throws EE_Error |
|
436 | - * @throws InvalidArgumentException |
|
437 | - * @throws InvalidDataTypeException |
|
438 | - * @throws InvalidInterfaceException |
|
439 | - */ |
|
440 | - public function column_attendees(EE_Event $item) |
|
441 | - { |
|
442 | - $attendees_query_args = array( |
|
443 | - 'action' => 'default', |
|
444 | - 'event_id' => $item->ID(), |
|
445 | - ); |
|
446 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
447 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
448 | - return EE_Registry::instance()->CAP->current_user_can( |
|
449 | - 'ee_read_event', |
|
450 | - 'espresso_registrations_view_registration', |
|
451 | - $item->ID() |
|
452 | - ) |
|
453 | - && EE_Registry::instance()->CAP->current_user_can( |
|
454 | - 'ee_read_registrations', |
|
455 | - 'espresso_registrations_view_registration' |
|
456 | - ) |
|
457 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
458 | - : $registered_attendees; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @param EE_Event $item |
|
464 | - * @return float |
|
465 | - * @throws EE_Error |
|
466 | - * @throws InvalidArgumentException |
|
467 | - * @throws InvalidDataTypeException |
|
468 | - * @throws InvalidInterfaceException |
|
469 | - */ |
|
470 | - public function column_tkts_sold(EE_Event $item) |
|
471 | - { |
|
472 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * @param EE_Event $item |
|
478 | - * @return string |
|
479 | - * @throws EE_Error |
|
480 | - * @throws InvalidArgumentException |
|
481 | - * @throws InvalidDataTypeException |
|
482 | - * @throws InvalidInterfaceException |
|
483 | - */ |
|
484 | - public function column_actions(EE_Event $item) |
|
485 | - { |
|
486 | - // todo: remove when attendees is active |
|
487 | - if (! defined('REG_ADMIN_URL')) { |
|
488 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
489 | - } |
|
490 | - $action_links = array(); |
|
491 | - $view_link = get_permalink($item->ID()); |
|
492 | - $action_links[] = '<a href="' . $view_link . '"' |
|
493 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
494 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
495 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
496 | - 'ee_edit_event', |
|
497 | - 'espresso_events_edit', |
|
498 | - $item->ID() |
|
499 | - )) { |
|
500 | - $edit_query_args = array( |
|
501 | - 'action' => 'edit', |
|
502 | - 'post' => $item->ID(), |
|
503 | - ); |
|
504 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
505 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
506 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
507 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
508 | - . '</a>'; |
|
509 | - } |
|
510 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
511 | - 'ee_read_registrations', |
|
512 | - 'espresso_registrations_view_registration' |
|
513 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
514 | - 'ee_read_event', |
|
515 | - 'espresso_registrations_view_registration', |
|
516 | - $item->ID() |
|
517 | - ) |
|
518 | - ) { |
|
519 | - $attendees_query_args = array( |
|
520 | - 'action' => 'default', |
|
521 | - 'event_id' => $item->ID(), |
|
522 | - ); |
|
523 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
524 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
525 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
526 | - . '<div class="dashicons dashicons-groups"></div>' |
|
527 | - . '</a>'; |
|
528 | - } |
|
529 | - $action_links = apply_filters( |
|
530 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
531 | - $action_links, |
|
532 | - $item |
|
533 | - ); |
|
534 | - return $this->_action_string( |
|
535 | - implode("\n\t", $action_links), |
|
536 | - $item, |
|
537 | - 'div' |
|
538 | - ); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Helper for adding columns conditionally |
|
544 | - * |
|
545 | - * @throws EE_Error |
|
546 | - * @throws InvalidArgumentException |
|
547 | - * @throws InvalidDataTypeException |
|
548 | - * @throws InvalidInterfaceException |
|
549 | - */ |
|
550 | - private function addConditionalColumns() |
|
551 | - { |
|
552 | - $event_category_count = EEM_Term::instance()->count( |
|
553 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
554 | - ); |
|
555 | - if ($event_category_count === 0) { |
|
556 | - return; |
|
557 | - } |
|
558 | - $column_array = []; |
|
559 | - foreach ($this->_columns as $column => $column_label) { |
|
560 | - $column_array[ $column ] = $column_label; |
|
561 | - if ($column === 'venue') { |
|
562 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
563 | - } |
|
564 | - } |
|
565 | - $this->_columns = $column_array; |
|
566 | - } |
|
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 (EE_Registry::instance()->CAP->current_user_can( |
|
97 | + 'ee_delete_events', |
|
98 | + 'espresso_events_trash_events' |
|
99 | + )) { |
|
100 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param EE_Event $item |
|
107 | + * @return string |
|
108 | + * @throws EE_Error |
|
109 | + */ |
|
110 | + protected function _get_row_class($item) |
|
111 | + { |
|
112 | + $class = parent::_get_row_class($item); |
|
113 | + // add status class |
|
114 | + $class .= $item instanceof EE_Event |
|
115 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
116 | + : ''; |
|
117 | + if ($this->_has_checkbox_column) { |
|
118 | + $class .= ' has-checkbox-column'; |
|
119 | + } |
|
120 | + return $class; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param EE_Event $item |
|
126 | + * @return string |
|
127 | + * @throws EE_Error |
|
128 | + */ |
|
129 | + public function column_status(EE_Event $item) |
|
130 | + { |
|
131 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
132 | + . $item->get_active_status() |
|
133 | + . '"></span>'; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param EE_Event $item |
|
139 | + * @return string |
|
140 | + * @throws EE_Error |
|
141 | + */ |
|
142 | + public function column_cb($item) |
|
143 | + { |
|
144 | + if (! $item instanceof EE_Event) { |
|
145 | + return ''; |
|
146 | + } |
|
147 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
148 | + // does event have any attached registrations? |
|
149 | + $regs = $item->count_related('Registration'); |
|
150 | + return $regs > 0 && $this->_view === 'trash' |
|
151 | + ? '<span class="ee-lock-icon"></span>' |
|
152 | + : sprintf( |
|
153 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
154 | + $item->ID() |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param EE_Event $item |
|
161 | + * @return mixed|string |
|
162 | + * @throws EE_Error |
|
163 | + */ |
|
164 | + public function column_id(EE_Event $item) |
|
165 | + { |
|
166 | + $content = $item->ID(); |
|
167 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
168 | + return $content; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param EE_Event $item |
|
174 | + * @return string |
|
175 | + * @throws EE_Error |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws InvalidDataTypeException |
|
178 | + * @throws InvalidInterfaceException |
|
179 | + */ |
|
180 | + public function column_name(EE_Event $item) |
|
181 | + { |
|
182 | + $edit_query_args = array( |
|
183 | + 'action' => 'edit', |
|
184 | + 'post' => $item->ID(), |
|
185 | + ); |
|
186 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
187 | + $actions = $this->_column_name_action_setup($item); |
|
188 | + $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
189 | + $content = '<strong><a class="row-title" href="' |
|
190 | + . $edit_link . '">' |
|
191 | + . $item->name() |
|
192 | + . '</a></strong>' |
|
193 | + . $status; |
|
194 | + $content .= '<br><span class="ee-status-text-small">' |
|
195 | + . EEH_Template::pretty_status( |
|
196 | + $item->get_active_status(), |
|
197 | + false, |
|
198 | + 'sentence' |
|
199 | + ) |
|
200 | + . '</span>'; |
|
201 | + $content .= $this->row_actions($actions); |
|
202 | + return $content; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Just a method for setting up the actions for the name column |
|
208 | + * |
|
209 | + * @param EE_Event $item |
|
210 | + * @return array array of actions |
|
211 | + * @throws EE_Error |
|
212 | + * @throws InvalidArgumentException |
|
213 | + * @throws InvalidDataTypeException |
|
214 | + * @throws InvalidInterfaceException |
|
215 | + */ |
|
216 | + protected function _column_name_action_setup(EE_Event $item) |
|
217 | + { |
|
218 | + // todo: remove when attendees is active |
|
219 | + if (! defined('REG_ADMIN_URL')) { |
|
220 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
221 | + } |
|
222 | + $actions = array(); |
|
223 | + $restore_event_link = ''; |
|
224 | + $delete_event_link = ''; |
|
225 | + $trash_event_link = ''; |
|
226 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
227 | + 'ee_edit_event', |
|
228 | + 'espresso_events_edit', |
|
229 | + $item->ID() |
|
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 (EE_Registry::instance()->CAP->current_user_can( |
|
242 | + 'ee_read_registrations', |
|
243 | + 'espresso_registrations_view_registration' |
|
244 | + ) |
|
245 | + && EE_Registry::instance()->CAP->current_user_can( |
|
246 | + 'ee_read_event', |
|
247 | + 'espresso_registrations_view_registration', |
|
248 | + $item->ID() |
|
249 | + ) |
|
250 | + ) { |
|
251 | + $attendees_query_args = array( |
|
252 | + 'action' => 'default', |
|
253 | + 'event_id' => $item->ID(), |
|
254 | + ); |
|
255 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
256 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
257 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
258 | + . esc_html__('Registrations', 'event_espresso') |
|
259 | + . '</a>'; |
|
260 | + } |
|
261 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
262 | + 'ee_delete_event', |
|
263 | + 'espresso_events_trash_event', |
|
264 | + $item->ID() |
|
265 | + )) { |
|
266 | + $trash_event_query_args = array( |
|
267 | + 'action' => 'trash_event', |
|
268 | + 'EVT_ID' => $item->ID(), |
|
269 | + ); |
|
270 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
271 | + $trash_event_query_args, |
|
272 | + EVENTS_ADMIN_URL |
|
273 | + ); |
|
274 | + } |
|
275 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
276 | + 'ee_delete_event', |
|
277 | + 'espresso_events_restore_event', |
|
278 | + $item->ID() |
|
279 | + )) { |
|
280 | + $restore_event_query_args = array( |
|
281 | + 'action' => 'restore_event', |
|
282 | + 'EVT_ID' => $item->ID(), |
|
283 | + ); |
|
284 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
285 | + $restore_event_query_args, |
|
286 | + EVENTS_ADMIN_URL |
|
287 | + ); |
|
288 | + } |
|
289 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
290 | + 'ee_delete_event', |
|
291 | + 'espresso_events_delete_event', |
|
292 | + $item->ID() |
|
293 | + )) { |
|
294 | + $delete_event_query_args = array( |
|
295 | + 'action' => 'delete_event', |
|
296 | + 'EVT_ID' => $item->ID(), |
|
297 | + ); |
|
298 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
299 | + $delete_event_query_args, |
|
300 | + EVENTS_ADMIN_URL |
|
301 | + ); |
|
302 | + } |
|
303 | + $view_link = get_permalink($item->ID()); |
|
304 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
305 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
306 | + . esc_html__('View', 'event_espresso') |
|
307 | + . '</a>'; |
|
308 | + if ($item->get('status') === 'trash') { |
|
309 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
310 | + 'ee_delete_event', |
|
311 | + 'espresso_events_restore_event', |
|
312 | + $item->ID() |
|
313 | + )) { |
|
314 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
315 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
316 | + . '">' |
|
317 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
318 | + . '</a>'; |
|
319 | + } |
|
320 | + if ($item->count_related('Registration') === 0 |
|
321 | + && EE_Registry::instance()->CAP->current_user_can( |
|
322 | + 'ee_delete_event', |
|
323 | + 'espresso_events_delete_event', |
|
324 | + $item->ID() |
|
325 | + ) |
|
326 | + ) { |
|
327 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
328 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
329 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
330 | + . '</a>'; |
|
331 | + } |
|
332 | + } else { |
|
333 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
334 | + 'ee_delete_event', |
|
335 | + 'espresso_events_trash_event', |
|
336 | + $item->ID() |
|
337 | + )) { |
|
338 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
339 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
340 | + . esc_html__('Trash', 'event_espresso') |
|
341 | + . '</a>'; |
|
342 | + } |
|
343 | + } |
|
344 | + return $actions; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @param EE_Event $item |
|
350 | + * @return string |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function column_author(EE_Event $item) |
|
354 | + { |
|
355 | + // user author info |
|
356 | + $event_author = get_userdata($item->wp_user()); |
|
357 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
358 | + // filter link |
|
359 | + $query_args = array( |
|
360 | + 'action' => 'default', |
|
361 | + 'EVT_wp_user' => $item->wp_user(), |
|
362 | + ); |
|
363 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
364 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
365 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
366 | + . $event_author->display_name |
|
367 | + . '</a>'; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * @param EE_Event $event |
|
373 | + * @return string |
|
374 | + * @throws EE_Error |
|
375 | + */ |
|
376 | + public function column_event_category(EE_Event $event) |
|
377 | + { |
|
378 | + $event_categories = $event->get_all_event_categories(); |
|
379 | + return implode( |
|
380 | + ', ', |
|
381 | + array_map( |
|
382 | + function (EE_Term $category) { |
|
383 | + return $category->name(); |
|
384 | + }, |
|
385 | + $event_categories |
|
386 | + ) |
|
387 | + ); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * @param EE_Event $item |
|
393 | + * @return string |
|
394 | + * @throws EE_Error |
|
395 | + */ |
|
396 | + public function column_venue(EE_Event $item) |
|
397 | + { |
|
398 | + $venue = $item->get_first_related('Venue'); |
|
399 | + return ! empty($venue) |
|
400 | + ? $venue->name() |
|
401 | + : ''; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @param EE_Event $item |
|
407 | + * @return string |
|
408 | + * @throws EE_Error |
|
409 | + */ |
|
410 | + public function column_start_date_time(EE_Event $item) |
|
411 | + { |
|
412 | + return $this->_dtt instanceof EE_Datetime |
|
413 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
414 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * @param EE_Event $item |
|
420 | + * @return string |
|
421 | + * @throws EE_Error |
|
422 | + */ |
|
423 | + public function column_reg_begins(EE_Event $item) |
|
424 | + { |
|
425 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
426 | + return $reg_start instanceof EE_Ticket |
|
427 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
428 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @param EE_Event $item |
|
434 | + * @return int|string |
|
435 | + * @throws EE_Error |
|
436 | + * @throws InvalidArgumentException |
|
437 | + * @throws InvalidDataTypeException |
|
438 | + * @throws InvalidInterfaceException |
|
439 | + */ |
|
440 | + public function column_attendees(EE_Event $item) |
|
441 | + { |
|
442 | + $attendees_query_args = array( |
|
443 | + 'action' => 'default', |
|
444 | + 'event_id' => $item->ID(), |
|
445 | + ); |
|
446 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
447 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
448 | + return EE_Registry::instance()->CAP->current_user_can( |
|
449 | + 'ee_read_event', |
|
450 | + 'espresso_registrations_view_registration', |
|
451 | + $item->ID() |
|
452 | + ) |
|
453 | + && EE_Registry::instance()->CAP->current_user_can( |
|
454 | + 'ee_read_registrations', |
|
455 | + 'espresso_registrations_view_registration' |
|
456 | + ) |
|
457 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
458 | + : $registered_attendees; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @param EE_Event $item |
|
464 | + * @return float |
|
465 | + * @throws EE_Error |
|
466 | + * @throws InvalidArgumentException |
|
467 | + * @throws InvalidDataTypeException |
|
468 | + * @throws InvalidInterfaceException |
|
469 | + */ |
|
470 | + public function column_tkts_sold(EE_Event $item) |
|
471 | + { |
|
472 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * @param EE_Event $item |
|
478 | + * @return string |
|
479 | + * @throws EE_Error |
|
480 | + * @throws InvalidArgumentException |
|
481 | + * @throws InvalidDataTypeException |
|
482 | + * @throws InvalidInterfaceException |
|
483 | + */ |
|
484 | + public function column_actions(EE_Event $item) |
|
485 | + { |
|
486 | + // todo: remove when attendees is active |
|
487 | + if (! defined('REG_ADMIN_URL')) { |
|
488 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
489 | + } |
|
490 | + $action_links = array(); |
|
491 | + $view_link = get_permalink($item->ID()); |
|
492 | + $action_links[] = '<a href="' . $view_link . '"' |
|
493 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
494 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
495 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
496 | + 'ee_edit_event', |
|
497 | + 'espresso_events_edit', |
|
498 | + $item->ID() |
|
499 | + )) { |
|
500 | + $edit_query_args = array( |
|
501 | + 'action' => 'edit', |
|
502 | + 'post' => $item->ID(), |
|
503 | + ); |
|
504 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
505 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
506 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
507 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
508 | + . '</a>'; |
|
509 | + } |
|
510 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
511 | + 'ee_read_registrations', |
|
512 | + 'espresso_registrations_view_registration' |
|
513 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
514 | + 'ee_read_event', |
|
515 | + 'espresso_registrations_view_registration', |
|
516 | + $item->ID() |
|
517 | + ) |
|
518 | + ) { |
|
519 | + $attendees_query_args = array( |
|
520 | + 'action' => 'default', |
|
521 | + 'event_id' => $item->ID(), |
|
522 | + ); |
|
523 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
524 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
525 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
526 | + . '<div class="dashicons dashicons-groups"></div>' |
|
527 | + . '</a>'; |
|
528 | + } |
|
529 | + $action_links = apply_filters( |
|
530 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
531 | + $action_links, |
|
532 | + $item |
|
533 | + ); |
|
534 | + return $this->_action_string( |
|
535 | + implode("\n\t", $action_links), |
|
536 | + $item, |
|
537 | + 'div' |
|
538 | + ); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Helper for adding columns conditionally |
|
544 | + * |
|
545 | + * @throws EE_Error |
|
546 | + * @throws InvalidArgumentException |
|
547 | + * @throws InvalidDataTypeException |
|
548 | + * @throws InvalidInterfaceException |
|
549 | + */ |
|
550 | + private function addConditionalColumns() |
|
551 | + { |
|
552 | + $event_category_count = EEM_Term::instance()->count( |
|
553 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
554 | + ); |
|
555 | + if ($event_category_count === 0) { |
|
556 | + return; |
|
557 | + } |
|
558 | + $column_array = []; |
|
559 | + foreach ($this->_columns as $column => $column_label) { |
|
560 | + $column_array[ $column ] = $column_label; |
|
561 | + if ($column === 'venue') { |
|
562 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
563 | + } |
|
564 | + } |
|
565 | + $this->_columns = $column_array; |
|
566 | + } |
|
567 | 567 | } |