@@ -15,11 +15,11 @@ |
||
15 | 15 | interface FactoryInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param mixed $arguments |
|
20 | - * @return mixed |
|
21 | - */ |
|
22 | - public static function create($arguments); |
|
18 | + /** |
|
19 | + * @param mixed $arguments |
|
20 | + * @return mixed |
|
21 | + */ |
|
22 | + public static function create($arguments); |
|
23 | 23 | |
24 | 24 | |
25 | 25 | } |
@@ -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 | /** |
@@ -12,411 +12,411 @@ |
||
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 | - ), |
|
202 | - 'Attendee_Meta' => array( |
|
203 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
204 | - 'ATTM_ID', |
|
205 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
206 | - false |
|
207 | - ), |
|
208 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
209 | - 'ATT_ID', |
|
210 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
211 | - false |
|
212 | - ), |
|
213 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
214 | - 'ATT_fname', |
|
215 | - esc_html__('First Name', 'event_espresso') |
|
216 | - ), |
|
217 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
218 | - 'ATT_lname', |
|
219 | - esc_html__('Last Name', 'event_espresso') |
|
220 | - ), |
|
221 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
222 | - 'ATT_address', |
|
223 | - esc_html__('Address Part 1', 'event_espresso') |
|
224 | - ), |
|
225 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
226 | - 'ATT_address2', |
|
227 | - esc_html__('Address Part 2', 'event_espresso') |
|
228 | - ), |
|
229 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
230 | - 'ATT_city', |
|
231 | - esc_html__('City', 'event_espresso') |
|
232 | - ), |
|
233 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
234 | - 'STA_ID', |
|
235 | - esc_html__('State', 'event_espresso'), |
|
236 | - true, |
|
237 | - 0, |
|
238 | - 'State' |
|
239 | - ), |
|
240 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
241 | - 'CNT_ISO', |
|
242 | - esc_html__('Country', 'event_espresso'), |
|
243 | - true, |
|
244 | - '', |
|
245 | - 'Country' |
|
246 | - ), |
|
247 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
248 | - 'ATT_zip', |
|
249 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
250 | - ), |
|
251 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
252 | - 'ATT_email', |
|
253 | - esc_html__('Email Address', 'event_espresso') |
|
254 | - ), |
|
255 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
256 | - 'ATT_phone', |
|
257 | - esc_html__('Phone', 'event_espresso') |
|
258 | - ), |
|
259 | - ), |
|
260 | - ); |
|
261 | - $this->_model_relations = array( |
|
262 | - 'Registration' => new EE_Has_Many_Relation(), |
|
263 | - 'State' => new EE_Belongs_To_Relation(), |
|
264 | - 'Country' => new EE_Belongs_To_Relation(), |
|
265 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
266 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
267 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
268 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
269 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
270 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
271 | - ); |
|
272 | - $this->_caps_slug = 'contacts'; |
|
273 | - parent::__construct($timezone); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
280 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
281 | - * |
|
282 | - * @param string $system_question_string |
|
283 | - * @return string|null if not found |
|
284 | - */ |
|
285 | - public function get_attendee_field_for_system_question($system_question_string) |
|
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 ] |
|
289 | - : null; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
296 | - * |
|
297 | - * @return array |
|
298 | - */ |
|
299 | - public function system_question_to_attendee_field_mapping() |
|
300 | - { |
|
301 | - return $this->_system_question_to_attendee_field_name; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
308 | - * |
|
309 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
310 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
311 | - * @throws EE_Error |
|
312 | - */ |
|
313 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
314 | - { |
|
315 | - return $this->get_all( |
|
316 | - array( |
|
317 | - array( |
|
318 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
319 | - ? $transaction_id_or_obj->ID() |
|
320 | - : $transaction_id_or_obj, |
|
321 | - ), |
|
322 | - ) |
|
323 | - ); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * retrieve a single attendee from db via their ID |
|
330 | - * |
|
331 | - * @param $ATT_ID |
|
332 | - * @return mixed array on success, FALSE on fail |
|
333 | - * @deprecated |
|
334 | - */ |
|
335 | - public function get_attendee_by_ID($ATT_ID = false) |
|
336 | - { |
|
337 | - // retrieve a particular EE_Attendee |
|
338 | - return $this->get_one_by_ID($ATT_ID); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * retrieve a single attendee from db via their ID |
|
345 | - * |
|
346 | - * @param array $where_cols_n_values |
|
347 | - * @return mixed array on success, FALSE on fail |
|
348 | - * @throws EE_Error |
|
349 | - */ |
|
350 | - public function get_attendee($where_cols_n_values = array()) |
|
351 | - { |
|
352 | - if (empty($where_cols_n_values)) { |
|
353 | - return false; |
|
354 | - } |
|
355 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
356 | - if (! empty($attendee)) { |
|
357 | - return array_shift($attendee); |
|
358 | - } |
|
359 | - return false; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Search for an existing Attendee record in the DB |
|
366 | - * |
|
367 | - * @param array $where_cols_n_values |
|
368 | - * @return bool|mixed |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - public function find_existing_attendee($where_cols_n_values = null) |
|
372 | - { |
|
373 | - // search by combo of first and last names plus the email address |
|
374 | - $attendee_data_keys = array( |
|
375 | - 'ATT_fname' => $this->_ATT_fname, |
|
376 | - 'ATT_lname' => $this->_ATT_lname, |
|
377 | - 'ATT_email' => $this->_ATT_email, |
|
378 | - ); |
|
379 | - // no search params means attendee object already exists. |
|
380 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
381 | - ? $where_cols_n_values |
|
382 | - : $attendee_data_keys; |
|
383 | - $valid_data = true; |
|
384 | - // check for required values |
|
385 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
386 | - ? $valid_data |
|
387 | - : false; |
|
388 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
389 | - ? $valid_data |
|
390 | - : false; |
|
391 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
392 | - ? $valid_data |
|
393 | - : false; |
|
394 | - if ($valid_data) { |
|
395 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
396 | - if ($attendee instanceof EE_Attendee) { |
|
397 | - return $attendee; |
|
398 | - } |
|
399 | - } |
|
400 | - return false; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Takes an incoming array of EE_Registration ids |
|
407 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
408 | - * |
|
409 | - * @since 4.3.0 |
|
410 | - * @param array $ids array of EE_Registration ids |
|
411 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
415 | - { |
|
416 | - $ids = (array) $ids; |
|
417 | - $_where = array( |
|
418 | - 'Registration.REG_ID' => array('in', $ids), |
|
419 | - ); |
|
420 | - return $this->get_all(array($_where)); |
|
421 | - } |
|
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 | + ), |
|
202 | + 'Attendee_Meta' => array( |
|
203 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
204 | + 'ATTM_ID', |
|
205 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
206 | + false |
|
207 | + ), |
|
208 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
209 | + 'ATT_ID', |
|
210 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
211 | + false |
|
212 | + ), |
|
213 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
214 | + 'ATT_fname', |
|
215 | + esc_html__('First Name', 'event_espresso') |
|
216 | + ), |
|
217 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
218 | + 'ATT_lname', |
|
219 | + esc_html__('Last Name', 'event_espresso') |
|
220 | + ), |
|
221 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
222 | + 'ATT_address', |
|
223 | + esc_html__('Address Part 1', 'event_espresso') |
|
224 | + ), |
|
225 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
226 | + 'ATT_address2', |
|
227 | + esc_html__('Address Part 2', 'event_espresso') |
|
228 | + ), |
|
229 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
230 | + 'ATT_city', |
|
231 | + esc_html__('City', 'event_espresso') |
|
232 | + ), |
|
233 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
234 | + 'STA_ID', |
|
235 | + esc_html__('State', 'event_espresso'), |
|
236 | + true, |
|
237 | + 0, |
|
238 | + 'State' |
|
239 | + ), |
|
240 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
241 | + 'CNT_ISO', |
|
242 | + esc_html__('Country', 'event_espresso'), |
|
243 | + true, |
|
244 | + '', |
|
245 | + 'Country' |
|
246 | + ), |
|
247 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
248 | + 'ATT_zip', |
|
249 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
250 | + ), |
|
251 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
252 | + 'ATT_email', |
|
253 | + esc_html__('Email Address', 'event_espresso') |
|
254 | + ), |
|
255 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
256 | + 'ATT_phone', |
|
257 | + esc_html__('Phone', 'event_espresso') |
|
258 | + ), |
|
259 | + ), |
|
260 | + ); |
|
261 | + $this->_model_relations = array( |
|
262 | + 'Registration' => new EE_Has_Many_Relation(), |
|
263 | + 'State' => new EE_Belongs_To_Relation(), |
|
264 | + 'Country' => new EE_Belongs_To_Relation(), |
|
265 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
266 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
267 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
268 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
269 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
270 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
271 | + ); |
|
272 | + $this->_caps_slug = 'contacts'; |
|
273 | + parent::__construct($timezone); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
280 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
281 | + * |
|
282 | + * @param string $system_question_string |
|
283 | + * @return string|null if not found |
|
284 | + */ |
|
285 | + public function get_attendee_field_for_system_question($system_question_string) |
|
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 ] |
|
289 | + : null; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
296 | + * |
|
297 | + * @return array |
|
298 | + */ |
|
299 | + public function system_question_to_attendee_field_mapping() |
|
300 | + { |
|
301 | + return $this->_system_question_to_attendee_field_name; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
308 | + * |
|
309 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
310 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
311 | + * @throws EE_Error |
|
312 | + */ |
|
313 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
314 | + { |
|
315 | + return $this->get_all( |
|
316 | + array( |
|
317 | + array( |
|
318 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
319 | + ? $transaction_id_or_obj->ID() |
|
320 | + : $transaction_id_or_obj, |
|
321 | + ), |
|
322 | + ) |
|
323 | + ); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * retrieve a single attendee from db via their ID |
|
330 | + * |
|
331 | + * @param $ATT_ID |
|
332 | + * @return mixed array on success, FALSE on fail |
|
333 | + * @deprecated |
|
334 | + */ |
|
335 | + public function get_attendee_by_ID($ATT_ID = false) |
|
336 | + { |
|
337 | + // retrieve a particular EE_Attendee |
|
338 | + return $this->get_one_by_ID($ATT_ID); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * retrieve a single attendee from db via their ID |
|
345 | + * |
|
346 | + * @param array $where_cols_n_values |
|
347 | + * @return mixed array on success, FALSE on fail |
|
348 | + * @throws EE_Error |
|
349 | + */ |
|
350 | + public function get_attendee($where_cols_n_values = array()) |
|
351 | + { |
|
352 | + if (empty($where_cols_n_values)) { |
|
353 | + return false; |
|
354 | + } |
|
355 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
356 | + if (! empty($attendee)) { |
|
357 | + return array_shift($attendee); |
|
358 | + } |
|
359 | + return false; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Search for an existing Attendee record in the DB |
|
366 | + * |
|
367 | + * @param array $where_cols_n_values |
|
368 | + * @return bool|mixed |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + public function find_existing_attendee($where_cols_n_values = null) |
|
372 | + { |
|
373 | + // search by combo of first and last names plus the email address |
|
374 | + $attendee_data_keys = array( |
|
375 | + 'ATT_fname' => $this->_ATT_fname, |
|
376 | + 'ATT_lname' => $this->_ATT_lname, |
|
377 | + 'ATT_email' => $this->_ATT_email, |
|
378 | + ); |
|
379 | + // no search params means attendee object already exists. |
|
380 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
381 | + ? $where_cols_n_values |
|
382 | + : $attendee_data_keys; |
|
383 | + $valid_data = true; |
|
384 | + // check for required values |
|
385 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
386 | + ? $valid_data |
|
387 | + : false; |
|
388 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
389 | + ? $valid_data |
|
390 | + : false; |
|
391 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
392 | + ? $valid_data |
|
393 | + : false; |
|
394 | + if ($valid_data) { |
|
395 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
396 | + if ($attendee instanceof EE_Attendee) { |
|
397 | + return $attendee; |
|
398 | + } |
|
399 | + } |
|
400 | + return false; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Takes an incoming array of EE_Registration ids |
|
407 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
408 | + * |
|
409 | + * @since 4.3.0 |
|
410 | + * @param array $ids array of EE_Registration ids |
|
411 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
415 | + { |
|
416 | + $ids = (array) $ids; |
|
417 | + $_where = array( |
|
418 | + 'Registration.REG_ID' => array('in', $ids), |
|
419 | + ); |
|
420 | + return $this->get_all(array($_where)); |
|
421 | + } |
|
422 | 422 | } |
@@ -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; |
@@ -98,7 +98,7 @@ |
||
98 | 98 | * |
99 | 99 | * @param EE_Event $event EE event object |
100 | 100 | * @param array $data The request data from the form |
101 | - * @return bool success or fail |
|
101 | + * @return integer success or fail |
|
102 | 102 | * @throws EE_Error |
103 | 103 | */ |
104 | 104 | public function attach_evt_message_templates($event, $data) |
@@ -12,276 +12,276 @@ |
||
12 | 12 | */ |
13 | 13 | class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks |
14 | 14 | { |
15 | - /** |
|
16 | - * espresso_events_Messages_Hooks_Extend constructor. |
|
17 | - * |
|
18 | - * @param \EE_Admin_Page $admin_page |
|
19 | - */ |
|
20 | - public function __construct(EE_Admin_Page $admin_page) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
24 | - */ |
|
25 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
26 | - 'ee_edit_messages', |
|
27 | - 'messages_events_editor_metabox' |
|
28 | - )) { |
|
29 | - return; |
|
30 | - } |
|
31 | - add_filter( |
|
32 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
33 | - array($this, 'caf_updates'), |
|
34 | - 10 |
|
35 | - ); |
|
36 | - add_action( |
|
37 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
38 | - array($this, 'duplicate_custom_message_settings'), |
|
39 | - 10, |
|
40 | - 2 |
|
41 | - ); |
|
42 | - parent::__construct($admin_page); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * extending the properties set in espresso_events_Messages_Hooks |
|
48 | - * |
|
49 | - * @access protected |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function _extend_properties() |
|
53 | - { |
|
54 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
55 | - $this->_ajax_func = array( |
|
56 | - 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
57 | - ); |
|
58 | - $this->_metaboxes = array( |
|
59 | - 0 => array( |
|
60 | - 'page_route' => array('edit', 'create_new'), |
|
61 | - 'func' => 'messages_metabox', |
|
62 | - 'label' => esc_html__('Notifications', 'event_espresso'), |
|
63 | - 'priority' => 'high', |
|
64 | - ), |
|
65 | - ); |
|
66 | - |
|
67 | - // see explanation for layout in EE_Admin_Hooks |
|
68 | - $this->_scripts_styles = array( |
|
69 | - 'registers' => array( |
|
70 | - 'events_msg_admin' => array( |
|
71 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
72 | - 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
73 | - ), |
|
74 | - 'events_msg_admin_css' => array( |
|
75 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
76 | - 'type' => 'css', |
|
77 | - ), |
|
78 | - ), |
|
79 | - 'enqueues' => array( |
|
80 | - 'events_msg_admin' => array('edit', 'create_new'), |
|
81 | - 'events_msg_admin_css' => array('edit', 'create_new'), |
|
82 | - ), |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - public function caf_updates($update_callbacks) |
|
88 | - { |
|
89 | - $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
90 | - return $update_callbacks; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Handles attaching Message Templates to the Event on save. |
|
96 | - * |
|
97 | - * @param EE_Event $event EE event object |
|
98 | - * @param array $data The request data from the form |
|
99 | - * @return bool success or fail |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - public function attach_evt_message_templates($event, $data) |
|
103 | - { |
|
104 | - // first we remove all existing relations on the Event for message types. |
|
105 | - $event->_remove_relations('Message_Template_Group'); |
|
106 | - // now let's just loop through the selected templates and add relations! |
|
107 | - if (isset($data['event_message_templates_relation'])) { |
|
108 | - foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
109 | - $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
110 | - } |
|
111 | - } |
|
112 | - // now save |
|
113 | - return $event->save(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param $event |
|
119 | - * @param $callback_args |
|
120 | - * @return string |
|
121 | - * @throws \EE_Error |
|
122 | - */ |
|
123 | - public function messages_metabox($event, $callback_args) |
|
124 | - { |
|
125 | - // let's get the active messengers (b/c messenger objects have the active message templates) |
|
126 | - // convert 'evt_id' to 'EVT_ID' |
|
127 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
128 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
129 | - ? $this->_req_data['post'] |
|
130 | - : $this->_req_data['EVT_ID']; |
|
131 | - |
|
132 | - $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
133 | - ? $this->_req_data['evt_id'] |
|
134 | - : $this->_req_data['EVT_ID']; |
|
135 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
136 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
137 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
138 | - $tabs = array(); |
|
139 | - |
|
140 | - // empty messengers? |
|
141 | - // Note message types will always have at least one available because every messenger has a default message type |
|
142 | - // associated with it (payment) if no other message types are selected. |
|
143 | - if (empty($active_messengers)) { |
|
144 | - $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
145 | - array('action' => 'settings'), |
|
146 | - EE_MSG_ADMIN_URL |
|
147 | - ); |
|
148 | - $error_msg = sprintf( |
|
149 | - esc_html__( |
|
150 | - 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
151 | - 'event_espresso' |
|
152 | - ), |
|
153 | - '<strong>', |
|
154 | - '</strong>', |
|
155 | - '<a href="' . $msg_activate_url . '">', |
|
156 | - '</a>' |
|
157 | - ); |
|
158 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
159 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
160 | - |
|
161 | - echo $error_content; |
|
162 | - echo $internal_content; |
|
163 | - return ''; |
|
164 | - } |
|
165 | - |
|
166 | - $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
167 | - // get content for active messengers |
|
168 | - foreach ($active_messengers as $name => $messenger) { |
|
169 | - // first check if there are any active message types for this messenger. |
|
170 | - $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
171 | - if (empty($active_mts)) { |
|
172 | - continue; |
|
173 | - } |
|
174 | - |
|
175 | - $tab_content = $messenger->get_messenger_admin_page_content( |
|
176 | - 'events', |
|
177 | - 'edit', |
|
178 | - array('event' => $event_id) |
|
179 | - ); |
|
180 | - |
|
181 | - if (! empty($tab_content)) { |
|
182 | - $tabs[ $name ] = $tab_content; |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
188 | - $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
189 | - if ($tabbed_content instanceof WP_Error) { |
|
190 | - $tabbed_content = $tabbed_content->get_error_message(); |
|
191 | - } |
|
192 | - |
|
193 | - $notices = ' |
|
15 | + /** |
|
16 | + * espresso_events_Messages_Hooks_Extend constructor. |
|
17 | + * |
|
18 | + * @param \EE_Admin_Page $admin_page |
|
19 | + */ |
|
20 | + public function __construct(EE_Admin_Page $admin_page) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
24 | + */ |
|
25 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
26 | + 'ee_edit_messages', |
|
27 | + 'messages_events_editor_metabox' |
|
28 | + )) { |
|
29 | + return; |
|
30 | + } |
|
31 | + add_filter( |
|
32 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
33 | + array($this, 'caf_updates'), |
|
34 | + 10 |
|
35 | + ); |
|
36 | + add_action( |
|
37 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
38 | + array($this, 'duplicate_custom_message_settings'), |
|
39 | + 10, |
|
40 | + 2 |
|
41 | + ); |
|
42 | + parent::__construct($admin_page); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * extending the properties set in espresso_events_Messages_Hooks |
|
48 | + * |
|
49 | + * @access protected |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function _extend_properties() |
|
53 | + { |
|
54 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
55 | + $this->_ajax_func = array( |
|
56 | + 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
57 | + ); |
|
58 | + $this->_metaboxes = array( |
|
59 | + 0 => array( |
|
60 | + 'page_route' => array('edit', 'create_new'), |
|
61 | + 'func' => 'messages_metabox', |
|
62 | + 'label' => esc_html__('Notifications', 'event_espresso'), |
|
63 | + 'priority' => 'high', |
|
64 | + ), |
|
65 | + ); |
|
66 | + |
|
67 | + // see explanation for layout in EE_Admin_Hooks |
|
68 | + $this->_scripts_styles = array( |
|
69 | + 'registers' => array( |
|
70 | + 'events_msg_admin' => array( |
|
71 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
72 | + 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
73 | + ), |
|
74 | + 'events_msg_admin_css' => array( |
|
75 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
76 | + 'type' => 'css', |
|
77 | + ), |
|
78 | + ), |
|
79 | + 'enqueues' => array( |
|
80 | + 'events_msg_admin' => array('edit', 'create_new'), |
|
81 | + 'events_msg_admin_css' => array('edit', 'create_new'), |
|
82 | + ), |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + public function caf_updates($update_callbacks) |
|
88 | + { |
|
89 | + $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
90 | + return $update_callbacks; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Handles attaching Message Templates to the Event on save. |
|
96 | + * |
|
97 | + * @param EE_Event $event EE event object |
|
98 | + * @param array $data The request data from the form |
|
99 | + * @return bool success or fail |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + public function attach_evt_message_templates($event, $data) |
|
103 | + { |
|
104 | + // first we remove all existing relations on the Event for message types. |
|
105 | + $event->_remove_relations('Message_Template_Group'); |
|
106 | + // now let's just loop through the selected templates and add relations! |
|
107 | + if (isset($data['event_message_templates_relation'])) { |
|
108 | + foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
109 | + $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
110 | + } |
|
111 | + } |
|
112 | + // now save |
|
113 | + return $event->save(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param $event |
|
119 | + * @param $callback_args |
|
120 | + * @return string |
|
121 | + * @throws \EE_Error |
|
122 | + */ |
|
123 | + public function messages_metabox($event, $callback_args) |
|
124 | + { |
|
125 | + // let's get the active messengers (b/c messenger objects have the active message templates) |
|
126 | + // convert 'evt_id' to 'EVT_ID' |
|
127 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
128 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
129 | + ? $this->_req_data['post'] |
|
130 | + : $this->_req_data['EVT_ID']; |
|
131 | + |
|
132 | + $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
133 | + ? $this->_req_data['evt_id'] |
|
134 | + : $this->_req_data['EVT_ID']; |
|
135 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
136 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
137 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
138 | + $tabs = array(); |
|
139 | + |
|
140 | + // empty messengers? |
|
141 | + // Note message types will always have at least one available because every messenger has a default message type |
|
142 | + // associated with it (payment) if no other message types are selected. |
|
143 | + if (empty($active_messengers)) { |
|
144 | + $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
145 | + array('action' => 'settings'), |
|
146 | + EE_MSG_ADMIN_URL |
|
147 | + ); |
|
148 | + $error_msg = sprintf( |
|
149 | + esc_html__( |
|
150 | + 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
151 | + 'event_espresso' |
|
152 | + ), |
|
153 | + '<strong>', |
|
154 | + '</strong>', |
|
155 | + '<a href="' . $msg_activate_url . '">', |
|
156 | + '</a>' |
|
157 | + ); |
|
158 | + $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
159 | + $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
160 | + |
|
161 | + echo $error_content; |
|
162 | + echo $internal_content; |
|
163 | + return ''; |
|
164 | + } |
|
165 | + |
|
166 | + $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
167 | + // get content for active messengers |
|
168 | + foreach ($active_messengers as $name => $messenger) { |
|
169 | + // first check if there are any active message types for this messenger. |
|
170 | + $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
171 | + if (empty($active_mts)) { |
|
172 | + continue; |
|
173 | + } |
|
174 | + |
|
175 | + $tab_content = $messenger->get_messenger_admin_page_content( |
|
176 | + 'events', |
|
177 | + 'edit', |
|
178 | + array('event' => $event_id) |
|
179 | + ); |
|
180 | + |
|
181 | + if (! empty($tab_content)) { |
|
182 | + $tabs[ $name ] = $tab_content; |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
188 | + $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
189 | + if ($tabbed_content instanceof WP_Error) { |
|
190 | + $tabbed_content = $tabbed_content->get_error_message(); |
|
191 | + } |
|
192 | + |
|
193 | + $notices = ' |
|
194 | 194 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
195 | 195 | <span class="ee-spinner ee-spin"></span><span class="hidden">' |
196 | - . esc_html__('loading...', 'event_espresso') |
|
197 | - . '</span> |
|
196 | + . esc_html__('loading...', 'event_espresso') |
|
197 | + . '</span> |
|
198 | 198 | </div> |
199 | 199 | <div class="ee-notices"></div>'; |
200 | 200 | |
201 | - if (defined('DOING_AJAX')) { |
|
202 | - return $tabbed_content; |
|
203 | - } |
|
204 | - |
|
205 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
206 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
207 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
213 | - * Takes incoming GRP_ID and name and description values from ajax request |
|
214 | - * to create a new custom template based off of the incoming GRP_ID. |
|
215 | - * |
|
216 | - * @access public |
|
217 | - * @return string either an html string will be returned or a success message |
|
218 | - * @throws EE_Error |
|
219 | - */ |
|
220 | - public function create_new_custom() |
|
221 | - { |
|
222 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
223 | - wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
224 | - } |
|
225 | - |
|
226 | - // let's clean up the _POST global a bit for downstream usage of name and description. |
|
227 | - $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
228 | - ? $this->_req_data['custom_template_args']['MTP_name'] |
|
229 | - : ''; |
|
230 | - $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
231 | - ? $this->_req_data['custom_template_args']['MTP_description'] |
|
232 | - : ''; |
|
233 | - |
|
234 | - |
|
235 | - // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
236 | - $this->_set_page_object(); |
|
237 | - |
|
238 | - // is this a template switch if so EE_Admin_Page child needs this object |
|
239 | - $this->_page_object->set_hook_object($this); |
|
240 | - |
|
241 | - $this->_page_object->add_message_template( |
|
242 | - $this->_req_data['messageType'], |
|
243 | - $this->_req_data['messenger'], |
|
244 | - $this->_req_data['group_ID'] |
|
245 | - ); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - public function create_new_admin_footer() |
|
250 | - { |
|
251 | - $this->edit_admin_footer(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * This is the dynamic method for this class |
|
257 | - * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
258 | - * |
|
259 | - * @return string |
|
260 | - * @throws DomainException |
|
261 | - */ |
|
262 | - public function edit_admin_footer() |
|
263 | - { |
|
264 | - EEH_Template::display_template( |
|
265 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
266 | - ); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
272 | - * the assigned custom message templates. |
|
273 | - * |
|
274 | - * @param EE_Event $new_event |
|
275 | - * @param EE_Event $original_event |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
279 | - { |
|
280 | - $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
281 | - foreach ($message_template_groups as $message_template_group) { |
|
282 | - $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
283 | - } |
|
284 | - // save new event |
|
285 | - $new_event->save(); |
|
286 | - } |
|
201 | + if (defined('DOING_AJAX')) { |
|
202 | + return $tabbed_content; |
|
203 | + } |
|
204 | + |
|
205 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
206 | + echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
207 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
213 | + * Takes incoming GRP_ID and name and description values from ajax request |
|
214 | + * to create a new custom template based off of the incoming GRP_ID. |
|
215 | + * |
|
216 | + * @access public |
|
217 | + * @return string either an html string will be returned or a success message |
|
218 | + * @throws EE_Error |
|
219 | + */ |
|
220 | + public function create_new_custom() |
|
221 | + { |
|
222 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
223 | + wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
224 | + } |
|
225 | + |
|
226 | + // let's clean up the _POST global a bit for downstream usage of name and description. |
|
227 | + $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
228 | + ? $this->_req_data['custom_template_args']['MTP_name'] |
|
229 | + : ''; |
|
230 | + $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
231 | + ? $this->_req_data['custom_template_args']['MTP_description'] |
|
232 | + : ''; |
|
233 | + |
|
234 | + |
|
235 | + // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
236 | + $this->_set_page_object(); |
|
237 | + |
|
238 | + // is this a template switch if so EE_Admin_Page child needs this object |
|
239 | + $this->_page_object->set_hook_object($this); |
|
240 | + |
|
241 | + $this->_page_object->add_message_template( |
|
242 | + $this->_req_data['messageType'], |
|
243 | + $this->_req_data['messenger'], |
|
244 | + $this->_req_data['group_ID'] |
|
245 | + ); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + public function create_new_admin_footer() |
|
250 | + { |
|
251 | + $this->edit_admin_footer(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * This is the dynamic method for this class |
|
257 | + * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
258 | + * |
|
259 | + * @return string |
|
260 | + * @throws DomainException |
|
261 | + */ |
|
262 | + public function edit_admin_footer() |
|
263 | + { |
|
264 | + EEH_Template::display_template( |
|
265 | + EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
266 | + ); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
272 | + * the assigned custom message templates. |
|
273 | + * |
|
274 | + * @param EE_Event $new_event |
|
275 | + * @param EE_Event $original_event |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
279 | + { |
|
280 | + $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
281 | + foreach ($message_template_groups as $message_template_group) { |
|
282 | + $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
283 | + } |
|
284 | + // save new event |
|
285 | + $new_event->save(); |
|
286 | + } |
|
287 | 287 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
24 | 24 | */ |
25 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
25 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
26 | 26 | 'ee_edit_messages', |
27 | 27 | 'messages_events_editor_metabox' |
28 | 28 | )) { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | protected function _extend_properties() |
53 | 53 | { |
54 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
54 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/'); |
|
55 | 55 | $this->_ajax_func = array( |
56 | 56 | 'ee_msgs_create_new_custom' => 'create_new_custom', |
57 | 57 | ); |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $this->_scripts_styles = array( |
69 | 69 | 'registers' => array( |
70 | 70 | 'events_msg_admin' => array( |
71 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
71 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js', |
|
72 | 72 | 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
73 | 73 | ), |
74 | 74 | 'events_msg_admin_css' => array( |
75 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
75 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css', |
|
76 | 76 | 'type' => 'css', |
77 | 77 | ), |
78 | 78 | ), |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | ), |
153 | 153 | '<strong>', |
154 | 154 | '</strong>', |
155 | - '<a href="' . $msg_activate_url . '">', |
|
155 | + '<a href="'.$msg_activate_url.'">', |
|
156 | 156 | '</a>' |
157 | 157 | ); |
158 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
159 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
158 | + $error_content = '<div class="error"><p>'.$error_msg.'</p></div>'; |
|
159 | + $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>'; |
|
160 | 160 | |
161 | 161 | echo $error_content; |
162 | 162 | echo $internal_content; |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | array('event' => $event_id) |
179 | 179 | ); |
180 | 180 | |
181 | - if (! empty($tab_content)) { |
|
182 | - $tabs[ $name ] = $tab_content; |
|
181 | + if ( ! empty($tab_content)) { |
|
182 | + $tabs[$name] = $tab_content; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
206 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
206 | + echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>'; |
|
207 | 207 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
208 | 208 | } |
209 | 209 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function create_new_custom() |
221 | 221 | { |
222 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
222 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
223 | 223 | wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
224 | 224 | } |
225 | 225 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | public function edit_admin_footer() |
263 | 263 | { |
264 | 264 | EEH_Template::display_template( |
265 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
265 | + EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php' |
|
266 | 266 | ); |
267 | 267 | } |
268 | 268 |
@@ -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 | { |
@@ -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 | } |
@@ -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, |
@@ -206,7 +206,7 @@ |
||
206 | 206 | function espresso_ticket_selector( $event = NULL ) { |
207 | 207 | if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
208 | 208 | espresso_load_ticket_selector(); |
209 | - \EED_Ticket_Selector::set_definitions(); |
|
209 | + \EED_Ticket_Selector::set_definitions(); |
|
210 | 210 | echo EED_Ticket_Selector::display_ticket_selector( $event ); |
211 | 211 | } |
212 | 212 | } |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | * @param int | \EE_Event $event |
15 | 15 | * @return bool |
16 | 16 | */ |
17 | -function is_espresso_event( $event = NULL ) { |
|
18 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
17 | +function is_espresso_event($event = NULL) { |
|
18 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
19 | 19 | // extract EE_Event object from passed param regardless of what it is (within reason of course) |
20 | - $event = EEH_Event_View::get_event( $event ); |
|
20 | + $event = EEH_Event_View::get_event($event); |
|
21 | 21 | // do we have a valid event ? |
22 | - return $event instanceof EE_Event ? TRUE : FALSE; |
|
22 | + return $event instanceof EE_Event ? TRUE : FALSE; |
|
23 | 23 | } |
24 | 24 | return FALSE; |
25 | 25 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @return bool |
32 | 32 | */ |
33 | 33 | function is_espresso_event_single() { |
34 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
34 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
35 | 35 | global $wp_query; |
36 | 36 | // return conditionals set by CPTs |
37 | 37 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return bool |
47 | 47 | */ |
48 | 48 | function is_espresso_event_archive() { |
49 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
49 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
50 | 50 | global $wp_query; |
51 | 51 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE; |
52 | 52 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return bool |
61 | 61 | */ |
62 | 62 | function is_espresso_event_taxonomy() { |
63 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
63 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
64 | 64 | global $wp_query; |
65 | 65 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE; |
66 | 66 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | * @param int | \EE_Venue $venue |
75 | 75 | * @return bool |
76 | 76 | */ |
77 | -function is_espresso_venue( $venue = NULL ) { |
|
78 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
77 | +function is_espresso_venue($venue = NULL) { |
|
78 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
79 | 79 | // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
80 | - $venue = EEH_Venue_View::get_venue( $venue, FALSE ); |
|
80 | + $venue = EEH_Venue_View::get_venue($venue, FALSE); |
|
81 | 81 | // do we have a valid event ? |
82 | 82 | return $venue instanceof EE_Venue ? TRUE : FALSE; |
83 | 83 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return bool |
92 | 92 | */ |
93 | 93 | function is_espresso_venue_single() { |
94 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
94 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
95 | 95 | global $wp_query; |
96 | 96 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE; |
97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return bool |
106 | 106 | */ |
107 | 107 | function is_espresso_venue_archive() { |
108 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
108 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
109 | 109 | global $wp_query; |
110 | 110 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE; |
111 | 111 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return bool |
120 | 120 | */ |
121 | 121 | function is_espresso_venue_taxonomy() { |
122 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
122 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
123 | 123 | global $wp_query; |
124 | 124 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE; |
125 | 125 | } |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | * @param $conditional_tag |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | -function can_use_espresso_conditionals( $conditional_tag ) { |
|
137 | - if ( ! did_action( 'AHEE__EE_System__initialize' )) { |
|
136 | +function can_use_espresso_conditionals($conditional_tag) { |
|
137 | + if ( ! did_action('AHEE__EE_System__initialize')) { |
|
138 | 138 | EE_Error::doing_it_wrong( |
139 | 139 | __FUNCTION__, |
140 | 140 | sprintf( |
141 | - __( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'), |
|
141 | + __('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'), |
|
142 | 142 | $conditional_tag |
143 | 143 | ), |
144 | 144 | '4.4.0' |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | |
154 | 154 | /*************************** Event Queries ***************************/ |
155 | 155 | |
156 | -if ( ! function_exists( 'espresso_get_events' )) { |
|
156 | +if ( ! function_exists('espresso_get_events')) { |
|
157 | 157 | /** |
158 | 158 | * espresso_get_events |
159 | 159 | * @param array $params |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - function espresso_get_events( $params = array() ) { |
|
162 | + function espresso_get_events($params = array()) { |
|
163 | 163 | //set default params |
164 | 164 | $default_espresso_events_params = array( |
165 | 165 | 'limit' => 10, |
@@ -170,18 +170,18 @@ discard block |
||
170 | 170 | 'sort' => 'ASC' |
171 | 171 | ); |
172 | 172 | // allow the defaults to be filtered |
173 | - $default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params ); |
|
173 | + $default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params); |
|
174 | 174 | // grab params and merge with defaults, then extract |
175 | - $params = array_merge( $default_espresso_events_params, $params ); |
|
175 | + $params = array_merge($default_espresso_events_params, $params); |
|
176 | 176 | // run the query |
177 | - $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $params ); |
|
177 | + $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
178 | 178 | // assign results to a variable so we can return it |
179 | 179 | $events = $events_query->have_posts() ? $events_query->posts : array(); |
180 | 180 | // but first reset the query and postdata |
181 | 181 | wp_reset_query(); |
182 | 182 | wp_reset_postdata(); |
183 | 183 | EED_Events_Archive::remove_all_events_archive_filters(); |
184 | - unset( $events_query ); |
|
184 | + unset($events_query); |
|
185 | 185 | return $events; |
186 | 186 | } |
187 | 187 | } |
@@ -195,33 +195,33 @@ discard block |
||
195 | 195 | * espresso_load_ticket_selector |
196 | 196 | */ |
197 | 197 | function espresso_load_ticket_selector() { |
198 | - EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' ); |
|
198 | + EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
199 | 199 | } |
200 | 200 | |
201 | -if ( ! function_exists( 'espresso_ticket_selector' )) { |
|
201 | +if ( ! function_exists('espresso_ticket_selector')) { |
|
202 | 202 | /** |
203 | 203 | * espresso_ticket_selector |
204 | 204 | * @param null $event |
205 | 205 | */ |
206 | - function espresso_ticket_selector( $event = NULL ) { |
|
207 | - if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
|
206 | + function espresso_ticket_selector($event = NULL) { |
|
207 | + if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) { |
|
208 | 208 | espresso_load_ticket_selector(); |
209 | 209 | \EED_Ticket_Selector::set_definitions(); |
210 | - echo EED_Ticket_Selector::display_ticket_selector( $event ); |
|
210 | + echo EED_Ticket_Selector::display_ticket_selector($event); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | 215 | |
216 | - if ( ! function_exists( 'espresso_view_details_btn' )) { |
|
216 | + if ( ! function_exists('espresso_view_details_btn')) { |
|
217 | 217 | /** |
218 | 218 | * espresso_view_details_btn |
219 | 219 | * @param null $event |
220 | 220 | */ |
221 | - function espresso_view_details_btn( $event = NULL ) { |
|
222 | - if ( ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) { |
|
221 | + function espresso_view_details_btn($event = NULL) { |
|
222 | + if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) { |
|
223 | 223 | espresso_load_ticket_selector(); |
224 | - echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE ); |
|
224 | + echo EED_Ticket_Selector::display_ticket_selector($event, TRUE); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | /*************************** EEH_Event_View ***************************/ |
233 | 233 | |
234 | -if ( ! function_exists( 'espresso_load_event_list_assets' )) { |
|
234 | +if ( ! function_exists('espresso_load_event_list_assets')) { |
|
235 | 235 | /** |
236 | 236 | * espresso_load_event_list_assets |
237 | 237 | * ensures that event list styles and scripts are loaded |
@@ -240,13 +240,13 @@ discard block |
||
240 | 240 | */ |
241 | 241 | function espresso_load_event_list_assets() { |
242 | 242 | $event_list = EED_Events_Archive::instance(); |
243 | - add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 ); |
|
244 | - add_filter( 'FHEE_enable_default_espresso_css', '__return_true' ); |
|
243 | + add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10); |
|
244 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | |
249 | -if ( ! function_exists( 'espresso_event_reg_button' )) { |
|
249 | +if ( ! function_exists('espresso_event_reg_button')) { |
|
250 | 250 | /** |
251 | 251 | * espresso_event_reg_button |
252 | 252 | * returns the "Register Now" button if event is active, |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | * @param bool $EVT_ID |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) { |
|
262 | - $event_status = EEH_Event_View::event_active_status( $EVT_ID ); |
|
263 | - switch ( $event_status ) { |
|
261 | + function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) { |
|
262 | + $event_status = EEH_Event_View::event_active_status($EVT_ID); |
|
263 | + switch ($event_status) { |
|
264 | 264 | case EE_Datetime::sold_out : |
265 | 265 | $btn_text = __('Sold Out', 'event_espresso'); |
266 | 266 | $class = 'ee-pink'; |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | case EE_Datetime::upcoming : |
277 | 277 | case EE_Datetime::active : |
278 | 278 | default : |
279 | - $btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' ); |
|
279 | + $btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso'); |
|
280 | 280 | $class = 'ee-green'; |
281 | 281 | } |
282 | - if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) { |
|
282 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
283 | 283 | $btn_text = $btn_text_if_inactive; |
284 | 284 | $class = 'ee-grey'; |
285 | 285 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | |
294 | 294 | |
295 | 295 | |
296 | -if ( ! function_exists( 'espresso_display_ticket_selector' )) { |
|
296 | +if ( ! function_exists('espresso_display_ticket_selector')) { |
|
297 | 297 | /** |
298 | 298 | * espresso_display_ticket_selector |
299 | 299 | * whether or not to display the Ticket Selector for an event |
@@ -301,14 +301,14 @@ discard block |
||
301 | 301 | * @param bool $EVT_ID |
302 | 302 | * @return boolean |
303 | 303 | */ |
304 | - function espresso_display_ticket_selector( $EVT_ID = FALSE ) { |
|
305 | - return EEH_Event_View::display_ticket_selector( $EVT_ID ); |
|
304 | + function espresso_display_ticket_selector($EVT_ID = FALSE) { |
|
305 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | |
310 | 310 | |
311 | -if ( ! function_exists( 'espresso_event_status_banner' )) { |
|
311 | +if ( ! function_exists('espresso_event_status_banner')) { |
|
312 | 312 | /** |
313 | 313 | * espresso_event_status |
314 | 314 | * returns a banner showing the event status if it is sold out, expired, or inactive |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | * @param bool $EVT_ID |
317 | 317 | * @return string |
318 | 318 | */ |
319 | - function espresso_event_status_banner( $EVT_ID = FALSE ) { |
|
320 | - return EEH_Event_View::event_status( $EVT_ID ); |
|
319 | + function espresso_event_status_banner($EVT_ID = FALSE) { |
|
320 | + return EEH_Event_View::event_status($EVT_ID); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | |
325 | -if ( ! function_exists( 'espresso_event_status' )) { |
|
325 | +if ( ! function_exists('espresso_event_status')) { |
|
326 | 326 | /** |
327 | 327 | * espresso_event_status |
328 | 328 | * returns the event status if it is sold out, expired, or inactive |
@@ -331,17 +331,17 @@ discard block |
||
331 | 331 | * @param bool $echo |
332 | 332 | * @return string |
333 | 333 | */ |
334 | - function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) { |
|
335 | - if ( $echo ) { |
|
336 | - echo EEH_Event_View::event_active_status( $EVT_ID ); |
|
334 | + function espresso_event_status($EVT_ID = 0, $echo = TRUE) { |
|
335 | + if ($echo) { |
|
336 | + echo EEH_Event_View::event_active_status($EVT_ID); |
|
337 | 337 | return ''; |
338 | 338 | } |
339 | - return EEH_Event_View::event_active_status( $EVT_ID ); |
|
339 | + return EEH_Event_View::event_active_status($EVT_ID); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | 343 | |
344 | -if ( ! function_exists( 'espresso_event_categories' )) { |
|
344 | +if ( ! function_exists('espresso_event_categories')) { |
|
345 | 345 | /** |
346 | 346 | * espresso_event_categories |
347 | 347 | * returns the terms associated with an event |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | * @param bool $echo |
352 | 352 | * @return string |
353 | 353 | */ |
354 | - function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
355 | - if ( $echo ) { |
|
356 | - echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
354 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
355 | + if ($echo) { |
|
356 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
357 | 357 | return ''; |
358 | 358 | } |
359 | - return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
359 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | 363 | |
364 | -if ( ! function_exists( 'espresso_event_tickets_available' )) { |
|
364 | +if ( ! function_exists('espresso_event_tickets_available')) { |
|
365 | 365 | /** |
366 | 366 | * espresso_event_tickets_available |
367 | 367 | * returns the ticket types available for purchase for an event |
@@ -371,26 +371,26 @@ discard block |
||
371 | 371 | * @param bool $format |
372 | 372 | * @return string |
373 | 373 | */ |
374 | - function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) { |
|
375 | - $tickets = EEH_Event_View::event_tickets_available( $EVT_ID ); |
|
376 | - if ( is_array( $tickets ) && ! empty( $tickets )) { |
|
374 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) { |
|
375 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
376 | + if (is_array($tickets) && ! empty($tickets)) { |
|
377 | 377 | // if formatting then $html will be a string, else it will be an array of ticket objects |
378 | - $html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array(); |
|
379 | - foreach ( $tickets as $ticket ) { |
|
380 | - if ( $ticket instanceof EE_Ticket ) { |
|
381 | - if ( $format ) { |
|
382 | - $html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">'; |
|
383 | - $html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() ); |
|
378 | + $html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array(); |
|
379 | + foreach ($tickets as $ticket) { |
|
380 | + if ($ticket instanceof EE_Ticket) { |
|
381 | + if ($format) { |
|
382 | + $html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">'; |
|
383 | + $html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes()); |
|
384 | 384 | $html .= '</li>'; |
385 | 385 | } else { |
386 | 386 | $html[] = $ticket; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | } |
390 | - if ( $format ) { |
|
390 | + if ($format) { |
|
391 | 391 | $html .= '</ul>'; |
392 | 392 | } |
393 | - if ( $echo && ! $format ) { |
|
393 | + if ($echo && ! $format) { |
|
394 | 394 | echo $html; |
395 | 395 | return ''; |
396 | 396 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | -if ( ! function_exists( 'espresso_event_date_obj' )) { |
|
403 | +if ( ! function_exists('espresso_event_date_obj')) { |
|
404 | 404 | /** |
405 | 405 | * espresso_event_date_obj |
406 | 406 | * returns the primary date object for an event |
@@ -408,13 +408,13 @@ discard block |
||
408 | 408 | * @param bool $EVT_ID |
409 | 409 | * @return object |
410 | 410 | */ |
411 | - function espresso_event_date_obj( $EVT_ID = FALSE ) { |
|
412 | - return EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
411 | + function espresso_event_date_obj($EVT_ID = FALSE) { |
|
412 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | 416 | |
417 | -if ( ! function_exists( 'espresso_event_date' )) { |
|
417 | +if ( ! function_exists('espresso_event_date')) { |
|
418 | 418 | /** |
419 | 419 | * espresso_event_date |
420 | 420 | * returns the primary date for an event |
@@ -425,22 +425,22 @@ discard block |
||
425 | 425 | * @param bool $echo |
426 | 426 | * @return string |
427 | 427 | */ |
428 | - function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
429 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
430 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
431 | - $date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format ); |
|
432 | - $time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format ); |
|
433 | - if($echo){ |
|
434 | - echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
428 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
429 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
430 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
431 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
432 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
433 | + if ($echo) { |
|
434 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
435 | 435 | return ''; |
436 | 436 | } |
437 | - return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
437 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
438 | 438 | |
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | |
443 | -if ( ! function_exists( 'espresso_list_of_event_dates' )) { |
|
443 | +if ( ! function_exists('espresso_list_of_event_dates')) { |
|
444 | 444 | /** |
445 | 445 | * espresso_list_of_event_dates |
446 | 446 | * returns a unordered list of dates for an event |
@@ -455,40 +455,40 @@ discard block |
||
455 | 455 | * @param null $limit |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) { |
|
459 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
460 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
461 | - $date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format ); |
|
462 | - $time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format ); |
|
463 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit ); |
|
464 | - if ( ! $format ) { |
|
465 | - return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes ); |
|
458 | + function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) { |
|
459 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
460 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
461 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
462 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
463 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit); |
|
464 | + if ( ! $format) { |
|
465 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
466 | 466 | } |
467 | 467 | //d( $datetimes ); |
468 | - if ( is_array( $datetimes ) && ! empty( $datetimes )) { |
|
468 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
469 | 469 | global $post; |
470 | - $html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
471 | - foreach ( $datetimes as $datetime ) { |
|
472 | - if ( $datetime instanceof EE_Datetime ) { |
|
473 | - $html .= '<li id="ee-event-datetimes-li-' . $datetime->ID(); |
|
474 | - $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">'; |
|
470 | + $html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
471 | + foreach ($datetimes as $datetime) { |
|
472 | + if ($datetime instanceof EE_Datetime) { |
|
473 | + $html .= '<li id="ee-event-datetimes-li-'.$datetime->ID(); |
|
474 | + $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">'; |
|
475 | 475 | $datetime_name = $datetime->name(); |
476 | - $html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : ''; |
|
477 | - $html .= ! empty( $datetime_name ) && $add_breaks ? '<br />' : ''; |
|
478 | - $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>'; |
|
479 | - $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>'; |
|
476 | + $html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : ''; |
|
477 | + $html .= ! empty($datetime_name) && $add_breaks ? '<br />' : ''; |
|
478 | + $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>'; |
|
479 | + $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>'; |
|
480 | 480 | $datetime_description = $datetime->description(); |
481 | - $html .= ! empty( $datetime_description ) && $add_breaks ? '<br />' : ''; |
|
482 | - $html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : ''; |
|
483 | - $html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime ); |
|
481 | + $html .= ! empty($datetime_description) && $add_breaks ? '<br />' : ''; |
|
482 | + $html .= ! empty($datetime_description) ? ' - '.$datetime_description : ''; |
|
483 | + $html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime); |
|
484 | 484 | $html .= '</li>'; |
485 | 485 | } |
486 | 486 | } |
487 | 487 | $html .= $format ? '</ul>' : ''; |
488 | 488 | } else { |
489 | - $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : ''; |
|
489 | + $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : ''; |
|
490 | 490 | } |
491 | - if ( $echo ) { |
|
491 | + if ($echo) { |
|
492 | 492 | echo $html; |
493 | 493 | return ''; |
494 | 494 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | |
500 | -if ( ! function_exists( 'espresso_event_end_date' )) { |
|
500 | +if ( ! function_exists('espresso_event_end_date')) { |
|
501 | 501 | /** |
502 | 502 | * espresso_event_end_date |
503 | 503 | * returns the last date for an event |
@@ -508,20 +508,20 @@ discard block |
||
508 | 508 | * @param bool $echo |
509 | 509 | * @return string |
510 | 510 | */ |
511 | - function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
512 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
513 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
514 | - $date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format ); |
|
515 | - $time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format ); |
|
516 | - if($echo){ |
|
517 | - echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
511 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
512 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
513 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
514 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
515 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
516 | + if ($echo) { |
|
517 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
518 | 518 | return ''; |
519 | 519 | } |
520 | - return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
520 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
524 | -if ( ! function_exists( 'espresso_event_date_range' )) { |
|
524 | +if ( ! function_exists('espresso_event_date_range')) { |
|
525 | 525 | /** |
526 | 526 | * espresso_event_date_range |
527 | 527 | * returns the first and last chronologically ordered dates for an event (if different) |
@@ -534,31 +534,31 @@ discard block |
||
534 | 534 | * @param bool $echo |
535 | 535 | * @return string |
536 | 536 | */ |
537 | - function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
537 | + function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
538 | 538 | // set and filter date and time formats when a range is returned |
539 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
540 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format ); |
|
539 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
541 | 541 | // get the start and end date with NO time portion |
542 | - $the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID ); |
|
543 | - $the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID ); |
|
542 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
543 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
544 | 544 | // now we can determine if date range spans more than one day |
545 | - if ( $the_event_date != $the_event_end_date ) { |
|
546 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
547 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format ); |
|
545 | + if ($the_event_date != $the_event_end_date) { |
|
546 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
547 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
548 | 548 | $html = sprintf( |
549 | - __( '%1$s - %2$s', 'event_espresso' ), |
|
550 | - EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ), |
|
551 | - EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID ) |
|
549 | + __('%1$s - %2$s', 'event_espresso'), |
|
550 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
551 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
552 | 552 | ); |
553 | 553 | } else { |
554 | 554 | // set and filter date and time formats when only a single datetime is returned |
555 | - $single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' ); |
|
556 | - $single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' ); |
|
557 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format ); |
|
558 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format ); |
|
559 | - $html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID ); |
|
555 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
556 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
557 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
558 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
559 | + $html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
560 | 560 | } |
561 | - if ( $echo ) { |
|
561 | + if ($echo) { |
|
562 | 562 | echo $html; |
563 | 563 | return ''; |
564 | 564 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | -if ( ! function_exists( 'espresso_next_upcoming_datetime_obj' )) { |
|
569 | +if ( ! function_exists('espresso_next_upcoming_datetime_obj')) { |
|
570 | 570 | /** |
571 | 571 | * espresso_next_upcoming_datetime_obj |
572 | 572 | * returns the next upcoming datetime object for an event |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | * @param int $EVT_ID |
575 | 575 | * @return EE_Datetime|null |
576 | 576 | */ |
577 | - function espresso_next_upcoming_datetime_obj( $EVT_ID = 0 ) { |
|
578 | - return EEH_Event_View::get_next_upcoming_date_obj( $EVT_ID ); |
|
577 | + function espresso_next_upcoming_datetime_obj($EVT_ID = 0) { |
|
578 | + return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | -if ( ! function_exists( 'espresso_next_upcoming_datetime' ) ) { |
|
582 | +if ( ! function_exists('espresso_next_upcoming_datetime')) { |
|
583 | 583 | /** |
584 | 584 | * espresso_next_upcoming_datetime |
585 | 585 | * returns the start date and time for the next upcoming event. |
@@ -590,30 +590,30 @@ discard block |
||
590 | 590 | * @param bool $echo |
591 | 591 | * @return string |
592 | 592 | */ |
593 | - function espresso_next_upcoming_datetime( $date_format = '', $time_format = '', $EVT_ID = 0, $echo = true ) { |
|
593 | + function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) { |
|
594 | 594 | |
595 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
596 | - $date_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__date_format', $date_format ); |
|
595 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
596 | + $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
597 | 597 | |
598 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
599 | - $time_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__time_format', $time_format ); |
|
598 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
599 | + $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
600 | 600 | |
601 | - $datetime_format = trim( $date_format . ' ' . $time_format); |
|
601 | + $datetime_format = trim($date_format.' '.$time_format); |
|
602 | 602 | |
603 | - $datetime = espresso_next_upcoming_datetime_obj( $EVT_ID ); |
|
603 | + $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
604 | 604 | |
605 | - if( ! $datetime instanceof EE_Datetime ) { |
|
605 | + if ( ! $datetime instanceof EE_Datetime) { |
|
606 | 606 | return ''; |
607 | 607 | } |
608 | - if ( $echo ){ |
|
609 | - echo $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format ); |
|
608 | + if ($echo) { |
|
609 | + echo $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
610 | 610 | return ''; |
611 | 611 | } |
612 | - return $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format ); |
|
612 | + return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | -if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) { |
|
616 | +if ( ! function_exists('espresso_event_date_as_calendar_page')) { |
|
617 | 617 | /** |
618 | 618 | * espresso_event_date_as_calendar_page |
619 | 619 | * returns the primary date for an event, stylized to appear as the page of a calendar |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | * @param bool $EVT_ID |
622 | 622 | * @return string |
623 | 623 | */ |
624 | - function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) { |
|
625 | - EEH_Event_View::event_date_as_calendar_page( $EVT_ID ); |
|
624 | + function espresso_event_date_as_calendar_page($EVT_ID = FALSE) { |
|
625 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
629 | 629 | |
630 | 630 | |
631 | 631 | |
632 | -if ( ! function_exists( 'espresso_event_link_url' )) { |
|
632 | +if ( ! function_exists('espresso_event_link_url')) { |
|
633 | 633 | /** |
634 | 634 | * espresso_event_link_url |
635 | 635 | * |
@@ -637,18 +637,18 @@ discard block |
||
637 | 637 | * @param bool $echo |
638 | 638 | * @return string |
639 | 639 | */ |
640 | - function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) { |
|
641 | - if ( $echo ) { |
|
642 | - echo EEH_Event_View::event_link_url( $EVT_ID ); |
|
640 | + function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) { |
|
641 | + if ($echo) { |
|
642 | + echo EEH_Event_View::event_link_url($EVT_ID); |
|
643 | 643 | return ''; |
644 | 644 | } |
645 | - return EEH_Event_View::event_link_url( $EVT_ID ); |
|
645 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | 649 | |
650 | 650 | |
651 | -if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) { |
|
651 | +if ( ! function_exists('espresso_event_has_content_or_excerpt')) { |
|
652 | 652 | /** |
653 | 653 | * espresso_event_has_content_or_excerpt |
654 | 654 | * |
@@ -656,15 +656,15 @@ discard block |
||
656 | 656 | * @param bool $EVT_ID |
657 | 657 | * @return boolean |
658 | 658 | */ |
659 | - function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) { |
|
660 | - return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID ); |
|
659 | + function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) { |
|
660 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
661 | 661 | } |
662 | 662 | } |
663 | 663 | |
664 | 664 | |
665 | 665 | |
666 | 666 | |
667 | -if ( ! function_exists( 'espresso_event_content_or_excerpt' )) { |
|
667 | +if ( ! function_exists('espresso_event_content_or_excerpt')) { |
|
668 | 668 | /** |
669 | 669 | * espresso_event_content_or_excerpt |
670 | 670 | * |
@@ -673,18 +673,18 @@ discard block |
||
673 | 673 | * @param bool $echo |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) { |
|
677 | - if ( $echo ) { |
|
678 | - echo EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
676 | + function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) { |
|
677 | + if ($echo) { |
|
678 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
679 | 679 | return ''; |
680 | 680 | } |
681 | - return EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
681 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
682 | 682 | } |
683 | 683 | } |
684 | 684 | |
685 | 685 | |
686 | 686 | |
687 | -if ( ! function_exists( 'espresso_event_phone' )) { |
|
687 | +if ( ! function_exists('espresso_event_phone')) { |
|
688 | 688 | /** |
689 | 689 | * espresso_event_phone |
690 | 690 | * |
@@ -692,18 +692,18 @@ discard block |
||
692 | 692 | * @param bool $echo |
693 | 693 | * @return string |
694 | 694 | */ |
695 | - function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) { |
|
696 | - if ( $echo ) { |
|
697 | - echo EEH_Event_View::event_phone( $EVT_ID ); |
|
695 | + function espresso_event_phone($EVT_ID = 0, $echo = TRUE) { |
|
696 | + if ($echo) { |
|
697 | + echo EEH_Event_View::event_phone($EVT_ID); |
|
698 | 698 | return ''; |
699 | 699 | } |
700 | - return EEH_Event_View::event_phone( $EVT_ID ); |
|
700 | + return EEH_Event_View::event_phone($EVT_ID); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | 704 | |
705 | 705 | |
706 | -if ( ! function_exists( 'espresso_edit_event_link' )) { |
|
706 | +if ( ! function_exists('espresso_edit_event_link')) { |
|
707 | 707 | /** |
708 | 708 | * espresso_edit_event_link |
709 | 709 | * returns a link to edit an event |
@@ -712,39 +712,39 @@ discard block |
||
712 | 712 | * @param bool $echo |
713 | 713 | * @return string |
714 | 714 | */ |
715 | - function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) { |
|
716 | - if ( $echo ) { |
|
717 | - echo EEH_Event_View::edit_event_link( $EVT_ID ); |
|
715 | + function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) { |
|
716 | + if ($echo) { |
|
717 | + echo EEH_Event_View::edit_event_link($EVT_ID); |
|
718 | 718 | return ''; |
719 | 719 | } |
720 | - return EEH_Event_View::edit_event_link( $EVT_ID ); |
|
720 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
721 | 721 | } |
722 | 722 | } |
723 | 723 | |
724 | 724 | |
725 | -if ( ! function_exists( 'espresso_organization_name' )) { |
|
725 | +if ( ! function_exists('espresso_organization_name')) { |
|
726 | 726 | /** |
727 | 727 | * espresso_organization_name |
728 | 728 | * @param bool $echo |
729 | 729 | * @return string |
730 | 730 | */ |
731 | 731 | function espresso_organization_name($echo = TRUE) { |
732 | - if($echo){ |
|
733 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
732 | + if ($echo) { |
|
733 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
734 | 734 | return ''; |
735 | 735 | } |
736 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
736 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | -if ( ! function_exists( 'espresso_organization_address' )) { |
|
740 | +if ( ! function_exists('espresso_organization_address')) { |
|
741 | 741 | /** |
742 | 742 | * espresso_organization_address |
743 | 743 | * @param string $type |
744 | 744 | * @return string |
745 | 745 | */ |
746 | - function espresso_organization_address( $type = 'inline' ) { |
|
747 | - if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) { |
|
746 | + function espresso_organization_address($type = 'inline') { |
|
747 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
748 | 748 | $address = new EventEspresso\core\domain\entities\GenericAddress( |
749 | 749 | EE_Registry::instance()->CFG->organization->address_1, |
750 | 750 | EE_Registry::instance()->CFG->organization->address_2, |
@@ -753,129 +753,129 @@ discard block |
||
753 | 753 | EE_Registry::instance()->CFG->organization->zip, |
754 | 754 | EE_Registry::instance()->CFG->organization->CNT_ISO |
755 | 755 | ); |
756 | - return EEH_Address::format( $address, $type ); |
|
756 | + return EEH_Address::format($address, $type); |
|
757 | 757 | } |
758 | 758 | return ''; |
759 | 759 | } |
760 | 760 | } |
761 | 761 | |
762 | -if ( ! function_exists( 'espresso_organization_email' )) { |
|
762 | +if ( ! function_exists('espresso_organization_email')) { |
|
763 | 763 | /** |
764 | 764 | * espresso_organization_email |
765 | 765 | * @param bool $echo |
766 | 766 | * @return string |
767 | 767 | */ |
768 | - function espresso_organization_email( $echo = TRUE ) { |
|
769 | - if($echo){ |
|
770 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
768 | + function espresso_organization_email($echo = TRUE) { |
|
769 | + if ($echo) { |
|
770 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
771 | 771 | return ''; |
772 | 772 | } |
773 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
773 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
774 | 774 | } |
775 | 775 | } |
776 | 776 | |
777 | -if ( ! function_exists( 'espresso_organization_logo_url' )) { |
|
777 | +if ( ! function_exists('espresso_organization_logo_url')) { |
|
778 | 778 | /** |
779 | 779 | * espresso_organization_logo_url |
780 | 780 | * @param bool $echo |
781 | 781 | * @return string |
782 | 782 | */ |
783 | - function espresso_organization_logo_url( $echo = TRUE ) { |
|
784 | - if($echo){ |
|
785 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
783 | + function espresso_organization_logo_url($echo = TRUE) { |
|
784 | + if ($echo) { |
|
785 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
786 | 786 | return ''; |
787 | 787 | } |
788 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
788 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
789 | 789 | } |
790 | 790 | } |
791 | 791 | |
792 | -if ( ! function_exists( 'espresso_organization_facebook' )) { |
|
792 | +if ( ! function_exists('espresso_organization_facebook')) { |
|
793 | 793 | /** |
794 | 794 | * espresso_organization_facebook |
795 | 795 | * @param bool $echo |
796 | 796 | * @return string |
797 | 797 | */ |
798 | - function espresso_organization_facebook( $echo = TRUE ) { |
|
799 | - if($echo){ |
|
800 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
798 | + function espresso_organization_facebook($echo = TRUE) { |
|
799 | + if ($echo) { |
|
800 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
801 | 801 | return ''; |
802 | 802 | } |
803 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
803 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
804 | 804 | } |
805 | 805 | } |
806 | 806 | |
807 | -if ( ! function_exists( 'espresso_organization_twitter' )) { |
|
807 | +if ( ! function_exists('espresso_organization_twitter')) { |
|
808 | 808 | /** |
809 | 809 | * espresso_organization_twitter |
810 | 810 | * @param bool $echo |
811 | 811 | * @return string |
812 | 812 | */ |
813 | - function espresso_organization_twitter( $echo = TRUE ) { |
|
814 | - if($echo){ |
|
815 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
813 | + function espresso_organization_twitter($echo = TRUE) { |
|
814 | + if ($echo) { |
|
815 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
816 | 816 | return ''; |
817 | 817 | } |
818 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
818 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
819 | 819 | } |
820 | 820 | } |
821 | 821 | |
822 | -if ( ! function_exists( 'espresso_organization_linkedin' )) { |
|
822 | +if ( ! function_exists('espresso_organization_linkedin')) { |
|
823 | 823 | /** |
824 | 824 | * espresso_organization_linkedin |
825 | 825 | * @param bool $echo |
826 | 826 | * @return string |
827 | 827 | */ |
828 | - function espresso_organization_linkedin( $echo = TRUE ) { |
|
829 | - if($echo){ |
|
830 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
828 | + function espresso_organization_linkedin($echo = TRUE) { |
|
829 | + if ($echo) { |
|
830 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
831 | 831 | return ''; |
832 | 832 | } |
833 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
833 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
834 | 834 | } |
835 | 835 | } |
836 | 836 | |
837 | -if ( ! function_exists( 'espresso_organization_pinterest' )) { |
|
837 | +if ( ! function_exists('espresso_organization_pinterest')) { |
|
838 | 838 | /** |
839 | 839 | * espresso_organization_pinterest |
840 | 840 | * @param bool $echo |
841 | 841 | * @return string |
842 | 842 | */ |
843 | - function espresso_organization_pinterest( $echo = TRUE ) { |
|
844 | - if($echo){ |
|
845 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
843 | + function espresso_organization_pinterest($echo = TRUE) { |
|
844 | + if ($echo) { |
|
845 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
846 | 846 | return ''; |
847 | 847 | } |
848 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
848 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
849 | 849 | } |
850 | 850 | } |
851 | 851 | |
852 | -if ( ! function_exists( 'espresso_organization_google' )) { |
|
852 | +if ( ! function_exists('espresso_organization_google')) { |
|
853 | 853 | /** |
854 | 854 | * espresso_organization_google |
855 | 855 | * @param bool $echo |
856 | 856 | * @return string |
857 | 857 | */ |
858 | - function espresso_organization_google( $echo = TRUE ) { |
|
859 | - if($echo){ |
|
860 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
858 | + function espresso_organization_google($echo = TRUE) { |
|
859 | + if ($echo) { |
|
860 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
861 | 861 | return ''; |
862 | 862 | } |
863 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
863 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
867 | -if ( ! function_exists( 'espresso_organization_instagram' )) { |
|
867 | +if ( ! function_exists('espresso_organization_instagram')) { |
|
868 | 868 | /** |
869 | 869 | * espresso_organization_instagram |
870 | 870 | * @param bool $echo |
871 | 871 | * @return string |
872 | 872 | */ |
873 | - function espresso_organization_instagram( $echo = TRUE ) { |
|
874 | - if($echo){ |
|
875 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
873 | + function espresso_organization_instagram($echo = TRUE) { |
|
874 | + if ($echo) { |
|
875 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
876 | 876 | return ''; |
877 | 877 | } |
878 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
878 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
879 | 879 | } |
880 | 880 | } |
881 | 881 | |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | |
886 | 886 | |
887 | 887 | |
888 | -if ( ! function_exists( 'espresso_event_venues' )) { |
|
888 | +if ( ! function_exists('espresso_event_venues')) { |
|
889 | 889 | /** |
890 | 890 | * espresso_event_venues |
891 | 891 | * |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | |
900 | 900 | |
901 | 901 | |
902 | -if ( ! function_exists( 'espresso_venue_id' )) { |
|
902 | +if ( ! function_exists('espresso_venue_id')) { |
|
903 | 903 | /** |
904 | 904 | * espresso_venue_name |
905 | 905 | * |
@@ -907,15 +907,15 @@ discard block |
||
907 | 907 | * @param int $EVT_ID |
908 | 908 | * @return string |
909 | 909 | */ |
910 | - function espresso_venue_id( $EVT_ID = 0 ) { |
|
911 | - $venue = EEH_Venue_View::get_venue( $EVT_ID ); |
|
910 | + function espresso_venue_id($EVT_ID = 0) { |
|
911 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
912 | 912 | return $venue instanceof EE_Venue ? $venue->ID() : 0; |
913 | 913 | } |
914 | 914 | } |
915 | 915 | |
916 | 916 | |
917 | 917 | |
918 | -if ( ! function_exists( 'espresso_is_venue_private' ) ) { |
|
918 | +if ( ! function_exists('espresso_is_venue_private')) { |
|
919 | 919 | /** |
920 | 920 | * Return whether a venue is private or not. |
921 | 921 | * @see EEH_Venue_View::get_venue() for more info on expected return results. |
@@ -924,45 +924,45 @@ discard block |
||
924 | 924 | * |
925 | 925 | * @return bool | null |
926 | 926 | */ |
927 | - function espresso_is_venue_private( $VNU_ID = 0 ) { |
|
928 | - return EEH_Venue_View::is_venue_private( $VNU_ID ); |
|
927 | + function espresso_is_venue_private($VNU_ID = 0) { |
|
928 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
929 | 929 | } |
930 | 930 | } |
931 | 931 | |
932 | 932 | |
933 | 933 | |
934 | -if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) { |
|
934 | +if ( ! function_exists('espresso_venue_is_password_protected')) { |
|
935 | 935 | /** |
936 | 936 | * returns true or false if a venue is password protected or not |
937 | 937 | * |
938 | 938 | * @param int $VNU_ID optional, the venue id to check. |
939 | 939 | * @return string |
940 | 940 | */ |
941 | - function espresso_venue_is_password_protected( $VNU_ID = 0 ) { |
|
942 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
943 | - return EEH_Venue_View::is_venue_password_protected( $VNU_ID ); |
|
941 | + function espresso_venue_is_password_protected($VNU_ID = 0) { |
|
942 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
943 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
944 | 944 | } |
945 | 945 | } |
946 | 946 | |
947 | 947 | |
948 | 948 | |
949 | -if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) { |
|
949 | +if ( ! function_exists('espresso_password_protected_venue_form')) { |
|
950 | 950 | /** |
951 | 951 | * Returns a password form if venue is password protected. |
952 | 952 | * |
953 | 953 | * @param int $VNU_ID optional, the venue id to check. |
954 | 954 | * @return string |
955 | 955 | */ |
956 | - function espresso_password_protected_venue_form( $VNU_ID = 0 ) { |
|
957 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
958 | - return EEH_Venue_View::password_protected_venue_form( $VNU_ID ); |
|
956 | + function espresso_password_protected_venue_form($VNU_ID = 0) { |
|
957 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
958 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
959 | 959 | } |
960 | 960 | } |
961 | 961 | |
962 | 962 | |
963 | 963 | |
964 | 964 | |
965 | -if ( ! function_exists( 'espresso_venue_name' )) { |
|
965 | +if ( ! function_exists('espresso_venue_name')) { |
|
966 | 966 | /** |
967 | 967 | * espresso_venue_name |
968 | 968 | * |
@@ -972,19 +972,19 @@ discard block |
||
972 | 972 | * @param bool $echo |
973 | 973 | * @return string |
974 | 974 | */ |
975 | - function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) { |
|
976 | - if($echo){ |
|
977 | - echo EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
975 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) { |
|
976 | + if ($echo) { |
|
977 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
978 | 978 | return ''; |
979 | 979 | } |
980 | - return EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
980 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
981 | 981 | } |
982 | 982 | } |
983 | 983 | |
984 | 984 | |
985 | 985 | |
986 | 986 | |
987 | -if ( ! function_exists( 'espresso_venue_link' )) { |
|
987 | +if ( ! function_exists('espresso_venue_link')) { |
|
988 | 988 | /** |
989 | 989 | * espresso_venue_link |
990 | 990 | * |
@@ -993,14 +993,14 @@ discard block |
||
993 | 993 | * @param string $text |
994 | 994 | * @return string |
995 | 995 | */ |
996 | - function espresso_venue_link( $VNU_ID = 0, $text = '' ) { |
|
997 | - return EEH_Venue_View::venue_details_link( $VNU_ID, $text ); |
|
996 | + function espresso_venue_link($VNU_ID = 0, $text = '') { |
|
997 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
998 | 998 | } |
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | |
1002 | 1002 | |
1003 | -if ( ! function_exists( 'espresso_venue_description' )) { |
|
1003 | +if ( ! function_exists('espresso_venue_description')) { |
|
1004 | 1004 | /** |
1005 | 1005 | * espresso_venue_description |
1006 | 1006 | * |
@@ -1009,17 +1009,17 @@ discard block |
||
1009 | 1009 | * @param bool $echo |
1010 | 1010 | * @return string |
1011 | 1011 | */ |
1012 | - function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) { |
|
1013 | - if($echo){ |
|
1014 | - echo EEH_Venue_View::venue_description( $VNU_ID ); |
|
1012 | + function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) { |
|
1013 | + if ($echo) { |
|
1014 | + echo EEH_Venue_View::venue_description($VNU_ID); |
|
1015 | 1015 | return ''; |
1016 | 1016 | } |
1017 | - return EEH_Venue_View::venue_description( $VNU_ID ); |
|
1017 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
1018 | 1018 | } |
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | |
1022 | -if ( ! function_exists( 'espresso_venue_excerpt' )) { |
|
1022 | +if ( ! function_exists('espresso_venue_excerpt')) { |
|
1023 | 1023 | /** |
1024 | 1024 | * espresso_venue_excerpt |
1025 | 1025 | * |
@@ -1028,18 +1028,18 @@ discard block |
||
1028 | 1028 | * @param bool $echo |
1029 | 1029 | * @return string |
1030 | 1030 | */ |
1031 | - function espresso_venue_excerpt( $VNU_ID = 0, $echo = TRUE ) { |
|
1032 | - if ( $echo ) { |
|
1033 | - echo EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
1031 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) { |
|
1032 | + if ($echo) { |
|
1033 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1034 | 1034 | return ''; |
1035 | 1035 | } |
1036 | - return EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
1036 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
1041 | 1041 | |
1042 | -if ( ! function_exists( 'espresso_venue_categories' )) { |
|
1042 | +if ( ! function_exists('espresso_venue_categories')) { |
|
1043 | 1043 | /** |
1044 | 1044 | * espresso_venue_categories |
1045 | 1045 | * returns the terms associated with a venue |
@@ -1049,17 +1049,17 @@ discard block |
||
1049 | 1049 | * @param bool $echo |
1050 | 1050 | * @return string |
1051 | 1051 | */ |
1052 | - function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
1053 | - if ( $echo ) { |
|
1054 | - echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
1052 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
1053 | + if ($echo) { |
|
1054 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1055 | 1055 | return ''; |
1056 | 1056 | } |
1057 | - return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
1057 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1058 | 1058 | } |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | |
1062 | -if ( ! function_exists( 'espresso_venue_address' )) { |
|
1062 | +if ( ! function_exists('espresso_venue_address')) { |
|
1063 | 1063 | /** |
1064 | 1064 | * espresso_venue_address |
1065 | 1065 | * returns a formatted block of html for displaying a venue's address |
@@ -1069,17 +1069,17 @@ discard block |
||
1069 | 1069 | * @param bool $echo |
1070 | 1070 | * @return string |
1071 | 1071 | */ |
1072 | - function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
1073 | - if ( $echo ) { |
|
1074 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
1072 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
1073 | + if ($echo) { |
|
1074 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1075 | 1075 | return ''; |
1076 | 1076 | } |
1077 | - return EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
1077 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1078 | 1078 | } |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | |
1082 | -if ( ! function_exists( 'espresso_venue_raw_address' )) { |
|
1082 | +if ( ! function_exists('espresso_venue_raw_address')) { |
|
1083 | 1083 | /** |
1084 | 1084 | * espresso_venue_address |
1085 | 1085 | * returns an UN-formatted string containing a venue's address |
@@ -1089,17 +1089,17 @@ discard block |
||
1089 | 1089 | * @param bool $echo |
1090 | 1090 | * @return string |
1091 | 1091 | */ |
1092 | - function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
1093 | - if ( $echo ) { |
|
1094 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
1092 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
1093 | + if ($echo) { |
|
1094 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
1095 | 1095 | return ''; |
1096 | 1096 | } |
1097 | - return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
1097 | + return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
1098 | 1098 | } |
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | |
1102 | -if ( ! function_exists( 'espresso_venue_has_address' )) { |
|
1102 | +if ( ! function_exists('espresso_venue_has_address')) { |
|
1103 | 1103 | /** |
1104 | 1104 | * espresso_venue_has_address |
1105 | 1105 | * returns TRUE or FALSE if a Venue has address information |
@@ -1107,13 +1107,13 @@ discard block |
||
1107 | 1107 | * @param int $VNU_ID |
1108 | 1108 | * @return bool |
1109 | 1109 | */ |
1110 | - function espresso_venue_has_address( $VNU_ID = 0 ) { |
|
1111 | - return EEH_Venue_View::venue_has_address( $VNU_ID ); |
|
1110 | + function espresso_venue_has_address($VNU_ID = 0) { |
|
1111 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | |
1116 | -if ( ! function_exists( 'espresso_venue_gmap' )) { |
|
1116 | +if ( ! function_exists('espresso_venue_gmap')) { |
|
1117 | 1117 | /** |
1118 | 1118 | * espresso_venue_gmap |
1119 | 1119 | * returns a google map for the venue address |
@@ -1124,17 +1124,17 @@ discard block |
||
1124 | 1124 | * @param bool $echo |
1125 | 1125 | * @return string |
1126 | 1126 | */ |
1127 | - function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE ) { |
|
1128 | - if ( $echo ) { |
|
1129 | - echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
1127 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) { |
|
1128 | + if ($echo) { |
|
1129 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1130 | 1130 | return ''; |
1131 | 1131 | } |
1132 | - return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
1132 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1133 | 1133 | } |
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | |
1137 | -if ( ! function_exists( 'espresso_venue_phone' )) { |
|
1137 | +if ( ! function_exists('espresso_venue_phone')) { |
|
1138 | 1138 | /** |
1139 | 1139 | * espresso_venue_phone |
1140 | 1140 | * |
@@ -1142,18 +1142,18 @@ discard block |
||
1142 | 1142 | * @param bool $echo |
1143 | 1143 | * @return string |
1144 | 1144 | */ |
1145 | - function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) { |
|
1146 | - if ( $echo ) { |
|
1147 | - echo EEH_Venue_View::venue_phone( $VNU_ID ); |
|
1145 | + function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) { |
|
1146 | + if ($echo) { |
|
1147 | + echo EEH_Venue_View::venue_phone($VNU_ID); |
|
1148 | 1148 | return ''; |
1149 | 1149 | } |
1150 | - return EEH_Venue_View::venue_phone( $VNU_ID ); |
|
1150 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
1151 | 1151 | } |
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | |
1155 | 1155 | |
1156 | -if ( ! function_exists( 'espresso_venue_website' )) { |
|
1156 | +if ( ! function_exists('espresso_venue_website')) { |
|
1157 | 1157 | /** |
1158 | 1158 | * espresso_venue_website |
1159 | 1159 | * |
@@ -1161,18 +1161,18 @@ discard block |
||
1161 | 1161 | * @param bool $echo |
1162 | 1162 | * @return string |
1163 | 1163 | */ |
1164 | - function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) { |
|
1165 | - if ( $echo ) { |
|
1166 | - echo EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
1164 | + function espresso_venue_website($VNU_ID = 0, $echo = TRUE) { |
|
1165 | + if ($echo) { |
|
1166 | + echo EEH_Venue_View::venue_website_link($VNU_ID); |
|
1167 | 1167 | return ''; |
1168 | 1168 | } |
1169 | - return EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
1169 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | |
1174 | 1174 | |
1175 | -if ( ! function_exists( 'espresso_edit_venue_link' )) { |
|
1175 | +if ( ! function_exists('espresso_edit_venue_link')) { |
|
1176 | 1176 | /** |
1177 | 1177 | * espresso_edit_venue_link |
1178 | 1178 | * |
@@ -1180,12 +1180,12 @@ discard block |
||
1180 | 1180 | * @param bool $echo |
1181 | 1181 | * @return string |
1182 | 1182 | */ |
1183 | - function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) { |
|
1184 | - if($echo){ |
|
1185 | - echo EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
1183 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) { |
|
1184 | + if ($echo) { |
|
1185 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1186 | 1186 | return ''; |
1187 | 1187 | } |
1188 | - return EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
1188 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1189 | 1189 | } |
1190 | 1190 | } |
1191 | 1191 |
@@ -164,7 +164,7 @@ |
||
164 | 164 | |
165 | 165 | |
166 | 166 | /** |
167 | - * @param $ticket |
|
167 | + * @param \EE_Base_Class $ticket |
|
168 | 168 | * @throws DomainException |
169 | 169 | * @throws EE_Error |
170 | 170 | * @throws UnexpectedEntityException |
@@ -26,702 +26,702 @@ |
||
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 | - $this->event = $event; |
|
117 | - $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
118 | - $this->setHooks(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - private function setHooks() |
|
126 | - { |
|
127 | - add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
128 | - add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
129 | - add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
130 | - add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
131 | - add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
132 | - add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
133 | - add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
134 | - add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - public function clearResults() |
|
142 | - { |
|
143 | - $this->spaces_remaining = null; |
|
144 | - $this->total_spaces_available = null; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return EE_Ticket[] |
|
150 | - * @throws EE_Error |
|
151 | - * @throws InvalidDataTypeException |
|
152 | - * @throws InvalidInterfaceException |
|
153 | - * @throws InvalidArgumentException |
|
154 | - */ |
|
155 | - public function getActiveTickets() |
|
156 | - { |
|
157 | - if (empty($this->active_tickets)) { |
|
158 | - $this->active_tickets = $this->event->tickets( |
|
159 | - array( |
|
160 | - array('TKT_deleted' => false), |
|
161 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
162 | - ) |
|
163 | - ); |
|
164 | - } |
|
165 | - return $this->active_tickets; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param EE_Ticket[] $active_tickets |
|
171 | - * @throws EE_Error |
|
172 | - * @throws DomainException |
|
173 | - * @throws UnexpectedEntityException |
|
174 | - */ |
|
175 | - public function setActiveTickets(array $active_tickets = array()) |
|
176 | - { |
|
177 | - if (! empty($active_tickets)) { |
|
178 | - foreach ($active_tickets as $active_ticket) { |
|
179 | - $this->validateTicket($active_ticket); |
|
180 | - } |
|
181 | - // sort incoming array by ticket quantity (asc) |
|
182 | - usort( |
|
183 | - $active_tickets, |
|
184 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
185 | - if ($a->qty() === $b->qty()) { |
|
186 | - return 0; |
|
187 | - } |
|
188 | - return ($a->qty() < $b->qty()) |
|
189 | - ? -1 |
|
190 | - : 1; |
|
191 | - } |
|
192 | - ); |
|
193 | - } |
|
194 | - $this->active_tickets = $active_tickets; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @param $ticket |
|
200 | - * @throws DomainException |
|
201 | - * @throws EE_Error |
|
202 | - * @throws UnexpectedEntityException |
|
203 | - */ |
|
204 | - private function validateTicket($ticket) |
|
205 | - { |
|
206 | - if (! $ticket instanceof EE_Ticket) { |
|
207 | - throw new DomainException( |
|
208 | - esc_html__( |
|
209 | - 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
210 | - 'event_espresso' |
|
211 | - ) |
|
212 | - ); |
|
213 | - } |
|
214 | - if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
215 | - throw new DomainException( |
|
216 | - sprintf( |
|
217 | - esc_html__( |
|
218 | - 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - $ticket->get_event_ID(), |
|
222 | - $this->event->ID() |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @return EE_Datetime[] |
|
231 | - */ |
|
232 | - public function getDatetimes() |
|
233 | - { |
|
234 | - return $this->datetimes; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param EE_Datetime $datetime |
|
240 | - * @throws EE_Error |
|
241 | - * @throws DomainException |
|
242 | - */ |
|
243 | - public function setDatetime(EE_Datetime $datetime) |
|
244 | - { |
|
245 | - if ($datetime->event()->ID() !== $this->event->ID()) { |
|
246 | - throw new DomainException( |
|
247 | - sprintf( |
|
248 | - esc_html__( |
|
249 | - 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
250 | - 'event_espresso' |
|
251 | - ), |
|
252 | - $datetime->event()->ID(), |
|
253 | - $this->event->ID() |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * calculate spaces remaining based on "saleable" tickets |
|
263 | - * |
|
264 | - * @return float|int |
|
265 | - * @throws EE_Error |
|
266 | - * @throws DomainException |
|
267 | - * @throws UnexpectedEntityException |
|
268 | - * @throws InvalidDataTypeException |
|
269 | - * @throws InvalidInterfaceException |
|
270 | - * @throws InvalidArgumentException |
|
271 | - */ |
|
272 | - public function spacesRemaining() |
|
273 | - { |
|
274 | - if ($this->spaces_remaining === null) { |
|
275 | - $this->initialize(); |
|
276 | - $this->spaces_remaining = $this->calculate(); |
|
277 | - } |
|
278 | - return $this->spaces_remaining; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * calculates total available spaces for an event with no regard for sold tickets |
|
284 | - * |
|
285 | - * @return int|float |
|
286 | - * @throws EE_Error |
|
287 | - * @throws DomainException |
|
288 | - * @throws UnexpectedEntityException |
|
289 | - * @throws InvalidDataTypeException |
|
290 | - * @throws InvalidInterfaceException |
|
291 | - * @throws InvalidArgumentException |
|
292 | - */ |
|
293 | - public function totalSpacesAvailable() |
|
294 | - { |
|
295 | - if ($this->total_spaces_available === null) { |
|
296 | - $this->initialize(); |
|
297 | - $this->total_spaces_available = $this->calculate(false); |
|
298 | - } |
|
299 | - return $this->total_spaces_available; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Loops through the active tickets for the event |
|
305 | - * and builds a series of data arrays that will be used for calculating |
|
306 | - * the total maximum available spaces, as well as the spaces remaining. |
|
307 | - * Because ticket quantities affect datetime spaces and vice versa, |
|
308 | - * we need to be constantly updating these data arrays as things change, |
|
309 | - * which is the entire reason for their existence. |
|
310 | - * |
|
311 | - * @throws EE_Error |
|
312 | - * @throws DomainException |
|
313 | - * @throws UnexpectedEntityException |
|
314 | - * @throws InvalidDataTypeException |
|
315 | - * @throws InvalidInterfaceException |
|
316 | - * @throws InvalidArgumentException |
|
317 | - */ |
|
318 | - private function initialize() |
|
319 | - { |
|
320 | - if ($this->debug) { |
|
321 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
322 | - } |
|
323 | - $this->datetime_tickets = array(); |
|
324 | - $this->datetime_spaces = array(); |
|
325 | - $this->ticket_datetimes = array(); |
|
326 | - $this->ticket_quantities = array(); |
|
327 | - $this->tickets_sold = array(); |
|
328 | - $this->total_spaces = array(); |
|
329 | - $active_tickets = $this->getActiveTickets(); |
|
330 | - if (! empty($active_tickets)) { |
|
331 | - foreach ($active_tickets as $ticket) { |
|
332 | - $this->validateTicket($ticket); |
|
333 | - // we need to index our data arrays using strings for the purpose of sorting, |
|
334 | - // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
335 | - $ticket_identifier = "T{$ticket->ID()}"; |
|
336 | - // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
337 | - // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
338 | - $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
339 | - // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
340 | - $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
341 | - foreach ($ticket_datetimes as $datetime) { |
|
342 | - // save all datetimes |
|
343 | - $this->setDatetime($datetime); |
|
344 | - $datetime_identifier = "D{$datetime->ID()}"; |
|
345 | - $reg_limit = $datetime->reg_limit(); |
|
346 | - // ticket quantity can not exceed datetime reg limit |
|
347 | - $max_tickets = min($max_tickets, $reg_limit); |
|
348 | - // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
349 | - // we are going to move all of our data into the following arrays: |
|
350 | - // datetime spaces initially represents the reg limit for each datetime, |
|
351 | - // but this will get adjusted as tickets are accounted for |
|
352 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
353 | - // just an array of ticket IDs grouped by datetime |
|
354 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
355 | - // and an array of datetime IDs grouped by ticket |
|
356 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
357 | - } |
|
358 | - // total quantity of sold and reserved for each ticket |
|
359 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
360 | - // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
361 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
362 | - } |
|
363 | - } |
|
364 | - // sort datetime spaces by reg limit, but maintain our string indexes |
|
365 | - asort($this->datetime_spaces, SORT_NUMERIC); |
|
366 | - // datetime tickets need to be sorted in the SAME order as the above array... |
|
367 | - // so we'll just use array_merge() to take the structure of datetime_spaces |
|
368 | - // but overwrite all of the data with that from datetime_tickets |
|
369 | - $this->datetime_tickets = array_merge( |
|
370 | - $this->datetime_spaces, |
|
371 | - $this->datetime_tickets |
|
372 | - ); |
|
373 | - if ($this->debug) { |
|
374 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
375 | - \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
376 | - \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * performs calculations on initialized data |
|
383 | - * |
|
384 | - * @param bool $consider_sold |
|
385 | - * @return int|float |
|
386 | - */ |
|
387 | - private function calculate($consider_sold = true) |
|
388 | - { |
|
389 | - if ($this->debug) { |
|
390 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
391 | - \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
392 | - } |
|
393 | - if ($consider_sold) { |
|
394 | - // subtract amounts sold from all ticket quantities and datetime spaces |
|
395 | - $this->adjustTicketQuantitiesDueToSales(); |
|
396 | - } |
|
397 | - foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
398 | - $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
399 | - } |
|
400 | - // total spaces available is just the sum of the spaces available for each datetime |
|
401 | - $spaces_remaining = array_sum($this->total_spaces); |
|
402 | - if ($this->debug) { |
|
403 | - \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
404 | - \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
405 | - \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
406 | - } |
|
407 | - return $spaces_remaining; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
413 | - */ |
|
414 | - private function adjustTicketQuantitiesDueToSales() |
|
415 | - { |
|
416 | - if ($this->debug) { |
|
417 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
418 | - } |
|
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; |
|
422 | - // don't let values go below zero |
|
423 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
424 | - $this->ticket_quantities[ $ticket_identifier ], |
|
425 | - 0 |
|
426 | - ); |
|
427 | - if ($this->debug) { |
|
428 | - \EEH_Debug_Tools::printr( |
|
429 | - "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
430 | - 'subtracting', |
|
431 | - __FILE__, |
|
432 | - __LINE__ |
|
433 | - ); |
|
434 | - } |
|
435 | - } |
|
436 | - if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
437 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
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; |
|
442 | - // don't let values go below zero |
|
443 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
444 | - $this->datetime_spaces[ $ticket_datetime ], |
|
445 | - 0 |
|
446 | - ); |
|
447 | - if ($this->debug) { |
|
448 | - \EEH_Debug_Tools::printr( |
|
449 | - "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
450 | - 'subtracting', |
|
451 | - __FILE__, |
|
452 | - __LINE__ |
|
453 | - ); |
|
454 | - } |
|
455 | - } |
|
456 | - } |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @param string $datetime_identifier |
|
464 | - * @param array $tickets |
|
465 | - */ |
|
466 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
467 | - { |
|
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 ] |
|
471 | - : 0; |
|
472 | - // and bail if it is not |
|
473 | - if (! $reg_limit) { |
|
474 | - if ($this->debug) { |
|
475 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
476 | - } |
|
477 | - return; |
|
478 | - } |
|
479 | - if ($this->debug) { |
|
480 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
481 | - \EEH_Debug_Tools::printr( |
|
482 | - "{$reg_limit}", |
|
483 | - 'REG LIMIT', |
|
484 | - __FILE__, |
|
485 | - __LINE__ |
|
486 | - ); |
|
487 | - } |
|
488 | - // number of allocated spaces always starts at zero |
|
489 | - $spaces_allocated = 0; |
|
490 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
491 | - foreach ($tickets as $ticket_identifier) { |
|
492 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
493 | - $datetime_identifier, |
|
494 | - $reg_limit, |
|
495 | - $ticket_identifier, |
|
496 | - $spaces_allocated |
|
497 | - ); |
|
498 | - } |
|
499 | - // spaces can't be negative |
|
500 | - $spaces_allocated = max($spaces_allocated, 0); |
|
501 | - if ($spaces_allocated) { |
|
502 | - // track any non-zero values |
|
503 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
504 | - if ($this->debug) { |
|
505 | - \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
506 | - } |
|
507 | - } else { |
|
508 | - if ($this->debug) { |
|
509 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
510 | - } |
|
511 | - } |
|
512 | - if ($this->debug) { |
|
513 | - \EEH_Debug_Tools::printr( |
|
514 | - $this->total_spaces[ $datetime_identifier ], |
|
515 | - '$total_spaces', |
|
516 | - __FILE__, |
|
517 | - __LINE__ |
|
518 | - ); |
|
519 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
520 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * @param string $datetime_identifier |
|
527 | - * @param int $reg_limit |
|
528 | - * @param string $ticket_identifier |
|
529 | - * @param int $spaces_allocated |
|
530 | - * @return int |
|
531 | - */ |
|
532 | - private function calculateAvailableSpacesForTicket( |
|
533 | - $datetime_identifier, |
|
534 | - $reg_limit, |
|
535 | - $ticket_identifier, |
|
536 | - $spaces_allocated |
|
537 | - ) { |
|
538 | - // make sure ticket quantity is set |
|
539 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
540 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
541 | - : 0; |
|
542 | - if ($this->debug) { |
|
543 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
544 | - \EEH_Debug_Tools::printr( |
|
545 | - "{$ticket_quantity}", |
|
546 | - "ticket $ticket_identifier quantity: ", |
|
547 | - __FILE__, |
|
548 | - __LINE__, |
|
549 | - 2 |
|
550 | - ); |
|
551 | - } |
|
552 | - if ($ticket_quantity) { |
|
553 | - if ($this->debug) { |
|
554 | - \EEH_Debug_Tools::printr( |
|
555 | - ($spaces_allocated <= $reg_limit) |
|
556 | - ? 'true' |
|
557 | - : 'false', |
|
558 | - ' . spaces_allocated <= reg_limit = ', |
|
559 | - __FILE__, |
|
560 | - __LINE__ |
|
561 | - ); |
|
562 | - } |
|
563 | - // if the datetime is NOT at full capacity yet |
|
564 | - if ($spaces_allocated <= $reg_limit) { |
|
565 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
566 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
567 | - // or the maximum ticket quantity |
|
568 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
569 | - // adjust the available quantity in our tracking array |
|
570 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
571 | - // and increment spaces allocated for this datetime |
|
572 | - $spaces_allocated += $ticket_quantity; |
|
573 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
574 | - if ($this->debug) { |
|
575 | - \EEH_Debug_Tools::printr( |
|
576 | - "{$ticket_quantity} {$ticket_identifier} tickets", |
|
577 | - ' > > allocate ', |
|
578 | - __FILE__, |
|
579 | - __LINE__, |
|
580 | - 3 |
|
581 | - ); |
|
582 | - if ($at_capacity) { |
|
583 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
584 | - } |
|
585 | - } |
|
586 | - // now adjust all other datetimes that allow access to this ticket |
|
587 | - $this->adjustDatetimes( |
|
588 | - $datetime_identifier, |
|
589 | - $ticket_identifier, |
|
590 | - $ticket_quantity, |
|
591 | - $at_capacity |
|
592 | - ); |
|
593 | - } |
|
594 | - } |
|
595 | - return $spaces_allocated; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * subtracts ticket amounts from all datetime reg limits |
|
601 | - * that allow access to the ticket specified, |
|
602 | - * because that ticket could be used |
|
603 | - * to attend any of the datetimes it has access to |
|
604 | - * |
|
605 | - * @param string $datetime_identifier |
|
606 | - * @param string $ticket_identifier |
|
607 | - * @param bool $at_capacity |
|
608 | - * @param int $ticket_quantity |
|
609 | - */ |
|
610 | - private function adjustDatetimes( |
|
611 | - $datetime_identifier, |
|
612 | - $ticket_identifier, |
|
613 | - $ticket_quantity, |
|
614 | - $at_capacity |
|
615 | - ) { |
|
616 | - /** @var array $datetime_tickets */ |
|
617 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
618 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
619 | - continue; |
|
620 | - } |
|
621 | - $adjusted = $this->adjustDatetimeSpaces( |
|
622 | - $datetime_ID, |
|
623 | - $ticket_identifier, |
|
624 | - $ticket_quantity |
|
625 | - ); |
|
626 | - // skip to next ticket if nothing changed |
|
627 | - if (! ($adjusted || $at_capacity)) { |
|
628 | - continue; |
|
629 | - } |
|
630 | - // then all of it's tickets are now unavailable |
|
631 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
632 | - if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
633 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
634 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
635 | - ) { |
|
636 | - if ($this->debug) { |
|
637 | - \EEH_Debug_Tools::printr( |
|
638 | - $datetime_ticket, |
|
639 | - ' . . . adjust ticket quantities for', |
|
640 | - __FILE__, |
|
641 | - __LINE__ |
|
642 | - ); |
|
643 | - } |
|
644 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
645 | - // otherwise just subtract the ticket quantity |
|
646 | - $new_quantity = $at_capacity |
|
647 | - ? 0 |
|
648 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
649 | - // don't let ticket quantity go below zero |
|
650 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
651 | - if ($this->debug) { |
|
652 | - \EEH_Debug_Tools::printr( |
|
653 | - $at_capacity |
|
654 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
655 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
656 | - " . . . . {$datetime_ticket} quantity set to ", |
|
657 | - __FILE__, |
|
658 | - __LINE__ |
|
659 | - ); |
|
660 | - } |
|
661 | - } |
|
662 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
663 | - if ($datetime_ticket === $ticket_identifier) { |
|
664 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
665 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
666 | - ) { |
|
667 | - if ($this->debug) { |
|
668 | - \EEH_Debug_Tools::printr( |
|
669 | - $datetime_ticket, |
|
670 | - ' . . adjust other Datetimes for', |
|
671 | - __FILE__, |
|
672 | - __LINE__ |
|
673 | - ); |
|
674 | - } |
|
675 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
676 | - // don't adjust the current datetime twice |
|
677 | - if ($datetime !== $datetime_identifier) { |
|
678 | - $this->adjustDatetimeSpaces( |
|
679 | - $datetime, |
|
680 | - $datetime_ticket, |
|
681 | - $ticket_quantity |
|
682 | - ); |
|
683 | - } |
|
684 | - } |
|
685 | - } |
|
686 | - } |
|
687 | - } |
|
688 | - } |
|
689 | - } |
|
690 | - |
|
691 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
692 | - { |
|
693 | - // does datetime have spaces available? |
|
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) |
|
698 | - ) { |
|
699 | - if ($this->debug) { |
|
700 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
701 | - \EEH_Debug_Tools::printr( |
|
702 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
703 | - " . . current {$datetime_identifier} spaces available", |
|
704 | - __FILE__, |
|
705 | - __LINE__ |
|
706 | - ); |
|
707 | - } |
|
708 | - // then decrement the available spaces for the datetime |
|
709 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
710 | - // but don't let quantities go below zero |
|
711 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
712 | - $this->datetime_spaces[ $datetime_identifier ], |
|
713 | - 0 |
|
714 | - ); |
|
715 | - if ($this->debug) { |
|
716 | - \EEH_Debug_Tools::printr( |
|
717 | - "{$ticket_quantity}", |
|
718 | - " . . . {$datetime_identifier} capacity reduced by", |
|
719 | - __FILE__, |
|
720 | - __LINE__ |
|
721 | - ); |
|
722 | - } |
|
723 | - return true; |
|
724 | - } |
|
725 | - return false; |
|
726 | - } |
|
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 | + $this->event = $event; |
|
117 | + $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
118 | + $this->setHooks(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + private function setHooks() |
|
126 | + { |
|
127 | + add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
128 | + add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
129 | + add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
130 | + add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
131 | + add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
132 | + add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
133 | + add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
134 | + add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + public function clearResults() |
|
142 | + { |
|
143 | + $this->spaces_remaining = null; |
|
144 | + $this->total_spaces_available = null; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return EE_Ticket[] |
|
150 | + * @throws EE_Error |
|
151 | + * @throws InvalidDataTypeException |
|
152 | + * @throws InvalidInterfaceException |
|
153 | + * @throws InvalidArgumentException |
|
154 | + */ |
|
155 | + public function getActiveTickets() |
|
156 | + { |
|
157 | + if (empty($this->active_tickets)) { |
|
158 | + $this->active_tickets = $this->event->tickets( |
|
159 | + array( |
|
160 | + array('TKT_deleted' => false), |
|
161 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
162 | + ) |
|
163 | + ); |
|
164 | + } |
|
165 | + return $this->active_tickets; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param EE_Ticket[] $active_tickets |
|
171 | + * @throws EE_Error |
|
172 | + * @throws DomainException |
|
173 | + * @throws UnexpectedEntityException |
|
174 | + */ |
|
175 | + public function setActiveTickets(array $active_tickets = array()) |
|
176 | + { |
|
177 | + if (! empty($active_tickets)) { |
|
178 | + foreach ($active_tickets as $active_ticket) { |
|
179 | + $this->validateTicket($active_ticket); |
|
180 | + } |
|
181 | + // sort incoming array by ticket quantity (asc) |
|
182 | + usort( |
|
183 | + $active_tickets, |
|
184 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
185 | + if ($a->qty() === $b->qty()) { |
|
186 | + return 0; |
|
187 | + } |
|
188 | + return ($a->qty() < $b->qty()) |
|
189 | + ? -1 |
|
190 | + : 1; |
|
191 | + } |
|
192 | + ); |
|
193 | + } |
|
194 | + $this->active_tickets = $active_tickets; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @param $ticket |
|
200 | + * @throws DomainException |
|
201 | + * @throws EE_Error |
|
202 | + * @throws UnexpectedEntityException |
|
203 | + */ |
|
204 | + private function validateTicket($ticket) |
|
205 | + { |
|
206 | + if (! $ticket instanceof EE_Ticket) { |
|
207 | + throw new DomainException( |
|
208 | + esc_html__( |
|
209 | + 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
210 | + 'event_espresso' |
|
211 | + ) |
|
212 | + ); |
|
213 | + } |
|
214 | + if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
215 | + throw new DomainException( |
|
216 | + sprintf( |
|
217 | + esc_html__( |
|
218 | + 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + $ticket->get_event_ID(), |
|
222 | + $this->event->ID() |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @return EE_Datetime[] |
|
231 | + */ |
|
232 | + public function getDatetimes() |
|
233 | + { |
|
234 | + return $this->datetimes; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param EE_Datetime $datetime |
|
240 | + * @throws EE_Error |
|
241 | + * @throws DomainException |
|
242 | + */ |
|
243 | + public function setDatetime(EE_Datetime $datetime) |
|
244 | + { |
|
245 | + if ($datetime->event()->ID() !== $this->event->ID()) { |
|
246 | + throw new DomainException( |
|
247 | + sprintf( |
|
248 | + esc_html__( |
|
249 | + 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
250 | + 'event_espresso' |
|
251 | + ), |
|
252 | + $datetime->event()->ID(), |
|
253 | + $this->event->ID() |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $this->datetimes[ $datetime->ID() ] = $datetime; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * calculate spaces remaining based on "saleable" tickets |
|
263 | + * |
|
264 | + * @return float|int |
|
265 | + * @throws EE_Error |
|
266 | + * @throws DomainException |
|
267 | + * @throws UnexpectedEntityException |
|
268 | + * @throws InvalidDataTypeException |
|
269 | + * @throws InvalidInterfaceException |
|
270 | + * @throws InvalidArgumentException |
|
271 | + */ |
|
272 | + public function spacesRemaining() |
|
273 | + { |
|
274 | + if ($this->spaces_remaining === null) { |
|
275 | + $this->initialize(); |
|
276 | + $this->spaces_remaining = $this->calculate(); |
|
277 | + } |
|
278 | + return $this->spaces_remaining; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * calculates total available spaces for an event with no regard for sold tickets |
|
284 | + * |
|
285 | + * @return int|float |
|
286 | + * @throws EE_Error |
|
287 | + * @throws DomainException |
|
288 | + * @throws UnexpectedEntityException |
|
289 | + * @throws InvalidDataTypeException |
|
290 | + * @throws InvalidInterfaceException |
|
291 | + * @throws InvalidArgumentException |
|
292 | + */ |
|
293 | + public function totalSpacesAvailable() |
|
294 | + { |
|
295 | + if ($this->total_spaces_available === null) { |
|
296 | + $this->initialize(); |
|
297 | + $this->total_spaces_available = $this->calculate(false); |
|
298 | + } |
|
299 | + return $this->total_spaces_available; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Loops through the active tickets for the event |
|
305 | + * and builds a series of data arrays that will be used for calculating |
|
306 | + * the total maximum available spaces, as well as the spaces remaining. |
|
307 | + * Because ticket quantities affect datetime spaces and vice versa, |
|
308 | + * we need to be constantly updating these data arrays as things change, |
|
309 | + * which is the entire reason for their existence. |
|
310 | + * |
|
311 | + * @throws EE_Error |
|
312 | + * @throws DomainException |
|
313 | + * @throws UnexpectedEntityException |
|
314 | + * @throws InvalidDataTypeException |
|
315 | + * @throws InvalidInterfaceException |
|
316 | + * @throws InvalidArgumentException |
|
317 | + */ |
|
318 | + private function initialize() |
|
319 | + { |
|
320 | + if ($this->debug) { |
|
321 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
322 | + } |
|
323 | + $this->datetime_tickets = array(); |
|
324 | + $this->datetime_spaces = array(); |
|
325 | + $this->ticket_datetimes = array(); |
|
326 | + $this->ticket_quantities = array(); |
|
327 | + $this->tickets_sold = array(); |
|
328 | + $this->total_spaces = array(); |
|
329 | + $active_tickets = $this->getActiveTickets(); |
|
330 | + if (! empty($active_tickets)) { |
|
331 | + foreach ($active_tickets as $ticket) { |
|
332 | + $this->validateTicket($ticket); |
|
333 | + // we need to index our data arrays using strings for the purpose of sorting, |
|
334 | + // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
335 | + $ticket_identifier = "T{$ticket->ID()}"; |
|
336 | + // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
337 | + // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
338 | + $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
339 | + // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
340 | + $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
341 | + foreach ($ticket_datetimes as $datetime) { |
|
342 | + // save all datetimes |
|
343 | + $this->setDatetime($datetime); |
|
344 | + $datetime_identifier = "D{$datetime->ID()}"; |
|
345 | + $reg_limit = $datetime->reg_limit(); |
|
346 | + // ticket quantity can not exceed datetime reg limit |
|
347 | + $max_tickets = min($max_tickets, $reg_limit); |
|
348 | + // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
349 | + // we are going to move all of our data into the following arrays: |
|
350 | + // datetime spaces initially represents the reg limit for each datetime, |
|
351 | + // but this will get adjusted as tickets are accounted for |
|
352 | + $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
353 | + // just an array of ticket IDs grouped by datetime |
|
354 | + $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
355 | + // and an array of datetime IDs grouped by ticket |
|
356 | + $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
357 | + } |
|
358 | + // total quantity of sold and reserved for each ticket |
|
359 | + $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
360 | + // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
361 | + $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
362 | + } |
|
363 | + } |
|
364 | + // sort datetime spaces by reg limit, but maintain our string indexes |
|
365 | + asort($this->datetime_spaces, SORT_NUMERIC); |
|
366 | + // datetime tickets need to be sorted in the SAME order as the above array... |
|
367 | + // so we'll just use array_merge() to take the structure of datetime_spaces |
|
368 | + // but overwrite all of the data with that from datetime_tickets |
|
369 | + $this->datetime_tickets = array_merge( |
|
370 | + $this->datetime_spaces, |
|
371 | + $this->datetime_tickets |
|
372 | + ); |
|
373 | + if ($this->debug) { |
|
374 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
375 | + \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
376 | + \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * performs calculations on initialized data |
|
383 | + * |
|
384 | + * @param bool $consider_sold |
|
385 | + * @return int|float |
|
386 | + */ |
|
387 | + private function calculate($consider_sold = true) |
|
388 | + { |
|
389 | + if ($this->debug) { |
|
390 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
391 | + \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
392 | + } |
|
393 | + if ($consider_sold) { |
|
394 | + // subtract amounts sold from all ticket quantities and datetime spaces |
|
395 | + $this->adjustTicketQuantitiesDueToSales(); |
|
396 | + } |
|
397 | + foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
398 | + $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
399 | + } |
|
400 | + // total spaces available is just the sum of the spaces available for each datetime |
|
401 | + $spaces_remaining = array_sum($this->total_spaces); |
|
402 | + if ($this->debug) { |
|
403 | + \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
404 | + \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
405 | + \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
406 | + } |
|
407 | + return $spaces_remaining; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
413 | + */ |
|
414 | + private function adjustTicketQuantitiesDueToSales() |
|
415 | + { |
|
416 | + if ($this->debug) { |
|
417 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
418 | + } |
|
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; |
|
422 | + // don't let values go below zero |
|
423 | + $this->ticket_quantities[ $ticket_identifier ] = max( |
|
424 | + $this->ticket_quantities[ $ticket_identifier ], |
|
425 | + 0 |
|
426 | + ); |
|
427 | + if ($this->debug) { |
|
428 | + \EEH_Debug_Tools::printr( |
|
429 | + "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
430 | + 'subtracting', |
|
431 | + __FILE__, |
|
432 | + __LINE__ |
|
433 | + ); |
|
434 | + } |
|
435 | + } |
|
436 | + if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
437 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
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; |
|
442 | + // don't let values go below zero |
|
443 | + $this->datetime_spaces[ $ticket_datetime ] = max( |
|
444 | + $this->datetime_spaces[ $ticket_datetime ], |
|
445 | + 0 |
|
446 | + ); |
|
447 | + if ($this->debug) { |
|
448 | + \EEH_Debug_Tools::printr( |
|
449 | + "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
450 | + 'subtracting', |
|
451 | + __FILE__, |
|
452 | + __LINE__ |
|
453 | + ); |
|
454 | + } |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @param string $datetime_identifier |
|
464 | + * @param array $tickets |
|
465 | + */ |
|
466 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
467 | + { |
|
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 ] |
|
471 | + : 0; |
|
472 | + // and bail if it is not |
|
473 | + if (! $reg_limit) { |
|
474 | + if ($this->debug) { |
|
475 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
476 | + } |
|
477 | + return; |
|
478 | + } |
|
479 | + if ($this->debug) { |
|
480 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
481 | + \EEH_Debug_Tools::printr( |
|
482 | + "{$reg_limit}", |
|
483 | + 'REG LIMIT', |
|
484 | + __FILE__, |
|
485 | + __LINE__ |
|
486 | + ); |
|
487 | + } |
|
488 | + // number of allocated spaces always starts at zero |
|
489 | + $spaces_allocated = 0; |
|
490 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
491 | + foreach ($tickets as $ticket_identifier) { |
|
492 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
493 | + $datetime_identifier, |
|
494 | + $reg_limit, |
|
495 | + $ticket_identifier, |
|
496 | + $spaces_allocated |
|
497 | + ); |
|
498 | + } |
|
499 | + // spaces can't be negative |
|
500 | + $spaces_allocated = max($spaces_allocated, 0); |
|
501 | + if ($spaces_allocated) { |
|
502 | + // track any non-zero values |
|
503 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
504 | + if ($this->debug) { |
|
505 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
506 | + } |
|
507 | + } else { |
|
508 | + if ($this->debug) { |
|
509 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
510 | + } |
|
511 | + } |
|
512 | + if ($this->debug) { |
|
513 | + \EEH_Debug_Tools::printr( |
|
514 | + $this->total_spaces[ $datetime_identifier ], |
|
515 | + '$total_spaces', |
|
516 | + __FILE__, |
|
517 | + __LINE__ |
|
518 | + ); |
|
519 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
520 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * @param string $datetime_identifier |
|
527 | + * @param int $reg_limit |
|
528 | + * @param string $ticket_identifier |
|
529 | + * @param int $spaces_allocated |
|
530 | + * @return int |
|
531 | + */ |
|
532 | + private function calculateAvailableSpacesForTicket( |
|
533 | + $datetime_identifier, |
|
534 | + $reg_limit, |
|
535 | + $ticket_identifier, |
|
536 | + $spaces_allocated |
|
537 | + ) { |
|
538 | + // make sure ticket quantity is set |
|
539 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
540 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
541 | + : 0; |
|
542 | + if ($this->debug) { |
|
543 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
544 | + \EEH_Debug_Tools::printr( |
|
545 | + "{$ticket_quantity}", |
|
546 | + "ticket $ticket_identifier quantity: ", |
|
547 | + __FILE__, |
|
548 | + __LINE__, |
|
549 | + 2 |
|
550 | + ); |
|
551 | + } |
|
552 | + if ($ticket_quantity) { |
|
553 | + if ($this->debug) { |
|
554 | + \EEH_Debug_Tools::printr( |
|
555 | + ($spaces_allocated <= $reg_limit) |
|
556 | + ? 'true' |
|
557 | + : 'false', |
|
558 | + ' . spaces_allocated <= reg_limit = ', |
|
559 | + __FILE__, |
|
560 | + __LINE__ |
|
561 | + ); |
|
562 | + } |
|
563 | + // if the datetime is NOT at full capacity yet |
|
564 | + if ($spaces_allocated <= $reg_limit) { |
|
565 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
566 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
567 | + // or the maximum ticket quantity |
|
568 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
569 | + // adjust the available quantity in our tracking array |
|
570 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
571 | + // and increment spaces allocated for this datetime |
|
572 | + $spaces_allocated += $ticket_quantity; |
|
573 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
574 | + if ($this->debug) { |
|
575 | + \EEH_Debug_Tools::printr( |
|
576 | + "{$ticket_quantity} {$ticket_identifier} tickets", |
|
577 | + ' > > allocate ', |
|
578 | + __FILE__, |
|
579 | + __LINE__, |
|
580 | + 3 |
|
581 | + ); |
|
582 | + if ($at_capacity) { |
|
583 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
584 | + } |
|
585 | + } |
|
586 | + // now adjust all other datetimes that allow access to this ticket |
|
587 | + $this->adjustDatetimes( |
|
588 | + $datetime_identifier, |
|
589 | + $ticket_identifier, |
|
590 | + $ticket_quantity, |
|
591 | + $at_capacity |
|
592 | + ); |
|
593 | + } |
|
594 | + } |
|
595 | + return $spaces_allocated; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * subtracts ticket amounts from all datetime reg limits |
|
601 | + * that allow access to the ticket specified, |
|
602 | + * because that ticket could be used |
|
603 | + * to attend any of the datetimes it has access to |
|
604 | + * |
|
605 | + * @param string $datetime_identifier |
|
606 | + * @param string $ticket_identifier |
|
607 | + * @param bool $at_capacity |
|
608 | + * @param int $ticket_quantity |
|
609 | + */ |
|
610 | + private function adjustDatetimes( |
|
611 | + $datetime_identifier, |
|
612 | + $ticket_identifier, |
|
613 | + $ticket_quantity, |
|
614 | + $at_capacity |
|
615 | + ) { |
|
616 | + /** @var array $datetime_tickets */ |
|
617 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
618 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
619 | + continue; |
|
620 | + } |
|
621 | + $adjusted = $this->adjustDatetimeSpaces( |
|
622 | + $datetime_ID, |
|
623 | + $ticket_identifier, |
|
624 | + $ticket_quantity |
|
625 | + ); |
|
626 | + // skip to next ticket if nothing changed |
|
627 | + if (! ($adjusted || $at_capacity)) { |
|
628 | + continue; |
|
629 | + } |
|
630 | + // then all of it's tickets are now unavailable |
|
631 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
632 | + if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
633 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
634 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
635 | + ) { |
|
636 | + if ($this->debug) { |
|
637 | + \EEH_Debug_Tools::printr( |
|
638 | + $datetime_ticket, |
|
639 | + ' . . . adjust ticket quantities for', |
|
640 | + __FILE__, |
|
641 | + __LINE__ |
|
642 | + ); |
|
643 | + } |
|
644 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
645 | + // otherwise just subtract the ticket quantity |
|
646 | + $new_quantity = $at_capacity |
|
647 | + ? 0 |
|
648 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
649 | + // don't let ticket quantity go below zero |
|
650 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
651 | + if ($this->debug) { |
|
652 | + \EEH_Debug_Tools::printr( |
|
653 | + $at_capacity |
|
654 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
655 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
656 | + " . . . . {$datetime_ticket} quantity set to ", |
|
657 | + __FILE__, |
|
658 | + __LINE__ |
|
659 | + ); |
|
660 | + } |
|
661 | + } |
|
662 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
663 | + if ($datetime_ticket === $ticket_identifier) { |
|
664 | + if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
665 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
666 | + ) { |
|
667 | + if ($this->debug) { |
|
668 | + \EEH_Debug_Tools::printr( |
|
669 | + $datetime_ticket, |
|
670 | + ' . . adjust other Datetimes for', |
|
671 | + __FILE__, |
|
672 | + __LINE__ |
|
673 | + ); |
|
674 | + } |
|
675 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
676 | + // don't adjust the current datetime twice |
|
677 | + if ($datetime !== $datetime_identifier) { |
|
678 | + $this->adjustDatetimeSpaces( |
|
679 | + $datetime, |
|
680 | + $datetime_ticket, |
|
681 | + $ticket_quantity |
|
682 | + ); |
|
683 | + } |
|
684 | + } |
|
685 | + } |
|
686 | + } |
|
687 | + } |
|
688 | + } |
|
689 | + } |
|
690 | + |
|
691 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
692 | + { |
|
693 | + // does datetime have spaces available? |
|
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) |
|
698 | + ) { |
|
699 | + if ($this->debug) { |
|
700 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
701 | + \EEH_Debug_Tools::printr( |
|
702 | + "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
703 | + " . . current {$datetime_identifier} spaces available", |
|
704 | + __FILE__, |
|
705 | + __LINE__ |
|
706 | + ); |
|
707 | + } |
|
708 | + // then decrement the available spaces for the datetime |
|
709 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
710 | + // but don't let quantities go below zero |
|
711 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
712 | + $this->datetime_spaces[ $datetime_identifier ], |
|
713 | + 0 |
|
714 | + ); |
|
715 | + if ($this->debug) { |
|
716 | + \EEH_Debug_Tools::printr( |
|
717 | + "{$ticket_quantity}", |
|
718 | + " . . . {$datetime_identifier} capacity reduced by", |
|
719 | + __FILE__, |
|
720 | + __LINE__ |
|
721 | + ); |
|
722 | + } |
|
723 | + return true; |
|
724 | + } |
|
725 | + return false; |
|
726 | + } |
|
727 | 727 | } |
@@ -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) { |