@@ -19,511 +19,511 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @return Messages_Admin_Page |
|
24 | - */ |
|
25 | - public function get_admin_page() |
|
26 | - { |
|
27 | - return $this->_admin_page; |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @throws EE_Error |
|
33 | - * @throws InvalidArgumentException |
|
34 | - * @throws InvalidDataTypeException |
|
35 | - * @throws InvalidInterfaceException |
|
36 | - */ |
|
37 | - protected function _setup_data() |
|
38 | - { |
|
39 | - $this->_data = $this->_get_messages($this->_per_page, $this->_view); |
|
40 | - $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _set_properties() |
|
45 | - { |
|
46 | - $this->_wp_list_args = array( |
|
47 | - 'singular' => esc_html__('Message', 'event_espresso'), |
|
48 | - 'plural' => esc_html__('Messages', 'event_espresso'), |
|
49 | - 'ajax' => true, |
|
50 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
51 | - ); |
|
52 | - |
|
53 | - $this->_columns = array( |
|
54 | - 'cb' => '<input type="checkbox" />', |
|
55 | - 'to' => esc_html__('To', 'event_espresso'), |
|
56 | - 'from' => esc_html__('From', 'event_espresso'), |
|
57 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
58 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
59 | - 'context' => esc_html__('Context', 'event_espresso'), |
|
60 | - 'modified' => esc_html__('Modified', 'event_espresso'), |
|
61 | - 'action' => esc_html__('Actions', 'event_espresso'), |
|
62 | - 'msg_id' => esc_html__('ID', 'event_espresso'), |
|
63 | - ); |
|
64 | - |
|
65 | - $this->_sortable_columns = array( |
|
66 | - 'modified' => array('MSG_modified' => true), |
|
67 | - 'message_type' => array('MSG_message_type' => false), |
|
68 | - 'messenger' => array('MSG_messenger' => false), |
|
69 | - 'to' => array('MSG_to' => false), |
|
70 | - 'from' => array('MSG_from' => false), |
|
71 | - 'context' => array('MSG_context' => false), |
|
72 | - 'msg_id' => array('MSG_ID', false), |
|
73 | - ); |
|
74 | - |
|
75 | - $this->_primary_column = 'to'; |
|
76 | - |
|
77 | - $this->_hidden_columns = array( |
|
78 | - 'msg_id', |
|
79 | - ); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * This simply sets up the row class for the table rows. |
|
85 | - * Allows for easier overriding of child methods for setting up sorting. |
|
86 | - * |
|
87 | - * @param EE_Message $item the current item |
|
88 | - * @return string |
|
89 | - * @throws EE_Error |
|
90 | - */ |
|
91 | - protected function _get_row_class($item) |
|
92 | - { |
|
93 | - $class = parent::_get_row_class($item); |
|
94 | - //add status class |
|
95 | - $class .= ' ee-status-strip msg-status-' . $item->STS_ID(); |
|
96 | - if ($this->_has_checkbox_column) { |
|
97 | - $class .= ' has-checkbox-column'; |
|
98 | - } |
|
99 | - return $class; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * _get_table_filters |
|
105 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
106 | - * get's shown in the table. |
|
107 | - * |
|
108 | - * @abstract |
|
109 | - * @access protected |
|
110 | - * @return array |
|
111 | - * @throws EE_Error |
|
112 | - * @throws InvalidArgumentException |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - */ |
|
116 | - protected function _get_table_filters() |
|
117 | - { |
|
118 | - $filters = array(); |
|
119 | - |
|
120 | - //get select_inputs |
|
121 | - $select_inputs = array( |
|
122 | - $this->_get_messengers_dropdown_filter(), |
|
123 | - $this->_get_message_types_dropdown_filter(), |
|
124 | - $this->_get_contexts_for_message_types_dropdown_filter(), |
|
125 | - ); |
|
126 | - |
|
127 | - //set filters to select inputs if they aren't empty |
|
128 | - foreach ($select_inputs as $select_input) { |
|
129 | - if ($select_input) { |
|
130 | - $filters[] = $select_input; |
|
131 | - } |
|
132 | - } |
|
133 | - return $filters; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @throws EE_Error |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - protected function _add_view_counts() |
|
144 | - { |
|
145 | - foreach ($this->_views as $view => $args) { |
|
146 | - $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param EE_Message $message |
|
153 | - * @return string checkbox |
|
154 | - * @throws EE_Error |
|
155 | - */ |
|
156 | - public function column_cb($message) |
|
157 | - { |
|
158 | - return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID()); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param EE_Message $message |
|
164 | - * @return string |
|
165 | - * @throws EE_Error |
|
166 | - */ |
|
167 | - public function column_msg_id(EE_Message $message) |
|
168 | - { |
|
169 | - return $message->ID(); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param EE_Message $message |
|
175 | - * @return string The recipient of the message |
|
176 | - * @throws EE_Error |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws ReflectionException |
|
179 | - * @throws InvalidDataTypeException |
|
180 | - * @throws InvalidInterfaceException |
|
181 | - */ |
|
182 | - public function column_to(EE_Message $message) |
|
183 | - { |
|
184 | - EE_Registry::instance()->load_helper('URL'); |
|
185 | - $actions = array(); |
|
186 | - $actions['delete'] = '<a href="' |
|
187 | - . EEH_URL::add_query_args_and_nonce( |
|
188 | - array( |
|
189 | - 'page' => 'espresso_messages', |
|
190 | - 'action' => 'delete_ee_message', |
|
191 | - 'MSG_ID' => $message->ID(), |
|
192 | - ), |
|
193 | - admin_url('admin.php') |
|
194 | - ) |
|
195 | - . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
196 | - $recipient_object = $message->recipient_object(); |
|
197 | - if ($recipient_object instanceof CapabilitiesActionRestrictionInterface |
|
198 | - && $recipient_object->canRead( |
|
199 | - new Context( |
|
200 | - 'view_link_from_message_list_table', |
|
201 | - esc_html__( |
|
202 | - 'View link for recipient displayed in the "To" column in the message list table.', |
|
203 | - 'event_espresso' |
|
204 | - ) |
|
205 | - ) |
|
206 | - ) |
|
207 | - ) { |
|
208 | - $view_details_link = $recipient_object instanceof EEI_Admin_Links |
|
209 | - ? $recipient_object->get_admin_details_link() |
|
210 | - : ''; |
|
211 | - if (! empty($view_details_link)) { |
|
212 | - $actions['view'] = '<a href="' . $view_details_link . '">' |
|
213 | - . esc_html__( |
|
214 | - 'View Recipient Details', |
|
215 | - 'event_espresso' |
|
216 | - ) |
|
217 | - . '</a>'; |
|
218 | - } |
|
219 | - } |
|
220 | - return esc_html($message->to()) . $this->row_actions($actions); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @param EE_Message $message |
|
226 | - * @return string The sender of the message |
|
227 | - * @throws EE_Error |
|
228 | - */ |
|
229 | - public function column_from(EE_Message $message) |
|
230 | - { |
|
231 | - return esc_html($message->from()); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param EE_Message $message |
|
237 | - * @return string The messenger used to send the message. |
|
238 | - * @throws EE_Error |
|
239 | - */ |
|
240 | - public function column_messenger(EE_Message $message) |
|
241 | - { |
|
242 | - return ucwords($message->messenger_label()); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param EE_Message $message |
|
248 | - * @return string The message type used to generate the message. |
|
249 | - * @throws EE_Error |
|
250 | - */ |
|
251 | - public function column_message_type(EE_Message $message) |
|
252 | - { |
|
253 | - return ucwords($message->message_type_label()); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param EE_Message $message |
|
259 | - * @return string The context the message was generated for. |
|
260 | - * @throws EE_Error |
|
261 | - * @throws InvalidArgumentException |
|
262 | - * @throws InvalidDataTypeException |
|
263 | - * @throws InvalidInterfaceException |
|
264 | - * @throws ReflectionException |
|
265 | - */ |
|
266 | - public function column_context(EE_Message $message) |
|
267 | - { |
|
268 | - return $message->context_label(); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @param EE_Message $message |
|
274 | - * @return string The timestamp when this message was last modified. |
|
275 | - * @throws EE_Error |
|
276 | - */ |
|
277 | - public function column_modified(EE_Message $message) |
|
278 | - { |
|
279 | - return $message->modified(); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param EE_Message $message |
|
285 | - * @return string Actions that can be done on the current message. |
|
286 | - * @throws EE_Error |
|
287 | - * @throws InvalidArgumentException |
|
288 | - * @throws InvalidDataTypeException |
|
289 | - * @throws InvalidInterfaceException |
|
290 | - * @throws ReflectionException |
|
291 | - */ |
|
292 | - public function column_action(EE_Message $message) |
|
293 | - { |
|
294 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
295 | - $action_links = array( |
|
296 | - 'view' => EEH_MSG_Template::get_message_action_link('view', $message), |
|
297 | - 'error' => EEH_MSG_Template::get_message_action_link('error', $message), |
|
298 | - 'generate_now' => EEH_MSG_Template::get_message_action_link('generate_now', $message), |
|
299 | - 'send_now' => EEH_MSG_Template::get_message_action_link('send_now', $message), |
|
300 | - 'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message), |
|
301 | - 'view_transaction' => EEH_MSG_Template::get_message_action_link('view_transaction', $message), |
|
302 | - ); |
|
303 | - $content = ''; |
|
304 | - switch ($message->STS_ID()) { |
|
305 | - case EEM_Message::status_sent: |
|
306 | - $content = $action_links['view'] |
|
307 | - . $action_links['queue_for_resending'] |
|
308 | - . $action_links['view_transaction']; |
|
309 | - break; |
|
310 | - case EEM_Message::status_resend: |
|
311 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
312 | - break; |
|
313 | - case EEM_Message::status_retry: |
|
314 | - $content = $action_links['view'] |
|
315 | - . $action_links['send_now'] |
|
316 | - . $action_links['error'] |
|
317 | - . $action_links['view_transaction']; |
|
318 | - break; |
|
319 | - case EEM_Message::status_failed: |
|
320 | - case EEM_Message::status_debug_only: |
|
321 | - $content = $action_links['error'] . $action_links['view_transaction']; |
|
322 | - break; |
|
323 | - case EEM_Message::status_idle: |
|
324 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
325 | - break; |
|
326 | - case EEM_Message::status_incomplete: |
|
327 | - $content = $action_links['generate_now'] . $action_links['view_transaction']; |
|
328 | - break; |
|
329 | - } |
|
330 | - return $content; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Retrieve the EE_Message objects for the list table. |
|
336 | - * |
|
337 | - * @param int $perpage The number of items per page |
|
338 | - * @param string $view The view items are being retrieved for |
|
339 | - * @param bool $count Whether to just return a count or not. |
|
340 | - * @param bool $all Disregard any paging info (no limit on data returned). |
|
341 | - * @return EE_Message[]|int |
|
342 | - * @throws EE_Error |
|
343 | - * @throws InvalidArgumentException |
|
344 | - * @throws InvalidDataTypeException |
|
345 | - * @throws InvalidInterfaceException |
|
346 | - */ |
|
347 | - protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false) |
|
348 | - { |
|
349 | - |
|
350 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
351 | - ? $this->_req_data['paged'] |
|
352 | - : 1; |
|
353 | - |
|
354 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
355 | - ? $this->_req_data['perpage'] |
|
356 | - : $perpage; |
|
357 | - |
|
358 | - $offset = ($current_page - 1) * $per_page; |
|
359 | - $limit = $all || $count ? null : array($offset, $per_page); |
|
360 | - $query_params = array( |
|
361 | - 'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'], |
|
362 | - 'order' => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'], |
|
363 | - 'limit' => $limit, |
|
364 | - ); |
|
365 | - |
|
366 | - /** |
|
367 | - * Any filters coming in from other routes? |
|
368 | - */ |
|
369 | - if (isset($this->_req_data['filterby'])) { |
|
370 | - $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); |
|
371 | - if (! $count) { |
|
372 | - $query_params['group_by'] = 'MSG_ID'; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - //view conditionals |
|
377 | - if ($view !== 'all' && $count && $all) { |
|
378 | - $query_params[0]['AND*view_conditional'] = array( |
|
379 | - 'STS_ID' => strtoupper($view), |
|
380 | - ); |
|
381 | - } |
|
382 | - |
|
383 | - if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
384 | - $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed |
|
385 | - ? array( |
|
386 | - 'STS_ID' => array( |
|
387 | - 'IN', |
|
388 | - array(EEM_Message::status_failed, EEM_Message::status_messenger_executing), |
|
389 | - ), |
|
390 | - ) |
|
391 | - : array('STS_ID' => strtoupper($this->_req_data['status'])); |
|
392 | - } |
|
393 | - |
|
394 | - if (! $all && ! empty($this->_req_data['s'])) { |
|
395 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
396 | - $query_params[0]['OR'] = array( |
|
397 | - 'MSG_to' => array('LIKE', $search_string), |
|
398 | - 'MSG_from' => array('LIKE', $search_string), |
|
399 | - 'MSG_subject' => array('LIKE', $search_string), |
|
400 | - 'MSG_content' => array('LIKE', $search_string), |
|
401 | - ); |
|
402 | - } |
|
403 | - |
|
404 | - //account for debug only status. We don't show Messages with the EEM_Message::status_debug_only to clients when |
|
405 | - //the messages system is in debug mode. |
|
406 | - //Note: for backward compat with previous iterations, this is necessary because there may be |
|
407 | - // EEM_Message::status_debug_only |
|
408 | - //messages in the database. |
|
409 | - if (! EEM_Message::debug()) { |
|
410 | - $query_params[0]['AND*debug_only_conditional'] = array( |
|
411 | - 'STS_ID' => array('!=', EEM_Message::status_debug_only), |
|
412 | - ); |
|
413 | - } |
|
414 | - |
|
415 | - //account for filters |
|
416 | - if (! $all |
|
417 | - && isset($this->_req_data['ee_messenger_filter_by']) |
|
418 | - && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected' |
|
419 | - ) { |
|
420 | - $query_params[0]['AND*messenger_filter'] = array( |
|
421 | - 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'], |
|
422 | - ); |
|
423 | - } |
|
424 | - if (! $all |
|
425 | - && ! empty($this->_req_data['ee_message_type_filter_by']) |
|
426 | - && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected' |
|
427 | - ) { |
|
428 | - $query_params[0]['AND*message_type_filter'] = array( |
|
429 | - 'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'], |
|
430 | - ); |
|
431 | - } |
|
432 | - |
|
433 | - if (! $all |
|
434 | - && ! empty($this->_req_data['ee_context_filter_by']) |
|
435 | - && $this->_req_data['ee_context_filter_by'] !== 'none_selected' |
|
436 | - ) { |
|
437 | - $query_params[0]['AND*context_filter'] = array( |
|
438 | - 'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])), |
|
439 | - ); |
|
440 | - } |
|
441 | - |
|
442 | - return $count |
|
443 | - /** @type int */ |
|
444 | - ? EEM_Message::instance()->count($query_params, null, true) |
|
445 | - /** @type EE_Message[] */ |
|
446 | - : EEM_Message::instance()->get_all($query_params); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Generate dropdown filter select input for messengers. |
|
452 | - * |
|
453 | - * @return string |
|
454 | - * @throws EE_Error |
|
455 | - * @throws InvalidArgumentException |
|
456 | - * @throws InvalidDataTypeException |
|
457 | - * @throws InvalidInterfaceException |
|
458 | - */ |
|
459 | - protected function _get_messengers_dropdown_filter() |
|
460 | - { |
|
461 | - $messenger_options = array(); |
|
462 | - $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
463 | - |
|
464 | - //setup array of messenger options |
|
465 | - foreach ($active_messages_grouped_by_messenger as $active_message) { |
|
466 | - if ($active_message instanceof EE_Message) { |
|
467 | - $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label()); |
|
468 | - } |
|
469 | - } |
|
470 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Generate dropdown filter select input for message types |
|
476 | - * |
|
477 | - * @return string |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidArgumentException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws InvalidInterfaceException |
|
482 | - */ |
|
483 | - protected function _get_message_types_dropdown_filter() |
|
484 | - { |
|
485 | - $message_type_options = array(); |
|
486 | - $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all( |
|
487 | - array('group_by' => 'MSG_message_type') |
|
488 | - ); |
|
489 | - |
|
490 | - //setup array of message type options |
|
491 | - foreach ($active_messages_grouped_by_message_type as $active_message) { |
|
492 | - if ($active_message instanceof EE_Message) { |
|
493 | - $message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label()); |
|
494 | - } |
|
495 | - } |
|
496 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * Generate dropdown filter select input for message type contexts |
|
502 | - * |
|
503 | - * @return string |
|
504 | - * @throws EE_Error |
|
505 | - * @throws InvalidArgumentException |
|
506 | - * @throws InvalidDataTypeException |
|
507 | - * @throws InvalidInterfaceException |
|
508 | - */ |
|
509 | - protected function _get_contexts_for_message_types_dropdown_filter() |
|
510 | - { |
|
511 | - $context_options = array(); |
|
512 | - $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
513 | - |
|
514 | - //setup array of context options |
|
515 | - foreach ($active_messages_grouped_by_context as $active_message) { |
|
516 | - if ($active_message instanceof EE_Message) { |
|
517 | - $message_type = $active_message->message_type_object(); |
|
518 | - if ($message_type instanceof EE_message_type) { |
|
519 | - foreach ($message_type->get_contexts() as $context => $context_details) { |
|
520 | - if (isset($context_details['label'])) { |
|
521 | - $context_options[$context] = $context_details['label']; |
|
522 | - } |
|
523 | - } |
|
524 | - } |
|
525 | - } |
|
526 | - } |
|
527 | - return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options); |
|
528 | - } |
|
22 | + /** |
|
23 | + * @return Messages_Admin_Page |
|
24 | + */ |
|
25 | + public function get_admin_page() |
|
26 | + { |
|
27 | + return $this->_admin_page; |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @throws EE_Error |
|
33 | + * @throws InvalidArgumentException |
|
34 | + * @throws InvalidDataTypeException |
|
35 | + * @throws InvalidInterfaceException |
|
36 | + */ |
|
37 | + protected function _setup_data() |
|
38 | + { |
|
39 | + $this->_data = $this->_get_messages($this->_per_page, $this->_view); |
|
40 | + $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _set_properties() |
|
45 | + { |
|
46 | + $this->_wp_list_args = array( |
|
47 | + 'singular' => esc_html__('Message', 'event_espresso'), |
|
48 | + 'plural' => esc_html__('Messages', 'event_espresso'), |
|
49 | + 'ajax' => true, |
|
50 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
51 | + ); |
|
52 | + |
|
53 | + $this->_columns = array( |
|
54 | + 'cb' => '<input type="checkbox" />', |
|
55 | + 'to' => esc_html__('To', 'event_espresso'), |
|
56 | + 'from' => esc_html__('From', 'event_espresso'), |
|
57 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
58 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
59 | + 'context' => esc_html__('Context', 'event_espresso'), |
|
60 | + 'modified' => esc_html__('Modified', 'event_espresso'), |
|
61 | + 'action' => esc_html__('Actions', 'event_espresso'), |
|
62 | + 'msg_id' => esc_html__('ID', 'event_espresso'), |
|
63 | + ); |
|
64 | + |
|
65 | + $this->_sortable_columns = array( |
|
66 | + 'modified' => array('MSG_modified' => true), |
|
67 | + 'message_type' => array('MSG_message_type' => false), |
|
68 | + 'messenger' => array('MSG_messenger' => false), |
|
69 | + 'to' => array('MSG_to' => false), |
|
70 | + 'from' => array('MSG_from' => false), |
|
71 | + 'context' => array('MSG_context' => false), |
|
72 | + 'msg_id' => array('MSG_ID', false), |
|
73 | + ); |
|
74 | + |
|
75 | + $this->_primary_column = 'to'; |
|
76 | + |
|
77 | + $this->_hidden_columns = array( |
|
78 | + 'msg_id', |
|
79 | + ); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * This simply sets up the row class for the table rows. |
|
85 | + * Allows for easier overriding of child methods for setting up sorting. |
|
86 | + * |
|
87 | + * @param EE_Message $item the current item |
|
88 | + * @return string |
|
89 | + * @throws EE_Error |
|
90 | + */ |
|
91 | + protected function _get_row_class($item) |
|
92 | + { |
|
93 | + $class = parent::_get_row_class($item); |
|
94 | + //add status class |
|
95 | + $class .= ' ee-status-strip msg-status-' . $item->STS_ID(); |
|
96 | + if ($this->_has_checkbox_column) { |
|
97 | + $class .= ' has-checkbox-column'; |
|
98 | + } |
|
99 | + return $class; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * _get_table_filters |
|
105 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
106 | + * get's shown in the table. |
|
107 | + * |
|
108 | + * @abstract |
|
109 | + * @access protected |
|
110 | + * @return array |
|
111 | + * @throws EE_Error |
|
112 | + * @throws InvalidArgumentException |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + */ |
|
116 | + protected function _get_table_filters() |
|
117 | + { |
|
118 | + $filters = array(); |
|
119 | + |
|
120 | + //get select_inputs |
|
121 | + $select_inputs = array( |
|
122 | + $this->_get_messengers_dropdown_filter(), |
|
123 | + $this->_get_message_types_dropdown_filter(), |
|
124 | + $this->_get_contexts_for_message_types_dropdown_filter(), |
|
125 | + ); |
|
126 | + |
|
127 | + //set filters to select inputs if they aren't empty |
|
128 | + foreach ($select_inputs as $select_input) { |
|
129 | + if ($select_input) { |
|
130 | + $filters[] = $select_input; |
|
131 | + } |
|
132 | + } |
|
133 | + return $filters; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @throws EE_Error |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + protected function _add_view_counts() |
|
144 | + { |
|
145 | + foreach ($this->_views as $view => $args) { |
|
146 | + $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param EE_Message $message |
|
153 | + * @return string checkbox |
|
154 | + * @throws EE_Error |
|
155 | + */ |
|
156 | + public function column_cb($message) |
|
157 | + { |
|
158 | + return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID()); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param EE_Message $message |
|
164 | + * @return string |
|
165 | + * @throws EE_Error |
|
166 | + */ |
|
167 | + public function column_msg_id(EE_Message $message) |
|
168 | + { |
|
169 | + return $message->ID(); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param EE_Message $message |
|
175 | + * @return string The recipient of the message |
|
176 | + * @throws EE_Error |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws ReflectionException |
|
179 | + * @throws InvalidDataTypeException |
|
180 | + * @throws InvalidInterfaceException |
|
181 | + */ |
|
182 | + public function column_to(EE_Message $message) |
|
183 | + { |
|
184 | + EE_Registry::instance()->load_helper('URL'); |
|
185 | + $actions = array(); |
|
186 | + $actions['delete'] = '<a href="' |
|
187 | + . EEH_URL::add_query_args_and_nonce( |
|
188 | + array( |
|
189 | + 'page' => 'espresso_messages', |
|
190 | + 'action' => 'delete_ee_message', |
|
191 | + 'MSG_ID' => $message->ID(), |
|
192 | + ), |
|
193 | + admin_url('admin.php') |
|
194 | + ) |
|
195 | + . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
196 | + $recipient_object = $message->recipient_object(); |
|
197 | + if ($recipient_object instanceof CapabilitiesActionRestrictionInterface |
|
198 | + && $recipient_object->canRead( |
|
199 | + new Context( |
|
200 | + 'view_link_from_message_list_table', |
|
201 | + esc_html__( |
|
202 | + 'View link for recipient displayed in the "To" column in the message list table.', |
|
203 | + 'event_espresso' |
|
204 | + ) |
|
205 | + ) |
|
206 | + ) |
|
207 | + ) { |
|
208 | + $view_details_link = $recipient_object instanceof EEI_Admin_Links |
|
209 | + ? $recipient_object->get_admin_details_link() |
|
210 | + : ''; |
|
211 | + if (! empty($view_details_link)) { |
|
212 | + $actions['view'] = '<a href="' . $view_details_link . '">' |
|
213 | + . esc_html__( |
|
214 | + 'View Recipient Details', |
|
215 | + 'event_espresso' |
|
216 | + ) |
|
217 | + . '</a>'; |
|
218 | + } |
|
219 | + } |
|
220 | + return esc_html($message->to()) . $this->row_actions($actions); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @param EE_Message $message |
|
226 | + * @return string The sender of the message |
|
227 | + * @throws EE_Error |
|
228 | + */ |
|
229 | + public function column_from(EE_Message $message) |
|
230 | + { |
|
231 | + return esc_html($message->from()); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param EE_Message $message |
|
237 | + * @return string The messenger used to send the message. |
|
238 | + * @throws EE_Error |
|
239 | + */ |
|
240 | + public function column_messenger(EE_Message $message) |
|
241 | + { |
|
242 | + return ucwords($message->messenger_label()); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param EE_Message $message |
|
248 | + * @return string The message type used to generate the message. |
|
249 | + * @throws EE_Error |
|
250 | + */ |
|
251 | + public function column_message_type(EE_Message $message) |
|
252 | + { |
|
253 | + return ucwords($message->message_type_label()); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param EE_Message $message |
|
259 | + * @return string The context the message was generated for. |
|
260 | + * @throws EE_Error |
|
261 | + * @throws InvalidArgumentException |
|
262 | + * @throws InvalidDataTypeException |
|
263 | + * @throws InvalidInterfaceException |
|
264 | + * @throws ReflectionException |
|
265 | + */ |
|
266 | + public function column_context(EE_Message $message) |
|
267 | + { |
|
268 | + return $message->context_label(); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @param EE_Message $message |
|
274 | + * @return string The timestamp when this message was last modified. |
|
275 | + * @throws EE_Error |
|
276 | + */ |
|
277 | + public function column_modified(EE_Message $message) |
|
278 | + { |
|
279 | + return $message->modified(); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param EE_Message $message |
|
285 | + * @return string Actions that can be done on the current message. |
|
286 | + * @throws EE_Error |
|
287 | + * @throws InvalidArgumentException |
|
288 | + * @throws InvalidDataTypeException |
|
289 | + * @throws InvalidInterfaceException |
|
290 | + * @throws ReflectionException |
|
291 | + */ |
|
292 | + public function column_action(EE_Message $message) |
|
293 | + { |
|
294 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
295 | + $action_links = array( |
|
296 | + 'view' => EEH_MSG_Template::get_message_action_link('view', $message), |
|
297 | + 'error' => EEH_MSG_Template::get_message_action_link('error', $message), |
|
298 | + 'generate_now' => EEH_MSG_Template::get_message_action_link('generate_now', $message), |
|
299 | + 'send_now' => EEH_MSG_Template::get_message_action_link('send_now', $message), |
|
300 | + 'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message), |
|
301 | + 'view_transaction' => EEH_MSG_Template::get_message_action_link('view_transaction', $message), |
|
302 | + ); |
|
303 | + $content = ''; |
|
304 | + switch ($message->STS_ID()) { |
|
305 | + case EEM_Message::status_sent: |
|
306 | + $content = $action_links['view'] |
|
307 | + . $action_links['queue_for_resending'] |
|
308 | + . $action_links['view_transaction']; |
|
309 | + break; |
|
310 | + case EEM_Message::status_resend: |
|
311 | + $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
312 | + break; |
|
313 | + case EEM_Message::status_retry: |
|
314 | + $content = $action_links['view'] |
|
315 | + . $action_links['send_now'] |
|
316 | + . $action_links['error'] |
|
317 | + . $action_links['view_transaction']; |
|
318 | + break; |
|
319 | + case EEM_Message::status_failed: |
|
320 | + case EEM_Message::status_debug_only: |
|
321 | + $content = $action_links['error'] . $action_links['view_transaction']; |
|
322 | + break; |
|
323 | + case EEM_Message::status_idle: |
|
324 | + $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
325 | + break; |
|
326 | + case EEM_Message::status_incomplete: |
|
327 | + $content = $action_links['generate_now'] . $action_links['view_transaction']; |
|
328 | + break; |
|
329 | + } |
|
330 | + return $content; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Retrieve the EE_Message objects for the list table. |
|
336 | + * |
|
337 | + * @param int $perpage The number of items per page |
|
338 | + * @param string $view The view items are being retrieved for |
|
339 | + * @param bool $count Whether to just return a count or not. |
|
340 | + * @param bool $all Disregard any paging info (no limit on data returned). |
|
341 | + * @return EE_Message[]|int |
|
342 | + * @throws EE_Error |
|
343 | + * @throws InvalidArgumentException |
|
344 | + * @throws InvalidDataTypeException |
|
345 | + * @throws InvalidInterfaceException |
|
346 | + */ |
|
347 | + protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false) |
|
348 | + { |
|
349 | + |
|
350 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
351 | + ? $this->_req_data['paged'] |
|
352 | + : 1; |
|
353 | + |
|
354 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
355 | + ? $this->_req_data['perpage'] |
|
356 | + : $perpage; |
|
357 | + |
|
358 | + $offset = ($current_page - 1) * $per_page; |
|
359 | + $limit = $all || $count ? null : array($offset, $per_page); |
|
360 | + $query_params = array( |
|
361 | + 'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'], |
|
362 | + 'order' => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'], |
|
363 | + 'limit' => $limit, |
|
364 | + ); |
|
365 | + |
|
366 | + /** |
|
367 | + * Any filters coming in from other routes? |
|
368 | + */ |
|
369 | + if (isset($this->_req_data['filterby'])) { |
|
370 | + $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); |
|
371 | + if (! $count) { |
|
372 | + $query_params['group_by'] = 'MSG_ID'; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + //view conditionals |
|
377 | + if ($view !== 'all' && $count && $all) { |
|
378 | + $query_params[0]['AND*view_conditional'] = array( |
|
379 | + 'STS_ID' => strtoupper($view), |
|
380 | + ); |
|
381 | + } |
|
382 | + |
|
383 | + if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
384 | + $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed |
|
385 | + ? array( |
|
386 | + 'STS_ID' => array( |
|
387 | + 'IN', |
|
388 | + array(EEM_Message::status_failed, EEM_Message::status_messenger_executing), |
|
389 | + ), |
|
390 | + ) |
|
391 | + : array('STS_ID' => strtoupper($this->_req_data['status'])); |
|
392 | + } |
|
393 | + |
|
394 | + if (! $all && ! empty($this->_req_data['s'])) { |
|
395 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
396 | + $query_params[0]['OR'] = array( |
|
397 | + 'MSG_to' => array('LIKE', $search_string), |
|
398 | + 'MSG_from' => array('LIKE', $search_string), |
|
399 | + 'MSG_subject' => array('LIKE', $search_string), |
|
400 | + 'MSG_content' => array('LIKE', $search_string), |
|
401 | + ); |
|
402 | + } |
|
403 | + |
|
404 | + //account for debug only status. We don't show Messages with the EEM_Message::status_debug_only to clients when |
|
405 | + //the messages system is in debug mode. |
|
406 | + //Note: for backward compat with previous iterations, this is necessary because there may be |
|
407 | + // EEM_Message::status_debug_only |
|
408 | + //messages in the database. |
|
409 | + if (! EEM_Message::debug()) { |
|
410 | + $query_params[0]['AND*debug_only_conditional'] = array( |
|
411 | + 'STS_ID' => array('!=', EEM_Message::status_debug_only), |
|
412 | + ); |
|
413 | + } |
|
414 | + |
|
415 | + //account for filters |
|
416 | + if (! $all |
|
417 | + && isset($this->_req_data['ee_messenger_filter_by']) |
|
418 | + && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected' |
|
419 | + ) { |
|
420 | + $query_params[0]['AND*messenger_filter'] = array( |
|
421 | + 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'], |
|
422 | + ); |
|
423 | + } |
|
424 | + if (! $all |
|
425 | + && ! empty($this->_req_data['ee_message_type_filter_by']) |
|
426 | + && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected' |
|
427 | + ) { |
|
428 | + $query_params[0]['AND*message_type_filter'] = array( |
|
429 | + 'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'], |
|
430 | + ); |
|
431 | + } |
|
432 | + |
|
433 | + if (! $all |
|
434 | + && ! empty($this->_req_data['ee_context_filter_by']) |
|
435 | + && $this->_req_data['ee_context_filter_by'] !== 'none_selected' |
|
436 | + ) { |
|
437 | + $query_params[0]['AND*context_filter'] = array( |
|
438 | + 'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])), |
|
439 | + ); |
|
440 | + } |
|
441 | + |
|
442 | + return $count |
|
443 | + /** @type int */ |
|
444 | + ? EEM_Message::instance()->count($query_params, null, true) |
|
445 | + /** @type EE_Message[] */ |
|
446 | + : EEM_Message::instance()->get_all($query_params); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Generate dropdown filter select input for messengers. |
|
452 | + * |
|
453 | + * @return string |
|
454 | + * @throws EE_Error |
|
455 | + * @throws InvalidArgumentException |
|
456 | + * @throws InvalidDataTypeException |
|
457 | + * @throws InvalidInterfaceException |
|
458 | + */ |
|
459 | + protected function _get_messengers_dropdown_filter() |
|
460 | + { |
|
461 | + $messenger_options = array(); |
|
462 | + $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
463 | + |
|
464 | + //setup array of messenger options |
|
465 | + foreach ($active_messages_grouped_by_messenger as $active_message) { |
|
466 | + if ($active_message instanceof EE_Message) { |
|
467 | + $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label()); |
|
468 | + } |
|
469 | + } |
|
470 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Generate dropdown filter select input for message types |
|
476 | + * |
|
477 | + * @return string |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidArgumentException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws InvalidInterfaceException |
|
482 | + */ |
|
483 | + protected function _get_message_types_dropdown_filter() |
|
484 | + { |
|
485 | + $message_type_options = array(); |
|
486 | + $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all( |
|
487 | + array('group_by' => 'MSG_message_type') |
|
488 | + ); |
|
489 | + |
|
490 | + //setup array of message type options |
|
491 | + foreach ($active_messages_grouped_by_message_type as $active_message) { |
|
492 | + if ($active_message instanceof EE_Message) { |
|
493 | + $message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label()); |
|
494 | + } |
|
495 | + } |
|
496 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * Generate dropdown filter select input for message type contexts |
|
502 | + * |
|
503 | + * @return string |
|
504 | + * @throws EE_Error |
|
505 | + * @throws InvalidArgumentException |
|
506 | + * @throws InvalidDataTypeException |
|
507 | + * @throws InvalidInterfaceException |
|
508 | + */ |
|
509 | + protected function _get_contexts_for_message_types_dropdown_filter() |
|
510 | + { |
|
511 | + $context_options = array(); |
|
512 | + $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
513 | + |
|
514 | + //setup array of context options |
|
515 | + foreach ($active_messages_grouped_by_context as $active_message) { |
|
516 | + if ($active_message instanceof EE_Message) { |
|
517 | + $message_type = $active_message->message_type_object(); |
|
518 | + if ($message_type instanceof EE_message_type) { |
|
519 | + foreach ($message_type->get_contexts() as $context => $context_details) { |
|
520 | + if (isset($context_details['label'])) { |
|
521 | + $context_options[$context] = $context_details['label']; |
|
522 | + } |
|
523 | + } |
|
524 | + } |
|
525 | + } |
|
526 | + } |
|
527 | + return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options); |
|
528 | + } |
|
529 | 529 | } |
@@ -15,960 +15,960 @@ |
||
15 | 15 | class EE_Message extends EE_Base_Class implements EEI_Admin_Links |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
20 | - * @type null |
|
21 | - */ |
|
22 | - public $template_pack; |
|
23 | - |
|
24 | - /** |
|
25 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
26 | - * @type null |
|
27 | - */ |
|
28 | - public $template_variation; |
|
29 | - |
|
30 | - /** |
|
31 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
32 | - * @type string |
|
33 | - */ |
|
34 | - public $content = ''; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @type EE_messenger $_messenger |
|
39 | - */ |
|
40 | - protected $_messenger = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_message_type $_message_type |
|
44 | - */ |
|
45 | - protected $_message_type = null; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param array $props_n_values |
|
50 | - * @param string $timezone |
|
51 | - * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
52 | - * format. |
|
53 | - * @return EE_Message |
|
54 | - * @throws EE_Error |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws ReflectionException |
|
57 | - * @throws InvalidDataTypeException |
|
58 | - * @throws InvalidInterfaceException |
|
59 | - */ |
|
60 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
61 | - { |
|
62 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
63 | - //if object doesn't exist, let's generate a unique token on instantiation so that its available even before |
|
64 | - // saving to db. |
|
65 | - if (! $has_object) { |
|
66 | - EE_Registry::instance()->load_helper('URL'); |
|
67 | - $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
68 | - } |
|
69 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param array $props_n_values |
|
75 | - * @param string $timezone |
|
76 | - * @return EE_Message |
|
77 | - */ |
|
78 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
79 | - { |
|
80 | - return new self($props_n_values, true, $timezone); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Gets MSG_token |
|
86 | - * |
|
87 | - * @return int |
|
88 | - * @throws EE_Error |
|
89 | - */ |
|
90 | - public function MSG_token() |
|
91 | - { |
|
92 | - return $this->get('MSG_token'); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Sets MSG_token |
|
98 | - * |
|
99 | - * @param int $MSG_token |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - public function set_MSG_token($MSG_token) |
|
103 | - { |
|
104 | - $this->set('MSG_token', $MSG_token); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets GRP_ID |
|
110 | - * |
|
111 | - * @return int |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - public function GRP_ID() |
|
115 | - { |
|
116 | - return $this->get('GRP_ID'); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Sets GRP_ID |
|
122 | - * |
|
123 | - * @param int $GRP_ID |
|
124 | - * @throws EE_Error |
|
125 | - */ |
|
126 | - public function set_GRP_ID($GRP_ID) |
|
127 | - { |
|
128 | - $this->set('GRP_ID', $GRP_ID); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * Gets TXN_ID |
|
134 | - * |
|
135 | - * @return int |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public function TXN_ID() |
|
139 | - { |
|
140 | - return $this->get('TXN_ID'); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Sets TXN_ID |
|
146 | - * |
|
147 | - * @param int $TXN_ID |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - public function set_TXN_ID($TXN_ID) |
|
151 | - { |
|
152 | - $this->set('TXN_ID', $TXN_ID); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Gets messenger |
|
158 | - * |
|
159 | - * @return string |
|
160 | - * @throws EE_Error |
|
161 | - */ |
|
162 | - public function messenger() |
|
163 | - { |
|
164 | - return $this->get('MSG_messenger'); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Sets messenger |
|
170 | - * |
|
171 | - * @param string $messenger |
|
172 | - * @throws EE_Error |
|
173 | - */ |
|
174 | - public function set_messenger($messenger) |
|
175 | - { |
|
176 | - $this->set('MSG_messenger', $messenger); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns corresponding messenger object for the set messenger on this message |
|
182 | - * |
|
183 | - * @return EE_messenger | null |
|
184 | - */ |
|
185 | - public function messenger_object() |
|
186 | - { |
|
187 | - return $this->_messenger; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Sets messenger |
|
193 | - * |
|
194 | - * @param EE_messenger $messenger |
|
195 | - */ |
|
196 | - public function set_messenger_object(EE_messenger $messenger) |
|
197 | - { |
|
198 | - $this->_messenger = $messenger; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * validates messenger |
|
204 | - * |
|
205 | - * @param bool $throw_exceptions |
|
206 | - * @return bool |
|
207 | - * @throws EE_Error |
|
208 | - */ |
|
209 | - public function valid_messenger($throw_exceptions = false) |
|
210 | - { |
|
211 | - if ($this->_messenger instanceof EE_messenger) { |
|
212 | - return true; |
|
213 | - } |
|
214 | - if ($throw_exceptions) { |
|
215 | - throw new EE_Error( |
|
216 | - sprintf( |
|
217 | - esc_html__( |
|
218 | - 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - $this->messenger() |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - return false; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * This returns the set localized label for the messenger on this message. |
|
231 | - * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
232 | - * with this message. |
|
233 | - * |
|
234 | - * @param bool $plural whether to return the plural label or not. |
|
235 | - * @return string |
|
236 | - * @throws EE_Error |
|
237 | - */ |
|
238 | - public function messenger_label($plural = false) |
|
239 | - { |
|
240 | - $label_type = $plural ? 'plural' : 'singular'; |
|
241 | - $messenger = $this->messenger_object(); |
|
242 | - return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Gets message_type |
|
248 | - * |
|
249 | - * @return string |
|
250 | - * @throws EE_Error |
|
251 | - */ |
|
252 | - public function message_type() |
|
253 | - { |
|
254 | - return $this->get('MSG_message_type'); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Sets message_type |
|
260 | - * |
|
261 | - * @param string $message_type |
|
262 | - * @throws EE_Error |
|
263 | - */ |
|
264 | - public function set_message_type($message_type) |
|
265 | - { |
|
266 | - $this->set('MSG_message_type', $message_type); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Returns the message type object for the set message type on this message |
|
272 | - * |
|
273 | - * @return EE_message_type | null |
|
274 | - */ |
|
275 | - public function message_type_object() |
|
276 | - { |
|
277 | - return $this->_message_type; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Sets message_type |
|
283 | - * |
|
284 | - * @param EE_message_type $message_type |
|
285 | - * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
286 | - * the message type or not. |
|
287 | - * @throws EE_Error |
|
288 | - */ |
|
289 | - public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
290 | - { |
|
291 | - $this->_message_type = $message_type; |
|
292 | - if ($set_priority) { |
|
293 | - $this->set_priority($this->_message_type->get_priority()); |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * validates message_type |
|
300 | - * |
|
301 | - * @param bool $throw_exceptions |
|
302 | - * @return bool |
|
303 | - * @throws \EE_Error |
|
304 | - * @throws EE_Error |
|
305 | - */ |
|
306 | - public function valid_message_type($throw_exceptions = false) |
|
307 | - { |
|
308 | - if ($this->_message_type instanceof EE_message_type) { |
|
309 | - return true; |
|
310 | - } |
|
311 | - if ($throw_exceptions) { |
|
312 | - throw new EE_Error( |
|
313 | - sprintf( |
|
314 | - esc_html__( |
|
315 | - 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
316 | - 'event_espresso' |
|
317 | - ), |
|
318 | - $this->message_type() |
|
319 | - ) |
|
320 | - ); |
|
321 | - } |
|
322 | - return false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
328 | - * |
|
329 | - * @param bool $throw_exceptions |
|
330 | - * @return bool |
|
331 | - * @throws EE_Error |
|
332 | - */ |
|
333 | - public function is_valid($throw_exceptions = false) |
|
334 | - { |
|
335 | - if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
336 | - return true; |
|
337 | - } |
|
338 | - return false; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * This validates whether the internal messenger and message type objects are valid for sending. |
|
344 | - * Three checks are done: |
|
345 | - * 1. There is a valid messenger object. |
|
346 | - * 2. There is a valid message type object. |
|
347 | - * 3. The message type object is active for the messenger. |
|
348 | - * |
|
349 | - * @param bool $throw_exceptions |
|
350 | - * @return bool But only if $throw_exceptions is set to true. |
|
351 | - * @throws EE_Error But only if $throw_exceptions is set to true. |
|
352 | - * @throws InvalidArgumentException |
|
353 | - * @throws ReflectionException |
|
354 | - * @throws InvalidDataTypeException |
|
355 | - * @throws InvalidInterfaceException |
|
356 | - */ |
|
357 | - public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
358 | - { |
|
359 | - $valid = false; |
|
360 | - if ($this->is_valid($throw_exceptions)) { |
|
361 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
362 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
363 | - $valid = $message_resource_manager->is_message_type_active_for_messenger( |
|
364 | - $this->messenger(), |
|
365 | - $this->message_type() |
|
366 | - ); |
|
367 | - if (! $valid && $throw_exceptions) { |
|
368 | - throw new EE_Error( |
|
369 | - sprintf( |
|
370 | - esc_html__( |
|
371 | - 'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
372 | - 'event_espresso' |
|
373 | - ), |
|
374 | - $this->message_type(), |
|
375 | - $this->messenger() |
|
376 | - ) |
|
377 | - ); |
|
378 | - } |
|
379 | - } |
|
380 | - return $valid; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * This returns the set localized label for the message type on this message. |
|
386 | - * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
387 | - * with this message. |
|
388 | - * |
|
389 | - * @param bool $plural whether to return the plural label or not. |
|
390 | - * @return string |
|
391 | - * @throws EE_Error |
|
392 | - */ |
|
393 | - public function message_type_label($plural = false) |
|
394 | - { |
|
395 | - $label_type = $plural ? 'plural' : 'singular'; |
|
396 | - $message_type = $this->message_type_object(); |
|
397 | - return $message_type instanceof EE_message_type |
|
398 | - ? $message_type->label[$label_type] |
|
399 | - : str_replace( |
|
400 | - '_', |
|
401 | - ' ', |
|
402 | - $this->message_type() |
|
403 | - ); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Gets context |
|
409 | - * |
|
410 | - * @return string |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - public function context() |
|
414 | - { |
|
415 | - return $this->get('MSG_context'); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
421 | - * types. Otherwise, this will just return the set context slug on this object. |
|
422 | - * |
|
423 | - * @return string |
|
424 | - * @throws EE_Error |
|
425 | - * @throws InvalidArgumentException |
|
426 | - * @throws ReflectionException |
|
427 | - * @throws InvalidDataTypeException |
|
428 | - * @throws InvalidInterfaceException |
|
429 | - */ |
|
430 | - public function context_label() |
|
431 | - { |
|
432 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
433 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
434 | - $contexts = $message_resource_manager->get_all_contexts(); |
|
435 | - return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Sets context |
|
441 | - * |
|
442 | - * @param string $context |
|
443 | - * @throws EE_Error |
|
444 | - */ |
|
445 | - public function set_context($context) |
|
446 | - { |
|
447 | - $this->set('MSG_context', $context); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Gets recipient_ID |
|
453 | - * |
|
454 | - * @return int |
|
455 | - * @throws EE_Error |
|
456 | - */ |
|
457 | - public function recipient_ID() |
|
458 | - { |
|
459 | - return $this->get('MSG_recipient_ID'); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * Sets recipient_ID |
|
465 | - * |
|
466 | - * @param string $recipient_ID |
|
467 | - * @throws EE_Error |
|
468 | - */ |
|
469 | - public function set_recipient_ID($recipient_ID) |
|
470 | - { |
|
471 | - $this->set('MSG_recipient_ID', $recipient_ID); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * Gets recipient_type |
|
477 | - * |
|
478 | - * @return string |
|
479 | - * @throws EE_Error |
|
480 | - */ |
|
481 | - public function recipient_type() |
|
482 | - { |
|
483 | - return $this->get('MSG_recipient_type'); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * Return the related object matching the recipient type and ID. |
|
489 | - * |
|
490 | - * @return EE_Base_Class|null |
|
491 | - * @throws EE_Error |
|
492 | - */ |
|
493 | - public function recipient_object() |
|
494 | - { |
|
495 | - if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
496 | - return null; |
|
497 | - } |
|
498 | - |
|
499 | - return $this->get_first_related($this->recipient_type()); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Sets recipient_type |
|
505 | - * |
|
506 | - * @param string $recipient_type |
|
507 | - * @throws EE_Error |
|
508 | - */ |
|
509 | - public function set_recipient_type($recipient_type) |
|
510 | - { |
|
511 | - $this->set('MSG_recipient_type', $recipient_type); |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * Gets content |
|
517 | - * |
|
518 | - * @return string |
|
519 | - * @throws EE_Error |
|
520 | - */ |
|
521 | - public function content() |
|
522 | - { |
|
523 | - return $this->get('MSG_content'); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Sets content |
|
529 | - * |
|
530 | - * @param string $content |
|
531 | - * @throws EE_Error |
|
532 | - */ |
|
533 | - public function set_content($content) |
|
534 | - { |
|
535 | - $this->set('MSG_content', $content); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Gets subject |
|
541 | - * |
|
542 | - * @return string |
|
543 | - * @throws EE_Error |
|
544 | - */ |
|
545 | - public function subject() |
|
546 | - { |
|
547 | - return $this->get('MSG_subject'); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * Sets subject |
|
553 | - * |
|
554 | - * @param string $subject |
|
555 | - * @throws EE_Error |
|
556 | - */ |
|
557 | - public function set_subject($subject) |
|
558 | - { |
|
559 | - $this->set('MSG_subject', $subject); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Gets to |
|
565 | - * |
|
566 | - * @return string |
|
567 | - * @throws EE_Error |
|
568 | - */ |
|
569 | - public function to() |
|
570 | - { |
|
571 | - $to = $this->get('MSG_to'); |
|
572 | - return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to; |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * Sets to |
|
578 | - * |
|
579 | - * @param string $to |
|
580 | - * @throws EE_Error |
|
581 | - */ |
|
582 | - public function set_to($to) |
|
583 | - { |
|
584 | - $this->set('MSG_to', $to); |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * Gets from |
|
590 | - * |
|
591 | - * @return string |
|
592 | - * @throws EE_Error |
|
593 | - */ |
|
594 | - public function from() |
|
595 | - { |
|
596 | - return $this->get('MSG_from'); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * Sets from |
|
602 | - * |
|
603 | - * @param string $from |
|
604 | - * @throws EE_Error |
|
605 | - */ |
|
606 | - public function set_from($from) |
|
607 | - { |
|
608 | - $this->set('MSG_from', $from); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * Gets priority |
|
614 | - * |
|
615 | - * @return int |
|
616 | - * @throws EE_Error |
|
617 | - */ |
|
618 | - public function priority() |
|
619 | - { |
|
620 | - return $this->get('MSG_priority'); |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Sets priority |
|
626 | - * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
627 | - * this method calls the send_now method to verify that. |
|
628 | - * |
|
629 | - * @param int $priority |
|
630 | - * @throws EE_Error |
|
631 | - */ |
|
632 | - public function set_priority($priority) |
|
633 | - { |
|
634 | - $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
635 | - parent::set('MSG_priority', $priority); |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * Overrides parent::set method so we can capture any sets for priority. |
|
641 | - * |
|
642 | - * @see parent::set() for phpdocs |
|
643 | - * @param string $field_name |
|
644 | - * @param mixed $field_value |
|
645 | - * @param bool $use_default |
|
646 | - * @throws EE_Error |
|
647 | - */ |
|
648 | - public function set($field_name, $field_value, $use_default = false) |
|
649 | - { |
|
650 | - if ($field_name === 'MSG_priority') { |
|
651 | - $this->set_priority($field_value); |
|
652 | - } |
|
653 | - parent::set($field_name, $field_value, $use_default); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * @return bool |
|
659 | - * @throws \EE_Error |
|
660 | - */ |
|
661 | - public function send_now() |
|
662 | - { |
|
663 | - $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() |
|
664 | - ? EEM_Message::priority_high |
|
665 | - : $this->priority(); |
|
666 | - return $send_now === EEM_Message::priority_high; |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * Gets STS_ID |
|
672 | - * |
|
673 | - * @return string |
|
674 | - * @throws EE_Error |
|
675 | - */ |
|
676 | - public function STS_ID() |
|
677 | - { |
|
678 | - return $this->get('STS_ID'); |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * Sets STS_ID |
|
684 | - * |
|
685 | - * @param string $STS_ID |
|
686 | - * @throws EE_Error |
|
687 | - */ |
|
688 | - public function set_STS_ID($STS_ID) |
|
689 | - { |
|
690 | - $this->set('STS_ID', $STS_ID); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * Gets created |
|
696 | - * |
|
697 | - * @return string |
|
698 | - * @throws EE_Error |
|
699 | - */ |
|
700 | - public function created() |
|
701 | - { |
|
702 | - return $this->get('MSG_created'); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * Sets created |
|
708 | - * |
|
709 | - * @param string $created |
|
710 | - * @throws EE_Error |
|
711 | - */ |
|
712 | - public function set_created($created) |
|
713 | - { |
|
714 | - $this->set('MSG_created', $created); |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * Gets modified |
|
720 | - * |
|
721 | - * @return string |
|
722 | - * @throws EE_Error |
|
723 | - */ |
|
724 | - public function modified() |
|
725 | - { |
|
726 | - return $this->get('MSG_modified'); |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * Sets modified |
|
732 | - * |
|
733 | - * @param string $modified |
|
734 | - * @throws EE_Error |
|
735 | - */ |
|
736 | - public function set_modified($modified) |
|
737 | - { |
|
738 | - $this->set('MSG_modified', $modified); |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * Sets generation data for this message. |
|
744 | - * |
|
745 | - * @param mixed $data |
|
746 | - * @throws EE_Error |
|
747 | - */ |
|
748 | - public function set_generation_data($data) |
|
749 | - { |
|
750 | - $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * Returns any set generation data for this message. |
|
756 | - * |
|
757 | - * @return mixed|null |
|
758 | - * @throws EE_Error |
|
759 | - */ |
|
760 | - public function get_generation_data() |
|
761 | - { |
|
762 | - return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * Gets any error message. |
|
768 | - * |
|
769 | - * @return mixed|null |
|
770 | - * @throws EE_Error |
|
771 | - */ |
|
772 | - public function error_message() |
|
773 | - { |
|
774 | - return $this->get_field_or_extra_meta('MSG_error'); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * Sets an error message. |
|
780 | - * |
|
781 | - * @param $message |
|
782 | - * @return bool|int |
|
783 | - * @throws EE_Error |
|
784 | - */ |
|
785 | - public function set_error_message($message) |
|
786 | - { |
|
787 | - return $this->set_field_or_extra_meta('MSG_error', $message); |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * This retrieves the associated template pack with this message. |
|
793 | - * |
|
794 | - * @return EE_Messages_Template_Pack|null |
|
795 | - * @throws EE_Error |
|
796 | - * @throws InvalidArgumentException |
|
797 | - * @throws ReflectionException |
|
798 | - * @throws InvalidDataTypeException |
|
799 | - * @throws InvalidInterfaceException |
|
800 | - */ |
|
801 | - public function get_template_pack() |
|
802 | - { |
|
803 | - /** |
|
804 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
805 | - */ |
|
806 | - if (! empty($this->template_pack)) { |
|
807 | - return $this->template_pack; |
|
808 | - } |
|
809 | - /** @type EE_Message_Template_Group $grp */ |
|
810 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
811 | - //if no group then let's try to get the first related group by internal messenger and message type |
|
812 | - // (will use global grp). |
|
813 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
814 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
815 | - array( |
|
816 | - array( |
|
817 | - 'MTP_messenger' => $this->messenger(), |
|
818 | - 'MTP_message_type' => $this->message_type(), |
|
819 | - 'MTP_is_global' => true, |
|
820 | - ), |
|
821 | - ) |
|
822 | - ); |
|
823 | - } |
|
824 | - |
|
825 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * Retrieves the variation used for generating this message. |
|
831 | - * |
|
832 | - * @return string |
|
833 | - * @throws EE_Error |
|
834 | - * @throws InvalidArgumentException |
|
835 | - * @throws InvalidDataTypeException |
|
836 | - * @throws InvalidInterfaceException |
|
837 | - */ |
|
838 | - public function get_template_pack_variation() |
|
839 | - { |
|
840 | - /** |
|
841 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
842 | - */ |
|
843 | - if (! empty($this->template_variation)) { |
|
844 | - return $this->template_variation; |
|
845 | - } |
|
846 | - |
|
847 | - /** @type EE_Message_Template_Group $grp */ |
|
848 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
849 | - |
|
850 | - //if no group then let's try to get the first related group by internal messenger and message type |
|
851 | - // (will use global grp). |
|
852 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
853 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
854 | - array( |
|
855 | - array( |
|
856 | - 'MTP_messenger' => $this->messenger(), |
|
857 | - 'MTP_message_type' => $this->message_type(), |
|
858 | - 'MTP_is_global' => true, |
|
859 | - ), |
|
860 | - ) |
|
861 | - ); |
|
862 | - } |
|
863 | - |
|
864 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
865 | - } |
|
866 | - |
|
867 | - /** |
|
868 | - * Return the link to the admin details for the object. |
|
869 | - * |
|
870 | - * @return string |
|
871 | - * @throws EE_Error |
|
872 | - * @throws InvalidArgumentException |
|
873 | - * @throws ReflectionException |
|
874 | - * @throws InvalidDataTypeException |
|
875 | - * @throws InvalidInterfaceException |
|
876 | - */ |
|
877 | - public function get_admin_details_link() |
|
878 | - { |
|
879 | - EE_Registry::instance()->load_helper('URL'); |
|
880 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
881 | - switch ($this->STS_ID()) { |
|
882 | - case EEM_Message::status_failed: |
|
883 | - case EEM_Message::status_debug_only: |
|
884 | - return EEH_MSG_Template::generate_error_display_trigger($this); |
|
885 | - break; |
|
886 | - |
|
887 | - case EEM_Message::status_sent: |
|
888 | - return EEH_MSG_Template::generate_browser_trigger($this); |
|
889 | - break; |
|
890 | - |
|
891 | - default: |
|
892 | - return ''; |
|
893 | - } |
|
894 | - } |
|
895 | - |
|
896 | - /** |
|
897 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
898 | - * |
|
899 | - * @return string |
|
900 | - * @throws EE_Error |
|
901 | - * @throws InvalidArgumentException |
|
902 | - * @throws ReflectionException |
|
903 | - * @throws InvalidDataTypeException |
|
904 | - * @throws InvalidInterfaceException |
|
905 | - */ |
|
906 | - public function get_admin_edit_link() |
|
907 | - { |
|
908 | - return $this->get_admin_details_link(); |
|
909 | - } |
|
910 | - |
|
911 | - /** |
|
912 | - * Returns the link to a settings page for the object. |
|
913 | - * |
|
914 | - * @return string |
|
915 | - * @throws EE_Error |
|
916 | - * @throws InvalidArgumentException |
|
917 | - * @throws ReflectionException |
|
918 | - * @throws InvalidDataTypeException |
|
919 | - * @throws InvalidInterfaceException |
|
920 | - */ |
|
921 | - public function get_admin_settings_link() |
|
922 | - { |
|
923 | - EE_Registry::instance()->load_helper('URL'); |
|
924 | - return EEH_URL::add_query_args_and_nonce( |
|
925 | - array( |
|
926 | - 'page' => 'espresso_messages', |
|
927 | - 'action' => 'settings', |
|
928 | - ), |
|
929 | - admin_url('admin.php') |
|
930 | - ); |
|
931 | - } |
|
932 | - |
|
933 | - /** |
|
934 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
935 | - * |
|
936 | - * @return string |
|
937 | - * @throws EE_Error |
|
938 | - * @throws InvalidArgumentException |
|
939 | - * @throws ReflectionException |
|
940 | - * @throws InvalidDataTypeException |
|
941 | - * @throws InvalidInterfaceException |
|
942 | - */ |
|
943 | - public function get_admin_overview_link() |
|
944 | - { |
|
945 | - EE_Registry::instance()->load_helper('URL'); |
|
946 | - return EEH_URL::add_query_args_and_nonce( |
|
947 | - array( |
|
948 | - 'page' => 'espresso_messages', |
|
949 | - 'action' => 'default', |
|
950 | - ), |
|
951 | - admin_url('admin.php') |
|
952 | - ); |
|
953 | - } |
|
954 | - |
|
955 | - |
|
956 | - /** |
|
957 | - * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
958 | - * it. |
|
959 | - * Note this also SAVES the current message object to the db because it adds an error message to accompany the |
|
960 | - * status. |
|
961 | - * |
|
962 | - * @throws EE_Error |
|
963 | - */ |
|
964 | - public function set_messenger_is_executing() |
|
965 | - { |
|
966 | - $this->set_STS_ID(EEM_Message::status_messenger_executing); |
|
967 | - $this->set_error_message( |
|
968 | - esc_html__( |
|
969 | - 'A message with this status indicates that there was a problem that occurred while the message was being processed by the messenger. It is still possible that the message was sent successfully, but at some point during the processing there was a failure. This usually is indicative of a timeout issue with PHP or memory limits being reached. If you see this repeatedly you may want to consider upgrading the memory available to PHP on your server.', |
|
970 | - 'event_espresso' |
|
971 | - ) |
|
972 | - ); |
|
973 | - } |
|
18 | + /** |
|
19 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
20 | + * @type null |
|
21 | + */ |
|
22 | + public $template_pack; |
|
23 | + |
|
24 | + /** |
|
25 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
26 | + * @type null |
|
27 | + */ |
|
28 | + public $template_variation; |
|
29 | + |
|
30 | + /** |
|
31 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
32 | + * @type string |
|
33 | + */ |
|
34 | + public $content = ''; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @type EE_messenger $_messenger |
|
39 | + */ |
|
40 | + protected $_messenger = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_message_type $_message_type |
|
44 | + */ |
|
45 | + protected $_message_type = null; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param array $props_n_values |
|
50 | + * @param string $timezone |
|
51 | + * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
52 | + * format. |
|
53 | + * @return EE_Message |
|
54 | + * @throws EE_Error |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws ReflectionException |
|
57 | + * @throws InvalidDataTypeException |
|
58 | + * @throws InvalidInterfaceException |
|
59 | + */ |
|
60 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
61 | + { |
|
62 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
63 | + //if object doesn't exist, let's generate a unique token on instantiation so that its available even before |
|
64 | + // saving to db. |
|
65 | + if (! $has_object) { |
|
66 | + EE_Registry::instance()->load_helper('URL'); |
|
67 | + $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
68 | + } |
|
69 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param array $props_n_values |
|
75 | + * @param string $timezone |
|
76 | + * @return EE_Message |
|
77 | + */ |
|
78 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
79 | + { |
|
80 | + return new self($props_n_values, true, $timezone); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Gets MSG_token |
|
86 | + * |
|
87 | + * @return int |
|
88 | + * @throws EE_Error |
|
89 | + */ |
|
90 | + public function MSG_token() |
|
91 | + { |
|
92 | + return $this->get('MSG_token'); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Sets MSG_token |
|
98 | + * |
|
99 | + * @param int $MSG_token |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + public function set_MSG_token($MSG_token) |
|
103 | + { |
|
104 | + $this->set('MSG_token', $MSG_token); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets GRP_ID |
|
110 | + * |
|
111 | + * @return int |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + public function GRP_ID() |
|
115 | + { |
|
116 | + return $this->get('GRP_ID'); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Sets GRP_ID |
|
122 | + * |
|
123 | + * @param int $GRP_ID |
|
124 | + * @throws EE_Error |
|
125 | + */ |
|
126 | + public function set_GRP_ID($GRP_ID) |
|
127 | + { |
|
128 | + $this->set('GRP_ID', $GRP_ID); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * Gets TXN_ID |
|
134 | + * |
|
135 | + * @return int |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public function TXN_ID() |
|
139 | + { |
|
140 | + return $this->get('TXN_ID'); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Sets TXN_ID |
|
146 | + * |
|
147 | + * @param int $TXN_ID |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + public function set_TXN_ID($TXN_ID) |
|
151 | + { |
|
152 | + $this->set('TXN_ID', $TXN_ID); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Gets messenger |
|
158 | + * |
|
159 | + * @return string |
|
160 | + * @throws EE_Error |
|
161 | + */ |
|
162 | + public function messenger() |
|
163 | + { |
|
164 | + return $this->get('MSG_messenger'); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Sets messenger |
|
170 | + * |
|
171 | + * @param string $messenger |
|
172 | + * @throws EE_Error |
|
173 | + */ |
|
174 | + public function set_messenger($messenger) |
|
175 | + { |
|
176 | + $this->set('MSG_messenger', $messenger); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns corresponding messenger object for the set messenger on this message |
|
182 | + * |
|
183 | + * @return EE_messenger | null |
|
184 | + */ |
|
185 | + public function messenger_object() |
|
186 | + { |
|
187 | + return $this->_messenger; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Sets messenger |
|
193 | + * |
|
194 | + * @param EE_messenger $messenger |
|
195 | + */ |
|
196 | + public function set_messenger_object(EE_messenger $messenger) |
|
197 | + { |
|
198 | + $this->_messenger = $messenger; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * validates messenger |
|
204 | + * |
|
205 | + * @param bool $throw_exceptions |
|
206 | + * @return bool |
|
207 | + * @throws EE_Error |
|
208 | + */ |
|
209 | + public function valid_messenger($throw_exceptions = false) |
|
210 | + { |
|
211 | + if ($this->_messenger instanceof EE_messenger) { |
|
212 | + return true; |
|
213 | + } |
|
214 | + if ($throw_exceptions) { |
|
215 | + throw new EE_Error( |
|
216 | + sprintf( |
|
217 | + esc_html__( |
|
218 | + 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + $this->messenger() |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + return false; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * This returns the set localized label for the messenger on this message. |
|
231 | + * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
232 | + * with this message. |
|
233 | + * |
|
234 | + * @param bool $plural whether to return the plural label or not. |
|
235 | + * @return string |
|
236 | + * @throws EE_Error |
|
237 | + */ |
|
238 | + public function messenger_label($plural = false) |
|
239 | + { |
|
240 | + $label_type = $plural ? 'plural' : 'singular'; |
|
241 | + $messenger = $this->messenger_object(); |
|
242 | + return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Gets message_type |
|
248 | + * |
|
249 | + * @return string |
|
250 | + * @throws EE_Error |
|
251 | + */ |
|
252 | + public function message_type() |
|
253 | + { |
|
254 | + return $this->get('MSG_message_type'); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Sets message_type |
|
260 | + * |
|
261 | + * @param string $message_type |
|
262 | + * @throws EE_Error |
|
263 | + */ |
|
264 | + public function set_message_type($message_type) |
|
265 | + { |
|
266 | + $this->set('MSG_message_type', $message_type); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Returns the message type object for the set message type on this message |
|
272 | + * |
|
273 | + * @return EE_message_type | null |
|
274 | + */ |
|
275 | + public function message_type_object() |
|
276 | + { |
|
277 | + return $this->_message_type; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Sets message_type |
|
283 | + * |
|
284 | + * @param EE_message_type $message_type |
|
285 | + * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
286 | + * the message type or not. |
|
287 | + * @throws EE_Error |
|
288 | + */ |
|
289 | + public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
290 | + { |
|
291 | + $this->_message_type = $message_type; |
|
292 | + if ($set_priority) { |
|
293 | + $this->set_priority($this->_message_type->get_priority()); |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * validates message_type |
|
300 | + * |
|
301 | + * @param bool $throw_exceptions |
|
302 | + * @return bool |
|
303 | + * @throws \EE_Error |
|
304 | + * @throws EE_Error |
|
305 | + */ |
|
306 | + public function valid_message_type($throw_exceptions = false) |
|
307 | + { |
|
308 | + if ($this->_message_type instanceof EE_message_type) { |
|
309 | + return true; |
|
310 | + } |
|
311 | + if ($throw_exceptions) { |
|
312 | + throw new EE_Error( |
|
313 | + sprintf( |
|
314 | + esc_html__( |
|
315 | + 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
316 | + 'event_espresso' |
|
317 | + ), |
|
318 | + $this->message_type() |
|
319 | + ) |
|
320 | + ); |
|
321 | + } |
|
322 | + return false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
328 | + * |
|
329 | + * @param bool $throw_exceptions |
|
330 | + * @return bool |
|
331 | + * @throws EE_Error |
|
332 | + */ |
|
333 | + public function is_valid($throw_exceptions = false) |
|
334 | + { |
|
335 | + if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
336 | + return true; |
|
337 | + } |
|
338 | + return false; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * This validates whether the internal messenger and message type objects are valid for sending. |
|
344 | + * Three checks are done: |
|
345 | + * 1. There is a valid messenger object. |
|
346 | + * 2. There is a valid message type object. |
|
347 | + * 3. The message type object is active for the messenger. |
|
348 | + * |
|
349 | + * @param bool $throw_exceptions |
|
350 | + * @return bool But only if $throw_exceptions is set to true. |
|
351 | + * @throws EE_Error But only if $throw_exceptions is set to true. |
|
352 | + * @throws InvalidArgumentException |
|
353 | + * @throws ReflectionException |
|
354 | + * @throws InvalidDataTypeException |
|
355 | + * @throws InvalidInterfaceException |
|
356 | + */ |
|
357 | + public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
358 | + { |
|
359 | + $valid = false; |
|
360 | + if ($this->is_valid($throw_exceptions)) { |
|
361 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
362 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
363 | + $valid = $message_resource_manager->is_message_type_active_for_messenger( |
|
364 | + $this->messenger(), |
|
365 | + $this->message_type() |
|
366 | + ); |
|
367 | + if (! $valid && $throw_exceptions) { |
|
368 | + throw new EE_Error( |
|
369 | + sprintf( |
|
370 | + esc_html__( |
|
371 | + 'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
372 | + 'event_espresso' |
|
373 | + ), |
|
374 | + $this->message_type(), |
|
375 | + $this->messenger() |
|
376 | + ) |
|
377 | + ); |
|
378 | + } |
|
379 | + } |
|
380 | + return $valid; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * This returns the set localized label for the message type on this message. |
|
386 | + * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
387 | + * with this message. |
|
388 | + * |
|
389 | + * @param bool $plural whether to return the plural label or not. |
|
390 | + * @return string |
|
391 | + * @throws EE_Error |
|
392 | + */ |
|
393 | + public function message_type_label($plural = false) |
|
394 | + { |
|
395 | + $label_type = $plural ? 'plural' : 'singular'; |
|
396 | + $message_type = $this->message_type_object(); |
|
397 | + return $message_type instanceof EE_message_type |
|
398 | + ? $message_type->label[$label_type] |
|
399 | + : str_replace( |
|
400 | + '_', |
|
401 | + ' ', |
|
402 | + $this->message_type() |
|
403 | + ); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Gets context |
|
409 | + * |
|
410 | + * @return string |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + public function context() |
|
414 | + { |
|
415 | + return $this->get('MSG_context'); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
421 | + * types. Otherwise, this will just return the set context slug on this object. |
|
422 | + * |
|
423 | + * @return string |
|
424 | + * @throws EE_Error |
|
425 | + * @throws InvalidArgumentException |
|
426 | + * @throws ReflectionException |
|
427 | + * @throws InvalidDataTypeException |
|
428 | + * @throws InvalidInterfaceException |
|
429 | + */ |
|
430 | + public function context_label() |
|
431 | + { |
|
432 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
433 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
434 | + $contexts = $message_resource_manager->get_all_contexts(); |
|
435 | + return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Sets context |
|
441 | + * |
|
442 | + * @param string $context |
|
443 | + * @throws EE_Error |
|
444 | + */ |
|
445 | + public function set_context($context) |
|
446 | + { |
|
447 | + $this->set('MSG_context', $context); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Gets recipient_ID |
|
453 | + * |
|
454 | + * @return int |
|
455 | + * @throws EE_Error |
|
456 | + */ |
|
457 | + public function recipient_ID() |
|
458 | + { |
|
459 | + return $this->get('MSG_recipient_ID'); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * Sets recipient_ID |
|
465 | + * |
|
466 | + * @param string $recipient_ID |
|
467 | + * @throws EE_Error |
|
468 | + */ |
|
469 | + public function set_recipient_ID($recipient_ID) |
|
470 | + { |
|
471 | + $this->set('MSG_recipient_ID', $recipient_ID); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * Gets recipient_type |
|
477 | + * |
|
478 | + * @return string |
|
479 | + * @throws EE_Error |
|
480 | + */ |
|
481 | + public function recipient_type() |
|
482 | + { |
|
483 | + return $this->get('MSG_recipient_type'); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * Return the related object matching the recipient type and ID. |
|
489 | + * |
|
490 | + * @return EE_Base_Class|null |
|
491 | + * @throws EE_Error |
|
492 | + */ |
|
493 | + public function recipient_object() |
|
494 | + { |
|
495 | + if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
496 | + return null; |
|
497 | + } |
|
498 | + |
|
499 | + return $this->get_first_related($this->recipient_type()); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Sets recipient_type |
|
505 | + * |
|
506 | + * @param string $recipient_type |
|
507 | + * @throws EE_Error |
|
508 | + */ |
|
509 | + public function set_recipient_type($recipient_type) |
|
510 | + { |
|
511 | + $this->set('MSG_recipient_type', $recipient_type); |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * Gets content |
|
517 | + * |
|
518 | + * @return string |
|
519 | + * @throws EE_Error |
|
520 | + */ |
|
521 | + public function content() |
|
522 | + { |
|
523 | + return $this->get('MSG_content'); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Sets content |
|
529 | + * |
|
530 | + * @param string $content |
|
531 | + * @throws EE_Error |
|
532 | + */ |
|
533 | + public function set_content($content) |
|
534 | + { |
|
535 | + $this->set('MSG_content', $content); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Gets subject |
|
541 | + * |
|
542 | + * @return string |
|
543 | + * @throws EE_Error |
|
544 | + */ |
|
545 | + public function subject() |
|
546 | + { |
|
547 | + return $this->get('MSG_subject'); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * Sets subject |
|
553 | + * |
|
554 | + * @param string $subject |
|
555 | + * @throws EE_Error |
|
556 | + */ |
|
557 | + public function set_subject($subject) |
|
558 | + { |
|
559 | + $this->set('MSG_subject', $subject); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Gets to |
|
565 | + * |
|
566 | + * @return string |
|
567 | + * @throws EE_Error |
|
568 | + */ |
|
569 | + public function to() |
|
570 | + { |
|
571 | + $to = $this->get('MSG_to'); |
|
572 | + return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to; |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * Sets to |
|
578 | + * |
|
579 | + * @param string $to |
|
580 | + * @throws EE_Error |
|
581 | + */ |
|
582 | + public function set_to($to) |
|
583 | + { |
|
584 | + $this->set('MSG_to', $to); |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * Gets from |
|
590 | + * |
|
591 | + * @return string |
|
592 | + * @throws EE_Error |
|
593 | + */ |
|
594 | + public function from() |
|
595 | + { |
|
596 | + return $this->get('MSG_from'); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * Sets from |
|
602 | + * |
|
603 | + * @param string $from |
|
604 | + * @throws EE_Error |
|
605 | + */ |
|
606 | + public function set_from($from) |
|
607 | + { |
|
608 | + $this->set('MSG_from', $from); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * Gets priority |
|
614 | + * |
|
615 | + * @return int |
|
616 | + * @throws EE_Error |
|
617 | + */ |
|
618 | + public function priority() |
|
619 | + { |
|
620 | + return $this->get('MSG_priority'); |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Sets priority |
|
626 | + * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
627 | + * this method calls the send_now method to verify that. |
|
628 | + * |
|
629 | + * @param int $priority |
|
630 | + * @throws EE_Error |
|
631 | + */ |
|
632 | + public function set_priority($priority) |
|
633 | + { |
|
634 | + $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
635 | + parent::set('MSG_priority', $priority); |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * Overrides parent::set method so we can capture any sets for priority. |
|
641 | + * |
|
642 | + * @see parent::set() for phpdocs |
|
643 | + * @param string $field_name |
|
644 | + * @param mixed $field_value |
|
645 | + * @param bool $use_default |
|
646 | + * @throws EE_Error |
|
647 | + */ |
|
648 | + public function set($field_name, $field_value, $use_default = false) |
|
649 | + { |
|
650 | + if ($field_name === 'MSG_priority') { |
|
651 | + $this->set_priority($field_value); |
|
652 | + } |
|
653 | + parent::set($field_name, $field_value, $use_default); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * @return bool |
|
659 | + * @throws \EE_Error |
|
660 | + */ |
|
661 | + public function send_now() |
|
662 | + { |
|
663 | + $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() |
|
664 | + ? EEM_Message::priority_high |
|
665 | + : $this->priority(); |
|
666 | + return $send_now === EEM_Message::priority_high; |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * Gets STS_ID |
|
672 | + * |
|
673 | + * @return string |
|
674 | + * @throws EE_Error |
|
675 | + */ |
|
676 | + public function STS_ID() |
|
677 | + { |
|
678 | + return $this->get('STS_ID'); |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * Sets STS_ID |
|
684 | + * |
|
685 | + * @param string $STS_ID |
|
686 | + * @throws EE_Error |
|
687 | + */ |
|
688 | + public function set_STS_ID($STS_ID) |
|
689 | + { |
|
690 | + $this->set('STS_ID', $STS_ID); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * Gets created |
|
696 | + * |
|
697 | + * @return string |
|
698 | + * @throws EE_Error |
|
699 | + */ |
|
700 | + public function created() |
|
701 | + { |
|
702 | + return $this->get('MSG_created'); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * Sets created |
|
708 | + * |
|
709 | + * @param string $created |
|
710 | + * @throws EE_Error |
|
711 | + */ |
|
712 | + public function set_created($created) |
|
713 | + { |
|
714 | + $this->set('MSG_created', $created); |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * Gets modified |
|
720 | + * |
|
721 | + * @return string |
|
722 | + * @throws EE_Error |
|
723 | + */ |
|
724 | + public function modified() |
|
725 | + { |
|
726 | + return $this->get('MSG_modified'); |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * Sets modified |
|
732 | + * |
|
733 | + * @param string $modified |
|
734 | + * @throws EE_Error |
|
735 | + */ |
|
736 | + public function set_modified($modified) |
|
737 | + { |
|
738 | + $this->set('MSG_modified', $modified); |
|
739 | + } |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * Sets generation data for this message. |
|
744 | + * |
|
745 | + * @param mixed $data |
|
746 | + * @throws EE_Error |
|
747 | + */ |
|
748 | + public function set_generation_data($data) |
|
749 | + { |
|
750 | + $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * Returns any set generation data for this message. |
|
756 | + * |
|
757 | + * @return mixed|null |
|
758 | + * @throws EE_Error |
|
759 | + */ |
|
760 | + public function get_generation_data() |
|
761 | + { |
|
762 | + return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * Gets any error message. |
|
768 | + * |
|
769 | + * @return mixed|null |
|
770 | + * @throws EE_Error |
|
771 | + */ |
|
772 | + public function error_message() |
|
773 | + { |
|
774 | + return $this->get_field_or_extra_meta('MSG_error'); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * Sets an error message. |
|
780 | + * |
|
781 | + * @param $message |
|
782 | + * @return bool|int |
|
783 | + * @throws EE_Error |
|
784 | + */ |
|
785 | + public function set_error_message($message) |
|
786 | + { |
|
787 | + return $this->set_field_or_extra_meta('MSG_error', $message); |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * This retrieves the associated template pack with this message. |
|
793 | + * |
|
794 | + * @return EE_Messages_Template_Pack|null |
|
795 | + * @throws EE_Error |
|
796 | + * @throws InvalidArgumentException |
|
797 | + * @throws ReflectionException |
|
798 | + * @throws InvalidDataTypeException |
|
799 | + * @throws InvalidInterfaceException |
|
800 | + */ |
|
801 | + public function get_template_pack() |
|
802 | + { |
|
803 | + /** |
|
804 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
805 | + */ |
|
806 | + if (! empty($this->template_pack)) { |
|
807 | + return $this->template_pack; |
|
808 | + } |
|
809 | + /** @type EE_Message_Template_Group $grp */ |
|
810 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
811 | + //if no group then let's try to get the first related group by internal messenger and message type |
|
812 | + // (will use global grp). |
|
813 | + if (! $grp instanceof EE_Message_Template_Group) { |
|
814 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
815 | + array( |
|
816 | + array( |
|
817 | + 'MTP_messenger' => $this->messenger(), |
|
818 | + 'MTP_message_type' => $this->message_type(), |
|
819 | + 'MTP_is_global' => true, |
|
820 | + ), |
|
821 | + ) |
|
822 | + ); |
|
823 | + } |
|
824 | + |
|
825 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * Retrieves the variation used for generating this message. |
|
831 | + * |
|
832 | + * @return string |
|
833 | + * @throws EE_Error |
|
834 | + * @throws InvalidArgumentException |
|
835 | + * @throws InvalidDataTypeException |
|
836 | + * @throws InvalidInterfaceException |
|
837 | + */ |
|
838 | + public function get_template_pack_variation() |
|
839 | + { |
|
840 | + /** |
|
841 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
842 | + */ |
|
843 | + if (! empty($this->template_variation)) { |
|
844 | + return $this->template_variation; |
|
845 | + } |
|
846 | + |
|
847 | + /** @type EE_Message_Template_Group $grp */ |
|
848 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
849 | + |
|
850 | + //if no group then let's try to get the first related group by internal messenger and message type |
|
851 | + // (will use global grp). |
|
852 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
853 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
854 | + array( |
|
855 | + array( |
|
856 | + 'MTP_messenger' => $this->messenger(), |
|
857 | + 'MTP_message_type' => $this->message_type(), |
|
858 | + 'MTP_is_global' => true, |
|
859 | + ), |
|
860 | + ) |
|
861 | + ); |
|
862 | + } |
|
863 | + |
|
864 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
865 | + } |
|
866 | + |
|
867 | + /** |
|
868 | + * Return the link to the admin details for the object. |
|
869 | + * |
|
870 | + * @return string |
|
871 | + * @throws EE_Error |
|
872 | + * @throws InvalidArgumentException |
|
873 | + * @throws ReflectionException |
|
874 | + * @throws InvalidDataTypeException |
|
875 | + * @throws InvalidInterfaceException |
|
876 | + */ |
|
877 | + public function get_admin_details_link() |
|
878 | + { |
|
879 | + EE_Registry::instance()->load_helper('URL'); |
|
880 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
881 | + switch ($this->STS_ID()) { |
|
882 | + case EEM_Message::status_failed: |
|
883 | + case EEM_Message::status_debug_only: |
|
884 | + return EEH_MSG_Template::generate_error_display_trigger($this); |
|
885 | + break; |
|
886 | + |
|
887 | + case EEM_Message::status_sent: |
|
888 | + return EEH_MSG_Template::generate_browser_trigger($this); |
|
889 | + break; |
|
890 | + |
|
891 | + default: |
|
892 | + return ''; |
|
893 | + } |
|
894 | + } |
|
895 | + |
|
896 | + /** |
|
897 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
898 | + * |
|
899 | + * @return string |
|
900 | + * @throws EE_Error |
|
901 | + * @throws InvalidArgumentException |
|
902 | + * @throws ReflectionException |
|
903 | + * @throws InvalidDataTypeException |
|
904 | + * @throws InvalidInterfaceException |
|
905 | + */ |
|
906 | + public function get_admin_edit_link() |
|
907 | + { |
|
908 | + return $this->get_admin_details_link(); |
|
909 | + } |
|
910 | + |
|
911 | + /** |
|
912 | + * Returns the link to a settings page for the object. |
|
913 | + * |
|
914 | + * @return string |
|
915 | + * @throws EE_Error |
|
916 | + * @throws InvalidArgumentException |
|
917 | + * @throws ReflectionException |
|
918 | + * @throws InvalidDataTypeException |
|
919 | + * @throws InvalidInterfaceException |
|
920 | + */ |
|
921 | + public function get_admin_settings_link() |
|
922 | + { |
|
923 | + EE_Registry::instance()->load_helper('URL'); |
|
924 | + return EEH_URL::add_query_args_and_nonce( |
|
925 | + array( |
|
926 | + 'page' => 'espresso_messages', |
|
927 | + 'action' => 'settings', |
|
928 | + ), |
|
929 | + admin_url('admin.php') |
|
930 | + ); |
|
931 | + } |
|
932 | + |
|
933 | + /** |
|
934 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
935 | + * |
|
936 | + * @return string |
|
937 | + * @throws EE_Error |
|
938 | + * @throws InvalidArgumentException |
|
939 | + * @throws ReflectionException |
|
940 | + * @throws InvalidDataTypeException |
|
941 | + * @throws InvalidInterfaceException |
|
942 | + */ |
|
943 | + public function get_admin_overview_link() |
|
944 | + { |
|
945 | + EE_Registry::instance()->load_helper('URL'); |
|
946 | + return EEH_URL::add_query_args_and_nonce( |
|
947 | + array( |
|
948 | + 'page' => 'espresso_messages', |
|
949 | + 'action' => 'default', |
|
950 | + ), |
|
951 | + admin_url('admin.php') |
|
952 | + ); |
|
953 | + } |
|
954 | + |
|
955 | + |
|
956 | + /** |
|
957 | + * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
958 | + * it. |
|
959 | + * Note this also SAVES the current message object to the db because it adds an error message to accompany the |
|
960 | + * status. |
|
961 | + * |
|
962 | + * @throws EE_Error |
|
963 | + */ |
|
964 | + public function set_messenger_is_executing() |
|
965 | + { |
|
966 | + $this->set_STS_ID(EEM_Message::status_messenger_executing); |
|
967 | + $this->set_error_message( |
|
968 | + esc_html__( |
|
969 | + 'A message with this status indicates that there was a problem that occurred while the message was being processed by the messenger. It is still possible that the message was sent successfully, but at some point during the processing there was a failure. This usually is indicative of a timeout issue with PHP or memory limits being reached. If you see this repeatedly you may want to consider upgrading the memory available to PHP on your server.', |
|
970 | + 'event_espresso' |
|
971 | + ) |
|
972 | + ); |
|
973 | + } |
|
974 | 974 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
63 | 63 | //if object doesn't exist, let's generate a unique token on instantiation so that its available even before |
64 | 64 | // saving to db. |
65 | - if (! $has_object) { |
|
65 | + if ( ! $has_object) { |
|
66 | 66 | EE_Registry::instance()->load_helper('URL'); |
67 | 67 | $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
68 | 68 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $this->messenger(), |
365 | 365 | $this->message_type() |
366 | 366 | ); |
367 | - if (! $valid && $throw_exceptions) { |
|
367 | + if ( ! $valid && $throw_exceptions) { |
|
368 | 368 | throw new EE_Error( |
369 | 369 | sprintf( |
370 | 370 | esc_html__( |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | */ |
493 | 493 | public function recipient_object() |
494 | 494 | { |
495 | - if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
495 | + if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
496 | 496 | return null; |
497 | 497 | } |
498 | 498 | |
@@ -803,14 +803,14 @@ discard block |
||
803 | 803 | /** |
804 | 804 | * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
805 | 805 | */ |
806 | - if (! empty($this->template_pack)) { |
|
806 | + if ( ! empty($this->template_pack)) { |
|
807 | 807 | return $this->template_pack; |
808 | 808 | } |
809 | 809 | /** @type EE_Message_Template_Group $grp */ |
810 | 810 | $grp = $this->get_first_related('Message_Template_Group'); |
811 | 811 | //if no group then let's try to get the first related group by internal messenger and message type |
812 | 812 | // (will use global grp). |
813 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
813 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
814 | 814 | $grp = EEM_Message_Template_Group::instance()->get_one( |
815 | 815 | array( |
816 | 816 | array( |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | /** |
841 | 841 | * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
842 | 842 | */ |
843 | - if (! empty($this->template_variation)) { |
|
843 | + if ( ! empty($this->template_variation)) { |
|
844 | 844 | return $this->template_variation; |
845 | 845 | } |
846 | 846 |