@@ -570,7 +570,7 @@ |
||
570 | 570 | * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
571 | 571 | * or EEH_MSG_Template::convert_payment_status_to_message_type |
572 | 572 | * @param string $payment_status The payment status being matched. |
573 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
573 | + * @return string|false The payment message type slug matching the status or false if no match. |
|
574 | 574 | */ |
575 | 575 | protected static function _get_payment_message_type($payment_status) |
576 | 576 | { |
@@ -13,1084 +13,1084 @@ |
||
13 | 13 | class EED_Messages extends EED_Module |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * This holds the EE_messages controller |
|
18 | - * |
|
19 | - * @deprecated 4.9.0 |
|
20 | - * @var EE_messages $_EEMSG |
|
21 | - */ |
|
22 | - protected static $_EEMSG; |
|
23 | - |
|
24 | - /** |
|
25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | - */ |
|
27 | - protected static $_message_resource_manager; |
|
28 | - |
|
29 | - /** |
|
30 | - * This holds the EE_Messages_Processor business class. |
|
31 | - * |
|
32 | - * @type EE_Messages_Processor |
|
33 | - */ |
|
34 | - protected static $_MSG_PROCESSOR; |
|
35 | - |
|
36 | - /** |
|
37 | - * holds all the paths for various messages components. |
|
38 | - * Utilized by autoloader registry |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $_MSG_PATHS; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
47 | - * Format is: |
|
48 | - * array( |
|
49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
50 | - * ) |
|
51 | - * |
|
52 | - * @var EE_Messages_Template_Pack[] |
|
53 | - */ |
|
54 | - protected static $_TMP_PACKS = array(); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @return EED_Messages |
|
59 | - */ |
|
60 | - public static function instance() |
|
61 | - { |
|
62 | - return parent::get_instance(__CLASS__); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
68 | - * |
|
69 | - * @since 4.5.0 |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks() |
|
73 | - { |
|
74 | - //actions |
|
75 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
76 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
77 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
78 | - //filters |
|
79 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
80 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
81 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
82 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
83 | - //register routes |
|
84 | - self::_register_routes(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public static function set_hooks_admin() |
|
94 | - { |
|
95 | - //actions |
|
96 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
97 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
98 | - array('EED_Messages', 'payment_reminder'), 10); |
|
99 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
100 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
101 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
102 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
103 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
104 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
105 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
106 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
107 | - //filters |
|
108 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
109 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
110 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
111 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
112 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
113 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * All the message triggers done by route go in here. |
|
119 | - * |
|
120 | - * @since 4.5.0 |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected static function _register_routes() |
|
124 | - { |
|
125 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
126 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
127 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
128 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
129 | - do_action('AHEE__EED_Messages___register_routes'); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * This is called when a browser display trigger is executed. |
|
135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
136 | - * browser. |
|
137 | - * |
|
138 | - * @since 4.9.0 |
|
139 | - * @param WP $WP |
|
140 | - */ |
|
141 | - public function browser_trigger($WP) |
|
142 | - { |
|
143 | - //ensure controller is loaded |
|
144 | - self::_load_controller(); |
|
145 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
146 | - try { |
|
147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
149 | - } catch (EE_Error $e) { |
|
150 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
151 | - 'event_espresso'); |
|
152 | - // add specific message for developers if WP_DEBUG in on |
|
153 | - $error_msg .= '||' . $e->getMessage(); |
|
154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * This is called when a browser error trigger is executed. |
|
161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
162 | - * message and display it. |
|
163 | - * |
|
164 | - * @since 4.9.0 |
|
165 | - * @param $WP |
|
166 | - */ |
|
167 | - public function browser_error_trigger($WP) |
|
168 | - { |
|
169 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
170 | - if ($token) { |
|
171 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
172 | - if ($message instanceof EE_Message) { |
|
173 | - header('HTTP/1.1 200 OK'); |
|
174 | - $error_msg = nl2br($message->error_message()); |
|
175 | - ?> |
|
16 | + /** |
|
17 | + * This holds the EE_messages controller |
|
18 | + * |
|
19 | + * @deprecated 4.9.0 |
|
20 | + * @var EE_messages $_EEMSG |
|
21 | + */ |
|
22 | + protected static $_EEMSG; |
|
23 | + |
|
24 | + /** |
|
25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | + */ |
|
27 | + protected static $_message_resource_manager; |
|
28 | + |
|
29 | + /** |
|
30 | + * This holds the EE_Messages_Processor business class. |
|
31 | + * |
|
32 | + * @type EE_Messages_Processor |
|
33 | + */ |
|
34 | + protected static $_MSG_PROCESSOR; |
|
35 | + |
|
36 | + /** |
|
37 | + * holds all the paths for various messages components. |
|
38 | + * Utilized by autoloader registry |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $_MSG_PATHS; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
47 | + * Format is: |
|
48 | + * array( |
|
49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
50 | + * ) |
|
51 | + * |
|
52 | + * @var EE_Messages_Template_Pack[] |
|
53 | + */ |
|
54 | + protected static $_TMP_PACKS = array(); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @return EED_Messages |
|
59 | + */ |
|
60 | + public static function instance() |
|
61 | + { |
|
62 | + return parent::get_instance(__CLASS__); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
68 | + * |
|
69 | + * @since 4.5.0 |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks() |
|
73 | + { |
|
74 | + //actions |
|
75 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
76 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
77 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
78 | + //filters |
|
79 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
80 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
81 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
82 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
83 | + //register routes |
|
84 | + self::_register_routes(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public static function set_hooks_admin() |
|
94 | + { |
|
95 | + //actions |
|
96 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
97 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
98 | + array('EED_Messages', 'payment_reminder'), 10); |
|
99 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
100 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
101 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
102 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
103 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
104 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
105 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
106 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
107 | + //filters |
|
108 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
109 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
110 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
111 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
112 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
113 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * All the message triggers done by route go in here. |
|
119 | + * |
|
120 | + * @since 4.5.0 |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected static function _register_routes() |
|
124 | + { |
|
125 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
126 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
127 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
128 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
129 | + do_action('AHEE__EED_Messages___register_routes'); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * This is called when a browser display trigger is executed. |
|
135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
136 | + * browser. |
|
137 | + * |
|
138 | + * @since 4.9.0 |
|
139 | + * @param WP $WP |
|
140 | + */ |
|
141 | + public function browser_trigger($WP) |
|
142 | + { |
|
143 | + //ensure controller is loaded |
|
144 | + self::_load_controller(); |
|
145 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
146 | + try { |
|
147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
149 | + } catch (EE_Error $e) { |
|
150 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
151 | + 'event_espresso'); |
|
152 | + // add specific message for developers if WP_DEBUG in on |
|
153 | + $error_msg .= '||' . $e->getMessage(); |
|
154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * This is called when a browser error trigger is executed. |
|
161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
162 | + * message and display it. |
|
163 | + * |
|
164 | + * @since 4.9.0 |
|
165 | + * @param $WP |
|
166 | + */ |
|
167 | + public function browser_error_trigger($WP) |
|
168 | + { |
|
169 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
170 | + if ($token) { |
|
171 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
172 | + if ($message instanceof EE_Message) { |
|
173 | + header('HTTP/1.1 200 OK'); |
|
174 | + $error_msg = nl2br($message->error_message()); |
|
175 | + ?> |
|
176 | 176 | <!DOCTYPE html> |
177 | 177 | <html> |
178 | 178 | <head></head> |
179 | 179 | <body> |
180 | 180 | <?php echo empty($error_msg) |
181 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
182 | - 'event_espresso') |
|
183 | - : wp_kses( |
|
184 | - $error_msg, |
|
185 | - array( |
|
186 | - 'a' => array( |
|
187 | - 'href' => array(), |
|
188 | - 'title' => array(), |
|
189 | - ), |
|
190 | - 'span' => array(), |
|
191 | - 'div' => array(), |
|
192 | - 'p' => array(), |
|
193 | - 'strong' => array(), |
|
194 | - 'em' => array(), |
|
195 | - 'br' => array(), |
|
196 | - ) |
|
197 | - ); ?> |
|
181 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
182 | + 'event_espresso') |
|
183 | + : wp_kses( |
|
184 | + $error_msg, |
|
185 | + array( |
|
186 | + 'a' => array( |
|
187 | + 'href' => array(), |
|
188 | + 'title' => array(), |
|
189 | + ), |
|
190 | + 'span' => array(), |
|
191 | + 'div' => array(), |
|
192 | + 'p' => array(), |
|
193 | + 'strong' => array(), |
|
194 | + 'em' => array(), |
|
195 | + 'br' => array(), |
|
196 | + ) |
|
197 | + ); ?> |
|
198 | 198 | </body> |
199 | 199 | </html> |
200 | 200 | <?php |
201 | - exit; |
|
202 | - } |
|
203 | - } |
|
204 | - return; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * This runs when the msg_url_trigger route has initiated. |
|
210 | - * |
|
211 | - * @since 4.5.0 |
|
212 | - * @param WP $WP |
|
213 | - * @throws EE_Error |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function run($WP) |
|
217 | - { |
|
218 | - //ensure controller is loaded |
|
219 | - self::_load_controller(); |
|
220 | - // attempt to process message |
|
221 | - try { |
|
222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
223 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
225 | - } catch (EE_Error $e) { |
|
226 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
227 | - 'event_espresso'); |
|
228 | - // add specific message for developers if WP_DEBUG in on |
|
229 | - $error_msg .= '||' . $e->getMessage(); |
|
230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * This is triggered by the 'msg_cron_trigger' route. |
|
237 | - * |
|
238 | - * @param WP $WP |
|
239 | - */ |
|
240 | - public function execute_batch_request($WP) |
|
241 | - { |
|
242 | - $this->run_cron(); |
|
243 | - header('HTTP/1.1 200 OK'); |
|
244 | - exit(); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
250 | - * request. |
|
251 | - */ |
|
252 | - public function run_cron() |
|
253 | - { |
|
254 | - self::_load_controller(); |
|
255 | - //get required vars |
|
256 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
257 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
258 | - |
|
259 | - //now let's verify transient, if not valid exit immediately |
|
260 | - if (! get_transient($transient_key)) { |
|
261 | - /** |
|
262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
263 | - */ |
|
264 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
265 | - } |
|
266 | - |
|
267 | - //if made it here, lets' delete the transient to keep the db clean |
|
268 | - delete_transient($transient_key); |
|
269 | - |
|
270 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
271 | - |
|
272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
273 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
274 | - self::$_MSG_PROCESSOR->$method(); |
|
275 | - } else { |
|
276 | - //no matching task |
|
277 | - /** |
|
278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
279 | - */ |
|
280 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
281 | - $cron_type))); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * This is used to retrieve the template pack for the given name. |
|
291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
292 | - * the default template pack is returned. |
|
293 | - * |
|
294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
296 | - * in generating the Pack class name). |
|
297 | - * @return EE_Messages_Template_Pack |
|
298 | - */ |
|
299 | - public static function get_template_pack($template_pack_name) |
|
300 | - { |
|
301 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
302 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Retrieves an array of all template packs. |
|
308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
309 | - * |
|
310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
311 | - * @return EE_Messages_Template_Pack[] |
|
312 | - */ |
|
313 | - public static function get_template_packs() |
|
314 | - { |
|
315 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
316 | - |
|
317 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
319 | - $template_pack_collection->rewind(); |
|
320 | - $template_packs = array(); |
|
321 | - while ($template_pack_collection->valid()) { |
|
322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
323 | - $template_pack_collection->next(); |
|
324 | - } |
|
325 | - return $template_packs; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
331 | - * |
|
332 | - * @since 4.5.0 |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public static function set_autoloaders() |
|
336 | - { |
|
337 | - if (empty(self::$_MSG_PATHS)) { |
|
338 | - self::_set_messages_paths(); |
|
339 | - foreach (self::$_MSG_PATHS as $path) { |
|
340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
341 | - } |
|
342 | - // add aliases |
|
343 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
344 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
351 | - * for use by the Messages Autoloaders |
|
352 | - * |
|
353 | - * @since 4.5.0 |
|
354 | - * @return void. |
|
355 | - */ |
|
356 | - protected static function _set_messages_paths() |
|
357 | - { |
|
358 | - $dir_ref = array( |
|
359 | - 'messages/message_type', |
|
360 | - 'messages/messenger', |
|
361 | - 'messages/defaults', |
|
362 | - 'messages/defaults/email', |
|
363 | - 'messages/data_class', |
|
364 | - 'messages/validators', |
|
365 | - 'messages/validators/email', |
|
366 | - 'messages/validators/html', |
|
367 | - 'shortcodes', |
|
368 | - ); |
|
369 | - $paths = array(); |
|
370 | - foreach ($dir_ref as $index => $dir) { |
|
371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
372 | - } |
|
373 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Takes care of loading dependencies |
|
379 | - * |
|
380 | - * @since 4.5.0 |
|
381 | - * @return void |
|
382 | - */ |
|
383 | - protected static function _load_controller() |
|
384 | - { |
|
385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
387 | - self::set_autoloaders(); |
|
388 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
389 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
390 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * @param EE_Transaction $transaction |
|
397 | - */ |
|
398 | - public static function payment_reminder(EE_Transaction $transaction) |
|
399 | - { |
|
400 | - self::_load_controller(); |
|
401 | - $data = array($transaction, null); |
|
402 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Any messages triggers for after successful gateway payments should go in here. |
|
408 | - * |
|
409 | - * @param EE_Transaction object |
|
410 | - * @param EE_Payment object |
|
411 | - * @return void |
|
412 | - */ |
|
413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
414 | - { |
|
415 | - self::_load_controller(); |
|
416 | - $data = array($transaction, $payment); |
|
417 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
419 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @param EE_Transaction $transaction |
|
427 | - */ |
|
428 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
429 | - { |
|
430 | - self::_load_controller(); |
|
431 | - $data = array($transaction, null); |
|
432 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Trigger for Registration messages |
|
438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
439 | - * incoming transaction. |
|
440 | - * |
|
441 | - * @param EE_Registration $registration |
|
442 | - * @param array $extra_details |
|
443 | - * @return void |
|
444 | - */ |
|
445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
446 | - { |
|
447 | - |
|
448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | - //no messages please |
|
450 | - return; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - //get all registrations so we make sure we send messages for the right status. |
|
455 | - $all_registrations = $registration->transaction()->registrations(); |
|
456 | - |
|
457 | - //cached array of statuses so we only trigger messages once per status. |
|
458 | - $statuses_sent = array(); |
|
459 | - self::_load_controller(); |
|
460 | - $mtgs = array(); |
|
461 | - |
|
462 | - //loop through registrations and trigger messages once per status. |
|
463 | - foreach ($all_registrations as $reg) { |
|
464 | - |
|
465 | - //already triggered? |
|
466 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
467 | - continue; |
|
468 | - } |
|
469 | - |
|
470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
471 | - $mtgs = array_merge( |
|
472 | - $mtgs, |
|
473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
474 | - $message_type, |
|
475 | - array($registration->transaction(), null, $reg->status_ID()) |
|
476 | - ) |
|
477 | - ); |
|
478 | - $statuses_sent[] = $reg->status_ID(); |
|
479 | - } |
|
480 | - |
|
481 | - $mtgs = array_merge( |
|
482 | - $mtgs, |
|
483 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
484 | - 'registration_summary', |
|
485 | - array($registration->transaction(), null) |
|
486 | - ) |
|
487 | - ); |
|
488 | - |
|
489 | - //batch queue and initiate request |
|
490 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
491 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * This is a helper method used to very whether a registration notification should be sent or |
|
497 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
498 | - * |
|
499 | - * @param EE_Registration $registration [description] |
|
500 | - * @param array $extra_details [description] |
|
501 | - * @return bool true = send away, false = nope halt the presses. |
|
502 | - */ |
|
503 | - protected static function _verify_registration_notification_send( |
|
504 | - EE_Registration $registration, |
|
505 | - $extra_details = array() |
|
506 | - ) { |
|
507 | - //self::log( |
|
508 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
509 | - // $registration->transaction(), |
|
510 | - // array( '$extra_details' => $extra_details ) |
|
511 | - //); |
|
512 | - // currently only using this to send messages for the primary registrant |
|
513 | - if (! $registration->is_primary_registrant()) { |
|
514 | - return false; |
|
515 | - } |
|
516 | - // first we check if we're in admin and not doing front ajax |
|
517 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
518 | - //make sure appropriate admin params are set for sending messages |
|
519 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
520 | - //no messages sent please. |
|
521 | - return false; |
|
522 | - } |
|
523 | - } else { |
|
524 | - // frontend request (either regular or via AJAX) |
|
525 | - // TXN is NOT finalized ? |
|
526 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
527 | - return false; |
|
528 | - } |
|
529 | - // return visit but nothing changed ??? |
|
530 | - if ( |
|
531 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
532 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
533 | - ) { |
|
534 | - return false; |
|
535 | - } |
|
536 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
537 | - if ( |
|
538 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
539 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
540 | - ) { |
|
541 | - return false; |
|
542 | - } |
|
543 | - } |
|
544 | - // release the kraken |
|
545 | - return true; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
551 | - * status id. |
|
552 | - * |
|
553 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
554 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
555 | - * @param string $reg_status |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - protected static function _get_reg_status_array($reg_status = '') |
|
559 | - { |
|
560 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
561 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
562 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
563 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * Simply returns the payment message type for the given payment status. |
|
569 | - * |
|
570 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
571 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
572 | - * @param string $payment_status The payment status being matched. |
|
573 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
574 | - */ |
|
575 | - protected static function _get_payment_message_type($payment_status) |
|
576 | - { |
|
577 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
578 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
579 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
580 | - : false; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
586 | - * |
|
587 | - * @access public |
|
588 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
589 | - * @return bool success/fail |
|
590 | - */ |
|
591 | - public static function process_resend($req_data) |
|
592 | - { |
|
593 | - self::_load_controller(); |
|
594 | - |
|
595 | - //if $msgID in this request then skip to the new resend_message |
|
596 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
597 | - return self::resend_message(); |
|
598 | - } |
|
599 | - |
|
600 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
601 | - $req_data = (array)$req_data; |
|
602 | - foreach ($req_data as $request_key => $request_value) { |
|
603 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
604 | - } |
|
605 | - |
|
606 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
607 | - return false; |
|
608 | - } |
|
609 | - |
|
610 | - try { |
|
611 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
612 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
613 | - } catch (EE_Error $e) { |
|
614 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
615 | - return false; |
|
616 | - } |
|
617 | - EE_Error::add_success( |
|
618 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
619 | - ); |
|
620 | - return true; //everything got queued. |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
626 | - * |
|
627 | - * @return bool |
|
628 | - */ |
|
629 | - public static function resend_message() |
|
630 | - { |
|
631 | - self::_load_controller(); |
|
632 | - |
|
633 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
634 | - if (! $msgID) { |
|
635 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
636 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
637 | - return false; |
|
638 | - } |
|
639 | - |
|
640 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
641 | - |
|
642 | - //setup success message. |
|
643 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
644 | - EE_Error::add_success(sprintf( |
|
645 | - _n( |
|
646 | - 'There was %d message queued for resending.', |
|
647 | - 'There were %d messages queued for resending.', |
|
648 | - $count_ready_for_resend, |
|
649 | - 'event_espresso' |
|
650 | - ), |
|
651 | - $count_ready_for_resend |
|
652 | - )); |
|
653 | - return true; |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * Message triggers for manual payment applied by admin |
|
659 | - * |
|
660 | - * @param EE_Payment $payment EE_payment object |
|
661 | - * @return bool success/fail |
|
662 | - */ |
|
663 | - public static function process_admin_payment(EE_Payment $payment) |
|
664 | - { |
|
665 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
666 | - //we need to get the transaction object |
|
667 | - $transaction = $payment->transaction(); |
|
668 | - if ($transaction instanceof EE_Transaction) { |
|
669 | - $data = array($transaction, $payment); |
|
670 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
671 | - |
|
672 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
673 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
674 | - |
|
675 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
676 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
677 | - |
|
678 | - self::_load_controller(); |
|
679 | - |
|
680 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
681 | - |
|
682 | - //get count of queued for generation |
|
683 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
684 | - EEM_Message::status_incomplete, |
|
685 | - EEM_Message::status_idle, |
|
686 | - )); |
|
687 | - |
|
688 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
689 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
690 | - return true; |
|
691 | - } else { |
|
692 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
693 | - /** |
|
694 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
695 | - * IMMEDIATE generation. |
|
696 | - */ |
|
697 | - if ($count_failed > 0) { |
|
698 | - EE_Error::add_error(sprintf( |
|
699 | - _n( |
|
700 | - 'The payment notification generation failed.', |
|
701 | - '%d payment notifications failed being sent.', |
|
702 | - $count_failed, |
|
703 | - 'event_espresso' |
|
704 | - ), |
|
705 | - $count_failed |
|
706 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
707 | - |
|
708 | - return false; |
|
709 | - } else { |
|
710 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
711 | - return true; |
|
712 | - } |
|
713 | - } |
|
714 | - } else { |
|
715 | - EE_Error::add_error( |
|
716 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
717 | - 'event_espresso' |
|
718 | - ); |
|
719 | - return false; |
|
720 | - } |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
726 | - * |
|
727 | - * @since 4.3.0 |
|
728 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
729 | - * @param int $grp_id a specific message template group id. |
|
730 | - * @return void |
|
731 | - */ |
|
732 | - public static function send_newsletter_message($registrations, $grp_id) |
|
733 | - { |
|
734 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
735 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
736 | - self::_load_controller(); |
|
737 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
738 | - } |
|
739 | - |
|
740 | - |
|
741 | - /** |
|
742 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
743 | - * |
|
744 | - * @since 4.3.0 |
|
745 | - * @param string $registration_message_trigger_url |
|
746 | - * @param EE_Registration $registration |
|
747 | - * @param string $messenger |
|
748 | - * @param string $message_type |
|
749 | - * @return string |
|
750 | - */ |
|
751 | - public static function registration_message_trigger_url( |
|
752 | - $registration_message_trigger_url, |
|
753 | - EE_Registration $registration, |
|
754 | - $messenger = 'html', |
|
755 | - $message_type = 'invoice' |
|
756 | - ) { |
|
757 | - // whitelist $messenger |
|
758 | - switch ($messenger) { |
|
759 | - case 'pdf' : |
|
760 | - $sending_messenger = 'pdf'; |
|
761 | - $generating_messenger = 'html'; |
|
762 | - break; |
|
763 | - case 'html' : |
|
764 | - default : |
|
765 | - $sending_messenger = 'html'; |
|
766 | - $generating_messenger = 'html'; |
|
767 | - break; |
|
768 | - } |
|
769 | - // whitelist $message_type |
|
770 | - switch ($message_type) { |
|
771 | - case 'receipt' : |
|
772 | - $message_type = 'receipt'; |
|
773 | - break; |
|
774 | - case 'invoice' : |
|
775 | - default : |
|
776 | - $message_type = 'invoice'; |
|
777 | - break; |
|
778 | - } |
|
779 | - // verify that both the messenger AND the message type are active |
|
780 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
781 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
782 | - $template_query_params = array( |
|
783 | - 'MTP_is_active' => true, |
|
784 | - 'MTP_messenger' => $generating_messenger, |
|
785 | - 'MTP_message_type' => $message_type, |
|
786 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
787 | - ); |
|
788 | - //get the message template group. |
|
789 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
790 | - //if we don't have an EE_Message_Template_Group then return |
|
791 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
792 | - // remove EVT_ID from query params so that global templates get picked up |
|
793 | - unset($template_query_params['Event.EVT_ID']); |
|
794 | - //get global template as the fallback |
|
795 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
796 | - } |
|
797 | - //if we don't have an EE_Message_Template_Group then return |
|
798 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
799 | - return ''; |
|
800 | - } |
|
801 | - // generate the URL |
|
802 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
803 | - $sending_messenger, |
|
804 | - $generating_messenger, |
|
805 | - 'purchaser', |
|
806 | - $message_type, |
|
807 | - $registration, |
|
808 | - $msg_template_group->ID(), |
|
809 | - $registration->transaction_ID() |
|
810 | - ); |
|
811 | - |
|
812 | - } |
|
813 | - return $registration_message_trigger_url; |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - /** |
|
818 | - * Use to generate and return a message preview! |
|
819 | - * |
|
820 | - * @param string $type This should correspond with a valid message type |
|
821 | - * @param string $context This should correspond with a valid context for the message type |
|
822 | - * @param string $messenger This should correspond with a valid messenger. |
|
823 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
824 | - * preview |
|
825 | - * @return string|bool The body of the message or if send is requested, sends. |
|
826 | - */ |
|
827 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
828 | - { |
|
829 | - self::_load_controller(); |
|
830 | - $mtg = new EE_Message_To_Generate( |
|
831 | - $messenger, |
|
832 | - $type, |
|
833 | - array(), |
|
834 | - $context, |
|
835 | - true |
|
836 | - ); |
|
837 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
838 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
839 | - return $generated_preview_queue->get_message_repository()->current()->content(); |
|
840 | - } else { |
|
841 | - return $generated_preview_queue; |
|
842 | - } |
|
843 | - } |
|
844 | - |
|
845 | - |
|
846 | - /** |
|
847 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
848 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
849 | - * content found in the EE_Message objects in the queue. |
|
850 | - * |
|
851 | - * @since 4.9.0 |
|
852 | - * @param string $messenger a string matching a valid active messenger in the system |
|
853 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
854 | - * type name is still required to send along the message type to the |
|
855 | - * messenger because this is used for determining what specific |
|
856 | - * variations might be loaded for the generated message. |
|
857 | - * @param EE_Messages_Queue $queue |
|
858 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
859 | - * aggregate EE_Message object. |
|
860 | - * @return bool success or fail. |
|
861 | - */ |
|
862 | - public static function send_message_with_messenger_only( |
|
863 | - $messenger, |
|
864 | - $message_type, |
|
865 | - EE_Messages_Queue $queue, |
|
866 | - $custom_subject = '' |
|
867 | - ) { |
|
868 | - self::_load_controller(); |
|
869 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
870 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
871 | - 'Message_To_Generate_From_Queue', |
|
872 | - array( |
|
873 | - $messenger, |
|
874 | - $message_type, |
|
875 | - $queue, |
|
876 | - $custom_subject, |
|
877 | - ) |
|
878 | - ); |
|
879 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
880 | - } |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
885 | - * |
|
886 | - * @since 4.9.0 |
|
887 | - * @param array $message_ids An array of message ids |
|
888 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
889 | - * messages. |
|
890 | - */ |
|
891 | - public static function generate_now($message_ids) |
|
892 | - { |
|
893 | - self::_load_controller(); |
|
894 | - $messages = EEM_Message::instance()->get_all( |
|
895 | - array( |
|
896 | - 0 => array( |
|
897 | - 'MSG_ID' => array('IN', $message_ids), |
|
898 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
899 | - ), |
|
900 | - ) |
|
901 | - ); |
|
902 | - $generated_queue = false; |
|
903 | - if ($messages) { |
|
904 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
905 | - } |
|
906 | - |
|
907 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
908 | - EE_Error::add_error( |
|
909 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
910 | - 'event_espresso'), |
|
911 | - __FILE__, __FUNCTION__, __LINE__ |
|
912 | - ); |
|
913 | - } |
|
914 | - return $generated_queue; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
920 | - * EEM_Message::status_idle |
|
921 | - * |
|
922 | - * @since 4.9.0 |
|
923 | - * @param $message_ids |
|
924 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
925 | - */ |
|
926 | - public static function send_now($message_ids) |
|
927 | - { |
|
928 | - self::_load_controller(); |
|
929 | - $messages = EEM_Message::instance()->get_all( |
|
930 | - array( |
|
931 | - 0 => array( |
|
932 | - 'MSG_ID' => array('IN', $message_ids), |
|
933 | - 'STS_ID' => array( |
|
934 | - 'IN', |
|
935 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
936 | - ), |
|
937 | - ), |
|
938 | - ) |
|
939 | - ); |
|
940 | - $sent_queue = false; |
|
941 | - if ($messages) { |
|
942 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
943 | - } |
|
944 | - |
|
945 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
946 | - EE_Error::add_error( |
|
947 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
948 | - 'event_espresso'), |
|
949 | - __FILE__, __FUNCTION__, __LINE__ |
|
950 | - ); |
|
951 | - } else { |
|
952 | - //can count how many sent by using the messages in the queue |
|
953 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
954 | - if ($sent_count > 0) { |
|
955 | - EE_Error::add_success( |
|
956 | - sprintf( |
|
957 | - _n( |
|
958 | - 'There was %d message successfully sent.', |
|
959 | - 'There were %d messages successfully sent.', |
|
960 | - $sent_count, |
|
961 | - 'event_espresso' |
|
962 | - ), |
|
963 | - $sent_count |
|
964 | - ) |
|
965 | - ); |
|
966 | - } else { |
|
967 | - EE_Error::overwrite_errors(); |
|
968 | - EE_Error::add_error( |
|
969 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
201 | + exit; |
|
202 | + } |
|
203 | + } |
|
204 | + return; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * This runs when the msg_url_trigger route has initiated. |
|
210 | + * |
|
211 | + * @since 4.5.0 |
|
212 | + * @param WP $WP |
|
213 | + * @throws EE_Error |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function run($WP) |
|
217 | + { |
|
218 | + //ensure controller is loaded |
|
219 | + self::_load_controller(); |
|
220 | + // attempt to process message |
|
221 | + try { |
|
222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
223 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
225 | + } catch (EE_Error $e) { |
|
226 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
227 | + 'event_espresso'); |
|
228 | + // add specific message for developers if WP_DEBUG in on |
|
229 | + $error_msg .= '||' . $e->getMessage(); |
|
230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * This is triggered by the 'msg_cron_trigger' route. |
|
237 | + * |
|
238 | + * @param WP $WP |
|
239 | + */ |
|
240 | + public function execute_batch_request($WP) |
|
241 | + { |
|
242 | + $this->run_cron(); |
|
243 | + header('HTTP/1.1 200 OK'); |
|
244 | + exit(); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
250 | + * request. |
|
251 | + */ |
|
252 | + public function run_cron() |
|
253 | + { |
|
254 | + self::_load_controller(); |
|
255 | + //get required vars |
|
256 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
257 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
258 | + |
|
259 | + //now let's verify transient, if not valid exit immediately |
|
260 | + if (! get_transient($transient_key)) { |
|
261 | + /** |
|
262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
263 | + */ |
|
264 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
265 | + } |
|
266 | + |
|
267 | + //if made it here, lets' delete the transient to keep the db clean |
|
268 | + delete_transient($transient_key); |
|
269 | + |
|
270 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
271 | + |
|
272 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
273 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
274 | + self::$_MSG_PROCESSOR->$method(); |
|
275 | + } else { |
|
276 | + //no matching task |
|
277 | + /** |
|
278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
279 | + */ |
|
280 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
281 | + $cron_type))); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * This is used to retrieve the template pack for the given name. |
|
291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
292 | + * the default template pack is returned. |
|
293 | + * |
|
294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
296 | + * in generating the Pack class name). |
|
297 | + * @return EE_Messages_Template_Pack |
|
298 | + */ |
|
299 | + public static function get_template_pack($template_pack_name) |
|
300 | + { |
|
301 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
302 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Retrieves an array of all template packs. |
|
308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
309 | + * |
|
310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
311 | + * @return EE_Messages_Template_Pack[] |
|
312 | + */ |
|
313 | + public static function get_template_packs() |
|
314 | + { |
|
315 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
316 | + |
|
317 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
319 | + $template_pack_collection->rewind(); |
|
320 | + $template_packs = array(); |
|
321 | + while ($template_pack_collection->valid()) { |
|
322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
323 | + $template_pack_collection->next(); |
|
324 | + } |
|
325 | + return $template_packs; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
331 | + * |
|
332 | + * @since 4.5.0 |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public static function set_autoloaders() |
|
336 | + { |
|
337 | + if (empty(self::$_MSG_PATHS)) { |
|
338 | + self::_set_messages_paths(); |
|
339 | + foreach (self::$_MSG_PATHS as $path) { |
|
340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
341 | + } |
|
342 | + // add aliases |
|
343 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
344 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
351 | + * for use by the Messages Autoloaders |
|
352 | + * |
|
353 | + * @since 4.5.0 |
|
354 | + * @return void. |
|
355 | + */ |
|
356 | + protected static function _set_messages_paths() |
|
357 | + { |
|
358 | + $dir_ref = array( |
|
359 | + 'messages/message_type', |
|
360 | + 'messages/messenger', |
|
361 | + 'messages/defaults', |
|
362 | + 'messages/defaults/email', |
|
363 | + 'messages/data_class', |
|
364 | + 'messages/validators', |
|
365 | + 'messages/validators/email', |
|
366 | + 'messages/validators/html', |
|
367 | + 'shortcodes', |
|
368 | + ); |
|
369 | + $paths = array(); |
|
370 | + foreach ($dir_ref as $index => $dir) { |
|
371 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
372 | + } |
|
373 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Takes care of loading dependencies |
|
379 | + * |
|
380 | + * @since 4.5.0 |
|
381 | + * @return void |
|
382 | + */ |
|
383 | + protected static function _load_controller() |
|
384 | + { |
|
385 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
387 | + self::set_autoloaders(); |
|
388 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
389 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
390 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * @param EE_Transaction $transaction |
|
397 | + */ |
|
398 | + public static function payment_reminder(EE_Transaction $transaction) |
|
399 | + { |
|
400 | + self::_load_controller(); |
|
401 | + $data = array($transaction, null); |
|
402 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Any messages triggers for after successful gateway payments should go in here. |
|
408 | + * |
|
409 | + * @param EE_Transaction object |
|
410 | + * @param EE_Payment object |
|
411 | + * @return void |
|
412 | + */ |
|
413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
414 | + { |
|
415 | + self::_load_controller(); |
|
416 | + $data = array($transaction, $payment); |
|
417 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
419 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @param EE_Transaction $transaction |
|
427 | + */ |
|
428 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
429 | + { |
|
430 | + self::_load_controller(); |
|
431 | + $data = array($transaction, null); |
|
432 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Trigger for Registration messages |
|
438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
439 | + * incoming transaction. |
|
440 | + * |
|
441 | + * @param EE_Registration $registration |
|
442 | + * @param array $extra_details |
|
443 | + * @return void |
|
444 | + */ |
|
445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
446 | + { |
|
447 | + |
|
448 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | + //no messages please |
|
450 | + return; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + //get all registrations so we make sure we send messages for the right status. |
|
455 | + $all_registrations = $registration->transaction()->registrations(); |
|
456 | + |
|
457 | + //cached array of statuses so we only trigger messages once per status. |
|
458 | + $statuses_sent = array(); |
|
459 | + self::_load_controller(); |
|
460 | + $mtgs = array(); |
|
461 | + |
|
462 | + //loop through registrations and trigger messages once per status. |
|
463 | + foreach ($all_registrations as $reg) { |
|
464 | + |
|
465 | + //already triggered? |
|
466 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
467 | + continue; |
|
468 | + } |
|
469 | + |
|
470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
471 | + $mtgs = array_merge( |
|
472 | + $mtgs, |
|
473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
474 | + $message_type, |
|
475 | + array($registration->transaction(), null, $reg->status_ID()) |
|
476 | + ) |
|
477 | + ); |
|
478 | + $statuses_sent[] = $reg->status_ID(); |
|
479 | + } |
|
480 | + |
|
481 | + $mtgs = array_merge( |
|
482 | + $mtgs, |
|
483 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
484 | + 'registration_summary', |
|
485 | + array($registration->transaction(), null) |
|
486 | + ) |
|
487 | + ); |
|
488 | + |
|
489 | + //batch queue and initiate request |
|
490 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
491 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * This is a helper method used to very whether a registration notification should be sent or |
|
497 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
498 | + * |
|
499 | + * @param EE_Registration $registration [description] |
|
500 | + * @param array $extra_details [description] |
|
501 | + * @return bool true = send away, false = nope halt the presses. |
|
502 | + */ |
|
503 | + protected static function _verify_registration_notification_send( |
|
504 | + EE_Registration $registration, |
|
505 | + $extra_details = array() |
|
506 | + ) { |
|
507 | + //self::log( |
|
508 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
509 | + // $registration->transaction(), |
|
510 | + // array( '$extra_details' => $extra_details ) |
|
511 | + //); |
|
512 | + // currently only using this to send messages for the primary registrant |
|
513 | + if (! $registration->is_primary_registrant()) { |
|
514 | + return false; |
|
515 | + } |
|
516 | + // first we check if we're in admin and not doing front ajax |
|
517 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
518 | + //make sure appropriate admin params are set for sending messages |
|
519 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
520 | + //no messages sent please. |
|
521 | + return false; |
|
522 | + } |
|
523 | + } else { |
|
524 | + // frontend request (either regular or via AJAX) |
|
525 | + // TXN is NOT finalized ? |
|
526 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
527 | + return false; |
|
528 | + } |
|
529 | + // return visit but nothing changed ??? |
|
530 | + if ( |
|
531 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
532 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
533 | + ) { |
|
534 | + return false; |
|
535 | + } |
|
536 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
537 | + if ( |
|
538 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
539 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
540 | + ) { |
|
541 | + return false; |
|
542 | + } |
|
543 | + } |
|
544 | + // release the kraken |
|
545 | + return true; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
551 | + * status id. |
|
552 | + * |
|
553 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
554 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
555 | + * @param string $reg_status |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + protected static function _get_reg_status_array($reg_status = '') |
|
559 | + { |
|
560 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
561 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
562 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
563 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * Simply returns the payment message type for the given payment status. |
|
569 | + * |
|
570 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
571 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
572 | + * @param string $payment_status The payment status being matched. |
|
573 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
574 | + */ |
|
575 | + protected static function _get_payment_message_type($payment_status) |
|
576 | + { |
|
577 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
578 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
579 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
580 | + : false; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
586 | + * |
|
587 | + * @access public |
|
588 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
589 | + * @return bool success/fail |
|
590 | + */ |
|
591 | + public static function process_resend($req_data) |
|
592 | + { |
|
593 | + self::_load_controller(); |
|
594 | + |
|
595 | + //if $msgID in this request then skip to the new resend_message |
|
596 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
597 | + return self::resend_message(); |
|
598 | + } |
|
599 | + |
|
600 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
601 | + $req_data = (array)$req_data; |
|
602 | + foreach ($req_data as $request_key => $request_value) { |
|
603 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
604 | + } |
|
605 | + |
|
606 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
607 | + return false; |
|
608 | + } |
|
609 | + |
|
610 | + try { |
|
611 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
612 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
613 | + } catch (EE_Error $e) { |
|
614 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
615 | + return false; |
|
616 | + } |
|
617 | + EE_Error::add_success( |
|
618 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
619 | + ); |
|
620 | + return true; //everything got queued. |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
626 | + * |
|
627 | + * @return bool |
|
628 | + */ |
|
629 | + public static function resend_message() |
|
630 | + { |
|
631 | + self::_load_controller(); |
|
632 | + |
|
633 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
634 | + if (! $msgID) { |
|
635 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
636 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
637 | + return false; |
|
638 | + } |
|
639 | + |
|
640 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
641 | + |
|
642 | + //setup success message. |
|
643 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
644 | + EE_Error::add_success(sprintf( |
|
645 | + _n( |
|
646 | + 'There was %d message queued for resending.', |
|
647 | + 'There were %d messages queued for resending.', |
|
648 | + $count_ready_for_resend, |
|
649 | + 'event_espresso' |
|
650 | + ), |
|
651 | + $count_ready_for_resend |
|
652 | + )); |
|
653 | + return true; |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * Message triggers for manual payment applied by admin |
|
659 | + * |
|
660 | + * @param EE_Payment $payment EE_payment object |
|
661 | + * @return bool success/fail |
|
662 | + */ |
|
663 | + public static function process_admin_payment(EE_Payment $payment) |
|
664 | + { |
|
665 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
666 | + //we need to get the transaction object |
|
667 | + $transaction = $payment->transaction(); |
|
668 | + if ($transaction instanceof EE_Transaction) { |
|
669 | + $data = array($transaction, $payment); |
|
670 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
671 | + |
|
672 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
673 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
674 | + |
|
675 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
676 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
677 | + |
|
678 | + self::_load_controller(); |
|
679 | + |
|
680 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
681 | + |
|
682 | + //get count of queued for generation |
|
683 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
684 | + EEM_Message::status_incomplete, |
|
685 | + EEM_Message::status_idle, |
|
686 | + )); |
|
687 | + |
|
688 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
689 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
690 | + return true; |
|
691 | + } else { |
|
692 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
693 | + /** |
|
694 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
695 | + * IMMEDIATE generation. |
|
696 | + */ |
|
697 | + if ($count_failed > 0) { |
|
698 | + EE_Error::add_error(sprintf( |
|
699 | + _n( |
|
700 | + 'The payment notification generation failed.', |
|
701 | + '%d payment notifications failed being sent.', |
|
702 | + $count_failed, |
|
703 | + 'event_espresso' |
|
704 | + ), |
|
705 | + $count_failed |
|
706 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
707 | + |
|
708 | + return false; |
|
709 | + } else { |
|
710 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
711 | + return true; |
|
712 | + } |
|
713 | + } |
|
714 | + } else { |
|
715 | + EE_Error::add_error( |
|
716 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
717 | + 'event_espresso' |
|
718 | + ); |
|
719 | + return false; |
|
720 | + } |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
726 | + * |
|
727 | + * @since 4.3.0 |
|
728 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
729 | + * @param int $grp_id a specific message template group id. |
|
730 | + * @return void |
|
731 | + */ |
|
732 | + public static function send_newsletter_message($registrations, $grp_id) |
|
733 | + { |
|
734 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
735 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
736 | + self::_load_controller(); |
|
737 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
738 | + } |
|
739 | + |
|
740 | + |
|
741 | + /** |
|
742 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
743 | + * |
|
744 | + * @since 4.3.0 |
|
745 | + * @param string $registration_message_trigger_url |
|
746 | + * @param EE_Registration $registration |
|
747 | + * @param string $messenger |
|
748 | + * @param string $message_type |
|
749 | + * @return string |
|
750 | + */ |
|
751 | + public static function registration_message_trigger_url( |
|
752 | + $registration_message_trigger_url, |
|
753 | + EE_Registration $registration, |
|
754 | + $messenger = 'html', |
|
755 | + $message_type = 'invoice' |
|
756 | + ) { |
|
757 | + // whitelist $messenger |
|
758 | + switch ($messenger) { |
|
759 | + case 'pdf' : |
|
760 | + $sending_messenger = 'pdf'; |
|
761 | + $generating_messenger = 'html'; |
|
762 | + break; |
|
763 | + case 'html' : |
|
764 | + default : |
|
765 | + $sending_messenger = 'html'; |
|
766 | + $generating_messenger = 'html'; |
|
767 | + break; |
|
768 | + } |
|
769 | + // whitelist $message_type |
|
770 | + switch ($message_type) { |
|
771 | + case 'receipt' : |
|
772 | + $message_type = 'receipt'; |
|
773 | + break; |
|
774 | + case 'invoice' : |
|
775 | + default : |
|
776 | + $message_type = 'invoice'; |
|
777 | + break; |
|
778 | + } |
|
779 | + // verify that both the messenger AND the message type are active |
|
780 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
781 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
782 | + $template_query_params = array( |
|
783 | + 'MTP_is_active' => true, |
|
784 | + 'MTP_messenger' => $generating_messenger, |
|
785 | + 'MTP_message_type' => $message_type, |
|
786 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
787 | + ); |
|
788 | + //get the message template group. |
|
789 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
790 | + //if we don't have an EE_Message_Template_Group then return |
|
791 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
792 | + // remove EVT_ID from query params so that global templates get picked up |
|
793 | + unset($template_query_params['Event.EVT_ID']); |
|
794 | + //get global template as the fallback |
|
795 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
796 | + } |
|
797 | + //if we don't have an EE_Message_Template_Group then return |
|
798 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
799 | + return ''; |
|
800 | + } |
|
801 | + // generate the URL |
|
802 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
803 | + $sending_messenger, |
|
804 | + $generating_messenger, |
|
805 | + 'purchaser', |
|
806 | + $message_type, |
|
807 | + $registration, |
|
808 | + $msg_template_group->ID(), |
|
809 | + $registration->transaction_ID() |
|
810 | + ); |
|
811 | + |
|
812 | + } |
|
813 | + return $registration_message_trigger_url; |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + /** |
|
818 | + * Use to generate and return a message preview! |
|
819 | + * |
|
820 | + * @param string $type This should correspond with a valid message type |
|
821 | + * @param string $context This should correspond with a valid context for the message type |
|
822 | + * @param string $messenger This should correspond with a valid messenger. |
|
823 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
824 | + * preview |
|
825 | + * @return string|bool The body of the message or if send is requested, sends. |
|
826 | + */ |
|
827 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
828 | + { |
|
829 | + self::_load_controller(); |
|
830 | + $mtg = new EE_Message_To_Generate( |
|
831 | + $messenger, |
|
832 | + $type, |
|
833 | + array(), |
|
834 | + $context, |
|
835 | + true |
|
836 | + ); |
|
837 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
838 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
839 | + return $generated_preview_queue->get_message_repository()->current()->content(); |
|
840 | + } else { |
|
841 | + return $generated_preview_queue; |
|
842 | + } |
|
843 | + } |
|
844 | + |
|
845 | + |
|
846 | + /** |
|
847 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
848 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
849 | + * content found in the EE_Message objects in the queue. |
|
850 | + * |
|
851 | + * @since 4.9.0 |
|
852 | + * @param string $messenger a string matching a valid active messenger in the system |
|
853 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
854 | + * type name is still required to send along the message type to the |
|
855 | + * messenger because this is used for determining what specific |
|
856 | + * variations might be loaded for the generated message. |
|
857 | + * @param EE_Messages_Queue $queue |
|
858 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
859 | + * aggregate EE_Message object. |
|
860 | + * @return bool success or fail. |
|
861 | + */ |
|
862 | + public static function send_message_with_messenger_only( |
|
863 | + $messenger, |
|
864 | + $message_type, |
|
865 | + EE_Messages_Queue $queue, |
|
866 | + $custom_subject = '' |
|
867 | + ) { |
|
868 | + self::_load_controller(); |
|
869 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
870 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
871 | + 'Message_To_Generate_From_Queue', |
|
872 | + array( |
|
873 | + $messenger, |
|
874 | + $message_type, |
|
875 | + $queue, |
|
876 | + $custom_subject, |
|
877 | + ) |
|
878 | + ); |
|
879 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
880 | + } |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
885 | + * |
|
886 | + * @since 4.9.0 |
|
887 | + * @param array $message_ids An array of message ids |
|
888 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
889 | + * messages. |
|
890 | + */ |
|
891 | + public static function generate_now($message_ids) |
|
892 | + { |
|
893 | + self::_load_controller(); |
|
894 | + $messages = EEM_Message::instance()->get_all( |
|
895 | + array( |
|
896 | + 0 => array( |
|
897 | + 'MSG_ID' => array('IN', $message_ids), |
|
898 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
899 | + ), |
|
900 | + ) |
|
901 | + ); |
|
902 | + $generated_queue = false; |
|
903 | + if ($messages) { |
|
904 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
905 | + } |
|
906 | + |
|
907 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
908 | + EE_Error::add_error( |
|
909 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
910 | + 'event_espresso'), |
|
911 | + __FILE__, __FUNCTION__, __LINE__ |
|
912 | + ); |
|
913 | + } |
|
914 | + return $generated_queue; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
920 | + * EEM_Message::status_idle |
|
921 | + * |
|
922 | + * @since 4.9.0 |
|
923 | + * @param $message_ids |
|
924 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
925 | + */ |
|
926 | + public static function send_now($message_ids) |
|
927 | + { |
|
928 | + self::_load_controller(); |
|
929 | + $messages = EEM_Message::instance()->get_all( |
|
930 | + array( |
|
931 | + 0 => array( |
|
932 | + 'MSG_ID' => array('IN', $message_ids), |
|
933 | + 'STS_ID' => array( |
|
934 | + 'IN', |
|
935 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
936 | + ), |
|
937 | + ), |
|
938 | + ) |
|
939 | + ); |
|
940 | + $sent_queue = false; |
|
941 | + if ($messages) { |
|
942 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
943 | + } |
|
944 | + |
|
945 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
946 | + EE_Error::add_error( |
|
947 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
948 | + 'event_espresso'), |
|
949 | + __FILE__, __FUNCTION__, __LINE__ |
|
950 | + ); |
|
951 | + } else { |
|
952 | + //can count how many sent by using the messages in the queue |
|
953 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
954 | + if ($sent_count > 0) { |
|
955 | + EE_Error::add_success( |
|
956 | + sprintf( |
|
957 | + _n( |
|
958 | + 'There was %d message successfully sent.', |
|
959 | + 'There were %d messages successfully sent.', |
|
960 | + $sent_count, |
|
961 | + 'event_espresso' |
|
962 | + ), |
|
963 | + $sent_count |
|
964 | + ) |
|
965 | + ); |
|
966 | + } else { |
|
967 | + EE_Error::overwrite_errors(); |
|
968 | + EE_Error::add_error( |
|
969 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
970 | 970 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
971 | - 'event_espresso'), |
|
972 | - __FILE__, __FUNCTION__, __LINE__ |
|
973 | - ); |
|
974 | - } |
|
975 | - } |
|
976 | - return $sent_queue; |
|
977 | - } |
|
978 | - |
|
979 | - |
|
980 | - /** |
|
981 | - * This will queue the incoming message ids for resending. |
|
982 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
983 | - * |
|
984 | - * @since 4.9.0 |
|
985 | - * @param array $message_ids An array of EE_Message IDs |
|
986 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
987 | - * resending. |
|
988 | - */ |
|
989 | - public static function queue_for_resending($message_ids) |
|
990 | - { |
|
991 | - self::_load_controller(); |
|
992 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
993 | - |
|
994 | - //get queue and count |
|
995 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
996 | - |
|
997 | - if ( |
|
998 | - $queue_count > 0 |
|
999 | - ) { |
|
1000 | - EE_Error::add_success( |
|
1001 | - sprintf( |
|
1002 | - _n( |
|
1003 | - '%d message successfully queued for resending.', |
|
1004 | - '%d messages successfully queued for resending.', |
|
1005 | - $queue_count, |
|
1006 | - 'event_espresso' |
|
1007 | - ), |
|
1008 | - $queue_count |
|
1009 | - ) |
|
1010 | - ); |
|
1011 | - /** |
|
1012 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1013 | - */ |
|
1014 | - } elseif ( |
|
1015 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1016 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1017 | - ) { |
|
1018 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1019 | - if ($queue_count > 0) { |
|
1020 | - EE_Error::add_success( |
|
1021 | - sprintf( |
|
1022 | - _n( |
|
1023 | - '%d message successfully sent.', |
|
1024 | - '%d messages successfully sent.', |
|
1025 | - $queue_count, |
|
1026 | - 'event_espresso' |
|
1027 | - ), |
|
1028 | - $queue_count |
|
1029 | - ) |
|
1030 | - ); |
|
1031 | - } else { |
|
1032 | - EE_Error::add_error( |
|
1033 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1034 | - 'event_espresso'), |
|
1035 | - __FILE__, __FUNCTION__, __LINE__ |
|
1036 | - ); |
|
1037 | - } |
|
1038 | - } else { |
|
1039 | - EE_Error::add_error( |
|
1040 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1041 | - 'event_espresso'), |
|
1042 | - __FILE__, __FUNCTION__, __LINE__ |
|
1043 | - ); |
|
1044 | - } |
|
1045 | - return (bool)$queue_count; |
|
1046 | - } |
|
1047 | - |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * debug |
|
1051 | - * |
|
1052 | - * @param string $class |
|
1053 | - * @param string $func |
|
1054 | - * @param string $line |
|
1055 | - * @param \EE_Transaction $transaction |
|
1056 | - * @param array $info |
|
1057 | - * @param bool $display_request |
|
1058 | - */ |
|
1059 | - protected static function log( |
|
1060 | - $class = '', |
|
1061 | - $func = '', |
|
1062 | - $line = '', |
|
1063 | - EE_Transaction $transaction, |
|
1064 | - $info = array(), |
|
1065 | - $display_request = false |
|
1066 | - ) { |
|
1067 | - if (WP_DEBUG && false) { |
|
1068 | - if ($transaction instanceof EE_Transaction) { |
|
1069 | - // don't serialize objects |
|
1070 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1071 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1072 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1073 | - if ($transaction->ID()) { |
|
1074 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1075 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1076 | - } |
|
1077 | - } |
|
1078 | - } |
|
1079 | - |
|
1080 | - } |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Resets all the static properties in this class when called. |
|
1085 | - */ |
|
1086 | - public static function reset() |
|
1087 | - { |
|
1088 | - self::$_EEMSG = null; |
|
1089 | - self::$_message_resource_manager = null; |
|
1090 | - self::$_MSG_PROCESSOR = null; |
|
1091 | - self::$_MSG_PATHS = null; |
|
1092 | - self::$_TMP_PACKS = array(); |
|
1093 | - } |
|
971 | + 'event_espresso'), |
|
972 | + __FILE__, __FUNCTION__, __LINE__ |
|
973 | + ); |
|
974 | + } |
|
975 | + } |
|
976 | + return $sent_queue; |
|
977 | + } |
|
978 | + |
|
979 | + |
|
980 | + /** |
|
981 | + * This will queue the incoming message ids for resending. |
|
982 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
983 | + * |
|
984 | + * @since 4.9.0 |
|
985 | + * @param array $message_ids An array of EE_Message IDs |
|
986 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
987 | + * resending. |
|
988 | + */ |
|
989 | + public static function queue_for_resending($message_ids) |
|
990 | + { |
|
991 | + self::_load_controller(); |
|
992 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
993 | + |
|
994 | + //get queue and count |
|
995 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
996 | + |
|
997 | + if ( |
|
998 | + $queue_count > 0 |
|
999 | + ) { |
|
1000 | + EE_Error::add_success( |
|
1001 | + sprintf( |
|
1002 | + _n( |
|
1003 | + '%d message successfully queued for resending.', |
|
1004 | + '%d messages successfully queued for resending.', |
|
1005 | + $queue_count, |
|
1006 | + 'event_espresso' |
|
1007 | + ), |
|
1008 | + $queue_count |
|
1009 | + ) |
|
1010 | + ); |
|
1011 | + /** |
|
1012 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1013 | + */ |
|
1014 | + } elseif ( |
|
1015 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1016 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1017 | + ) { |
|
1018 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1019 | + if ($queue_count > 0) { |
|
1020 | + EE_Error::add_success( |
|
1021 | + sprintf( |
|
1022 | + _n( |
|
1023 | + '%d message successfully sent.', |
|
1024 | + '%d messages successfully sent.', |
|
1025 | + $queue_count, |
|
1026 | + 'event_espresso' |
|
1027 | + ), |
|
1028 | + $queue_count |
|
1029 | + ) |
|
1030 | + ); |
|
1031 | + } else { |
|
1032 | + EE_Error::add_error( |
|
1033 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1034 | + 'event_espresso'), |
|
1035 | + __FILE__, __FUNCTION__, __LINE__ |
|
1036 | + ); |
|
1037 | + } |
|
1038 | + } else { |
|
1039 | + EE_Error::add_error( |
|
1040 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1041 | + 'event_espresso'), |
|
1042 | + __FILE__, __FUNCTION__, __LINE__ |
|
1043 | + ); |
|
1044 | + } |
|
1045 | + return (bool)$queue_count; |
|
1046 | + } |
|
1047 | + |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * debug |
|
1051 | + * |
|
1052 | + * @param string $class |
|
1053 | + * @param string $func |
|
1054 | + * @param string $line |
|
1055 | + * @param \EE_Transaction $transaction |
|
1056 | + * @param array $info |
|
1057 | + * @param bool $display_request |
|
1058 | + */ |
|
1059 | + protected static function log( |
|
1060 | + $class = '', |
|
1061 | + $func = '', |
|
1062 | + $line = '', |
|
1063 | + EE_Transaction $transaction, |
|
1064 | + $info = array(), |
|
1065 | + $display_request = false |
|
1066 | + ) { |
|
1067 | + if (WP_DEBUG && false) { |
|
1068 | + if ($transaction instanceof EE_Transaction) { |
|
1069 | + // don't serialize objects |
|
1070 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1071 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1072 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1073 | + if ($transaction->ID()) { |
|
1074 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1075 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1076 | + } |
|
1077 | + } |
|
1078 | + } |
|
1079 | + |
|
1080 | + } |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Resets all the static properties in this class when called. |
|
1085 | + */ |
|
1086 | + public static function reset() |
|
1087 | + { |
|
1088 | + self::$_EEMSG = null; |
|
1089 | + self::$_message_resource_manager = null; |
|
1090 | + self::$_MSG_PROCESSOR = null; |
|
1091 | + self::$_MSG_PATHS = null; |
|
1092 | + self::$_TMP_PACKS = array(); |
|
1093 | + } |
|
1094 | 1094 | |
1095 | 1095 | } |
1096 | 1096 | // End of file EED_Messages.module.php |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
151 | 151 | 'event_espresso'); |
152 | 152 | // add specific message for developers if WP_DEBUG in on |
153 | - $error_msg .= '||' . $e->getMessage(); |
|
153 | + $error_msg .= '||'.$e->getMessage(); |
|
154 | 154 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
155 | 155 | } |
156 | 156 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
227 | 227 | 'event_espresso'); |
228 | 228 | // add specific message for developers if WP_DEBUG in on |
229 | - $error_msg .= '||' . $e->getMessage(); |
|
229 | + $error_msg .= '||'.$e->getMessage(); |
|
230 | 230 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
231 | 231 | } |
232 | 232 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | $transient_key = EE_Registry::instance()->REQ->get('key'); |
258 | 258 | |
259 | 259 | //now let's verify transient, if not valid exit immediately |
260 | - if (! get_transient($transient_key)) { |
|
260 | + if ( ! get_transient($transient_key)) { |
|
261 | 261 | /** |
262 | 262 | * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
263 | 263 | */ |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | |
270 | 270 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
271 | 271 | |
272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
272 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
273 | 273 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
274 | 274 | self::$_MSG_PROCESSOR->$method(); |
275 | 275 | } else { |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | 'messages/validators/html', |
367 | 367 | 'shortcodes', |
368 | 368 | ); |
369 | - $paths = array(); |
|
369 | + $paths = array(); |
|
370 | 370 | foreach ($dir_ref as $index => $dir) { |
371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
371 | + $paths[$index] = EE_LIBRARIES.$dir; |
|
372 | 372 | } |
373 | 373 | self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
374 | 374 | } |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | protected static function _load_controller() |
384 | 384 | { |
385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
385 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | 386 | EE_Registry::instance()->load_core('Request_Handler'); |
387 | 387 | self::set_autoloaders(); |
388 | 388 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
446 | 446 | { |
447 | 447 | |
448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
448 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | 449 | //no messages please |
450 | 450 | return; |
451 | 451 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | // array( '$extra_details' => $extra_details ) |
511 | 511 | //); |
512 | 512 | // currently only using this to send messages for the primary registrant |
513 | - if (! $registration->is_primary_registrant()) { |
|
513 | + if ( ! $registration->is_primary_registrant()) { |
|
514 | 514 | return false; |
515 | 515 | } |
516 | 516 | // first we check if we're in admin and not doing front ajax |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | } else { |
524 | 524 | // frontend request (either regular or via AJAX) |
525 | 525 | // TXN is NOT finalized ? |
526 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
526 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
527 | 527 | return false; |
528 | 528 | } |
529 | 529 | // return visit but nothing changed ??? |
@@ -598,12 +598,12 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | //make sure any incoming request data is set on the REQ so that it gets picked up later. |
601 | - $req_data = (array)$req_data; |
|
601 | + $req_data = (array) $req_data; |
|
602 | 602 | foreach ($req_data as $request_key => $request_value) { |
603 | 603 | EE_Registry::instance()->REQ->set($request_key, $request_value); |
604 | 604 | } |
605 | 605 | |
606 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
606 | + if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
607 | 607 | return false; |
608 | 608 | } |
609 | 609 | |
@@ -631,13 +631,13 @@ discard block |
||
631 | 631 | self::_load_controller(); |
632 | 632 | |
633 | 633 | $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
634 | - if (! $msgID) { |
|
634 | + if ( ! $msgID) { |
|
635 | 635 | EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
636 | 636 | 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
637 | 637 | return false; |
638 | 638 | } |
639 | 639 | |
640 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
640 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
641 | 641 | |
642 | 642 | //setup success message. |
643 | 643 | $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | public static function send_newsletter_message($registrations, $grp_id) |
733 | 733 | { |
734 | 734 | //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
735 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
735 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
736 | 736 | self::_load_controller(); |
737 | 737 | self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
738 | 738 | } |
@@ -788,14 +788,14 @@ discard block |
||
788 | 788 | //get the message template group. |
789 | 789 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
790 | 790 | //if we don't have an EE_Message_Template_Group then return |
791 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
791 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
792 | 792 | // remove EVT_ID from query params so that global templates get picked up |
793 | 793 | unset($template_query_params['Event.EVT_ID']); |
794 | 794 | //get global template as the fallback |
795 | 795 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
796 | 796 | } |
797 | 797 | //if we don't have an EE_Message_Template_Group then return |
798 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
798 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
799 | 799 | return ''; |
800 | 800 | } |
801 | 801 | // generate the URL |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | public static function preview_message($type, $context, $messenger, $send = false) |
828 | 828 | { |
829 | 829 | self::_load_controller(); |
830 | - $mtg = new EE_Message_To_Generate( |
|
830 | + $mtg = new EE_Message_To_Generate( |
|
831 | 831 | $messenger, |
832 | 832 | $type, |
833 | 833 | array(), |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | public static function generate_now($message_ids) |
892 | 892 | { |
893 | 893 | self::_load_controller(); |
894 | - $messages = EEM_Message::instance()->get_all( |
|
894 | + $messages = EEM_Message::instance()->get_all( |
|
895 | 895 | array( |
896 | 896 | 0 => array( |
897 | 897 | 'MSG_ID' => array('IN', $message_ids), |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
905 | 905 | } |
906 | 906 | |
907 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
907 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
908 | 908 | EE_Error::add_error( |
909 | 909 | __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
910 | 910 | 'event_espresso'), |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | public static function send_now($message_ids) |
927 | 927 | { |
928 | 928 | self::_load_controller(); |
929 | - $messages = EEM_Message::instance()->get_all( |
|
929 | + $messages = EEM_Message::instance()->get_all( |
|
930 | 930 | array( |
931 | 931 | 0 => array( |
932 | 932 | 'MSG_ID' => array('IN', $message_ids), |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
943 | 943 | } |
944 | 944 | |
945 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
945 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
946 | 946 | EE_Error::add_error( |
947 | 947 | __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
948 | 948 | 'event_espresso'), |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | __FILE__, __FUNCTION__, __LINE__ |
1043 | 1043 | ); |
1044 | 1044 | } |
1045 | - return (bool)$queue_count; |
|
1045 | + return (bool) $queue_count; |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | |
@@ -1071,7 +1071,7 @@ discard block |
||
1071 | 1071 | $info['TXN_status'] = $transaction->status_ID(); |
1072 | 1072 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
1073 | 1073 | if ($transaction->ID()) { |
1074 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1074 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
1075 | 1075 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
1076 | 1076 | } |
1077 | 1077 | } |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | |
15 | 15 | //need the MER plugin active for this test (we'll deactivate it after). |
16 | 16 | $I->ensurePluginActive( |
17 | - 'event-espresso-mer-multi-event-registration', |
|
18 | - 'activated' |
|
17 | + 'event-espresso-mer-multi-event-registration', |
|
18 | + 'activated' |
|
19 | 19 | ); |
20 | 20 | |
21 | 21 | //k now we need to make sure the registration multi-status message type is active because it isn't by default |
@@ -68,42 +68,42 @@ discard block |
||
68 | 68 | $I->loginAsAdmin(); |
69 | 69 | $I->amOnMessagesActivityListTablePage(); |
70 | 70 | $I->see( |
71 | - '[email protected]', |
|
72 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
73 | - 'to', |
|
74 | - 'Registration Multi-status Summary', |
|
75 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
76 | - '', |
|
77 | - 'Primary Registrant' |
|
78 | - ) |
|
71 | + '[email protected]', |
|
72 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
73 | + 'to', |
|
74 | + 'Registration Multi-status Summary', |
|
75 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
76 | + '', |
|
77 | + 'Primary Registrant' |
|
78 | + ) |
|
79 | 79 | ); |
80 | 80 | $I->see( |
81 | - '[email protected]', |
|
82 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
83 | - 'to', |
|
84 | - 'Registration Multi-status Summary', |
|
85 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
86 | - ) |
|
81 | + '[email protected]', |
|
82 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
83 | + 'to', |
|
84 | + 'Registration Multi-status Summary', |
|
85 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
86 | + ) |
|
87 | 87 | ); |
88 | 88 | //verify count |
89 | 89 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
90 | - 1, |
|
91 | - '[email protected]', |
|
92 | - 'to', |
|
93 | - 'Registration Multi-status Summary', |
|
94 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
95 | - 'Email', |
|
96 | - 'Primary Registrant' |
|
90 | + 1, |
|
91 | + '[email protected]', |
|
92 | + 'to', |
|
93 | + 'Registration Multi-status Summary', |
|
94 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
95 | + 'Email', |
|
96 | + 'Primary Registrant' |
|
97 | 97 | ); |
98 | 98 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
99 | - 1, |
|
100 | - '[email protected]', |
|
101 | - 'to', |
|
102 | - 'Registration Multi-status Summary' |
|
99 | + 1, |
|
100 | + '[email protected]', |
|
101 | + 'to', |
|
102 | + 'Registration Multi-status Summary' |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | //deactivate MER plugin so its not active for future tests |
106 | 106 | $I->ensurePluginDeactivated( |
107 | - 'event-espresso-mer-multi-event-registration', |
|
108 | - 'Plugin deactivated' |
|
107 | + 'event-espresso-mer-multi-event-registration', |
|
108 | + 'Plugin deactivated' |
|
109 | 109 | ); |
110 | 110 | \ No newline at end of file |
@@ -11,20 +11,20 @@ |
||
11 | 11 | */ |
12 | 12 | class RegistrationsAdmin extends CoreAdmin |
13 | 13 | { |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - const REGISTRATION_STATUS_NOT_APPROVED = 'RNA'; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + const REGISTRATION_STATUS_NOT_APPROVED = 'RNA'; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - const REGISTRATION_STATUS_APPROVED = 'RAP'; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + const REGISTRATION_STATUS_APPROVED = 'RAP'; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - const REGISTRATION_STATUS_PENDING_PAYMENT = 'RPP'; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + const REGISTRATION_STATUS_PENDING_PAYMENT = 'RPP'; |
|
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -14,143 +14,143 @@ |
||
14 | 14 | class EventsAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Selector for the Add new Event button in the admin. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Selector for the Event Title field in the event editor |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | - |
|
30 | - /** |
|
31 | - * Selector for the publish submit button in the event editor. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Selector for the view link after publishing an event. |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Selector for the ID of the event in the event editor |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Selector for the search input on the event list table page. |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $additional_params |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
70 | - { |
|
71 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * The selector for the DTTname field for the given row in the event editor. |
|
77 | - * @param int $row_number |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
81 | - { |
|
82 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
88 | - * @param int $row_number |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
92 | - { |
|
93 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
99 | - * |
|
100 | - * @param string $field_name |
|
101 | - * @param int $row_number |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
105 | - { |
|
106 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
112 | - * @param int $row_number |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
116 | - { |
|
117 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
123 | - * @param $field_name |
|
124 | - * @param int $row_number |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
128 | - { |
|
129 | - return "//tr[@id='display-ticketrow-$row_number']/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']"; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
135 | - * @param string $event_title |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
139 | - { |
|
140 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
145 | - { |
|
146 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
147 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
152 | - { |
|
153 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
154 | - . "//ancestor::td//span[@class='view']/a"; |
|
155 | - } |
|
17 | + /** |
|
18 | + * Selector for the Add new Event button in the admin. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Selector for the Event Title field in the event editor |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | + |
|
30 | + /** |
|
31 | + * Selector for the publish submit button in the event editor. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Selector for the view link after publishing an event. |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Selector for the ID of the event in the event editor |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Selector for the search input on the event list table page. |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $additional_params |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
70 | + { |
|
71 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * The selector for the DTTname field for the given row in the event editor. |
|
77 | + * @param int $row_number |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
81 | + { |
|
82 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
88 | + * @param int $row_number |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
92 | + { |
|
93 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
99 | + * |
|
100 | + * @param string $field_name |
|
101 | + * @param int $row_number |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
105 | + { |
|
106 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
112 | + * @param int $row_number |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
116 | + { |
|
117 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
123 | + * @param $field_name |
|
124 | + * @param int $row_number |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
128 | + { |
|
129 | + return "//tr[@id='display-ticketrow-$row_number']/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']"; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
135 | + * @param string $event_title |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
139 | + { |
|
140 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
145 | + { |
|
146 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
147 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
152 | + { |
|
153 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
154 | + . "//ancestor::td//span[@class='view']/a"; |
|
155 | + } |
|
156 | 156 | } |
157 | 157 | \ No newline at end of file |
@@ -12,146 +12,146 @@ |
||
12 | 12 | class MessagesAdmin extends CoreAdmin |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Context slug for the admin messages context. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - const ADMIN_CONTEXT_SLUG = 'admin'; |
|
20 | - |
|
21 | - /** |
|
22 | - * Context slug for the primary attendee messages context |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Status reference for the EEM_Message::status_sent status. |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - const MESSAGE_STATUS_SENT = 'MSN'; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Message type slug for the Payment Failed message type |
|
37 | - */ |
|
38 | - const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request'; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * This is the container where active message types for a messenger are found/dragged to. |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
65 | - * a string. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public static function messageActivityListTableUrl($additional_params = '') |
|
69 | - { |
|
70 | - return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
76 | - * a string. |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
80 | - { |
|
81 | - return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
87 | - * a string. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public static function customMessageTemplateListTableUrl($additional_params = '') |
|
91 | - { |
|
92 | - return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public static function messageSettingsUrl() |
|
100 | - { |
|
101 | - return self::adminUrl('espresso_messages', 'settings'); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
107 | - $message_type_slug, |
|
108 | - $messenger_slug = 'email' |
|
109 | - ) { |
|
110 | - return "#$message_type_slug-messagetype-$messenger_slug"; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $message_type_slug |
|
116 | - * @param string $context |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
120 | - { |
|
121 | - return $context |
|
122 | - ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
123 | - : '.' . $message_type_slug . '-edit-link'; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
129 | - * @param $field |
|
130 | - * @param $message_type_label |
|
131 | - * @param string $message_status |
|
132 | - * @param string $messenger |
|
133 | - * @param string $context |
|
134 | - * @param string $table_cell_content_for_field |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public static function messagesActivityListTableCellSelectorFor( |
|
138 | - $field, |
|
139 | - $message_type_label, |
|
140 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
141 | - $messenger = 'Email', |
|
142 | - $context = 'Event Admin', |
|
143 | - $table_cell_content_for_field = '' |
|
144 | - ) { |
|
145 | - $selector = "//tr[contains(@class, 'msg-status-$message_status')]" |
|
146 | - . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
147 | - if ($messenger) { |
|
148 | - $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
149 | - } |
|
150 | - $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
151 | - $selector .= $table_cell_content_for_field |
|
152 | - ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
153 | - : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
154 | - return $selector; |
|
155 | - } |
|
15 | + /** |
|
16 | + * Context slug for the admin messages context. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + const ADMIN_CONTEXT_SLUG = 'admin'; |
|
20 | + |
|
21 | + /** |
|
22 | + * Context slug for the primary attendee messages context |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Status reference for the EEM_Message::status_sent status. |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + const MESSAGE_STATUS_SENT = 'MSN'; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Message type slug for the Payment Failed message type |
|
37 | + */ |
|
38 | + const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = '#global_messages_settings-do-messages-on-same-request'; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * This is the container where active message types for a messenger are found/dragged to. |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
65 | + * a string. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public static function messageActivityListTableUrl($additional_params = '') |
|
69 | + { |
|
70 | + return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
76 | + * a string. |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
80 | + { |
|
81 | + return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
87 | + * a string. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public static function customMessageTemplateListTableUrl($additional_params = '') |
|
91 | + { |
|
92 | + return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public static function messageSettingsUrl() |
|
100 | + { |
|
101 | + return self::adminUrl('espresso_messages', 'settings'); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
107 | + $message_type_slug, |
|
108 | + $messenger_slug = 'email' |
|
109 | + ) { |
|
110 | + return "#$message_type_slug-messagetype-$messenger_slug"; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $message_type_slug |
|
116 | + * @param string $context |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
120 | + { |
|
121 | + return $context |
|
122 | + ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
123 | + : '.' . $message_type_slug . '-edit-link'; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
129 | + * @param $field |
|
130 | + * @param $message_type_label |
|
131 | + * @param string $message_status |
|
132 | + * @param string $messenger |
|
133 | + * @param string $context |
|
134 | + * @param string $table_cell_content_for_field |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public static function messagesActivityListTableCellSelectorFor( |
|
138 | + $field, |
|
139 | + $message_type_label, |
|
140 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
141 | + $messenger = 'Email', |
|
142 | + $context = 'Event Admin', |
|
143 | + $table_cell_content_for_field = '' |
|
144 | + ) { |
|
145 | + $selector = "//tr[contains(@class, 'msg-status-$message_status')]" |
|
146 | + . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
147 | + if ($messenger) { |
|
148 | + $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
149 | + } |
|
150 | + $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
151 | + $selector .= $table_cell_content_for_field |
|
152 | + ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
153 | + : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
154 | + return $selector; |
|
155 | + } |
|
156 | 156 | |
157 | 157 | } |
158 | 158 | \ No newline at end of file |
@@ -14,61 +14,61 @@ |
||
14 | 14 | trait EventsAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param string $additional_params |
|
19 | - */ |
|
20 | - public function amOnDefaultEventsListTablePage($additional_params = '') |
|
21 | - { |
|
22 | - $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @param string $additional_params |
|
19 | + */ |
|
20 | + public function amOnDefaultEventsListTablePage($additional_params = '') |
|
21 | + { |
|
22 | + $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Triggers the publishing of the Event. |
|
28 | - */ |
|
29 | - public function publishEvent() |
|
30 | - { |
|
31 | - $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
32 | - } |
|
26 | + /** |
|
27 | + * Triggers the publishing of the Event. |
|
28 | + */ |
|
29 | + public function publishEvent() |
|
30 | + { |
|
31 | + $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
37 | - * First this will search using the given title and then attempt to edit from the results of the search. |
|
38 | - * |
|
39 | - * Assumes actor is already logged in. |
|
40 | - * @param $event_title |
|
41 | - */ |
|
42 | - public function amEditingTheEventWithTitle($event_title) |
|
43 | - { |
|
44 | - $this->amOnDefaultEventsListTablePage(); |
|
45 | - $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
46 | - $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
47 | - $this->actor()->waitForText('Displaying search results for'); |
|
48 | - $this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title)); |
|
49 | - } |
|
35 | + /** |
|
36 | + * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
37 | + * First this will search using the given title and then attempt to edit from the results of the search. |
|
38 | + * |
|
39 | + * Assumes actor is already logged in. |
|
40 | + * @param $event_title |
|
41 | + */ |
|
42 | + public function amEditingTheEventWithTitle($event_title) |
|
43 | + { |
|
44 | + $this->amOnDefaultEventsListTablePage(); |
|
45 | + $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
46 | + $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
47 | + $this->actor()->waitForText('Displaying search results for'); |
|
48 | + $this->actor()->click(EventsPage::eventListTableEventTitleEditLink($event_title)); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" link |
|
54 | - * for the event in the event list table. |
|
55 | - * |
|
56 | - * Assumes the actor is already logged in and on the Event list table page. |
|
57 | - * @param string $event_title |
|
58 | - */ |
|
59 | - public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
60 | - { |
|
61 | - $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
62 | - $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
63 | - } |
|
52 | + /** |
|
53 | + * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" link |
|
54 | + * for the event in the event list table. |
|
55 | + * |
|
56 | + * Assumes the actor is already logged in and on the Event list table page. |
|
57 | + * @param string $event_title |
|
58 | + */ |
|
59 | + public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
60 | + { |
|
61 | + $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
62 | + $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | - public function changeDefaultRegistrationStatusTo($registration_status) |
|
68 | - { |
|
69 | - $this->actor()->selectOption( |
|
70 | - EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
71 | - $registration_status |
|
72 | - ); |
|
73 | - } |
|
67 | + public function changeDefaultRegistrationStatusTo($registration_status) |
|
68 | + { |
|
69 | + $this->actor()->selectOption( |
|
70 | + EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
71 | + $registration_status |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | \ No newline at end of file |
@@ -10,105 +10,105 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for |
|
99 | - )); |
|
100 | - $actual_count = count($elements); |
|
101 | - $this->actor()->assertEquals( |
|
102 | - $expected_occurence_count, |
|
103 | - $actual_count, |
|
104 | - sprintf( |
|
105 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
106 | - $expected_occurence_count, |
|
107 | - $text_to_check_for, |
|
108 | - $field, |
|
109 | - $actual_count |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for |
|
99 | + )); |
|
100 | + $actual_count = count($elements); |
|
101 | + $this->actor()->assertEquals( |
|
102 | + $expected_occurence_count, |
|
103 | + $actual_count, |
|
104 | + sprintf( |
|
105 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
106 | + $expected_occurence_count, |
|
107 | + $text_to_check_for, |
|
108 | + $field, |
|
109 | + $actual_count |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -12,481 +12,481 @@ |
||
12 | 12 | class Custom_Messages_Template_List_Table extends EE_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Custom_Messages_Template_List_Table constructor. |
|
17 | - * |
|
18 | - * @param EE_Admin_Page $admin_page |
|
19 | - */ |
|
20 | - public function __construct($admin_page) |
|
21 | - { |
|
22 | - //Set parent defaults |
|
23 | - parent::__construct($admin_page); |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @return Messages_Admin_Page |
|
29 | - */ |
|
30 | - public function get_admin_page() |
|
31 | - { |
|
32 | - return $this->_admin_page; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Setup initial data. |
|
37 | - */ |
|
38 | - protected function _setup_data() |
|
39 | - { |
|
40 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | - $this->_per_page, |
|
42 | - $this->_view, |
|
43 | - false, |
|
44 | - false, |
|
45 | - false |
|
46 | - ); |
|
47 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
48 | - $this->_per_page, |
|
49 | - $this->_view, |
|
50 | - true, |
|
51 | - true, |
|
52 | - false |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Set initial properties |
|
59 | - */ |
|
60 | - protected function _set_properties() |
|
61 | - { |
|
62 | - $this->_wp_list_args = array( |
|
63 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
64 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
65 | - 'ajax' => true, //for now, |
|
66 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
67 | - ); |
|
68 | - |
|
69 | - $this->_columns = array( |
|
70 | - 'cb' => '<input type="checkbox" />', |
|
71 | - 'name' => esc_html__('Template Name', 'event_espresso'), |
|
72 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
73 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
74 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
75 | - 'events' => esc_html__('Events', 'event_espresso'), |
|
76 | - //count of events using this template. |
|
77 | - 'actions' => '' |
|
78 | - ); |
|
79 | - |
|
80 | - $this->_sortable_columns = array( |
|
81 | - 'messenger' => array('MTP_messenger' => true), |
|
82 | - ); |
|
83 | - |
|
84 | - $this->_hidden_columns = array(); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
90 | - * message_type or messenger object before generating the row. |
|
91 | - * |
|
92 | - * @param EE_Message_Template_Group $item |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function single_row($item) |
|
96 | - { |
|
97 | - $message_type = $item->message_type_obj(); |
|
98 | - $messenger = $item->messenger_obj(); |
|
99 | - |
|
100 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | - echo ''; |
|
102 | - return; |
|
103 | - } |
|
104 | - |
|
105 | - parent::single_row($item); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - protected function _get_table_filters() |
|
113 | - { |
|
114 | - $filters = array(); |
|
115 | - |
|
116 | - //get select inputs |
|
117 | - $select_inputs = array( |
|
118 | - $this->_get_messengers_dropdown_filter(), |
|
119 | - $this->_get_message_types_dropdown_filter(), |
|
120 | - ); |
|
121 | - |
|
122 | - //set filters to select inputs if they aren't empty |
|
123 | - foreach ($select_inputs as $select_input) { |
|
124 | - if ($select_input) { |
|
125 | - $filters[] = $select_input; |
|
126 | - } |
|
127 | - } |
|
128 | - return $filters; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * we're just removing the search box for message templates, not needed. |
|
133 | - * |
|
134 | - * @return string (empty); |
|
135 | - */ |
|
136 | - function search_box($text, $input_id) |
|
137 | - { |
|
138 | - return ''; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Set the view counts on the _views property |
|
144 | - */ |
|
145 | - protected function _add_view_counts() |
|
146 | - { |
|
147 | - foreach ($this->_views as $view => $args) { |
|
148 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
149 | - $this->_per_page, |
|
150 | - $view, |
|
151 | - true, |
|
152 | - true, |
|
153 | - false |
|
154 | - ); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Custom message for when there are no items found. |
|
161 | - * |
|
162 | - * @since 4.3.0 |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function no_items() |
|
166 | - { |
|
167 | - if ($this->_view !== 'trashed') { |
|
168 | - printf( |
|
169 | - esc_html__( |
|
170 | - '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
171 | - 'event_espresso' |
|
172 | - ), |
|
173 | - '<strong>', |
|
174 | - '</strong>' |
|
175 | - ); |
|
176 | - } else { |
|
177 | - parent::no_items(); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param EE_Message_Template_Group $item |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - public function column_cb($item) |
|
187 | - { |
|
188 | - return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID()); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @param EE_Message_Template_Group $item |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - function column_name($item) |
|
197 | - { |
|
198 | - return '<p>' . $item->name() . '</p>'; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param EE_Message_Template_Group $item |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - function column_description($item) |
|
207 | - { |
|
208 | - return '<p>' . $item->description() . '</p>'; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param EE_Message_Template_Group $item |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - function column_actions($item) |
|
217 | - { |
|
218 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
219 | - 'ee_edit_messages', |
|
220 | - 'espresso_messages_add_new_message_template' |
|
221 | - )) { |
|
222 | - $create_args = array( |
|
223 | - 'GRP_ID' => $item->ID(), |
|
224 | - 'messenger' => $item->messenger(), |
|
225 | - 'message_type' => $item->message_type(), |
|
226 | - 'action' => 'add_new_message_template', |
|
227 | - ); |
|
228 | - $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
229 | - return sprintf( |
|
230 | - '<p><a href="%s" class="button button-small">%s</a></p>', |
|
231 | - $create_link, |
|
232 | - esc_html__('Create Custom', 'event_espresso') |
|
233 | - ); |
|
234 | - } |
|
235 | - return ''; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Return the content for the messenger column |
|
241 | - * @param EE_Message_Template_Group $item |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - function column_messenger($item) |
|
245 | - { |
|
246 | - |
|
247 | - //Build row actions |
|
248 | - $actions = array(); |
|
249 | - $edit_lnk_url = ''; |
|
250 | - |
|
251 | - // edit link but only if item isn't trashed. |
|
252 | - if (! $item->get('MTP_deleted') |
|
253 | - && EE_Registry::instance()->CAP->current_user_can( |
|
254 | - 'ee_edit_message', |
|
255 | - 'espresso_messages_edit_message_template', |
|
256 | - $item->ID() |
|
257 | - ) |
|
258 | - ) { |
|
259 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | - 'action' => 'edit_message_template', |
|
261 | - 'id' => $item->GRP_ID(), |
|
262 | - ), EE_MSG_ADMIN_URL); |
|
263 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
265 | - . ' title="' |
|
266 | - . esc_attr__('Edit Template', 'event_espresso') |
|
267 | - . '">' |
|
268 | - . esc_html__('Edit', 'event_espresso') |
|
269 | - . '</a>'; |
|
270 | - } |
|
271 | - |
|
272 | - $name_link = ! $item->get('MTP_deleted') |
|
273 | - && EE_Registry::instance()->CAP->current_user_can( |
|
274 | - 'ee_edit_message', |
|
275 | - 'espresso_messages_edit_message_template', |
|
276 | - $item->ID() |
|
277 | - ) |
|
278 | - && $edit_lnk_url |
|
279 | - ? '<a href="' |
|
280 | - . $edit_lnk_url |
|
281 | - . '" title="' |
|
282 | - . esc_attr__('Edit Template', 'event_espresso') |
|
283 | - . '">' |
|
284 | - . ucwords($item->messenger_obj()->label['singular']) |
|
285 | - . '</a>' |
|
286 | - : ucwords($item->messenger_obj()->label['singular']); |
|
287 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
288 | - 'id' => $item->GRP_ID(), |
|
289 | - 'noheader' => true, |
|
290 | - ), EE_MSG_ADMIN_URL); |
|
291 | - // restore link |
|
292 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
293 | - 'id' => $item->GRP_ID(), |
|
294 | - 'noheader' => true, |
|
295 | - ), EE_MSG_ADMIN_URL); |
|
296 | - // delete price link |
|
297 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
298 | - 'id' => $item->GRP_ID(), |
|
299 | - 'noheader' => true, |
|
300 | - ), EE_MSG_ADMIN_URL); |
|
301 | - |
|
302 | - if (! $item->get('MTP_deleted') |
|
303 | - && EE_Registry::instance()->CAP->current_user_can( |
|
304 | - 'ee_delete_message', |
|
305 | - 'espresso_messages_trash_message_template', |
|
306 | - $item->ID() |
|
307 | - ) |
|
308 | - ) { |
|
309 | - $actions['trash'] = '<a href="' |
|
310 | - . $trash_lnk_url |
|
311 | - . '" title="' |
|
312 | - . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
313 | - . '">' |
|
314 | - . esc_html__('Move to Trash', 'event_espresso') |
|
315 | - . '</a>'; |
|
316 | - } else { |
|
317 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
318 | - 'ee_delete_message', |
|
319 | - 'espresso_messages_restore_message_template', |
|
320 | - $item->ID() |
|
321 | - )) { |
|
322 | - $actions['restore'] = '<a href="' |
|
323 | - . $restore_lnk_url |
|
324 | - . '" title="' |
|
325 | - . esc_attr__('Restore Message Template', 'event_espresso') |
|
326 | - . '">' |
|
327 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
328 | - } |
|
329 | - |
|
330 | - if ($this->_view == 'trashed' |
|
331 | - && EE_Registry::instance()->CAP->current_user_can( |
|
332 | - 'ee_delete_message', |
|
333 | - 'espresso_messages_delete_message_template', |
|
334 | - $item->ID() |
|
335 | - )) { |
|
336 | - $actions['delete'] = '<a href="' |
|
337 | - . $delete_lnk_url |
|
338 | - . '" title="' |
|
339 | - . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
340 | - . '">' |
|
341 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
342 | - . '</a>'; |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - //we want to display the contexts in here so we need to set them up |
|
347 | - $c_label = $item->context_label(); |
|
348 | - $c_configs = $item->contexts_config(); |
|
349 | - $ctxt = array(); |
|
350 | - $context_templates = $item->context_templates(); |
|
351 | - foreach ($context_templates as $context => $template_fields) { |
|
352 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
353 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
354 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
355 | - : null; |
|
356 | - $inactive = empty($mtp_to) && ! empty($context_templates[$context]['to']) |
|
357 | - ? ' class="mtp-inactive"' |
|
358 | - : ''; |
|
359 | - $context_title = ucwords($c_configs[$context]['label']); |
|
360 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
361 | - 'id' => $item->GRP_ID(), |
|
362 | - 'context' => $context, |
|
363 | - ), EE_MSG_ADMIN_URL); |
|
364 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | - 'ee_edit_message', |
|
366 | - 'espresso_messages_edit_message_template', |
|
367 | - $item->ID() |
|
368 | - ) |
|
369 | - ? '<a' |
|
370 | - . $inactive |
|
371 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | - . ' href="' . $edit_link . '"' |
|
373 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
374 | - . $context_title |
|
375 | - . '</a>' |
|
376 | - : $context_title; |
|
377 | - } |
|
378 | - |
|
379 | - $ctx_content = ! $item->get('MTP_deleted') |
|
380 | - && EE_Registry::instance()->CAP->current_user_can( |
|
381 | - 'ee_edit_message', |
|
382 | - 'espresso_messages_edit_message_template', |
|
383 | - $item->ID() |
|
384 | - ) |
|
385 | - ? sprintf( |
|
386 | - '<strong>%s:</strong> ', |
|
387 | - ucwords($c_label['plural']) |
|
388 | - ) |
|
389 | - . implode(' | ', $ctxt) |
|
390 | - : ''; |
|
391 | - |
|
392 | - |
|
393 | - //Return the name contents |
|
394 | - return sprintf( |
|
395 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
396 | - /* $1%s */ |
|
397 | - $name_link, |
|
398 | - /* $2%s */ |
|
399 | - $item->GRP_ID(), |
|
400 | - /* %4$s */ |
|
401 | - $ctx_content, |
|
402 | - /* $3%s */ |
|
403 | - $this->row_actions($actions) |
|
404 | - ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * column_events |
|
409 | - * This provides a count of events using this custom template |
|
410 | - * |
|
411 | - * @param EE_Message_Template_Group $item message_template group data |
|
412 | - * @return string column output |
|
413 | - */ |
|
414 | - function column_events($item) |
|
415 | - { |
|
416 | - return $item->count_events(); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * column_message_type |
|
421 | - * |
|
422 | - * @param EE_Message_Template_Group $item message info for the row |
|
423 | - * @return string message_type name |
|
424 | - */ |
|
425 | - function column_message_type($item) |
|
426 | - { |
|
427 | - return ucwords($item->message_type_obj()->label['singular']); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Generate dropdown filter select input for messengers |
|
433 | - * |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - protected function _get_messengers_dropdown_filter() |
|
437 | - { |
|
438 | - $messenger_options = array(); |
|
439 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
440 | - array( |
|
441 | - array( |
|
442 | - 'MTP_is_active' => true, |
|
443 | - 'MTP_is_global' => false, |
|
444 | - ), |
|
445 | - 'group_by' => 'MTP_messenger', |
|
446 | - ) |
|
447 | - ); |
|
448 | - |
|
449 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
450 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
451 | - $messenger = $active_message_template_group->messenger_obj(); |
|
452 | - $messenger_label = $messenger instanceof EE_messenger |
|
453 | - ? $messenger->label['singular'] |
|
454 | - : $active_message_template_group->messenger(); |
|
455 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
456 | - } |
|
457 | - } |
|
458 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * Generate dropdown filter select input for message types |
|
464 | - * |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - protected function _get_message_types_dropdown_filter() |
|
468 | - { |
|
469 | - $message_type_options = array(); |
|
470 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
471 | - array( |
|
472 | - array( |
|
473 | - 'MTP_is_active' => true, |
|
474 | - 'MTP_is_global' => false, |
|
475 | - ), |
|
476 | - 'group_by' => 'MTP_message_type', |
|
477 | - ) |
|
478 | - ); |
|
479 | - |
|
480 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
481 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
482 | - $message_type = $active_message_template_group->message_type_obj(); |
|
483 | - $message_type_label = $message_type instanceof EE_message_type |
|
484 | - ? $message_type->label['singular'] |
|
485 | - : $active_message_template_group->message_type(); |
|
486 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
487 | - } |
|
488 | - } |
|
489 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
490 | - } |
|
15 | + /** |
|
16 | + * Custom_Messages_Template_List_Table constructor. |
|
17 | + * |
|
18 | + * @param EE_Admin_Page $admin_page |
|
19 | + */ |
|
20 | + public function __construct($admin_page) |
|
21 | + { |
|
22 | + //Set parent defaults |
|
23 | + parent::__construct($admin_page); |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @return Messages_Admin_Page |
|
29 | + */ |
|
30 | + public function get_admin_page() |
|
31 | + { |
|
32 | + return $this->_admin_page; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Setup initial data. |
|
37 | + */ |
|
38 | + protected function _setup_data() |
|
39 | + { |
|
40 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | + $this->_per_page, |
|
42 | + $this->_view, |
|
43 | + false, |
|
44 | + false, |
|
45 | + false |
|
46 | + ); |
|
47 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
48 | + $this->_per_page, |
|
49 | + $this->_view, |
|
50 | + true, |
|
51 | + true, |
|
52 | + false |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Set initial properties |
|
59 | + */ |
|
60 | + protected function _set_properties() |
|
61 | + { |
|
62 | + $this->_wp_list_args = array( |
|
63 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
64 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
65 | + 'ajax' => true, //for now, |
|
66 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
67 | + ); |
|
68 | + |
|
69 | + $this->_columns = array( |
|
70 | + 'cb' => '<input type="checkbox" />', |
|
71 | + 'name' => esc_html__('Template Name', 'event_espresso'), |
|
72 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
73 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
74 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
75 | + 'events' => esc_html__('Events', 'event_espresso'), |
|
76 | + //count of events using this template. |
|
77 | + 'actions' => '' |
|
78 | + ); |
|
79 | + |
|
80 | + $this->_sortable_columns = array( |
|
81 | + 'messenger' => array('MTP_messenger' => true), |
|
82 | + ); |
|
83 | + |
|
84 | + $this->_hidden_columns = array(); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
90 | + * message_type or messenger object before generating the row. |
|
91 | + * |
|
92 | + * @param EE_Message_Template_Group $item |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function single_row($item) |
|
96 | + { |
|
97 | + $message_type = $item->message_type_obj(); |
|
98 | + $messenger = $item->messenger_obj(); |
|
99 | + |
|
100 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | + echo ''; |
|
102 | + return; |
|
103 | + } |
|
104 | + |
|
105 | + parent::single_row($item); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + protected function _get_table_filters() |
|
113 | + { |
|
114 | + $filters = array(); |
|
115 | + |
|
116 | + //get select inputs |
|
117 | + $select_inputs = array( |
|
118 | + $this->_get_messengers_dropdown_filter(), |
|
119 | + $this->_get_message_types_dropdown_filter(), |
|
120 | + ); |
|
121 | + |
|
122 | + //set filters to select inputs if they aren't empty |
|
123 | + foreach ($select_inputs as $select_input) { |
|
124 | + if ($select_input) { |
|
125 | + $filters[] = $select_input; |
|
126 | + } |
|
127 | + } |
|
128 | + return $filters; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * we're just removing the search box for message templates, not needed. |
|
133 | + * |
|
134 | + * @return string (empty); |
|
135 | + */ |
|
136 | + function search_box($text, $input_id) |
|
137 | + { |
|
138 | + return ''; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Set the view counts on the _views property |
|
144 | + */ |
|
145 | + protected function _add_view_counts() |
|
146 | + { |
|
147 | + foreach ($this->_views as $view => $args) { |
|
148 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
149 | + $this->_per_page, |
|
150 | + $view, |
|
151 | + true, |
|
152 | + true, |
|
153 | + false |
|
154 | + ); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Custom message for when there are no items found. |
|
161 | + * |
|
162 | + * @since 4.3.0 |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function no_items() |
|
166 | + { |
|
167 | + if ($this->_view !== 'trashed') { |
|
168 | + printf( |
|
169 | + esc_html__( |
|
170 | + '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
171 | + 'event_espresso' |
|
172 | + ), |
|
173 | + '<strong>', |
|
174 | + '</strong>' |
|
175 | + ); |
|
176 | + } else { |
|
177 | + parent::no_items(); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param EE_Message_Template_Group $item |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + public function column_cb($item) |
|
187 | + { |
|
188 | + return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID()); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @param EE_Message_Template_Group $item |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + function column_name($item) |
|
197 | + { |
|
198 | + return '<p>' . $item->name() . '</p>'; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param EE_Message_Template_Group $item |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + function column_description($item) |
|
207 | + { |
|
208 | + return '<p>' . $item->description() . '</p>'; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param EE_Message_Template_Group $item |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + function column_actions($item) |
|
217 | + { |
|
218 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
219 | + 'ee_edit_messages', |
|
220 | + 'espresso_messages_add_new_message_template' |
|
221 | + )) { |
|
222 | + $create_args = array( |
|
223 | + 'GRP_ID' => $item->ID(), |
|
224 | + 'messenger' => $item->messenger(), |
|
225 | + 'message_type' => $item->message_type(), |
|
226 | + 'action' => 'add_new_message_template', |
|
227 | + ); |
|
228 | + $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
229 | + return sprintf( |
|
230 | + '<p><a href="%s" class="button button-small">%s</a></p>', |
|
231 | + $create_link, |
|
232 | + esc_html__('Create Custom', 'event_espresso') |
|
233 | + ); |
|
234 | + } |
|
235 | + return ''; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Return the content for the messenger column |
|
241 | + * @param EE_Message_Template_Group $item |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + function column_messenger($item) |
|
245 | + { |
|
246 | + |
|
247 | + //Build row actions |
|
248 | + $actions = array(); |
|
249 | + $edit_lnk_url = ''; |
|
250 | + |
|
251 | + // edit link but only if item isn't trashed. |
|
252 | + if (! $item->get('MTP_deleted') |
|
253 | + && EE_Registry::instance()->CAP->current_user_can( |
|
254 | + 'ee_edit_message', |
|
255 | + 'espresso_messages_edit_message_template', |
|
256 | + $item->ID() |
|
257 | + ) |
|
258 | + ) { |
|
259 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | + 'action' => 'edit_message_template', |
|
261 | + 'id' => $item->GRP_ID(), |
|
262 | + ), EE_MSG_ADMIN_URL); |
|
263 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
265 | + . ' title="' |
|
266 | + . esc_attr__('Edit Template', 'event_espresso') |
|
267 | + . '">' |
|
268 | + . esc_html__('Edit', 'event_espresso') |
|
269 | + . '</a>'; |
|
270 | + } |
|
271 | + |
|
272 | + $name_link = ! $item->get('MTP_deleted') |
|
273 | + && EE_Registry::instance()->CAP->current_user_can( |
|
274 | + 'ee_edit_message', |
|
275 | + 'espresso_messages_edit_message_template', |
|
276 | + $item->ID() |
|
277 | + ) |
|
278 | + && $edit_lnk_url |
|
279 | + ? '<a href="' |
|
280 | + . $edit_lnk_url |
|
281 | + . '" title="' |
|
282 | + . esc_attr__('Edit Template', 'event_espresso') |
|
283 | + . '">' |
|
284 | + . ucwords($item->messenger_obj()->label['singular']) |
|
285 | + . '</a>' |
|
286 | + : ucwords($item->messenger_obj()->label['singular']); |
|
287 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
288 | + 'id' => $item->GRP_ID(), |
|
289 | + 'noheader' => true, |
|
290 | + ), EE_MSG_ADMIN_URL); |
|
291 | + // restore link |
|
292 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
293 | + 'id' => $item->GRP_ID(), |
|
294 | + 'noheader' => true, |
|
295 | + ), EE_MSG_ADMIN_URL); |
|
296 | + // delete price link |
|
297 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
298 | + 'id' => $item->GRP_ID(), |
|
299 | + 'noheader' => true, |
|
300 | + ), EE_MSG_ADMIN_URL); |
|
301 | + |
|
302 | + if (! $item->get('MTP_deleted') |
|
303 | + && EE_Registry::instance()->CAP->current_user_can( |
|
304 | + 'ee_delete_message', |
|
305 | + 'espresso_messages_trash_message_template', |
|
306 | + $item->ID() |
|
307 | + ) |
|
308 | + ) { |
|
309 | + $actions['trash'] = '<a href="' |
|
310 | + . $trash_lnk_url |
|
311 | + . '" title="' |
|
312 | + . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
313 | + . '">' |
|
314 | + . esc_html__('Move to Trash', 'event_espresso') |
|
315 | + . '</a>'; |
|
316 | + } else { |
|
317 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
318 | + 'ee_delete_message', |
|
319 | + 'espresso_messages_restore_message_template', |
|
320 | + $item->ID() |
|
321 | + )) { |
|
322 | + $actions['restore'] = '<a href="' |
|
323 | + . $restore_lnk_url |
|
324 | + . '" title="' |
|
325 | + . esc_attr__('Restore Message Template', 'event_espresso') |
|
326 | + . '">' |
|
327 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
328 | + } |
|
329 | + |
|
330 | + if ($this->_view == 'trashed' |
|
331 | + && EE_Registry::instance()->CAP->current_user_can( |
|
332 | + 'ee_delete_message', |
|
333 | + 'espresso_messages_delete_message_template', |
|
334 | + $item->ID() |
|
335 | + )) { |
|
336 | + $actions['delete'] = '<a href="' |
|
337 | + . $delete_lnk_url |
|
338 | + . '" title="' |
|
339 | + . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
340 | + . '">' |
|
341 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
342 | + . '</a>'; |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + //we want to display the contexts in here so we need to set them up |
|
347 | + $c_label = $item->context_label(); |
|
348 | + $c_configs = $item->contexts_config(); |
|
349 | + $ctxt = array(); |
|
350 | + $context_templates = $item->context_templates(); |
|
351 | + foreach ($context_templates as $context => $template_fields) { |
|
352 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
353 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
354 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
355 | + : null; |
|
356 | + $inactive = empty($mtp_to) && ! empty($context_templates[$context]['to']) |
|
357 | + ? ' class="mtp-inactive"' |
|
358 | + : ''; |
|
359 | + $context_title = ucwords($c_configs[$context]['label']); |
|
360 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
361 | + 'id' => $item->GRP_ID(), |
|
362 | + 'context' => $context, |
|
363 | + ), EE_MSG_ADMIN_URL); |
|
364 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | + 'ee_edit_message', |
|
366 | + 'espresso_messages_edit_message_template', |
|
367 | + $item->ID() |
|
368 | + ) |
|
369 | + ? '<a' |
|
370 | + . $inactive |
|
371 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | + . ' href="' . $edit_link . '"' |
|
373 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
374 | + . $context_title |
|
375 | + . '</a>' |
|
376 | + : $context_title; |
|
377 | + } |
|
378 | + |
|
379 | + $ctx_content = ! $item->get('MTP_deleted') |
|
380 | + && EE_Registry::instance()->CAP->current_user_can( |
|
381 | + 'ee_edit_message', |
|
382 | + 'espresso_messages_edit_message_template', |
|
383 | + $item->ID() |
|
384 | + ) |
|
385 | + ? sprintf( |
|
386 | + '<strong>%s:</strong> ', |
|
387 | + ucwords($c_label['plural']) |
|
388 | + ) |
|
389 | + . implode(' | ', $ctxt) |
|
390 | + : ''; |
|
391 | + |
|
392 | + |
|
393 | + //Return the name contents |
|
394 | + return sprintf( |
|
395 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
396 | + /* $1%s */ |
|
397 | + $name_link, |
|
398 | + /* $2%s */ |
|
399 | + $item->GRP_ID(), |
|
400 | + /* %4$s */ |
|
401 | + $ctx_content, |
|
402 | + /* $3%s */ |
|
403 | + $this->row_actions($actions) |
|
404 | + ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * column_events |
|
409 | + * This provides a count of events using this custom template |
|
410 | + * |
|
411 | + * @param EE_Message_Template_Group $item message_template group data |
|
412 | + * @return string column output |
|
413 | + */ |
|
414 | + function column_events($item) |
|
415 | + { |
|
416 | + return $item->count_events(); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * column_message_type |
|
421 | + * |
|
422 | + * @param EE_Message_Template_Group $item message info for the row |
|
423 | + * @return string message_type name |
|
424 | + */ |
|
425 | + function column_message_type($item) |
|
426 | + { |
|
427 | + return ucwords($item->message_type_obj()->label['singular']); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Generate dropdown filter select input for messengers |
|
433 | + * |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + protected function _get_messengers_dropdown_filter() |
|
437 | + { |
|
438 | + $messenger_options = array(); |
|
439 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
440 | + array( |
|
441 | + array( |
|
442 | + 'MTP_is_active' => true, |
|
443 | + 'MTP_is_global' => false, |
|
444 | + ), |
|
445 | + 'group_by' => 'MTP_messenger', |
|
446 | + ) |
|
447 | + ); |
|
448 | + |
|
449 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
450 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
451 | + $messenger = $active_message_template_group->messenger_obj(); |
|
452 | + $messenger_label = $messenger instanceof EE_messenger |
|
453 | + ? $messenger->label['singular'] |
|
454 | + : $active_message_template_group->messenger(); |
|
455 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
456 | + } |
|
457 | + } |
|
458 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * Generate dropdown filter select input for message types |
|
464 | + * |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + protected function _get_message_types_dropdown_filter() |
|
468 | + { |
|
469 | + $message_type_options = array(); |
|
470 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
471 | + array( |
|
472 | + array( |
|
473 | + 'MTP_is_active' => true, |
|
474 | + 'MTP_is_global' => false, |
|
475 | + ), |
|
476 | + 'group_by' => 'MTP_message_type', |
|
477 | + ) |
|
478 | + ); |
|
479 | + |
|
480 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
481 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
482 | + $message_type = $active_message_template_group->message_type_obj(); |
|
483 | + $message_type_label = $message_type instanceof EE_message_type |
|
484 | + ? $message_type->label['singular'] |
|
485 | + : $active_message_template_group->message_type(); |
|
486 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
487 | + } |
|
488 | + } |
|
489 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
490 | + } |
|
491 | 491 | |
492 | 492 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function _setup_data() |
39 | 39 | { |
40 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
40 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | 41 | $this->_per_page, |
42 | 42 | $this->_view, |
43 | 43 | false, |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $message_type = $item->message_type_obj(); |
98 | 98 | $messenger = $item->messenger_obj(); |
99 | 99 | |
100 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
100 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | 101 | echo ''; |
102 | 102 | return; |
103 | 103 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | function column_name($item) |
197 | 197 | { |
198 | - return '<p>' . $item->name() . '</p>'; |
|
198 | + return '<p>'.$item->name().'</p>'; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function column_description($item) |
207 | 207 | { |
208 | - return '<p>' . $item->description() . '</p>'; |
|
208 | + return '<p>'.$item->description().'</p>'; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -249,19 +249,19 @@ discard block |
||
249 | 249 | $edit_lnk_url = ''; |
250 | 250 | |
251 | 251 | // edit link but only if item isn't trashed. |
252 | - if (! $item->get('MTP_deleted') |
|
252 | + if ( ! $item->get('MTP_deleted') |
|
253 | 253 | && EE_Registry::instance()->CAP->current_user_can( |
254 | 254 | 'ee_edit_message', |
255 | 255 | 'espresso_messages_edit_message_template', |
256 | 256 | $item->ID() |
257 | 257 | ) |
258 | 258 | ) { |
259 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
259 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | 260 | 'action' => 'edit_message_template', |
261 | 261 | 'id' => $item->GRP_ID(), |
262 | 262 | ), EE_MSG_ADMIN_URL); |
263 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
263 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'"' |
|
264 | + . ' class="'.$item->message_type().'-edit-link"' |
|
265 | 265 | . ' title="' |
266 | 266 | . esc_attr__('Edit Template', 'event_espresso') |
267 | 267 | . '">' |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | . '</a>'; |
270 | 270 | } |
271 | 271 | |
272 | - $name_link = ! $item->get('MTP_deleted') |
|
272 | + $name_link = ! $item->get('MTP_deleted') |
|
273 | 273 | && EE_Registry::instance()->CAP->current_user_can( |
274 | 274 | 'ee_edit_message', |
275 | 275 | 'espresso_messages_edit_message_template', |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | 'noheader' => true, |
300 | 300 | ), EE_MSG_ADMIN_URL); |
301 | 301 | |
302 | - if (! $item->get('MTP_deleted') |
|
302 | + if ( ! $item->get('MTP_deleted') |
|
303 | 303 | && EE_Registry::instance()->CAP->current_user_can( |
304 | 304 | 'ee_delete_message', |
305 | 305 | 'espresso_messages_trash_message_template', |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | . '" title="' |
325 | 325 | . esc_attr__('Restore Message Template', 'event_espresso') |
326 | 326 | . '">' |
327 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
327 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | if ($this->_view == 'trashed' |
@@ -361,16 +361,16 @@ discard block |
||
361 | 361 | 'id' => $item->GRP_ID(), |
362 | 362 | 'context' => $context, |
363 | 363 | ), EE_MSG_ADMIN_URL); |
364 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
364 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | 365 | 'ee_edit_message', |
366 | 366 | 'espresso_messages_edit_message_template', |
367 | 367 | $item->ID() |
368 | 368 | ) |
369 | 369 | ? '<a' |
370 | 370 | . $inactive |
371 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | - . ' href="' . $edit_link . '"' |
|
373 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
371 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link"' |
|
372 | + . ' href="'.$edit_link.'"' |
|
373 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
374 | 374 | . $context_title |
375 | 375 | . '</a>' |
376 | 376 | : $context_title; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -32,224 +32,224 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * This is used to hold the reports template data which is setup early in the request. |
|
37 | - * @type array |
|
38 | - */ |
|
39 | - protected $_reports_template_data = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * @Constructor |
|
43 | - * @access public |
|
44 | - * |
|
45 | - * @param bool $routing |
|
46 | - * |
|
47 | - * @return \Extend_Transactions_Admin_Page |
|
48 | - */ |
|
49 | - public function __construct($routing = true) |
|
50 | - { |
|
51 | - parent::__construct($routing); |
|
52 | - define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
53 | - define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
54 | - define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * _extend_page_config |
|
60 | - * |
|
61 | - * @access protected |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - protected function _extend_page_config() |
|
65 | - { |
|
66 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
67 | - |
|
68 | - $new_page_routes = array( |
|
69 | - 'reports' => array( |
|
70 | - 'func' => '_transaction_reports', |
|
71 | - 'capability' => 'ee_read_transactions' |
|
72 | - ) |
|
73 | - ); |
|
74 | - |
|
75 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
76 | - |
|
77 | - $new_page_config = array( |
|
78 | - 'reports' => array( |
|
79 | - 'nav' => array( |
|
80 | - 'label' => __('Reports', 'event_espresso'), |
|
81 | - 'order' => 20 |
|
82 | - ), |
|
83 | - 'help_tabs' => array( |
|
84 | - 'transactions_reports_help_tab' => array( |
|
85 | - 'title' => __('Transaction Reports', 'event_espresso'), |
|
86 | - 'filename' => 'transactions_reports' |
|
87 | - ) |
|
88 | - ), |
|
89 | - /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/ |
|
90 | - 'require_nonce' => false |
|
91 | - ) |
|
92 | - ); |
|
93 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * load_scripts_styles_reports |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public function load_scripts_styles_reports() |
|
104 | - { |
|
105 | - wp_register_script( |
|
106 | - 'ee-txn-reports-js', |
|
107 | - TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
108 | - array('google-charts'), |
|
109 | - EVENT_ESPRESSO_VERSION, |
|
110 | - true |
|
111 | - ); |
|
112 | - wp_enqueue_script('ee-txn-reports-js'); |
|
113 | - $this->_transaction_reports_js_setup(); |
|
114 | - EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
120 | - * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method. |
|
121 | - */ |
|
122 | - protected function _transaction_reports_js_setup() |
|
123 | - { |
|
124 | - $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report(); |
|
125 | - $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * _transaction_reports |
|
131 | - * generates Business Reports regarding Transactions |
|
132 | - * |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function _transaction_reports() |
|
136 | - { |
|
137 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
138 | - $this->_admin_page_title = __('Transactions', 'event_espresso'); |
|
139 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
140 | - $this->_reports_template_data, true); |
|
141 | - |
|
142 | - // the final template wrapper |
|
143 | - $this->display_admin_page_with_no_sidebar(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * _revenue_per_day_report |
|
149 | - * generates Business Report showing Total Revenue per Day. |
|
150 | - * |
|
151 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
152 | - * |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - private function _revenue_per_day_report($period = '-1 month') |
|
156 | - { |
|
157 | - |
|
158 | - $report_ID = 'txn-admin-revenue-per-day-report-dv'; |
|
159 | - |
|
160 | - $TXN = EEM_Transaction::instance(); |
|
161 | - |
|
162 | - $results = $TXN->get_revenue_per_day_report($period); |
|
163 | - $results = (array)$results; |
|
164 | - $revenue = array(); |
|
165 | - $subtitle = ''; |
|
166 | - |
|
167 | - if ($results) { |
|
168 | - $revenue[] = array( |
|
169 | - __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'), |
|
170 | - __('Total Revenue', 'event_espresso') |
|
171 | - ); |
|
172 | - foreach ($results as $result) { |
|
173 | - $revenue[] = array($result->txnDate, (float)$result->revenue); |
|
174 | - } |
|
175 | - |
|
176 | - //setup the date range. |
|
177 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
178 | - $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
179 | - $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
180 | - $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
181 | - } |
|
182 | - |
|
183 | - $report_title = esc_html__('Total Revenue per Day', 'event_espresso'); |
|
184 | - |
|
185 | - $report_params = array( |
|
186 | - 'title' => $report_title, |
|
187 | - 'subtitle' => $subtitle, |
|
188 | - 'id' => $report_ID, |
|
189 | - 'revenue' => $revenue, |
|
190 | - 'noResults' => empty($revenue) || count($revenue) === 1, |
|
191 | - 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
192 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
193 | - ); |
|
194 | - wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
|
195 | - |
|
196 | - return $report_ID; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * _revenue_per_event_report |
|
202 | - * generates Business Report showing total revenue per event. |
|
203 | - * |
|
204 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
205 | - * |
|
206 | - * @return int |
|
207 | - */ |
|
208 | - private function _revenue_per_event_report($period = '-1 month') |
|
209 | - { |
|
210 | - |
|
211 | - $report_ID = 'txn-admin-revenue-per-event-report-dv'; |
|
212 | - |
|
213 | - $TXN = EEM_Transaction::instance(); |
|
214 | - $results = $TXN->get_revenue_per_event_report($period); |
|
215 | - $results = (array)$results; |
|
216 | - $revenue = array(); |
|
217 | - $subtitle = ''; |
|
218 | - |
|
219 | - if ($results) { |
|
220 | - $revenue[] = array( |
|
221 | - __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'), |
|
222 | - __('Total Revenue', 'event_espresso') |
|
223 | - ); |
|
224 | - foreach ($results as $result) { |
|
225 | - if ($result->revenue > 1) { |
|
226 | - $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
|
227 | - $event_name = wp_trim_words($event_name, 5, '...'); |
|
228 | - $revenue[] = array($event_name, (float)$result->revenue); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - //setup the date range. |
|
233 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
234 | - $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
235 | - $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
236 | - $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
237 | - } |
|
238 | - |
|
239 | - $report_title = esc_html__('Total Revenue per Event', 'event_espresso'); |
|
240 | - |
|
241 | - $report_params = array( |
|
242 | - 'title' => $report_title, |
|
243 | - 'subtitle' => $subtitle, |
|
244 | - 'id' => $report_ID, |
|
245 | - 'revenue' => $revenue, |
|
246 | - 'noResults' => empty($revenue), |
|
247 | - 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
248 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
249 | - ); |
|
250 | - wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
|
251 | - |
|
252 | - return $report_ID; |
|
253 | - } |
|
35 | + /** |
|
36 | + * This is used to hold the reports template data which is setup early in the request. |
|
37 | + * @type array |
|
38 | + */ |
|
39 | + protected $_reports_template_data = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * @Constructor |
|
43 | + * @access public |
|
44 | + * |
|
45 | + * @param bool $routing |
|
46 | + * |
|
47 | + * @return \Extend_Transactions_Admin_Page |
|
48 | + */ |
|
49 | + public function __construct($routing = true) |
|
50 | + { |
|
51 | + parent::__construct($routing); |
|
52 | + define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
53 | + define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
54 | + define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * _extend_page_config |
|
60 | + * |
|
61 | + * @access protected |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + protected function _extend_page_config() |
|
65 | + { |
|
66 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
67 | + |
|
68 | + $new_page_routes = array( |
|
69 | + 'reports' => array( |
|
70 | + 'func' => '_transaction_reports', |
|
71 | + 'capability' => 'ee_read_transactions' |
|
72 | + ) |
|
73 | + ); |
|
74 | + |
|
75 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
76 | + |
|
77 | + $new_page_config = array( |
|
78 | + 'reports' => array( |
|
79 | + 'nav' => array( |
|
80 | + 'label' => __('Reports', 'event_espresso'), |
|
81 | + 'order' => 20 |
|
82 | + ), |
|
83 | + 'help_tabs' => array( |
|
84 | + 'transactions_reports_help_tab' => array( |
|
85 | + 'title' => __('Transaction Reports', 'event_espresso'), |
|
86 | + 'filename' => 'transactions_reports' |
|
87 | + ) |
|
88 | + ), |
|
89 | + /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/ |
|
90 | + 'require_nonce' => false |
|
91 | + ) |
|
92 | + ); |
|
93 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * load_scripts_styles_reports |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public function load_scripts_styles_reports() |
|
104 | + { |
|
105 | + wp_register_script( |
|
106 | + 'ee-txn-reports-js', |
|
107 | + TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
108 | + array('google-charts'), |
|
109 | + EVENT_ESPRESSO_VERSION, |
|
110 | + true |
|
111 | + ); |
|
112 | + wp_enqueue_script('ee-txn-reports-js'); |
|
113 | + $this->_transaction_reports_js_setup(); |
|
114 | + EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
120 | + * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method. |
|
121 | + */ |
|
122 | + protected function _transaction_reports_js_setup() |
|
123 | + { |
|
124 | + $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report(); |
|
125 | + $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * _transaction_reports |
|
131 | + * generates Business Reports regarding Transactions |
|
132 | + * |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function _transaction_reports() |
|
136 | + { |
|
137 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
138 | + $this->_admin_page_title = __('Transactions', 'event_espresso'); |
|
139 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
140 | + $this->_reports_template_data, true); |
|
141 | + |
|
142 | + // the final template wrapper |
|
143 | + $this->display_admin_page_with_no_sidebar(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * _revenue_per_day_report |
|
149 | + * generates Business Report showing Total Revenue per Day. |
|
150 | + * |
|
151 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
152 | + * |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + private function _revenue_per_day_report($period = '-1 month') |
|
156 | + { |
|
157 | + |
|
158 | + $report_ID = 'txn-admin-revenue-per-day-report-dv'; |
|
159 | + |
|
160 | + $TXN = EEM_Transaction::instance(); |
|
161 | + |
|
162 | + $results = $TXN->get_revenue_per_day_report($period); |
|
163 | + $results = (array)$results; |
|
164 | + $revenue = array(); |
|
165 | + $subtitle = ''; |
|
166 | + |
|
167 | + if ($results) { |
|
168 | + $revenue[] = array( |
|
169 | + __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'), |
|
170 | + __('Total Revenue', 'event_espresso') |
|
171 | + ); |
|
172 | + foreach ($results as $result) { |
|
173 | + $revenue[] = array($result->txnDate, (float)$result->revenue); |
|
174 | + } |
|
175 | + |
|
176 | + //setup the date range. |
|
177 | + $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
178 | + $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
179 | + $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
180 | + $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
181 | + } |
|
182 | + |
|
183 | + $report_title = esc_html__('Total Revenue per Day', 'event_espresso'); |
|
184 | + |
|
185 | + $report_params = array( |
|
186 | + 'title' => $report_title, |
|
187 | + 'subtitle' => $subtitle, |
|
188 | + 'id' => $report_ID, |
|
189 | + 'revenue' => $revenue, |
|
190 | + 'noResults' => empty($revenue) || count($revenue) === 1, |
|
191 | + 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
192 | + '<h2>' . $report_title . '</h2><p>', '</p>') |
|
193 | + ); |
|
194 | + wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
|
195 | + |
|
196 | + return $report_ID; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * _revenue_per_event_report |
|
202 | + * generates Business Report showing total revenue per event. |
|
203 | + * |
|
204 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
205 | + * |
|
206 | + * @return int |
|
207 | + */ |
|
208 | + private function _revenue_per_event_report($period = '-1 month') |
|
209 | + { |
|
210 | + |
|
211 | + $report_ID = 'txn-admin-revenue-per-event-report-dv'; |
|
212 | + |
|
213 | + $TXN = EEM_Transaction::instance(); |
|
214 | + $results = $TXN->get_revenue_per_event_report($period); |
|
215 | + $results = (array)$results; |
|
216 | + $revenue = array(); |
|
217 | + $subtitle = ''; |
|
218 | + |
|
219 | + if ($results) { |
|
220 | + $revenue[] = array( |
|
221 | + __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'), |
|
222 | + __('Total Revenue', 'event_espresso') |
|
223 | + ); |
|
224 | + foreach ($results as $result) { |
|
225 | + if ($result->revenue > 1) { |
|
226 | + $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
|
227 | + $event_name = wp_trim_words($event_name, 5, '...'); |
|
228 | + $revenue[] = array($event_name, (float)$result->revenue); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + //setup the date range. |
|
233 | + $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
234 | + $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
235 | + $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
236 | + $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
237 | + } |
|
238 | + |
|
239 | + $report_title = esc_html__('Total Revenue per Event', 'event_espresso'); |
|
240 | + |
|
241 | + $report_params = array( |
|
242 | + 'title' => $report_title, |
|
243 | + 'subtitle' => $subtitle, |
|
244 | + 'id' => $report_ID, |
|
245 | + 'revenue' => $revenue, |
|
246 | + 'noResults' => empty($revenue), |
|
247 | + 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
248 | + '<h2>' . $report_title . '</h2><p>', '</p>') |
|
249 | + ); |
|
250 | + wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
|
251 | + |
|
252 | + return $report_ID; |
|
253 | + } |
|
254 | 254 | |
255 | 255 | } |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | public function __construct($routing = true) |
50 | 50 | { |
51 | 51 | parent::__construct($routing); |
52 | - define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
53 | - define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
54 | - define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
52 | + define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/'); |
|
53 | + define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/'); |
|
54 | + define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function _extend_page_config() |
65 | 65 | { |
66 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
66 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions'; |
|
67 | 67 | |
68 | 68 | $new_page_routes = array( |
69 | 69 | 'reports' => array( |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | wp_register_script( |
106 | 106 | 'ee-txn-reports-js', |
107 | - TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
107 | + TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js', |
|
108 | 108 | array('google-charts'), |
109 | 109 | EVENT_ESPRESSO_VERSION, |
110 | 110 | true |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function _transaction_reports() |
136 | 136 | { |
137 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
137 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
138 | 138 | $this->_admin_page_title = __('Transactions', 'event_espresso'); |
139 | 139 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
140 | 140 | $this->_reports_template_data, true); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $TXN = EEM_Transaction::instance(); |
161 | 161 | |
162 | 162 | $results = $TXN->get_revenue_per_day_report($period); |
163 | - $results = (array)$results; |
|
163 | + $results = (array) $results; |
|
164 | 164 | $revenue = array(); |
165 | 165 | $subtitle = ''; |
166 | 166 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | __('Total Revenue', 'event_espresso') |
171 | 171 | ); |
172 | 172 | foreach ($results as $result) { |
173 | - $revenue[] = array($result->txnDate, (float)$result->revenue); |
|
173 | + $revenue[] = array($result->txnDate, (float) $result->revenue); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | //setup the date range. |
177 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
177 | + $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
178 | 178 | $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
179 | 179 | $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
180 | 180 | $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'revenue' => $revenue, |
190 | 190 | 'noResults' => empty($revenue) || count($revenue) === 1, |
191 | 191 | 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
192 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
192 | + '<h2>'.$report_title.'</h2><p>', '</p>') |
|
193 | 193 | ); |
194 | 194 | wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
195 | 195 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $TXN = EEM_Transaction::instance(); |
214 | 214 | $results = $TXN->get_revenue_per_event_report($period); |
215 | - $results = (array)$results; |
|
215 | + $results = (array) $results; |
|
216 | 216 | $revenue = array(); |
217 | 217 | $subtitle = ''; |
218 | 218 | |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | if ($result->revenue > 1) { |
226 | 226 | $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
227 | 227 | $event_name = wp_trim_words($event_name, 5, '...'); |
228 | - $revenue[] = array($event_name, (float)$result->revenue); |
|
228 | + $revenue[] = array($event_name, (float) $result->revenue); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | //setup the date range. |
233 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
233 | + $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
234 | 234 | $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
235 | 235 | $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
236 | 236 | $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | 'revenue' => $revenue, |
246 | 246 | 'noResults' => empty($revenue), |
247 | 247 | 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
248 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
248 | + '<h2>'.$report_title.'</h2><p>', '</p>') |
|
249 | 249 | ); |
250 | 250 | wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
251 | 251 |